test/runtime/SharedArchiveFile/CdsDifferentObjectAlignment.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.

@@ -32,11 +32,11 @@
  * @bug 8025642
  * @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;
 import jdk.test.lib.Platform;
 
 public class CdsDifferentObjectAlignment {
     public static void main(String[] args) throws Exception {

@@ -59,40 +59,18 @@
     throws Exception {
         String createAlignmentArgument = "-XX:ObjectAlignmentInBytes=" +
             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 " +
             "does not equal the current ObjectAlignmentInBytes of %d",
             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);
     }
 }