changeset 18146:9db0af368bb4

truffleCache: refactor in order to fix recursive inlining warning
author Bernhard Urban <bernhard.urban@jku.at>
date Wed, 22 Oct 2014 14:50:09 +0200
parents 0e7455cb3004
children 67a5f283487a 31ad929e1afd
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java
diffstat 1 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java	Tue Oct 21 20:33:04 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java	Wed Oct 22 14:50:09 2014 +0200
@@ -104,11 +104,7 @@
         return graph;
     }
 
-    public StructuredGraph lookup(ResolvedJavaMethod method, NodeInputList<ValueNode> arguments, CanonicalizerPhase canonicalizer) {
-        if (method.getAnnotation(CompilerDirectives.TruffleBoundary.class) != null) {
-            return null;
-        }
-
+    private static List<Object> computeCacheKey(ResolvedJavaMethod method, NodeInputList<ValueNode> arguments) {
         List<Object> key = new ArrayList<>(arguments.size() + 1);
         key.add(method);
         for (ValueNode v : arguments) {
@@ -116,12 +112,28 @@
                 key.add(v.stamp());
             }
         }
+        return key;
+    }
+
+    public StructuredGraph lookup(ResolvedJavaMethod method, NodeInputList<ValueNode> arguments, CanonicalizerPhase canonicalizer) {
+        List<Object> key = computeCacheKey(method, arguments);
         StructuredGraph resultGraph = cache.get(key);
         if (resultGraph == markerGraph) {
-            // Avoid recursive inlining or a previous attempt bailed out (and we won't try again).
+            // compilation failed previously, don't try again
+            return null;
+        }
+        StructuredGraph graph = cacheLookup(method, arguments, canonicalizer);
+        assert graph != markerGraph : "markerGraph should not leak out";
+        return graph;
+    }
+
+    private StructuredGraph cacheLookup(ResolvedJavaMethod method, NodeInputList<ValueNode> arguments, CanonicalizerPhase canonicalizer) {
+        if (method.getAnnotation(CompilerDirectives.TruffleBoundary.class) != null) {
             return null;
         }
 
+        List<Object> key = computeCacheKey(method, arguments);
+        StructuredGraph resultGraph = cache.get(key);
         if (resultGraph != null) {
             lastUsed.put(key, counter++);
             return resultGraph;
@@ -280,7 +292,7 @@
     private void expandInvoke(MethodCallTargetNode methodCallTargetNode, CanonicalizerPhase canonicalizer) {
         StructuredGraph inlineGraph = providers.getReplacements().getMethodSubstitution(methodCallTargetNode.targetMethod());
         if (inlineGraph == null) {
-            inlineGraph = TruffleCacheImpl.this.lookup(methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), canonicalizer);
+            inlineGraph = cacheLookup(methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), canonicalizer);
         }
         if (inlineGraph == null) {
             return;