Skip to content

Commit 2afbaa4

Browse files
author
Adam Hrbac
committed
Use truffle APIs correctly
1 parent 516ddcb commit 2afbaa4

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,33 +1031,33 @@ Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNo
10311031
* cached or uncached nodes.
10321032
*/
10331033
if (usingCachedNodes) {
1034-
return executeCached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop);
1034+
return executeCached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, false);
10351035
} else {
10361036
CompilerDirectives.transferToInterpreterAndInvalidate();
10371037
usingCachedNodes = true;
10381038
Object result = executeUncached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop);
10391039
if (result instanceof InterpreterContinuation) {
10401040
InterpreterContinuation continuation = (InterpreterContinuation) result;
1041-
return executeCached(virtualFrame, localFrame, osrNode, continuation.bci, continuation.stackTop);
1041+
return executeCached(virtualFrame, localFrame, osrNode, continuation.bci, continuation.stackTop, true);
10421042
}
10431043
return result;
10441044
}
10451045
}
10461046

10471047
@BytecodeInterpreterSwitch
1048-
private Object executeCached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop) {
1049-
return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, true);
1048+
private Object executeCached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, boolean fromOSR) {
1049+
return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, true, fromOSR);
10501050
}
10511051

10521052
@BytecodeInterpreterSwitch
10531053
private Object executeUncached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop) {
1054-
return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, false);
1054+
return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, false, false);
10551055
}
10561056

10571057
@ExplodeLoop(kind = ExplodeLoop.LoopExplosionKind.MERGE_EXPLODE)
10581058
@SuppressWarnings("fallthrough")
10591059
@BytecodeInterpreterSwitch
1060-
private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, boolean useCachedNodes) {
1060+
private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, boolean useCachedNodes, boolean fromOSR) {
10611061
boolean inCompiledCode = CompilerDirectives.inCompiledCode();
10621062
Object[] arguments = virtualFrame.getArguments();
10631063
Object globals = PArguments.getGlobals(arguments);
@@ -1098,7 +1098,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
10981098
int pastLine = -1;
10991099
if (threadState.getTraceFun() != null && !threadState.isTracing()) {
11001100
pyFrame = ensurePyFrame(virtualFrame, null);
1101-
if (initialBci == 0 || isGeneratorOrCoroutine) {
1101+
// if we are simply continuing to run an OSR loop after the replacememnt, tracing an
1102+
// extra CALL event would be incorrect
1103+
if (!fromOSR) {
11021104
pyFrame.setLocalTraceFun(invokeTraceFunction(threadState.getTraceFun(), null, threadState, virtualFrame, pyFrame, PythonContext.TraceEvent.CALL,
11031105
initialBci == 0 ? getFirstLineno() : (pastLine = bciToLine(initialBci))));
11041106
}
@@ -2154,12 +2156,13 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
21542156
pyFrame = ensurePyFrame(virtualFrame, pyFrame);
21552157
if (pyFrame.getLocalTraceFun() != null) {
21562158
if (traceGetExceptionTracebackNode == null) {
2157-
traceGetExceptionTracebackNode = GetExceptionTracebackNode.create();
2159+
CompilerDirectives.transferToInterpreterAndInvalidate();
2160+
traceGetExceptionTracebackNode = insert(GetExceptionTracebackNode.create());
21582161
}
21592162
Object traceback = traceGetExceptionTracebackNode.execute(pe);
21602163
pyFrame.setLocalTraceFun(invokeTraceFunction(pyFrame.getLocalTraceFun(),
21612164
factory.createTuple(new Object[]{pe.getClass(), pe.setCatchingFrameAndGetEscapedException(virtualFrame, this), traceback}), threadState, virtualFrame, pyFrame,
2162-
PythonContext.TraceEvent.EXCEPTION, -1));
2165+
PythonContext.TraceEvent.EXCEPTION, bciToLine(bci)));
21632166
}
21642167
}
21652168

@@ -2171,7 +2174,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
21712174
} else {
21722175
if (getCaughtExceptionNode == null) {
21732176
CompilerDirectives.transferToInterpreterAndInvalidate();
2174-
getCaughtExceptionNode = ExceptionStateNodes.GetCaughtExceptionNode.create();
2177+
getCaughtExceptionNode = insert(ExceptionStateNodes.GetCaughtExceptionNode.create());
21752178
}
21762179
PException exceptionState = getCaughtExceptionNode.execute(virtualFrame);
21772180
if (exceptionState != null) {
@@ -2224,21 +2227,22 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
22242227

22252228
private PFrame ensurePyFrame(VirtualFrame virtualFrame, PFrame pyFrame) {
22262229
if (traceMaterializeFrameNode == null) {
2227-
traceMaterializeFrameNode = MaterializeFrameNode.create();
2230+
CompilerDirectives.transferToInterpreterAndInvalidate();
2231+
traceMaterializeFrameNode = insert(MaterializeFrameNode.create());
22282232
}
22292233
if (pyFrame == null) {
22302234
return traceMaterializeFrameNode.execute(virtualFrame, this, true, true);
22312235
}
22322236
return pyFrame;
22332237
}
2234-
// TODO: trace with OSR in a generator will create extraneous call events
22352238

22362239
private Object invokeTraceFunction(Object traceFn, Object arg, PythonContext.PythonThreadState threadState, VirtualFrame virtualFrame, PFrame tracing,
22372240
PythonContext.TraceEvent event, int line) {
22382241
threadState.tracingStart(event);
22392242
Object nonNullArg = arg == null ? PNone.NONE : arg;
22402243
if (traceCallTernaryMethodNode == null) {
2241-
traceCallTernaryMethodNode = CallTernaryMethodNode.create();
2244+
CompilerDirectives.transferToInterpreterAndInvalidate();
2245+
traceCallTernaryMethodNode = insert(CallTernaryMethodNode.create());
22422246
}
22432247
try {
22442248
if (line != -1) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public static final class PythonThreadState {
237237
PThreadState nativeWrapper;
238238

239239
/* Assume that no trace function was ever set. */
240-
public Assumption noTracingInThread = Assumption.create("noTracingInThread");
240+
public final Assumption noTracingInThread = Assumption.create("noTracingInThread");
241241

242242
/* The global tracing function, set by sys.settrace and returned by sys.gettrace. */
243243
Object traceFun;

0 commit comments

Comments
 (0)