Merge
authormseledtsov
Tue, 18 Apr 2017 23:52:58 +0200
changeset 46390 cb3afb654b77
parent 46388 d7a164ad6b7f (current diff)
parent 46389 d55896236dfd (diff)
child 46391 e33ea5371600
child 46394 c5bfe8f7bb1e
Merge
hotspot/test/runtime/SharedArchiveFile/CDSTestUtils.java
--- a/hotspot/test/runtime/SharedArchiveFile/ArchiveDoesNotExist.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/ArchiveDoesNotExist.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, 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
@@ -33,7 +33,8 @@
  * @run main ArchiveDoesNotExist
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSOptions;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 import java.io.File;
 
@@ -45,27 +46,22 @@
         if (cdsFile.exists())
             throw new RuntimeException("Test error: cds file already exists");
 
-        // Sharing: on
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-           "-XX:+UnlockDiagnosticVMOptions",
-           "-XX:SharedArchiveFile=./" + fileName,
-           "-Xshare:on",
-           "-version");
+        CDSOptions opts = (new CDSOptions()).setArchiveName(fileName);
 
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldContain("Specified shared archive not found");
-        output.shouldHaveExitValue(1);
+        // -Xshare=on
+        OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
+        if (!CDSTestUtils.isUnableToMap(out)) {
+            out.shouldContain("Specified shared archive not found")
+               .shouldHaveExitValue(1);
+        }
 
-        // Sharing: auto
-        pb = ProcessTools.createJavaProcessBuilder(
-           "-XX:+UnlockDiagnosticVMOptions",
-           "-XX:SharedArchiveFile=./" + fileName,
-           "-Xshare:auto",
-           "-version");
-
-        output = new OutputAnalyzer(pb.start());
-        output.shouldMatch("(java|openjdk) version");
-        output.shouldNotContain("sharing");
-        output.shouldHaveExitValue(0);
+        // -Xshare=auto
+        opts.setXShareMode("auto");
+        out = CDSTestUtils.runWithArchive(opts);
+        if (!CDSTestUtils.isUnableToMap(out)) {
+            out.shouldMatch("(java|openjdk) version")
+               .shouldNotContain("sharing")
+               .shouldHaveExitValue(0);
+        }
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/BootAppendTests.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/BootAppendTests.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -43,6 +43,8 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
+import jdk.test.lib.cds.CDSOptions;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 
@@ -67,45 +69,45 @@
 
     public static void main(String... args) throws Exception {
         dumpArchive();
+
+        logTestCase("1");
         testBootAppendModuleClass();
+
+        log("TESTCASE: 2");
         testBootAppendDuplicateModuleClass();
+
+        logTestCase("3");
         testBootAppendExcludedModuleClass();
+
+        logTestCase("4");
         testBootAppendDuplicateExcludedModuleClass();
+
+        logTestCase("5");
         testBootAppendClass();
     }
 
+    private static void logTestCase(String msg) {
+        System.out.println();
+        System.out.printf("TESTCASE: %s", msg);
+        System.out.println();
+    }
+
     static void dumpArchive() throws Exception {
         // create the classlist
-        File classlist = new File(new File(System.getProperty("test.classes", ".")),
-                                  "BootAppendTest.classlist");
-        FileOutputStream fos = new FileOutputStream(classlist);
-        PrintStream ps = new PrintStream(fos);
-        for (String s : ARCHIVE_CLASSES) {
-            ps.println(s);
-        }
-        ps.close();
-        fos.close();
+        File classlist = CDSTestUtils.makeClassList(ARCHIVE_CLASSES);
 
         // build jar files
         appJar = ClassFileInstaller.writeJar("app.jar", APP_CLASS);
         bootAppendJar = ClassFileInstaller.writeJar("bootAppend.jar",
             BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS, BOOT_APPEND_CLASS);
 
-        // dump
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=./BootAppendTests.jsa",
-            "-XX:SharedClassListFile=" + classlist.getPath(),
-            "-XX:+PrintSharedSpaces",
-            "-Xbootclasspath/a:" + bootAppendJar,
-            "-Xshare:dump");
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldContain("Loading classes to share")
-              .shouldHaveExitValue(0);
 
+        OutputAnalyzer out = CDSTestUtils.createArchiveAndCheck(
+                                 "-Xbootclasspath/a:" + bootAppendJar,
+                                 "-XX:SharedClassListFile=" + classlist.getPath());
         // Make sure all the classes were successfully archived.
         for (String archiveClass : ARCHIVE_CLASSES) {
-            output.shouldNotContain("Preload Warning: Cannot find " + archiveClass);
+            out.shouldNotContain("Preload Warning: Cannot find " + archiveClass);
         }
     }
 
@@ -119,16 +121,13 @@
     //          should not be loaded at runtime.
     public static void testBootAppendModuleClass() throws Exception {
         for (String mode : modes) {
-            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-                "-XX:+UnlockDiagnosticVMOptions",
-                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
-                "-cp", appJar,
-                "-Xbootclasspath/a:" + bootAppendJar,
-                "-Xshare:" + mode,
-                APP_CLASS,
-                BOOT_APPEND_MODULE_CLASS_NAME);
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
-            output.shouldContain("java.lang.ClassNotFoundException: javax.sound.sampled.MyClass");
+            CDSOptions opts = (new CDSOptions())
+                .setXShareMode(mode).setUseVersion(false)
+                .addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar)
+                .addSuffix(APP_CLASS, BOOT_APPEND_MODULE_CLASS_NAME);
+
+            CDSTestUtils.runWithArchive(opts)
+                .shouldContain("java.lang.ClassNotFoundException: javax.sound.sampled.MyClass");
         }
     }
 
