@@ -1011,13 +1011,60 @@ private InterpreterContinuation(int bci, int stackTop) {
1011
1011
1012
1012
@ ValueType
1013
1013
private static final class MutableLoopData {
1014
+ public int getPastBci () {
1015
+ return getTraceData ().pastBci ;
1016
+ }
1017
+
1018
+ public int setPastBci (int pastBci ) {
1019
+ return this .getTraceData ().pastBci = pastBci ;
1020
+ }
1021
+
1022
+ public int getPastLine () {
1023
+ return getTraceData ().pastLine ;
1024
+ }
1025
+
1026
+ public int setPastLine (int pastLine ) {
1027
+ return this .getTraceData ().pastLine = pastLine ;
1028
+ }
1029
+
1030
+ public int getReturnLine () {
1031
+ return getTraceData ().returnLine ;
1032
+ }
1033
+
1034
+ public int setReturnLine (int returnLine ) {
1035
+ return this .getTraceData ().returnLine = returnLine ;
1036
+ }
1037
+
1038
+ public PFrame getPyFrame () {
1039
+ return getTraceData ().pyFrame ;
1040
+ }
1041
+
1042
+ public PFrame setPyFrame (PFrame pyFrame ) {
1043
+ return this .getTraceData ().pyFrame = pyFrame ;
1044
+ }
1045
+
1046
+ private TraceData getTraceData () {
1047
+ if (traceData == null ) {
1048
+ traceData = new TraceData ();
1049
+ }
1050
+ return traceData ;
1051
+ }
1052
+
1014
1053
/*
1015
1054
* data for tracing
1016
1055
*/
1017
- int pastBci ;
1018
- int pastLine ;
1019
- int returnLine ;
1020
- PFrame pyFrame ;
1056
+ private static final class TraceData {
1057
+ TraceData () {
1058
+ pastBci = 0 ;
1059
+ pastLine = returnLine = -1 ;
1060
+ }
1061
+ private int pastBci ;
1062
+ private int pastLine ;
1063
+ private int returnLine ;
1064
+ private PFrame pyFrame = null ;
1065
+ }
1066
+
1067
+ private TraceData traceData = null ;
1021
1068
1022
1069
int loopCount ;
1023
1070
/*
@@ -1087,7 +1134,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1087
1134
MutableLoopData mutableData = new MutableLoopData ();
1088
1135
int stackTop = initialStackTop ;
1089
1136
int bci = initialBci ;
1090
- mutableData .pastLine = -1 ;
1091
1137
1092
1138
byte [] localBC = bytecode ;
1093
1139
Object [] localConsts = consts ;
@@ -1107,20 +1153,18 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1107
1153
// extra CALL event would be incorrect
1108
1154
if (!noTrace .isValid () && threadState .getTraceFun () != null && !fromOSR ) {
1109
1155
invokeTraceFunction (virtualFrame , null , threadState , mutableData , PythonContext .TraceEvent .CALL ,
1110
- initialBci == 0 ? getFirstLineno () : (mutableData .pastLine = bciToLine (initialBci )), false );
1156
+ initialBci == 0 ? getFirstLineno () : (mutableData .setPastLine ( bciToLine (initialBci ) )), false );
1111
1157
}
1112
1158
1113
- mutableData .returnLine = -1 ;
1114
-
1115
1159
int oparg = 0 ;
1116
1160
while (true ) {
1117
1161
final byte bc = localBC [bci ];
1118
1162
final int beginBci = bci ;
1119
1163
if (!noTrace .isValid () && threadState .getTraceFun () != null ) {
1120
1164
int thisLine = bciToLine (bci );
1121
- boolean onANewLine = thisLine != mutableData .pastLine ;
1122
- mutableData .pastLine = thisLine ;
1123
- OpCodes c = OpCodes .fromOpCode (localBC [mutableData .pastBci ]);
1165
+ boolean onANewLine = thisLine != mutableData .getPastLine () ;
1166
+ mutableData .setPastLine ( thisLine ) ;
1167
+ OpCodes c = OpCodes .fromOpCode (localBC [mutableData .getPastBci () ]);
1124
1168
/*
1125
1169
* normally, we trace a line every time the previous bytecode instruction was on a
1126
1170
* different line than the current one. There are a number of exceptions to this,
@@ -1138,23 +1182,23 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1138
1182
* https://github.com/python/cpython/blob/main/Objects/lnotab_notes.txt#L210-L215
1139
1183
* for more details
1140
1184
*/
1141
- boolean shouldTrace = mutableData .pastBci > bci ; // is a backward jump
1185
+ boolean shouldTrace = mutableData .getPastBci () > bci ; // is a backward jump
1142
1186
if (!shouldTrace ) {
1143
1187
shouldTrace = onANewLine &&
1144
1188
// is not a forward jump
1145
- (mutableData .pastBci + c .length () >= bci ||
1189
+ (mutableData .getPastBci () + c .length () >= bci ||
1146
1190
// is a forward jump to the start of line
1147
1191
bciToLine (bci - 1 ) != thisLine );
1148
1192
}
1149
1193
if (shouldTrace ) {
1150
- mutableData .returnLine = mutableData .pastLine ;
1151
- mutableData .pyFrame = ensurePyFrame (virtualFrame , mutableData .pyFrame );
1152
- if (mutableData .pyFrame .getTraceLine ()) {
1194
+ mutableData .setReturnLine ( mutableData .getPastLine ()) ;
1195
+ mutableData .setPyFrame ( ensurePyFrame (virtualFrame , mutableData .getPyFrame ()) );
1196
+ if (mutableData .getPyFrame () .getTraceLine ()) {
1153
1197
invokeTraceFunction (virtualFrame , null , threadState , mutableData , PythonContext .TraceEvent .LINE ,
1154
- mutableData .pastLine , true );
1198
+ mutableData .getPastLine () , true );
1155
1199
}
1156
1200
}
1157
- mutableData .pastBci = bci ;
1201
+ mutableData .setPastBci ( bci ) ;
1158
1202
}
1159
1203
1160
1204
CompilerAsserts .partialEvaluationConstant (bc );
@@ -1612,7 +1656,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1612
1656
Object value = virtualFrame .getObject (stackTop );
1613
1657
if (!noTrace .isValid () && threadState .getTraceFun () != null ) {
1614
1658
invokeTraceFunction (virtualFrame , value , threadState , mutableData , PythonContext .TraceEvent .RETURN ,
1615
- mutableData .returnLine , true );
1659
+ mutableData .getReturnLine () , true );
1616
1660
}
1617
1661
if (isGeneratorOrCoroutine ) {
1618
1662
throw new GeneratorReturnException (value );
@@ -2054,7 +2098,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2054
2098
}
2055
2099
if (!noTrace .isValid () && threadState .getTraceFun () != null ) {
2056
2100
invokeTraceFunction (virtualFrame , value , threadState , mutableData , PythonContext .TraceEvent .RETURN ,
2057
- mutableData .returnLine , true );
2101
+ mutableData .getReturnLine () , true );
2058
2102
}
2059
2103
return new GeneratorYieldResult (bci + 1 , stackTop , value );
2060
2104
}
@@ -2144,8 +2188,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2144
2188
}
2145
2189
2146
2190
if (!noTrace .isValid () && threadState .getTraceFun () != null && !threadState .isTracing () && pe != null ) {
2147
- mutableData .pyFrame = ensurePyFrame (virtualFrame , mutableData .pyFrame );
2148
- if (mutableData .pyFrame .getLocalTraceFun () != null ) {
2191
+ mutableData .setPyFrame ( ensurePyFrame (virtualFrame , mutableData .getPyFrame ()) );
2192
+ if (mutableData .getPyFrame () .getLocalTraceFun () != null ) {
2149
2193
Object traceback = GetExceptionTracebackNode .getUncached ().execute (pe );
2150
2194
PBaseException peForPython = pe .setCatchingFrameAndGetEscapedException (virtualFrame , this );
2151
2195
Object peType = GetClassNode .getUncached ().execute (peForPython );
@@ -2186,7 +2230,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2186
2230
}
2187
2231
if (!noTrace .isValid () && threadState .getTraceFun () != null ) {
2188
2232
invokeTraceFunction (virtualFrame , PNone .NONE , threadState , mutableData , PythonContext .TraceEvent .RETURN ,
2189
- mutableData .returnLine , true );
2233
+ mutableData .getReturnLine () , true );
2190
2234
}
2191
2235
if (e == pe ) {
2192
2236
throw pe ;
@@ -2230,7 +2274,7 @@ private void invokeTraceFunction(VirtualFrame virtualFrame, Object arg, PythonCo
2230
2274
return ;
2231
2275
}
2232
2276
threadState .tracingStart (event );
2233
- PFrame pyFrame = mutableData .pyFrame = ensurePyFrame (virtualFrame , mutableData .pyFrame );
2277
+ PFrame pyFrame = mutableData .setPyFrame ( ensurePyFrame (virtualFrame , mutableData .getPyFrame ()) );
2234
2278
Object traceFn = useLocalFn ? pyFrame .getLocalTraceFun () : threadState .getTraceFun ();
2235
2279
if (traceFn == null ) {
2236
2280
threadState .tracingStop ();
0 commit comments