--- 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")); --- /dev/null 2018-04-27 20:26:53.042636102 -0700 +++ new/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java 2018-05-24 10:20:18.674950161 -0700 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * 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. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test TestJmapCoreMetaspace + * @summary Test verifies that jhsdb jmap could generate heap dump from core when metspace is full + * @modules java.base/jdk.internal.misc + * @library /test/lib + * @run driver/timeout=240 TestJmapCore run metaspace + */