changeset 5183:e1e681a5558e

fix PriorityQueue, enable PriorityQueue and CacheGraphs
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 02 Apr 2012 19:46:48 +0200
parents 70aaaa83b93a
children d5cf399e6637
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/EscapeField.java src/share/vm/interpreter/invocationCounter.cpp src/share/vm/runtime/globals.hpp
diffstat 6 files changed, 118 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java	Mon Apr 02 12:19:18 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java	Mon Apr 02 19:46:48 2012 +0200
@@ -84,13 +84,14 @@
     public static int     MatureExecutionsTypeProfile        = 1;
 
     // comilation queue
-    public static boolean PriorityCompileQueue               = ____;
+    public static int     TimedBootstrap                     = -1;
+    public static boolean PriorityCompileQueue               = true;
     public static int     SlowQueueCutoff                    = 100000;
     public static boolean SlowCompileThreads                 = ____;
     public static boolean DynamicCompilePriority             = ____;
 
     // graph caching
-    public static boolean CacheGraphs                        = ____;
+    public static boolean CacheGraphs                        = true;
     public static int     GraphCacheSize                     = 1000;
     public static boolean PrintGraphCache                    = ____;
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Mon Apr 02 12:19:18 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Mon Apr 02 19:46:48 2012 +0200
@@ -22,6 +22,7 @@
  */
 package com.oracle.graal.hotspot;
 
+import java.io.*;
 import java.util.concurrent.*;
 
 import com.oracle.graal.compiler.*;
@@ -36,6 +37,15 @@
 
 public final class CompilationTask implements Runnable, Comparable<CompilationTask> {
 
+
+    public static final ThreadLocal<Boolean> withinEnqueue = new ThreadLocal<Boolean>() {
+        @Override
+        protected Boolean initialValue() {
+            return Boolean.valueOf(Thread.currentThread() instanceof CompilerThread);
+        }
+    };
+
+
     private volatile boolean cancelled;
 
     private final Compiler compiler;
@@ -73,16 +83,28 @@
 //    private static PrintStream out = System.out;
 
     public void run() {
-        if (cancelled) {
-            return;
+        withinEnqueue.set(Boolean.FALSE);
+        try {
+            if (cancelled) {
+                return;
+            }
+            if (GraalOptions.DynamicCompilePriority) {
+                int threadPriority = priority < GraalOptions.SlowQueueCutoff ? Thread.NORM_PRIORITY : Thread.MIN_PRIORITY;
+                if (Thread.currentThread().getPriority() != threadPriority) {
+    //                out.print(threadPriority);
+                    Thread.currentThread().setPriority(threadPriority);
+                }
+            }
+            runCompilation();
+            if (method.currentTask() == this) {
+                method.setCurrentTask(null);
+            }
+        } finally {
+            withinEnqueue.set(Boolean.TRUE);
         }
-        if (GraalOptions.DynamicCompilePriority) {
-            int threadPriority = priority < GraalOptions.SlowQueueCutoff ? Thread.NORM_PRIORITY : Thread.MIN_PRIORITY;
-            if (Thread.currentThread().getPriority() != threadPriority) {
-//                out.print(threadPriority);
-                Thread.currentThread().setPriority(threadPriority);
-            }
-        }
+    }
+
+    public void runCompilation() {
         CiCompilationStatistics stats = CiCompilationStatistics.create(method);
         try {
             final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed();
@@ -121,9 +143,6 @@
             }
         }
         stats.finish(method);
-        if (method.currentTask() == this) {
-            method.setCurrentTask(null);
-        }
     }
 
     @Override
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Mon Apr 02 12:19:18 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Mon Apr 02 19:46:48 2012 +0200
@@ -113,21 +113,11 @@
         }
 
         // Create compilation queue.
