--- old/test/jdk/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java 2018-10-18 18:02:21.000000000 -0400 +++ new/test/jdk/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java 2018-10-18 18:02:21.000000000 -0400 @@ -48,6 +48,7 @@ import java.util.*; import sun.hotspot.code.Compiler; +import sun.hotspot.WhiteBox; public class ResetPeakMemoryUsage { private static MemoryMXBean mbean = ManagementFactory.getMemoryMXBean(); @@ -67,9 +68,12 @@ RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseConcMarkSweepGC"); } RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseParallelGC"); - RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseG1GC", "-XX:G1HeapRegionSize=1m"); + RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseG1GC", "-XX:-G1UseLegacyMonitoring", + "-XX:G1HeapRegionSize=1m"); + RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseG1GC", "-XX:+G1UseLegacyMonitoring", + "-XX:G1HeapRegionSize=1m"); RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseSerialGC", - "-XX:MarkSweepAlwaysCompactCount=1"); + "-XX:MarkSweepAlwaysCompactCount=1"); } private static class TestMain { @@ -79,14 +83,29 @@ boolean found = false; while (iter.hasNext()) { MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next(); - // only check heap pools that support usage threshold - // this is typically only the old generation space - // since the other spaces are expected to get filled up + // Only check heap pools that support a usage threshold. + // This is typically only the old generation space + // since the other spaces are expected to get filled up. if (p.getType() == MemoryType.HEAP && - p.isUsageThresholdSupported()) - { - found = true; - testPool(p); + p.isUsageThresholdSupported()) { + // In all collectors except G1, only the old generation supports a + // usage threshold. The G1 legacy mode "G1 Old Gen" also does. In + // G1 default mode, both the old space ("G1 Old Space": it's not + // really a generation in the non-G1 collector sense) and the + // humongous space ("G1 Humongous Space"), support a usage threshold. + // So, the following condition is true for all non-G1 old generations, + // for the G1 legacy old gen, and for the G1 default humongous space. + // It is not true for the G1 default old gen. + // + // We're allocating humongous objects in this test, so the G1 default + // mode "G1 Old Space" occupancy doesn't change, because humongous + // objects are allocated in the "G1 Humongous Space". If we allowed + // the G1 default mode "G1 Old Space", notification would never + // happen because no objects are allocated there. + if (!p.getName().equals("G1 Old Space")) { + found = true; + testPool(p); + } } } if (!found) { @@ -131,13 +150,11 @@ formatSize("After allocation: peak", peak1.getUsed())); } - - // The object is now garbage and do a GC - // memory usage should drop + // The object is now garbage and do a GC. Memory usage should drop. obj = null; - //This will cause sure shot GC unlike Runtime.gc() invoked by mbean.gc() - while(weakRef.get() != null) { + // This will cause a sure shot GC unlike Runtime.gc() invoked by mbean.gc() + while (weakRef.get() != null) { mbean.gc(); }