@@ -1074,6 +1074,14 @@ public int setReturnLine(int returnLine) {
1074
1074
return this .getTraceData ().returnLine = returnLine ;
1075
1075
}
1076
1076
1077
+ public boolean isReturnCalled () {
1078
+ return this .getTraceData ().returnCalled ;
1079
+ }
1080
+
1081
+ public void setReturnCalled (boolean value ) {
1082
+ this .getTraceData ().returnCalled = value ;
1083
+ }
1084
+
1077
1085
public PFrame getPyFrame () {
1078
1086
return getTraceData ().pyFrame ;
1079
1087
}
@@ -1082,11 +1090,11 @@ public PFrame setPyFrame(PFrame pyFrame) {
1082
1090
return this .getTraceData ().pyFrame = pyFrame ;
1083
1091
}
1084
1092
1085
- private TraceData getTraceData () {
1086
- if (traceData == null ) {
1087
- traceData = new TraceData ();
1093
+ private InstrumentationData getTraceData () {
1094
+ if (instrumentationData == null ) {
1095
+ instrumentationData = new InstrumentationData ();
1088
1096
}
1089
- return traceData ;
1097
+ return instrumentationData ;
1090
1098
}
1091
1099
1092
1100
public PythonContext .PythonThreadState getThreadState (Node node ) {
@@ -1097,10 +1105,10 @@ public PythonContext.PythonThreadState getThreadState(Node node) {
1097
1105
}
1098
1106
1099
1107
/*
1100
- * data for tracing
1108
+ * Data for tracing, profiling and instrumentation
1101
1109
*/
1102
- private static final class TraceData {
1103
- TraceData () {
1110
+ private static final class InstrumentationData {
1111
+ InstrumentationData () {
1104
1112
pastBci = 0 ;
1105
1113
pastLine = returnLine = -1 ;
1106
1114
}
@@ -1109,11 +1117,12 @@ private static final class TraceData {
1109
1117
private int pastLine ;
1110
1118
private int returnLine ;
1111
1119
private PFrame pyFrame = null ;
1120
+ private boolean returnCalled ;
1112
1121
1113
1122
private PythonContext .PythonThreadState threadState = null ;
1114
1123
}
1115
1124
1116
- private TraceData traceData = null ;
1125
+ private InstrumentationData instrumentationData = null ;
1117
1126
1118
1127
int loopCount ;
1119
1128
/*
@@ -1175,7 +1184,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1175
1184
final PythonLanguage language = PythonLanguage .get (this );
1176
1185
final Assumption noTraceOrProfile = language .noTracingOrProfilingAssumption ;
1177
1186
final InstrumentationSupport instrumentation = instrumentationRoot .getInstrumentation ();
1178
- boolean returnCalled = false ;
1179
1187
if (instrumentation != null ) {
1180
1188
Object result = enterRoot (virtualFrame );
1181
1189
if (result != null ) {
@@ -1682,8 +1690,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1682
1690
traceOrProfileReturn (virtualFrame , mutableData , value , tracingEnabled , profilingEnabled );
1683
1691
1684
1692
if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
1685
- returnCalled = true ;
1686
- notifyRootReturn (virtualFrame , value );
1693
+ notifyRootReturn (virtualFrame , mutableData , value );
1687
1694
}
1688
1695
if (isGeneratorOrCoroutine ) {
1689
1696
throw new GeneratorReturnException (value );
@@ -2101,8 +2108,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2101
2108
}
2102
2109
traceOrProfileYield (virtualFrame , mutableData , value , tracingEnabled , profilingEnabled );
2103
2110
if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
2104
- returnCalled = true ;
2105
- notifyRootReturn (virtualFrame , value );
2111
+ notifyRootReturn (virtualFrame , mutableData , value );
2106
2112
}
2107
2113
return new GeneratorYieldResult (bci + 1 , stackTop , value );
2108
2114
}
@@ -2176,7 +2182,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2176
2182
} catch (Throwable e ) {
2177
2183
if (instrumentation != null ) {
2178
2184
// Need to handle instrumentation frame unwind
2179
- Object result = notifyException (virtualFrame , instrumentation , returnCalled , bci , e );
2185
+ Object result = notifyException (virtualFrame , instrumentation , mutableData , bci , e );
2180
2186
if (result == ProbeNode .UNWIND_ACTION_REENTER ) {
2181
2187
copyArgs (virtualFrame .getArguments (), virtualFrame );
2182
2188
bci = 0 ;
@@ -2275,15 +2281,15 @@ private int handleException(VirtualFrame virtualFrame, Frame localFrame, boolean
2275
2281
}
2276
2282
2277
2283
@ InliningCutoff
2278
- private Object notifyException (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , boolean returnCalled , int bci , Throwable e ) {
2284
+ private Object notifyException (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , MutableLoopData mutableData , int bci , Throwable e ) {
2279
2285
try {
2280
2286
instrumentation .notifyException (virtualFrame , bciToLine (bci ), e );
2281
2287
} catch (Throwable t ) {
2282
2288
e = t ;
2283
2289
}
2284
2290
if (instrumentationRoot instanceof WrapperNode ) {
2285
2291
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2286
- Object result = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , e , returnCalled );
2292
+ Object result = wrapper .getProbeNode ().onReturnExceptionalOrUnwind (virtualFrame , e , mutableData . isReturnCalled () );
2287
2293
checkOnReturnExceptionalOrUnwindResult (result );
2288
2294
return result ;
2289
2295
}
@@ -2300,7 +2306,8 @@ private void checkOnReturnExceptionalOrUnwindResult(Object result) {
2300
2306
}
2301
2307
2302
2308
@ InliningCutoff
2303
- private void notifyRootReturn (VirtualFrame virtualFrame , Object value ) {
2309
+ private void notifyRootReturn (VirtualFrame virtualFrame , MutableLoopData mutableData , Object value ) {
2310
+ mutableData .setReturnCalled (true );
2304
2311
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2305
2312
wrapper .getProbeNode ().onReturnValue (virtualFrame , value );
2306
2313
}
0 commit comments