--- old/test/jdk/jdk/jfr/event/gc/stacktrace/AllocationStackTrace.java 2018-10-08 18:33:51.000000000 -0400 +++ new/test/jdk/jdk/jfr/event/gc/stacktrace/AllocationStackTrace.java 2018-10-08 18:33:51.000000000 -0400 @@ -305,7 +305,7 @@ * 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[]{ @@ -317,10 +317,10 @@ } /** - * 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[]{ @@ -336,7 +336,7 @@ * used */ public static void testMetaspaceG1GCAllocEvent() throws Exception { - GarbageCollectorMXBean bean = garbageCollectorMXBean("G1 Young Generation"); + GarbageCollectorMXBean bean = g1YoungGarbageCollectorMXBean(); MemoryAllocator memory = new MetaspaceMemoryAllocator(); String[] expectedStack = new String[]{ @@ -354,7 +354,7 @@ 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[]{ @@ -367,8 +367,30 @@ 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; }