8270991: G1 Full GC always performs heap verification after JDK-8269295

Reviewed-by: iwalulya, kbarrett
This commit is contained in:
Thomas Schatzl 2021-07-21 15:41:34 +00:00
parent cd8783c08e
commit 57611b3021
2 changed files with 33 additions and 11 deletions
src/hotspot/share/gc/g1
test/hotspot/jtreg/gc/arguments

@ -1028,6 +1028,9 @@ void G1CollectedHeap::prepare_heap_for_full_collection() {
void G1CollectedHeap::verify_before_full_collection(bool explicit_gc) {
assert(!GCCause::is_user_requested_gc(gc_cause()) || explicit_gc, "invariant");
assert_used_and_recalculate_used_equal(this);
if (!VerifyBeforeGC) {
return;
}
_verifier->verify_region_sets_optional();
_verifier->verify_before_gc(G1HeapVerifier::G1VerifyFull);
_verifier->check_bitmaps("Full GC Start");
@ -1073,6 +1076,9 @@ void G1CollectedHeap::abort_refinement() {
}
void G1CollectedHeap::verify_after_full_collection() {
if (!VerifyAfterGC) {
return;
}
_hrm.verify_optional();
_verifier->verify_region_sets_optional();
_verifier->verify_after_gc(G1HeapVerifier::G1VerifyFull);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@ -34,6 +34,8 @@ package gc.arguments;
* @modules java.management
* @library /test/lib
* @library /
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run driver gc.arguments.TestVerifyBeforeAndAfterGCFlags
*/
@ -44,6 +46,8 @@ import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import sun.hotspot.WhiteBox;
public class TestVerifyBeforeAndAfterGCFlags {
// VerifyBeforeGC:[Verifying threads heap tenured eden syms strs zone dict metaspace chunks hand code cache ]
@ -63,30 +67,40 @@ public class TestVerifyBeforeAndAfterGCFlags {
"-XX:-DisplayVMOutput",
"VerifyBeforeGC",
"VerifyAfterGC" });
testVerifyFlags(false, false, filteredOpts);
testVerifyFlags(true, true, filteredOpts);
testVerifyFlags(true, false, filteredOpts);
testVerifyFlags(false, true, filteredOpts);
// Young GC
testVerifyFlags(false, false, false, filteredOpts);
testVerifyFlags(true, true, false, filteredOpts);
testVerifyFlags(true, false, false, filteredOpts);
testVerifyFlags(false, true, false, filteredOpts);
// Full GC
testVerifyFlags(false, false, true, filteredOpts);
testVerifyFlags(true, true, true, filteredOpts);
testVerifyFlags(true, false, true, filteredOpts);
testVerifyFlags(false, true, true, filteredOpts);
}
public static void testVerifyFlags(boolean verifyBeforeGC,
boolean verifyAfterGC,
boolean doFullGC,
String[] opts) throws Exception {
ArrayList<String> vmOpts = new ArrayList<>();
if (opts != null && (opts.length > 0)) {
Collections.addAll(vmOpts, opts);
}
Collections.addAll(vmOpts, new String[] {
"-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-Xlog:gc+verify=debug",
"-Xmx5m",
"-Xms5m",
"-Xmn3m",
"-XX:+UnlockDiagnosticVMOptions",
(verifyBeforeGC ? "-XX:+VerifyBeforeGC"
: "-XX:-VerifyBeforeGC"),
(verifyAfterGC ? "-XX:+VerifyAfterGC"
: "-XX:-VerifyAfterGC"),
GarbageProducer.class.getName() });
GarbageProducer.class.getName(),
doFullGC ? "t" : "f" });
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(vmOpts);
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
@ -111,10 +125,12 @@ public class TestVerifyBeforeAndAfterGCFlags {
static long[][] garbage = new long[10][];
public static void main(String args[]) {
int j = 0;
for(int i = 0; i<1000; i++) {
garbage[j] = new long[10000];
j = (j+1)%garbage.length;
WhiteBox wb = WhiteBox.getWhiteBox();
if (args[0].equals("t")) {
wb.fullGC();
} else {
wb.youngGC();
}
}
}