--- old/test/jdk/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java 2018-10-08 18:33:48.000000000 -0400 +++ new/test/jdk/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java 2018-10-08 18:33:47.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 { @@ -83,10 +87,16 @@ // 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()) { + if (!p.getName().equals("G1 Old Space")) { + // With G1, humongous objects are tracked in the old space + // only in legacy monitoring mode. In normal mode, G1 tracks + // humongous objects in the humongous space, which latter also + // supports a usage threshold, and will thus by tested instead + // of the old space. + found = true; + testPool(p); + } } } if (!found) { @@ -131,13 +141,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(); }