Skip to content

Commit

Permalink
8320331: G1 Full GC Heap verification relies on metadata not reset be…
Browse files Browse the repository at this point in the history
…fore verification

Backport-of: 1629a9059bd2e0f07559a384be4276c7dc13eff2
  • Loading branch information
GoeLin committed Apr 23, 2024
1 parent d11a065 commit ffdde9c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2761,7 +2761,7 @@ bool G1CollectedHeap::check_young_list_empty() {

// Remove the given HeapRegion from the appropriate region set.
void G1CollectedHeap::prepare_region_for_full_compaction(HeapRegion* hr) {
if (hr->is_humongous()) {
if (hr->is_humongous()) {
_humongous_set.remove(hr);
} else if (hr->is_old()) {
_old_set.remove(hr);
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/g1/g1FullCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class PrepareRegionsClosure : public HeapRegionClosure {
PrepareRegionsClosure(G1FullCollector* collector) : _collector(collector) { }

bool do_heap_region(HeapRegion* hr) {
hr->prepare_for_full_gc();
G1CollectedHeap::heap()->prepare_region_for_full_compaction(hr);
_collector->before_marking_update_attribute_table(hr);
return false;
Expand Down
17 changes: 12 additions & 5 deletions src/hotspot/share/gc/g1/heapRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class HeapRegion : public CHeapObj<mtGC> {

void update_bot_for_block(HeapWord* start, HeapWord* end);

void prepare_for_full_gc();
// Update heap region that has been compacted to be consistent after Full GC.
void reset_compacted_after_full_gc(HeapWord* new_top);
// Update skip-compacting heap region to be consistent after Full GC.
Expand Down Expand Up @@ -233,11 +234,17 @@ class HeapRegion : public CHeapObj<mtGC> {
HeapWord* volatile _top_at_mark_start;

// The area above this limit is fully parsable. This limit
// is equal to bottom except from Remark and until the region has been
// scrubbed concurrently. The scrubbing ensures that all dead objects (with
// possibly unloaded classes) have beenreplaced with filler objects that
// are parsable. Below this limit the marking bitmap must be used to
// determine size and liveness.
// is equal to bottom except
//
// * from Remark and until the region has been scrubbed concurrently. The
// scrubbing ensures that all dead objects (with possibly unloaded classes)
// have been replaced with filler objects that are parsable.
// * after the marking phase in the Full GC pause until the objects have been
// moved. Some (debug) code iterates over the heap after marking but before
// compaction.
//
// Below this limit the marking bitmap must be used to determine size and
// liveness.
HeapWord* volatile _parsable_bottom;

// Amount of dead data in the region.
Expand Down
9 changes: 8 additions & 1 deletion src/hotspot/share/gc/g1/heapRegion.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ inline size_t HeapRegion::block_size(const HeapWord* p, HeapWord* const pb) cons
return cast_to_oop(p)->size();
}

inline void HeapRegion::prepare_for_full_gc() {
// After marking and class unloading the heap temporarily contains dead objects
// with unloaded klasses. Moving parsable_bottom makes some (debug) code correctly
// skip dead objects.
_parsable_bottom = top();
}

inline void HeapRegion::reset_compacted_after_full_gc(HeapWord* new_top) {
set_top(new_top);
// After a compaction the mark bitmap in a movable region is invalid.
Expand All @@ -201,7 +208,7 @@ inline void HeapRegion::reset_skip_compacting_after_full_gc() {

inline void HeapRegion::reset_after_full_gc_common() {
// Everything above bottom() is parsable and live.
_parsable_bottom = bottom();
reset_parsable_bottom();

// Clear unused heap memory in debug builds.
if (ZapUnusedHeapArea) {
Expand Down
12 changes: 11 additions & 1 deletion test/hotspot/jtreg/runtime/Metaspace/FragmentMetaspace.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 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
Expand Down Expand Up @@ -29,6 +29,16 @@
* @run main/othervm/timeout=200 -Xmx1g FragmentMetaspace
*/

/**
* @test id=8320331
* @bug 8320331
* @requires vm.debug
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.compiler
* @run main/othervm/timeout=200 -XX:+UnlockDiagnosticVMOptions -XX:+VerifyDuringGC -Xmx1g FragmentMetaspace
*/

import java.io.IOException;
import jdk.test.lib.classloader.GeneratingCompilingClassLoader;

Expand Down

1 comment on commit ffdde9c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.