@@ -116,7 +116,10 @@ _PyOptimizer_Optimize(
116
116
_PyExecutorObject * * executor_ptr , int chain_depth )
117
117
{
118
118
_PyStackRef * stack_pointer = frame -> stackpointer ;
119
- assert (_PyInterpreterState_GET ()-> jit );
119
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
120
+ assert (interp -> jit );
121
+ assert (!interp -> compiling );
122
+ interp -> compiling = true;
120
123
// The first executor in a chain and the MAX_CHAIN_DEPTH'th executor *must*
121
124
// make progress in order to avoid infinite loops or excessively-long
122
125
// side-exit chains. We can only insert the executor into the bytecode if
@@ -126,10 +129,12 @@ _PyOptimizer_Optimize(
126
129
PyCodeObject * code = _PyFrame_GetCode (frame );
127
130
assert (PyCode_Check (code ));
128
131
if (progress_needed && !has_space_for_executor (code , start )) {
132
+ interp -> compiling = false;
129
133
return 0 ;
130
134
}
131
135
int err = uop_optimize (frame , start , executor_ptr , (int )(stack_pointer - _PyFrame_Stackbase (frame )), progress_needed );
132
136
if (err <= 0 ) {
137
+ interp -> compiling = false;
133
138
return err ;
134
139
}
135
140
assert (* executor_ptr != NULL );
@@ -143,6 +148,7 @@ _PyOptimizer_Optimize(
143
148
* it might get confused by the executor disappearing,
144
149
* but there is not much we can do about that here. */
145
150
Py_DECREF (* executor_ptr );
151
+ interp -> compiling = false;
146
152
return 0 ;
147
153
}
148
154
insert_executor (code , start , index , * executor_ptr );
@@ -152,6 +158,7 @@ _PyOptimizer_Optimize(
152
158
}
153
159
(* executor_ptr )-> vm_data .chain_depth = chain_depth ;
154
160
assert ((* executor_ptr )-> vm_data .valid );
161
+ interp -> compiling = false;
155
162
return 1 ;
156
163
}
157
164
@@ -1280,7 +1287,14 @@ uop_optimize(
1280
1287
{
1281
1288
_PyBloomFilter dependencies ;
1282
1289
_Py_BloomFilter_Init (& dependencies );
1283
- _PyUOpInstruction buffer [UOP_MAX_TRACE_LENGTH ];
1290
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
1291
+ if (interp -> jit_uop_buffer == NULL ) {
1292
+ interp -> jit_uop_buffer = (_PyUOpInstruction * )_PyObject_VirtualAlloc (UOP_BUFFER_SIZE );
1293
+ if (interp -> jit_uop_buffer == NULL ) {
1294
+ return 0 ;
1295
+ }
1296
+ }
1297
+ _PyUOpInstruction * buffer = interp -> jit_uop_buffer ;
1284
1298
OPT_STAT_INC (attempts );
1285
1299
char * env_var = Py_GETENV ("PYTHON_UOPS_OPTIMIZE" );
1286
1300
bool is_noopt = true;
0 commit comments