Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame,
_Py_CODEUNIT *close_loop_instr, int curr_stackdepth, int chain_depth, _PyExitData *exit,
int oparg);

void _PyJit_FinalizeTracing(PyThreadState *tstate);
void _PyJit_ResetTracing(PyThreadState *tstate);

void _PyJit_Tracer_InvalidateDependency(PyThreadState *old_tstate, void *obj);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Protect the JIT against recursive tracing.
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ stop_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
exit->temperature = initial_temperature_backoff_counter();
}
}
_PyJit_FinalizeTracing(tstate);
_PyJit_ResetTracing(tstate);
return err;
}
#endif
Expand Down
8 changes: 6 additions & 2 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,11 @@ _PyJit_TryInitializeTracing(
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
// A recursive trace.
// Don't trace into the inner call because it will stomp on the previous trace, causing endless retraces.
if (_tstate->jit_tracer_state.prev_state.code_curr_size > CODE_SIZE_EMPTY) {
if (_tstate->jit_tracer_state.prev_state.code_curr_size > CODE_SIZE_EMPTY ||
_tstate->jit_tracer_state.initial_state.func != NULL) {
// gh-143123: It is possible for another function to finalize the current
// tracer's state while tracing. This might happen in a
// Python -> C -> Python call.
return 0;
}
if (oparg > 0xFFFF) {
Expand Down Expand Up @@ -1089,7 +1093,7 @@ _PyJit_TryInitializeTracing(
}

Py_NO_INLINE void
_PyJit_FinalizeTracing(PyThreadState *tstate)
_PyJit_ResetTracing(PyThreadState *tstate)
{
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
Py_CLEAR(_tstate->jit_tracer_state.initial_state.code);
Expand Down
1 change: 1 addition & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ init_threadstate(_PyThreadStateImpl *_tstate,

#ifdef _Py_TIER2
_tstate->jit_tracer_state.code_buffer = NULL;
_PyJit_ResetTracing(tstate);
#endif
tstate->delete_later = NULL;

Expand Down
Loading