Skip to content

Commit 3d5359b

Browse files
committed
Use the correct BytecodeNode in GetFrameLocalsNode
1 parent 7ff5327 commit 3d5359b

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3345,7 +3345,7 @@ private void syncLocalsBackToFrame(VirtualFrame virtualFrame, PFrame pyFrame, in
33453345
Frame localFrame = getLocalFrame(virtualFrame);
33463346
if (pyFrame.localsAccessed()) {
33473347
enterTraceProfile(bci, TRACE_PROFILE_SYNC_LOCALS_BACK);
3348-
GetFrameLocalsNode.syncLocalsBackToFrame(co, this, pyFrame, localFrame);
3348+
GetFrameLocalsNode.syncLocalsBackToFrame(co, pyFrame, localFrame, null);
33493349
}
33503350
}
33513351

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,8 @@ private PFrame ensurePyFrame(VirtualFrame frame, BytecodeNode location) {
540540
return traceMaterializeFrameNode.executeOnStack(frame, location, true, true);
541541
}
542542

543-
private void syncLocalsBackToFrame(VirtualFrame frame, PFrame pyFrame) {
544-
GetFrameLocalsNode.syncLocalsBackToFrame(co, this, pyFrame, frame);
543+
private void syncLocalsBackToFrame(VirtualFrame frame, PFrame pyFrame, BytecodeNode location) {
544+
GetFrameLocalsNode.syncLocalsBackToFrame(co, pyFrame, frame, location);
545545
}
546546

547547
/**
@@ -583,7 +583,7 @@ private void invokeProfileFunction(VirtualFrame virtualFrame, BytecodeNode locat
583583
// Force locals dict sync, so that we can sync them back later
584584
GetFrameLocalsNode.executeUncached(pyFrame, false);
585585
Object result = doInvokeProfileOrTraceFunction(virtualFrame, location, threadState, profileFun, pyFrame, event.name, arg);
586-
syncLocalsBackToFrame(virtualFrame, pyFrame);
586+
syncLocalsBackToFrame(virtualFrame, pyFrame, location);
587587
Object realResult = result == PNone.NONE ? null : result;
588588
pyFrame.setLocalTraceFun(realResult);
589589
} catch (Throwable e) {
@@ -631,7 +631,7 @@ private void invokeTraceFunction(VirtualFrame virtualFrame, BytecodeNode locatio
631631
// Force locals dict sync, so that we can sync them back later
632632
GetFrameLocalsNode.executeUncached(pyFrame, false);
633633
Object result = doInvokeProfileOrTraceFunction(virtualFrame, location, threadState, traceFn, pyFrame, event.pythonName, nonNullArg);
634-
syncLocalsBackToFrame(virtualFrame, pyFrame);
634+
syncLocalsBackToFrame(virtualFrame, pyFrame, location);
635635
// https://github.com/python/cpython/issues/104232
636636
if (useLocalFn) {
637637
Object realResult = result == PNone.NONE ? traceFn : result;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@
4949
import com.oracle.graal.python.builtins.objects.frame.PFrame;
5050
import com.oracle.graal.python.compiler.CodeUnit;
5151
import com.oracle.graal.python.lib.PyDictGetItem;
52-
import com.oracle.graal.python.nodes.PRootNode;
5352
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
54-
import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo;
55-
import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode;
5653
import com.oracle.graal.python.runtime.CallerFlags;
5754
import com.oracle.graal.python.runtime.PythonOptions;
5855
import com.oracle.graal.python.runtime.object.PFactory;
@@ -116,7 +113,7 @@ static Object doLoop(VirtualFrame frame, Node inliningTarget, PFrame pyFrame, bo
116113
localsDict = PFactory.createDict(PythonLanguage.get(inliningTarget));
117114
pyFrame.setLocalsDict(localsDict);
118115
}
119-
copyLocalsToDict.execute(locals, localsDict);
116+
copyLocalsToDict.execute(locals, localsDict, pyFrame.getBytecodeNode());
120117
return localsDict;
121118
}
122119

@@ -130,11 +127,11 @@ static Object doCustomLocals(PFrame pyFrame, @SuppressWarnings("unused") boolean
130127
@GenerateUncached
131128
@GenerateInline(false) // footprint reduction 104 -> 86
132129
abstract static class CopyLocalsToDict extends Node {
133-
abstract void execute(MaterializedFrame locals, PDict dict);
130+
abstract void execute(MaterializedFrame locals, PDict dict, BytecodeNode bytecodeNode);
134131

135132
@Specialization(guards = {"cachedFd == locals.getFrameDescriptor()", "info != null", "count < 32"}, limit = "1")
136133
@ExplodeLoop
137-
void doCachedFd(MaterializedFrame locals, PDict dict,
134+
static void doCachedFd(MaterializedFrame locals, PDict dict, BytecodeNode bytecodeNode,
138135
@Bind Node inliningTarget,
139136
@SuppressWarnings("unused") @Cached("locals.getFrameDescriptor()") FrameDescriptor cachedFd,
140137
@Bind("getInfo(cachedFd)") FrameInfo info,
@@ -144,9 +141,7 @@ void doCachedFd(MaterializedFrame locals, PDict dict,
144141
int regularVarCount = info.getRegularVariableCount();
145142

146143
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
147-
BytecodeDSLFrameInfo bytecodeDSLFrameInfo = (BytecodeDSLFrameInfo) info;
148-
PBytecodeDSLRootNode rootNode = bytecodeDSLFrameInfo.getRootNode();
149-
Object[] localsArray = rootNode.getBytecodeNode().getLocalValues(0, locals);
144+
Object[] localsArray = bytecodeNode.getLocalValues(0, locals);
150145
for (int i = 0; i < count; i++) {
151146
copyItem(inliningTarget, localsArray[i], info, dict, setItem, delItem, i, i >= regularVarCount);
152147
}
@@ -158,7 +153,7 @@ void doCachedFd(MaterializedFrame locals, PDict dict,
158153
}
159154

160155
@Specialization(replaces = "doCachedFd")
161-
void doGeneric(MaterializedFrame locals, PDict dict,
156+
void doGeneric(MaterializedFrame locals, PDict dict, BytecodeNode bytecodeNode,
162157
@Bind Node inliningTarget,
163158
@Shared("setItem") @Cached HashingStorageSetItem setItem,
164159
@Shared("delItem") @Cached HashingStorageDelItem delItem) {
@@ -171,9 +166,7 @@ void doGeneric(MaterializedFrame locals, PDict dict,
171166
int regularVarCount = info.getRegularVariableCount();
172167

173168
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
174-
BytecodeDSLFrameInfo bytecodeDSLFrameInfo = (BytecodeDSLFrameInfo) info;
175-
PBytecodeDSLRootNode rootNode = bytecodeDSLFrameInfo.getRootNode();
176-
Object[] localsArray = rootNode.getBytecodeNode().getLocalValues(0, locals);
169+
Object[] localsArray = bytecodeNode.getLocalValues(0, locals);
177170
for (int i = 0; i < count; i++) {
178171
copyItem(inliningTarget, localsArray[i], info, dict, setItem, delItem, i, i >= regularVarCount);
179172
}
@@ -207,19 +200,17 @@ protected static FrameInfo getInfo(FrameDescriptor fd) {
207200
/**
208201
* Equivalent of CPython's {@code PyFrame_LocalsToFast}
209202
*/
210-
public static void syncLocalsBackToFrame(CodeUnit co, PRootNode root, PFrame pyFrame, Frame localFrame) {
203+
public static void syncLocalsBackToFrame(CodeUnit co, PFrame pyFrame, Frame localFrame, BytecodeNode bytecodeNode) {
211204
if (!pyFrame.hasCustomLocals()) {
212205
PDict localsDict = (PDict) pyFrame.getLocalsDict();
213-
copyLocalsArray(localFrame, root, localsDict, co.varnames, 0, false);
214-
copyLocalsArray(localFrame, root, localsDict, co.cellvars, co.varnames.length, true);
215-
copyLocalsArray(localFrame, root, localsDict, co.freevars, co.varnames.length + co.cellvars.length, true);
206+
copyLocalsArray(localFrame, localsDict, bytecodeNode, co.varnames, 0, false);
207+
copyLocalsArray(localFrame, localsDict, bytecodeNode, co.cellvars, co.varnames.length, true);
208+
copyLocalsArray(localFrame, localsDict, bytecodeNode, co.freevars, co.varnames.length + co.cellvars.length, true);
216209
}
217210
}
218211

219-
private static void copyLocalsArray(Frame localFrame, PRootNode root, PDict localsDict, TruffleString[] namesArray, int offset, boolean deref) {
212+
private static void copyLocalsArray(Frame localFrame, PDict localsDict, BytecodeNode bytecodeNode, TruffleString[] namesArray, int offset, boolean deref) {
220213
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
221-
PBytecodeDSLRootNode bytecodeDSLRootNode = (PBytecodeDSLRootNode) root;
222-
BytecodeNode bytecodeNode = bytecodeDSLRootNode.getBytecodeNode();
223214
for (int i = 0; i < namesArray.length; i++) {
224215
TruffleString varname = namesArray[i];
225216
Object value = getDictItemUncached(localsDict, varname);

0 commit comments

Comments
 (0)