diff graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java @ 10672:e7d07c9bb779

Removed priority compilation queue. Fixed another race condition in the compilation queue. Removed Graal-specific compilation policy.
author Christian Haeubl <haeubl@ssw.jku.at>
date Tue, 09 Jul 2013 17:53:58 +0200
parents 25de9c96a032
children d335c16d2fe7
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Jul 09 11:21:06 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Jul 09 17:53:58 2013 +0200
@@ -64,12 +64,6 @@
     @Option(help = "File to which compiler logging is sent")
     private static final OptionValue<String> LogFile = new OptionValue<>(null);
 
-    @Option(help = "Use low priority compilation threads")
-    private static final OptionValue<Boolean> SlowCompileThreads = new OptionValue<>(false);
-
-    @Option(help = "Use priority-based compilation queue")
-    private static final OptionValue<Boolean> PriorityCompileQueue = new OptionValue<>(true);
-
     @Option(help = "Print compilation queue activity periodically")
     private static final OptionValue<Boolean> PrintQueue = new OptionValue<>(false);
 
@@ -108,7 +102,6 @@
     public final HotSpotResolvedPrimitiveType typeVoid;
 
     private ThreadPoolExecutor compileQueue;
-    private ThreadPoolExecutor slowCompileQueue;
     private AtomicInteger compileTaskIds = new AtomicInteger();
 
     private volatile boolean bootstrapRunning;
@@ -211,13 +204,7 @@
         }
 
         // Create compilation queue.
