changeset 6962:e9f69041ac38

Merge.
author Doug Simon <doug.simon@oracle.com>
date Sun, 18 Nov 2012 21:30:35 +0100
parents 72b8f81ef9c4 (current diff) 98d691bc23da (diff)
children dd0dd0321e2a
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java src/share/vm/graal/graalCompiler.hpp
diffstat 3 files changed, 41 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Sun Nov 18 21:20:31 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Sun Nov 18 21:30:35 2012 +0100
@@ -42,15 +42,8 @@
         }
     };
 
-    public static final ThreadLocal<Long> withinCompilation = new ThreadLocal<Long>() {
-        @Override
-        protected Long initialValue() {
-            return 0L;
-        }
-    };
-
-
     private volatile boolean cancelled;
+    private volatile boolean inProgress;
 
     private final HotSpotGraalRuntime graalRuntime;
     private final PhasePlan plan;
@@ -59,13 +52,12 @@
     private final int entryBCI;
     private final int id;
     private final int priority;
-    private final Runnable callback;
 
-    public static CompilationTask create(HotSpotGraalRuntime graalRuntime, PhasePlan plan, OptimisticOptimizations optimisticOpts, HotSpotResolvedJavaMethod method, int entryBCI, int id, int priority, Runnable callback) {
-        return new CompilationTask(graalRuntime, plan, optimisticOpts, method, entryBCI, id, priority, callback);
+    public static CompilationTask create(HotSpotGraalRuntime graalRuntime, PhasePlan plan, OptimisticOptimizations optimisticOpts, HotSpotResolvedJavaMethod method, int entryBCI, int id, int priority) {
+        return new CompilationTask(graalRuntime, plan, optimisticOpts, method, entryBCI, id, priority);
     }
 
-    private CompilationTask(HotSpotGraalRuntime graalRuntime, PhasePlan plan, OptimisticOptimizations optimisticOpts, HotSpotResolvedJavaMethod method, int entryBCI, int id, int priority, Runnable callback) {
+    private CompilationTask(HotSpotGraalRuntime graalRuntime, PhasePlan plan, OptimisticOptimizations optimisticOpts, HotSpotResolvedJavaMethod method, int entryBCI, int id, int priority) {
         this.graalRuntime = graalRuntime;
         this.plan = plan;
         this.method = method;
@@ -73,14 +65,13 @@
         this.entryBCI = entryBCI;
         this.id = id;
         this.priority = priority;
-        this.callback = callback;
     }
 
-    public ResolvedJavaMethod method() {
+    public ResolvedJavaMethod getMethod() {
         return method;
     }
 
-    public int priority() {
+    public int getPriority() {
         return priority;
     }
 
@@ -88,12 +79,21 @@
         cancelled = true;
     }
 
+    public boolean isInProgress() {
+        return inProgress;
+    }
+
+    public int getEntryBCI() {
+        return entryBCI;
+    }
+
     public void run() {
         withinEnqueue.set(Boolean.FALSE);
         try {
             if (cancelled) {
                 return;
             }
+            inProgress = true;
             if (GraalOptions.DynamicCompilePriority) {
                 int threadPriority = priority < GraalOptions.SlowQueueCutoff ? Thread.NORM_PRIORITY : Thread.MIN_PRIORITY;
                 if (Thread.currentThread().getPriority() != threadPriority) {
@@ -105,12 +105,12 @@
                 method.setCurrentTask(null);
             }
         } finally {
+            inProgress = false;
             withinEnqueue.set(Boolean.TRUE);
         }
     }
 
     public void runCompilation() {
-        withinCompilation.set(withinCompilation.get() + 1);
         CompilationStatistics stats = CompilationStatistics.create(method);
         try {
             final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed();
@@ -156,10 +156,6 @@
             }
         }
         stats.finish(method);
-        if (callback != null) {
-            callback.run();
-        }
-        withinCompilation.set(withinCompilation.get() - 1);
     }
 
     private void installMethod(final CompilationResult tm) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Sun Nov 18 21:20:31 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Sun Nov 18 21:30:35 2012 +0100
@@ -67,6 +67,8 @@
     private ThreadPoolExecutor slowCompileQueue;
     private AtomicInteger compileTaskIds = new AtomicInteger();
 
+    private volatile boolean bootstrapRunning;
+
     private PrintStream log = System.out;
 
     public VMToCompilerImpl(HotSpotGraalRuntime compiler) {
@@ -191,6 +193,7 @@
         TTY.flush();
         long startTime = System.currentTimeMillis();
 
+        bootstrapRunning = true;
         boolean firstRun = true;
         do {
             // Initialize compile queue with a selected set of methods.
@@ -234,6 +237,7 @@
             }
         } while ((System.currentTimeMillis() - startTime) <= GraalOptions.TimedBootstrap);
         CompilationStatistics.clear("bootstrap");
+        bootstrapRunning = false;
 
         TTY.println(" in %d ms", System.currentTimeMillis() - startTime);
         if (graalRuntime.getCache() != null) {
@@ -375,6 +379,11 @@
     }
 
     public boolean compileMethod(final HotSpotResolvedJavaMethod method, final int entryBCI, boolean blocking, int priority) throws Throwable {
+        boolean osrCompilation = entryBCI != StructuredGraph.INVOCATION_ENTRY_BCI;
+        if (osrCompilation && bootstrapRunning) {
+            // no OSR compilations during bootstrap - the compiler is just too slow at this point, and we know that there are no endless loops
+            return true;
+        }
 
         if (CompilationTask.withinEnqueue.get()) {
             // This is required to avoid deadlocking a compiler thread. The issue is that a
@@ -383,24 +392,32 @@
             // to add something to its own queue.
             return false;
         }
-
         CompilationTask.withinEnqueue.set(Boolean.TRUE);
 
         try {
             CompilationTask current = method.currentTask();
             if (!blocking && current != null) {
-                if (GraalOptions.PriorityCompileQueue) {
-                    // normally compilation tasks will only be re-queued when they get a priority boost, so cancel the old task and add a new one
-                    current.cancel();
+                if (current.isInProgress()) {
+                    if (current.getEntryBCI() == entryBCI) {
+                        // a compilation with the correct bci is already in progress, so just return true
+                        return true;
+                    }
                 } else {
-                    // without a prioritizing compile queue it makes no sense to re-queue the compilation task
-                    return true;
+                    if (GraalOptions.PriorityCompileQueue) {
+                        // normally compilation tasks will only be re-queued when they get a priority boost, so cancel the old task and add a new one
+                        current.cancel();
+                    } else {
+                        // without a prioritizing compile queue it makes no sense to re-queue the compilation task
+                        return true;
+                    }
                 }
             }
 
             final OptimisticOptimizations optimisticOpts = new OptimisticOptimizations(method);
             int id = compileTaskIds.incrementAndGet();
-            CompilationTask task = CompilationTask.create(graalRuntime, createPhasePlan(optimisticOpts, false), optimisticOpts, method, StructuredGraph.INVOCATION_ENTRY_BCI, id, priority, null);
+            // OSR compilations need to be finished quickly, so they get max priority
+            int queuePriority = osrCompilation ? -1 : priority;
+            CompilationTask task = CompilationTask.create(graalRuntime, createPhasePlan(optimisticOpts, osrCompilation), optimisticOpts, method, entryBCI, id, queuePriority);
             if (blocking) {
                 task.runCompilation();
             } else {
@@ -416,22 +433,6 @@
                     return false;
                 }
             }
-            if (entryBCI != StructuredGraph.INVOCATION_ENTRY_BCI && CompilationTask.withinCompilation.get() == 0) {
-                final OptimisticOptimizations osrOptimisticOpts = new OptimisticOptimizations(method);
-                int osrId = compileTaskIds.incrementAndGet();
-                Debug.log("OSR compilation %s@%d", method, entryBCI);
-                final CountDownLatch latch = new CountDownLatch(1);
-                Runnable callback = new Runnable() {
-                    @Override
-                    public void run() {
-                        latch.countDown();
-                    }
-                };
-                CompilationTask osrTask = CompilationTask.create(graalRuntime, createPhasePlan(osrOptimisticOpts, true), osrOptimisticOpts, method, entryBCI, osrId, Integer.MAX_VALUE, callback);
-                compileQueue.execute(osrTask);
-                latch.await();
-                return true;
-            }
             return true;
         } finally {
             CompilationTask.withinEnqueue.set(Boolean.FALSE);
--- a/src/share/vm/graal/graalCompiler.hpp	Sun Nov 18 21:20:31 2012 +0100
+++ b/src/share/vm/graal/graalCompiler.hpp	Sun Nov 18 21:30:35 2012 +0100
@@ -50,7 +50,7 @@
 
   // Native / OSR not supported
   virtual bool supports_native()                 { return true; }
-  virtual bool supports_osr   ()                 { return false; }
+  virtual bool supports_osr   ()                 { return true; }
 
   // Pretend to be C1
   bool is_c1   ()                                { return true; }