test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java
Print this page
rev 5700 : 7195557: NPG: Unexpected number of memory pools
Summary: Update management tests to work with a VM without a permanent generation memory pool
Reviewed-by:
*** 46,56 ****
private static List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
private static List<MemoryManagerMXBean> managers = ManagementFactory.getMemoryManagerMXBeans();
private static Map<String, PoolRecord> result = new HashMap<>();
private static boolean trace = false;
private static boolean testFailed = false;
! private static final int EXPECTED_NUM_POOLS = 2;
private static final int NUM_GCS = 3;
private static final int THRESHOLD = 10;
private static Checker checker;
private static int numGCs = 0;
--- 46,56 ----
private static List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
private static List<MemoryManagerMXBean> managers = ManagementFactory.getMemoryManagerMXBeans();
private static Map<String, PoolRecord> result = new HashMap<>();
private static boolean trace = false;
private static boolean testFailed = false;
! private static int numMemoryPools = 1;
private static final int NUM_GCS = 3;
private static final int THRESHOLD = 10;
private static Checker checker;
private static int numGCs = 0;
*** 127,144 ****
// Find the Old generation which supports low memory detection
for (MemoryPoolMXBean p : pools) {
MemoryUsage u = p.getUsage();
if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) {
PoolRecord pr = new PoolRecord(p);
result.put(p.getName(), pr);
! if (result.size() == EXPECTED_NUM_POOLS) {
break;
}
}
}
! if (result.size() != EXPECTED_NUM_POOLS) {
throw new RuntimeException("Unexpected number of selected pools");
}
try {
// This test creates a checker thread responsible for checking
--- 127,149 ----
// Find the Old generation which supports low memory detection
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() == numMemoryPools) {
break;
}
}
}
! if (result.size() != numMemoryPools) {
throw new RuntimeException("Unexpected number of selected pools");
}
try {
// This test creates a checker thread responsible for checking
*** 207,217 ****
super(name);
};
public void run() {
while (true) {
try {
! signals.acquire(EXPECTED_NUM_POOLS);
checkResult();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (BrokenBarrierException e) {
throw new RuntimeException(e);
--- 212,222 ----
super(name);
};
public void run() {
while (true) {
try {
! signals.acquire(numMemoryPools);
checkResult();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (BrokenBarrierException e) {
throw new RuntimeException(e);