test/runtime/SharedArchiveFile/CdsDifferentCompactStrings.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -28,11 +28,11 @@
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
  *          java.management
  */
 
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 
 public class CdsDifferentCompactStrings {
     public static void main(String[] args) throws Exception {
         createAndLoadSharedArchive("+", "-");

@@ -43,34 +43,16 @@
         throws Exception
     {
         String createCompactStringsArgument = "-XX:" + create + "CompactStrings";
         String loadCompactStringsArgument   = "-XX:" + load   + "CompactStrings";
 
-        String filename = "./CdsDifferentCompactStrings" + create + ".jsa";
+        OutputAnalyzer out = CDSTestUtils.createArchive(createCompactStringsArgument);
+        CDSTestUtils.checkDump(out);
 
-        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);
-
-        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);
     }
 }