gh-143421: Move JitOptContext from stack allocation to per-thread heap allocation (GH-143536)

* move JitOptContext to _PyThreadStateImpl
* make _PyUOpInstruction buffer a part of _PyThreadStateImpl

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
Hai Zhu 2026-01-09 03:38:21 +08:00 committed by GitHub
parent cea2d2475d
commit aeb3403563
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 150 additions and 147 deletions

View file

@ -1025,13 +1025,6 @@ _PyJit_TryInitializeTracing(
if (oparg > 0xFFFF) {
return 0;
}
if (_tstate->jit_tracer_state.code_buffer == NULL) {
_tstate->jit_tracer_state.code_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE);
if (_tstate->jit_tracer_state.code_buffer == NULL) {
// Don't error, just go to next instruction.
return 0;
}
}
PyObject *func = PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
if (func == NULL) {
return 0;
@ -1484,8 +1477,8 @@ uop_optimize(
OPT_STAT_INC(traces_created);
if (!is_noopt) {
length = _Py_uop_analyze_and_optimize(
_tstate->jit_tracer_state.initial_state.func,
buffer,length,
_tstate,
buffer, length,
curr_stackentries, dependencies);
if (length <= 0) {
return length;