changeset 26459:fa5576f930e6

8057174: MemoryMXBean tests -- TEST FAILED: chunkSize: 6291456 is less than YOUNG_GEN_SIZE: 8388608 Reviewed-by: jbachorik, jwilhelm, dfuchs
author stefank
date Thu, 04 Sep 2014 13:20:27 +0200
parents d6a5aed9204b
children 68a3e0abedfd
files jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java jdk/test/java/lang/management/MemoryMXBean/MemoryManagement.java
diffstat 2 files changed, 37 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java	Tue Sep 09 19:02:36 2014 +0400
+++ b/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java	Thu Sep 04 13:20:27 2014 +0200
@@ -63,11 +63,16 @@
         // 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");
+        // Using large pages will change the young gen size,
+        // make sure we don't use them for this test.
+        final String lpFlag = "-XX:-UseLargePages";
+        // Prevent G1 from selecting a large heap region size,
+        // since that would change the young gen size.
+        final String g1Flag = "-XX:G1HeapRegionSize=1m";
+        RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseSerialGC");
+        RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseParallelGC");
+        RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag);
+        RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC");
     }
 
     private static volatile boolean listenerInvoked = false;
@@ -155,19 +160,23 @@
             Thread allocator = new AllocatorThread();
             Thread sweeper = new SweeperThread();
 
-            // Now set threshold
+            // The chunk size needs to be larger than YOUNG_GEN_SIZE,
+            // otherwise we will get intermittent failures when objects
+            // end up in the young gen instead of the old gen.
+            final long epsilon = 1024;
+            chunkSize = YOUNG_GEN_SIZE + epsilon;
+
             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.
+            // Sanity check. Make sure the new threshold isn't too large.
             // 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);
+            final long headRoom = chunkSize * 2;
+            final long max = mu.getMax();
+            if (max != -1 && newThreshold > max - headRoom) {
+                throw new RuntimeException("TEST FAILED: newThreshold: " + newThreshold +
+                        " is too near the maximum old gen size: " + max +
+                        " used: " + mu.getUsed() + " headRoom: " + headRoom);
             }
 
             System.out.println("Setting threshold for " + mpool.getName() +
--- a/jdk/test/java/lang/management/MemoryMXBean/MemoryManagement.java	Tue Sep 09 19:02:36 2014 +0400
+++ b/jdk/test/java/lang/management/MemoryMXBean/MemoryManagement.java	Thu Sep 04 13:20:27 2014 +0200
@@ -31,7 +31,7 @@
  * @author  Mandy Chung
  *
  * @build MemoryManagement MemoryUtil
- * @run main/othervm/timeout=600 -Xmn8m MemoryManagement
+ * @run main/othervm/timeout=600 -Xmn8m -XX:+IgnoreUnrecognizedVMOptions -XX:G1HeapRegionSize=1 -XX:-UseLargePages MemoryManagement
  */
 
 import java.lang.management.*;
@@ -103,25 +103,24 @@
 
         Thread allocator = new AllocatorThread();
 
+        // The chunk size needs to be larger than YOUNG_GEN_SIZE,
+        // otherwise we will get intermittent failures when objects
+        // end up in the young gen instead of the old gen.
+        final long epsilon = 1024;
+        chunkSize = YOUNG_GEN_SIZE + epsilon;
+
         // Now set threshold
         MemoryUsage mu = mpool.getUsage();
-        long max = mu.getMax();
-        if (max != -1) {
-            chunkSize = (max - mu.getUsed()) / 20;
-        } else { // 6980984
-            System.gc();
-            chunkSize = Runtime.getRuntime().freeMemory()/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.
+        // Sanity check. Make sure the new threshold isn't too large.
         // 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);
+        final long headRoom = chunkSize * 2;
+        final long max = mu.getMax();
+        if (max != -1 && newThreshold > max - headRoom) {
+            throw new RuntimeException("TEST FAILED: newThreshold: " + newThreshold +
+                    " is too near the maximum old gen size: " + max +
+                    " used: " + mu.getUsed() + " headRoom: " + headRoom);
         }
 
         System.out.println("Setting threshold for " + mpool.getName() +