gh-141504: Refactor policy object into a single opt_config (gh-143644)

This commit is contained in:
Donghee Na 2026-01-15 09:53:00 +09:00 committed by GitHub
parent a73ba4d46e
commit 794f758cd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 89 additions and 64 deletions

View file

@ -580,9 +580,10 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
}
co->_co_firsttraceable = entry_point;
#ifdef Py_GIL_DISABLED
_PyCode_Quicken(_PyCode_CODE(co), Py_SIZE(co), interp->config.tlbc_enabled);
int enable_counters = interp->config.tlbc_enabled && interp->opt_config.specialization_enabled;
_PyCode_Quicken(_PyCode_CODE(co), Py_SIZE(co), enable_counters);
#else
_PyCode_Quicken(_PyCode_CODE(co), Py_SIZE(co), 1);
_PyCode_Quicken(_PyCode_CODE(co), Py_SIZE(co), interp->opt_config.specialization_enabled);
#endif
notify_code_watchers(PY_CODE_EVENT_CREATE, co);
return 0;
@ -3369,13 +3370,13 @@ deopt_code_unit(PyCodeObject *code, int i)
}
static void
copy_code(_Py_CODEUNIT *dst, PyCodeObject *co)
copy_code(PyInterpreterState *interp, _Py_CODEUNIT *dst, PyCodeObject *co)
{
int code_len = (int) Py_SIZE(co);
for (int i = 0; i < code_len; i += _PyInstruction_GetLength(co, i)) {
dst[i] = deopt_code_unit(co, i);
}
_PyCode_Quicken(dst, code_len, 1);
_PyCode_Quicken(dst, code_len, interp->opt_config.specialization_enabled);
}
static Py_ssize_t
@ -3391,7 +3392,7 @@ get_pow2_greater(Py_ssize_t initial, Py_ssize_t limit)
}
static _Py_CODEUNIT *
create_tlbc_lock_held(PyCodeObject *co, Py_ssize_t idx)
create_tlbc_lock_held(PyInterpreterState *interp, PyCodeObject *co, Py_ssize_t idx)
{
_PyCodeArray *tlbc = co->co_tlbc;
if (idx >= tlbc->size) {
@ -3414,7 +3415,7 @@ create_tlbc_lock_held(PyCodeObject *co, Py_ssize_t idx)
PyErr_NoMemory();
return NULL;
}
copy_code((_Py_CODEUNIT *) bc, co);
copy_code(interp, (_Py_CODEUNIT *) bc, co);
assert(tlbc->entries[idx] == NULL);
tlbc->entries[idx] = bc;
return (_Py_CODEUNIT *) bc;
@ -3429,7 +3430,8 @@ get_tlbc_lock_held(PyCodeObject *co)
if (idx < tlbc->size && tlbc->entries[idx] != NULL) {
return (_Py_CODEUNIT *)tlbc->entries[idx];
}
return create_tlbc_lock_held(co, idx);
PyInterpreterState *interp = tstate->base.interp;
return create_tlbc_lock_held(interp, co, idx);
}
_Py_CODEUNIT *