# HG changeset patch # User jwilhelm # Date 1433861334 -7200 # Node ID aa2436bfead2fa9c2dd707024340a0399612d526 # Parent 6cf349c0d1a5ece38e835f3fe3c72dbc2790dff4# Parent 5f705077cf7a692fde4792463f916222bdc0c424 Merge diff -r 6cf349c0d1a5 -r aa2436bfead2 jdk/test/com/sun/jdi/cds/CDSBreakpointTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/com/sun/jdi/cds/CDSBreakpointTest.java Tue Jun 09 16:48:54 2015 +0200 @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8054386 + * @summary java debugging test for CDS + * @modules jdk.jdi + * java.base/sun.misc + * java.management + * jdk.jartool/sun.tools.jar + * @library /lib/testlibrary + * @library .. + * @run compile -g ../BreakpointTest.java + * @run main CDSBreakpointTest + */ + +/* + * Launch the JDI BreakpointTest, which will set a debugger breakpoint in + * BreakpointTarg. BreakpointTarg is first dumped into the CDS archive, + * so this will test debugging a class in the archive. + */ + +public class CDSBreakpointTest extends CDSJDITest { + static String jarClasses[] = { + // BreakpointTarg is the only class we need in the archive. It will + // be launched by BreakpointTest as the debuggee application. Note, + // compiling BreakpointTest.java above will cause BreakpointTarg to + // be compiled since it is also in BreakpointTest.java. + "BreakpointTarg", + }; + static String testname = "BreakpointTest"; + + public static void main(String[] args) throws Exception { + runTest(testname, jarClasses); + } +} diff -r 6cf349c0d1a5 -r aa2436bfead2 jdk/test/com/sun/jdi/cds/CDSDeleteAllBkptsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/com/sun/jdi/cds/CDSDeleteAllBkptsTest.java Tue Jun 09 16:48:54 2015 +0200 @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8054386 + * @summary java debugging test for CDS + * @modules jdk.jdi + * java.base/sun.misc + * java.management + * jdk.jartool/sun.tools.jar + * @library /lib/testlibrary + * @library .. + * @run compile -g ../DeleteAllBkptsTest.java + * @run main CDSDeleteAllBkptsTest + */ + +/* + * Launch the JDI DeleteAllBkptsTest, which will set a debugger breakpoint in + * DeleteAllBkptsTarg and then clear them. DeleteAllBkptsTarg is first dumped + * into the CDS archive, so this will test debugging a class in the archive. + */ + +public class CDSDeleteAllBkptsTest extends CDSJDITest { + static String jarClasses[] = { + // DeleteAllBkptsTarg is the only class we need in the archive. It will + // be launched by DeleteAllBkptsTest as the debuggee application. Note, + // compiling DeleteAllBkptsTest.java above will cause DeleteAllBkptsTarg to + // be compiled since it is also in DeleteAllBkptsTest.java. + "DeleteAllBkptsTarg", + }; + static String testname = "DeleteAllBkptsTest"; + + public static void main(String[] args) throws Exception { + runTest(testname, jarClasses); + } +} diff -r 6cf349c0d1a5 -r aa2436bfead2 jdk/test/com/sun/jdi/cds/CDSFieldWatchpoints.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/com/sun/jdi/cds/CDSFieldWatchpoints.java Tue Jun 09 16:48:54 2015 +0200 @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8054386 + * @summary java debugging test for CDS + * @modules jdk.jdi + * java.base/sun.misc + * java.management + * jdk.jartool/sun.tools.jar + * @library /lib/testlibrary + * @library .. + * @run compile -g ../FieldWatchpoints.java + * @run main CDSFieldWatchpoints + */ + +/* + * Launch the JDI FieldWatchpoints test, which will setup field watchpoints in + * FieldWatchpointsDebugee. FieldWatchpointsDebugee is first dumped into the + * CDS archive, so this will test debugging a class in the archive. + */ + +public class CDSFieldWatchpoints extends CDSJDITest { + static String jarClasses[] = { + // FieldWatchpointsDebugee. A, and B are the only classes we need in the archive. + // FieldWatchpointsDebugee will be launched by FieldWatchpoints as the debuggee + // application. Note, compiling FieldWatchpoints.java above will cause + // FieldWatchpointsDebugee to be compiled since it is also in FieldWatchpoints.java. + "FieldWatchpointsDebugee", "A", "B", + }; + static String testname = "FieldWatchpoints"; + + public static void main(String[] args) throws Exception { + runTest(testname, jarClasses); + } +} diff -r 6cf349c0d1a5 -r aa2436bfead2 jdk/test/com/sun/jdi/cds/CDSJDITest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/com/sun/jdi/cds/CDSJDITest.java Tue Jun 09 16:48:54 2015 +0200 @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2013, 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. + */ + +/* + * Helper superclass for launching JDI tests out of the CDS archive. +*/ + +import jdk.testlibrary.OutputAnalyzer; +import jdk.testlibrary.ProcessTools; + +import java.io.*; +import java.util.ArrayList; +import sun.tools.jar.Main; + +public class CDSJDITest { + private static final String classesDir = System.getProperty("test.classes"); + + public static void runTest(String testname, String[] jarClasses) throws Exception { + File jarClasslistFile = makeClassList(jarClasses); + String appJar = buildJar(testname, jarClasses); + + // These are the arguments passed to createJavaProcessBuilder() to launch + // the JDI test. + String[] testArgs = { + // JVM Args: + // These first three properties are setup by jtreg, and must be passed + // to the JDI test subprocess because it needs them in order to + // pass them to the subprocess it will create for the debuggee. This + // is how the JPRT -javaopts are passed to the debggee. See + // VMConnection.getDebuggeeVMOptions(). + getPropOpt("test.classes"), + getPropOpt("test.java.opts"), + getPropOpt("test.vm.opts"), + // Pass -showversion to the JDI test just so we get a bit of trace output. + "-showversion", + // Main class: + testname, + // Args to the Main Class: + // These argument all follow the above argument, and are + // in fact passed to .main() as java arguments. will + // pass them as JVM arguments to the debuggee process it creates. + "-Xbootclasspath/a:" + appJar, + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+TraceClassPaths", + "-XX:SharedArchiveFile=./SharedArchiveFile.jsa", + "-Xshare:on", + "-showversion" + }; + + // Dump the archive + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xbootclasspath/a:" + appJar, + "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./SharedArchiveFile.jsa", + "-XX:ExtraSharedClassListFile=" + jarClasslistFile.getPath(), + "-Xshare:dump"); + OutputAnalyzer outputDump = executeAndLog(pb, "exec"); + for (String jarClass : jarClasses) { + outputDump.shouldNotContain("Cannot find " + jarClass); + } + outputDump.shouldContain("Loading classes to share"); + outputDump.shouldHaveExitValue(0); + + // Run the test specified JDI test + pb = ProcessTools.createJavaProcessBuilder(true, testArgs); + OutputAnalyzer outputRun = executeAndLog(pb, "exec"); + try { + outputRun.shouldContain("sharing"); + outputRun.shouldHaveExitValue(0); + } catch (RuntimeException e) { + outputRun.shouldContain("Unable to use shared archive"); + outputRun.shouldHaveExitValue(1); + } + } + + public static String getPropOpt(String prop) { + String propVal = System.getProperty(prop); + if (propVal == null) propVal = ""; + System.out.println(prop + ": '" + propVal + "'"); + return "-D" + prop + "=" + propVal; + } + + public static File makeClassList(String appClasses[]) throws Exception { + File classList = getOutputFile("test.classlist"); + FileOutputStream fos = new FileOutputStream(classList); + PrintStream ps = new PrintStream(fos); + + addToClassList(ps, appClasses); + + ps.close(); + fos.close(); + + return classList; + } + + public static OutputAnalyzer executeAndLog(ProcessBuilder pb, String logName) throws Exception { + long started = System.currentTimeMillis(); + OutputAnalyzer output = ProcessTools.executeProcess(pb); + writeFile(getOutputFile(logName + ".stdout"), output.getStdout()); + writeFile(getOutputFile(logName + ".stderr"), output.getStderr()); + System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]"); + System.out.println("[STDOUT]\n" + output.getStdout()); + System.out.println("[STDERR]\n" + output.getStderr()); + return output; + } + + private static void writeFile(File file, String content) throws Exception { + FileOutputStream fos = new FileOutputStream(file); + PrintStream ps = new PrintStream(fos); + ps.print(content); + ps.close(); + fos.close(); + } + + public static File getOutputFile(String name) { + File dir = new File(System.getProperty("test.classes", ".")); + return new File(dir, getTestNamePrefix() + name); + } + + private static void addToClassList(PrintStream ps, String classes[]) throws IOException { + if (classes != null) { + for (String s : classes) { + ps.println(s); + } + } + } + + private static String testNamePrefix; + + private static String getTestNamePrefix() { + if (testNamePrefix == null) { + StackTraceElement[] elms = (new Throwable()).getStackTrace(); + if (elms.length > 0) { + for (StackTraceElement n: elms) { + if ("main".equals(n.getMethodName())) { + testNamePrefix = n.getClassName() + "-"; + break; + } + } + } + + if (testNamePrefix == null) { + testNamePrefix = ""; + } + } + return testNamePrefix; + } + + private static String buildJar(String jarName, String ...classNames) + throws Exception { + + String jarFullName = classesDir + File.separator + jarName + ".jar"; + createSimpleJar(classesDir, jarFullName, classNames); + return jarFullName; + } + + private static void createSimpleJar(String jarClassesDir, String jarName, + String[] classNames) throws Exception { + + ArrayList args = new ArrayList(); + args.add("cf"); + args.add(jarName); + addJarClassArgs(args, jarClassesDir, classNames); + createJar(args); + } + + private static void addJarClassArgs(ArrayList args, String jarClassesDir, + String[] classNames) { + + for (String name : classNames) { + args.add("-C"); + args.add(jarClassesDir); + args.add(name + ".class"); + } + } + + private static void createJar(ArrayList args) { + Main jarTool = new Main(System.out, System.err, "jar"); + if (!jarTool.run(args.toArray(new String[1]))) { + throw new RuntimeException("jar operation failed"); + } + } +} diff -r 6cf349c0d1a5 -r aa2436bfead2 jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java --- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java Thu Jun 04 15:38:00 2015 -0700 +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java Tue Jun 09 16:48:54 2015 +0200 @@ -278,16 +278,46 @@ } /** - * Create ProcessBuilder using the java launcher from the jdk to be tested - * and with any platform specific arguments prepended + * Create ProcessBuilder using the java launcher from the jdk to be tested, + * and with any platform specific arguments prepended. + * + * @param command Arguments to pass to the java command. + * @return The ProcessBuilder instance representing the java command. */ public static ProcessBuilder createJavaProcessBuilder(String... command) throws Exception { + return createJavaProcessBuilder(false, command); + } + + /** + * Create ProcessBuilder using the java launcher from the jdk to be tested, + * and with any platform specific arguments prepended. + * + * @param addTestVmAndJavaOptions If true, adds test.vm.opts and test.java.opts + * to the java arguments. + * @param command Arguments to pass to the java command. + * @return The ProcessBuilder instance representing the java command. + */ + public static ProcessBuilder createJavaProcessBuilder(boolean addTestVmAndJavaOptions, String... command) throws Exception { String javapath = JDKToolFinder.getJDKTool("java"); ArrayList args = new ArrayList<>(); args.add(javapath); Collections.addAll(args, getPlatformSpecificVMArgs()); + + if (addTestVmAndJavaOptions) { + // -cp is needed to make sure the same classpath is used whether the test is + // run in AgentVM mode or OtherVM mode. It was added to the hotspot version + // of this API as part of 8077608. However, for the jdk version it is only + // added when addTestVmAndJavaOptions is true in order to minimize + // disruption to existing JDK tests, which have yet to be tested with -cp + // being added. At some point -cp should always be added to be consistent + // with what the hotspot version does. + args.add("-cp"); + args.add(System.getProperty("java.class.path")); + Collections.addAll(args, Utils.getTestJavaOpts()); + } + Collections.addAll(args, command); // Reporting