-        final BlockingQueue<Runnable> queue;
-        if (GraalOptions.PriorityCompileQueue) {
-            queue = new PriorityBlockingQueue<>();
-        } else {
-            queue = new LinkedBlockingQueue<>();
-        }
+        BlockingQueue<Runnable> queue = GraalOptions.PriorityCompileQueue ? new PriorityBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>();
         compileQueue = new ThreadPoolExecutor(GraalOptions.Threads, GraalOptions.Threads, 0L, TimeUnit.MILLISECONDS, queue, CompilerThread.FACTORY);
 
         if (GraalOptions.SlowCompileThreads) {
-            final BlockingQueue<Runnable> slowQueue;
-            if (GraalOptions.PriorityCompileQueue) {
-                slowQueue = new PriorityBlockingQueue<>();
-            } else {
-                slowQueue = new LinkedBlockingQueue<>();
-            }
+            BlockingQueue<Runnable> slowQueue = GraalOptions.PriorityCompileQueue ? new PriorityBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>();
             slowCompileQueue = new ThreadPoolExecutor(GraalOptions.Threads, GraalOptions.Threads, 0L, TimeUnit.MILLISECONDS, slowQueue, CompilerThread.LOW_PRIORITY_FACTORY);
         }
 
@@ -171,23 +161,43 @@
         TTY.flush();
         long startTime = System.currentTimeMillis();
 
