@@ -147,6 +147,11 @@ _PyOptimizer_Optimize(
147147 interp -> compiling = false;
148148 return 0 ;
149149 }
150+ // One of our depencies while tracing was invalidated. Not worth compiling.
151+ if (!tstate -> interp -> jit_tracer_dependencies_still_valid ) {
152+ interp -> compiling = false;
153+ return 0 ;
154+ }
150155 _PyExecutorObject * executor ;
151156 int err = uop_optimize (frame , tstate , & executor , progress_needed );
152157 if (err <= 0 ) {
@@ -560,9 +565,6 @@ _PyJIT_translate_single_bytecode_to_trace(
560565 int oparg ,
561566 int jump_taken )
562567{
563- if (PyStackRef_IsNull (frame -> f_funcobj )) {
564- goto unsupported ;
565- }
566568
567569 int is_first_instr = tstate -> interp -> jit_tracer_initial_instr == this_instr ;
568570 bool progress_needed = (tstate -> interp -> jit_tracer_initial_chain_depth % MAX_CHAIN_DEPTH ) == 0 && is_first_instr ;;
@@ -794,12 +796,16 @@ _PyJIT_translate_single_bytecode_to_trace(
794796 }
795797 if (uop == _PUSH_FRAME || uop == _RETURN_VALUE || uop == _RETURN_GENERATOR || uop == _YIELD_VALUE ) {
796798 PyCodeObject * new_code = (PyCodeObject * )PyStackRef_AsPyObjectBorrow (frame -> f_executable );
797- PyFunctionObject * new_func = (PyCodeObject * )PyStackRef_AsPyObjectBorrow (frame -> f_funcobj );
799+ PyFunctionObject * new_func = (PyFunctionObject * )PyStackRef_AsPyObjectBorrow (frame -> f_funcobj );
798800 if (new_func != NULL ) {
799801 operand = (uintptr_t )new_func ;
802+ DPRINTF (2 , "Adding %p func to op\n" , (void * )operand );
803+ _Py_BloomFilter_Add (dependencies , new_func );
800804 }
801805 else if (new_code != NULL ) {
802806 operand = (uintptr_t )new_code | 1 ;
807+ DPRINTF (2 , "Adding %p code to op\n" , (void * )operand );
808+ _Py_BloomFilter_Add (dependencies , new_code );
803809 }
804810 else {
805811 operand = 0 ;
@@ -866,6 +872,7 @@ _PyJIT_InitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_
866872 tstate -> interp -> jit_tracer_initial_stack_depth = curr_stackdepth ;
867873 tstate -> interp -> jit_tracer_initial_chain_depth = chain_depth ;
868874 tstate -> interp -> jit_tracer_current_frame = frame ;
875+ tstate -> interp -> jit_tracer_dependencies_still_valid = true;
869876}
870877
871878void
@@ -1530,6 +1537,25 @@ _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is
15301537 _Py_Executors_InvalidateAll (interp , is_invalidation );
15311538}
15321539
1540+ void
1541+ _Py_JITTracer_InvalidateDependency (PyThreadState * old_tstate , void * obj )
1542+ {
1543+ _PyBloomFilter obj_filter ;
1544+ _Py_BloomFilter_Init (& obj_filter );
1545+ _Py_BloomFilter_Add (& obj_filter , obj );
1546+ HEAD_LOCK (& _PyRuntime );
1547+
1548+ PyInterpreterState * interp = old_tstate -> interp ;
1549+
1550+ _Py_FOR_EACH_TSTATE_UNLOCKED (interp , tstate ) {
1551+ if (bloom_filter_may_contain (& tstate -> interp -> jit_tracer_dependencies , & obj_filter ))
1552+ {
1553+ tstate -> interp -> jit_tracer_dependencies_still_valid = false;
1554+ }
1555+
1556+ }
1557+ HEAD_UNLOCK (& _PyRuntime );
1558+ }
15331559/* Invalidate all executors */
15341560void
15351561_Py_Executors_InvalidateAll (PyInterpreterState * interp , int is_invalidation )
0 commit comments