@@ -143,17 +142,13 @@
     //          The one from the boot modules should be loaded instead.
     public static void testBootAppendDuplicateModuleClass() throws Exception {
         for (String mode : modes) {
-            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-                "-XX:+UnlockDiagnosticVMOptions",
-                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
-                "-XX:+TraceClassLoading",
-                "-cp", appJar,
-                "-Xbootclasspath/a:" + bootAppendJar,
-                "-Xshare:" + mode,
-                APP_CLASS,
-                BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
-            output.shouldContain("[class,load] org.omg.CORBA.Context source: jrt:/java.corba");
+            CDSOptions opts = (new CDSOptions())
+                .setXShareMode(mode).setUseVersion(false)
+                .addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar)
+                .addSuffix(APP_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
+
+            CDSTestUtils.runWithArchive(opts)
+                .shouldContain("[class,load] org.omg.CORBA.Context source: jrt:/java.corba");
         }
     }
 
@@ -167,22 +162,19 @@
     //          loaded from the archive at runtime.
     public static void testBootAppendExcludedModuleClass() throws Exception {
         for (String mode : modes) {
-            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-                "-XX:+UnlockDiagnosticVMOptions",
-                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
-                "-XX:+TraceClassLoading",
-                "-cp", appJar,
-                "-Xbootclasspath/a:" + bootAppendJar,
-                "--limit-modules=java.base",
-                "-Xshare:" + mode,
-                APP_CLASS,
-                BOOT_APPEND_MODULE_CLASS_NAME);
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
-            output.shouldContain("[class,load] javax.sound.sampled.MyClass");
+            CDSOptions opts = (new CDSOptions())
+                .setXShareMode(mode).setUseVersion(false)
+                .addPrefix("-Xbootclasspath/a:" + bootAppendJar,
+                           "--limit-modules=java.base", "-cp", appJar)
+                .addSuffix("-Xlog:class+load=info",
+                           APP_CLASS, BOOT_APPEND_MODULE_CLASS_NAME);
+
+            OutputAnalyzer out = CDSTestUtils.runWithArchive(opts)
+                .shouldContain("[class,load] javax.sound.sampled.MyClass");
 
             // When CDS is enabled, the shared class should be loaded from the archive.
             if (mode.equals("on")) {
-                output.shouldContain("[class,load] javax.sound.sampled.MyClass source: shared objects file");
+                out.shouldContain("[class,load] javax.sound.sampled.MyClass source: shared objects file");
             }
         }
     }
