Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8303027: [Lilliput/JDK17] Correctly resolve forwarded objects in G1 heap iteration #6

Closed
wants to merge 9 commits into from
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
5 changes: 4 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,9 @@ 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())) {
assert(!G1CollectedHeap::heap()->collector_state()->in_full_gc() || !RESOLVE, "don't resolve during full-GC");
assert(G1CollectedHeap::heap()->collector_state()->in_full_gc() || !obj->is_forwarded() || RESOLVE, "resolve object during non-full when forwarded");
if (RESOLVE && obj->is_forwarded()) {
obj = obj->forwardee();
}
#endif
Expand Down
51 changes: 51 additions & 0 deletions test/hotspot/jtreg/runtime/oom/TestOOM.java
@@ -0,0 +1,51 @@
/*
* 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
* @summary Test that we're failing with OOME and not with VM crash
* @run main/othervm -Xmx10g 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;
}
}
}