< prev index next >

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

Print this page

        

@@ -81,13 +81,17 @@
         final String g1Flag = "-XX:G1HeapRegionSize=1m";
 
         // Runs the test collecting subprocess I/O while it's running.
         traceTest(classMain + ", -XX:+UseSerialGC", nmFlag, lpFlag, "-XX:+UseSerialGC");
         traceTest(classMain + ", -XX:+UseParallelGC", nmFlag, lpFlag, "-XX:+UseParallelGC");
-        traceTest(classMain + ", -XX:+UseG1GC", nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag);
+        traceTest(classMain + ", -XX:+UseG1GC -XX:-G1UseLegacyMonitoring", nmFlag, lpFlag,
+                  "-XX:+UseG1GC", "-XX:-G1UseLegacyMonitoring", g1Flag);
+        traceTest(classMain + ", -XX:+UseG1GC -XX:+G1UseLegacyMonitoring", nmFlag, lpFlag,
+                  "-XX:+UseG1GC", "-XX:+G1UseLegacyMonitoring", g1Flag);
         if (!Compiler.isGraalEnabled()) { // Graal does not support CMS
-            traceTest(classMain + ", -XX:+UseConcMarkSweepGC", nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC");
+             traceTest(classMain + ", -XX:+UseConcMarkSweepGC", nmFlag, lpFlag,
+                       "-XX:+UseConcMarkSweepGC");
         }
     }
 
     /*
      * Creating command-line for running subprocess JVM:

@@ -232,19 +236,33 @@
             ListIterator iter = pools.listIterator();
             while (iter.hasNext()) {
                 MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
                 if (p.getType() == MemoryType.HEAP &&
                     p.isUsageThresholdSupported()) {
+                    if (!p.getName().equals("G1 Old Space")) {
+                        // In G1, humongous objects are tracked in the old space only in
+                        // legacy monitoring mode. In default mode, G1 tracks humongous
+                        // objects in the humongous space, which latter also supports a
+                        // usage threshold. Since we're allocating humongous objects in
+                        // this test, in default mode the old space doesn't change. For
+                        // this test, we use the old space in legacy mode (it's called
+                        // "G1 Old Gen" and the humongous space in default mode. If we
+                        // used "G1 Old Space" in default mode, notification would never
+                        // happen.
                     mpool = p;
                     if (trace) {
                         System.out.println("Selected memory pool for low memory " +
                             "detection.");
                         MemoryUtil.printMemoryPool(mpool);
                     }
                     break;
                 }
             }
+            }
+            if (mpool == null) {
+                throw new RuntimeException("TEST FAILED: No heap pool found");
+            }
 
             TestListener listener = new TestListener();
             SensorListener l2 = new SensorListener();
             NotificationEmitter emitter = (NotificationEmitter) mm;
             emitter.addNotificationListener(listener, null, null);
< prev index next >