changeset 20095:c7c799f40c1e

Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
author Christian Humer <christian.humer@gmail.com>
date Mon, 30 Mar 2015 22:52:03 +0200
parents 47ae36e2af46
children 3844fb65016c
files graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java
diffstat 2 files changed, 28 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Mon Mar 30 20:45:04 2015 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Mon Mar 30 22:52:03 2015 +0200
@@ -215,11 +215,15 @@
         Runnable r = new Runnable() {
             @Override
             public void run() {
+                boolean success = true;
                 try (Scope s = Debug.scope("Truffle", new TruffleDebugJavaMethod(optimizedCallTarget))) {
                     truffleCompiler.compileMethod(optimizedCallTarget);
-                    optimizedCallTarget.notifyCompilationFinished();
                 } catch (Throwable e) {
                     optimizedCallTarget.notifyCompilationFailed(e);
+                    success = false;
+                } finally {
+                    optimizedCallTarget.notifyCompilationFinished(success);
+
                 }
             }
         };
@@ -248,7 +252,10 @@
         if (codeTask != null && isCompiling(optimizedCallTarget)) {
             this.compilations.remove(optimizedCallTarget);
             boolean result = codeTask.cancel(true);
-            getCompilationNotify().notifyCompilationDequeued(optimizedCallTarget, source, reason);
+            if (result) {
+                optimizedCallTarget.notifyCompilationFinished(false);
+                getCompilationNotify().notifyCompilationDequeued(optimizedCallTarget, source, reason);
+            }
             return result;
         }
         return false;
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java	Mon Mar 30 20:45:04 2015 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java	Mon Mar 30 22:52:03 2015 +0200
@@ -27,7 +27,6 @@
 import java.io.*;
 import java.lang.reflect.*;
 import java.util.*;
-import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
 import java.util.stream.*;
 
@@ -72,6 +71,7 @@
 
     private TruffleInlining inlining;
     private int cachedNonTrivialNodeCount = -1;
+    private boolean compiling;
 
     /**
      * When this call target is inlined, the inlining {@link InstalledCode} registers this
@@ -102,6 +102,10 @@
         this.nodeRewritingAssumption = new CyclicAssumption("nodeRewritingAssumption of " + rootNode.toString());
     }
 
+    public final boolean isCompiling() {
+        return compiling;
+    }
+
     private static RootNode cloneRootNode(RootNode root) {
         if (root == null || !root.isCloningAllowed()) {
             return null;
@@ -174,7 +178,7 @@
     }
 
     @ExplodeLoop
-    private void profileArguments(Object[] args) {
+    void profileArguments(Object[] args) {
         if (profiledArgumentTypesAssumption == null) {
             CompilerDirectives.transferToInterpreterAndInvalidate();
             initializeProfiledArgumentTypes(args);
@@ -272,7 +276,12 @@
         VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), args);
         Object result = callProxy(frame);
 
-        // Profile call return type
+        profileReturnType(result);
+
+        return result;
+    }
+
+    void profileReturnType(Object result) {
         if (profiledReturnTypeAssumption == null) {
             if (TruffleReturnTypeSpeculation.getValue()) {
                 CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -286,8 +295,6 @@
                 profiledReturnTypeAssumption.invalidate();
             }
         }
-
-        return result;
     }
 
     @Override
@@ -321,25 +328,16 @@
             this.runtime.reinstallStubs();
         } else {
             compilationProfile.reportInterpreterCall();
-            if (compilationPolicy.shouldCompile(compilationProfile, getCompilerOptions())) {
+            if (!isCompiling() && compilationPolicy.shouldCompile(compilationProfile, getCompilerOptions())) {
                 compile();
             }
         }
     }
 
     public void compile() {
-        compile(TruffleBackgroundCompilation.getValue() && !TruffleCompilationExceptionsAreThrown.getValue());
-    }
-
-    public void compile(boolean mayBeAsynchronous) {
-        if (!runtime.isCompiling(this)) {
-            runtime.compile(this, mayBeAsynchronous);
-        } else if (!mayBeAsynchronous && runtime.isCompiling(this)) {
-            try {
-                runtime.waitForCompilation(this, 20000);
-            } catch (ExecutionException | TimeoutException e) {
-                Debug.log(3, e.getMessage());
-            }
+        if (!isCompiling()) {
+            compiling = true;
+            runtime.compile(this, TruffleBackgroundCompilation.getValue() && !TruffleCompilationExceptionsAreThrown.getValue());
         }
     }
 
@@ -363,11 +361,11 @@
         }
     }
 
-    public void notifyCompilationFinished() {
-        // Compilation was successful.
-        if (inlining != null) {
+    public void notifyCompilationFinished(boolean successful) {
+        if (successful && inlining != null) {
             dequeueInlinedCallSites(inlining);
         }
+        compiling = false;
     }
 
     private void dequeueInlinedCallSites(TruffleInlining parentDecision) {