@@ -1224,11 +1224,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1224
1224
1225
1225
try {
1226
1226
if (instrumentation != null ) {
1227
- int line = bciToLine (bci );
1228
- int pastLine = mutableData .getPastLine ();
1229
- instrumentation .notifyStatement (virtualFrame , pastLine , line );
1230
- mutableData .setPastLine (line );
1231
- mutableData .setPastBci (bci );
1227
+ notifyStatement (virtualFrame , instrumentation , mutableData , bci );
1232
1228
}
1233
1229
1234
1230
switch (bc ) {
@@ -1681,8 +1677,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1681
1677
1682
1678
if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
1683
1679
returnCalled = true ;
1684
- WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
1685
- wrapper .getProbeNode ().onReturnValue (virtualFrame , value );
1680
+ notifyRootReturn (virtualFrame , value );
1686
1681
}
1687
1682
if (isGeneratorOrCoroutine ) {
1688
1683
throw new GeneratorReturnException (value );
@@ -2101,8 +2096,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2101
2096
traceOrProfileYield (virtualFrame , mutableData , value , tracingEnabled , profilingEnabled );
2102
2097
if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
2103
2098
returnCalled = true ;
2104
- WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2105
- wrapper .getProbeNode ().onReturnValue (virtualFrame , value );
2099
+ notifyRootReturn (virtualFrame , value );
2106
2100
}
2107
2101
return new GeneratorYieldResult (bci + 1 , stackTop , value );
2108
2102
}
@@ -2192,19 +2186,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2192
2186
traceException (virtualFrame , mutableData , bci , pe );
2193
2187
}
2194
2188
if (instrumentation != null ) {
2195
- instrumentation .notifyException (virtualFrame , bciToLine (beginBci ), e );
2196
- if (instrumentationRoot instanceof WrapperNode ) {
2197
- returnCalled = true ;
2198
- WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2199
- Object result = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , e , false );
2200
- if (result == ProbeNode .UNWIND_ACTION_REENTER ) {
2201
- throw CompilerDirectives .shouldNotReachHere ("Reenter shouldn't occur at this point" );
2202
- } else if (result != null ) {
2203
- if (isGeneratorOrCoroutine ) {
2204
- throw CompilerDirectives .shouldNotReachHere ("Cannot replace return value of generators" );
2205
- }
2206
- return result ;
2207
- }
2189
+ Object result = notifyException (virtualFrame , instrumentation , returnCalled , beginBci , e );
2190
+ if (result != null ) {
2191
+ return result ;
2208
2192
}
2209
2193
}
2210
2194
@@ -2226,30 +2210,72 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2226
2210
bci = exceptionHandlerRanges [targetIndex ];
2227
2211
oparg = 0 ;
2228
2212
}
2229
- } catch (ThreadDeath e ) {
2213
+ } catch (ThreadDeath t ) {
2230
2214
// Need to handle instrumentation frame unwind
2231
- if (instrumentationRoot instanceof WrapperNode ) {
2232
- WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2233
- Object ret = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , e , returnCalled );
2234
- if (ret == ProbeNode .UNWIND_ACTION_REENTER ) {
2235
- if (isGeneratorOrCoroutine ) {
2236
- CompilerDirectives .transferToInterpreterAndInvalidate ();
2237
- throw new UnsupportedOperationException ("Frame restarting is not possible in generators" );
2238
- }
2239
- copyArgs (virtualFrame .getArguments (), localFrame );
2240
- bci = 0 ;
2241
- stackTop = getInitialStackTop ();
2242
- oparg = 0 ;
2243
- continue ;
2244
- } else if (ret != null ) {
2245
- return ret ;
2246
- }
2215
+ Object result = handlePossibleReenter (virtualFrame , t , returnCalled );
2216
+ if (result == ProbeNode .UNWIND_ACTION_REENTER ) {
2217
+ bci = 0 ;
2218
+ stackTop = getInitialStackTop ();
2219
+ oparg = 0 ;
2220
+ continue ;
2221
+ } else if (result != null ) {
2222
+ return result ;
2247
2223
}
2248
- throw e ;
2224
+ throw t ;
2249
2225
}
2250
2226
}
2251
2227
}
2252
2228
2229
+ @ InliningCutoff
2230
+ private Object notifyException (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , boolean returnCalled , int bci , Throwable e ) {
2231
+ instrumentation .notifyException (virtualFrame , bciToLine (bci ), e );
2232
+ if (instrumentationRoot instanceof WrapperNode ) {
2233
+ WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2234
+ Object result = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , e , returnCalled );
2235
+ if (result == ProbeNode .UNWIND_ACTION_REENTER ) {
2236
+ throw CompilerDirectives .shouldNotReachHere ("Reenter shouldn't occur at this point" );
2237
+ } else if (result != null ) {
2238
+ if (co .isGeneratorOrCoroutine ()) {
2239
+ throw CompilerDirectives .shouldNotReachHere ("Cannot replace return value of generators" );
2240
+ }
2241
+ }
2242
+ return result ;
2243
+ }
2244
+ return null ;
2245
+ }
2246
+
2247
+ @ InliningCutoff
2248
+ private void notifyRootReturn (VirtualFrame virtualFrame , Object value ) {
2249
+ WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2250
+ wrapper .getProbeNode ().onReturnValue (virtualFrame , value );
2251
+ }
2252
+
2253
+ @ InliningCutoff
2254
+ private void notifyStatement (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , MutableLoopData mutableData , int bci ) {
2255
+ int line = bciToLine (bci );
2256
+ int pastLine = mutableData .getPastLine ();
2257
+ instrumentation .notifyStatement (virtualFrame , pastLine , line );
2258
+ mutableData .setPastLine (line );
2259
+ mutableData .setPastBci (bci );
2260
+ }
2261
+
2262
+ @ InliningCutoff
2263
+ private Object handlePossibleReenter (VirtualFrame virtualFrame , ThreadDeath t , boolean returnCalled ) {
2264
+ if (instrumentationRoot instanceof WrapperNode ) {
2265
+ WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2266
+ Object result = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , t , returnCalled );
2267
+ if (result == ProbeNode .UNWIND_ACTION_REENTER ) {
2268
+ if (co .isGeneratorOrCoroutine ()) {
2269
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
2270
+ throw new UnsupportedOperationException ("Frame restarting is not possible in generators" );
2271
+ }
2272
+ copyArgs (virtualFrame .getArguments (), virtualFrame );
2273
+ }
2274
+ return result ;
2275
+ }
2276
+ return null ;
2277
+ }
2278
+
2253
2279
@ InliningCutoff
2254
2280
private Object enterRoot (VirtualFrame virtualFrame ) {
2255
2281
if (instrumentationRoot instanceof WrapperNode ) {
0 commit comments