@@ -1076,12 +1076,19 @@ _PyJit_FinalizeTracing(PyThreadState *tstate, int err)
10761076 exit -> temperature = initial_temperature_backoff_counter (& tstate -> interp -> opt_config );
10771077 }
10781078 }
1079+ // Clear all recorded values
1080+ _PyJitUopBuffer * buffer = & tracer -> code_buffer ;
1081+ for (_PyUOpInstruction * inst = buffer -> start ; inst < buffer -> next ; inst ++ ) {
1082+ if (_PyUop_Flags [inst -> opcode ] & HAS_RECORDS_VALUE_FLAG ) {
1083+ Py_XDECREF ((PyObject * )(uintptr_t )inst -> operand0 );
1084+ }
1085+ }
10791086 Py_CLEAR (tracer -> initial_state .code );
10801087 Py_CLEAR (tracer -> initial_state .func );
10811088 Py_CLEAR (tracer -> initial_state .executor );
10821089 Py_CLEAR (tracer -> prev_state .instr_code );
10831090 Py_CLEAR (tracer -> prev_state .recorded_value );
1084- uop_buffer_init (& tracer -> code_buffer , & tracer -> uop_array [0 ], UOP_MAX_TRACE_LENGTH );
1091+ uop_buffer_init (buffer , & tracer -> uop_array [0 ], UOP_MAX_TRACE_LENGTH );
10851092 tracer -> is_tracing = false;
10861093}
10871094
@@ -1521,6 +1528,11 @@ uop_optimize(
15211528 }
15221529 assert (_PyOpcode_uop_name [buffer [pc ].opcode ]);
15231530 }
1531+ // We've cleaned up the references in the buffer, so discard the code buffer
1532+ // to avoid doing it again during tracer cleanup
1533+ _PyJitUopBuffer * code_buffer = & _tstate -> jit_tracer_state -> code_buffer ;
1534+ code_buffer -> next = code_buffer -> start ;
1535+
15241536 OPT_HIST (effective_trace_length (buffer , length ), optimized_trace_length_hist );
15251537 _PyUOpInstruction * output = & _tstate -> jit_tracer_state -> uop_array [0 ];
15261538 length = stack_allocate (buffer , output , length );
0 commit comments