8172149: CTW library should call System::exit
authoriignatyev
Fri, 30 Dec 2016 20:11:49 +0300
changeset 43414 bd9a5a9dc9bc
parent 43413 d7c02958fdd4
child 43415 55cd866a84e9
8172149: CTW library should call System::exit Reviewed-by: vlivanov
hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java
hotspot/test/testlibrary_tests/ctw/ClassesDirTest.java
hotspot/test/testlibrary_tests/ctw/ClassesListTest.java
hotspot/test/testlibrary_tests/ctw/CtwTest.java
hotspot/test/testlibrary_tests/ctw/JarDirTest.java
hotspot/test/testlibrary_tests/ctw/JarsTest.java
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java	Tue Dec 27 22:34:07 2016 +0100
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java	Fri Dec 30 20:11:49 2016 +0300
@@ -59,6 +59,8 @@
             OUT = os;
         }
 
+        boolean passed = false;
+
         try {
             try {
                 if (ManagementFactory.getCompilationMXBean() == null) {
@@ -84,10 +86,10 @@
                     PathHandler.getClassCount(),
                     Compiler.getMethodCount(),
                     System.currentTimeMillis() - start);
+            passed = true;
         } finally {
-            if (os != null) {
-                os.close();
-            }
+            // <clinit> might have started new threads
+            System.exit(passed ? 0 : 1);
         }
     }
 
--- a/hotspot/test/testlibrary_tests/ctw/ClassesDirTest.java	Tue Dec 27 22:34:07 2016 +0100
+++ b/hotspot/test/testlibrary_tests/ctw/ClassesDirTest.java	Fri Dec 30 20:11:49 2016 +0300
@@ -30,11 +30,11 @@
  *          java.base/jdk.internal.reflect
  *          java.management
  * @build sun.hotspot.WhiteBox Foo Bar
- * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar
- *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main ClassesDirTest prepare
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld classes
- * @run main ClassesDirTest check ctw.log
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox Foo Bar
+ *                                sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run driver ClassesDirTest prepare
+ * @run driver ClassesDirTest compile classes
+ * @run driver ClassesDirTest check
  * @summary testing of CompileTheWorld :: classes in directory
  * @author igor.ignatyev@oracle.com
  */
--- a/hotspot/test/testlibrary_tests/ctw/ClassesListTest.java	Tue Dec 27 22:34:07 2016 +0100
+++ b/hotspot/test/testlibrary_tests/ctw/ClassesListTest.java	Fri Dec 30 20:11:49 2016 +0300
@@ -30,11 +30,11 @@
  *          java.base/jdk.internal.reflect
  *          java.management
  * @build sun.hotspot.WhiteBox Foo Bar
- * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar
- *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main ClassesListTest prepare
- * @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld classes.lst
- * @run main ClassesListTest check ctw.log
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox Foo Bar
+ *                                sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run driver ClassesListTest prepare
+ * @run driver/timeout=600 ClassesListTest compile classes.lst
+ * @run driver ClassesListTest check
  * @summary testing of CompileTheWorld :: list of classes in file
  * @author igor.ignatyev@oracle.com
  */
--- a/hotspot/test/testlibrary_tests/ctw/CtwTest.java	Tue Dec 27 22:34:07 2016 +0100
+++ b/hotspot/test/testlibrary_tests/ctw/CtwTest.java	Fri Dec 30 20:11:49 2016 +0300
@@ -21,6 +21,7 @@
  * questions.
  */
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Collections;
 import java.util.ArrayList;
@@ -38,8 +39,20 @@
 
 import jdk.test.lib.JDKToolFinder;
 import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.process.ProcessTools;
 
 public abstract class CtwTest {
+    private static final String LOG_FILE = "ctw.log";
+    private static final String[] CTW_COMMAND = {
+        "-Xbootclasspath/a:.",
+        "-XX:+UnlockDiagnosticVMOptions",
+        "-XX:+WhiteBoxAPI",
+        "-Dsun.hotspot.tools.ctw.logfile=" + LOG_FILE,
+        "--add-exports", "java.base/jdk.internal.jimage=ALL-UNNAMED",
+        "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED",
+        "--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
+        sun.hotspot.tools.ctw.CompileTheWorld.class.getName(),
+    };
     protected final String[] shouldContain;
     protected CtwTest(String[] shouldContain) {
         this.shouldContain = shouldContain;
@@ -54,7 +67,10 @@
                 prepare();
                 break;
             case "check":
-                check(args);
+                check();
+                break;
+            case "compile":
+                compile(args);
                 break;
             default:
                 throw new Error("unregonized action -- " + args[0]);
@@ -63,20 +79,27 @@
 
     protected void prepare() throws Exception { }
 
-    protected void check(String[] args) throws Exception  {
-        if (args.length < 2) {
-            throw new Error("logfile isn't specified");
-        }
-        String logfile = args[1];
-        try (BufferedReader r = Files.newBufferedReader(Paths.get(logfile),
+    protected void check() throws Exception  {
+        try (BufferedReader r = Files.newBufferedReader(Paths.get(LOG_FILE),
                 Charset.defaultCharset())) {
             OutputAnalyzer output = readOutput(r);
-           for (String test : shouldContain) {
+            for (String test : shouldContain) {
                 output.shouldContain(test);
             }
         }
     }
 
+    protected void compile(String[] args) throws Exception {
+        // concat CTW_COMMAND and args w/o 0th element
+        String[] cmd = Arrays.copyOf(CTW_COMMAND, CTW_COMMAND.length + args.length - 1);
+        System.arraycopy(args, 1, cmd, CTW_COMMAND.length, args.length - 1);
+
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmd);
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        dump(output, "compile");
+        output.shouldHaveExitValue(0);
+    }
+
     private static OutputAnalyzer readOutput(BufferedReader reader)
             throws IOException {
         StringBuilder builder = new StringBuilder();
--- a/hotspot/test/testlibrary_tests/ctw/JarDirTest.java	Tue Dec 27 22:34:07 2016 +0100
+++ b/hotspot/test/testlibrary_tests/ctw/JarDirTest.java	Fri Dec 30 20:11:49 2016 +0300
@@ -32,11 +32,11 @@
  *          java.management
  *          jdk.jvmstat/sun.jvmstat.monitor
  * @build sun.hotspot.WhiteBox Foo Bar
- * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar
- *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main JarDirTest prepare
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld jars/*
- * @run main JarDirTest check ctw.log
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox Foo Bar
+ *                                sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run driver JarDirTest prepare
+ * @run driver JarDirTest compile jars/*
+ * @run driver JarDirTest check
  * @summary testing of CompileTheWorld :: jars in directory
  * @author igor.ignatyev@oracle.com
  */
--- a/hotspot/test/testlibrary_tests/ctw/JarsTest.java	Tue Dec 27 22:34:07 2016 +0100
+++ b/hotspot/test/testlibrary_tests/ctw/JarsTest.java	Fri Dec 30 20:11:49 2016 +0300
@@ -32,11 +32,11 @@
  *          java.management
  *          jdk.jvmstat/sun.jvmstat.monitor
  * @build sun.hotspot.WhiteBox Foo Bar
- * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar
- *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main JarsTest prepare
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld foo.jar bar.jar
- * @run main JarsTest check ctw.log
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox Foo Bar
+ *                                sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run driver JarsTest prepare
+ * @run driver JarsTest compile foo.jar bar.jar
+ * @run driver JarsTest check
  * @summary testing of CompileTheWorld :: jars
  * @author igor.ignatyev@oracle.com
  */