test/runtime/SharedArchiveFile/SharedStrings.java

Print this page

        

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

@@ -34,58 +34,44 @@
  *          java.management
  * @build SharedStringsWb sun.hotspot.WhiteBox
  * @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 servces 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",
             "-XX:+UseG1GC",
             "-XX:+UseCompressedOops",
             "-XX:+PrintSharedSpaces",
             // Needed for bootclasspath match, for CDS to work with WhiteBox API
             "-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(
                 "-XX:+UnlockDiagnosticVMOptions",
                 "-XX:SharedArchiveFile=./SharedStrings.jsa",
                 // these are required modes for shared strings
                 "-XX:+UseCompressedOops", "-XX:+UseG1GC",
                 // needed for access to white box test API
                 "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"),
                 "-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);
     }
 }