-        BlockingQueue<Runnable> queue = PriorityCompileQueue.getValue() ? new PriorityBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>();
-        compileQueue = new ThreadPoolExecutor(Threads.getValue(), Threads.getValue(), 0L, TimeUnit.MILLISECONDS, queue, CompilerThread.FACTORY);
-
-        if (SlowCompileThreads.getValue()) {
-            BlockingQueue<Runnable> slowQueue = PriorityCompileQueue.getValue() ? new PriorityBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>();
-            slowCompileQueue = new ThreadPoolExecutor(Threads.getValue(), Threads.getValue(), 0L, TimeUnit.MILLISECONDS, slowQueue, CompilerThread.LOW_PRIORITY_FACTORY);
-        }
+        compileQueue = new ThreadPoolExecutor(Threads.getValue(), Threads.getValue(), 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), CompilerThread.FACTORY);
 
         // Create queue status printing thread.
         if (PrintQueue.getValue()) {
@@ -226,11 +213,7 @@
                 @Override
                 public void run() {
                     while (true) {
-                        if (slowCompileQueue == null) {
-                            TTY.println(compileQueue.toString());
-                        } else {
-                            TTY.println("fast: " + compileQueue.toString() + " slow: " + slowCompileQueue);
-                        }
+                        TTY.println(compileQueue.toString());
                         try {
                             Thread.sleep(1000);
                         } catch (InterruptedException e) {
@@ -395,14 +378,8 @@
                 try {
                     assert !CompilationTask.withinEnqueue.get();
                     CompilationTask.withinEnqueue.set(Boolean.TRUE);
-                    if (slowCompileQueue == null) {
-                        if (compileQueue.getCompletedTaskCount() >= Math.max(3, compileQueue.getTaskCount())) {
-                            break;
-                        }
-                    } else {
-                        if (compileQueue.getCompletedTaskCount() + slowCompileQueue.getCompletedTaskCount() >= Math.max(3, compileQueue.getTaskCount() + slowCompileQueue.getTaskCount())) {
-                            break;
-                        }
+                    if (compileQueue.getCompletedTaskCount() >= Math.max(3, compileQueue.getTaskCount())) {
+                        break;
                     }
                 } finally {
                     CompilationTask.withinEnqueue.set(Boolean.FALSE);
@@ -440,7 +417,7 @@
     private void enqueue(Method m) throws Throwable {
         JavaMethod javaMethod = graalRuntime.getRuntime().lookupJavaMethod(m);
         assert !Modifier.isAbstract(((HotSpotResolvedJavaMethod) javaMethod).getModifiers()) && !Modifier.isNative(((HotSpotResolvedJavaMethod) javaMethod).getModifiers()) : javaMethod;
-        compileMethod((HotSpotResolvedJavaMethod) javaMethod, StructuredGraph.INVOCATION_ENTRY_BCI, false, 10);
+        compileMethod((HotSpotResolvedJavaMethod) javaMethod, StructuredGraph.INVOCATION_ENTRY_BCI, false);
     }
 
     private static void shutdownCompileQueue(ThreadPoolExecutor queue) throws InterruptedException {
@@ -458,7 +435,6 @@
             assert !CompilationTask.withinEnqueue.get();
             CompilationTask.withinEnqueue.set(Boolean.TRUE);
             shutdownCompileQueue(compileQueue);
-            shutdownCompileQueue(slowCompileQueue);
         } finally {
             CompilationTask.withinEnqueue.set(Boolean.FALSE);
         }
@@ -576,15 +552,15 @@
     }
 
     @Override
-    public void compileMethod(long metaspaceMethod, final HotSpotResolvedObjectType holder, final int entryBCI, boolean blocking, int priority) throws Throwable {
+    public void compileMethod(long metaspaceMethod, final HotSpotResolvedObjectType holder, final int entryBCI, boolean blocking) throws Throwable {
         HotSpotResolvedJavaMethod method = holder.createMethod(metaspaceMethod);
-        compileMethod(method, entryBCI, blocking, priority);
+        compileMethod(method, entryBCI, blocking);
     }
 
     /**
      * Compiles a method to machine code.
      */
-    public void compileMethod(final HotSpotResolvedJavaMethod method, final int entryBCI, boolean blocking, int priority) throws Throwable {
+    public void compileMethod(final HotSpotResolvedJavaMethod method, final int entryBCI, boolean blocking) 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,
@@ -600,39 +576,24 @@
             return;
         }
 
+        CompilationTask.withinEnqueue.set(Boolean.TRUE);
         try {
-            CompilationTask.withinEnqueue.set(Boolean.TRUE);
-            if (!method.tryToQueueForCompilation()) {
-                // method is already queued
-                CompilationTask current = method.currentTask();
-                if (!PriorityCompileQueue.getValue() || current == null || !current.tryToCancel()) {
-                    // normally compilation tasks will only be re-queued when they get a
-                    // priority boost, so cancel the old task and add a new one
-                    // without a prioritizing compile queue it makes no sense to re-queue the
-                    // compilation task
-                    return;
-                }
-            }
-            assert method.isQueuedForCompilation();
+            if (method.tryToQueueForCompilation()) {
+                assert method.isQueuedForCompilation();
+
+                final OptimisticOptimizations optimisticOpts = new OptimisticOptimizations(method);
+                int id = compileTaskIds.incrementAndGet();
+                CompilationTask task = CompilationTask.create(graalRuntime, createPhasePlan(optimisticOpts, osrCompilation), optimisticOpts, method, entryBCI, id);
 
-            final OptimisticOptimizations optimisticOpts = new OptimisticOptimizations(method);
-            int id = compileTaskIds.incrementAndGet();
-            // 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 {
-                try {
-                    method.setCurrentTask(task);
-                    if (SlowCompileThreads.getValue() && priority > SlowQueueCutoff.getValue()) {
-                        slowCompileQueue.execute(task);
-                    } else {
+                if (blocking) {
+                    task.runCompilation();
+                } else {
+                    try {
+                        method.setCurrentTask(task);
                         compileQueue.execute(task);
+                    } catch (RejectedExecutionException e) {
+                        // The compile queue was already shut down.
                     }
-                } catch (RejectedExecutionException e) {
-                    // The compile queue was already shut down.
                 }
             }
         } finally {