Skip to content

Commit 697eeef

Browse files
committed
Add Uncached variant to LookupSpecialMethodSlotNode
1 parent 85c0dc0 commit 697eeef

10 files changed

+88
-34
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
5151
import com.oracle.graal.python.runtime.PythonContext;
5252
import com.oracle.graal.python.runtime.PythonOptions;
53+
import com.oracle.truffle.api.TruffleLanguage;
5354
import com.oracle.truffle.api.dsl.Bind;
5455
import com.oracle.truffle.api.dsl.Cached;
5556
import com.oracle.truffle.api.dsl.CachedContext;
@@ -184,6 +185,7 @@ public static LookupCallableSlotInMRONode create(SpecialMethodSlot slot) {
184185

185186
protected static final class UncachedLookup extends LookupCallableSlotInMRONode {
186187

188+
private final TruffleLanguage.ContextReference<PythonContext> contextRef = lookupContextReference(PythonLanguage.class);
187189
private final SpecialMethodSlot slot;
188190

189191
private UncachedLookup(SpecialMethodSlot slot) {
@@ -193,7 +195,11 @@ private UncachedLookup(SpecialMethodSlot slot) {
193195
@Override
194196
public final Object execute(Object klass) {
195197
if (klass instanceof PythonBuiltinClassType) {
196-
return slot.getValue(lookupContextReference(PythonLanguage.class).get().getCore().lookupType((PythonBuiltinClassType) klass));
198+
Object result = slot.getValue((PythonBuiltinClassType) klass);
199+
if (result == null) {
200+
result = slot.getValue(contextRef.get().getCore().lookupType((PythonBuiltinClassType) klass));
201+
}
202+
return result;
197203
} else if (klass instanceof PythonManagedClass) {
198204
return slot.getValue((PythonManagedClass) klass);
199205
} else {
@@ -202,6 +208,11 @@ public final Object execute(Object klass) {
202208
}
203209
}
204210

211+
@Override
212+
public boolean isAdoptable() {
213+
return false;
214+
}
215+
205216
private static final UncachedLookup[] UNCACHEDS = new UncachedLookup[SpecialMethodSlot.values().length];
206217
static {
207218
SpecialMethodSlot[] values = SpecialMethodSlot.values();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4848
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4949
import com.oracle.graal.python.nodes.call.CallNode;
50-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptor.BoundDescriptor;
50+
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
5151
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
5252
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
5353
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4545
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4646
import com.oracle.graal.python.nodes.call.CallNode;
47-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptor.BoundDescriptor;
47+
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
4848
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
4949
import com.oracle.truffle.api.RootCallTarget;
5050
import com.oracle.truffle.api.dsl.Cached;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallTernaryMethodNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4747
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4848
import com.oracle.graal.python.nodes.call.CallNode;
49-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptor.BoundDescriptor;
49+
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
5050
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
5151
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
5252
import com.oracle.graal.python.runtime.PythonContext;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallUnaryMethodNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4848
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4949
import com.oracle.graal.python.nodes.call.CallNode;
50-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptor.BoundDescriptor;
50+
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
5151
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
5252
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5353
import com.oracle.graal.python.runtime.PythonContext;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallVarargsMethodNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4646
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4747
import com.oracle.graal.python.nodes.call.CallNode;
48-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptor.BoundDescriptor;
48+
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
4949
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
5050
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode.VarargsBuiltinDirectInvocationNotSupported;
5151
import com.oracle.graal.python.util.PythonUtils;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupSpecialBaseNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
package com.oracle.graal.python.nodes.call.special;
4242

4343
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
44-
import com.oracle.truffle.api.frame.VirtualFrame;
44+
import com.oracle.truffle.api.frame.Frame;
4545
import com.oracle.truffle.api.nodes.Node;
4646

4747
public abstract class LookupSpecialBaseNode extends Node {
48-
public abstract Object execute(VirtualFrame frame, Object type, Object receiver);
48+
public abstract Object execute(Frame frame, Object type, Object receiver);
4949

5050
public static LookupSpecialBaseNode create(String key) {
5151
SpecialMethodSlot slot = SpecialMethodSlot.findSpecialSlot(key);
@@ -54,5 +54,4 @@ public static LookupSpecialBaseNode create(String key) {
5454
}
5555
return LookupSpecialMethodNode.create(key);
5656
}
57-
5857
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupSpecialMethodNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public static LookupSpecialMethodNode create(String name) {
7575
@Specialization
7676
Object lookup(VirtualFrame frame, Object type, Object receiver,
7777
@Cached(parameters = "name") LookupAttributeInMRONode lookupMethod,
78-
@Cached MaybeBindDescriptor bind) {
79-
return bind.execute(frame, lookupMethod.execute(type), receiver);
78+
@Cached MaybeBindDescriptorNode bind) {
79+
return bind.execute(frame, lookupMethod.execute(type), receiver, type);
8080
}
8181

8282
@GenerateUncached
@@ -104,10 +104,10 @@ Object lookup(VirtualFrame frame, Object type, String name, Object receiver,
104104
}
105105
Object getMethod = lookupGet.execute(descriptor, SpecialMethodNames.__GET__);
106106
if (getMethod != PNone.NO_VALUE) {
107-
return new MaybeBindDescriptor.BoundDescriptor(callGet.execute(frame, getMethod, descriptor, receiver, type));
107+
return new MaybeBindDescriptorNode.BoundDescriptor(callGet.execute(frame, getMethod, descriptor, receiver, type));
108108
}
109109
// CPython considers non-descriptors already bound
110-
return new MaybeBindDescriptor.BoundDescriptor(descriptor);
110+
return new MaybeBindDescriptorNode.BoundDescriptor(descriptor);
111111
}
112112
}
113113
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupSpecialMethodSlotNode.java

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
4646
import com.oracle.truffle.api.dsl.Cached;
4747
import com.oracle.truffle.api.dsl.Specialization;
48+
import com.oracle.truffle.api.frame.Frame;
4849
import com.oracle.truffle.api.frame.VirtualFrame;
4950

5051
/**
@@ -54,20 +55,53 @@
5455
* handle as well.
5556
*/
5657
public abstract class LookupSpecialMethodSlotNode extends LookupSpecialBaseNode {
57-
protected final SpecialMethodSlot slot;
58+
protected static abstract class CachedLookup extends LookupSpecialMethodSlotNode {
59+
protected final SpecialMethodSlot slot;
5860

59-
public LookupSpecialMethodSlotNode(SpecialMethodSlot slot) {
60-
this.slot = slot;
61+
public CachedLookup(SpecialMethodSlot slot) {
62+
this.slot = slot;
63+
}
64+
65+
@Specialization
66+
Object lookup(VirtualFrame frame, Object type, Object receiver,
67+
@Cached(parameters = "slot") LookupCallableSlotInMRONode lookupSlot,
68+
@Cached MaybeBindDescriptorNode bind) {
69+
return bind.execute(frame, lookupSlot.execute(type), receiver, type);
70+
}
6171
}
6272

6373
public static LookupSpecialMethodSlotNode create(SpecialMethodSlot slot) {
64-
return LookupSpecialMethodSlotNodeGen.create(slot);
74+
return LookupSpecialMethodSlotNodeFactory.CachedLookupNodeGen.create(slot);
75+
}
76+
77+
private final static class UncachedLookup extends LookupSpecialMethodSlotNode {
78+
protected final LookupCallableSlotInMRONode lookup;
79+
80+
public UncachedLookup(SpecialMethodSlot slot) {
81+
this.lookup = LookupCallableSlotInMRONode.getUncached(slot);
82+
}
83+
84+
@Override
85+
public Object execute(@SuppressWarnings("unused") Frame frame, Object type, Object receiver) {
86+
return MaybeBindDescriptorNode.getUncached().execute(frame, lookup.execute(type), receiver, type);
87+
}
88+
89+
@Override
90+
public boolean isAdoptable() {
91+
return false;
92+
}
93+
94+
private static final UncachedLookup[] UNCACHEDS = new UncachedLookup[SpecialMethodSlot.values().length];
95+
static {
96+
SpecialMethodSlot[] values = SpecialMethodSlot.values();
97+
for (int i = 0; i < values.length; i++) {
98+
SpecialMethodSlot slot = values[i];
99+
UNCACHEDS[i] = new UncachedLookup(slot);
100+
}
101+
}
65102
}
66103

67-
@Specialization
68-
Object lookup(VirtualFrame frame, Object type, Object receiver,
69-
@Cached(parameters = "slot") LookupCallableSlotInMRONode lookupSlot,
70-
@Cached MaybeBindDescriptor bind) {
71-
return bind.execute(frame, lookupSlot.execute(type), receiver);
104+
public static LookupSpecialMethodSlotNode getUncached(SpecialMethodSlot slot) {
105+
return UncachedLookup.UNCACHEDS[slot.ordinal()];
72106
}
73107
}
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor;
55
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
66
import com.oracle.graal.python.builtins.objects.function.PFunction;
7+
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
78
import com.oracle.graal.python.nodes.PNodeWithContext;
8-
import com.oracle.graal.python.nodes.SpecialMethodNames;
9-
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
9+
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
1010
import com.oracle.graal.python.nodes.object.GetClassNode;
1111
import com.oracle.truffle.api.dsl.Cached;
1212
import com.oracle.truffle.api.dsl.GenerateUncached;
13+
import com.oracle.truffle.api.dsl.ImportStatic;
1314
import com.oracle.truffle.api.dsl.Specialization;
1415
import com.oracle.truffle.api.frame.Frame;
1516
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -19,7 +20,8 @@
1920
* nodes handle unbound.
2021
*/
2122
@GenerateUncached
22-
public abstract class MaybeBindDescriptor extends PNodeWithContext {
23+
@ImportStatic(SpecialMethodSlot.class)
24+
public abstract class MaybeBindDescriptorNode extends PNodeWithContext {
2325

2426
/**
2527
* Wrapper for bound descriptor cases, just to be able to distinguish them from unbound
@@ -33,25 +35,25 @@ public BoundDescriptor(Object descriptor) {
3335
}
3436
}
3537

36-
public abstract Object execute(Frame frame, Object descriptor, Object receiver);
38+
public abstract Object execute(Frame frame, Object descriptor, Object receiver, Object receiverType);
3739

3840
@Specialization(guards = "isNoValue(descriptor)")
39-
static Object doNoValue(Object descriptor, @SuppressWarnings("unused") Object receiver) {
41+
static Object doNoValue(Object descriptor, @SuppressWarnings("unused") Object receiver, @SuppressWarnings("unused") Object receiverType) {
4042
return descriptor;
4143
}
4244

4345
@Specialization
44-
static Object doBuiltin(BuiltinMethodDescriptor descriptor, @SuppressWarnings("unused") Object receiver) {
46+
static Object doBuiltin(BuiltinMethodDescriptor descriptor, @SuppressWarnings("unused") Object receiver, @SuppressWarnings("unused") Object receiverType) {
4547
return descriptor;
4648
}
4749

4850
@Specialization
49-
static Object doBuiltin(PBuiltinFunction descriptor, @SuppressWarnings("unused") Object receiver) {
51+
static Object doBuiltin(PBuiltinFunction descriptor, @SuppressWarnings("unused") Object receiver, @SuppressWarnings("unused") Object receiverType) {
5052
return descriptor;
5153
}
5254

5355
@Specialization
54-
static Object doFunction(PFunction descriptor, @SuppressWarnings("unused") Object receiver) {
56+
static Object doFunction(PFunction descriptor, @SuppressWarnings("unused") Object receiver, @SuppressWarnings("unused") Object receiverType) {
5557
return descriptor;
5658
}
5759

@@ -60,15 +62,23 @@ protected static boolean needsToBind(Object descriptor) {
6062
}
6163

6264
@Specialization(guards = "needsToBind(descriptor)")
63-
static Object doBind(VirtualFrame frame, Object descriptor, Object receiver,
65+
static Object doBind(VirtualFrame frame, Object descriptor, Object receiver, Object receiverType,
6466
@Cached GetClassNode getClassNode,
65-
@Cached LookupAttributeInMRONode.Dynamic lookupGet,
67+
@Cached(parameters = "Get") LookupCallableSlotInMRONode lookupGet,
6668
@Cached CallTernaryMethodNode callGet) {
67-
Object getMethod = lookupGet.execute(descriptor, SpecialMethodNames.__GET__);
69+
Object getMethod = lookupGet.execute(getClassNode.execute(descriptor));
6870
if (getMethod != PNone.NO_VALUE) {
69-
return new BoundDescriptor(callGet.execute(frame, getMethod, descriptor, receiver, getClassNode.execute(receiver)));
71+
return new BoundDescriptor(callGet.execute(frame, getMethod, descriptor, receiver, receiverType));
7072
}
7173
// CPython considers non-descriptors already bound
7274
return new BoundDescriptor(descriptor);
7375
}
76+
77+
public static MaybeBindDescriptorNode create() {
78+
return MaybeBindDescriptorNodeGen.create();
79+
}
80+
81+
public static MaybeBindDescriptorNode getUncached() {
82+
return MaybeBindDescriptorNodeGen.getUncached();
83+
}
7484
}

0 commit comments

Comments
 (0)