--- old/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java 2018-05-24 10:20:18.361950946 -0700 +++ new/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java 2018-05-24 10:20:18.020951800 -0700 @@ -23,10 +23,10 @@ /* * @test TestJmapCore - * @summary Test verifies that jhsdb jmap could generate heap dump from core + * @summary Test verifies that jhsdb jmap could generate heap dump from core when heap is full * @modules java.base/jdk.internal.misc * @library /test/lib - * @run driver TestJmapCore + * @run driver/timeout=240 TestJmapCore run heap */ import jdk.test.lib.Asserts; @@ -39,27 +39,36 @@ import jdk.test.lib.process.OutputAnalyzer; import java.io.File; -import java.util.Arrays; -import java.util.stream.Collectors; public class TestJmapCore { static final String pidSeparator = ":KILLED_PID"; + public static String HEAP_OOME = "heap"; + public static String METASPACE_OOME = "metaspace"; + + public static void main(String[] args) throws Throwable { if (args.length == 1) { - // If any arguments are set prints pid so main process coud find corefile + // If 1 argument is set prints pid so main process could find corefile System.out.println(ProcessHandle.current().pid() + pidSeparator); try { - Object[] oa = new Object[Integer.MAX_VALUE / 2]; - for(int i = 0; i < oa.length; i++) { - oa[i] = new Object[Integer.MAX_VALUE / 2]; + if (args[0].equals(HEAP_OOME)) { + Object[] oa = new Object[Integer.MAX_VALUE / 2]; + for(int i = 0; i < oa.length; i++) { + oa[i] = new Object[Integer.MAX_VALUE / 2]; + } + } else { + GeneratingClassLoader loader = new GeneratingClassLoader(); + for (int i = 0; ; i++) { + loader.loadClass(loader.getClassName(i)); + } } throw new Error("OOME not triggered"); } catch (OutOfMemoryError err) { return; } } - test(); + test(args[1]); } // Test tries to run java with ulimit unlimited if it is possible @@ -75,10 +84,10 @@ } } - static void test() throws Throwable { + static void test(String type) throws Throwable { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-XX:+CreateCoredumpOnCrash", - "-XX:+CrashOnOutOfMemoryError", "-XX:-TransmitErrorReport", - TestJmapCore.class.getName(), "throwOOME"); + "-XX:MaxMetaspaceSize=64m", "-XX:+CrashOnOutOfMemoryError", "-XX:-TransmitErrorReport", + TestJmapCore.class.getName(), type); boolean useDefaultUlimit = useDefaultUlimit(); System.out.println("Run test with ulimit: " + (useDefaultUlimit ? "default" : "unlimited"));