< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -80,25 +80,47 @@
         if (trace) {
             MemoryUtil.printMemoryPools(pools);
             MemoryUtil.printMemoryManagers(managers);
         }
 
-        // Find the Old generation which supports low memory detection
+        // Find a pool which which supports low memory detection
         ListIterator iter = pools.listIterator();
         while (iter.hasNext()) {
             MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
+            // Only check heap pools that support a usage threshold.
+            // This is typically only the old generation space
+            // since the other spaces are expected to get filled up.
             if (p.getType() == MemoryType.HEAP &&
                 p.isUsageThresholdSupported()) {
+                // In all collectors except G1, only the old generation supports a
+                // usage threshold. The G1 legacy mode "G1 Old Gen" also does. In
+                // G1 default mode, both the old space ("G1 Old Space": it's not
+                // really a generation in the non-G1 collector sense) and the
+                // humongous space ("G1 Humongous Space"), support a usage threshold.
+                // So, the following condition is true for all non-G1 old generations,
+                // for the G1 legacy old gen, and for the G1 default humongous space.
+                // It is not true for the G1 default old gen.
+                //
+                // We're allocating humongous objects in this test, so the G1 default
+                // mode "G1 Old Space" occupancy doesn't change, because humongous
+                // objects are allocated in the "G1 Humongous Space". If we allowed
+                // the G1 default mode "G1 Old Space", notification would never
+                // happen because no objects are allocated there.
+                if (!p.getName().equals("G1 Old Space")) {
                 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");
+        }
 
         SensorListener listener = new SensorListener();
         NotificationEmitter emitter = (NotificationEmitter) mm;
         emitter.addNotificationListener(listener, null, null);
 
< prev index next >