@@ -116,7 +116,10 @@ _PyOptimizer_Optimize(
116116 _PyExecutorObject * * executor_ptr , int chain_depth )
117117{
118118 _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;
120123 // The first executor in a chain and the MAX_CHAIN_DEPTH'th executor *must*
121124 // make progress in order to avoid infinite loops or excessively-long
122125 // side-exit chains. We can only insert the executor into the bytecode if
@@ -126,10 +129,12 @@ _PyOptimizer_Optimize(
126129 PyCodeObject * code = _PyFrame_GetCode (frame );
127130 assert (PyCode_Check (code ));
128131 if (progress_needed && !has_space_for_executor (code , start )) {
132+ interp -> compiling = false;
129133 return 0 ;
130134 }
131135 int err = uop_optimize (frame , start , executor_ptr , (int )(stack_pointer - _PyFrame_Stackbase (frame )), progress_needed );
132136 if (err <= 0 ) {
137+ interp -> compiling = false;
133138 return err ;
134139 }
135140 assert (* executor_ptr != NULL );
@@ -143,6 +148,7 @@ _PyOptimizer_Optimize(
143148 * it might get confused by the executor disappearing,
144149 * but there is not much we can do about that here. */
145150 Py_DECREF (* executor_ptr );
151+ interp -> compiling = false;
146152 return 0 ;
147153 }
148154 insert_executor (code , start , index , * executor_ptr );
@@ -152,6 +158,7 @@ _PyOptimizer_Optimize(
152158 }
153159 (* executor_ptr )-> vm_data .chain_depth = chain_depth ;
154160 assert ((* executor_ptr )-> vm_data .valid );
161+ interp -> compiling = false;
155162 return 1 ;
156163}
157164
@@ -1280,7 +1287,14 @@ uop_optimize(
12801287{
12811288 _PyBloomFilter dependencies ;
12821289 _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 ;
12841298 OPT_STAT_INC (attempts );
12851299 char * env_var = Py_GETENV ("PYTHON_UOPS_OPTIMIZE" );
12861300 bool is_noopt = true;
0 commit comments