changeset 20014:dab7f071220a

Wait until all classes are loaded before compiling in multithreaded CTW
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Mon, 23 Mar 2015 12:21:25 -0700
parents 8ea3dde07ff7
children ae0e4453df73
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java	Mon Mar 23 12:20:49 2015 -0700
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java	Mon Mar 23 12:21:25 2015 -0700
@@ -160,6 +160,11 @@
     private boolean verbose;
     private final Config config;
 
+    /**
+     * Signal that the threads should start compiling in multithreaded mode.
+     */
+    private boolean running;
+
     private ThreadPoolExecutor threadPool;
 
     /**
@@ -327,6 +332,7 @@
         }
 
         if (threadPool != null) {
+            startThreads();
             while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) {
                 System.out.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles");
                 try {
@@ -344,6 +350,21 @@
                         compileTime.get(), memoryUsed.get());
     }
 
+    private synchronized void startThreads() {
+        running = true;
+        // Wake up any waiting threads
+        notifyAll();
+    }
+
+    private synchronized void waitToRun() {
+        while (!running) {
+            try {
+                wait();
+            } catch (InterruptedException e) {
+            }
+        }
+    }
+
     class CTWCompilationTask extends CompilationTask {
 
         CTWCompilationTask(HotSpotBackend backend, HotSpotResolvedJavaMethod method) {
@@ -364,6 +385,7 @@
         if (threadPool != null) {
             threadPool.submit(new Runnable() {
                 public void run() {
+                    waitToRun();
                     try (OverrideScope s = config.apply()) {
                         compileMethod(method, classFileCounter);
                     }