@@ -1076,12 +1076,19 @@ _PyJit_FinalizeTracing(PyThreadState *tstate, int err) |
1076 | 1076 | exit->temperature = initial_temperature_backoff_counter(&tstate->interp->opt_config); |
1077 | 1077 | } |
1078 | 1078 | } |
| 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 | + } |
1079 | 1086 | Py_CLEAR(tracer->initial_state.code); |
1080 | 1087 | Py_CLEAR(tracer->initial_state.func); |
1081 | 1088 | Py_CLEAR(tracer->initial_state.executor); |
1082 | 1089 | Py_CLEAR(tracer->prev_state.instr_code); |
1083 | 1090 | 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); |
1085 | 1092 | tracer->is_tracing = false; |
1086 | 1093 | } |
1087 | 1094 |
|
@@ -1521,6 +1528,11 @@ uop_optimize( |
1521 | 1528 | } |
1522 | 1529 | assert(_PyOpcode_uop_name[buffer[pc].opcode]); |
1523 | 1530 | } |
| 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 | + |
1524 | 1536 | OPT_HIST(effective_trace_length(buffer, length), optimized_trace_length_hist); |
1525 | 1537 | _PyUOpInstruction *output = &_tstate->jit_tracer_state->uop_array[0]; |
1526 | 1538 | length = stack_allocate(buffer, output, length); |
|