Skip to content

Commit 4a7b60c

Browse files
committed
Remove LookupInMROBaseNode.contextRef
1 parent e569ce1 commit 4a7b60c

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/LookupAttributeInMRONode.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@
6161
import com.oracle.truffle.api.Assumption;
6262
import com.oracle.truffle.api.CompilerAsserts;
6363
import com.oracle.truffle.api.CompilerDirectives;
64-
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
6564
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
66-
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
6765
import com.oracle.truffle.api.dsl.Bind;
6866
import com.oracle.truffle.api.dsl.Cached;
6967
import com.oracle.truffle.api.dsl.CachedContext;
@@ -115,12 +113,9 @@ public static LookupAttributeInMRONode.Dynamic getUncached() {
115113

116114
private final boolean skipPythonClasses;
117115
protected final String key;
118-
@CompilationFinal private ContextReference<PythonContext> contextRef;
119116
@Child private TypeNodes.IsSameTypeNode isSameTypeNode = IsSameTypeNodeGen.create();
120117
@Child private GetMroStorageNode getMroNode;
121118

122-
protected static final int MAX_DICT_TYPES = ReadAttributeFromObjectNode.MAX_DICT_TYPES;
123-
124119
public LookupAttributeInMRONode(String key, boolean skipPythonClasses) {
125120
this.key = key;
126121
this.skipPythonClasses = skipPythonClasses;
@@ -158,7 +153,8 @@ public static Object findAttr(PythonCore core, PythonBuiltinClassType klass, Obj
158153
@Specialization(guards = {"klass == cachedKlass"}, limit = "getAttributeAccessInlineCacheMaxDepth()", assumptions = "singleContextAssumption()")
159154
protected static Object lookupPBCTCached(@SuppressWarnings("unused") PythonBuiltinClassType klass,
160155
@Cached("klass") @SuppressWarnings("unused") PythonBuiltinClassType cachedKlass,
161-
@Cached("findAttr(getCore(), cachedKlass, key)") Object cachedValue) {
156+
@SuppressWarnings("unused") @CachedContext(PythonLanguage.class) PythonContext ctx,
157+
@Cached("findAttr(ctx.getCore(), cachedKlass, key)") Object cachedValue) {
162158
return cachedValue;
163159
}
164160

@@ -173,7 +169,8 @@ protected static boolean canCache(Object value) {
173169
@Specialization(guards = {"klass == cachedKlass", "canCache(cachedValue)"}, limit = "getAttributeAccessInlineCacheMaxDepth()")
174170
protected static Object lookupPBCTCachedMulti(@SuppressWarnings("unused") PythonBuiltinClassType klass,
175171
@Cached("klass") @SuppressWarnings("unused") PythonBuiltinClassType cachedKlass,
176-
@Cached("findAttr(getCore(), cachedKlass, key)") Object cachedValue) {
172+
@SuppressWarnings("unused") @CachedContext(PythonLanguage.class) PythonContext ctx,
173+
@Cached("findAttr(ctx.getCore(), cachedKlass, key)") Object cachedValue) {
177174
return cachedValue;
178175
}
179176

@@ -192,19 +189,21 @@ public static PythonBuiltinClassType findOwnerInMro(PythonCore core, PythonBuilt
192189
@Specialization(replaces = "lookupPBCTCached", guards = "klass == cachedKlass", limit = "getAttributeAccessInlineCacheMaxDepth()")
193190
protected Object lookupPBCTCachedOwner(@SuppressWarnings("unused") PythonBuiltinClassType klass,
194191
@Cached("klass") @SuppressWarnings("unused") PythonBuiltinClassType cachedKlass,
195-
@Cached("findOwnerInMro(getCore(), cachedKlass, key)") PythonBuiltinClassType ownerKlass,
192+
@CachedContext(PythonLanguage.class) PythonContext ctx,
193+
@Cached("findOwnerInMro(ctx.getCore(), cachedKlass, key)") PythonBuiltinClassType ownerKlass,
196194
@Cached ReadAttributeFromDynamicObjectNode readAttrNode) {
197195
if (ownerKlass == null) {
198196
return PNone.NO_VALUE;
199197
} else {
200-
return readAttrNode.execute(getCore().lookupType(ownerKlass), key);
198+
return readAttrNode.execute(ctx.getCore().lookupType(ownerKlass), key);
201199
}
202200
}
203201

204202
@Specialization(replaces = "lookupPBCTCachedOwner")
205203
protected Object lookupPBCTGeneric(PythonBuiltinClassType klass,
204+
@CachedContext(PythonLanguage.class) PythonContext ctx,
206205
@Cached ReadAttributeFromDynamicObjectNode readAttrNode) {
207-
return findAttr(getCore(), klass, key, readAttrNode);
206+
return findAttr(ctx.getCore(), klass, key, readAttrNode);
208207
}
209208

210209
static final class AttributeAssumptionPair {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/LookupCallableSlotInMRONode.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
4848
import com.oracle.graal.python.builtins.objects.type.PythonClass;
4949
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
50+
import com.oracle.graal.python.runtime.PythonContext;
5051
import com.oracle.graal.python.runtime.PythonOptions;
5152
import com.oracle.truffle.api.dsl.Bind;
5253
import com.oracle.truffle.api.dsl.Cached;
54+
import com.oracle.truffle.api.dsl.CachedContext;
5355
import com.oracle.truffle.api.dsl.ImportStatic;
5456
import com.oracle.truffle.api.dsl.Specialization;
5557

@@ -103,7 +105,8 @@ static Object doBuiltinCachedSingleCtx(@SuppressWarnings("unused") PythonBuiltin
103105
assumptions = {"singleContextAssumption()"}, limit = "getAttributeAccessInlineCacheMaxDepth()")
104106
static Object doBuiltinTypeCachedSingleCtx(@SuppressWarnings("unused") PythonBuiltinClassType klassType,
105107
@SuppressWarnings("unused") @Cached("klassType") PythonBuiltinClassType cachedKlassType,
106-
@Cached("slot.getValue(getCore().lookupType(cachedKlassType))") Object value) {
108+
@SuppressWarnings("unused") @CachedContext(PythonLanguage.class) PythonContext ctx,
109+
@Cached("slot.getValue(ctx.getCore().lookupType(cachedKlassType))") Object value) {
107110
return value;
108111
}
109112

@@ -152,12 +155,13 @@ static Object doBuiltinTypeMultiContext(@SuppressWarnings("unused") PythonBuilti
152155
// Fallback when the cache with PythonBuiltinClassType overflows:
153156

154157
@Specialization(replaces = {"doBuiltinTypeCached", "doBuiltinTypeCachedSingleCtx", "doBuiltinTypeMultiContext"})
155-
Object doBuiltinTypeGeneric(PythonBuiltinClassType klass) {
158+
Object doBuiltinTypeGeneric(PythonBuiltinClassType klass,
159+
@CachedContext(PythonLanguage.class) PythonContext ctx) {
156160
Object result = slot.getValue(klass);
157161
if (result != null) {
158162
return result;
159163
} else {
160-
return slot.getValue(getCore().lookupType(klass));
164+
return slot.getValue(ctx.getCore().lookupType(klass));
161165
}
162166
}
163167

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/LookupInMROBaseNode.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,13 @@
4040
*/
4141
package com.oracle.graal.python.nodes.attributes;
4242

43-
import com.oracle.graal.python.PythonLanguage;
4443
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
4544
import com.oracle.graal.python.nodes.PNodeWithContext;
46-
import com.oracle.graal.python.runtime.PythonContext;
47-
import com.oracle.graal.python.runtime.PythonCore;
4845
import com.oracle.graal.python.runtime.PythonOptions;
49-
import com.oracle.truffle.api.CompilerDirectives;
50-
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
51-
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
5246
import com.oracle.truffle.api.dsl.ImportStatic;
5347

5448
@ImportStatic(PythonOptions.class)
5549
public abstract class LookupInMROBaseNode extends PNodeWithContext {
56-
@CompilationFinal private ContextReference<PythonContext> contextRef;
57-
58-
protected PythonCore getCore() {
59-
if (contextRef == null) {
60-
CompilerDirectives.transferToInterpreterAndInvalidate();
61-
contextRef = lookupContextReference(PythonLanguage.class);
62-
}
63-
return contextRef.get().getCore();
64-
}
65-
6650
public abstract Object execute(Object klass);
6751

6852
public static LookupInMROBaseNode create(String key) {

0 commit comments

Comments
 (0)