< prev index next >

test/jdk/jdk/jfr/event/gc/stacktrace/AllocationStackTrace.java

Print this page

        

@@ -303,11 +303,11 @@
 
     /**
      * Tests event stacktrace for young GC if -XX:+UseG1GC is used
      */
     public static void testG1YoungAllocEvent() throws Exception {
-        GarbageCollectorMXBean bean = garbageCollectorMXBean("G1 Young Generation");
+        GarbageCollectorMXBean bean = g1YoungGarbageCollectorMXBean();
         MemoryAllocator memory = new EdenMemoryAllocator();
 
         String[] expectedStack = new String[]{
             "jdk.jfr.event.gc.stacktrace.AllocationStackTrace.testAllocEvent",
             "jdk.jfr.event.gc.stacktrace.AllocationStackTrace.testG1YoungAllocEvent"

@@ -315,14 +315,14 @@
 
         testAllocEvent(bean, memory, expectedStack);
     }
 
     /**
-     * Tests event stacktrace for old GC if -XX:+UseG1GC is used
+     * Tests event stacktrace for old/full GC if -XX:+UseG1GC is used
      */
     public static void testG1OldAllocEvent() throws Exception {
-        GarbageCollectorMXBean bean = garbageCollectorMXBean("G1 Old Generation");
+        GarbageCollectorMXBean bean = g1FullGarbageCollectorMXBean();
         MemoryAllocator memory = new OldGenMemoryAllocator();
 
         String[] expectedStack = new String[]{
             "jdk.jfr.event.gc.stacktrace.AllocationStackTrace.testAllocEvent",
             "jdk.jfr.event.gc.stacktrace.AllocationStackTrace.testG1OldAllocEvent"

@@ -334,11 +334,11 @@
     /**
      * Tests event stacktrace during metaspace GC threshold if -XX:+UseG1GC is
      * used
      */
     public static void testMetaspaceG1GCAllocEvent() throws Exception {
-        GarbageCollectorMXBean bean = garbageCollectorMXBean("G1 Young Generation");
+        GarbageCollectorMXBean bean = g1YoungGarbageCollectorMXBean();
         MemoryAllocator memory = new MetaspaceMemoryAllocator();
 
         String[] expectedStack = new String[]{
             "jdk.jfr.event.gc.stacktrace.AllocationStackTrace.testAllocEvent",
             "jdk.jfr.event.gc.stacktrace.AllocationStackTrace.testMetaspaceG1GCAllocEvent"

@@ -352,11 +352,11 @@
      * -XX:+UseG1GC is used
      */
     public static void testG1HumonAllocEvent() throws Exception {
         // G1 tries to reclaim humongous objects at every young collection
         // after doing a conservative estimate of its liveness
-        GarbageCollectorMXBean bean = garbageCollectorMXBean("G1 Young Generation");
+        GarbageCollectorMXBean bean = g1YoungGarbageCollectorMXBean();
         MemoryAllocator memory = new HumongousMemoryAllocator();
 
         String[] expectedStack = new String[]{
             "jdk.jfr.event.gc.stacktrace.AllocationStackTrace.testAllocEvent",
             "jdk.jfr.event.gc.stacktrace.AllocationStackTrace.testG1HumonAllocEvent"

@@ -365,12 +365,34 @@
         testAllocEvent(bean, memory, expectedStack);
     }
 
     private static GarbageCollectorMXBean garbageCollectorMXBean(String name) throws Exception {
         MBeanServer server = ManagementFactory.getPlatformMBeanServer();
-        GarbageCollectorMXBean bean = ManagementFactory.newPlatformMXBeanProxy(
-                server, "java.lang:type=GarbageCollector,name=" + name, GarbageCollectorMXBean.class);
+        GarbageCollectorMXBean bean;
+        try {
+            bean = ManagementFactory.newPlatformMXBeanProxy(server,
+                                                            "java.lang:type=GarbageCollector,name=" + name,
+                                                            GarbageCollectorMXBean.class);
+        } catch (IllegalArgumentException e) {
+            bean = null;
+        }
+        return bean;
+    }
+
+    private static GarbageCollectorMXBean g1YoungGarbageCollectorMXBean() throws Exception {
+        GarbageCollectorMXBean bean = garbageCollectorMXBean("G1 Young Generation");
+        if (bean == null) {
+            bean = garbageCollectorMXBean("G1 Young");
+        }
+        return bean;
+    }
+
+    private static GarbageCollectorMXBean g1FullGarbageCollectorMXBean() throws Exception {
+        GarbageCollectorMXBean bean = garbageCollectorMXBean("G1 Old Generation");
+        if (bean == null) {
+            bean = garbageCollectorMXBean("G1 Full");
+        }
         return bean;
     }
 
     /**
      * Performs JFR recording, GC provocation/detection and stacktrace
< prev index next >