Skip to content

Commit 0d3e65d

Browse files
committed
Fix: deopt loop in ResolveHandleCache.
1 parent 797068c commit 0d3e65d

File tree

1 file changed

+15
-8
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext

1 file changed

+15
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CExtNodes.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
import com.oracle.truffle.api.interop.UnsupportedTypeException;
163163
import com.oracle.truffle.api.library.CachedLibrary;
164164
import com.oracle.truffle.api.nodes.ExplodeLoop;
165+
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
165166
import com.oracle.truffle.api.nodes.Node;
166167
import com.oracle.truffle.api.nodes.NodeUtil;
167168
import com.oracle.truffle.api.profiles.BranchProfile;
@@ -3114,25 +3115,31 @@ public abstract static class ResolveHandleNode extends Node {
31143115

31153116
@Specialization(limit = "3", //
31163117
guards = {"cachedPointer == pointer", "cachedValue != null"}, //
3117-
assumptions = {"singleContextAssumption()", "getHandleValidAssumption(cachedValue)"})
3118-
static PythonNativeWrapper doLongCachedSingleContext(@SuppressWarnings("unused") long pointer,
3118+
assumptions = "singleContextAssumption()", //
3119+
rewriteOn = InvalidAssumptionException.class)
3120+
static PythonNativeWrapper resolveLongCached(@SuppressWarnings("unused") long pointer,
31193121
@Cached("pointer") @SuppressWarnings("unused") long cachedPointer,
3120-
@Cached("resolveHandleUncached(pointer)") PythonNativeWrapper cachedValue) {
3122+
@Cached("resolveHandleUncached(pointer)") PythonNativeWrapper cachedValue,
3123+
@Cached("getHandleValidAssumption(cachedValue)") Assumption associationValidAssumption) throws InvalidAssumptionException {
3124+
associationValidAssumption.check();
31213125
return cachedValue;
31223126
}
31233127

31243128
@Specialization(limit = "3", //
31253129
guards = {"isSame(referenceLibrary, cachedPointerObject, pointerObject)", "cachedValue != null"}, //
3126-
assumptions = {"singleContextAssumption()", "getHandleValidAssumption(cachedValue)"})
3127-
static PythonNativeWrapper doObjectCachedSingleContext(@SuppressWarnings("unused") Object pointerObject,
3130+
assumptions = "singleContextAssumption()", //
3131+
rewriteOn = InvalidAssumptionException.class)
3132+
static PythonNativeWrapper resolveObjectCached(@SuppressWarnings("unused") Object pointerObject,
31283133
@Cached("pointerObject") @SuppressWarnings("unused") Object cachedPointerObject,
31293134
@CachedLibrary("cachedPointerObject") @SuppressWarnings("unused") ReferenceLibrary referenceLibrary,
3130-
@Cached("resolveHandleUncached(pointerObject)") PythonNativeWrapper cachedValue) {
3135+
@Cached("resolveHandleUncached(pointerObject)") PythonNativeWrapper cachedValue,
3136+
@Cached("getHandleValidAssumption(cachedValue)") Assumption associationValidAssumption) throws InvalidAssumptionException {
3137+
associationValidAssumption.check();
31313138
return cachedValue;
31323139
}
31333140

3134-
@Specialization(replaces = {"doObjectCachedSingleContext", "doLongCachedSingleContext"})
3135-
static Object doGeneric(Object pointerObject,
3141+
@Specialization(replaces = {"resolveLongCached", "resolveObjectCached"})
3142+
static Object resolveGeneric(Object pointerObject,
31363143
@Cached PCallCapiFunction callTruffleCannotBeHandleNode,
31373144
@Cached PCallCapiFunction callTruffleManagedFromHandleNode) {
31383145
if (!((boolean) callTruffleCannotBeHandleNode.call(NativeCAPISymbols.FUN_TRUFFLE_CANNOT_BE_HANDLE, pointerObject))) {

0 commit comments

Comments
 (0)