< prev index next >

test/jdk/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java

Print this page

        

*** 46,55 **** --- 46,56 ---- import java.lang.management.*; import java.lang.ref.WeakReference; import java.util.*; import sun.hotspot.code.Compiler; + import sun.hotspot.WhiteBox; public class ResetPeakMemoryUsage { private static MemoryMXBean mbean = ManagementFactory.getMemoryMXBean(); // make public so that it can't be optimized away easily public static Object[] obj;
*** 65,75 **** final String mn = "-Xmn8m"; if (!Compiler.isGraalEnabled()) { // Graal does not support CMS 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:+UseSerialGC", "-XX:MarkSweepAlwaysCompactCount=1"); } private static class TestMain { --- 66,79 ---- final String mn = "-Xmn8m"; if (!Compiler.isGraalEnabled()) { // Graal does not support CMS RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseConcMarkSweepGC"); } RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseParallelGC"); ! 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"); } private static class TestMain {
*** 77,96 **** List pools = ManagementFactory.getMemoryPoolMXBeans(); ListIterator iter = pools.listIterator(); 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 if (p.getType() == MemoryType.HEAP && ! p.isUsageThresholdSupported()) ! { found = true; testPool(p); } } if (!found) { throw new RuntimeException("No heap pool found"); } } } --- 81,115 ---- List pools = ManagementFactory.getMemoryPoolMXBeans(); ListIterator iter = pools.listIterator(); boolean found = false; while (iter.hasNext()) { MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next(); ! // 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()) { ! // 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) { throw new RuntimeException("No heap pool found"); } } }
*** 129,145 **** formatSize("Before allocation: peak", peak0.getUsed()) + " expected to be < " + formatSize("After allocation: peak", peak1.getUsed())); } ! ! // 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) { mbean.gc(); } MemoryUsage usage2 = mpool.getUsage(); MemoryUsage peak2 = mpool.getPeakUsage(); --- 148,162 ---- formatSize("Before allocation: peak", peak0.getUsed()) + " expected to be < " + formatSize("After allocation: peak", peak1.getUsed())); } ! // The object is now garbage and do a GC. Memory usage should drop. obj = null; ! // This will cause a sure shot GC unlike Runtime.gc() invoked by mbean.gc() ! while (weakRef.get() != null) { mbean.gc(); } MemoryUsage usage2 = mpool.getUsage(); MemoryUsage peak2 = mpool.getPeakUsage();
< prev index next >