< prev index next >

test/hotspot/jtreg/gc/g1/mixedgc/TestOldGenCollectionUsage.java

Print this page

        

@@ -31,11 +31,12 @@
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
  * @modules java.management
  * @build sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
- * @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -verbose:gc -XX:SurvivorRatio=1 -Xmx14m -Xms14m -XX:MaxTenuringThreshold=1 -XX:InitiatingHeapOccupancyPercent=100 -XX:-G1UseAdaptiveIHOP -XX:G1MixedGCCountTarget=4 -XX:MaxGCPauseMillis=30000 -XX:G1HeapRegionSize=1m -XX:G1HeapWastePercent=0 -XX:G1MixedGCLiveThresholdPercent=100 TestOldGenCollectionUsage
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:-G1UseLegacyMonitoring -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -verbose:gc -XX:SurvivorRatio=1 -Xmx12m -Xms12m -XX:MaxTenuringThreshold=1 -XX:InitiatingHeapOccupancyPercent=100 -XX:-G1UseAdaptiveIHOP -XX:G1MixedGCCountTarget=4 -XX:MaxGCPauseMillis=30000 -XX:G1HeapRegionSize=1m -XX:G1HeapWastePercent=0 -XX:G1MixedGCLiveThresholdPercent=100 TestOldGenCollectionUsage
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+G1UseLegacyMonitoring -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -verbose:gc -XX:SurvivorRatio=1 -Xmx12m -Xms12m -XX:MaxTenuringThreshold=1 -XX:InitiatingHeapOccupancyPercent=100 -XX:-G1UseAdaptiveIHOP -XX:G1MixedGCCountTarget=4 -XX:MaxGCPauseMillis=30000 -XX:G1HeapRegionSize=1m -XX:G1HeapWastePercent=0 -XX:G1MixedGCLiveThresholdPercent=100 TestOldGenCollectionUsage
  */
 
 import jdk.test.lib.Asserts;
 import sun.hotspot.WhiteBox;
 