@@ -199,19 +191,16 @@
     //          java.corba is excluded.
     public static void testBootAppendDuplicateExcludedModuleClass() throws Exception {
         for (String mode : modes) {
-            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-                "-XX:+UnlockDiagnosticVMOptions",
-                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
-                "-XX:+TraceClassLoading",
-                "-cp", appJar,
-                "-Xbootclasspath/a:" + bootAppendJar,
-                "--limit-modules=java.base",
-                "-Xshare:" + mode,
-                APP_CLASS,
-                BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
-            output.shouldContain("[class,load] org.omg.CORBA.Context");
-            output.shouldMatch(".*\\[class,load\\] org.omg.CORBA.Context source:.*bootAppend.jar");
+            CDSOptions opts = (new CDSOptions())
+                .setXShareMode(mode).setUseVersion(false)
+                .addPrefix("-Xbootclasspath/a:" + bootAppendJar,
+                           "--limit-modules=java.base", "-cp", appJar)
+                .addSuffix("-Xlog:class+load=info",
+                           APP_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
+
+            CDSTestUtils.runWithArchive(opts)
+                .shouldContain("[class,load] org.omg.CORBA.Context")
+                .shouldMatch(".*\\[class,load\\] org.omg.CORBA.Context source:.*bootAppend.jar");
         }
     }
 
@@ -224,22 +213,20 @@
     //          can be loaded at runtime when CDS is enabled.
     public static void testBootAppendClass() throws Exception {
         for (String mode : modes) {
-            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-                "-XX:+UnlockDiagnosticVMOptions",
-                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
-                "-XX:+TraceClassLoading",
-                "-cp", appJar,
-                "-Xbootclasspath/a:" + bootAppendJar,
-                "-Xshare:" + mode,
-                APP_CLASS,
-                BOOT_APPEND_CLASS_NAME);
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
-            output.shouldContain("[class,load] nonjdk.myPackage.MyClass");
+            CDSOptions opts = (new CDSOptions())
+                .setXShareMode(mode).setUseVersion(false)
+                .addPrefix("-Xbootclasspath/a:" + bootAppendJar,
+                           "--limit-modules=java.base", "-cp", appJar)
+                .addSuffix("-Xlog:class+load=info",
+                           APP_CLASS, BOOT_APPEND_CLASS_NAME);
+
+            OutputAnalyzer out = CDSTestUtils.runWithArchive(opts)
+                .shouldContain("[class,load] nonjdk.myPackage.MyClass");
 
             // If CDS is enabled, the nonjdk.myPackage.MyClass should be loaded
             // from the shared archive.
             if (mode.equals("on")) {
-                output.shouldContain(
+                out.shouldContain(
                     "[class,load] nonjdk.myPackage.MyClass source: shared objects file");
             }
         }
--- a/hotspot/test/runtime/SharedArchiveFile/CDSTestUtils.java	Tue Apr 18 22:25:33 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2016, 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.
- */
-
-import java.io.IOException;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
-import jdk.test.lib.process.OutputAnalyzer;
-
-
-// This class contains common test utilities for CDS testing
-public class CDSTestUtils {
-
-    // check result of 'dump' operation
-    public static void checkDump(OutputAnalyzer output, String... extraMatches)
-        throws Exception {
-
-        output.shouldContain("Loading classes to share");
-        output.shouldHaveExitValue(0);
-
-        for (String match : extraMatches) {
-            output.shouldContain(match);
-        }
-    }
-
-
-    // check the output for indication that mapping of the archive failed
-    public static boolean isUnableToMap(OutputAnalyzer output) {
-        String outStr = output.getOutput();
-        if ((output.getExitValue() == 1) && (
-            outStr.contains("Unable to reserve shared space at required address") ||
-            outStr.contains("Unable to map ReadOnly shared space at required address") ||
-            outStr.contains("Unable to map ReadWrite shared space at required address") ||
-            outStr.contains("Unable to map MiscData shared space at required address") ||
-            outStr.contains("Unable to map MiscCode shared space at required address") ||
-            outStr.contains("Unable to map shared string space at required address") ||
-            outStr.contains("Could not allocate metaspace at a compatible address") ||
-            outStr.contains("Unable to allocate shared string space: range is not within java heap") ))
-        {
-            return true;
-        }
-
-        return false;
-    }
-
-    // check result of 'exec' operation, that is when JVM is run using the archive
-    public static void checkExec(OutputAnalyzer output, String... extraMatches) throws Exception {
-        if (isUnableToMap(output)) {
-            System.out.println("Unable to map shared archive: test did not complete; assumed PASS");
-            return;
-        }
-        output.shouldContain("sharing");
-        output.shouldHaveExitValue(0);
-
-        for (String match : extraMatches) {
-            output.shouldContain(match);
-        }
-    }
-
-
-    // get the file object for the test artifact
-    private static File getTestArtifactFile(String prefix, String name) {
-        File dir = new File(System.getProperty("test.classes", "."));
-        return new File(dir, prefix + name);
-    }
-
-
-    // create file containing the specified class list
-    public static File makeClassList(String testCaseName, String classes[])
-        throws Exception {
-
-        File classList = getTestArtifactFile(testCaseName, "test.classlist");
-        FileOutputStream fos = new FileOutputStream(classList);
-        PrintStream ps = new PrintStream(fos);
-
-        addToClassList(ps, classes);
-
-        ps.close();
-        fos.close();
-
-        return classList;
-    }
-
-
-    private static void addToClassList(PrintStream ps, String classes[])
-        throws IOException
-    {
-        if (classes != null) {
-            for (String s : classes) {
-                ps.println(s);
-            }
-        }
-    }
-
-}
--- a/hotspot/test/runtime/SharedArchiveFile/CdsDifferentCompactStrings.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/CdsDifferentCompactStrings.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, 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
@@ -30,7 +30,7 @@
  *          java.management
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 
 public class CdsDifferentCompactStrings {
@@ -45,32 +45,14 @@
         String createCompactStringsArgument = "-XX:" + create + "CompactStrings";
         String loadCompactStringsArgument   = "-XX:" + load   + "CompactStrings";
 
-        String filename = "./CdsDifferentCompactStrings" + create + ".jsa";
-
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + filename,
-            "-Xshare:dump",
-            createCompactStringsArgument);
-
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldContain("Loading classes to share");
-        output.shouldHaveExitValue(0);
+        OutputAnalyzer out = CDSTestUtils.createArchive(createCompactStringsArgument);
+        CDSTestUtils.checkDump(out);
 
-        pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + filename,
-            "-Xshare:on",
-            loadCompactStringsArgument,
-            "-version");
-
-        output = new OutputAnalyzer(pb.start());
-        try {
-            output.shouldContain("The shared archive file's CompactStrings " +
-                "setting .* does not equal the current CompactStrings setting");
-        } catch (RuntimeException e) {
-            output.shouldContain("Unable to use shared archive");
+        out = CDSTestUtils.runWithArchive(loadCompactStringsArgument);
+        if (!CDSTestUtils.isUnableToMap(out)) {
+            out.shouldMatch("The shared archive file's CompactStrings " +
+                "setting .* does not equal the current CompactStrings setting")
+                .shouldHaveExitValue(1);
         }
-        output.shouldHaveExitValue(1);
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, 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
@@ -34,7 +34,7 @@
  *          java.management
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.Platform;
 
@@ -61,26 +61,6 @@
             createAlignment;
         String loadAlignmentArgument = "-XX:ObjectAlignmentInBytes=" +
             loadAlignment;
-        String filename = "./CdsDifferentObjectAlignment" + createAlignment + ".jsa";
-
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + filename,
-            "-Xshare:dump",
-            createAlignmentArgument);
-
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldContain("Loading classes to share");
-        output.shouldHaveExitValue(0);
-
-        pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + filename,
-            "-Xshare:on",
-            loadAlignmentArgument,
-            "-version");
-
-        output = new OutputAnalyzer(pb.start());
         String expectedErrorMsg =
             String.format(
             "The shared archive file's ObjectAlignmentInBytes of %d " +
@@ -88,11 +68,9 @@
             createAlignment,
             loadAlignment);
 
