Skip to content

Commit b055942

Browse files
committed
Track frame reference root node instead of call node
1 parent c211b2a commit b055942

17 files changed

+64
-96
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ public static IndirectCallData lookupIndirectCallData(Node node) {
12091209

12101210
public static IndirectCallData createIndirectCallData(Node node) {
12111211
CompilerAsserts.neverPartOfCompilation();
1212-
return get(node).indirectCallDataMap.computeIfAbsent(node, n -> new IndirectCallData(node));
1212+
return get(node).indirectCallDataMap.computeIfAbsent(node, n -> new IndirectCallData());
12131213
}
12141214

12151215
public Source getOrCreateSource(Function<Object, Source> rootNodeFunction, Object key) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,12 +2514,12 @@ class InitializeBuildClass {
25142514
// will use the explicitly given object as it is
25152515
}
25162516
}
2517-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
2517+
Object savedState = IndirectCallContext.enter(frame, inliningTarget, indirectCallData);
25182518
InitializeBuildClass init;
25192519
try {
25202520
init = new InitializeBuildClass(ctx);
25212521
} finally {
2522-
IndirectCallContext.exit(frame, indirectCallData, savedState);
2522+
IndirectCallContext.exit(frame, inliningTarget, indirectCallData, savedState);
25232523
}
25242524

