@@ -2172,6 +2172,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2172
2172
// Need to handle instrumentation frame unwind
2173
2173
Object result = notifyException (virtualFrame , instrumentation , returnCalled , bci , e );
2174
2174
if (result == ProbeNode .UNWIND_ACTION_REENTER ) {
2175
+ copyArgs (virtualFrame .getArguments (), virtualFrame );
2175
2176
bci = 0 ;
2176
2177
stackTop = getInitialStackTop ();
2177
2178
oparg = 0 ;
@@ -2269,21 +2270,29 @@ private int handleException(VirtualFrame virtualFrame, Frame localFrame, boolean
2269
2270
2270
2271
@ InliningCutoff
2271
2272
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
+ }
2273
2278
if (instrumentationRoot instanceof WrapperNode ) {
2274
2279
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2275
2280
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 );
2282
2282
return result ;
2283
2283
}
2284
2284
return null ;
2285
2285
}
2286
2286
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
+
2287
2296
@ InliningCutoff
2288
2297
private void notifyRootReturn (VirtualFrame virtualFrame , Object value ) {
2289
2298
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
@@ -2307,13 +2316,12 @@ private Object enterRoot(VirtualFrame virtualFrame) {
2307
2316
wrapper .getProbeNode ().onEnter (virtualFrame );
2308
2317
} catch (Throwable t ) {
2309
2318
Object result = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , t , false );
2319
+ checkOnReturnExceptionalOrUnwindResult (result );
2310
2320
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 );
2312
2323
return null ;
2313
2324
} else if (result != null ) {
2314
- if (co .isGeneratorOrCoroutine ()) {
2315
- throw CompilerDirectives .shouldNotReachHere ("Cannot replace return value of generators" );
2316
- }
2317
2325
return result ;
2318
2326
}
2319
2327
}
0 commit comments