-        try {
-            output.shouldContain(expectedErrorMsg);
-        } catch (RuntimeException e) {
-            output.shouldContain("Unable to use shared archive");
-        }
-        output.shouldHaveExitValue(1);
+        CDSTestUtils.createArchiveAndCheck(createAlignmentArgument);
+
+        OutputAnalyzer out = CDSTestUtils.runWithArchive(loadAlignmentArgument);
+        CDSTestUtils.checkExecExpectError(out, 1, expectedErrorMsg);
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/CdsSameObjectAlignment.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/CdsSameObjectAlignment.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, 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
@@ -30,9 +30,9 @@
  *          java.management
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.Platform;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.Platform;
 
 public class CdsSameObjectAlignment {
     public static void main(String[] args) throws Exception {
@@ -57,40 +57,7 @@
         System.out.println("dumpAndLoadSharedArchive(): objectAlignmentInBytes = "
             + objectAlignmentInBytes);
 
-        String filename = "./CdsSameObjectAlignment" + objectAlignmentInBytes + ".jsa";
-        // create shared archive
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + filename,
-            "-Xshare:dump",
-            objectAlignmentArg);
-
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldContain("Loading classes to share");
-        output.shouldHaveExitValue(0);
-
-
-        // run using the shared archive
-        pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + filename,
-            "-Xshare:on",
-            objectAlignmentArg,
-            "-version");
-
-        output = new OutputAnalyzer(pb.start());
-
-        try {
-            output.shouldContain("sharing");
-            output.shouldHaveExitValue(0);
-        } catch (RuntimeException e) {
-            // CDS uses absolute addresses for performance.
-            // It will try to reserve memory at a specific address;
-            // there is a chance such reservation will fail
-            // If it does, it is NOT considered a failure of the feature,
-            // rather a possible expected outcome, though not likely
-            output.shouldContain("Unable to use shared archive");
-            output.shouldHaveExitValue(1);
-        }
+        CDSTestUtils.createArchiveAndCheck(objectAlignmentArg);
+        CDSTestUtils.runWithArchiveAndCheck(objectAlignmentArg);
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/DefaultUseWithClient.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/DefaultUseWithClient.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, 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
@@ -31,15 +31,13 @@
  * @bug 8032224
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.Platform;
 import java.io.File;
 
 public class DefaultUseWithClient {
     public static void main(String[] args) throws Exception {
-        String fileName = "DefaultUseWithClient.jsa";
-
         // On 32-bit windows CDS should be on by default in "-client" config
         // Skip this test on any other platform
         boolean is32BitWindows = (Platform.isWindows() && Platform.is32bit());
@@ -48,29 +46,7 @@
             return;
         }
 
-        // create the archive
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-           "-XX:+UnlockDiagnosticVMOptions",
-           "-XX:SharedArchiveFile=./" + fileName,
-           "-Xshare:dump");
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldHaveExitValue(0);
-
-        pb = ProcessTools.createJavaProcessBuilder(
-           "-XX:+UnlockDiagnosticVMOptions",
-           "-XX:SharedArchiveFile=./" + fileName,
-           "-client",
-           "-XX:+PrintSharedSpaces",
-           "-version");
-
-        output = new OutputAnalyzer(pb.start());
-        try {
-            output.shouldContain("sharing");
-        } catch (RuntimeException e) {
-            // if sharing failed due to ASLR or similar reasons,
-            // check whether sharing was attempted at all (UseSharedSpaces)
-            output.shouldContain("UseSharedSpaces:");
-        }
-        output.shouldHaveExitValue(0);
+        CDSTestUtils.createArchiveAndCheck();
+        CDSTestUtils.runWithArchiveAndCheck("-client", "-XX:+PrintSharedSpaces");
    }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/LargeSharedSpace.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/LargeSharedSpace.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -33,7 +33,7 @@
  * @run main LargeSharedSpace
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.Platform;
 
@@ -46,10 +46,8 @@
        //
        // The archive should be dumped successfully. It might fail to reserve memory
        // for shared space under low memory condition. The dumping process should not crash.