@@ -48,24 +49,38 @@
 // 8195115 says that for the "G1 Old Gen" MemoryPool, CollectionUsage.used
 // is zero for G1 after a mixed collection, which is incorrect.
 
 public class TestOldGenCollectionUsage {
 
-    private String poolName = "G1 Old Gen";
-    private String collectorName = "G1 Young Generation";
+    private String poolName;
+    private String youngCollectorName;
+    private String mixedCollectorName;
+    private boolean useLegacyMonitoring;
 
     public static void main(String [] args) throws Exception {
         TestOldGenCollectionUsage t = new TestOldGenCollectionUsage();
         t.run();
     }
 
     public TestOldGenCollectionUsage() {
-        System.out.println("Monitor G1 Old Gen pool with G1 Young Generation collector.");
+        useLegacyMonitoring = LegacyMonitoring.use();
+        poolName = useLegacyMonitoring ? "G1 Old Gen" : "G1 Old Space";
+        youngCollectorName = useLegacyMonitoring ? "G1 Young Generation" : "G1 Young";
+        mixedCollectorName = useLegacyMonitoring ? "G1 Young Generation" : "G1 Mixed";
+        System.out.println("Monitor G1 Old Gen pool with " + mixedCollectorName + " collector.");
+    }
+
+    public static class LegacyMonitoring {
+        private static final boolean useLegacyMonitoring = getUseLegacyMonitoring();
+        private static boolean getUseLegacyMonitoring() {
+            return ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-XX:+G1UseLegacyMonitoring");
+        }
+        public static boolean use() { return useLegacyMonitoring; }
     }
 
     public void run() {
-        // Find memory pool and collector
+        // Find old space memory pool and collectors
         List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
         MemoryPoolMXBean pool = null;
         boolean foundPool = false;
         for (int i = 0; i < pools.size(); i++) {
             pool = pools.get(i);

@@ -79,68 +94,81 @@
         if (!foundPool) {
             throw new RuntimeException(poolName + " not found, test with -XX:+UseG1GC");
         }
 
         List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans();
-        GarbageCollectorMXBean collector = null;
-        boolean foundCollector = false;
+        GarbageCollectorMXBean youngCollector = null;
+        GarbageCollectorMXBean mixedCollector = null;
         for (int i = 0; i < collectors.size(); i++) {
-            collector = collectors.get(i);
+            GarbageCollectorMXBean collector = collectors.get(i);
             String name = collector.getName();
-            if (name.contains(collectorName)) {
-                System.out.println("Found collector: " + name);
-                foundCollector = true;
-                break;
+            if (name.equals(youngCollectorName)) {
+                System.out.println("Found young collector: " + name);
+                youngCollector = collector;
             }
+            if (name.equals(mixedCollectorName)) {
+                System.out.println("Found mixed collector: " + name);
+                mixedCollector = collector;
         }
-        if (!foundCollector) {
-            throw new RuntimeException(collectorName + " not found, test with -XX:+UseG1GC");
+        }
+        if (youngCollector == null) {
+            throw new RuntimeException(youngCollectorName + " not found, test with -XX:+UseG1GC");
+        }
+        if (mixedCollector == null) {
+            throw new RuntimeException(mixedCollectorName + " not found, test with -XX:+UseG1GC");
         }
 
         MixedGCProvoker gcProvoker = new MixedGCProvoker();
         gcProvoker.allocateOldObjects();
 
-        // Verify no non-zero result was stored
+        // Verify no non-zero result was stored for the pool
         long usage = pool.getCollectionUsage().getUsed();
         System.out.println(poolName + ": usage after GC = " + usage);
         if (usage > 0) {
             throw new RuntimeException("Premature mixed collections(s)");
         }
 
-        // Verify that collections were done
-        long collectionCount = collector.getCollectionCount();
-        System.out.println(collectorName + ": collection count = "
-                           + collectionCount);
-        long collectionTime = collector.getCollectionTime();
-        System.out.println(collectorName + ": collection time  = "
-                           + collectionTime);
-        if (collectionCount <= 0) {
-            throw new RuntimeException("Collection count <= 0");
+        // Verify that young collections were done
+        long youngCollectionCount = youngCollector.getCollectionCount();
+        System.out.println(youngCollectorName + ": collection count = "
+                           + youngCollectionCount);
+        long youngCollectionTime = youngCollector.getCollectionTime();
+        System.out.println(youngCollectorName + ": collection time  = "
+                           + youngCollectionTime);
+        if (youngCollectionCount <= 0) {
+            throw new RuntimeException("Young collection count <= 0");
         }
-        if (collectionTime <= 0) {
-            throw new RuntimeException("Collector has not run");
+        if (youngCollectionTime <= 0) {
+            throw new RuntimeException("Young collector did not run");
         }
 
+        // Force promotion
         gcProvoker.provokeMixedGC();
 
         usage = pool.getCollectionUsage().getUsed();
         System.out.println(poolName + ": usage after GC = " + usage);
         if (usage <= 0) {
             throw new RuntimeException(poolName + " found with zero usage");
         }
 
-        long newCollectionCount = collector.getCollectionCount();
-        System.out.println(collectorName + ": collection count = "
+        long newCollectionCount = mixedCollector.getCollectionCount();
+        System.out.println(mixedCollectorName + ": collection count = "
                            + newCollectionCount);
-        long newCollectionTime = collector.getCollectionTime();
-        System.out.println(collectorName + ": collection time  = "
+        long newCollectionTime = mixedCollector.getCollectionTime();
+        System.out.println(mixedCollectorName + ": collection time  = "
                            + newCollectionTime);
-        if (newCollectionCount <= collectionCount) {
+        if (useLegacyMonitoring) {
+            if (newCollectionCount <= youngCollectionCount) {
             throw new RuntimeException("No new collection");
         }
-        if (newCollectionTime <= collectionTime) {
-            throw new RuntimeException("Collector has not run some more");
+        } else {
+            if (newCollectionCount <= 0) {
+                throw new RuntimeException("Mixed collection count <= 0");
+            }
+            if (newCollectionTime <= 0) {
+                throw new RuntimeException("Mixed collector did not run");
+            }
         }
 
         System.out.println("Test passed.");
     }
 
< prev index next >