--- old/test/hotspot/jtreg/ProblemList.txt 2018-06-12 16:04:24.856922746 -0700 +++ new/test/hotspot/jtreg/ProblemList.txt 2018-06-12 16:04:24.490923736 -0700 @@ -172,9 +172,6 @@ vmTestbase/nsk/jdb/exclude/exclude001/exclude001.java 8197938 windows-all -vmTestbase/heapdump/JMapHeapCore/TestDescription.java 8023376,8001227,8051445 generic-all -vmTestbase/heapdump/JMapMetaspaceCore/TestDescription.java 8023376,8001227,8051445 generic-all - vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn001/forceEarlyReturn001.java 7199837 generic-all ############################################################################# --- old/test/hotspot/jtreg/TEST.groups 2018-06-12 16:04:25.507920985 -0700 +++ new/test/hotspot/jtreg/TEST.groups 2018-06-12 16:04:25.159921926 -0700 @@ -209,6 +209,7 @@ -runtime/ConstantPool/IntfMethod.java \ -runtime/ErrorHandling/CreateCoredumpOnCrash.java \ -runtime/ErrorHandling/ErrorHandler.java \ + -runtime/ErrorHandling/TestHeapDumpOnOutOfMemoryError.java \ -runtime/ErrorHandling/TimeoutInErrorHandlingTest.java \ -runtime/logging/MonitorMismatchTest.java \ -runtime/memory/ReserveMemory.java \ @@ -271,6 +272,8 @@ serviceability/logging \ serviceability/sa \ -serviceability/sa/ClhsdbScanOops.java \ + -serviceability/sa/TestJmapCore.java \ + -serviceability/sa/TestJmapCoreMetaspace.java \ -serviceability/sa/TestHeapDumpForLargeArray.java tier1 = \ @@ -2263,17 +2266,6 @@ vmTestbase_vm_mlvm = \ vmTestbase/vm/mlvm -# Heap dump tests -vmTestbase_vm_heapdump = \ - vmTestbase/heapdump - -vmTestbase_vm_heapdump_quick = \ - vmTestbase/heapdump/OnOOMToFile/TestDescription.java \ - vmTestbase/heapdump/OnOOMToFileMetaspace/TestDescription.java \ - vmTestbase/heapdump/OnOOMToPath/TestDescription.java \ - vmTestbase/heapdump/JMapHeapCore/TestDescription.java \ - vmTestbase/heapdump/JMapMetaspace/TestDescription.java - # Tests for attach-on-demand implementation vmTestbase_nsk_aod = \ vmTestbase/nsk/aod --- old/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/GeneratedClassProducer.java 2018-06-12 16:04:26.196919122 -0700 +++ new/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/GeneratedClassProducer.java 2018-06-12 16:04:25.834920101 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -22,6 +22,8 @@ */ package utils; +import jdk.test.lib.classloader.GeneratingClassLoader; + /** * Garbage producer that creates classes loaded with GeneratingClassLoader. * --- /dev/null 2018-04-27 20:26:53.042636102 -0700 +++ new/test/hotspot/jtreg/runtime/ErrorHandling/TestHeapDumpOnOutOfMemoryError.java 2018-06-12 16:04:26.498918305 -0700 @@ -0,0 +1,83 @@ +/* + * 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 TestHeapDumpOnOutOfMemoryError + * @summary Test verifies that -XX:HeapDumpOnOutOfMemoryError dump heap when OutOfMemory is thrown in heap + * @library /test/lib + * @run driver TestHeapDumpOnOutOfMemoryError run heap + */ + +import jdk.test.lib.Asserts; +import jdk.test.lib.classloader.GeneratingClassLoader; +import jdk.test.lib.hprof.HprofParser; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +import java.io.File; + +public class TestHeapDumpOnOutOfMemoryError { + + public static final String HEAP_OOME = "heap"; + public static final String METASPACE_OOME = "metaspace"; + + public static void main(String[] args) throws Exception { + if (args.length == 1) { + try { + if (args[0].equals(HEAP_OOME)) { + Object[] oa = new Object[Integer.MAX_VALUE]; + for(int i = 0; i < oa.length; i++) { + oa[i] = new Object[Integer.MAX_VALUE]; + } + } 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(args[1]); + } + + static void test(String type) throws Exception { + String heapdumpFilename = type + ".hprof"; + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+HeapDumpOnOutOfMemoryError", + "-XX:HeapDumpPath=" + heapdumpFilename, "-XX:MaxMetaspaceSize=64m", + TestHeapDumpOnOutOfMemoryError.class.getName(), type); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.stdoutShouldNotBeEmpty(); + output.shouldContain("Dumping heap to " + type + ".hprof"); + File dump = new File(heapdumpFilename); + Asserts.assertTrue(dump.exists() && dump.isFile(), + "Could not find dump file " + dump.getAbsolutePath()); + + HprofParser.parse(new File(heapdumpFilename)); + System.out.println("PASSED"); + } + +} --- /dev/null 2018-04-27 20:26:53.042636102 -0700 +++ new/test/hotspot/jtreg/runtime/ErrorHandling/TestHeapDumpOnOutOfMemoryErrorInMetaspace.java 2018-06-12 16:04:27.189916436 -0700 @@ -0,0 +1,29 @@ +/* + * 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 TestHeapDumpOnOutOfMemoryErrorInMetaspace + * @summary Test verifies that -XX:HeapDumpOnOutOfMemoryError dump heap when OutOfMemory is thrown in metaspace + * @library /test/lib + * @run driver/timeout=240 TestHeapDumpOnOutOfMemoryError run metaspace + */ --- /dev/null 2018-04-27 20:26:53.042636102 -0700 +++ new/test/hotspot/jtreg/runtime/ErrorHandling/TestHeapDumpPath.java 2018-06-12 16:04:27.856914632 -0700 @@ -0,0 +1,78 @@ +/* + * 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 TestHeapDumpPath + * @summary Test verifies that -XX:HeapDumpPath= supports directory as a parameter. + * @library /test/lib + * @run driver TestHeapDumpPath + */ + +import jdk.test.lib.Asserts; +import jdk.test.lib.hprof.HprofParser; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +import java.io.File; + +public class TestHeapDumpPath { + + public static void main(String[] args) throws Exception { + if (args.length == 1) { + try { + Object[] oa = new Object[Integer.MAX_VALUE]; + throw new Error("OOME not triggered"); + } catch (OutOfMemoryError err) { + return; + } + } + + testHeapDumpPath(); + } + static void testHeapDumpPath() throws Exception { + String heapdumpPath = "dumps"; + File dumpDirectory = new File(heapdumpPath); + dumpDirectory.mkdir(); + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+HeapDumpOnOutOfMemoryError", + "-Xmx64m", "-XX:HeapDumpPath=" + heapdumpPath, TestHeapDumpPath.class.getName(), "OOME"); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.stdoutShouldNotBeEmpty(); + output.shouldContain("Dumping heap"); + + Asserts.assertFalse(dumpDirectory.listFiles().length == 0, + "There is no dump files found in " + dumpDirectory ); + + Asserts.assertTrue(dumpDirectory.listFiles().length == 1, + "There are unexpected files in " + dumpDirectory + + ": " + String.join(",", dumpDirectory.list()) +"."); + + File dump = dumpDirectory.listFiles()[0]; + Asserts.assertTrue(dump.exists() && dump.isFile(), + "Could not find dump file " + dump.getAbsolutePath()); + + HprofParser.parse(dump); + System.out.println("PASSED"); + } + +} --- /dev/null 2018-04-27 20:26:53.042636102 -0700 +++ new/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java 2018-06-12 16:04:28.576912685 -0700 @@ -0,0 +1,142 @@ +/* + * 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 TestJmapCore + * @summary Test verifies that jhsdb jmap could generate heap dump from core when heap is full + * @library /test/lib + * @run driver/timeout=240 TestJmapCore run heap + */ + +import jdk.test.lib.Asserts; +import jdk.test.lib.JDKToolFinder; +import jdk.test.lib.JDKToolLauncher; +import jdk.test.lib.Platform; +import jdk.test.lib.classloader.GeneratingClassLoader; +import jdk.test.lib.hprof.HprofParser; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +import java.io.File; + +public class TestJmapCore { + static final String pidSeparator = ":KILLED_PID"; + + public static final String HEAP_OOME = "heap"; + public static final String METASPACE_OOME = "metaspace"; + + + public static void main(String[] args) throws Throwable { + if (args.length == 1) { + // If 1 argument is set prints pid so main process could find corefile + System.out.println(ProcessHandle.current().pid() + pidSeparator); + try { + 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(args[1]); + } + + // Test tries to run java with ulimit unlimited if it is possible + static boolean useDefaultUlimit() { + if (Platform.isWindows()) { + return true; + } + try { + OutputAnalyzer output = ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && ulimit -c"); + return !(output.getExitValue() == 0 && output.getStdout().contains("unlimited")); + } catch (Throwable t) { + return true; + } + } + + static void test(String type) throws Throwable { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-XX:+CreateCoredumpOnCrash", + "-XX:MaxMetaspaceSize=64m", "-XX:+CrashOnOutOfMemoryError", "-XX:-TransmitErrorReport", + TestJmapCore.class.getName(), type); + + boolean useDefaultUlimit = useDefaultUlimit(); + System.out.println("Run test with ulimit: " + (useDefaultUlimit ? "default" : "unlimited")); + OutputAnalyzer output = useDefaultUlimit + ? ProcessTools.executeProcess(pb) + : ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && " + + ProcessTools.getCommandLine(pb)); + File core; + String pattern = Platform.isWindows() ? "mdmp" : "core"; + File[] cores = new File(".").listFiles((dir, name) -> name.contains(pattern)); + if (cores.length == 0) { + // /cores/core.$pid might be generated on macosx by default + String pid = output.firstMatch("^(\\d+)" + pidSeparator, 1); + core = new File("cores/core." + pid); + if (!core.exists()) { + System.out.println("Has not been able to find coredump. Test skipped."); + return; + } + } else { + Asserts.assertTrue(cores.length == 1, + "There are unexpected files containing core " + + ": " + String.join(",", new File(".").list()) + "."); + core = cores[0]; + } + System.out.println("Found corefile: " + core.getAbsolutePath()); + + File dumpFile = new File("heap.hprof"); + JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); + launcher.addToolArg("jmap"); + launcher.addToolArg("--binaryheap"); + launcher.addToolArg("--dumpfile=" + dumpFile); + launcher.addToolArg("--exe"); + launcher.addToolArg(JDKToolFinder.getTestJDKTool("java")); + launcher.addToolArg("--core"); + launcher.addToolArg(core.getPath()); + + ProcessBuilder jhsdpb = new ProcessBuilder(); + jhsdpb.command(launcher.getCommand()); + Process jhsdb = jhsdpb.start(); + OutputAnalyzer out = new OutputAnalyzer(jhsdb); + + jhsdb.waitFor(); + + System.out.println(out.getStdout()); + System.err.println(out.getStderr()); + + Asserts.assertTrue(dumpFile.exists() && dumpFile.isFile(), + "Could not find dump file " + dumpFile.getAbsolutePath()); + + HprofParser.parse(dumpFile); + System.out.println("PASSED"); + } +} --- /dev/null 2018-04-27 20:26:53.042636102 -0700 +++ new/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java 2018-06-12 16:04:29.264910825 -0700 @@ -0,0 +1,29 @@ +/* + * 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 + * @library /test/lib + * @run driver/timeout=240 TestJmapCore run metaspace + */ --- old/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/ClassLoadUtils.java 2018-06-12 16:04:30.452907612 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2015, 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. - */ -package utils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.FileInputStream; - -public class ClassLoadUtils { - - private ClassLoadUtils() { - } - - /** - * Get filename of class file from classpath for given class name. - * - * @param className class name - * @return filename or null if not found - */ - public static String getClassPath(String className) { - String fileName = className.replace(".", File.separator) + ".class"; - String[] classPath = System.getProperty("java.class.path").split(File.pathSeparator); - File target = null; - int i; - for (i = 0; i < classPath.length; ++i) { - target = new File(classPath[i] + File.separator + fileName); - System.out.println("Try: " + target); - if (target.exists()) { - break; - } - } - if (i != classPath.length) { - return classPath[i]; - } - return null; - } - - /** - * Get filename of class file from classpath for given class name. - * - * @param className class name - * @return filename or null if not found - */ - public static String getClassPathFileName(String className) { - String fileName = className.replace(".", File.separator) + ".class"; - String[] classPath = System.getProperty("java.class.path").split(File.pathSeparator); - File target = null; - int i; - for (i = 0; i < classPath.length; ++i) { - target = new File(classPath[i] + File.separator + fileName); - System.out.println("Try: " + target); - if (target.exists()) { - break; - } - } - if (i != classPath.length) { - try { - return target.getCanonicalPath(); - } catch (IOException e) { - return null; - } - } - return null; - } - - public static String getRedefineClassFileName(String dir, String className) { - String fileName = getClassPathFileName(className); - if (fileName == null) { - return null; - } - if (fileName.contains("classes")) { - return fileName.replace("classes", dir); - } else { - String classPath = getClassPath(className); - if (classPath != null) { - return classPath + File.separator + "newclass" + File.separator + className.replace(".", File.separator) + ".class"; - } else { - return null; - } - } - } - - /** - * Get filename of class file which is to be redefined. - */ - public static String getRedefineClassFileName(String className) { - return getRedefineClassFileName("newclass", className); - } - - /** - * Read whole file. - * - * @param file file - * @return contents of file as byte array - */ - public static byte[] readFile(File file) throws IOException { - InputStream in = new FileInputStream(file); - long countl = file.length(); - if (countl > Integer.MAX_VALUE) { - throw new IOException("File is too huge"); - } - int count = (int) countl; - byte[] buffer = new byte[count]; - int n = 0; - try { - while (n < count) { - int k = in.read(buffer, n, count - n); - if (k < 0) { - throw new IOException("Unexpected EOF"); - } - n += k; - } - } finally { - in.close(); - } - return buffer; - } - - /** - * Read whole file. - * - * @param name file name - * @return contents of file as byte array - */ - public static byte[] readFile(String name) throws IOException { - return readFile(new File(name)); - } -} --- /dev/null 2018-04-27 20:26:53.042636102 -0700 +++ new/test/lib/jdk/test/lib/classloader/ClassLoadUtils.java 2018-06-12 16:04:29.982908883 -0700 @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2015, 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. + */ +package jdk.test.lib.classloader; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.FileInputStream; + +public class ClassLoadUtils { + + private ClassLoadUtils() { + } + + /** + * Get filename of class file from classpath for given class name. + * + * @param className class name + * @return filename or null if not found + */ + public static String getClassPath(String className) { + String fileName = className.replace(".", File.separator) + ".class"; + String[] classPath = System.getProperty("java.class.path").split(File.pathSeparator); + File target = null; + int i; + for (i = 0; i < classPath.length; ++i) { + target = new File(classPath[i] + File.separator + fileName); + System.out.println("Try: " + target); + if (target.exists()) { + break; + } + } + if (i != classPath.length) { + return classPath[i]; + } + return null; + } + + /** + * Get filename of class file from classpath for given class name. + * + * @param className class name + * @return filename or null if not found + */ + public static String getClassPathFileName(String className) { + String fileName = className.replace(".", File.separator) + ".class"; + String[] classPath = System.getProperty("java.class.path").split(File.pathSeparator); + File target = null; + int i; + for (i = 0; i < classPath.length; ++i) { + target = new File(classPath[i] + File.separator + fileName); + System.out.println("Try: " + target); + if (target.exists()) { + break; + } + } + if (i != classPath.length) { + try { + return target.getCanonicalPath(); + } catch (IOException e) { + return null; + } + } + return null; + } + + public static String getRedefineClassFileName(String dir, String className) { + String fileName = getClassPathFileName(className); + if (fileName == null) { + return null; + } + if (fileName.contains("classes")) { + return fileName.replace("classes", dir); + } else { + String classPath = getClassPath(className); + if (classPath != null) { + return classPath + File.separator + "newclass" + File.separator + className.replace(".", File.separator) + ".class"; + } else { + return null; + } + } + } + + /** + * Get filename of class file which is to be redefined. + */ + public static String getRedefineClassFileName(String className) { + return getRedefineClassFileName("newclass", className); + } + + /** + * Read whole file. + * + * @param file file + * @return contents of file as byte array + */ + public static byte[] readFile(File file) throws IOException { + InputStream in = new FileInputStream(file); + long countl = file.length(); + if (countl > Integer.MAX_VALUE) { + throw new IOException("File is too huge"); + } + int count = (int) countl; + byte[] buffer = new byte[count]; + int n = 0; + try { + while (n < count) { + int k = in.read(buffer, n, count - n); + if (k < 0) { + throw new IOException("Unexpected EOF"); + } + n += k; + } + } finally { + in.close(); + } + return buffer; + } + + /** + * Read whole file. + * + * @param name file name + * @return contents of file as byte array + */ + public static byte[] readFile(String name) throws IOException { + return readFile(new File(name)); + } +} --- old/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/GeneratingClassLoader.java 2018-06-12 16:04:31.230905508 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2015, 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. - */ -package utils; - -import java.io.*; -import java.util.*; - -/** - * Classloader that generates classes on the fly. - * - * This classloader can load classes with name starting with 'Class'. It will - * use TemplateClass as template and will replace class name in the bytecode of - * template class. It can be used for example to detect memory leaks in class - * loading or to quickly fill PermGen. - */ -class GeneratingClassLoader extends ClassLoader { - - public synchronized Class loadClass(String name) throws ClassNotFoundException { - return loadClass(name, false); - } - - public synchronized Class loadClass(String name, boolean resolve) - throws ClassNotFoundException { - Class c = findLoadedClass(name); - if (c != null) { - return c; - } - if (!name.startsWith(PREFIX)) { - return super.loadClass(name, resolve); - } - if (name.length() != templateClassName.length()) { - throw new ClassNotFoundException("Only can load classes with name.length() = " + getNameLength() + " got: '" + name + "' length: " + name.length()); - } - byte[] bytecode = getPatchedByteCode(name); - c = defineClass(name, bytecode, 0, bytecode.length); - if (resolve) { - resolveClass(c); - } - return c; - } - - /** - * Create generating class loader that will use class file for given class - * from classpath as template. - */ - GeneratingClassLoader(String templateClassName) { - this.templateClassName = templateClassName; - classPath = System.getProperty("java.class.path").split(File.pathSeparator); - try { - templateClassNameBytes = templateClassName.getBytes(encoding); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - - /** - * Create generating class loader that will use class file for - * nsk.share.classload.TemplateClass as template. - */ - GeneratingClassLoader() { - this(TemplateClass.class.getName()); - } - - int getNameLength() { - return templateClassName.length(); - } - - String getPrefix() { - return PREFIX; - } - - String getClassName(int number) { - StringBuffer sb = new StringBuffer(); - sb.append(PREFIX); - sb.append(number); - int n = templateClassName.length() - sb.length(); - for (int i = 0; i < n; ++i) { - sb.append("_"); - } - return sb.toString(); - } - - private byte[] getPatchedByteCode(String name) throws ClassNotFoundException { - try { - byte[] bytecode = getByteCode(); - String fname = name.replace(".", File.separator); - byte[] replaceBytes = fname.getBytes(encoding); - for (int offset : offsets) { - for (int i = 0; i < replaceBytes.length; ++i) { - bytecode[offset + i] = replaceBytes[i]; - } - } - return bytecode; - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - - private byte[] getByteCode() throws ClassNotFoundException { - if (bytecode == null) { - readByteCode(); - } - if (offsets == null) { - getOffsets(bytecode); - if (offsets == null) { - throw new RuntimeException("Class name not found in template class file"); - } - } - return (byte[]) bytecode.clone(); - } - - private void readByteCode() throws ClassNotFoundException { - String fname = templateClassName.replace(".", File.separator) + ".class"; - File target = null; - for (int i = 0; i < classPath.length; ++i) { - target = new File(classPath[i] + File.separator + fname); - if (target.exists()) { - break; - } - } - - if (target == null || !target.exists()) { - throw new ClassNotFoundException("File not found: " + target); - } - try { - bytecode = ClassLoadUtils.readFile(target); - } catch (IOException e) { - throw new ClassNotFoundException(templateClassName, e); - } - } - - private void getOffsets(byte[] bytecode) { - List offsets = new ArrayList(); - if (this.offsets == null) { - String pname = templateClassName.replace(".", "/"); - try { - byte[] pnameb = pname.getBytes(encoding); - int i = 0; - while (true) { - while (i < bytecode.length) { - int j = 0; - while (j < pnameb.length && bytecode[i + j] == pnameb[j]) { - ++j; - } - if (j == pnameb.length) { - break; - } - i++; - } - if (i == bytecode.length) { - break; - } - offsets.add(new Integer(i)); - i++; - } - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - this.offsets = new int[offsets.size()]; - for (int i = 0; i < offsets.size(); ++i) { - this.offsets[i] = offsets.get(i).intValue(); - } - } - } - - static final String DEFAULT_CLASSNAME = TemplateClass.class.getName(); - static final String PREFIX = "Class"; - - private final String[] classPath; - private byte[] bytecode; - private int[] offsets; - private final String encoding = "UTF8"; - private final String templateClassName; - private final byte[] templateClassNameBytes; -} --- /dev/null 2018-04-27 20:26:53.042636102 -0700 +++ new/test/lib/jdk/test/lib/classloader/GeneratingClassLoader.java 2018-06-12 16:04:30.774906741 -0700 @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2015, 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. + */ +package jdk.test.lib.classloader; + +import java.io.*; +import java.util.*; + +/** + * Classloader that generates classes on the fly. + * + * This classloader can load classes with name starting with 'Class'. It will + * use TemplateClass as template and will replace class name in the bytecode of + * template class. It can be used for example to detect memory leaks in class + * loading or to quickly fill Metaspace. + */ +class TemplateClass { +} + +public class GeneratingClassLoader extends ClassLoader { + + public synchronized Class loadClass(String name) throws ClassNotFoundException { + return loadClass(name, false); + } + + public synchronized Class loadClass(String name, boolean resolve) + throws ClassNotFoundException { + Class c = findLoadedClass(name); + if (c != null) { + return c; + } + if (!name.startsWith(PREFIX)) { + return super.loadClass(name, resolve); + } + if (name.length() != templateClassName.length()) { + throw new ClassNotFoundException("Only can load classes with name.length() = " + getNameLength() + " got: '" + name + "' length: " + name.length()); + } + byte[] bytecode = getPatchedByteCode(name); + c = defineClass(name, bytecode, 0, bytecode.length); + if (resolve) { + resolveClass(c); + } + return c; + } + + /** + * Create generating class loader that will use class file for given class + * from classpath as template. + */ + public GeneratingClassLoader(String templateClassName) { + this.templateClassName = templateClassName; + classPath = System.getProperty("java.class.path").split(File.pathSeparator); + try { + templateClassNameBytes = templateClassName.getBytes(encoding); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + /** + * Create generating class loader that will use class file for + * nsk.share.classload.TemplateClass as template. + */ + public GeneratingClassLoader() { + this(TemplateClass.class.getName()); + } + + public int getNameLength() { + return templateClassName.length(); + } + + String getPrefix() { + return PREFIX; + } + + public String getClassName(int number) { + StringBuffer sb = new StringBuffer(); + sb.append(PREFIX); + sb.append(number); + int n = templateClassName.length() - sb.length(); + for (int i = 0; i < n; ++i) { + sb.append("_"); + } + return sb.toString(); + } + + private byte[] getPatchedByteCode(String name) throws ClassNotFoundException { + try { + byte[] bytecode = getByteCode(); + String fname = name.replace(".", File.separator); + byte[] replaceBytes = fname.getBytes(encoding); + for (int offset : offsets) { + for (int i = 0; i < replaceBytes.length; ++i) { + bytecode[offset + i] = replaceBytes[i]; + } + } + return bytecode; + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + private byte[] getByteCode() throws ClassNotFoundException { + if (bytecode == null) { + readByteCode(); + } + if (offsets == null) { + getOffsets(bytecode); + if (offsets == null) { + throw new RuntimeException("Class name not found in template class file"); + } + } + return (byte[]) bytecode.clone(); + } + + private void readByteCode() throws ClassNotFoundException { + String fname = templateClassName.replace(".", File.separator) + ".class"; + File target = null; + for (int i = 0; i < classPath.length; ++i) { + target = new File(classPath[i] + File.separator + fname); + if (target.exists()) { + break; + } + } + + if (target == null || !target.exists()) { + throw new ClassNotFoundException("File not found: " + target); + } + try { + bytecode = ClassLoadUtils.readFile(target); + } catch (IOException e) { + throw new ClassNotFoundException(templateClassName, e); + } + } + + private void getOffsets(byte[] bytecode) { + List offsets = new ArrayList(); + if (this.offsets == null) { + String pname = templateClassName.replace(".", "/"); + try { + byte[] pnameb = pname.getBytes(encoding); + int i = 0; + while (true) { + while (i < bytecode.length) { + int j = 0; + while (j < pnameb.length && bytecode[i + j] == pnameb[j]) { + ++j; + } + if (j == pnameb.length) { + break; + } + i++; + } + if (i == bytecode.length) { + break; + } + offsets.add(new Integer(i)); + i++; + } + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + this.offsets = new int[offsets.size()]; + for (int i = 0; i < offsets.size(); ++i) { + this.offsets[i] = offsets.get(i).intValue(); + } + } + } + + public static final String DEFAULT_CLASSNAME = TemplateClass.class.getName(); + static final String PREFIX = "Class"; + + private final String[] classPath; + private byte[] bytecode; + private int[] offsets; + private final String encoding = "UTF8"; + private final String templateClassName; + private final byte[] templateClassNameBytes; +} --- old/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/TemplateClass.java 2018-06-12 16:04:32.016903382 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2015, 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. - */ -package utils; - -class TemplateClass { -} --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapHeap/TEST.properties 2018-06-12 16:04:32.647901676 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 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. -# -exclusiveAccess.dirs=. --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapHeap/TestDescription.java 2018-06-12 16:04:33.358899753 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017, 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 - * - * @summary converted from VM testbase heapdump/JMapHeap. - * VM testbase keywords: [heapdump, feature_heapdump, nonconcurrent, jdk] - * VM testbase readme: - * DESCRIPTION - * This test verifies that heap dump created by JMap is able to be - * parsed by HprofParser. It fills the heap with objects of different types - * till OutOfMemoryError, then uses JMap to create heap dump and then - * verifies created heap dump with HprofParser. - * - * @library /vmTestbase - * /test/lib - * @run driver jdk.test.lib.FileInstaller . . - * @build jdk.test.lib.hprof.HprofParser - * heapdump.share.EatMemory - * @run shell/timeout=300 run.sh - */ - --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapHeap/run.sh 2018-06-12 16:04:34.037897917 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,51 +0,0 @@ -#!/bin/sh -# Copyright (c) 2007, 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. - -. $TESTSRC/../share/common.sh - -JAVA_OPTS="${JAVA_OPTS} -XX:-UseGCOverheadLimit -Xmx1G" - -DUMPFILE=heap.bin - -rm -f ${DUMPFILE} - -JMAP_DUMP_OPT="-dump:format=b,file=${DUMPFILE}" - -${JAVA} ${JAVA_OPTS} heapdump.share.EatMemory -exec "${JMAP} ${JMAP_DUMP_OPT} %p" - -status=$? - -if [ $status -ne 0 ]; then - fail "Java exited with exit status: $status" -fi - -if [ ! -f "${DUMPFILE}" ]; then - fail "Dump file was not created: $DUMPFILE" -fi - -verify_heapdump ${DUMPFILE} - -if [ $? -ne 0 ]; then - fail "Verification of heap dump failed" -fi - -pass --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapHeapCore/TestDescription.java 2018-06-12 16:04:34.763895954 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017, 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 - * - * @summary converted from VM testbase heapdump/JMapHeapCore. - * VM testbase keywords: [heapdump, feature_heapdump, nonconcurrent.jdk, quick, quarantine] - * VM testbase comments: JDK-8023376 JDK-8001227 JDK-8051445 - * VM testbase readme: - * DESCRIPTION - * This test verifies that heap dump created by jhsdb is able to be - * parsed by HprofParser. It fills the heap with objects of different types - * till OutOfMemoryError, forces core dump, then uses jhsdb on core file - * to create heap dump and then verifies created heap dump with HprofParser. - * - * @library /vmTestbase - * /test/lib - * @run driver jdk.test.lib.FileInstaller . . - * @build jdk.test.lib.hprof.HprofParser - * heapdump.share.EatMemory - * @run shell/timeout=300 run.sh - */ - --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapHeapCore/run.sh 2018-06-12 16:04:35.582893739 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,88 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2007, 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. -# - -. $TESTSRC/../share/common.sh - -JAVA_OPTS="${JAVA_OPTS} -XX:-UseGCOverheadLimit -XX:-TransmitErrorReport" - -if [ $CORE_SUPPORTED -eq 0 ]; then - pass "Core dump is not supported" -fi - -DUMPFILE=heap.bin - -rm -f ${DUMPFILE} - -ulimit -c unlimited || true - -echo "Below 'Unexpected error' is actually expected - JVM is forced to dump core" -${JAVA} ${JAVA_OPTS} heapdump.share.EatMemory -core & - -pid=$! - -wait $pid - -status=$? - -if [ $status -eq 0 ]; then - pass "Java exited with exit status: $status" -fi - -for CORE in core* /cores/core.$pid; do - [ -e "$CORE" ] && break; -done - -if [ ! -f "$CORE" ]; then - fail "Java exited with exit status: $status, but core file was not created" -fi -echo "Found core file: $CORE" - -JMAP_DUMP_OPT="--binaryheap --dumpfile=${DUMPFILE}" -EXE_OPT="--exe" -CORE_OPT="--core" -JHSDB_OPT="jmap" - -${JHSDB} ${JHSDB_OPT} ${JMAP_DUMP_OPT} ${EXE_OPT} ${JAVA} ${CORE_OPT} ${CORE} - -status=$? -if [ $status -ne 0 ]; then - fail "jmap exited with exit status $status" -fi - -if [ ! -f "${DUMPFILE}" ]; then - fail "Dump file was not created: $DUMPFILE" -fi - -verify_heapdump ${DUMPFILE} - -if [ $? -ne 0 ]; then - fail "Verification of heap dump failed" -fi - -if [ "$TEST_CLEANUP" != "false" ]; then - rm -f ${CORE} - rm -f hs_err_pid* -fi - -pass --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapMetaspace/TEST.properties 2018-06-12 16:04:36.504891245 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 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. -# -exclusiveAccess.dirs=. --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapMetaspace/TestDescription.java 2018-06-12 16:04:37.285889133 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017, 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 - * - * @summary converted from VM testbase heapdump/JMapMetaspace. - * VM testbase keywords: [heapdump, feature_heapdump, nonconcurrent, jdk, quick] - * VM testbase readme: - * DESCRIPTION - * This test verifies that heap dump created by JMap is able to be - * parsed by HprofParser. It fills metaspace with classes till OutOfMemoryError, - * then uses JMap to create heap dump and then verifies created heap dump with HprofParser. - * - * @requires vm.opt.final.ClassUnloading - * @library /vmTestbase - * /test/lib - * @run driver jdk.test.lib.FileInstaller . . - * @build jdk.test.lib.hprof.HprofParser - * heapdump.share.EatMemory - * @run shell/timeout=300 run.sh - */ --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapMetaspace/run.sh 2018-06-12 16:04:38.174886729 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,53 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2014, 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. -# - -. $TESTSRC/../share/common.sh - -JAVA_OPTS="${JAVA_OPTS} -XX:-UseGCOverheadLimit -XX:MaxMetaspaceSize=64m" - -DUMPFILE=heap.bin - -rm -f ${DUMPFILE} - -JMAP_DUMP_OPT="-dump:format=b,file=${DUMPFILE}" - -${JAVA} ${JAVA_OPTS} heapdump.share.EatMemory -metaspace -exec "${JMAP} ${JMAP_DUMP_OPT} %p" - -status=$? - -if [ $status -ne 0 ]; then - fail "Java exited with exit status: $status" -fi - -if [ ! -f "${DUMPFILE}" ]; then - fail "Dump file was not created: ${DUMPFILE}" -fi - -verify_heapdump ${DUMPFILE} - -if [ $? -ne 0 ]; then - fail "Verification of heap dump failed" -fi - -pass --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapMetaspaceCore/TEST.properties 2018-06-12 16:04:39.269883768 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 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. -# -exclusiveAccess.dirs=. --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapMetaspaceCore/TestDescription.java 2018-06-12 16:04:40.151881383 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017, 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 - * - * @summary converted from VM testbase heapdump/JMapMetaspaceCore. - * VM testbase keywords: [heapdump, feature_heapdump, nonconcurrent, jdk, quarantine] - * VM testbase comments: JDK-8023376 JDK-8001227 JDK-8051445 - * VM testbase readme: - * DESCRIPTION - * This test verifies that heap dump created by jhsdb is able to be - * parsed by HprofParser. It fills metaspace with classes till OutOfMemoryError, - * forces core dump, then uses jhsdb one core file to create heap dump - * and then verifies created heap dump with HprofParser. - * - * @library /vmTestbase - * /test/lib - * @run driver jdk.test.lib.FileInstaller . . - * @build jdk.test.lib.hprof.HprofParser - * heapdump.share.EatMemory - * @run shell/timeout=300 run.sh - */ - --- old/test/hotspot/jtreg/vmTestbase/heapdump/JMapMetaspaceCore/run.sh 2018-06-12 16:04:41.028879012 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,90 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2014, 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. -# - -. $TESTSRC/../share/common.sh - -JAVA_OPTS="${JAVA_OPTS} -XX:-UseGCOverheadLimit -XX:MaxMetaspaceSize=64m -XX:-TransmitErrorReport" - -if [ $CORE_SUPPORTED -eq 0 ]; then - pass "Core dump is not supported" -fi - -DUMPFILE=heap.bin - -rm -f ${DUMPFILE} - -ulimit -c unlimited || true - -echo "Below 'Unexpected error' is actually expected - JVM is forced to dump core" - -${JAVA} ${JAVA_OPTS} heapdump.share.EatMemory -metaspace -core & - -pid=$! - -wait $pid - -status=$? - -if [ $status -eq 0 ]; then - pass "Java exited with exit status: $status" -fi - -for CORE in core* /cores/core.$pid; do - [ -e "$CORE" ] && break; -done - -if [ ! -f "$CORE" ]; then - fail "Java exited with exit status $status, but core file was not created" -fi - -echo "Found core file: $CORE" - -JMAP_DUMP_OPT="--binaryheap --dumpfile=${DUMPFILE}" -EXE_OPT="--exe" -CORE_OPT="--core" -JHSDB_OPT="jmap" - -${JHSDB} ${JHSDB_OPT} ${JMAP_DUMP_OPT} ${EXE_OPT} ${JAVA} ${CORE_OPT} ${CORE} - -status=$? -if [ $status -ne 0 ]; then - fail "jmap exited with exit status $status" -fi - -if [ ! -f "${DUMPFILE}" ]; then - fail "Dump file was not created: $DUMPFILE" -fi - -verify_heapdump ${DUMPFILE} - -if [ $? -ne 0 ]; then - fail "Verification of heap dump failed" -fi - -if [ "$TEST_CLEANUP" != "false" ]; then - rm -f ${CORE} - rm -f hs_err_pid* -fi - -pass --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToFile/TEST.properties 2018-06-12 16:04:41.928876578 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 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. -# -exclusiveAccess.dirs=. --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToFile/TestDescription.java 2018-06-12 16:04:42.919873898 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017, 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 - * - * @summary converted from VM testbase heapdump/OnOOMToFile. - * VM testbase keywords: [heapdump, feature_heapdump, nonconcurrent, jdk, quick] - * VM testbase readme: - * DESCRIPTION - * This test verifies -XX:+HeapDumpOnOutOfMemory VM option. It - * fills the heap with objects of different types till OutOfMemoryError - * and then verifies created heap dump with HprofParser. - * COMMENTS - * This test uses -XX:HeapDumpPath= option pointing to file. - * - * @library /vmTestbase - * /test/lib - * @run driver jdk.test.lib.FileInstaller . . - * @build jdk.test.lib.hprof.HprofParser - * heapdump.share.EatMemory - * @run shell/timeout=300 run.sh - */ - --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToFile/run.sh 2018-06-12 16:04:43.773871589 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,53 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2007, 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. -# - -. $TESTSRC/../share/common.sh - -JAVA_OPTS="${JAVA_OPTS} -XX:-UseGCOverheadLimit" - -DUMPFILE=${DUMPBASE}/java.hprof - -rm -f ${DUMPFILE} - -JAVA_OPTS="${JAVA_OPTS} -Xmx`get_max_heap_size $JAVA_OPTS`" - -${JAVA} ${JAVA_OPTS} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${DUMPFILE} heapdump.share.EatMemory - -status=$? - -if [ $status -ne 0 ]; then - fail "Java command exited with exit status $status" -fi - -if [ ! -f "${DUMPFILE}" ]; then - fail "Dump file was not created: ${DUMPFILE}" -fi - -verify_heapdump ${DUMPFILE} - -if [ $? -ne 0 ]; then - fail "Verification of heap dump failed" -fi - -pass --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToFileMetaspace/TEST.properties 2018-06-12 16:04:44.625869285 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 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. -# -exclusiveAccess.dirs=. --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToFileMetaspace/TestDescription.java 2018-06-12 16:04:45.500866919 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017, 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 - * - * @summary converted from VM testbase heapdump/OnOOMToFileMetaspace. - * VM testbase keywords: [heapdump, feature_heapdump, nonconcurrent, jdk, quick] - * VM testbase readme: - * DESCRIPTION - * This test verifies -XX:+HeapDumpOnOutOfMemory VM option. It fills - * metaspace with classes till OutOfMemoryError is thrown and then - * verifies create heap dump with HprofParser. - * COMMENTS - * This test uses -XX:HeapDumpPath= option pointing to file. - * - * @library /vmTestbase - * /test/lib - * @run driver jdk.test.lib.FileInstaller . . - * @build jdk.test.lib.hprof.HprofParser - * heapdump.share.EatMemory - * @run shell/timeout=300 run.sh - */ - --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToFileMetaspace/run.sh 2018-06-12 16:04:46.404864474 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,53 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2014, 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. -# - -. $TESTSRC/../share/common.sh - -JAVA_OPTS="${JAVA_OPTS} -XX:-UseGCOverheadLimit -XX:MaxMetaspaceSize=64m" - -DUMPFILE=${DUMPBASE}/java.hprof - -rm -f ${DUMPFILE} - -JAVA_OPTS="${JAVA_OPTS} -Xmx`get_max_heap_size $JAVA_OPTS`" - -${JAVA} ${JAVA_OPTS} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${DUMPFILE} heapdump.share.EatMemory -metaspace - -status=$? - -if [ $status -ne 0 ]; then - fail "Java command exited with exit status $status" -fi - -if [ ! -f "${DUMPFILE}" ]; then - fail "Dump file was not created: ${DUMPFILE}" -fi - -verify_heapdump ${DUMPFILE} - -if [ $? -ne 0 ]; then - fail "Verification of heap dump failed" -fi - -pass --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToPath/TEST.properties 2018-06-12 16:04:47.272862127 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 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. -# -exclusiveAccess.dirs=. --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToPath/TestDescription.java 2018-06-12 16:04:48.109859864 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017, 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 - * - * @summary converted from VM testbase heapdump/OnOOMToPath. - * VM testbase keywords: [heapdump, feature_heapdump, nonconcurrent, jdk, quick] - * VM testbase readme: - * DESCRIPTION - * This test verifies -XX:+HeapDumpOnOutOfMemory VM option. It - * fills the heap with objects of different types till OutOfMemoryError - * and then verifies created heap dump with HprofParser. - * COMMENTS - * This test uses -XX:HeapDumpPath= option pointing to directory in which - * heap dump file should be created. - * - * @library /vmTestbase - * /test/lib - * @run driver jdk.test.lib.FileInstaller . . - * @build jdk.test.lib.hprof.HprofParser - * heapdump.share.EatMemory - * @run shell/timeout=300 run.sh - */ - --- old/test/hotspot/jtreg/vmTestbase/heapdump/OnOOMToPath/run.sh 2018-06-12 16:04:49.021857398 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,57 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2007, 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. -# - -. $TESTSRC/../share/common.sh - -JAVA_OPTS="${JAVA_OPTS} -XX:-UseGCOverheadLimit" - -DUMPPATH=${DUMPBASE}/dumps - -rm -rf ${DUMPPATH} - -mkdir -p ${DUMPPATH} - -JAVA_OPTS="${JAVA_OPTS} -Xmx`get_max_heap_size $JAVA_OPTS`" - -${JAVA} ${JAVA_OPTS} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${DUMPPATH} heapdump.share.EatMemory - -status=$? - -if [ $status -ne 0 ]; then - fail "Java command exited with exit status $status" -fi - -DUMPFILE=`ls ${DUMPPATH}/*` - -if [ ! -f "${DUMPFILE}" ]; then - fail "Dump file was not created: $DUMPPATH/\*" -fi - -verify_heapdump ${DUMPFILE} - -if [ $? -ne 0 ]; then - fail "Verification of heap dump failed" -fi - -pass --- old/test/hotspot/jtreg/vmTestbase/heapdump/README 2018-06-12 16:04:49.776855357 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,38 +0,0 @@ -Copyright (c) 2007, 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. - -heapdump/JMapHeap - test for heapdump for jmap on live process -heapdump/JMapHeapCore - test for heap for jmap on core file -heapdump/JMapMetaspace - test for heapdump for jmap on live process, fills metaspace with classes -heapdump/JMapMetaspaceCore - test for heap for jmap on core file, fills metaspace with classes -heapdump/OnOOMToFile - test for -XX:+HeapDumpOnOutOfMemoryError and -XX:HeapDumpPath option - for file. This test fills heap with objects of different types. -heapdump/OnOOMToFileMetaspace - the same test as OnOOMToFile, but it fills metaspace with classes -heapdump/OnOOMToPath - the same test as OnOOMToFile for -XX:HeapDumpPath option that points to directory -heapdump/OnOOMRun - test for -XX:OnOutOfMemoryError option --- old/test/hotspot/jtreg/vmTestbase/heapdump/share/EatMemory.java 2018-06-12 16:04:50.665852953 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2007, 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. - */ - -package heapdump.share; - -import java.util.List; -import java.util.ArrayList; -import java.io.InputStreamReader; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Random; - -import vm.share.ProcessUtils; - -import java.util.LinkedList; - -import nsk.share.gc.gp.classload.GeneratedClassProducer; - -/** - * This test eats memory by generating random garbage. - *

