8211336: [TESTBUG] appcds tests with incorrect usage of -XX:+UseStringDeduplication
authoriklam
Mon, 29 Oct 2018 14:01:46 -0700
changeset 52400 ca309ee4fd92
parent 52399 858c1639bf72
child 52401 595ab4f025d7
8211336: [TESTBUG] appcds tests with incorrect usage of -XX:+UseStringDeduplication Reviewed-by: dholmes, ccheung, mseledtsov
test/hotspot/jtreg/runtime/appcds/sharedStrings/ExerciseGC.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions_noCompactStrings.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions_stringDedup.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/InternSharedString.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/InvalidFileFormat.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/LargePages.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/LockSharedStrings.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsBasic.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsBasicPlus.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsStress.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsUtils.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsWbTest.java
test/hotspot/jtreg/runtime/appcds/sharedStrings/SysDictCrash.java
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/ExerciseGC.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/ExerciseGC.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,17 +27,16 @@
  * @summary Exercise GC with shared strings
  * @requires vm.cds.archived.java.heap
  * @library /test/hotspot/jtreg/runtime/appcds /test/lib
- * @modules java.base/jdk.internal.misc
- * @modules java.management
- *          jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool/sun.tools.jar
  * @build HelloStringGC sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  * @run driver ExerciseGC
- * @run main/othervm -XX:+UseStringDeduplication ExerciseGC
- * @run main/othervm -XX:-CompactStrings ExerciseGC
  */
 public class ExerciseGC {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, ExerciseGC::test);
