changeset 15695:128359d7cddc

once the Graal compilation queue has been shutdown, don't process any pending compilations and be more defensive about preventing future compilations to be queued
author Doug Simon <doug.simon@oracle.com>
date Thu, 15 May 2014 22:46:45 +0200
parents 7b999df1dabc
children 5f1373b3527d
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java
diffstat 3 files changed, 43 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Thu May 15 22:43:44 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Thu May 15 22:46:45 2014 +0200
@@ -107,6 +107,13 @@
     private final int id;
     private final AtomicReference<CompilationStatus> status;
 
+    /**
+     * The executor processing the Graal compilation queue this task was placed on. This will be
+     * null for blocking compilations or if compilations are scheduled as native HotSpot
+     * {@linkplain #ctask CompileTask}s.
+     */
+    private final ExecutorService executor;
+
     private StructuredGraph graph;
 
     /**
@@ -129,7 +136,8 @@
      */
     private final long ctask;
 
-    public CompilationTask(HotSpotBackend backend, HotSpotResolvedJavaMethod method, int entryBCI, long ctask, boolean blocking) {
+    public CompilationTask(ExecutorService executor, HotSpotBackend backend, HotSpotResolvedJavaMethod method, int entryBCI, long ctask, boolean blocking) {
+        this.executor = executor;
         this.backend = backend;
         this.method = method;
         this.entryBCI = entryBCI;
@@ -165,7 +173,7 @@
     public void run() {
         withinEnqueue.set(Boolean.FALSE);
         try {
-            runCompilation(true);
+            runCompilation();
         } finally {
             withinEnqueue.set(Boolean.TRUE);
             status.set(CompilationStatus.Finished);
@@ -235,7 +243,14 @@
         return method.getCompilationProfilingInfo(osrCompilation);
     }
 
-    public void runCompilation(boolean clearFromCompilationQueue) {
+    public void runCompilation() {
+        if (executor != null && executor.isShutdown()) {
+            // We don't want to do any unnecessary compilation is the Graal compilation
+            // queue has been shutdown. Note that we leave the JVM_ACC_QUEUED bit set
+            // for the method so that it won't be re-scheduled for compilation.
+            return;
+        }
+
         /*
          * no code must be outside this try/finally because it could happen otherwise that
          * clearQueuedForCompilation() is not executed
@@ -402,7 +417,7 @@
                 c2vm.notifyCompilationStatistics(id, method, entryBCI != INVOCATION_ENTRY_BCI, processedBytes, time, timeUnitsPerSecond, installedCode);
             }
 
-            if (clearFromCompilationQueue) {
+            if (executor != null) {
                 assert method.isQueuedForCompilation();
                 method.clearQueuedForCompilation();
             }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java	Thu May 15 22:43:44 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java	Thu May 15 22:46:45 2014 +0200
@@ -317,7 +317,7 @@
     class CTWCompilationTask extends CompilationTask {
 
         CTWCompilationTask(HotSpotBackend backend, HotSpotResolvedJavaMethod method) {
-            super(backend, method, INVOCATION_ENTRY_BCI, 0L, false);
+            super(null, backend, method, INVOCATION_ENTRY_BCI, 0L, false);
         }
 
         /**
@@ -349,7 +349,7 @@
 
             HotSpotBackend backend = runtime.getHostBackend();
             CompilationTask task = new CTWCompilationTask(backend, method);
-            task.runCompilation(false);
+            task.runCompilation();
 
             compileTime += (System.currentTimeMillis() - start);
             compiledMethodsCounter++;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Thu May 15 22:43:44 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Thu May 15 22:46:45 2014 +0200
@@ -91,7 +91,7 @@
      * is in the proper state.
      */
     static class Queue {
-        private ThreadPoolExecutor executor;
+        private final ThreadPoolExecutor executor;
 
         Queue(CompilerThreadFactory factory) {
             executor = new ThreadPoolExecutor(Threads.getValue(), Threads.getValue(), 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue<Runnable>(), factory);
@@ -117,11 +117,19 @@
             executor.execute(task);
         }
 
+        /**
+         * @see ExecutorService#isShutdown()
+         */
+        public boolean isShutdown() {
+            return executor.isShutdown();
+        }
+
         public void shutdown() throws InterruptedException {
             assert CompilationTask.isWithinEnqueue();
-            executor.shutdown();
-            if (Debug.isEnabled() && Dump.getValue() != null) {
-                // Wait 2 seconds to flush out all graph dumps that may be of interest
+            executor.shutdownNow();
+            if (Debug.isEnabled() && (Dump.getValue() != null || areMetricsOrTimersEnabled())) {
+                // Wait up to 2 seconds to flush out all graph dumps and stop metrics/timers
+                // being updated.
                 executor.awaitTermination(2, TimeUnit.SECONDS);
             }
         }
@@ -472,19 +480,7 @@
         printMap(new DebugValueScope(null, result), debugValues);
     }
 
-    static long collectTotal(DebugValue value) {
-        List<DebugValueMap> maps = DebugValueMap.getTopLevelMaps();
-        long total = 0;
-        for (int i = 0; i < maps.size(); i++) {
-            DebugValueMap map = maps.get(i);
-            int index = value.getIndex();
-            total += map.getCurrentValue(index);
-            total += collectTotal(map.getChildren(), index);
-        }
-        return total;
-    }
-
-    private static long collectTotal(List<DebugValueMap> maps, int index) {
+    public static long collectTotal(List<DebugValueMap> maps, int index) {
         long total = 0;
         for (int i = 0; i < maps.size(); i++) {
             DebugValueMap map = maps.get(i);
@@ -570,8 +566,8 @@
     void compileMethod(final HotSpotResolvedJavaMethod method, final int entryBCI, long ctask, final boolean blocking) {
         if (ctask != 0L) {
             HotSpotBackend backend = runtime.getHostBackend();
-            CompilationTask task = new CompilationTask(backend, method, entryBCI, ctask, false);
-            task.runCompilation(false);
+            CompilationTask task = new CompilationTask(null, backend, method, entryBCI, ctask, false);
+            task.runCompilation();
             return;
         }
 
@@ -596,13 +592,14 @@
             if (method.tryToQueueForCompilation()) {
                 assert method.isQueuedForCompilation();
 
-                HotSpotBackend backend = runtime.getHostBackend();
-                CompilationTask task = new CompilationTask(backend, method, entryBCI, ctask, block);
-
                 try {
-                    compileQueue.execute(task);
-                    if (block) {
-                        task.block();
+                    if (!compileQueue.executor.isShutdown()) {
+                        HotSpotBackend backend = runtime.getHostBackend();
+                        CompilationTask task = new CompilationTask(compileQueue.executor, backend, method, entryBCI, ctask, block);
+                        compileQueue.execute(task);
+                        if (block) {
+                            task.block();
+                        }
                     }
                 } catch (RejectedExecutionException e) {
                     // The compile queue was already shut down.