- * This program can eat either heap or metaspace using - * interned strings depending on parameter metaspace. After this, it - * can also force JVM to show dump, dump core or execute some command. - * The following command line switches are supported: - *

- * "-sleepTime" time to sleep - * "-signal" show dump after OOM - * "-metaspace" eat metaspace - * "-core" dump core after OOM - * "-exec command" execute command after OOM - */ -public class EatMemory { - private long sleepTime; - private boolean signal; - private boolean metaspace; - private boolean core; - private String exec; - private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - private long initialFactor = 50; - private long minChunk = 1000; - private long factor = 5; - private long chunk; - private Runtime runtime = Runtime.getRuntime(); - private int n = 0; - private final int arrayExtraSize = 12; - private final int stringLength = 128; - private byte[] reserved = new byte[(int) (runtime.maxMemory() / 20)]; - private List storage = new ArrayList(); - private List strings = new ArrayList(); - - /** - * @param sleepTime time to sleep - * @param signal true if need to force JVM to show dump (Ctrl-Break / Ctrl-/) after OOM - * @param metaspace true if need to eat metaspace - * @param core true if need to force JVM to dump core - * @param exec command to execute after OOM - */ - public EatMemory(long sleepTime, boolean signal, boolean metaspace, boolean core, String exec) { - this.sleepTime = sleepTime; - this.signal = signal; - this.metaspace = metaspace; - this.core = core; - this.exec = exec; - } - - private int getSize(long chunk, long factor) { - return (int) Math.min(Integer.MAX_VALUE, (chunk - arrayExtraSize) / factor); - } - - private Object create(long chunk) { - switch (++n % 8) { - case 0: - return new byte[getSize(chunk, 1)]; - case 1: - return new short[getSize(chunk, 2)]; - case 2: - return new char[getSize(chunk, 2)]; - case 3: - return new boolean[getSize(chunk, 1)]; - case 4: - return new long[getSize(chunk, 8)]; - case 5: - return new float[getSize(chunk, 4)]; - case 6: - return new double[getSize(chunk, 8)]; - case 7: - return new Object[getSize(chunk, 16)]; - default: - // Should never happen - return null; - } - } - - - public void eatHeap() { - try { - int[][] arrays = new int[Integer.MAX_VALUE / 2][]; - for (int i = 0; ; ++i) { - arrays[i] = new int[Integer.MAX_VALUE / 2]; - } - } catch (OutOfMemoryError x) { - reserved = null; - } - } - - public void eatMetaspace() { - try { - System.out.println("Starting eating metaspace..."); - GeneratedClassProducer gp = new GeneratedClassProducer(); - List lst = new LinkedList(); - System.out.println("... Oh, so tasty!"); - while (true) { - lst.add(gp.create(0)); - } - } catch (OutOfMemoryError e) { - } - } - - public void eatMemory() throws IOException { - if (metaspace) - eatMetaspace(); - else - eatHeap(); - reserved = null; - } - - /** - * Sleep some time to give system time to process a signal, start - * process, etc. - */ - private void sleepSome() { - try { - Thread.sleep(sleepTime); - } catch (InterruptedException e) { - } - } - - /** - * Throws an exception if execution was not successful. - */ - private void execute() throws IOException, InterruptedException { - int pid = ProcessUtils.getPid(); - if (pid < 0) { - throw new RuntimeException("Negative pid " + pid + "; Failed to executed " + exec); - } - exec = exec.replaceAll("%p", Integer.toString(pid)); - System.out.println("Executing " + exec); - Process process = Runtime.getRuntime().exec(exec); - sleepSome(); - process.waitFor(); - StringBuilder sb = copy(process.getInputStream(), System.out); - sb.append(copy(process.getErrorStream(), System.out)); - if (process.exitValue() != 0) { - // trying provide as much informative failure string - // hoping, it will be the last line in the error stream... - - - String failureCause = "Unknown"; - String allTheOutput = sb.toString(); - String[] lines = allTheOutput.split(System.getProperty("line.separator")); - - for (int i = lines.length - 1; i >= 0; i--) { - // Check that string is not empty - if (!lines[i].trim().equals("")) { - failureCause = lines[i]; - break; - } - } - throw new RuntimeException(failureCause); - } - } - - private StringBuilder copy(InputStream in, OutputStream out) throws IOException { - byte[] buff = new byte[1000]; - StringBuilder sb = new StringBuilder(); - while (in.available() != 0) { - n = in.read(buff, 0, buff.length); - out.write(buff, 0, n); - sb.append(new String(buff, 0, n)); - } - return sb; - } - - public void run() throws Exception { - eatMemory(); - if (signal) { - ProcessUtils.sendCtrlBreak(); - sleepSome(); - - } - if (exec != null) { - execute(); - } - if (core) { - /* - * We try to dump core here. - * On Unix systems a signal is sent to the process. We need to wait some time - * to give time to process it. On Windows systems, core dump is not supported - * and we just do not do anything in this case. - */ - boolean res = ProcessUtils.dumpCore(); - if (res) { - sleepSome(); - throw new RuntimeException("Signal sent, but core was not dumped"); - } - } - } - - public static void main(String[] args) throws Exception { - long sleepTime = 5000; - boolean signal = false; - boolean metaspace = false; - boolean core = false; - String exec = null; - for (int i = 0; i < args.length; ++i) { - if (args[i].equalsIgnoreCase("-sleepTime")) { - if (++i < args.length) { - long time = Long.parseLong(args[i]); - if (time != 0) - sleepTime = time; - } else - throw new RuntimeException("Argument expected after -sleepTime"); - } - if (args[i].equalsIgnoreCase("-signal")) - signal = true; - if (args[i].equalsIgnoreCase("-metaspace")) - metaspace = true; - if (args[i].equalsIgnoreCase("-core")) - core = true; - if (args[i].equalsIgnoreCase("-exec")) { - if (++i < args.length) - exec = args[i]; - else - throw new RuntimeException("Argument expected after -exec"); - } - } - new EatMemory(sleepTime, signal, metaspace, core, exec).run(); - } -} --- old/test/hotspot/jtreg/vmTestbase/heapdump/share/common.sh 2018-06-12 16:04:51.563850525 -0700 +++ /dev/null 2018-04-27 20:26:53.042636102 -0700 @@ -1,187 +0,0 @@ -#!/bin/bash -# Copyright (c) 2007, 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. - -# This script contains useful functions for testing heapdump -# feature of VM. - -: ${JAVA:="$TESTJAVA/bin/java"} -: ${JAVA_OPTS:="$TESTJAVAOPTS $TESTVMOPTS -cp $TESTCLASSPATH"} -: ${CP:="$TESTCLASSPATH"} -: ${TEST_CLEANUP:="false"} -: ${JMAP:="$TESTJAVA/bin/jmap"} -: ${JHSDB:="$TESTJAVA/bin/jhsdb"} - -export PATH=$PATH:$TESTNATIVEPATH -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TESTNATIVEPATH -export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$TESTNATIVEPATH - -if [ -z "${JAVA}" ]; then - echo JAVA variable is not set. - exit 1 -fi - -if [ -n "${testWorkDir}" ]; then - cd ${testWorkDir} -fi - -if [ -z "${DUMPBASE}" ]; then - DUMPBASE=. -fi -if [ -z "$DEBUGGER_JAVA_OPTS" ]; then - DEBUGGER_JAVA_OPTS="$JAVA_OPTS" -fi - -CORE_SUPPORTED=1 - -for opt in $DEBUGGER_JAVA_OPTS; do - case $opt in - -D*) - JMAP="$JMAP -J$opt" - ;; - esac -done - -export CORE_SUPPORTED - -# Verify heap dump -# This function starts HprofParser and looks for message "Server is ready." -# in output, in which case heap dump is verified. -verify_heapdump() { - filename=$1 - shift - echo Verifying ${filename} - echo ${JAVA} -cp $CP jdk.test.lib.hprof.HprofParser ${filename} - ${JAVA} -cp $CP jdk.test.lib.hprof.HprofParser ${filename} -} - -cleanup() { - result="$1" - if [ -n "$DUMPFILE" ]; then - if [ "$TEST_CLEANUP" != "false" ]; then - rm -f "$DUMPFILE" - else - gzip "$DUMPFILE" || true - fi - fi -} - -fail() { - message="$1" - res=1 - echo "$message" - echo "TEST FAILED" - cleanup $res - exit 1 -} - -pass() { - message="$1" - if [ -n "$message" ]; then - echo "$message" - fi - echo "TEST PASSED" - cleanup 0 - exit 0 -} - -# Parse VM options that have size argument and return it's value in bytes. -# Function applicable to -Xmn, -Xms, -Xms and all possible -XX: options. -parse_heap_size() { - OPTION=$1 - SIZE=0 - MULTIPLIER=0 - - # On Solaris sed don't support '+' quantificator, so * is used. - # There is no support for '?' too, so * is used instead. - # Generally speaking, there sed on Solaris support only basic REs. - case "$OPTION" in - -Xm*) - SIZE=`echo $OPTION | sed -e 's#-Xm[xns]\([0-9][0-9]*\).*#\1#'` - MULTIPLIER=`echo $OPTION | sed -e 's#-Xm[xns][0-9][0-9]*\([kKmMgG]*\)#\1#'` - ;; - -XX*) - SIZE=`echo $OPTION | sed -e 's#[^=][^=]*=\([0-9][0-9]*\).*#\1#'` - MULTIPLIER=`echo $OPTION | sed -e 's#[^=][^=]*=[0-9][0-9]*\([kKmMgG]*\)#\1#'` - ;; - esac - - case "$MULTIPLIER" in - k|K) - SIZE=$(( SIZE * 1024 )) - ;; - m|M) - SIZE=$(( SIZE * 1024 * 1024 )) - ;; - g|G) - SIZE=$(( SIZE * 1024 * 1024 * 1024 )) - ;; - esac - - echo $SIZE -} - -# Derivate max heap size from passed option list. -get_max_heap_size() { - MaxHeapSize= - InitialHeapSize= - MaxNewSize= - NewSize= - OldSize= - - for OPTION in "$@"; do - case "$OPTION" in - -Xmx*|-XX:MaxHeapSize=*) - MaxHeapSize=`parse_heap_size $OPTION` - ;; - -Xms*|-XX:InitialHeapSize=*) - InitialHeapSize=`parse_heap_size $OPTION` - ;; - -Xmn*|-XX:MaxNewSize=*) - MaxNewSize=`parse_heap_size $OPTION` - ;; - -XX:NewSize=*) - NewSize=`parse_heap_size $OPTION` - ;; - -XX:OldSize=*) - OldSize=`parse_heap_size $OPTION` - ;; - esac - done - - if [ -n "$MaxHeapSize" ]; then - echo "$MaxHeapSize" - elif [ -n "$InitialHeapSize" ]; then - echo "$InitialHeapSize" - elif [ -n "$MaxNewSize" -a -n "$OldSize" ]; then - echo $(( MaxHeapSize + OldSize )) - elif [ -n "$NewSize" -a -n "$OldSize" ]; then - echo $(( 2 * NewSize + OldSize )) - elif [ -n "$OldSize" ]; then - echo $(( 2 * OldSize )) - elif [ -n "$MaxNewSize" ]; then - echo $(( 2 * MaxNewSize )) - elif [ -n "$NewSize" ]; then - echo $(( 3 * NewSize )) - else - echo "128M" - fi -}