Merge
authoriveresov
Wed, 19 Apr 2017 04:10:56 +0000
changeset 46395 ab5b504181d8
parent 46392 d5572756efd6 (diff)
parent 46394 c5bfe8f7bb1e (current diff)
child 46396 4cca6758a9ee
child 46400 3b90b2f0d575
Merge
hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArchHotSpotNodeCostProvider.java
hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotNodeCostProvider.java
hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.sparc/src/org/graalvm/compiler/hotspot/sparc/SPARCHotSpotNodeCostProvider.java
hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompileTheWorld.java
hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompileTheWorldOptions.java
hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/nodes/HotSpotNodeCostProvider.java
hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/spi/DefaultNodeCostProvider.java
hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/spi/NodeCostProvider.java
--- a/hotspot/test/applications/ctw/Modules.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/applications/ctw/Modules.java	Wed Apr 19 04:10:56 2017 +0000
@@ -33,6 +33,6 @@
  * @build sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run driver/timeout=0 sun.hotspot.tools.ctw.CtwRunner modules
+ * @run main/timeout=0 sun.hotspot.tools.ctw.CtwRunner modules
  */
 
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathDirEntry.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathDirEntry.java	Wed Apr 19 04:10:56 2017 +0000
@@ -66,6 +66,16 @@
         }
     }
 
+    @Override
+    public long classCount() {
+        try {
+            return Files.walk(root, FileVisitOption.FOLLOW_LINKS).count();
+        } catch (IOException e) {
+            throw new Error("can not walk dir " + root + " : "
+                    + e.getMessage(), e);
+        }
+    }
+
     private void processFile(Path file) {
         if (Utils.isClassFile(file.toString())) {
             processClass(pathToClassName(file));
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java	Wed Apr 19 04:10:56 2017 +0000
@@ -54,8 +54,7 @@
         if (!Files.exists(root)) {
             return;
         }
-        try {
-            JarFile jarFile = new JarFile(root.toFile());
+        try (JarFile jarFile = new JarFile(root.toFile())) {
             JarEntry entry;
             for (Enumeration<JarEntry> e = jarFile.entries();
                     e.hasMoreElements(); ) {
@@ -70,7 +69,20 @@
         }
     }
 
-     private void processJarEntry(JarEntry entry) {
+    @Override
+    public long classCount() {
+        try (JarFile jarFile = new JarFile(root.toFile())) {
+            return jarFile.stream()
+                    .map(JarEntry::getName)
+                    .filter(Utils::isClassFile)
+                    .count();
+        } catch (IOException e) {
+            throw new Error("can not open jar file " + root + " : "
+                    + e.getMessage() , e);
+        }
+    }
+
+    private void processJarEntry(JarEntry entry) {
         String filename = entry.getName();
         if (Utils.isClassFile(filename)) {
             processClass(Utils.fileNameToClassName(filename));
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarInDirEntry.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarInDirEntry.java	Wed Apr 19 04:10:56 2017 +0000
@@ -56,5 +56,18 @@
             ioe.printStackTrace();
         }
     }
+
+    @Override
+    public long classCount() {
+        try {
+            return Files.list(root)
+                    .filter(p -> p.getFileName().toString().endsWith(".jar"))
+                    .map(p -> new ClassPathJarEntry(p, executor))
+                    .mapToLong(ClassPathJarEntry::classCount).sum();
+        } catch (IOException e) {
+            throw new Error("can not walk dir " + root + " : "
+                    + e.getMessage(), e);
+        }
+    }
 }
 
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java	Wed Apr 19 04:10:56 2017 +0000
@@ -54,8 +54,7 @@
         if (!Files.exists(root)) {
             return;
         }
-        try {
-            ImageReader reader = ImageReader.open(root);
+        try (ImageReader reader = ImageReader.open(root)) {
             Arrays.stream(reader.getEntryNames())
                     .filter(name -> name.endsWith(".class"))
                     .filter(name -> !name.endsWith("module-info.class"))
@@ -65,4 +64,18 @@
             ioe.printStackTrace();
         }
     }
+
+    @Override
+    public long classCount() {
+        try (ImageReader reader = ImageReader.open(root)) {
+            return Arrays.stream(reader.getEntryNames())
+                    .filter(name -> name.endsWith(".class"))
+                    .filter(name -> !name.endsWith("module-info.class"))
+                    .map(Utils::fileNameToClassName)
+                    .count();
+        } catch (IOException e) {
+            throw new Error("can not open jimage file " + root + " : "
+                    + e.getMessage() , e);
+        }
+    }
 }
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassesListInFile.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassesListInFile.java	Wed Apr 19 04:10:56 2017 +0000
@@ -45,8 +45,7 @@
             return;
         }
         try {
-            try (BufferedReader reader = Files.newBufferedReader(root,
-                    StandardCharsets.UTF_8)) {
+            try (BufferedReader reader = Files.newBufferedReader(root)) {
                 String line;
                 while (!isFinished() && ((line = reader.readLine()) != null)) {
                     processClass(line);
@@ -56,4 +55,16 @@
             e.printStackTrace();
         }
     }
+
+    @Override
+    public long classCount() {
+        try {
+            try (BufferedReader reader = Files.newBufferedReader(root)) {
+                return reader.lines().count();
+            }
+        } catch (IOException e) {
+            throw new Error("can not read list " + root + " : "
+                    + e.getMessage(), e);
+        }
+    }
 }
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java	Wed Apr 19 04:10:56 2017 +0000
@@ -83,13 +83,17 @@
                 await(executor);
             }
             CompileTheWorld.OUT.printf("Done (%d classes, %d methods, %d ms)%n",
-                    PathHandler.getClassCount(),
+                    PathHandler.getProcessedClassCount(),
                     Compiler.getMethodCount(),
                     System.currentTimeMillis() - start);
             passed = true;
         } catch (Throwable t){
             t.printStackTrace(ERR);
         } finally {
+            try {
+                OUT.close();
+            } catch (Throwable ignore) {
+            }
             // <clinit> might have started new threads
             System.exit(passed ? 0 : 1);
         }
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java	Wed Apr 19 04:10:56 2017 +0000
@@ -23,16 +23,20 @@
 
 package sun.hotspot.tools.ctw;
 
