Skip to content
Permalink
Browse files
8270991: G1 Full GC always performs heap verification after JDK-8269295
Reviewed-by: iwalulya, kbarrett
  • Loading branch information
Thomas Schatzl committed Jul 21, 2021
1 parent cd8783c commit 57611b30219191160f7faccb811b41a31c25c0b8
Showing 2 changed files with 33 additions and 11 deletions.
@@ -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 @@
* @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.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 static void main(String args[]) throws Exception {
"-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 static class GarbageProducer {
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();
}
}
}

1 comment on commit 57611b3

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 57611b3 Jul 21, 2021

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.