Skip to content

Commit 2a56795

Browse files
committed
HandleCache, NativeReferenceCache, ObjectBuiltins, PClosureRootNode use PythonLanguage#isSingleContext
1 parent b9f8634 commit 2a56795

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.cext.capi;
4242

43-
import com.oracle.graal.python.PythonLanguage;
43+
import com.oracle.graal.python.nodes.PNodeWithContext;
4444
import com.oracle.graal.python.runtime.GilNode;
4545
import com.oracle.truffle.api.Assumption;
4646
import com.oracle.truffle.api.CompilerAsserts;
@@ -59,7 +59,6 @@
5959
import com.oracle.truffle.api.library.ExportLibrary;
6060
import com.oracle.truffle.api.library.ExportMessage;
6161
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
62-
import com.oracle.truffle.api.nodes.Node;
6362

6463
@ExportLibrary(InteropLibrary.class)
6564
public final class HandleCache implements TruffleObject {
@@ -107,12 +106,11 @@ public Object execute(Object[] arguments,
107106

108107
@GenerateUncached
109108
@ImportStatic(HandleCache.class)
110-
abstract static class GetOrInsertNode extends Node {
109+
abstract static class GetOrInsertNode extends PNodeWithContext {
111110
public abstract Object execute(HandleCache cache, long handle) throws UnsupportedTypeException, ArityException, UnsupportedMessageException;
112111

113112
@Specialization(limit = "CACHE_SIZE", //
114-
guards = {"handle == cachedHandle", "cachedValue != null"}, //
115-
assumptions = "singleContextAssumption()", //
113+
guards = {"isSingleContext()", "handle == cachedHandle", "cachedValue != null"}, //
116114
rewriteOn = InvalidAssumptionException.class)
117115
static PythonNativeWrapper doCachedSingleContext(@SuppressWarnings("unused") HandleCache cache, @SuppressWarnings("unused") long handle,
118116
@Cached("handle") @SuppressWarnings("unused") long cachedHandle,
@@ -122,7 +120,7 @@ static PythonNativeWrapper doCachedSingleContext(@SuppressWarnings("unused") Han
122120
return cachedValue;
123121
}
124122

125-
@Specialization(replaces = "doCachedSingleContext", assumptions = "singleContextAssumption()")
123+
@Specialization(replaces = "doCachedSingleContext", guards = "isSingleContext()")
126124
static Object doGenericSingleContext(@SuppressWarnings("unused") HandleCache cache, long handle,
127125
@Cached(value = "cache.getPtrToResolveHandle()", allowUncached = true) Object resolveHandleFunction,
128126
@CachedLibrary("resolveHandleFunction") InteropLibrary interopLibrary) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
@@ -151,10 +149,6 @@ static Object resolveHandle(long handle, Object ptrToResolveHandle, InteropLibra
151149
return interopLibrary.execute(ptrToResolveHandle, handle);
152150
}
153151

154-
Assumption singleContextAssumption() {
155-
return PythonLanguage.get(this).singleContextAssumption;
156-
}
157-
158152
static Assumption getHandleValidAssumption(PythonNativeWrapper nativeWrapper) {
159153
return nativeWrapper.ensureHandleValidAssumption();
160154
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext.NativeObjectReference;
4747
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetRefCntNode;
4848
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.GetRefCntNodeGen;
49+
import com.oracle.graal.python.nodes.PNodeWithContext;
4950
import com.oracle.graal.python.nodes.util.CannotCastException;
5051
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
5152
import com.oracle.graal.python.runtime.GilNode;
5253
import com.oracle.graal.python.runtime.PythonContext;
53-
import com.oracle.truffle.api.Assumption;
5454
import com.oracle.truffle.api.CompilerDirectives;
5555
import com.oracle.truffle.api.TruffleLogger;
5656
import com.oracle.truffle.api.dsl.Cached;
@@ -107,7 +107,7 @@ Object execute(Object[] arguments,
107107

108108
@GenerateUncached
109109
@ImportStatic(CApiGuards.class)
110-
public abstract static class ResolveNativeReferenceNode extends Node {
110+
public abstract static class ResolveNativeReferenceNode extends PNodeWithContext {
111111
private static final TruffleLogger LOGGER = PythonLanguage.getLogger(ResolveNativeReferenceNode.class);
112112

113113
private static final Object NO_REF_CNT = new Object();
@@ -127,9 +127,8 @@ protected static PythonContext getContext(Node node) {
127127
return PythonContext.get(node);
128128
}
129129

130-
@Specialization(guards = {"!isResolved(pointerObject)", "ref != null", "isSame(interoplibrary, pointerObject, ref)"}, //
130+
@Specialization(guards = {"isSingleContext()", "!isResolved(pointerObject)", "ref != null", "isSame(interoplibrary, pointerObject, ref)"}, //
131131
rewriteOn = {CannotCastException.class, InvalidCacheEntry.class}, //
132-
assumptions = "singleContextAssumption(interoplibrary)", //
133132
limit = "1")
134133
static PythonAbstractNativeObject doCachedPointer(@SuppressWarnings("unused") Object pointerObject, @SuppressWarnings("unused") Object refCnt, boolean steal,
135134
@Shared("stealProfile") @Cached ConditionProfile stealProfile,
@@ -235,10 +234,6 @@ static boolean isResolved(Object object) {
235234
return CApiGuards.isNativeWrapper(object) || object instanceof String;
236235
}
237236

238-
static Assumption singleContextAssumption(Node node) {
239-
return PythonLanguage.get(node).singleContextAssumption;
240-
}
241-
242237
static boolean isNoRefCnt(Object refCnt) {
243238
return refCnt == NO_REF_CNT;
244239
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ PNone init(Object self, Object[] arguments, PKeyword[] keywords,
242242
}
243243

244244
protected static ValueProfile createLookupProfile(Node node) {
245-
if (PythonLanguage.get(node).singleContextAssumption.isValid()) {
245+
if (PythonLanguage.get(node).isSingleContext()) {
246246
return ValueProfile.createIdentityProfile();
247247
} else {
248248
return ValueProfile.createClassProfile();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PClosureRootNode.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.oracle.graal.python.builtins.objects.cell.PCell;
4545
import com.oracle.graal.python.builtins.objects.function.PArguments;
4646
import com.oracle.graal.python.util.PythonUtils;
47-
import com.oracle.truffle.api.Assumption;
4847
import com.oracle.truffle.api.CompilerDirectives;
4948
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
5049
import com.oracle.truffle.api.frame.Frame;
@@ -54,15 +53,15 @@
5453

5554
@SuppressWarnings("deprecation") // new Frame API
5655
public abstract class PClosureRootNode extends PRootNode {
57-
private final Assumption singleContextAssumption;
56+
private final boolean isSingleContext;
5857
private final boolean annotationsAvailable;
5958
@CompilationFinal(dimensions = 1) protected final com.oracle.truffle.api.frame.FrameSlot[] freeVarSlots;
6059
@CompilationFinal(dimensions = 1) protected PCell[] closure;
6160
private final int length;
6261

6362
protected PClosureRootNode(PythonLanguage language, FrameDescriptor frameDescriptor, com.oracle.truffle.api.frame.FrameSlot[] freeVarSlots, boolean hasAnnotations) {
6463
super(language, frameDescriptor);
65-
this.singleContextAssumption = language.singleContextAssumption;
64+
this.isSingleContext = language.isSingleContext();
6665
this.freeVarSlots = freeVarSlots;
6766
this.length = freeVarSlots != null ? freeVarSlots.length : 0;
6867
this.annotationsAvailable = hasAnnotations;
@@ -71,10 +70,10 @@ protected PClosureRootNode(PythonLanguage language, FrameDescriptor frameDescrip
7170
protected final void addClosureCellsToLocals(Frame frame) {
7271
PCell[] frameClosure = PArguments.getClosure(frame);
7372
if (frameClosure != null) {
74-
if (singleContextAssumption.isValid() && closure == null) {
73+
if (isSingleContext && closure == null) {
7574
CompilerDirectives.transferToInterpreterAndInvalidate();
7675
closure = frameClosure;
77-
} else if (closure != PythonUtils.NO_CLOSURE && ((!singleContextAssumption.isValid() && closure != null) || closure != frameClosure)) {
76+
} else if (closure != PythonUtils.NO_CLOSURE && ((!isSingleContext && closure != null) || closure != frameClosure)) {
7877
CompilerDirectives.transferToInterpreterAndInvalidate();
7978
closure = PythonUtils.NO_CLOSURE;
8079
}

0 commit comments

Comments
 (0)