# HG changeset patch # User tschatzl # Parent 747213d1b6b8590b7be1852949f16130a54d251c diff -r 747213d1b6b8 src/hotspot/share/prims/whitebox.cpp --- a/src/hotspot/share/prims/whitebox.cpp Mon Jul 20 16:08:23 2020 +0200 +++ b/src/hotspot/share/prims/whitebox.cpp Mon Jul 20 17:00:00 2020 +0200 @@ -398,6 +398,10 @@ return (jlong)HeapAlignment; WB_END +WB_ENTRY(jlong, WB_GetMillisSinceLastWholeHeapExamined(JNIEnv* env, jobject o)) + return Universe::heap()->millis_since_last_whole_heap_examined(); +WB_END + WB_ENTRY(jboolean, WB_SupportsConcurrentGCBreakpoints(JNIEnv* env, jobject o)) return Universe::heap()->supports_concurrent_gc_breakpoints(); WB_END @@ -2295,6 +2299,7 @@ {CC"getVMLargePageSize", CC"()J", (void*)&WB_GetVMLargePageSize}, {CC"getHeapSpaceAlignment", CC"()J", (void*)&WB_GetHeapSpaceAlignment}, {CC"getHeapAlignment", CC"()J", (void*)&WB_GetHeapAlignment}, + {CC"getMillisSinceWholeHeapExamined", CC"()J", (void*)&WB_GetMillisSinceLastWholeHeapExamined }, {CC"countAliveClasses0", CC"(Ljava/lang/String;)I", (void*)&WB_CountAliveClasses }, {CC"getSymbolRefcount", CC"(Ljava/lang/String;)I", (void*)&WB_GetSymbolRefcount }, {CC"parseCommandLine0", diff -r 747213d1b6b8 test/hotspot/jtreg/gc/TestMillisSinceWholeHeapExamined.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/gc/TestMillisSinceWholeHeapExamined.java Mon Jul 20 17:00:00 2020 +0200 @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2020, 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. + */ + +package gc; + +/* + * @test TestMillisSinceWholeHeapExaminedSerial + * @bug 8248221 + * @requires vm.gc.Serial + * @library /test/lib + * @modules java.base/jdk.internal.misc + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseSerialGC gc.TestMillisSinceWholeHeapExamined true true false + * @summary Verifies that sun.rmi.transport.GC.maxObjectInspectionAge updates in the correct situations + */ + +/* + * @test TestMillisSinceWholeHeapExaminedParallel + * @bug 8248221 + * @requires vm.gc.Parallel + * @library /test/lib + * @modules java.base/jdk.internal.misc + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseParallelGC gc.TestMillisSinceWholeHeapExamined true true false + * @summary Verifies that sun.rmi.transport.GC.maxObjectInspectionAge updates in the correct situations + */ + +/* + * @test TestMillisSinceWholeHeapExaminedG1 + * @bug 8248221 + * @requires vm.gc.G1 + * @library /test/lib + * @modules java.base/jdk.internal.misc + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseG1GC gc.TestMillisSinceWholeHeapExamined true true true + * @summary Verifies that sun.rmi.transport.GC.maxObjectInspectionAge updates in the correct situations + */ + +/* + * @test TestMillisSinceWholeHeapExaminedZ + * @bug 8248221 + * @requires vm.gc.Z + * @library /test/lib + * @modules java.base/jdk.internal.misc + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseZGC gc.TestMillisSinceWholeHeapExamined false true false + * @summary Verifies that sun.rmi.transport.GC.maxObjectInspectionAge updates in the correct situations + */ + +/* + * @test TestMillisSinceWholeHeapExaminedShenandoah + * @bug 8248221 + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseShenandoahGC gc.TestMillisSinceWholeHeapExamined false true false + * @summary Verifies that sun.rmi.transport.GC.maxObjectInspectionAge updates in the correct situations + */ + +import static jdk.test.lib.Asserts.assertTrue; +import sun.hotspot.WhiteBox; + +public class TestMillisSinceWholeHeapExamined { + private static int Delay = 100; + + private static void waitABit() throws Exception { + Thread.sleep(Delay); + } + + private static void testYoungGC() throws Exception { + WhiteBox wb = WhiteBox.getWhiteBox(); + long initial = wb.getMillisSinceWholeHeapExamined(); + waitABit(); + wb.youngGC(); + long current = wb.getMillisSinceWholeHeapExamined(); + System.out.println("young: initial " + initial + " current " + current); + assertTrue(current >= Delay); // GC should not update. + } + + private static void testFullGC() throws Exception { + WhiteBox wb = WhiteBox.getWhiteBox(); + long initial = wb.getMillisSinceWholeHeapExamined(); + waitABit(); + wb.fullGC(); + long current = wb.getMillisSinceWholeHeapExamined(); + System.out.println("full: initial " + initial + " current " + current); + assertTrue(wb.getMillisSinceWholeHeapExamined() < Delay); // GC must update. + } + + private static void testConcurrentFullGC() throws Exception { + WhiteBox wb = WhiteBox.getWhiteBox(); + long initial = wb.getMillisSinceWholeHeapExamined(); + waitABit(); + assertTrue(wb.g1StartConcMarkCycle()); + while (wb.g1InConcurrentMark()) { + Thread.sleep(5); + } + long current = wb.getMillisSinceWholeHeapExamined(); + System.out.println("concfull: initial " + initial + " current " + current); + assertTrue(current < Delay); // GC must update. + } + + public static void main(String[] args) throws Exception { + WhiteBox wb = WhiteBox.getWhiteBox(); + // Clean out old any remaining objects in young gen to avoid extra GCs. + wb.fullGC(); + + if (args[0].equals("true")) { + testYoungGC(); + } + + if (args[1].equals("true")) { + testFullGC(); + } + + if (args[2].equals("true")) { + testConcurrentFullGC(); + } + } +} diff -r 747213d1b6b8 test/lib/sun/hotspot/WhiteBox.java --- a/test/lib/sun/hotspot/WhiteBox.java Mon Jul 20 16:08:23 2020 +0200 +++ b/test/lib/sun/hotspot/WhiteBox.java Mon Jul 20 17:00:00 2020 +0200 @@ -84,6 +84,7 @@ public native long getVMLargePageSize(); public native long getHeapSpaceAlignment(); public native long getHeapAlignment(); + public native long getMillisSinceWholeHeapExamined(); private native boolean isObjectInOldGen0(Object o); public boolean isObjectInOldGen(Object o) {