+import jdk.test.lib.Asserts;
 import jdk.test.lib.Utils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.util.Pair;
 
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Predicate;
 import java.util.regex.Pattern;
@@ -97,7 +101,10 @@
 
 
     private void startCtwforAllClasses() {
-        long classStart = 0;
+        long classStart = 0L;
+        long classCount = classCount();
+        Asserts.assertGreaterThan(classCount, 0L,
+                targetPath + " does not have any classes");
         boolean done = false;
         while (!done) {
             String[] cmd = cmd(classStart);
@@ -123,6 +130,16 @@
                         exitCode);
                 Pair<String, Long> lastClass = getLastClass(out);
                 if (exitCode == 0) {
+                    long lastIndex = lastClass == null ? -1 : lastClass.second;
+                    if (lastIndex != classCount) {
+                        errors.add(new Error(phase + ": Unexpected zero exit code"
+                                + "before finishing all compilations."
+                                + " lastClass[" + lastIndex
+                                + "] != classCount[" + classCount + "]"));
+                    } else {
+                        System.out.println("Executed CTW for all " + classCount
+                                + " classes in " + targetPath);
+                    }
                     done = true;
                 } else {
                     if (lastClass == null) {
@@ -144,12 +161,17 @@
         }
     }
 
+    private long classCount() {
+        return PathHandler.create(targetPath.toString(), Runnable::run)
+                .classCount();
+    }
+
     private Pair<String, Long> getLastClass(Path errFile) {
-        try {
-            String line = Files.newBufferedReader(errFile)
-                    .lines()
+        try (BufferedReader reader = Files.newBufferedReader(errFile)) {
+            String line = reader.lines()
                     .filter(IS_CLASS_LINE)
-                    .reduce((a, b) -> b).orElse(null);
+                    .reduce((a, b) -> b)
+                    .orElse(null);
             if (line != null) {
                 int open = line.indexOf('[') + 1;
                 int close = line.indexOf(']');
@@ -166,7 +188,7 @@
 
     private String[] cmd(long classStart) {
         String phase = phaseName(classStart);
-        return new String[]{
+        return new String[] {
                 "-Xbatch",
                 "-XX:-UseCounterDecay",
                 "-XX:-ShowMessageBoxOnError",
--- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java	Wed Apr 19 03:21:41 2017 +0000
+++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java	Wed Apr 19 04:10:56 2017 +0000
@@ -62,7 +62,7 @@
         this.loader = ClassLoader.getSystemClassLoader();
     }
 
-   /**
+    /**
      * Factory method. Construct concrete handler in depends from {@code path}.
      *
      * @param path     the path to process
@@ -118,11 +118,16 @@
     }
 
     /**
-     * Processes all classes in specified path.
+     * Processes all classes in the specified path.
      */
     public abstract void process();
 
-   /**
+    /**
+     * @return count of all classes in the specified path.
+     */
+    public abstract long classCount();
+
+    /**
      * Sets class loader, that will be used to define class at
      * {@link #processClass(String)}.
      *
@@ -168,7 +173,7 @@
     /**
      * @return count of processed classes
      */
-    public static long getClassCount() {
+    public static long getProcessedClassCount() {
         long id = CLASS_COUNT.get();
         if (id < Utils.COMPILE_THE_WORLD_START_AT) {
             return 0;