gh-152330: Make perf_trampoline thread safe.#152331
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
The following commit authors need to sign the Contributor License Agreement: |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Summary of Changes
Fixes multiple critical data races, post-fork deadlocks, memory leaks, and edge-case exception handling issues in
perf_trampoline.cunder Free Threading and Python 3.14.perf_trampoline_mutex): Introduced a dedicated mutex to guard global state mutations and JIT arena allocations (compile_trampoline(), initialization, and teardown). Hot-path executions remain lock-free.perf_status,extra_code_index, andpersist_after_forkto atomic operations.py_trampoline_evaluatorto loadextra_code_indexatomically. If deactivation has started (returning-1), evaluating threads cleanly bypass the JIT trampoline and fall back to_PyEval_EvalFrameDefaultinstead of hitting assertion failures.write_statewriting to/tmp/perf-PID.map) from the critical section, ensuring slow disk I/O does not hold the compiler lock.perf_trampoline_mutexto an unlocked state, preventing deadlocks if a thread forks while another thread holds the lock.PyErr_Clear()) and the trampoline is disabled gracefully rather than leaking unhandled exceptions or crashing.pycore_ceval_state.hby initializing the global watcher ID sentinel to-1instead of0. This allows0to be correctly recognized as a valid active watcher ID.Fixes gh-152330