Skip to content

Commit

Permalink
8303027: [Lilliput/JDK17] Correctly resolve forwarded objects in G1 h…
Browse files Browse the repository at this point in the history
…eap iteration

Reviewed-by: shade
  • Loading branch information
rkennke committed Feb 23, 2023
1 parent 23bfadb commit 4e089d1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/hotspot/share/gc/g1/heapRegion.cpp
Expand Up @@ -860,12 +860,21 @@ HeapWord* HeapRegion::cross_threshold(HeapWord* start, HeapWord* end) {
return _bot_part.threshold();
}

void HeapRegion::object_iterate(ObjectClosure* blk) {
template<bool RESOLVE>
void HeapRegion::object_iterate_impl(ObjectClosure* blk) {
HeapWord* p = bottom();
while (p < top()) {
if (block_is_obj(p)) {
blk->do_object(cast_to_oop(p));
}
p += block_size(p);
p += block_size<RESOLVE>(p);
}
}

void HeapRegion::object_iterate(ObjectClosure* blk) {
if (G1CollectedHeap::heap()->collector_state()->in_full_gc()) {
object_iterate_impl<false>(blk);
} else {
object_iterate_impl<true>(blk);
}
}
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/g1/heapRegion.hpp
Expand Up @@ -145,6 +145,9 @@ class HeapRegion : public CHeapObj<mtGC> {
// This version synchronizes with other calls to par_allocate_impl().
inline HeapWord* par_allocate_impl(size_t min_word_size, size_t desired_word_size, size_t* actual_word_size);

template<bool RESOLVE>
void object_iterate_impl(ObjectClosure* blk);

public:
HeapWord* block_start(const void* p);

Expand Down Expand Up @@ -183,6 +186,7 @@ class HeapRegion : public CHeapObj<mtGC> {

// Returns the object size for all valid block starts
// and the amount of unallocated words if called on top()
template<bool RESOLVE = false>
size_t block_size(const HeapWord* p) const;

// Scans through the region using the bitmap to determine what
Expand Down
10 changes: 9 additions & 1 deletion src/hotspot/share/gc/g1/heapRegion.inline.hpp
Expand Up @@ -177,6 +177,7 @@ inline bool HeapRegion::is_obj_dead(const oop obj, const G1CMBitMap* const prev_
!is_closed_archive();
}

template <bool RESOLVE>
inline size_t HeapRegion::block_size(const HeapWord *addr) const {
if (addr == top()) {
return pointer_delta(end(), addr);
Expand All @@ -185,7 +186,14 @@ inline size_t HeapRegion::block_size(const HeapWord *addr) const {
if (block_is_obj(addr)) {
oop obj = cast_to_oop(addr);
#ifdef _LP64
if (obj->is_forwarded() && CompressedKlassPointers::is_null(obj->mark().narrow_klass())) {
#ifdef ASSERT
if (RESOLVE) {
assert(!G1CollectedHeap::heap()->collector_state()->in_full_gc(), "Illegal/excessive resolve during full-GC");
} else {
assert(G1CollectedHeap::heap()->collector_state()->in_full_gc() || !obj->is_forwarded(), "Missing resolve when forwarded during normal GC");
}
#endif
if (RESOLVE && obj->is_forwarded()) {
obj = obj->forwardee();
}
#endif
Expand Down
59 changes: 59 additions & 0 deletions test/hotspot/jtreg/runtime/oom/TestOOM.java
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8303027
* @requires vm.bits == "64"
* @summary Test that we're failing with OOME and not with VM crash
* @run main/othervm -Xmx1g -XX:-UseCompressedOops TestOOM
*/
/*
* @test
* @bug 8303027
* @requires vm.bits == "32"
* @summary Test that we're failing with OOME and not with VM crash
* @run main/othervm -Xmx1g TestOOM
*/
public class TestOOM {
public static void main(String[] args) {
// Test that it exits with OOME and not with VM crash.
try {
LinkedInsanity previous = null;
while (true) {
previous = new LinkedInsanity(previous);
}
} catch (OutOfMemoryError e) {
// That's expected
}
}

private static class LinkedInsanity {
private final LinkedInsanity previous;
private final int[] padding = new int[64000];

public LinkedInsanity(LinkedInsanity previous) {
this.previous = previous;
}
}
}

0 comments on commit 4e089d1

Please sign in to comment.