8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
authorstefank
Tue, 19 Aug 2014 12:18:09 +0200
changeset 25999 1e494b91a5a5
parent 25998 3efc2a6b082a
child 26038 ddbc61761999
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64 Reviewed-by: sla, brutisso, mgerdin
jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java
jdk/test/java/lang/management/MemoryMXBean/MemoryManagement.java
--- a/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java	Tue Aug 19 17:11:28 2014 +0200
+++ b/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java	Tue Aug 19 12:18:09 2014 +0200
@@ -50,6 +50,7 @@
     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;
 
     /**
@@ -59,11 +60,14 @@
      */
     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");
+        // 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;
@@ -156,6 +160,16 @@
             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());
--- a/jdk/test/java/lang/management/MemoryMXBean/MemoryManagement.java	Tue Aug 19 17:11:28 2014 +0200
+++ b/jdk/test/java/lang/management/MemoryMXBean/MemoryManagement.java	Tue Aug 19 12:18:09 2014 +0200
@@ -31,7 +31,7 @@
  * @author  Mandy Chung
  *
  * @build MemoryManagement MemoryUtil
- * @run main/othervm/timeout=600 MemoryManagement
+ * @run main/othervm/timeout=600 -Xmn8m MemoryManagement
  */
 
 import java.lang.management.*;
@@ -49,6 +49,8 @@
     private static volatile boolean trace = false;
     private static volatile boolean testFailed = false;
     private static final int NUM_CHUNKS = 2;
+    // Must match -Xmn set on the @run line
+    private static final int YOUNG_GEN_SIZE = 8 * 1024 * 1024;
     private static volatile long chunkSize;
     private static volatile int listenerInvoked = 0;
 
@@ -112,6 +114,16 @@
         }
         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());