--- old/test/jdk/java/lang/management/MemoryMXBean/LowMemoryTest.java 2018-10-18 18:02:16.000000000 -0400 +++ new/test/jdk/java/lang/management/MemoryMXBean/LowMemoryTest.java 2018-10-18 18:02:16.000000000 -0400 @@ -83,9 +83,13 @@ // Runs the test collecting subprocess I/O while it's running. traceTest(classMain + ", -XX:+UseSerialGC", nmFlag, lpFlag, "-XX:+UseSerialGC"); traceTest(classMain + ", -XX:+UseParallelGC", nmFlag, lpFlag, "-XX:+UseParallelGC"); - traceTest(classMain + ", -XX:+UseG1GC", nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag); + traceTest(classMain + ", -XX:+UseG1GC -XX:-G1UseLegacyMonitoring", nmFlag, lpFlag, + "-XX:+UseG1GC", "-XX:-G1UseLegacyMonitoring", g1Flag); + traceTest(classMain + ", -XX:+UseG1GC -XX:+G1UseLegacyMonitoring", nmFlag, lpFlag, + "-XX:+UseG1GC", "-XX:+G1UseLegacyMonitoring", g1Flag); if (!Compiler.isGraalEnabled()) { // Graal does not support CMS - traceTest(classMain + ", -XX:+UseConcMarkSweepGC", nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC"); + traceTest(classMain + ", -XX:+UseConcMarkSweepGC", nmFlag, lpFlag, + "-XX:+UseConcMarkSweepGC"); } } @@ -232,17 +236,39 @@ ListIterator iter = pools.listIterator(); while (iter.hasNext()) { MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next(); + // Only check heap pools that support a usage threshold. + // This is typically only the old generation space + // since the other spaces are expected to get filled up. if (p.getType() == MemoryType.HEAP && p.isUsageThresholdSupported()) { - mpool = p; - if (trace) { - System.out.println("Selected memory pool for low memory " + - "detection."); - MemoryUtil.printMemoryPool(mpool); + // In all collectors except G1, only the old generation supports a + // usage threshold. The G1 legacy mode "G1 Old Gen" also does. In + // G1 default mode, both the old space ("G1 Old Space": it's not + // really a generation in the non-G1 collector sense) and the + // humongous space ("G1 Humongous Space"), support a usage threshold. + // So, the following condition is true for all non-G1 old generations, + // for the G1 legacy old gen, and for the G1 default humongous space. + // It is not true for the G1 default old gen. + // + // We're allocating humongous objects in this test, so the G1 default + // mode "G1 Old Space" occupancy doesn't change, because humongous + // objects are allocated in the "G1 Humongous Space". If we allowed + // the G1 default mode "G1 Old Space", notification would never + // happen because no objects are allocated there. + if (!p.getName().equals("G1 Old Space")) { + mpool = p; + if (trace) { + System.out.println("Selected memory pool for low memory " + + "detection."); + MemoryUtil.printMemoryPool(mpool); + } + break; } - break; } } + if (mpool == null) { + throw new RuntimeException("TEST FAILED: No heap pool found"); + } TestListener listener = new TestListener(); SensorListener l2 = new SensorListener();