Skip to content

Commit f34a8ec

Browse files
committed
Move returnCalled to MutableLoopData
1 parent 95c9c26 commit f34a8ec

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,14 @@ public int setReturnLine(int returnLine) {
10741074
return this.getTraceData().returnLine = returnLine;
10751075
}
10761076

1077+
public boolean isReturnCalled() {
1078+
return this.getTraceData().returnCalled;
1079+
}
1080+
1081+
public void setReturnCalled(boolean value) {
1082+
this.getTraceData().returnCalled = value;
1083+
}
1084+
10771085
public PFrame getPyFrame() {
10781086
return getTraceData().pyFrame;
10791087
}
@@ -1082,11 +1090,11 @@ public PFrame setPyFrame(PFrame pyFrame) {
10821090
return this.getTraceData().pyFrame = pyFrame;
10831091
}
10841092

1085-
private TraceData getTraceData() {
1086-
if (traceData == null) {
1087-
traceData = new TraceData();
1093+
private InstrumentationData getTraceData() {
1094+
if (instrumentationData == null) {
1095+
instrumentationData = new InstrumentationData();
10881096
}
1089-
return traceData;
1097+
return instrumentationData;
10901098
}
10911099

10921100
public PythonContext.PythonThreadState getThreadState(Node node) {
@@ -1097,10 +1105,10 @@ public PythonContext.PythonThreadState getThreadState(Node node) {
10971105
}
10981106

10991107
/*
1100-
* data for tracing
1108+
* Data for tracing, profiling and instrumentation
11011109
*/
1102-
private static final class TraceData {
1103-
TraceData() {
1110+
private static final class InstrumentationData {
1111+
InstrumentationData() {
11041112
pastBci = 0;
11051113
pastLine = returnLine = -1;
11061114
}
@@ -1109,11 +1117,12 @@ private static final class TraceData {
11091117
private int pastLine;
11101118
private int returnLine;
11111119
private PFrame pyFrame = null;
1120+
private boolean returnCalled;
11121121

11131122
private PythonContext.PythonThreadState threadState = null;
11141123
}
11151124

1116-
private TraceData traceData = null;
1125+
private InstrumentationData instrumentationData = null;
11171126

11181127
int loopCount;
11191128
/*
@@ -1175,7 +1184,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
11751184
final PythonLanguage language = PythonLanguage.get(this);
11761185
final Assumption noTraceOrProfile = language.noTracingOrProfilingAssumption;
11771186
final InstrumentationSupport instrumentation = instrumentationRoot.getInstrumentation();
1178-
boolean returnCalled = false;
11791187
if (instrumentation != null) {
11801188
Object result = enterRoot(virtualFrame);
11811189
if (result != null) {
@@ -1682,8 +1690,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
16821690
traceOrProfileReturn(virtualFrame, mutableData, value, tracingEnabled, profilingEnabled);
16831691

16841692
if (instrumentation != null && instrumentationRoot instanceof WrapperNode) {
1685-
returnCalled = true;
1686-
notifyRootReturn(virtualFrame, value);
1693+
notifyRootReturn(virtualFrame, mutableData, value);
16871694
}
16881695
if (isGeneratorOrCoroutine) {
16891696
throw new GeneratorReturnException(value);
@@ -2101,8 +2108,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
21012108
}
21022109
traceOrProfileYield(virtualFrame, mutableData, value, tracingEnabled, profilingEnabled);
21032110
if (instrumentation != null && instrumentationRoot instanceof WrapperNode) {
2104-
returnCalled = true;
2105-
notifyRootReturn(virtualFrame, value);
2111+
notifyRootReturn(virtualFrame, mutableData, value);
21062112
}
21072113
return new GeneratorYieldResult(bci + 1, stackTop, value);
21082114
}
@@ -2176,7 +2182,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
21762182
} catch (Throwable e) {
21772183
if (instrumentation != null) {
21782184
// Need to handle instrumentation frame unwind
2179-
Object result = notifyException(virtualFrame, instrumentation, returnCalled, bci, e);
2185+
Object result = notifyException(virtualFrame, instrumentation, mutableData, bci, e);
21802186
if (result == ProbeNode.UNWIND_ACTION_REENTER) {
21812187
copyArgs(virtualFrame.getArguments(), virtualFrame);
21822188
bci = 0;
@@ -2275,15 +2281,15 @@ private int handleException(VirtualFrame virtualFrame, Frame localFrame, boolean
22752281
}
22762282

22772283
@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) {
22792285
try {
22802286
instrumentation.notifyException(virtualFrame, bciToLine(bci), e);
22812287
} catch (Throwable t) {
22822288
e = t;
22832289
}
22842290
if (instrumentationRoot instanceof WrapperNode) {
22852291
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
2286-
Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, e, returnCalled);
2292+
Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, e, mutableData.isReturnCalled());
22872293
checkOnReturnExceptionalOrUnwindResult(result);
22882294
return result;
22892295
}
@@ -2300,7 +2306,8 @@ private void checkOnReturnExceptionalOrUnwindResult(Object result) {
23002306
}
23012307

23022308
@InliningCutoff
2303-
private void notifyRootReturn(VirtualFrame virtualFrame, Object value) {
2309+
private void notifyRootReturn(VirtualFrame virtualFrame, MutableLoopData mutableData, Object value) {
2310+
mutableData.setReturnCalled(true);
23042311
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
23052312
wrapper.getProbeNode().onReturnValue(virtualFrame, value);
23062313
}

0 commit comments

Comments
 (0)