@@ -1050,6 +1050,13 @@ private TraceData getTraceData() {
1050
1050
return traceData ;
1051
1051
}
1052
1052
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
+
1053
1060
/*
1054
1061
* data for tracing
1055
1062
*/
@@ -1063,6 +1070,8 @@ private static final class TraceData {
1063
1070
private int pastLine ;
1064
1071
private int returnLine ;
1065
1072
private PFrame pyFrame = null ;
1073
+
1074
+ private PythonContext .PythonThreadState threadState = null ;
1066
1075
}
1067
1076
1068
1077
private TraceData traceData = null ;
@@ -1126,7 +1135,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1126
1135
1127
1136
final PythonLanguage language = PythonLanguage .get (this );
1128
1137
final Assumption noTrace = language .noTracingAssumption ;
1129
- final PythonContext .PythonThreadState threadState = PythonContext .get (this ).getThreadState (language );
1130
1138
1131
1139
/*
1132
1140
* 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
1152
1160
1153
1161
// if we are simply continuing to run an OSR loop after the replacement, tracing an
1154
1162
// 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 ,
1157
1165
initialBci == 0 ? getFirstLineno () : (mutableData .setPastLine (bciToLine (initialBci ))), false );
1158
1166
}
1159
1167
1160
1168
int oparg = 0 ;
1161
1169
while (true ) {
1162
1170
final byte bc = localBC [bci ];
1163
1171
final int beginBci = bci ;
1164
- if (!noTrace .isValid () && threadState .getTraceFun () != null ) {
1172
+ if (!noTrace .isValid () && mutableData . getThreadState ( this ) .getTraceFun () != null ) {
1165
1173
int thisLine = bciToLine (bci );
1166
1174
boolean onANewLine = thisLine != mutableData .getPastLine ();
1167
1175
mutableData .setPastLine (thisLine );
@@ -1195,7 +1203,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1195
1203
mutableData .setReturnLine (mutableData .getPastLine ());
1196
1204
mutableData .setPyFrame (ensurePyFrame (virtualFrame , mutableData .getPyFrame ()));
1197
1205
if (mutableData .getPyFrame ().getTraceLine ()) {
1198
- invokeTraceFunction (virtualFrame , null , threadState , mutableData , PythonContext .TraceEvent .LINE ,
1206
+ invokeTraceFunction (virtualFrame , null , mutableData . getThreadState ( this ) , mutableData , PythonContext .TraceEvent .LINE ,
1199
1207
mutableData .getPastLine (), true );
1200
1208
}
1201
1209
}
@@ -1655,8 +1663,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1655
1663
LoopNode .reportLoopCount (this , mutableData .loopCount );
1656
1664
}
1657
1665
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 ,
1660
1668
mutableData .getReturnLine (), true );
1661
1669
}
1662
1670
if (isGeneratorOrCoroutine ) {
@@ -2097,8 +2105,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2097
2105
// Clear slots that were popped (if any)
2098
2106
clearFrameSlots (localFrame , stackTop + 1 , initialStackTop );
2099
2107
}
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 ,
2102
2110
mutableData .getReturnLine (), true );
2103
2111
}
2104
2112
return new GeneratorYieldResult (bci + 1 , stackTop , value );
@@ -2188,14 +2196,14 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2188
2196
}
2189
2197
}
2190
2198
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 ) {
2192
2200
mutableData .setPyFrame (ensurePyFrame (virtualFrame , mutableData .getPyFrame ()));
2193
2201
if (mutableData .getPyFrame ().getLocalTraceFun () != null ) {
2194
2202
Object traceback = GetExceptionTracebackNode .getUncached ().execute (pe );
2195
2203
PBaseException peForPython = pe .setCatchingFrameAndGetEscapedException (virtualFrame , this );
2196
2204
Object peType = GetClassNode .getUncached ().execute (peForPython );
2197
2205
invokeTraceFunction (virtualFrame ,
2198
- factory .createTuple (new Object []{peType , peForPython , traceback }), threadState ,
2206
+ factory .createTuple (new Object []{peType , peForPython , traceback }), mutableData . getThreadState ( this ) ,
2199
2207
mutableData ,
2200
2208
PythonContext .TraceEvent .EXCEPTION , bciToLine (bci ), true );
2201
2209
}
@@ -2229,8 +2237,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2229
2237
if (CompilerDirectives .hasNextTier () && mutableData .loopCount > 0 ) {
2230
2238
LoopNode .reportLoopCount (this , mutableData .loopCount );
2231
2239
}
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 ,
2234
2242
mutableData .getReturnLine (), true );
2235
2243
}
2236
2244
if (e == pe ) {
0 commit comments