Skip to content

Commit 1629a90

Browse files
author
Thomas Schatzl
committedNov 22, 2023
8320331: G1 Full GC Heap verification relies on metadata not reset before verification
Reviewed-by: iwalulya, ayang
1 parent 93bdc2a commit 1629a90

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed
 

‎src/hotspot/share/gc/g1/g1CollectedHeap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2765,7 +2765,7 @@ bool G1CollectedHeap::check_young_list_empty() {
27652765

27662766
// Remove the given HeapRegion from the appropriate region set.
27672767
void G1CollectedHeap::prepare_region_for_full_compaction(HeapRegion* hr) {
2768-
if (hr->is_humongous()) {
2768+
if (hr->is_humongous()) {
27692769
_humongous_set.remove(hr);
27702770
} else if (hr->is_old()) {
27712771
_old_set.remove(hr);

‎src/hotspot/share/gc/g1/g1FullCollector.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class PrepareRegionsClosure : public HeapRegionClosure {
171171
PrepareRegionsClosure(G1FullCollector* collector) : _collector(collector) { }
172172

173173
bool do_heap_region(HeapRegion* hr) {
174+
hr->prepare_for_full_gc();
174175
G1CollectedHeap::heap()->prepare_region_for_full_compaction(hr);
175176
_collector->before_marking_update_attribute_table(hr);
176177
return false;

‎src/hotspot/share/gc/g1/heapRegion.hpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class HeapRegion : public CHeapObj<mtGC> {
174174

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

177+
void prepare_for_full_gc();
177178
// Update heap region that has been compacted to be consistent after Full GC.
178179
void reset_compacted_after_full_gc(HeapWord* new_top);
179180
// Update skip-compacting heap region to be consistent after Full GC.
@@ -229,11 +230,17 @@ class HeapRegion : public CHeapObj<mtGC> {
229230
HeapWord* volatile _top_at_mark_start;
230231

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

239246
// Amount of dead data in the region.

‎src/hotspot/share/gc/g1/heapRegion.inline.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ inline size_t HeapRegion::block_size(const HeapWord* p, HeapWord* const pb) cons
167167
return cast_to_oop(p)->size();
168168
}
169169

170+
inline void HeapRegion::prepare_for_full_gc() {
171+
// After marking and class unloading the heap temporarily contains dead objects
172+
// with unloaded klasses. Moving parsable_bottom makes some (debug) code correctly
173+
// skip dead objects.
174+
_parsable_bottom = top();
175+
}
176+
170177
inline void HeapRegion::reset_compacted_after_full_gc(HeapWord* new_top) {
171178
set_top(new_top);
172179
// After a compaction the mark bitmap in a movable region is invalid.
@@ -188,7 +195,7 @@ inline void HeapRegion::reset_skip_compacting_after_full_gc() {
188195

189196
inline void HeapRegion::reset_after_full_gc_common() {
190197
// Everything above bottom() is parsable and live.
191-
_parsable_bottom = bottom();
198+
reset_parsable_bottom();
192199

193200
// Clear unused heap memory in debug builds.
194201
if (ZapUnusedHeapArea) {

‎test/hotspot/jtreg/runtime/Metaspace/FragmentMetaspace.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,16 @@
2929
* @run main/othervm/timeout=200 -Xmx1g FragmentMetaspace
3030
*/
3131

32+
/**
33+
* @test id=8320331
34+
* @bug 8320331
35+
* @requires vm.debug
36+
* @library /test/lib
37+
* @modules java.base/jdk.internal.misc
38+
* @modules java.compiler
39+
* @run main/othervm/timeout=200 -XX:+UnlockDiagnosticVMOptions -XX:+VerifyDuringGC -Xmx1g FragmentMetaspace
40+
*/
41+
3242
import java.io.IOException;
3343
import jdk.test.lib.classloader.GeneratingCompilingClassLoader;
3444

3 commit comments

Comments
 (3)

openjdk-notifier[bot] commented on Nov 22, 2023

@openjdk-notifier[bot]

GoeLin commented on Apr 22, 2024

@GoeLin
Member

/backport jdk21u-dev

openjdk[bot] commented on Apr 22, 2024

@openjdk[bot]

@GoeLin the backport was successfully created on the branch backport-GoeLin-1629a905 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 1629a905 from the openjdk/jdk repository.

The commit being backported was authored by Thomas Schatzl on 22 Nov 2023 and was reviewed by Ivan Walulya and Albert Mingkun Yang.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-1629a905:backport-GoeLin-1629a905
$ git checkout backport-GoeLin-1629a905
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-1629a905
Please sign in to comment.