diff --git a/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java b/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java index f8c77f7708edfae7ac7204e5e3124a5dcb43e120..b8bcd7e140ccf315b8b6a0d5b41eec49a21e1699 100644 --- a/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java +++ b/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java @@ -48,7 +48,7 @@ public class CollectionUsageThreshold { private static Map result = new HashMap<>(); private static boolean trace = false; private static boolean testFailed = false; - private static final int EXPECTED_NUM_POOLS = 2; + private static int numMemoryPools = 1; private static final int NUM_GCS = 3; private static final int THRESHOLD = 10; private static Checker checker; @@ -129,14 +129,19 @@ public class CollectionUsageThreshold { for (MemoryPoolMXBean p : pools) { MemoryUsage u = p.getUsage(); if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) { + if (p.getName().toLowerCase().contains("perm")) { + // if we have a "perm gen" pool increase the number of expected + // memory pools by one. + numMemoryPools++; + } PoolRecord pr = new PoolRecord(p); result.put(p.getName(), pr); - if (result.size() == EXPECTED_NUM_POOLS) { + if (result.size() == numMemoryPools) { break; } } } - if (result.size() != EXPECTED_NUM_POOLS) { + if (result.size() != numMemoryPools) { throw new RuntimeException("Unexpected number of selected pools"); } @@ -209,7 +214,7 @@ public class CollectionUsageThreshold { public void run() { while (true) { try { - signals.acquire(EXPECTED_NUM_POOLS); + signals.acquire(numMemoryPools); checkResult(); } catch (InterruptedException e) { throw new RuntimeException(e); diff --git a/test/java/lang/management/MemoryMXBean/MemoryTest.java b/test/java/lang/management/MemoryMXBean/MemoryTest.java index b2cf9e2f69c6d27ca74821681c0e301b7443a1df..ae84e832ad32f417c972d0266108ce4fc084ff3f 100644 --- a/test/java/lang/management/MemoryMXBean/MemoryTest.java +++ b/test/java/lang/management/MemoryMXBean/MemoryTest.java @@ -58,8 +58,11 @@ public class MemoryTest { // They are: Copy/Scavenger + MSC + CodeCache manager // (or equivalent for other collectors) // Number of GC memory managers = 2 - private static int[] expectedMinNumPools = {3, 2}; - private static int[] expectedMaxNumPools = {3, 4}; + + // Hotspot VM 1.8+ after perm gen removal is expected to have only + // one non-heap memory pool + private static int[] expectedMinNumPools = {3, 1}; + private static int[] expectedMaxNumPools = {3, 1}; private static int expectedNumGCMgrs = 2; private static int expectedNumMgrs = expectedNumGCMgrs + 1; private static String[] types = { "heap", "non-heap" }; @@ -80,6 +83,7 @@ public class MemoryTest { private static void checkMemoryPools() throws Exception { List pools = ManagementFactory.getMemoryPoolMXBeans(); + boolean hasPerm = false; int[] numPools = new int[NUM_TYPES]; for (ListIterator iter = pools.listIterator(); iter.hasNext();) { @@ -90,6 +94,16 @@ public class MemoryTest { if (pool.getType() == MemoryType.NON_HEAP) { numPools[NONHEAP]++; } + if (pool.getName().toLowerCase().contains("perm")) { + hasPerm = true; + } + } + + if (hasPerm) { + // If the VM has perm gen there will be between 2 and 4 non heap + // pools (4 if class data sharing is used) + expectedMinNumPools[NONHEAP] = 2; + expectedMaxNumPools[NONHEAP] = 4; } // Check the number of Memory pools