# HG changeset patch # User Christian Humer # Date 1423679375 -3600 # Node ID 6135f3a3fa45e106aa2b10f6ad3b3d464af901ae # Parent 37bbcabf77443c3dfeebadeae0c34123eddfeed7 Truffle-DSL: fix function call example can throw a guard assertion. diff -r 37bbcabf7744 -r 6135f3a3fa45 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/examples/FunctionCall.java --- 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; } }