-       pb = ProcessTools.createJavaProcessBuilder(
-                "-XX:SharedMiscCodeSize=1066924031", "-XX:+UnlockDiagnosticVMOptions",
-                "-XX:SharedArchiveFile=./LargeSharedSpace.jsa", "-Xshare:dump");
-       output = new OutputAnalyzer(pb.start());
+       output = CDSTestUtils.createArchive("-XX:SharedMiscCodeSize=1066924031",
+                                           "-XX:+UnlockDiagnosticVMOptions");
        try {
            output.shouldContain("Loading classes to share");
        } catch (RuntimeException e1) {
@@ -64,12 +62,10 @@
        //
        // The dumping process should not crash.
        if (Platform.is64bit()) {
-           pb = ProcessTools.createJavaProcessBuilder(
-                    "-XX:+UseCompressedClassPointers", "-XX:CompressedClassSpaceSize=3G",
-                    "-XX:SharedMiscCodeSize=1600386047", "-XX:+UnlockDiagnosticVMOptions",
-                    "-XX:SharedArchiveFile=./LargeSharedSpace.jsa", "-Xshare:dump");
-           output = new OutputAnalyzer(pb.start());
-           output.shouldContain("larger than compressed klass limit");
+           CDSTestUtils.createArchive(
+               "-XX:+UseCompressedClassPointers", "-XX:CompressedClassSpaceSize=3G",
+               "-XX:SharedMiscCodeSize=1600386047")
+               .shouldContain("larger than compressed klass limit");
         }
 
         // Test case 3: -XX:SharedMiscCodeSize=1600386047
@@ -79,15 +75,12 @@
         //
         // The dumping process should not crash.
         if (Platform.is32bit()) {
-           pb = ProcessTools.createJavaProcessBuilder(
-                    "-XX:SharedMiscCodeSize=1600386047", "-XX:+UnlockDiagnosticVMOptions",
-                    "-XX:SharedArchiveFile=./LargeSharedSpace.jsa", "-Xshare:dump");
-           output = new OutputAnalyzer(pb.start());
-           try {
-               output.shouldContain("Loading classes to share");
-           } catch (RuntimeException e3) {
-               output.shouldContain("Unable to allocate memory for shared space");
-           }
+            output = CDSTestUtils.createArchive("-XX:SharedMiscCodeSize=1600386047");
+            try {
+                output.shouldContain("Loading classes to share");
+            } catch (RuntimeException e3) {
+                output.shouldContain("Unable to allocate memory for shared space");
+            }
         }
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/PrintSharedArchiveAndExit.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/PrintSharedArchiveAndExit.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, 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
@@ -30,41 +30,38 @@
  *          java.management
  */
 
+import jdk.test.lib.cds.CDSOptions;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 
+
 public class PrintSharedArchiveAndExit {
-  public static void main(String[] args) throws Exception {
-    String filename = "./PrintSharedArchiveAndExit.jsa";
-
-    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-        "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename, "-Xshare:dump");
-    OutputAnalyzer output = new OutputAnalyzer(pb.start());
-    try {
-      output.shouldContain("Loading classes to share");
-      output.shouldHaveExitValue(0);
+    public static void main(String[] args) throws Exception {
+        String archiveName = "PrintSharedArchiveAndExit.jsa";
+        CDSOptions opts = (new CDSOptions()).setArchiveName(archiveName);
+        OutputAnalyzer out = CDSTestUtils.createArchive(opts);
+        CDSTestUtils.checkDump(out);
 
-      // (1) With a valid archive
-      pb = ProcessTools.createJavaProcessBuilder(
-          "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename,
-          "-XX:+PrintSharedArchiveAndExit", "-version");
-      output = new OutputAnalyzer(pb.start());
-      output.shouldContain("archive is valid");
-      output.shouldNotContain("java version");     // Should not print JVM version
-      output.shouldHaveExitValue(0);               // Should report success in error code.
+        // (1) With a valid archive
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+                "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + archiveName,
+                "-XX:+PrintSharedArchiveAndExit", "-version");
+        out = CDSTestUtils.executeAndLog(pb, "print-shared-archive-and-version");
+        if (!CDSTestUtils.isUnableToMap(out)) {
+            out.shouldContain("archive is valid")
+                .shouldNotContain("java version")     // Should not print JVM version
+                .shouldHaveExitValue(0);              // Should report success in error code.
+        }
 
-      pb = ProcessTools.createJavaProcessBuilder(
-          "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename,
-          "-XX:+PrintSharedArchiveAndExit");
-      output = new OutputAnalyzer(pb.start());
-      output.shouldContain("archive is valid");
-      output.shouldNotContain("Usage:");           // Should not print JVM help message
-      output.shouldHaveExitValue(0);               // Should report success in error code.
-
-    } catch (RuntimeException e) {
-      e.printStackTrace();
-      output.shouldContain("Unable to use shared archive");
-      output.shouldHaveExitValue(1);
+        pb = ProcessTools.createJavaProcessBuilder(
+                "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + archiveName,
+                "-XX:+PrintSharedArchiveAndExit");
+        out = CDSTestUtils.executeAndLog(pb, "print-shared-archive");
+        if (!CDSTestUtils.isUnableToMap(out)) {
+            out.shouldContain("archive is valid")
+                .shouldNotContain("Usage:")           // Should not print JVM help message
+                .shouldHaveExitValue(0);               // Should report success in error code.
+        }
     }
-  }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/SASymbolTableTest.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/SASymbolTableTest.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -37,6 +37,7 @@
 
 import java.util.Arrays;
 import java.util.List;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.JDKToolFinder;
@@ -55,26 +56,18 @@
     static String jsaName = "./SASymbolTableTest.jsa";
     private static LingeredApp theApp = null;
 
+
     public static void main(String[] args) throws Exception {
         if (!Platform.shouldSAAttach()) {
             System.out.println("SA attach not expected to work - test skipped.");
             return;
         }
-        createArchive();
+
+        CDSTestUtils.createArchiveAndCheck();
         run(true);
         run(false);
     }
 
-    private static void createArchive()  throws Exception {
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + jsaName,
-            "-Xshare:dump");
-
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldContain("Loading classes to share");
-        output.shouldHaveExitValue(0);
-    }
 
     private static void run(boolean useArchive) throws Exception {
         String flag = useArchive ? "auto" : "off";
--- a/hotspot/test/runtime/SharedArchiveFile/SharedArchiveFile.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/SharedArchiveFile.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, 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
@@ -30,27 +30,28 @@
  *          java.management
  */
 
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 
-public class SharedArchiveFile {
-  public static void main(String[] args) throws Exception {
-    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-        "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./SharedArchiveFile.jsa", "-Xshare:dump");
-    OutputAnalyzer output = new OutputAnalyzer(pb.start());
-    try {
-      output.shouldContain("Loading classes to share");
-      output.shouldHaveExitValue(0);
 
-      pb = ProcessTools.createJavaProcessBuilder(
-        "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./SharedArchiveFile.jsa", "-Xshare:on", "-version");
-      output = new OutputAnalyzer(pb.start());
-      output.shouldContain("sharing");
-      output.shouldHaveExitValue(0);
+// NOTE: This test serves as a sanity test and also as an example for simple
+// use of SharedArchiveFile argument. For this reason it DOES NOT use the utility
+// methods to form command line to create/use shared archive.
+public class SharedArchiveFile {
+    public static void main(String[] args) throws Exception {
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+                                "-XX:+UnlockDiagnosticVMOptions",
+                                "-XX:SharedArchiveFile=./SharedArchiveFile.jsa",
+                                "-Xshare:dump");
+        OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "SharedArchiveFile");
+        CDSTestUtils.checkDump(out);
 
-    } catch (RuntimeException e) {
-      output.shouldContain("Unable to use shared archive");
-      output.shouldHaveExitValue(1);
+        pb = ProcessTools.createJavaProcessBuilder(
+                              "-XX:+UnlockDiagnosticVMOptions",
+                              "-XX:SharedArchiveFile=./SharedArchiveFile.jsa",
+                              "-Xshare:on", "-version");
+        out = CDSTestUtils.executeAndLog(pb, "SharedArchiveFile");
+        CDSTestUtils.checkExec(out);
     }
-  }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/SharedBaseAddress.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/SharedBaseAddress.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, 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
@@ -31,7 +31,8 @@
  * @run main SharedBaseAddress
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
+import jdk.test.lib.cds.CDSOptions;
 import jdk.test.lib.process.OutputAnalyzer;
 
 public class SharedBaseAddress {
@@ -48,30 +49,12 @@
         for (String testEntry : testTable) {
             String filename = "SharedBaseAddress" + testEntry + ".jsa";
             System.out.println("sharedBaseAddress = " + testEntry);
-
-            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-               "-XX:+UnlockDiagnosticVMOptions",
-               "-XX:SharedArchiveFile=" + filename,
-               "-XX:SharedBaseAddress=" + testEntry,
-               "-Xshare:dump");
-
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
-
-            output.shouldContain("Loading classes to share");
+            CDSOptions opts = (new CDSOptions())
+                .setArchiveName(filename)
+                .addPrefix("-XX:SharedBaseAddress=" + testEntry);
 
-            try {
-                pb = ProcessTools.createJavaProcessBuilder(
-                    "-XX:+UnlockDiagnosticVMOptions",
-                    "-XX:SharedArchiveFile=" + filename,
-                    "-Xshare:on",
-                    "-version");
-                output = new OutputAnalyzer(pb.start());
-                output.shouldContain("sharing");
-                output.shouldHaveExitValue(0);
-            } catch (RuntimeException e) {
-                output.shouldContain("Unable to use shared archive");
-                output.shouldHaveExitValue(1);
-            }
+            CDSTestUtils.createArchiveAndCheck(opts);
+            CDSTestUtils.runWithArchiveAndCheck(opts);
         }
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/SharedStrings.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/SharedStrings.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -36,12 +36,17 @@
  * @run main ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox
  * @run main SharedStrings
  */
+
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 
 public class SharedStrings {
     public static void main(String[] args) throws Exception {
-        boolean test_runtime = true;
+        // Note: This is a basic sanity test for Shared Strings feature.
+        // This also serves as a reference on how to use this feature,
+        // hence the command lines are spelled out instead of using the
+        // test utils methods.
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
             "-XX:+UnlockDiagnosticVMOptions",
             "-XX:SharedArchiveFile=./SharedStrings.jsa",
@@ -52,22 +57,11 @@
             "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"),
             "-Xshare:dump");
 
-        OutputAnalyzer dumpOutput = new OutputAnalyzer(pb.start());
-        try {
-            dumpOutput.shouldContain("Loading classes to share");
-            dumpOutput.shouldContain("Shared string table stats");
-            dumpOutput.shouldHaveExitValue(0);
-        } catch (RuntimeException e) {
-            if (dumpOutput.getOutput().indexOf("Shared strings are excluded") != -1 ||
-                dumpOutput.getOutput().indexOf("Cannot dump shared archive") != -1) {
-                test_runtime = false;
-            } else {
-                throw new RuntimeException("Unexpected failure");
-            }
-        }
+        OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "dump");
+        CDSTestUtils.checkDump(out, "Shared string table stats");
 
-        if (test_runtime) {
-            pb = ProcessTools.createJavaProcessBuilder(
+
+        pb = ProcessTools.createJavaProcessBuilder(
                 "-XX:+UnlockDiagnosticVMOptions",
                 "-XX:SharedArchiveFile=./SharedStrings.jsa",
                 // these are required modes for shared strings
@@ -77,15 +71,7 @@
                 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
                 "-Xshare:on", "-showversion", "SharedStringsWb");
 
-            OutputAnalyzer output = new OutputAnalyzer(pb.start());
-
-            try {
-                output.shouldContain("sharing");
-                output.shouldHaveExitValue(0);
-            } catch (RuntimeException e) {
-                output.shouldContain("Unable to use shared archive");
-                output.shouldHaveExitValue(1);
-            }
-        }
+        out = CDSTestUtils.executeAndLog(pb, "exec");
+        CDSTestUtils.checkExec(out);
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/SharedStringsDedup.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/SharedStringsDedup.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -34,7 +34,7 @@
  * @run main SharedStringsDedup
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 import java.io.File;
 
@@ -44,30 +44,10 @@
 // doesn't happen often so it won't impact coverage).
 public class SharedStringsDedup {
     public static void main(String[] args) throws Exception {
-        // Dump
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=./SharedStringsDedup.jsa",
-            "-XX:+UseCompressedOops", "-XX:+UseG1GC",
-            "-XX:+PrintSharedSpaces",
-            "-Xshare:dump");
-
-        new OutputAnalyzer(pb.start())
-            .shouldContain("Loading classes to share")
-            .shouldContain("Shared string table stats")
-            .shouldHaveExitValue(0);
-
-        // Run with -Xshare:auto
-        pb = ProcessTools.createJavaProcessBuilder(
-           "-XX:+UnlockDiagnosticVMOptions",
-           "-XX:SharedArchiveFile=./SharedStringsDedup.jsa",
-           "-XX:+UseCompressedOops", "-XX:+UseG1GC",
-           "-XX:+UseStringDeduplication",
-           "-Xshare:auto",
-           "-version");
-
-        new OutputAnalyzer(pb.start())
-            .shouldMatch("(java|openjdk) version")
-            .shouldHaveExitValue(0);
+        OutputAnalyzer out =
+            CDSTestUtils.createArchive("-XX:+UseCompressedOops", "-XX:+UseG1GC");
+        CDSTestUtils.checkDump(out, "Shared string table stats");
+        CDSTestUtils.runWithArchiveAndCheck("-XX:+UseCompressedOops", "-XX:+UseG1GC",
+                                            "-XX:+UseStringDeduplication");
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/SharedStringsRunAuto.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/SharedStringsRunAuto.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -34,35 +34,15 @@
  * @run main SharedStringsRunAuto
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 import java.io.File;
 
 public class SharedStringsRunAuto {
     public static void main(String[] args) throws Exception {
-        // Dump
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=./SharedStringsRunAuto.jsa",
-            "-XX:+UseCompressedOops", "-XX:+UseG1GC",
-            "-XX:+PrintSharedSpaces",
-            "-Xshare:dump");
-
-        new OutputAnalyzer(pb.start())
-            .shouldContain("Loading classes to share")
-            .shouldContain("Shared string table stats")
-            .shouldHaveExitValue(0);
-
-        // Run with -Xshare:auto
-        pb = ProcessTools.createJavaProcessBuilder(
-           "-XX:+UnlockDiagnosticVMOptions",
-           "-XX:SharedArchiveFile=./SharedStringsRunAuto.jsa",
-           "-XX:+UseCompressedOops", "-XX:+UseG1GC",
-           "-Xshare:auto",
-           "-version");
-
-        new OutputAnalyzer(pb.start())
-            .shouldMatch("(java|openjdk) version")
-            .shouldHaveExitValue(0);
+        OutputAnalyzer out =
+            CDSTestUtils.createArchive("-XX:+UseCompressedOops", "-XX:+UseG1GC");
+        CDSTestUtils.checkDump(out, "Shared string table stats");
+        CDSTestUtils.runWithArchiveAndCheck("-XX:+UseCompressedOops", "-XX:+UseG1GC");
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/SharedSymbolTableBucketSize.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/SharedSymbolTableBucketSize.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, 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
@@ -30,41 +30,35 @@
  *          java.management
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 
 public class SharedSymbolTableBucketSize {
     public static void main(String[] args) throws Exception {
         int bucket_size = 8;
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-Xshare:dump", "-XX:+PrintSharedSpaces",
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=./SharedSymbolTableBucketSize.jsa",
-            "-XX:SharedSymbolTableBucketSize=" + Integer.valueOf(bucket_size));
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        output.shouldContain("Loading classes to share");
-        output.shouldHaveExitValue(0);
+
+        OutputAnalyzer output =
+            CDSTestUtils.createArchive("-XX:SharedSymbolTableBucketSize="
+                                       + Integer.valueOf(bucket_size));
+        CDSTestUtils.checkDump(output);
 
-        String s = output.firstMatch("Average bucket size     : .*");
-        Float f = Float.parseFloat(s.substring(25));
-        int size = Math.round(f);
-        if (size != bucket_size) {
-          throw new Exception("FAILED: incorrect bucket size " + size +
-                              ", expect " + bucket_size);
+        if (!CDSTestUtils.isUnableToMap(output)) {
+            String s = output.firstMatch("Average bucket size     : .*");
+            Float f = Float.parseFloat(s.substring(25));
+            int size = Math.round(f);
+            if (size != bucket_size) {
+                throw new Exception("FAILED: incorrect bucket size " + size +
+                                    ", expect " + bucket_size);
+            }
         }
 
-
         // Invalid SharedSymbolTableBucketSize input
         String input[] = {"-XX:SharedSymbolTableBucketSize=-1",
                           "-XX:SharedSymbolTableBucketSize=2.5"};
         for (int i = 0; i < input.length; i++) {
-          pb = ProcessTools.createJavaProcessBuilder(
-               "-Xshare:dump", "-XX:+PrintSharedSpaces",
-               "-XX:+UnlockDiagnosticVMOptions",
-               "-XX:SharedArchiveFile=./SharedSymbolTableBucketSize.jsa",
-               input[i]);
-          output = new OutputAnalyzer(pb.start());
-          output.shouldContain("Improperly specified VM option");
-      }
-  }
+            CDSTestUtils.createArchive(input[i])
+                .shouldContain("Improperly specified VM option")
+                .shouldHaveExitValue(1);
+        }
+    }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, 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
@@ -30,7 +30,7 @@
  * @run main SpaceUtilizationCheck
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 
 import java.util.regex.Pattern;
@@ -49,12 +49,9 @@
     private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2;
 
     public static void main(String[] args) throws Exception {
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-           "-XX:+UnlockDiagnosticVMOptions",
-           "-XX:SharedArchiveFile=./SpaceUtilizationCheck.jsa",
-           "-Xshare:dump");
+        OutputAnalyzer output = CDSTestUtils.createArchive();
+        CDSTestUtils.checkDump(output);
 
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
         String stdout = output.getStdout();
         ArrayList<String> utilization = findUtilization(stdout);
 
--- a/hotspot/test/runtime/SharedArchiveFile/TestInterpreterMethodEntries.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/TestInterpreterMethodEntries.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -35,7 +35,8 @@
 import java.lang.Math;
 import java.util.zip.CRC32;
 import java.util.zip.CRC32C;
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSOptions;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 
 public class TestInterpreterMethodEntries {
@@ -68,29 +69,13 @@
         String useCRC32   = "-XX:" + use  + "UseCRC32Intrinsics";
         String useCRC32C  = "-XX:" + use  + "UseCRC32CIntrinsics";
 
-        // Dump shared archive
-        String filename = "./TestInterpreterMethodEntries" + dump + ".jsa";
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + filename,
-            "-Xshare:dump",
-            dumpFMA, dumpCRC32, dumpCRC32C);
-        OutputAnalyzer output = new OutputAnalyzer(pb.start());
-        CDSTestUtils.checkDump(output);
+        CDSTestUtils.createArchiveAndCheck(dumpFMA, dumpCRC32, dumpCRC32C);
 
-        // Use shared archive
-        pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=" + filename,
-            "-Xshare:on",
-            useFMA, useCRC32, useCRC32C,
-            "TestInterpreterMethodEntries", "run");
-        output = new OutputAnalyzer(pb.start());
-        if (CDSTestUtils.isUnableToMap(output)) {
-          System.out.println("Unable to map shared archive: test did not complete; assumed PASS");
-          return;
-        }
-        output.shouldHaveExitValue(0);
+        CDSOptions opts = (new CDSOptions())
+            .addPrefix(useFMA, useCRC32, useCRC32C, "-showversion")
+            .addSuffix("TestInterpreterMethodEntries", "run")
+            .setUseVersion(false);
+        CDSTestUtils.runWithArchiveAndCheck(opts);
     }
 }
 
