< prev index next >
test/jdk/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java
Print this page
@@ -46,10 +46,11 @@
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,11 +66,14 @@
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:+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 {
@@ -81,16 +85,22 @@
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())
- {
+ 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) {
throw new RuntimeException("No heap pool found");
}
}
}
@@ -129,17 +139,15 @@
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
+ // 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();
}
MemoryUsage usage2 = mpool.getUsage();
MemoryUsage peak2 = mpool.getPeakUsage();
< prev index next >