changeset 19304:6135f3a3fa45

Truffle-DSL: fix function call example can throw a guard assertion.
author Christian Humer <christian.humer@gmail.com>
date Wed, 11 Feb 2015 19:29:35 +0100
parents 37bbcabf7744
children 48bdad77afcd
files graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/examples/FunctionCall.java
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/examples/FunctionCall.java	Wed Feb 11 19:28:59 2015 +0100
+++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/examples/FunctionCall.java	Wed Feb 11 19:29:35 2015 +0100
@@ -86,13 +86,13 @@
 
         public static final int CACHE_SIZE = 2;
 
-        private CallTarget[] cachedTargets = new CallTarget[CACHE_SIZE];
+        private Function[] cachedFunctions = new Function[CACHE_SIZE];
 
         private int directCallFunctionGuard;
         private int directCall;
         private int indirectCall;
 
-        @Specialization(limit = "CACHE_SIZE", guards = {"function == cachedFunction", "!cacheFunctionTarget(cachedFunction)"})
+        @Specialization(limit = "CACHE_SIZE", guards = {"function == cachedFunction", "cacheFunctionTarget(cachedFunction)"})
         public Object directCallFunctionGuard(VirtualFrame frame, Function function, Object argument,  //
                         @Cached("function") Function cachedFunction, //
                         @Cached("create(cachedFunction.getTarget())") DirectCallNode callNode) {
@@ -102,15 +102,16 @@
 
         protected final boolean cacheFunctionTarget(Function function) {
             CompilerAsserts.neverPartOfCompilation();
-            if (cachedTargets != null) {
-                CallTarget target = function.getTarget();
-                for (int i = 0; i < cachedTargets.length; i++) {
-                    CallTarget cachedTarget = cachedTargets[i];
-                    if (cachedTarget == target) {
-                        cachedTargets = null;
+            if (cachedFunctions != null) {
+                for (int i = 0; i < cachedFunctions.length; i++) {
+                    Function cachedFunction = cachedFunctions[i];
+                    if (cachedFunction == null) {
+                        cachedFunctions[i] = function;
                         return true;
-                    } else if (cachedTarget == null) {
-                        cachedTargets[i] = target;
+                    } else if (cachedFunction == function) {
+                        return true;
+                    } else if (cachedFunction.getTarget() == function.getTarget()) {
+                        cachedFunctions = null;
                         return false;
                     }
                 }