+    }
+    public static void test(String[] args) throws Exception {
         SharedStringsUtils.buildJarAndWhiteBox("HelloStringGC");
 
         SharedStringsUtils.dumpWithWhiteBox(TestCommon.list("HelloStringGC"),
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions.java	Mon Oct 29 14:01:46 2018 -0700
@@ -22,6 +22,11 @@
  *
  */
 
+// NOTE: the test takes a long time for each VM option combination, so we split
+// it into 3 @test parts, so that they can be executed in parallel. If you make a
+// change, please ensure all @test blocks are in sync.
+
+
 /*
  * @test
  * @summary Test options that are incompatible with use of shared strings
@@ -36,9 +41,35 @@
  * @build sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @build HelloString
- * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions 0
  */
 
+
+/*
+ * @test
+ * @requires vm.cds.archived.java.heap
+ * @requires (vm.gc=="null")
+ * @library /test/lib /test/hotspot/jtreg/runtime/appcds
+ * @modules jdk.jartool/sun.tools.jar
+ * @build sun.hotspot.WhiteBox
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @build HelloString
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions 1
+ */
+
+/*
+ * @test
+ * @requires vm.cds.archived.java.heap
+ * @requires (vm.gc=="null")
+ * @library /test/lib /test/hotspot/jtreg/runtime/appcds
+ * @modules jdk.jartool/sun.tools.jar
+ * @build sun.hotspot.WhiteBox
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @build HelloString
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions 2
+ */
+
+
 import jdk.test.lib.Asserts;
 import jdk.test.lib.Platform;
 import jdk.test.lib.process.OutputAnalyzer;
@@ -59,10 +90,17 @@
         "The shared archive file's CompactStrings setting .* does not equal the current CompactStrings setting";
 
     static String appJar;
-    static String[] globalVmOptions;
+    static String[] vmOptionsPrefix = {};
 
     public static void main(String[] args) throws Exception {
-        globalVmOptions = args; // specified by "@run main" in IncompatibleOptions_*.java
+        String[] noargs = {};
+        SharedStringsUtils.run(Integer.parseInt(args[0]), 3, noargs, IncompatibleOptions::test);
+        // Add a new @test block if you get an assert ----^ about this number. See
+        // SharedStringsUtils.java for details.
+    }
+
+    public static void test(String[] args_ignored) throws Exception {
+        vmOptionsPrefix = SharedStringsUtils.getChildVMOptionsPrefix();
         appJar = JarBuilder.build("IncompatibleOptions", "HelloString");
 
         // Uncompressed OOPs
@@ -118,7 +156,7 @@
 
         System.out.println("Testcase: " + testCaseNr);
         OutputAnalyzer output = TestCommon.dump(appJar, TestCommon.list("Hello"),
-            TestCommon.concat(globalVmOptions,
+            TestCommon.concat(vmOptionsPrefix,
                 "-XX:+UseCompressedOops",
                 collectorOption,
                 "-XX:SharedArchiveConfigFile=" + TestCommon.getSourceFile("SharedStringsBasic.txt"),
@@ -145,12 +183,12 @@
         // main class param, and fails with "Could not find or load main class"
         if (!extraOption.isEmpty()) {
             output = TestCommon.exec(appJar,
-                TestCommon.concat(globalVmOptions,
+                TestCommon.concat(vmOptionsPrefix,
                     "-XX:+UseCompressedOops",
                     collectorOption, "-Xlog:cds", extraOption, "HelloString"));
         } else {
             output = TestCommon.exec(appJar,
-                TestCommon.concat(globalVmOptions,
+                TestCommon.concat(vmOptionsPrefix,
                     "-XX:+UseCompressedOops",
                     collectorOption, "-Xlog:cds", "HelloString"));
         }
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions_noCompactStrings.java	Fri Nov 02 23:44:45 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-/*
- * @test
- * @summary Test options that are incompatible with use of shared strings
- *          Also test mismatch in oops encoding between dump time and run time
- * @requires vm.cds.archived.java.heap
- * @comment This test explicitly chooses the type of GC to be used by sub-processes. It may conflict with the GC type set
- * via the -vmoptions command line option of JTREG. vm.gc==null will help the test case to discard the explicitly passed
- * vm options.
- * @requires (vm.gc=="null")
- * @library /test/lib /test/hotspot/jtreg/runtime/appcds
- * @modules jdk.jartool/sun.tools.jar
- * @build sun.hotspot.WhiteBox
- * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
- * @build HelloString
- * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions -XX:-CompactStrings
- */
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions_stringDedup.java	Fri Nov 02 23:44:45 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-/*
- * @test
- * @summary Test options that are incompatible with use of shared strings
- *          Also test mismatch in oops encoding between dump time and run time
- * @requires vm.cds.archived.java.heap
- * @comment This test explicitly chooses the type of GC to be used by sub-processes. It may conflict with the GC type set
- * via the -vmoptions command line option of JTREG. vm.gc==null will help the test case to discard the explicitly passed
- * vm options.
- * @requires (vm.gc=="null")
- * @library /test/lib /test/hotspot/jtreg/runtime/appcds
- * @modules jdk.jartool/sun.tools.jar
- * @build sun.hotspot.WhiteBox
- * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
- * @build HelloString
- * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions -XX:+UseStringDeduplication
- */
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/InternSharedString.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/InternSharedString.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,19 +27,19 @@
  * @summary Test shared strings together with string intern operation
  * @requires vm.cds.archived.java.heap
  * @library /test/hotspot/jtreg/runtime/appcds /test/lib
- * @modules java.base/jdk.internal.misc
- * @modules java.management
- *          jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool/sun.tools.jar
  * @compile InternStringTest.java
  * @build sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  * @run driver InternSharedString
- * @run main/othervm -XX:+UseStringDeduplication InternSharedString
- * @run main/othervm -XX:-CompactStrings InternSharedString
  */
 
 public class InternSharedString {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, InternSharedString::test);
+    }
+
+    public static void test(String[] args) throws Exception {
         SharedStringsUtils.buildJarAndWhiteBox("InternStringTest");
 
         SharedStringsUtils.dumpWithWhiteBox(TestCommon.list("InternStringTest"),
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/InvalidFileFormat.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/InvalidFileFormat.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,13 +27,9 @@
  * @summary Check most common errors in file format
  * @requires vm.cds.archived.java.heap
  * @library /test/lib /test/hotspot/jtreg/runtime/appcds
- * @modules java.base/jdk.internal.misc
- * @modules java.management
- *          jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool/sun.tools.jar
  * @build HelloString
  * @run driver InvalidFileFormat
- * @run main/othervm -XX:+UseStringDeduplication InvalidFileFormat
- * @run main/othervm -XX:-CompactStrings InvalidFileFormat
  */
 
 import java.io.File;
@@ -46,6 +42,10 @@
 // the previledge person in the server environment.
 public class InvalidFileFormat {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, InvalidFileFormat::test);
+    }
+
+    public static void test(String[] args) throws Exception {
         SharedStringsUtils.buildJar("HelloString");
 
         test("NonExistentFile.txt", "Unable to get hashtable dump file size");
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/LargePages.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/LargePages.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,17 +27,18 @@
  * @summary Basic shared string test with large pages
  * @requires vm.cds.archived.java.heap
  * @library /test/lib /test/hotspot/jtreg/runtime/appcds
- * @modules java.base/jdk.internal.misc
- * @modules java.management
- *          jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool/sun.tools.jar
  * @build HelloString
  * @run driver LargePages
- * @run main/othervm -XX:+UseStringDeduplication LargePages
- * @run main/othervm -XX:-CompactStrings LargePages
  */
 public class LargePages {
     static final String CDS_LOGGING = "-Xlog:cds,cds+hashtables";
+
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, LargePages::test);
+    }
+
+    public static void test(String[] args) throws Exception {
         SharedStringsUtils.buildJar("HelloString");
 
         SharedStringsUtils.dump(TestCommon.list("HelloString"),
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/LockSharedStrings.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/LockSharedStrings.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,19 +27,19 @@
  * @summary Test locking on shared strings
  * @requires vm.cds.archived.java.heap
  * @library /test/hotspot/jtreg/runtime/appcds /test/lib
- * @modules java.base/jdk.internal.misc
- * @modules java.management
- *          jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool/sun.tools.jar
  * @compile LockStringTest.java LockStringValueTest.java
  * @build sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  * @run driver LockSharedStrings
- * @run main/othervm -XX:+UseStringDeduplication LockSharedStrings
- * @run main/othervm -XX:-CompactStrings LockSharedStrings
  */
 
 public class LockSharedStrings {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, LockSharedStrings::test);
+    }
+
+    public static void test(String[] args) throws Exception {
         SharedStringsUtils.buildJarAndWhiteBox("LockStringTest", "LockStringValueTest");
 
         SharedStringsUtils.dumpWithWhiteBox(
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsBasic.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsBasic.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,44 +27,49 @@
  * @summary Basic test for shared strings
  * @requires vm.cds.archived.java.heap
  * @library /test/hotspot/jtreg/runtime/appcds /test/lib
- * @modules java.base/jdk.internal.misc
- * @modules java.management
- *          jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool/sun.tools.jar
  * @build HelloString
  * @run driver SharedStringsBasic
- * @run main/othervm -XX:+UseStringDeduplication SharedStringsBasic
- * @run main/othervm -XX:-CompactStrings SharedStringsBasic
  */
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 
-// This test does not use SharedStringsUtils intentionally:
+// This test does not use SharedStringsUtils.dumpXXX()
+// and SharedStringsUtils.runWithXXX() intentionally:
 // - in order to demonstrate the basic use of the functionality
 // - to provide sanity check and catch potential problems in the utils
 public class SharedStringsBasic {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, SharedStringsBasic::test);
+    }
+
+    public static void test(String[] args) throws Exception {
+        String vmOptionsPrefix[] = SharedStringsUtils.getChildVMOptionsPrefix();
+
         String appJar = JarBuilder.build("SharedStringsBasic", "HelloString");
 
         String sharedArchiveConfigFile =
             TestCommon.getSourceFile("SharedStringsBasic.txt").toString();
 
         ProcessBuilder dumpPb = ProcessTools.createJavaProcessBuilder(true,
+          TestCommon.concat(vmOptionsPrefix,
             "-cp", appJar,
             "-XX:SharedArchiveConfigFile=" + sharedArchiveConfigFile,
             "-XX:SharedArchiveFile=./SharedStringsBasic.jsa",
             "-Xshare:dump",
-            "-Xlog:cds,cds+hashtables");
+            "-Xlog:cds,cds+hashtables"));
 
         TestCommon.executeAndLog(dumpPb, "dump")
             .shouldContain("Shared string table stats")
             .shouldHaveExitValue(0);
 
         ProcessBuilder runPb = ProcessTools.createJavaProcessBuilder(true,
+          TestCommon.concat(vmOptionsPrefix,
             "-cp", appJar,
             "-XX:SharedArchiveFile=./SharedStringsBasic.jsa",
             "-Xshare:auto",
             "-showversion",
-            "HelloString");
+            "HelloString"));
 
         TestCommon.executeAndLog(runPb, "run").shouldHaveExitValue(0);
     }
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsBasicPlus.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsBasicPlus.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,18 +27,18 @@
  * @summary Basic plus test for shared strings
  * @requires vm.cds.archived.java.heap
  * @library /test/hotspot/jtreg/runtime/appcds /test/lib
- * @modules java.base/jdk.internal.misc
- * @modules java.management
- *          jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool/sun.tools.jar
  * @build HelloStringPlus sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  * @run driver SharedStringsBasicPlus
- * @run main/othervm -XX:+UseStringDeduplication SharedStringsBasicPlus
- * @run main/othervm -XX:-CompactStrings SharedStringsBasicPlus
  */
 
 public class SharedStringsBasicPlus {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, SharedStringsBasicPlus::test);
+    }
+
+    public static void test(String[] args) throws Exception {
         SharedStringsUtils.buildJarAndWhiteBox("HelloStringPlus");
 
         SharedStringsUtils.dumpWithWhiteBox( TestCommon.list("HelloStringPlus"),
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsStress.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsStress.java	Mon Oct 29 14:01:46 2018 -0700
@@ -30,8 +30,6 @@
  * @modules jdk.jartool/sun.tools.jar
  * @build HelloString
  * @run driver SharedStringsStress
- * @run main/othervm -XX:+UseStringDeduplication SharedStringsStress
- * @run main/othervm -XX:-CompactStrings SharedStringsStress
  */
 import java.io.File;
 import java.io.FileOutputStream;
@@ -42,6 +40,12 @@
 
 public class SharedStringsStress {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, SharedStringsStress::test);
+    }
+
+    public static void test(String[] args) throws Exception {
+        String vmOptionsPrefix[] = SharedStringsUtils.getChildVMOptionsPrefix();
+
         String appJar = JarBuilder.build("SharedStringsStress", "HelloString");
 
         String sharedArchiveConfigFile = System.getProperty("user.dir") + File.separator + "SharedStringsStress_gen.txt";
@@ -58,9 +62,11 @@
         }
 
         OutputAnalyzer dumpOutput = TestCommon.dump(appJar, TestCommon.list("HelloString"),
-                                                    "-XX:SharedArchiveConfigFile=" + sharedArchiveConfigFile);
+            TestCommon.concat(vmOptionsPrefix,
+                "-XX:SharedArchiveConfigFile=" + sharedArchiveConfigFile));
         TestCommon.checkDump(dumpOutput);
-        OutputAnalyzer execOutput = TestCommon.exec(appJar, "HelloString");
+        OutputAnalyzer execOutput = TestCommon.exec(appJar,
+            TestCommon.concat(vmOptionsPrefix, "HelloString"));
         TestCommon.checkExec(execOutput);
     }
 }
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsUtils.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsUtils.java	Mon Oct 29 14:01:46 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
 
 import jdk.test.lib.cds.CDSOptions;
 import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.Asserts;
 
 // A helper/utility class for testing shared strings
 public class SharedStringsUtils {
@@ -31,6 +32,49 @@
     public static final String TEST_JAR_NAME_FULL = "test.jar";
     public static final String WHITEBOX_JAR_NAME =  "whitebox";
 
+    public static interface Test {
+        public void dotest(String args[]) throws Exception ;
+    }
+
+    private static String[][] vmOptionCombos = {
+        {},
+        {"-XX:+UseStringDeduplication"},
+        {"-XX:-CompactStrings"}
+    };
+
+    private static String childVMOptionsPrefix[] = {};
+
+    // SharedStringsUtils.run() is for running the main test body multiple times, each with a different
+    // set of extra VM options that are passed to the child processes.
+    //
+    // See ./ExerciseGC.java for an example.
+    public static void run(String args[], Test t) throws Exception {
+        int numSetOfChildVMOptions = vmOptionCombos.length;
+        for (int i=0; i< numSetOfChildVMOptions; i++) {
+            run(i, numSetOfChildVMOptions, args, t);
+        }
+    }
+
+    public static void run(int i, int numSetOfChildVMOptions, String args[], Test t) throws Exception {
+        // When you add a new set of options to vmOptionCombos, we make sure all
+        // callers of this method (i.e., IncompatibleOptions.java) knows about it and will
+        // add new @test blocks accordingly.
+        Asserts.assertEQ(numSetOfChildVMOptions, vmOptionCombos.length);
+        String opts[] = vmOptionCombos[i];
+
+        System.out.print("Running with extra VM option prefix for child processes [" + opts.length + "] =");
+        for (String o : opts) {
+            System.out.print(" " + o);
+        }
+        System.out.println();
+        childVMOptionsPrefix = opts;
+        t.dotest(args);
+    }
+
+    public static String[] getChildVMOptionsPrefix() {
+        return childVMOptionsPrefix;
+    }
+
     public static String getWbParam() {
         return "-Xbootclasspath/a:" + TestCommon.getTestJar(WHITEBOX_JAR_NAME + ".jar");
     }
@@ -55,6 +99,7 @@
             TestCommon.concat(extraOptions, "-XX:+UseCompressedOops", "-XX:+UseG1GC",
             "-XX:SharedArchiveConfigFile=" +
             TestCommon.getSourceFile(sharedDataFile));
+        args = TestCommon.concat(childVMOptionsPrefix, args);
 
         return TestCommon.dump(appJar, appClasses, args);
     }
@@ -80,6 +125,7 @@
         String appJar = TestCommon.getTestJar(TEST_JAR_NAME_FULL);
         String[] args = TestCommon.concat(extraOptions,
             "-cp", appJar, "-XX:+UseCompressedOops", "-XX:+UseG1GC", className);
+        args = TestCommon.concat(childVMOptionsPrefix, args);
 
         OutputAnalyzer output = TestCommon.execAuto(args);
         checkExecAuto(output);
@@ -98,6 +144,7 @@
         String appJar = TestCommon.getTestJar(TEST_JAR_NAME_FULL);
         String[] args = TestCommon.concat(extraOptions,
             "-XX:+UseCompressedOops", "-XX:+UseG1GC", className);
+        args = TestCommon.concat(childVMOptionsPrefix, args);
 
         OutputAnalyzer output = TestCommon.exec(appJar, args);
         checkExec(output, extraMatches);
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsWbTest.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/SharedStringsWbTest.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,14 +27,10 @@
  * @summary White box test for shared strings
  * @requires vm.cds.archived.java.heap
  * @library /test/lib /test/hotspot/jtreg/runtime/appcds
- * @modules java.base/jdk.internal.misc
- * @modules java.management
- *          jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool/sun.tools.jar
  * @build sun.hotspot.WhiteBox SharedStringsWb
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  * @run driver SharedStringsWbTest
- * @run main/othervm -XX:+UseStringDeduplication SharedStringsWbTest
- * @run main/othervm -XX:-CompactStrings SharedStringsWbTest
  */
 
 import java.io.*;
@@ -42,6 +38,10 @@
 
 public class SharedStringsWbTest {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, SharedStringsWbTest::test);
+    }
+
+    public static void test(String[] args) throws Exception {
         SharedStringsUtils.buildJarAndWhiteBox("SharedStringsWb");
 
         SharedStringsUtils.dumpWithWhiteBox(TestCommon.list("SharedStringsWb"),
--- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/SysDictCrash.java	Fri Nov 02 23:44:45 2018 -0700
+++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/SysDictCrash.java	Mon Oct 29 14:01:46 2018 -0700
@@ -27,12 +27,9 @@
  * @summary Regression test for JDK-8098821
  * @bug 8098821
  * @requires vm.cds.archived.java.heap
+ * @modules jdk.jartool/sun.tools.jar
  * @library /test/lib /test/hotspot/jtreg/runtime/appcds
- * @modules java.base/jdk.internal.misc
- * @modules java.management
  * @run driver SysDictCrash
- * @run main/othervm -XX:+UseStringDeduplication SysDictCrash
- * @run main/othervm -XX:-CompactStrings SysDictCrash
  */
 
 import jdk.test.lib.process.OutputAnalyzer;
@@ -40,22 +37,30 @@
 
 public class SysDictCrash {
     public static void main(String[] args) throws Exception {
+        SharedStringsUtils.run(args, SysDictCrash::test);
+    }
+
+    public static void test(String[] args) throws Exception {
+        String vmOptionsPrefix[] = SharedStringsUtils.getChildVMOptionsPrefix();
+
         // SharedBaseAddress=0 puts the archive at a very high address on solaris,
         // which provokes the crash.
         ProcessBuilder dumpPb = ProcessTools.createJavaProcessBuilder(true,
+          TestCommon.concat(vmOptionsPrefix,
             "-XX:+UseG1GC", "-XX:MaxRAMPercentage=12.5",
             "-cp", ".",
             "-XX:SharedBaseAddress=0", "-XX:SharedArchiveFile=./SysDictCrash.jsa",
             "-Xshare:dump",
-            "-showversion", "-Xlog:cds,cds+hashtables");
+            "-showversion", "-Xlog:cds,cds+hashtables"));
 
         TestCommon.checkDump(TestCommon.executeAndLog(dumpPb, "dump"));
 
         ProcessBuilder runPb = ProcessTools.createJavaProcessBuilder(true,
+          TestCommon.concat(vmOptionsPrefix,
             "-XX:+UseG1GC", "-XX:MaxRAMPercentage=12.5",
             "-XX:SharedArchiveFile=./SysDictCrash.jsa",
             "-Xshare:on",
-            "-version");
+            "-version"));
 
         TestCommon.checkExec(TestCommon.executeAndLog(runPb, "exec"));
     }