Skip to content

Commit f25f7b3

Browse files
committed
Fix reenter after refactoring
1 parent 26adad9 commit f25f7b3

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
21722172
// Need to handle instrumentation frame unwind
21732173
Object result = notifyException(virtualFrame, instrumentation, returnCalled, bci, e);
21742174
if (result == ProbeNode.UNWIND_ACTION_REENTER) {
2175+
copyArgs(virtualFrame.getArguments(), virtualFrame);
21752176
bci = 0;
21762177
stackTop = getInitialStackTop();
21772178
oparg = 0;
@@ -2269,21 +2270,29 @@ private int handleException(VirtualFrame virtualFrame, Frame localFrame, boolean
22692270

22702271
@InliningCutoff
22712272
private Object notifyException(VirtualFrame virtualFrame, InstrumentationSupport instrumentation, boolean returnCalled, int bci, Throwable e) {
2272-
instrumentation.notifyException(virtualFrame, bciToLine(bci), e);
2273+
try {
2274+
instrumentation.notifyException(virtualFrame, bciToLine(bci), e);
2275+
} catch (Throwable t) {
2276+
e = t;
2277+
}
22732278
if (instrumentationRoot instanceof WrapperNode) {
22742279
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
22752280
Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, e, returnCalled);
2276-
if (result != null) {
2277-
if (co.isGeneratorOrCoroutine()) {
2278-
CompilerDirectives.transferToInterpreterAndInvalidate();
2279-
throw new IllegalStateException(result == ProbeNode.UNWIND_ACTION_REENTER ? "Frame restarting is not possible in generators" : "Cannot replace return value of generators");
2280-
}
2281-
}
2281+
checkOnReturnExceptionalOrUnwindResult(result);
22822282
return result;
22832283
}
22842284
return null;
22852285
}
22862286

2287+
private void checkOnReturnExceptionalOrUnwindResult(Object result) {
2288+
if (result != null) {
2289+
if (co.isGeneratorOrCoroutine()) {
2290+
CompilerDirectives.transferToInterpreterAndInvalidate();
2291+
throw new IllegalStateException(result == ProbeNode.UNWIND_ACTION_REENTER ? "Frame restarting is not possible in generators" : "Cannot replace return value of generators");
2292+
}
2293+
}
2294+
}
2295+
22872296
@InliningCutoff
22882297
private void notifyRootReturn(VirtualFrame virtualFrame, Object value) {
22892298
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
@@ -2307,13 +2316,12 @@ private Object enterRoot(VirtualFrame virtualFrame) {
23072316
wrapper.getProbeNode().onEnter(virtualFrame);
23082317
} catch (Throwable t) {
23092318
Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, t, false);
2319+
checkOnReturnExceptionalOrUnwindResult(result);
23102320
if (result == ProbeNode.UNWIND_ACTION_REENTER) {
2311-
// We're at the beginning, reenter means just continue
2321+
// We're at the beginning, reenter means just restore args and continue
2322+
copyArgs(virtualFrame.getArguments(), virtualFrame);
23122323
return null;
23132324
} else if (result != null) {
2314-
if (co.isGeneratorOrCoroutine()) {
2315-
throw CompilerDirectives.shouldNotReachHere("Cannot replace return value of generators");
2316-
}
23172325
return result;
23182326
}
23192327
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private static void handleException(VirtualFrame frame, InstrumentableNode.Wrapp
134134
public void notifyException(VirtualFrame frame, int line, Throwable exception) {
135135
InstrumentableNode.WrapperNode wrapper = getWrapperAtLine(line);
136136
if (wrapper != null) {
137-
wrapper.getProbeNode().onReturnExceptionalOrUnwind(frame, exception, false);
137+
handleException(frame, wrapper, exception, false);
138138
}
139139
}
140140

0 commit comments

Comments
 (0)