test/java/lang/management/MemoryMXBean/LowMemoryTest.java

Print this page
rev 10476 : 8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64

*** 48,71 **** private static MemoryPoolMXBean mpool = null; private static boolean trace = false; private static boolean testFailed = false; private static final int NUM_TRIGGERS = 5; private static final int NUM_CHUNKS = 2; private static long chunkSize; /** * Run the test multiple times with different GC versions. * First with default command line specified by the framework. * Then with GC versions specified by the test. */ public static void main(String a[]) throws Throwable { final String main = "LowMemoryTest$TestMain"; ! RunUtil.runTestKeepGcOpts(main); ! RunUtil.runTestClearGcOpts(main, "-XX:+UseSerialGC"); ! RunUtil.runTestClearGcOpts(main, "-XX:+UseParallelGC"); ! RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC"); ! RunUtil.runTestClearGcOpts(main, "-XX:+UseConcMarkSweepGC"); } private static volatile boolean listenerInvoked = false; static class SensorListener implements NotificationListener { @Override --- 48,75 ---- private static MemoryPoolMXBean mpool = null; private static boolean trace = false; private static boolean testFailed = false; private static final int NUM_TRIGGERS = 5; private static final int NUM_CHUNKS = 2; + private static final int YOUNG_GEN_SIZE = 8 * 1024 * 1024; private static long chunkSize; /** * Run the test multiple times with different GC versions. * First with default command line specified by the framework. * Then with GC versions specified by the test. */ public static void main(String a[]) throws Throwable { final String main = "LowMemoryTest$TestMain"; ! // Use a low young gen size to ensure that the ! // allocated objects are put in the old gen. ! final String nmFlag = "-Xmn" + YOUNG_GEN_SIZE; ! RunUtil.runTestKeepGcOpts(main, nmFlag); ! RunUtil.runTestClearGcOpts(main, nmFlag, "-XX:+UseSerialGC"); ! RunUtil.runTestClearGcOpts(main, nmFlag, "-XX:+UseParallelGC"); ! RunUtil.runTestClearGcOpts(main, nmFlag, "-XX:+UseG1GC"); ! RunUtil.runTestClearGcOpts(main, nmFlag, "-XX:+UseConcMarkSweepGC"); } private static volatile boolean listenerInvoked = false; static class SensorListener implements NotificationListener { @Override
*** 154,163 **** --- 158,177 ---- // Now set threshold MemoryUsage mu = mpool.getUsage(); chunkSize = (mu.getMax() - mu.getUsed()) / 20; newThreshold = mu.getUsed() + (chunkSize * NUM_CHUNKS); + // Sanity check. Make sure the chunkSize is large than the YOUNG_GEN_SIZE + // If the chunkSize are lower than the YOUNG_GEN_SIZE, we will get intermittent + // failures when objects end up in the young gen instead of the old gen. + // Tweak the test if this fails. + if (chunkSize < YOUNG_GEN_SIZE) { + throw new RuntimeException("TEST FAILED: " + + " chunkSize: " + chunkSize + " is less than YOUNG_GEN_SIZE: " + YOUNG_GEN_SIZE + + " max: " + mu.getMax() + " used: " + mu.getUsed() + " newThreshold: " + newThreshold); + } + System.out.println("Setting threshold for " + mpool.getName() + " from " + mpool.getUsageThreshold() + " to " + newThreshold + ". Current used = " + mu.getUsed()); mpool.setUsageThreshold(newThreshold);