@@ -1169,9 +1169,12 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1169
1169
final PythonLanguage language = PythonLanguage .get (this );
1170
1170
final Assumption noTraceOrProfile = language .noTracingOrProfilingAssumption ;
1171
1171
final InstrumentationSupport instrumentation = instrumentationRoot .getInstrumentation ();
1172
- if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
1173
- WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
1174
- wrapper .getProbeNode ().onEnter (virtualFrame );
1172
+ boolean returnCalled = false ;
1173
+ if (instrumentation != null ) {
1174
+ Object result = enterRoot (virtualFrame );
1175
+ if (result != null ) {
1176
+ return result ;
1177
+ }
1175
1178
}
1176
1179
1177
1180
/*
@@ -1214,19 +1217,20 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1214
1217
traceLine (virtualFrame , mutableData , localBC , bci );
1215
1218
}
1216
1219
profilingEnabled = isProfilingEnabled (noTraceOrProfile , mutableData );
1217
- if (instrumentation != null ) {
1218
- int line = bciToLine (bci );
1219
- int pastLine = mutableData .getPastLine ();
1220
- instrumentation .notifyStatement (virtualFrame , pastLine , line );
1221
- mutableData .setPastLine (line );
1222
- mutableData .setPastBci (bci );
1223
- }
1224
1220
1225
1221
CompilerAsserts .partialEvaluationConstant (bc );
1226
1222
CompilerAsserts .partialEvaluationConstant (bci );
1227
1223
CompilerAsserts .partialEvaluationConstant (stackTop );
1228
1224
1229
1225
try {
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 );
1232
+ }
1233
+
1230
1234
switch (bc ) {
1231
1235
case OpCodesConstants .LOAD_NONE :
1232
1236
virtualFrame .setObject (++stackTop , PNone .NONE );
@@ -1676,6 +1680,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1676
1680
traceOrProfileReturn (virtualFrame , mutableData , value , tracingEnabled , profilingEnabled );
1677
1681
1678
1682
if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
1683
+ returnCalled = true ;
1679
1684
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
1680
1685
wrapper .getProbeNode ().onReturnValue (virtualFrame , value );
1681
1686
}
@@ -2095,6 +2100,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2095
2100
}
2096
2101
traceOrProfileYield (virtualFrame , mutableData , value , tracingEnabled , profilingEnabled );
2097
2102
if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
2103
+ returnCalled = true ;
2098
2104
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2099
2105
wrapper .getProbeNode ().onReturnValue (virtualFrame , value );
2100
2106
}
@@ -2188,8 +2194,17 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2188
2194
if (instrumentation != null ) {
2189
2195
instrumentation .notifyException (virtualFrame , bciToLine (beginBci ), e );
2190
2196
if (instrumentationRoot instanceof WrapperNode ) {
2197
+ returnCalled = true ;
2191
2198
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2192
- wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , e , false );
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
+ }
2193
2208
}
2194
2209
}
2195
2210
@@ -2215,7 +2230,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2215
2230
// Need to handle instrumentation frame unwind
2216
2231
if (instrumentationRoot instanceof WrapperNode ) {
2217
2232
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2218
- Object ret = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , e , false );
2233
+ Object ret = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , e , returnCalled );
2219
2234
if (ret == ProbeNode .UNWIND_ACTION_REENTER ) {
2220
2235
if (isGeneratorOrCoroutine ) {
2221
2236
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -2226,13 +2241,37 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2226
2241
stackTop = getInitialStackTop ();
2227
2242
oparg = 0 ;
2228
2243
continue ;
2244
+ } else if (ret != null ) {
2245
+ return ret ;
2229
2246
}
2230
2247
}
2231
2248
throw e ;
2232
2249
}
2233
2250
}
2234
2251
}
2235
2252
2253
+ @ InliningCutoff
2254
+ private Object enterRoot (VirtualFrame virtualFrame ) {
2255
+ if (instrumentationRoot instanceof WrapperNode ) {
2256
+ WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2257
+ try {
2258
+ wrapper .getProbeNode ().onEnter (virtualFrame );
2259
+ } catch (Throwable t ) {
2260
+ Object result = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , t , false );
2261
+ if (result == ProbeNode .UNWIND_ACTION_REENTER ) {
2262
+ // We're at the beginning, reenter means just continue
2263
+ return null ;
2264
+ } else if (result != null ) {
2265
+ if (co .isGeneratorOrCoroutine ()) {
2266
+ throw CompilerDirectives .shouldNotReachHere ("Cannot replace return value of generators" );
2267
+ }
2268
+ return result ;
2269
+ }
2270
+ }
2271
+ }
2272
+ return null ;
2273
+ }
2274
+
2236
2275
private MakeFunctionNode insertMakeFunctionNode (Node [] localNodes , int beginBci , CodeUnit codeUnit ) {
2237
2276
return insertChildNode (localNodes , beginBci , MakeFunctionNodeGen .class , () -> MakeFunctionNode .create (getLanguage (PythonLanguage .class ), codeUnit , source ));
2238
2277
}
0 commit comments