-        // Initialize compile queue with a selected set of methods.
-        Class<Object> objectKlass = Object.class;
-        enqueue(getClass().getDeclaredMethod("compileWarmup"));
-        enqueue(objectKlass.getDeclaredMethod("equals", Object.class));
-        enqueue(objectKlass.getDeclaredMethod("toString"));
+        boolean firstRun = true;
+        do {
+            // Initialize compile queue with a selected set of methods.
+            Class<Object> objectKlass = Object.class;
+            if (firstRun) {
+                enqueue(getClass().getDeclaredMethod("compileWarmup"));
+                enqueue(objectKlass.getDeclaredMethod("equals", Object.class));
+                enqueue(objectKlass.getDeclaredMethod("toString"));
+                firstRun = false;
+            } else {
+                for (int i = 0; i < 100; i++) {
+                    enqueue(getClass().getDeclaredMethod("bootstrap"));
+                }
+            }
 
-        // Compile until the queue is empty.
-        int z = 0;
-        while (compileQueue.getCompletedTaskCount() < Math.max(3, compileQueue.getTaskCount()) || (
-                        slowCompileQueue != null && slowCompileQueue.getCompletedTaskCount() < Math.max(3, slowCompileQueue.getTaskCount()))) {
-            Thread.sleep(100);
-            while (z < compileQueue.getCompletedTaskCount() / 100) {
-                ++z;
-                TTY.print(".");
-                TTY.flush();
+            // Compile until the queue is empty.
+            int z = 0;
+            if (slowCompileQueue == null) {
+                while (compileQueue.getCompletedTaskCount() < Math.max(3, compileQueue.getTaskCount())) {
+                    Thread.sleep(100);
+                    while (z < compileQueue.getCompletedTaskCount() / 100) {
+                        ++z;
+                        TTY.print(".");
+                        TTY.flush();
+                    }
+                }
+            } else {
+                while (compileQueue.getCompletedTaskCount() + slowCompileQueue.getCompletedTaskCount() < Math.max(3, compileQueue.getTaskCount() + slowCompileQueue.getTaskCount())) {
+                    Thread.sleep(100);
+                    while (z < (compileQueue.getCompletedTaskCount() + slowCompileQueue.getCompletedTaskCount()) / 100) {
+                        ++z;
+                        TTY.print(".");
+                        TTY.flush();
+                    }
+                }
             }
-        }
+        } while ((System.currentTimeMillis() - startTime) <= GraalOptions.TimedBootstrap);
         CiCompilationStatistics.clear("bootstrap");
 
         TTY.println(" in %d ms", System.currentTimeMillis() - startTime);
@@ -306,46 +316,49 @@
 
     @Override
     public boolean compileMethod(final HotSpotMethodResolved method, final int entryBCI, boolean blocking, int priority) throws Throwable {
-        if (Thread.currentThread() instanceof CompilerThread) {
-            if (method.holder().name().contains("java/util/concurrent")) {
-                // This is required to avoid deadlocking a compiler thread. The issue is that a
-                // java.util.concurrent.BlockingQueue is used to implement the compilation worker
-                // queues. If a compiler thread triggers a compilation, then it may be blocked trying
-                // to add something to its own queue.
-                return false;
-            }
-        }
-
-        CompilationTask current = method.currentTask();
-        if (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();
-            } else {
-                // without a prioritizing compile queue it makes no sense to re-queue the compilation task
-                return true;
-            }
+        if (CompilationTask.withinEnqueue.get()) {
+            // This is required to avoid deadlocking a compiler thread. The issue is that a
+            // java.util.concurrent.BlockingQueue is used to implement the compilation worker
+            // queues. If a compiler thread triggers a compilation, then it may be blocked trying
+            // to add something to its own queue.
+            return false;
         }
+        CompilationTask.withinEnqueue.set(Boolean.TRUE);
 
-        final OptimisticOptimizations optimisticOpts = new OptimisticOptimizations(method);
-        int id = compileTaskIds.incrementAndGet();
-        CompilationTask task = CompilationTask.create(compiler, createHotSpotSpecificPhasePlan(optimisticOpts), optimisticOpts, method, id, priority);
-        if (blocking) {
-            task.run();
-        } else {
-            try {
-                method.setCurrentTask(task);
-                if (GraalOptions.SlowCompileThreads && priority > GraalOptions.SlowQueueCutoff) {
-                    slowCompileQueue.execute(task);
+        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();
                 } else {
-                    compileQueue.execute(task);
+                    // without a prioritizing compile queue it makes no sense to re-queue the compilation task
+                    return true;
                 }
-            } catch (RejectedExecutionException e) {
-                // The compile queue was already shut down.
-                return false;
             }
+
+            final OptimisticOptimizations optimisticOpts = new OptimisticOptimizations(method);
+            int id = compileTaskIds.incrementAndGet();
+            CompilationTask task = CompilationTask.create(compiler, createHotSpotSpecificPhasePlan(optimisticOpts), optimisticOpts, method, id, priority);
+            if (blocking) {
+                task.runCompilation();
+            } else {
+                try {
+                    method.setCurrentTask(task);
+                    if (GraalOptions.SlowCompileThreads && priority > GraalOptions.SlowQueueCutoff) {
+                        slowCompileQueue.execute(task);
+                    } else {
+                        compileQueue.execute(task);
+                    }
+                } catch (RejectedExecutionException e) {
+                    // The compile queue was already shut down.
+                    return false;
+                }
+            }
+            return true;
+        } finally {
+            CompilationTask.withinEnqueue.set(Boolean.FALSE);
         }
-        return true;
     }
 
     @Override
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/EscapeField.java	Mon Apr 02 12:19:18 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/EscapeField.java	Mon Apr 02 19:46:48 2012 +0200
@@ -26,9 +26,9 @@
 
 public class EscapeField {
 
-    private String name;
-    private Object representation;
-    private RiType type;
+    private final String name;
+    private final Object representation;
+    private final RiType type;
 
     public EscapeField(String name, Object representation, RiType type) {
         this.name = name;
--- a/src/share/vm/interpreter/invocationCounter.cpp	Mon Apr 02 12:19:18 2012 +0200
+++ b/src/share/vm/interpreter/invocationCounter.cpp	Mon Apr 02 19:46:48 2012 +0200
@@ -47,11 +47,12 @@
   // large value.  Now reduce the value, so that the method can be
   // executed many more times before re-entering the VM.
   int old_count = count();
-#ifdef GRAAL
-  int new_count = 1;
-#else
-  int new_count = MIN2(old_count, (int) (CompileThreshold / 2));
-#endif
+  int new_count;
+  if (CompilationPolicyChoice == 4) {
+    new_count = 1;
+  } else {
+    new_count = MIN2(old_count, (int) (CompileThreshold / 2));
+  }
   // prevent from going to zero, to distinguish from never-executed methods
   if (new_count == 0)  new_count = 1;
   if (old_count != new_count)  set(state(), new_count);
--- a/src/share/vm/runtime/globals.hpp	Mon Apr 02 12:19:18 2012 +0200
+++ b/src/share/vm/runtime/globals.hpp	Mon Apr 02 19:46:48 2012 +0200
@@ -2507,7 +2507,7 @@
   product(intx, CICompilerCount, CI_COMPILER_COUNT,                         \
           "Number of compiler threads to run")                              \
                                                                             \
-  product(intx, CompilationPolicyChoice, NOT_GRAAL(0) GRAAL_ONLY(0),        \
+  product(intx, CompilationPolicyChoice, NOT_GRAAL(0) GRAAL_ONLY(4),        \
           "which compilation policy (0/1)")                                 \
                                                                             \
   develop(bool, UseStackBanging, true,                                      \