Skip to content

Commit 032f315

Browse files
author
Adam Hrbac
committed
Attempt to limit performance degradation further
1 parent dc5fbf6 commit 032f315

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,13 @@ private TraceData getTraceData() {
10501050
return traceData;
10511051
}
10521052

1053+
public PythonContext.PythonThreadState getThreadState(Node node) {
1054+
if (this.getTraceData().threadState == null) {
1055+
return this.getTraceData().threadState = PythonContext.get(node).getThreadState(PythonLanguage.get(node));
1056+
}
1057+
return this.getTraceData().threadState;
1058+
}
1059+
10531060
/*
10541061
* data for tracing
10551062
*/
@@ -1063,6 +1070,8 @@ private static final class TraceData {
10631070
private int pastLine;
10641071
private int returnLine;
10651072
private PFrame pyFrame = null;
1073+
1074+
private PythonContext.PythonThreadState threadState = null;
10661075
}
10671076

10681077
private TraceData traceData = null;
@@ -1126,7 +1135,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
11261135

11271136
final PythonLanguage language = PythonLanguage.get(this);
11281137
final Assumption noTrace = language.noTracingAssumption;
1129-
final PythonContext.PythonThreadState threadState = PythonContext.get(this).getThreadState(language);
11301138

11311139
/*
11321140
* We use an object as a workaround for not being able to specify which local variables are
@@ -1152,16 +1160,16 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
11521160

11531161
// if we are simply continuing to run an OSR loop after the replacement, tracing an
11541162
// extra CALL event would be incorrect
1155-
if (!noTrace.isValid() && threadState.getTraceFun() != null && !fromOSR) {
1156-
invokeTraceFunction(virtualFrame, null, threadState, mutableData, PythonContext.TraceEvent.CALL,
1163+
if (!noTrace.isValid() && mutableData.getThreadState(this).getTraceFun() != null && !fromOSR) {
1164+
invokeTraceFunction(virtualFrame, null, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.CALL,
11571165
initialBci == 0 ? getFirstLineno() : (mutableData.setPastLine(bciToLine(initialBci))), false);
11581166
}
11591167

11601168
int oparg = 0;
11611169
while (true) {
11621170
final byte bc = localBC[bci];
11631171
final int beginBci = bci;
1164-
if (!noTrace.isValid() && threadState.getTraceFun() != null) {
1172+
if (!noTrace.isValid() && mutableData.getThreadState(this).getTraceFun() != null) {
11651173
int thisLine = bciToLine(bci);
11661174
boolean onANewLine = thisLine != mutableData.getPastLine();
11671175
mutableData.setPastLine(thisLine);
@@ -1195,7 +1203,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
11951203
mutableData.setReturnLine(mutableData.getPastLine());
11961204
mutableData.setPyFrame(ensurePyFrame(virtualFrame, mutableData.getPyFrame()));
11971205
if (mutableData.getPyFrame().getTraceLine()) {
1198-
invokeTraceFunction(virtualFrame, null, threadState, mutableData, PythonContext.TraceEvent.LINE,
1206+
invokeTraceFunction(virtualFrame, null, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.LINE,
11991207
mutableData.getPastLine(), true);
12001208
}
12011209
}
@@ -1655,8 +1663,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
16551663
LoopNode.reportLoopCount(this, mutableData.loopCount);
16561664
}
16571665
Object value = virtualFrame.getObject(stackTop);
1658-
if (!noTrace.isValid() && threadState.getTraceFun() != null) {
1659-
invokeTraceFunction(virtualFrame, value, threadState, mutableData, PythonContext.TraceEvent.RETURN,
1666+
if (!noTrace.isValid() && mutableData.getThreadState(this).getTraceFun() != null) {
1667+
invokeTraceFunction(virtualFrame, value, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.RETURN,
16601668
mutableData.getReturnLine(), true);
16611669
}
16621670
if (isGeneratorOrCoroutine) {
@@ -2097,8 +2105,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
20972105
// Clear slots that were popped (if any)
20982106
clearFrameSlots(localFrame, stackTop + 1, initialStackTop);
20992107
}
2100-
if (!noTrace.isValid() && threadState.getTraceFun() != null) {
2101-
invokeTraceFunction(virtualFrame, value, threadState, mutableData, PythonContext.TraceEvent.RETURN,
2108+
if (!noTrace.isValid() && mutableData.getThreadState(this).getTraceFun() != null) {
2109+
invokeTraceFunction(virtualFrame, value, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.RETURN,
21022110
mutableData.getReturnLine(), true);
21032111
}
21042112
return new GeneratorYieldResult(bci + 1, stackTop, value);
@@ -2188,14 +2196,14 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
21882196
}
21892197
}
21902198

2191-
if (!noTrace.isValid() && threadState.getTraceFun() != null && !threadState.isTracing() && pe != null) {
2199+
if (!noTrace.isValid() && mutableData.getThreadState(this).getTraceFun() != null && !mutableData.getThreadState(this).isTracing() && pe != null) {
21922200
mutableData.setPyFrame(ensurePyFrame(virtualFrame, mutableData.getPyFrame()));
21932201
if (mutableData.getPyFrame().getLocalTraceFun() != null) {
21942202
Object traceback = GetExceptionTracebackNode.getUncached().execute(pe);
21952203
PBaseException peForPython = pe.setCatchingFrameAndGetEscapedException(virtualFrame, this);
21962204
Object peType = GetClassNode.getUncached().execute(peForPython);
21972205
invokeTraceFunction(virtualFrame,
2198-
factory.createTuple(new Object[]{peType, peForPython, traceback}), threadState,
2206+
factory.createTuple(new Object[]{peType, peForPython, traceback}), mutableData.getThreadState(this),
21992207
mutableData,
22002208
PythonContext.TraceEvent.EXCEPTION, bciToLine(bci), true);
22012209
}
@@ -2229,8 +2237,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
22292237
if (CompilerDirectives.hasNextTier() && mutableData.loopCount > 0) {
22302238
LoopNode.reportLoopCount(this, mutableData.loopCount);
22312239
}
2232-
if (!noTrace.isValid() && threadState.getTraceFun() != null) {
2233-
invokeTraceFunction(virtualFrame, PNone.NONE, threadState, mutableData, PythonContext.TraceEvent.RETURN,
2240+
if (!noTrace.isValid() && mutableData.getThreadState(this).getTraceFun() != null) {
2241+
invokeTraceFunction(virtualFrame, PNone.NONE, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.RETURN,
22342242
mutableData.getReturnLine(), true);
22352243
}
22362244
if (e == pe) {

0 commit comments

Comments
 (0)