--- a/hotspot/test/runtime/SharedArchiveFile/serviceability/transformRelatedClasses/TransformRelatedClasses.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/serviceability/transformRelatedClasses/TransformRelatedClasses.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -56,10 +56,11 @@
 //     TransformerAgent - an agent that is used when JVM-under-test is executed
 //         to transform specific strings inside specified classes
 //     TransformerAgent.mf - accompanies transformer agent
-//     CDSTestUtils - Test Utilities common to all CDS tests
 
 import java.io.File;
 import java.util.ArrayList;
+import jdk.test.lib.cds.CDSOptions;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 
@@ -143,18 +144,11 @@
                                            testClasses);
 
         // create an archive
-        File classList = CDSTestUtils.makeClassList("transform-" + parent,
-                                                    testNames);
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
-                                        "-Xbootclasspath/a:" + testJar,
-                                        "-XX:+UnlockDiagnosticVMOptions",
-                                        "-XX:ExtraSharedClassListFile=" +
-                                        classList.getPath(),
-                                        "-XX:SharedArchiveFile=" + archiveName,
-                                        "-XX:+PrintSharedSpaces",
-                                        "-Xshare:dump");
-        OutputAnalyzer out = new OutputAnalyzer(pb.start());
-        CDSTestUtils.checkDump(out);
+        String classList =
+            CDSTestUtils.makeClassList("transform-" + parent, testNames).getPath();
+
+        CDSTestUtils.createArchiveAndCheck("-Xbootclasspath/a:" + testJar,
+            "-XX:ExtraSharedClassListFile=" + classList);
     }
 
 
