< prev index next >
test/gc/shenandoah/mxbeans/TestChurnNotifications.java
Print this page
rev 10790 : [backport] Prefix Shenandoah tests with "Test"
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates.
+ * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
*
* 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.
*
@@ -20,51 +20,53 @@
* questions.
*
*/
/*
- * @test ChurnNotifications
+ * @test TestChurnNotifications
* @summary Check that MX notifications are reported for all cycles
+ * @key gc
*
- * @run main/othervm -Xmx128m -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -Dprecise=true ChurnNotifications
- * @run main/othervm -Xmx128m -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -Dprecise=true ChurnNotifications
+ * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -Dprecise=true TestChurnNotifications
+ * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -Dprecise=true TestChurnNotifications
*
- * @run main/othervm -Xmx128m -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=adaptive -Dprecise=false ChurnNotifications
- * @run main/othervm -Xmx128m -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=static -Dprecise=false ChurnNotifications
- * @run main/othervm -Xmx128m -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=compact -Dprecise=false ChurnNotifications
- * @run main/othervm -Xmx128m -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -Dprecise=false ChurnNotifications
+ * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -Dprecise=false TestChurnNotifications
+ * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static -Dprecise=false TestChurnNotifications
+ * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact -Dprecise=false TestChurnNotifications
+ * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -Dprecise=false TestChurnNotifications
*/
import java.util.*;
import java.util.concurrent.atomic.*;
import javax.management.*;
import java.lang.management.*;
import javax.management.openmbean.*;
+
import com.sun.management.GarbageCollectionNotificationInfo;
-public class ChurnNotifications {
+public class TestChurnNotifications {
static final long HEAP_MB = 128; // adjust for test configuration above
static final long TARGET_MB = Long.getLong("target", 8_000); // 8 Gb allocation
// Should we track the churn precisely?
// Precise tracking is only reliable when GC is fully stop-the-world. Otherwise,
// we cannot tell, looking at heap used before/after, what was the GC churn.
static final boolean PRECISE = Boolean.getBoolean("precise");
- static final long M = 1024*1024;
+ static final long M = 1024 * 1024;
static volatile Object sink;
public static void main(String[] args) throws Exception {
final AtomicLong churnBytes = new AtomicLong();
NotificationListener listener = new NotificationListener() {
@Override
public void handleNotification(Notification n, Object o) {
if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
- GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData)n.getUserData());
+ GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
Map<String, MemoryUsage> mapBefore = info.getGcInfo().getMemoryUsageBeforeGc();
Map<String, MemoryUsage> mapAfter = info.getGcInfo().getMemoryUsageAfterGc();
MemoryUsage before = mapBefore.get("Shenandoah");
MemoryUsage after = mapAfter.get("Shenandoah");
@@ -82,13 +84,13 @@
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
((NotificationEmitter) bean).addNotificationListener(listener, null, null);
}
final int size = 100_000;
- long count = TARGET_MB * 1024 * 1024 / (16 + 4*size);
+ long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size);
- long mem = count * (16 + 4*size);
+ long mem = count * (16 + 4 * size);
for (int c = 0; c < count; c++) {
sink = new int[size];
}
@@ -96,18 +98,16 @@
Thread.sleep(1000);
long actual = churnBytes.get();
- long minExpected = PRECISE ? (mem - HEAP_MB*1024*1024) : 1;
- long maxExpected = mem + HEAP_MB*1024*1024;
+ long minExpected = PRECISE ? (mem - HEAP_MB * 1024 * 1024) : 1;
+ long maxExpected = mem + HEAP_MB * 1024 * 1024;
- String msg = "Expected = [" + minExpected/M +"; " + maxExpected/M + "] (" + mem/M + "), actual = " + actual/M;
+ String msg = "Expected = [" + minExpected / M + "; " + maxExpected / M + "] (" + mem / M + "), actual = " + actual / M;
if (minExpected < actual && actual < maxExpected) {
System.out.println(msg);
} else {
throw new IllegalStateException(msg);
}
}
}
-
-
< prev index next >