Merge
authoramurillo
Fri, 26 Jun 2015 19:11:19 -0700
changeset 31465 2c323e090b51
parent 31270 e6470b24700d (current diff)
parent 31464 256418c222ae (diff)
child 31466 3c041fe4cc7d
child 31668 042a51bddfa5
Merge
--- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/GHASH.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/GHASH.java	Fri Jun 26 19:11:19 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2015 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -62,14 +62,16 @@
 
     private static final int AES_BLOCK_SIZE = 16;
 
-    // Multiplies state0, state1 by V0, V1.
-    private void blockMult(long V0, long V1) {
+    // Multiplies state[0], state[1] by subkeyH[0], subkeyH[1].
+    private static void blockMult(long[] st, long[] subH) {
         long Z0 = 0;
         long Z1 = 0;
+        long V0 = subH[0];
+        long V1 = subH[1];
         long X;
 
-        // Separate loops for processing state0 and state1.
-        X = state0;
+        // Separate loops for processing state[0] and state[1].
+        X = st[0];
         for (int i = 0; i < 64; i++) {
             // Zi+1 = Zi if bit i of x is 0
             long mask = X >> 63;
@@ -89,7 +91,7 @@
             X <<= 1;
         }
 
-        X = state1;
+        X = st[1];
         for (int i = 64; i < 127; i++) {
             // Zi+1 = Zi if bit i of x is 0
             long mask = X >> 63;
@@ -115,15 +117,18 @@
         Z1 ^= V1 & mask;
 
         // Save result.
-        state0 = Z0;
-        state1 = Z1;
+        st[0] = Z0;
+        st[1] = Z1;
+
     }
 
+    /* subkeyH and state are stored in long[] for GHASH intrinsic use */
+
     // hash subkey H; should not change after the object has been constructed
-    private final long subkeyH0, subkeyH1;
+    private final long[] subkeyH;
 
     // buffer for storing hash
-    private long state0, state1;
+    private final long[] state;
 
     // variables for save/restore calls
     private long stateSave0, stateSave1;
@@ -141,8 +146,10 @@
         if ((subkeyH == null) || subkeyH.length != AES_BLOCK_SIZE) {
             throw new ProviderException("Internal error");
         }
-        this.subkeyH0 = getLong(subkeyH, 0);
-        this.subkeyH1 = getLong(subkeyH, 8);
+        state = new long[2];
+        this.subkeyH = new long[2];
+        this.subkeyH[0] = getLong(subkeyH, 0);
+        this.subkeyH[1] = getLong(subkeyH, 8);
     }
 
     /**
@@ -151,33 +158,30 @@
      * this object for different data w/ the same H.
      */
     void reset() {
-        state0 = 0;
-        state1 = 0;
+        state[0] = 0;
+        state[1] = 0;
     }
 
     /**
      * Save the current snapshot of this GHASH object.
      */
     void save() {
-        stateSave0 = state0;
-        stateSave1 = state1;
+        stateSave0 = state[0];
+        stateSave1 = state[1];
     }
 
     /**
      * Restores this object using the saved snapshot.
      */
     void restore() {
-        state0 = stateSave0;
-        state1 = stateSave1;
+        state[0] = stateSave0;
+        state[1] = stateSave1;
     }
 
-    private void processBlock(byte[] data, int ofs) {
-        if (data.length - ofs < AES_BLOCK_SIZE) {
-            throw new RuntimeException("need complete block");
-        }
-        state0 ^= getLong(data, ofs);
-        state1 ^= getLong(data, ofs + 8);
-        blockMult(subkeyH0, subkeyH1);
+    private static void processBlock(byte[] data, int ofs, long[] st, long[] subH) {
+        st[0] ^= getLong(data, ofs);
+        st[1] ^= getLong(data, ofs + 8);
+        blockMult(st, subH);
     }
 
     void update(byte[] in) {
@@ -185,22 +189,57 @@
     }
 
     void update(byte[] in, int inOfs, int inLen) {
-        if (inLen - inOfs > in.length) {
-            throw new RuntimeException("input length out of bound");
+        if (inLen == 0) {
+            return;
+        }
+        ghashRangeCheck(in, inOfs, inLen, state, subkeyH);
+        processBlocks(in, inOfs, inLen/AES_BLOCK_SIZE, state, subkeyH);
+    }
+
+    private static void ghashRangeCheck(byte[] in, int inOfs, int inLen, long[] st, long[] subH) {
+        if (inLen < 0) {
+            throw new RuntimeException("invalid input length: " + inLen);
+        }
+        if (inOfs < 0) {
+            throw new RuntimeException("invalid offset: " + inOfs);
+        }
+        if (inLen > in.length - inOfs) {
+            throw new RuntimeException("input length out of bound: " +
+                                       inLen + " > " + (in.length - inOfs));
         }
         if (inLen % AES_BLOCK_SIZE != 0) {
-            throw new RuntimeException("input length unsupported");
+            throw new RuntimeException("input length/block size mismatch: " +
+                                       inLen);
         }
 
-        for (int i = inOfs; i < (inOfs + inLen); i += AES_BLOCK_SIZE) {
-            processBlock(in, i);
+        // These two checks are for C2 checking
+        if (st.length != 2) {
+            throw new RuntimeException("internal state has invalid length: " +
+                                       st.length);
+        }
+        if (subH.length != 2) {
+            throw new RuntimeException("internal subkeyH has invalid length: " +
+                                       subH.length);
+        }
+    }
+    /*
+     * This is an intrinsified method.  The method's argument list must match
+     * the hotspot signature.  This method and methods called by it, cannot
+     * throw exceptions or allocate arrays as it will breaking intrinsics
+     */
+    private static void processBlocks(byte[] data, int inOfs, int blocks, long[] st, long[] subH) {
+        int offset = inOfs;
+        while (blocks > 0) {
+            processBlock(data, offset, st, subH);
+            blocks--;
+            offset += AES_BLOCK_SIZE;
         }
     }
 
     byte[] digest() {
         byte[] result = new byte[AES_BLOCK_SIZE];
-        putLong(result, 0, state0);
-        putLong(result, 8, state1);
+        putLong(result, 0, state[0]);
+        putLong(result, 8, state[1]);
         reset();
         return result;
     }
--- a/jdk/test/com/sun/crypto/provider/Cipher/AES/TestGHASH.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/com/sun/crypto/provider/Cipher/AES/TestGHASH.java	Fri Jun 26 19:11:19 2015 -0700
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015, Red Hat, Inc.
+ * Copyright (c) 2015, Oracle, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +25,14 @@
 /*
  * @test
  * @bug 8069072
- * @summary Test vectors for com.sun.crypto.provider.GHASH
+ * @summary Test vectors for com.sun.crypto.provider.GHASH.
+ *
+ * Single iteration to verify software-only GHASH algorithm.
+ * @run main TestGHASH
+ *
+ * Multi-iteration to verify test intrinsics GHASH, if available.
+ * Many iterations are needed so we are sure hotspot will use intrinsic
+ * @run main TestGHASH -n 10000
  */
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
@@ -124,43 +132,55 @@
 
     public static void main(String[] args) throws Exception {
         TestGHASH test;
-        if (args.length == 0) {
-            test = new TestGHASH("com.sun.crypto.provider.GHASH");
-        } else {
-            test = new TestGHASH(args[0]);
+        String test_class = "com.sun.crypto.provider.GHASH";
+        int i = 0;
+        int num_of_loops = 1;
+        while (args.length > i) {
+            if (args[i].compareTo("-c") == 0) {
+                test_class = args[++i];
+            } else if (args[i].compareTo("-n") == 0) {
+                num_of_loops = Integer.parseInt(args[++i]);
+            }
+            i++;
         }
 
-        // Test vectors from David A. McGrew, John Viega,
-        // "The Galois/Counter Mode of Operation (GCM)", 2005.
-        // <http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf>
+        System.out.println("Running " + num_of_loops + " iterations.");
+        test = new TestGHASH(test_class);
+        i = 0;
 
-        test.check(1, "66e94bd4ef8a2c3b884cfa59ca342b2e", "", "",
-                "00000000000000000000000000000000");
-        test.check(2,
-                "66e94bd4ef8a2c3b884cfa59ca342b2e", "",
-                "0388dace60b6a392f328c2b971b2fe78",
-                "f38cbb1ad69223dcc3457ae5b6b0f885");
-        test.check(3,
-                "b83b533708bf535d0aa6e52980d53b78", "",
-                "42831ec2217774244b7221b784d0d49c" +
-                "e3aa212f2c02a4e035c17e2329aca12e" +
-                "21d514b25466931c7d8f6a5aac84aa05" +
-                "1ba30b396a0aac973d58e091473f5985",
-                "7f1b32b81b820d02614f8895ac1d4eac");
-        test.check(4,
-                "b83b533708bf535d0aa6e52980d53b78",
-                "feedfacedeadbeeffeedfacedeadbeef" + "abaddad2",
-                "42831ec2217774244b7221b784d0d49c" +
-                "e3aa212f2c02a4e035c17e2329aca12e" +
-                "21d514b25466931c7d8f6a5aac84aa05" +
-                "1ba30b396a0aac973d58e091",
-                "698e57f70e6ecc7fd9463b7260a9ae5f");
-        test.check(5, "b83b533708bf535d0aa6e52980d53b78",
-                "feedfacedeadbeeffeedfacedeadbeef" + "abaddad2",
-                "61353b4c2806934a777ff51fa22a4755" +
-                "699b2a714fcdc6f83766e5f97b6c7423" +
-                "73806900e49f24b22b097544d4896b42" +
-                "4989b5e1ebac0f07c23f4598",
-                "df586bb4c249b92cb6922877e444d37b");
+        while (num_of_loops > i) {
+            // Test vectors from David A. McGrew, John Viega,
+            // "The Galois/Counter Mode of Operation (GCM)", 2005.
+            // <http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf>
+            test.check(1, "66e94bd4ef8a2c3b884cfa59ca342b2e", "", "",
+                       "00000000000000000000000000000000");
+            test.check(2,
+                       "66e94bd4ef8a2c3b884cfa59ca342b2e", "",
+                       "0388dace60b6a392f328c2b971b2fe78",
+                       "f38cbb1ad69223dcc3457ae5b6b0f885");
+            test.check(3,
+                       "b83b533708bf535d0aa6e52980d53b78", "",
+                       "42831ec2217774244b7221b784d0d49c" +
+                       "e3aa212f2c02a4e035c17e2329aca12e" +
+                       "21d514b25466931c7d8f6a5aac84aa05" +
+                       "1ba30b396a0aac973d58e091473f5985",
+                       "7f1b32b81b820d02614f8895ac1d4eac");
+            test.check(4,
+                       "b83b533708bf535d0aa6e52980d53b78",
+                       "feedfacedeadbeeffeedfacedeadbeef" + "abaddad2",
+                       "42831ec2217774244b7221b784d0d49c" +
+                       "e3aa212f2c02a4e035c17e2329aca12e" +
+                       "21d514b25466931c7d8f6a5aac84aa05" +
+                       "1ba30b396a0aac973d58e091",
+                       "698e57f70e6ecc7fd9463b7260a9ae5f");
+            test.check(5, "b83b533708bf535d0aa6e52980d53b78",
+                       "feedfacedeadbeeffeedfacedeadbeef" + "abaddad2",
+                       "61353b4c2806934a777ff51fa22a4755" +
+                       "699b2a714fcdc6f83766e5f97b6c7423" +
+                       "73806900e49f24b22b097544d4896b42" +
+                       "4989b5e1ebac0f07c23f4598",
+                       "df586bb4c249b92cb6922877e444d37b");
+            i++;
+        }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jdi/cds/CDSBreakpointTest.java	Fri Jun 26 19:11:19 2015 -0700
@@ -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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jdi/cds/CDSDeleteAllBkptsTest.java	Fri Jun 26 19:11:19 2015 -0700
@@ -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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jdi/cds/CDSFieldWatchpoints.java	Fri Jun 26 19:11:19 2015 -0700
@@ -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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jdi/cds/CDSJDITest.java	Fri Jun 26 19:11:19 2015 -0700
@@ -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 <testname> argument, and are
+            // in fact passed to <testname>.main() as java arguments. <testname> 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<String> args = new ArrayList<String>();
+        args.add("cf");
+        args.add(jarName);
+        addJarClassArgs(args, jarClassesDir, classNames);
+        createJar(args);
+    }
+
+    private static void addJarClassArgs(ArrayList<String> args, String jarClassesDir,
+        String[] classNames) {
+
+        for (String name : classNames) {
+            args.add("-C");
+            args.add(jarClassesDir);
+            args.add(name + ".class");
+        }
+    }
+
+    private static void createJar(ArrayList<String> args) {
+        Main jarTool = new Main(System.out, System.err, "jar");
+        if (!jarTool.run(args.toArray(new String[1]))) {
+            throw new RuntimeException("jar operation failed");
+        }
+    }
+}
--- a/jdk/test/com/sun/tools/attach/BasicTests.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/com/sun/tools/attach/BasicTests.java	Fri Jun 26 19:11:19 2015 -0700
@@ -21,17 +21,21 @@
  * questions.
  */
 
-import com.sun.tools.attach.*;
+import java.io.File;
+import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.io.IOException;
+import java.util.List;
 import java.util.Properties;
-import java.util.List;
-import java.io.File;
+
 import jdk.testlibrary.OutputAnalyzer;
-import jdk.testlibrary.JDKToolLauncher;
+import jdk.testlibrary.ProcessThread;
 import jdk.testlibrary.ProcessTools;
-import jdk.testlibrary.ProcessThread;
+
+import com.sun.tools.attach.AgentInitializationException;
+import com.sun.tools.attach.AgentLoadException;
+import com.sun.tools.attach.VirtualMachine;
+import com.sun.tools.attach.VirtualMachineDescriptor;
 
 /*
  * @test
--- a/jdk/test/com/sun/tools/attach/RunnerUtil.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/com/sun/tools/attach/RunnerUtil.java	Fri Jun 26 19:11:19 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -48,7 +48,7 @@
      */
     public static ProcessThread startApplication(String... additionalOpts) throws Throwable {
         String classpath = System.getProperty("test.class.path", ".");
-        String[] myArgs = concat(additionalOpts, new String [] { "-Dattach.test=true", "-classpath", classpath, "Application" });
+        String[] myArgs = concat(additionalOpts, new String [] { "-XX:+UsePerfData", "-Dattach.test=true", "-classpath", classpath, "Application" });
         String[] args = Utils.addTestJavaOpts(myArgs);
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
         ProcessThread pt = new ProcessThread("runApplication", (line) -> line.equals(Application.READY_MSG), pb);
--- a/jdk/test/javax/management/loading/MLetCLR/MLetCommand.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/javax/management/loading/MLetCLR/MLetCommand.java	Fri Jun 26 19:11:19 2015 -0700
@@ -31,7 +31,7 @@
  * @modules java.management
  * @run clean MLetCommand
  * @run build MLetCommand
- * @run main/othervm/policy=policy MLetCommand
+ * @run main/othervm/java.security.policy=policy MLetCommand
  */
 
 import javax.management.MBeanServer;
--- a/jdk/test/javax/management/modelmbean/ModelMBeanInfoSupport/GetAllDescriptorsTest.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/javax/management/modelmbean/ModelMBeanInfoSupport/GetAllDescriptorsTest.java	Fri Jun 26 19:11:19 2015 -0700
@@ -30,7 +30,7 @@
  * @modules java.management
  * @run clean GetAllDescriptorsTest
  * @run build GetAllDescriptorsTest
- * @run main/othervm/policy=policy  GetAllDescriptorsTest
+ * @run main/othervm/java.security.policy=policy  GetAllDescriptorsTest
  */
 
 import java.lang.reflect.*;
--- a/jdk/test/javax/management/modelmbean/SimpleModelMBean/SimpleModelMBeanCommand.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/javax/management/modelmbean/SimpleModelMBean/SimpleModelMBeanCommand.java	Fri Jun 26 19:11:19 2015 -0700
@@ -31,7 +31,7 @@
  * @modules java.management
  * @run clean SimpleModelMBeanCommand
  * @run build SimpleModelMBeanCommand
- * @run main/othervm/policy=policy  SimpleModelMBeanCommand
+ * @run main/othervm/java.security.policy=policy  SimpleModelMBeanCommand
  */
 
 import java.lang.reflect.*;
--- a/jdk/test/javax/management/remote/mandatory/notif/DeadListenerTest.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/javax/management/remote/mandatory/notif/DeadListenerTest.java	Fri Jun 26 19:11:19 2015 -0700
@@ -27,6 +27,7 @@
  * @summary Test that a listener can be removed remotely from an MBean that no longer exists.
  * @modules java.management/com.sun.jmx.remote.internal
  * @author Eamonn McManus
+ * @run main/othervm -XX:+UsePerfData DeadListenerTest
  */
 
 import com.sun.jmx.remote.internal.ServerNotifForwarder;
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java	Fri Jun 26 19:11:19 2015 -0700
@@ -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<String> 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
--- a/jdk/test/sun/management/jmxremote/bootstrap/LocalManagementTest.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/sun/management/jmxremote/bootstrap/LocalManagementTest.java	Fri Jun 26 19:11:19 2015 -0700
@@ -21,14 +21,15 @@
  * questions.
  */
 
-import java.io.File;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
+import jdk.testlibrary.ProcessTools;
+import jdk.testlibrary.Utils;
+
 /**
  * @test
  * @library /lib/testlibrary
@@ -39,14 +40,10 @@
  *          both agent properties and jvmstat buffer.
  * @modules java.management/sun.management
  * @build jdk.testlibrary.* TestManager TestApplication
- * @run main/othervm/timeout=300 -XX:+UsePerfData LocalManagementTest
+ * @run main/othervm/timeout=300 LocalManagementTest
  */
-
-import jdk.testlibrary.ProcessTools;
-
 public class LocalManagementTest {
     private static final String TEST_CLASSPATH = System.getProperty("test.class.path");
-    private static final String TEST_JDK = System.getProperty("test.jdk");
 
     public static void main(String[] args) throws Exception {
         int failures = 0;
@@ -96,6 +93,8 @@
 
     private static boolean doTest(String testId, String arg) throws Exception {
         List<String> args = new ArrayList<>();
+        args.add("-XX:+UsePerfData");
+        args.addAll(Utils.getVmOptions());
         args.add("-cp");
         args.add(TEST_CLASSPATH);
 
--- a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java	Fri Jun 26 19:11:19 2015 -0700
@@ -21,6 +21,7 @@
  * questions.
  */
 
+import java.io.EOFException;
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
@@ -36,7 +37,6 @@
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -45,6 +45,7 @@
 import javax.net.ssl.SSLHandshakeException;
 
 import jdk.testlibrary.ProcessTools;
+import jdk.testlibrary.Utils;
 import sun.management.Agent;
 import sun.management.AgentConfigurationError;
 
@@ -155,7 +156,28 @@
     }
 
     private static void testConnect(int port, int rmiPort) throws Exception {
+        EOFException lastException = null;
+        // factor adjusted timeout (5 seconds) for the RMI to become available
+        long timeout = System.currentTimeMillis() + Utils.adjustTimeout(5000);
+        do {
+            try {
+                doTestConnect(port, rmiPort);
+                lastException = null;
+            } catch (EOFException e) {
+                lastException = e;
+                System.out.println("Error establishing RMI connection. Retrying in 500ms.");
+                Thread.sleep(500);
+            }
+        } while (lastException != null && System.currentTimeMillis() < timeout);
 
+        if (lastException != null) {
+            // didn't manage to get the RMI running in time
+            // rethrow the exception
+            throw lastException;
+        }
+    }
+
+    private static void doTestConnect(int port, int rmiPort) throws Exception {
         dbg_print("RmiRegistry lookup...");
 
         dbg_print("Using port: " + port);
--- a/jdk/test/sun/management/jmxremote/startstop/ManagementAgentJcmd.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/sun/management/jmxremote/startstop/ManagementAgentJcmd.java	Fri Jun 26 19:11:19 2015 -0700
@@ -196,7 +196,9 @@
             l.addToolArg(cmd);
         }
 
-        StringBuilder output = new StringBuilder();
+        // this buffer will get filled in different threads
+        //   -> must be the synchronized StringBuffer
+        StringBuffer output = new StringBuffer();
 
         AtomicBoolean portUnavailable = new AtomicBoolean(false);
         Process p = ProcessTools.startProcess(
--- a/jdk/test/sun/tools/jmap/heapconfig/TmtoolTestScenario.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/sun/tools/jmap/heapconfig/TmtoolTestScenario.java	Fri Jun 26 19:11:19 2015 -0700
@@ -38,7 +38,7 @@
 
 public class TmtoolTestScenario {
 
-    private final ArrayList<String> toolOutput = new ArrayList();
+    private final ArrayList<String> toolOutput = new ArrayList<String>();
     private LingeredApp theApp = null;
     private final String toolName;
     private final String[] toolArgs;
@@ -72,7 +72,7 @@
      */
     public Map<String, String>  parseFlagsFinal() {
         List<String> astr = theApp.getAppOutput();
-        Map<String, String> vmMap = new HashMap();
+        Map<String, String> vmMap = new HashMap<String, String>();
 
         for (String line : astr) {
             String[] lv = line.trim().split("\\s+");
@@ -94,7 +94,10 @@
         System.out.println("Starting LingeredApp");
         try {
             try {
-                theApp = LingeredApp.startApp(vmArgs);
+                List<String> vmArgsExtended = new ArrayList<String>();
+                vmArgsExtended.add("-XX:+UsePerfData");
+                vmArgsExtended.addAll(vmArgs);
+                theApp = LingeredApp.startApp(vmArgsExtended);
 
                 System.out.println("Starting " + toolName + " against " + theApp.getPid());
                 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK(toolName);
@@ -120,7 +123,7 @@
 
                 return toolProcess.exitValue();
             } finally {
-                theApp.stopApp();
+                LingeredApp.stopApp(theApp);
             }
         } catch (IOException | InterruptedException ex) {
             throw new RuntimeException("Test ERROR " + ex, ex);
--- a/jdk/test/sun/tools/jps/JpsHelper.java	Fri Jun 26 21:34:34 2015 +0000
+++ b/jdk/test/sun/tools/jps/JpsHelper.java	Fri Jun 26 19:11:19 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -94,9 +94,10 @@
     }
 
     /**
-     * VM arguments to start test application with
+     * VM arguments to start test application with.
+     * -XX:+UsePerfData is required for running the tests on embedded platforms.
      */
-    public static final String[] VM_ARGS = {"-Xmx512m", "-XX:+PrintGCDetails"};
+    public static final String[] VM_ARGS = {"-XX:+UsePerfData", "-Xmx512m", "-XX:+PrintGCDetails"};
     /**
      * VM flag to start test application with
      */