@@ -165,15 +159,12 @@
         String agentParam = "-javaagent:" + agentJar + "=" +
             TransformTestCommon.getAgentParams(entry, parent, child);
 
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
-                                        "-Xbootclasspath/a:" + testJar,
-                                        "-XX:+UnlockDiagnosticVMOptions",
-                                        "-XX:SharedArchiveFile=" + archiveName,
-                                        "-Xlog:class+load=info",
-                                        "-Xshare:on", "-showversion",
-                                        agentParam, child);
-        OutputAnalyzer out = new OutputAnalyzer(pb.start());
+        CDSOptions opts = new CDSOptions()
+            .addPrefix("-Xbootclasspath/a:" + testJar, "-Xlog:class+load=info")
+            .setUseVersion(false)
+            .addSuffix( "-showversion",agentParam, child);
 
+        OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
         TransformTestCommon.checkResults(entry, out, parent, child);
     }
 }
--- a/hotspot/test/runtime/SharedArchiveFile/serviceability/transformRelatedClasses/TransformTestCommon.java	Tue Apr 18 22:25:33 2017 +0200
+++ b/hotspot/test/runtime/SharedArchiveFile/serviceability/transformRelatedClasses/TransformTestCommon.java	Tue Apr 18 23:52:58 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -21,6 +21,7 @@
  * questions.
  */
 
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;