< 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 {
*** 81,96 ****
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");
}
}
}
--- 85,106 ----
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()) {
! 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,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();
--- 139,153 ----
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 >