25252525
Object ns;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static boolean compare(VirtualFrame frame, Object left, Object right,
159159
if (!bufferAcquireLib.hasBuffer(left) || !bufferAcquireLib.hasBuffer(right)) {
160160
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.UNSUPPORTED_OPERAND_TYPES_OR_COMBINATION_OF_TYPES, left, right);
161161
}
162-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
162+
Object savedState = IndirectCallContext.enter(frame, inliningTarget, indirectCallData);
163163
Object leftBuffer = bufferAcquireLib.acquireReadonly(left);
164164
try {
165165
Object rightBuffer = bufferAcquireLib.acquireReadonly(right);
@@ -170,7 +170,7 @@ static boolean compare(VirtualFrame frame, Object left, Object right,
170170
}
171171
} finally {
172172
bufferLib.release(leftBuffer);
173-
IndirectCallContext.exit(frame, indirectCallData, savedState);
173+
IndirectCallContext.exit(frame, inliningTarget, indirectCallData, savedState);
174174
}
175175
}
176176
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StructureBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ static int _init_pos_args(VirtualFrame frame, Node inliningTarget, Object self,
191191
indirectCallData, setAttr, getItemNode, toString, getItem, pyTypeStgDictNode, getBaseClassNode, equalNode,
192192
raiseNode, recursionLimit - 1);
193193
} else {
194-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
194+
Object savedState = IndirectCallContext.enter(frame, inliningTarget, indirectCallData);
195195
try {
196196
index = _init_pos_args_boundary(self, base, args, kwds, index, indirectCallData, setAttr, getItemNode);
197197
} finally {
198-
IndirectCallContext.exit(frame, indirectCallData, savedState);
198+
IndirectCallContext.exit(frame, inliningTarget, indirectCallData, savedState);
199199
}
200200
}
201201
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAccessLibrary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ public void release(@SuppressWarnings("unused") Object receiver) {
117117
* multiple times on the same buffer.
118118
*/
119119
public final void release(Object receiver, VirtualFrame frame, IndirectCallData indirectCallData) {
120-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
120+
Object savedState = IndirectCallContext.enter(frame, this, indirectCallData);
121121
try {
122122
release(receiver);
123123
} finally {
124-
IndirectCallContext.exit(frame, indirectCallData, savedState);
124+
IndirectCallContext.exit(frame, this, indirectCallData, savedState);
125125
}
126126
}
127127

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAcquireLibrary.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ public final Object acquireReadonly(Object receiver) {
115115
* node which is an ancestor of the library.
116116
*/
117117
public final Object acquireReadonly(Object receiver, VirtualFrame frame, IndirectCallData indirectCallData) {
118-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
118+
Object savedState = IndirectCallContext.enter(frame, this, indirectCallData);
119119
try {
120120
return acquire(receiver, BufferFlags.PyBUF_SIMPLE);
121121
} finally {
122-
IndirectCallContext.exit(frame, indirectCallData, savedState);
122+
IndirectCallContext.exit(frame, this, indirectCallData, savedState);
123123
}
124124
}
125125

@@ -165,11 +165,11 @@ public final Object acquireWritable(Object receiver) {
165165
* node which is an ancestor of the library.
166166
*/
167167
public final Object acquireWritable(Object receiver, VirtualFrame frame, IndirectCallData indirectCallData) {
168-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
168+
Object savedState = IndirectCallContext.enter(frame, this, indirectCallData);
169169
try {
170170
return acquire(receiver, BufferFlags.PyBUF_WRITABLE);
171171
} finally {
172-
IndirectCallContext.exit(frame, indirectCallData, savedState);
172+
IndirectCallContext.exit(frame, this, indirectCallData, savedState);
173173
}
174174
}
175175

@@ -198,13 +198,13 @@ public final Object acquireWritable(Object receiver, VirtualFrame frame, PythonC
198198
* acquisition produced.
199199
*/
200200
public final Object acquireWritableWithTypeError(Object receiver, String callerName, VirtualFrame frame, IndirectCallData indirectCallData) {
201-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
201+
Object savedState = IndirectCallContext.enter(frame, this, indirectCallData);
202202
try {
203203
return acquireWritable(receiver);
204204
} catch (PException e) {
205205
throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.S_BRACKETS_ARG_MUST_BE_READ_WRITE_BYTES_LIKE_NOT_P, callerName, receiver);
206206
} finally {
207-
IndirectCallContext.exit(frame, indirectCallData, savedState);
207+
IndirectCallContext.exit(frame, this, indirectCallData, savedState);
208208
}
209209
}
210210

@@ -234,11 +234,11 @@ public Object acquire(Object receiver, int flags) {
234234
* library.
235235
*/
236236
public final Object acquire(Object receiver, int flags, VirtualFrame frame, IndirectCallData indirectCallData) {
237-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
237+
Object savedState = IndirectCallContext.enter(frame, this, indirectCallData);
238238
try {
239239
return acquire(receiver, flags);
240240
} finally {
241-
IndirectCallContext.exit(frame, indirectCallData, savedState);
241+
IndirectCallContext.exit(frame, this, indirectCallData, savedState);
242242
}
243243
}
244244

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,12 @@ static Object mod(VirtualFrame frame, Object self, Object right,
363363
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
364364
int bytesLen = bufferLib.getBufferLength(buffer);
365365
BytesFormatProcessor formatter = new BytesFormatProcessor(PythonContext.get(inliningTarget), getTupleItemNode, bytes, bytesLen, inliningTarget);
366-
Object savedState = IndirectCallContext.enter(frame, indirectCallData);
366+
Object savedState = IndirectCallContext.enter(frame, inliningTarget, indirectCallData);
367367
try {
368368
byte[] data = formatter.format(right);
369369
return create.execute(inliningTarget, self, data);
370370
} finally {
371-
IndirectCallContext.exit(frame, indirectCallData, savedState);
371+
IndirectCallContext.exit(frame, inliningTarget, indirectCallData, savedState);
372372
}
373373
} finally {
374374
bufferLib.release(buffer, frame, indirectCallData);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import com.oracle.truffle.api.bytecode.BytecodeNode;
6161
import com.oracle.truffle.api.frame.MaterializedFrame;
6262
import com.oracle.truffle.api.nodes.Node;
63+
import com.oracle.truffle.api.nodes.RootNode;
6364

6465
public final class PFrame extends PythonBuiltinObject {
6566
private static final int UNINITIALIZED_LINE = -2;
@@ -121,13 +122,12 @@ public void setJumpDestLine(int jumpDestLine) {
121122
// TODO: frames: this is a large object, think about how to make this
122123
// smaller
123124
public static final class Reference {
124-
public static final Reference EMPTY = new Reference(null);
125+
public static final Reference EMPTY = new Reference(null, null);
125126

126127
// The Python-level frame
127128
private PFrame pyFrame = null;
128129

129-
// The location of the last call
130-
private Node callNode = null;
130+
private final RootNode rootNode;
131131

132132
// A flag whether this frame is escaped. A Truffle frame is escaped if the corresponding
133133
// PFrame may be used without having the Truffle frame on the stack. This flag is also set
@@ -136,10 +136,15 @@ public static final class Reference {
136136

137137
private final Reference callerInfo;
138138

139-
public Reference(Reference callerInfo) {
139+
public Reference(RootNode rootNode, Reference callerInfo) {
140+
this.rootNode = rootNode;
140141
this.callerInfo = callerInfo;
141142
}
142143

144+
public RootNode getRootNode() {
145+
return rootNode;
146+
}
147+
143148
public void setBackref(PFrame.Reference backref) {
144149
assert pyFrame != null : "setBackref should only be called when the PFrame escaped";
145150
pyFrame.setBackref(backref);
@@ -162,14 +167,6 @@ public void setPyFrame(PFrame escapedFrame) {
162167
this.pyFrame = escapedFrame;
163168
}
164169

165-
public Node getCallNode() {
166-
return callNode;
167-
}
168-
169-
public void setCallNode(Node callNode) {
170-
this.callNode = callNode;
171-
}
172-
173170
public Reference getCallerInfo() {
174171
return callerInfo;
175172
}
@@ -188,10 +185,10 @@ public PFrame(PythonLanguage lang, @SuppressWarnings("unused") Object threadStat
188185
Object[] frameArgs = PArguments.create();
189186
PArguments.setGlobals(frameArgs, globals);
190187
PArguments.setSpecialArgument(frameArgs, localsDict);
191-
Reference curFrameInfo = new Reference(null);
188+
this.location = GetCodeRootNode.executeUncached(code);
189+
Reference curFrameInfo = new Reference(location != null ? location.getRootNode() : null, null);
192190
this.virtualFrameInfo = curFrameInfo;
193191
curFrameInfo.setPyFrame(this);
194-
this.location = GetCodeRootNode.executeUncached(code);
195192
this.line = this.location == null ? code.getFirstLineNo() : UNINITIALIZED_LINE;
196193
this.arguments = frameArgs;
197194
this.locals = null;
@@ -291,8 +288,8 @@ public RootCallTarget getTarget() {
291288
if (callTarget == null) {
292289
if (location != null) {
293290
callTarget = PythonUtils.getOrCreateCallTarget(location.getRootNode());
294-
} else if (getRef() != null && getRef().getCallNode() != null) {
295-
callTarget = PythonUtils.getOrCreateCallTarget(getRef().getCallNode().getRootNode());
291+
} else if (getRef() != null && getRef().getRootNode() != null) {
292+
callTarget = PythonUtils.getOrCreateCallTarget(getRef().getRootNode());
296293
}
297294
}
298295
return callTarget;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,11 @@ public static void executeUncached(BufferLifecycleManager buffer) {
628628
}
629629

630630
public final void execute(VirtualFrame frame, Node inliningTarget, IndirectCallData indirectCallData, BufferLifecycleManager buffer) {
631-
Object state = IndirectCallContext.enter(frame, indirectCallData);
631+
Object state = IndirectCallContext.enter(frame, inliningTarget, indirectCallData);
632632
try {
633633
execute(inliningTarget, buffer);
634634
} finally {
635-
IndirectCallContext.exit(frame, indirectCallData, state);
635+
IndirectCallContext.exit(frame, inliningTarget, indirectCallData, state);
636636
}
637637
}
638638

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,11 @@ static Object dir(VirtualFrame frame, Object obj,
905905
}
906906
Object klass = lookupAttrNode.execute(frame, inliningTarget, obj, T___CLASS__);
907907
if (klass != PNone.NO_VALUE) {
908-
Object state = IndirectCallContext.enter(frame, indirectCallData);
908+
Object state = IndirectCallContext.enter(frame, inliningTarget, indirectCallData);
909909
try {
910910
com.oracle.graal.python.builtins.objects.type.TypeBuiltins.DirNode.dir(names, klass);
911911
} finally {
912-
IndirectCallContext.exit(frame, indirectCallData, state);
912+
IndirectCallContext.exit(frame, inliningTarget, indirectCallData, state);
913913
}
914914
}
915915
return constructListNode.execute(frame, names);

0 commit comments

Comments
 (0)