changeset 15165:cf49b4e72de5

Reused installed code object for optimized call targets.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 16 Apr 2014 18:20:55 +0200
parents 62e218478931
children 7bc92bdfd322
files graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java
diffstat 4 files changed, 15 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java	Wed Apr 16 18:20:00 2014 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java	Wed Apr 16 18:20:55 2014 +0200
@@ -53,7 +53,7 @@
     }
 
     public boolean isOptimized() {
-        return installedCode != null || installedCodeTask != null;
+        return installedCode.isValid() || installedCodeTask != null;
     }
 
     @Override
@@ -75,8 +75,6 @@
         InstalledCode currentInstalledCode = installedCode;
         if (currentInstalledCode.isValid()) {
             reinstallCallMethodShortcut();
-        } else {
-            return compiledCodeInvalidated(args);
         }
         return interpreterCall(args);
     }
@@ -88,17 +86,12 @@
         HotSpotTruffleRuntime.installOptimizedCallTargetCallMethod();
     }
 
-    private Object compiledCodeInvalidated(Object[] args) {
-        invalidate(null, null, "Compiled code invalidated");
-        return call(args);
-    }
-
     @Override
     protected void invalidate(Node oldNode, Node newNode, CharSequence reason) {
         InstalledCode m = this.installedCode;
-        if (m != null) {
+        if (m.isValid()) {
             CompilerAsserts.neverPartOfCompilation();
-            installedCode = null;
+            m.invalidate();
             compilationProfile.reportInvalidated();
             logOptimizedInvalidated(this, oldNode, newNode, reason);
         }
@@ -128,7 +121,6 @@
                 try {
                     return installedCode.executeVarargs(new Object[]{this, args});
                 } catch (InvalidInstalledCodeException ex) {
-                    return compiledCodeInvalidated(args);
                 }
             }
         }
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Wed Apr 16 18:20:00 2014 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Wed Apr 16 18:20:55 2014 +0200
@@ -26,7 +26,6 @@
 import static com.oracle.graal.compiler.GraalCompiler.*;
 import static com.oracle.graal.truffle.TruffleCompilerOptions.*;
 
-import java.lang.reflect.*;
 import java.util.*;
 
 import com.oracle.graal.api.code.*;
@@ -37,7 +36,6 @@
 import com.oracle.graal.compiler.target.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.debug.Debug.Scope;
-import com.oracle.graal.graph.*;
 import com.oracle.graal.java.*;
 import com.oracle.graal.lir.asm.*;
 import com.oracle.graal.nodes.*;
@@ -175,41 +173,17 @@
         }
     }
 
-    private static Method[] callBoundaryMethods;
-
-    public static boolean isCallBoundaryMethod(ResolvedJavaMethod method) {
-        for (Method m : getCallBoundaryMethods()) {
-            Providers providers = getGraalProviders();
-            ResolvedJavaMethod current = providers.getMetaAccess().lookupJavaMethod(m);
-            if (current.equals(method)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public static Method[] getCallBoundaryMethods() {
-        if (callBoundaryMethods == null) {
-            try {
-                callBoundaryMethods = new Method[]{HotSpotOptimizedCallTarget.class.getDeclaredMethod("callBoundary", new Class[]{Object[].class})};
-            } catch (NoSuchMethodException | SecurityException e) {
-                throw GraalInternalError.shouldNotReachHere();
-            }
-        }
-
-        return callBoundaryMethods;
-    }
-
     public static void installOptimizedCallTargetCallMethod() {
-        Method[] methods = getCallBoundaryMethods();
-        for (Method method : methods) {
-            Providers providers = getGraalProviders();
-            MetaAccessProvider metaAccess = providers.getMetaAccess();
-            CodeCacheProvider codeCache = providers.getCodeCache();
-            ResolvedJavaMethod resolvedCallMethod = metaAccess.lookupJavaMethod(method);
-            CompilationResult compResult = compileMethod(resolvedCallMethod);
-            try (Scope s = Debug.scope("CodeInstall", codeCache, resolvedCallMethod)) {
-                codeCache.setDefaultMethod(resolvedCallMethod, compResult);
+        Providers providers = getGraalProviders();
+        MetaAccessProvider metaAccess = providers.getMetaAccess();
+        ResolvedJavaType type = metaAccess.lookupJavaType(HotSpotOptimizedCallTarget.class);
+        for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
+            if (method.getAnnotation(TruffleCallBoundary.class) != null) {
+                CompilationResult compResult = compileMethod(method);
+                CodeCacheProvider codeCache = providers.getCodeCache();
+                try (Scope s = Debug.scope("CodeInstall", codeCache, method)) {
+                    codeCache.setDefaultMethod(method, compResult);
+                }
             }
         }
     }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java	Wed Apr 16 18:20:00 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java	Wed Apr 16 18:20:55 2014 +0200
@@ -266,7 +266,7 @@
             }
 
             int nodeCount = OptimizedCallUtils.countNonTrivialNodes(callTarget, true);
-            String comment = callTarget.installedCode == null ? " int" : "";
+            String comment = callTarget.installedCode.isValid() ? "" : " int";
             comment += callTarget.compilationEnabled ? "" : " fail";
             OUT.printf("%-50s | %10d | %15d | %10d | %3d%s\n", callTarget.getRootNode(), callTarget.callCount, nodeCount, nodeCount, callTarget.getCompilationProfile().getInvalidationCount(), comment);
 
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java	Wed Apr 16 18:20:00 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java	Wed Apr 16 18:20:55 2014 +0200
@@ -151,7 +151,7 @@
 
         long timePartialEvaluationFinished = System.nanoTime();
         int nodeCountPartialEval = graph.getNodeCount();
-        InstalledCode compiledMethod = compileMethodHelper(graph, assumptions, compilable.toString(), compilable.getSpeculationLog(), null);
+        InstalledCode compiledMethod = compileMethodHelper(graph, assumptions, compilable.toString(), compilable.getSpeculationLog(), compilable.installedCode);
         long timeCompilationFinished = System.nanoTime();
         int nodeCountLowered = graph.getNodeCount();