gh-137838: Fix JIT trace buffer overrun by increasing possible exit stubs (gh-138177)

This commit is contained in:
Donghee Na 2025-09-09 09:51:08 +09:00 committed by GitHub
parent 03ee060ec8
commit 5edfe55acf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 6 deletions

View file

@ -591,9 +591,8 @@ translate_bytecode_to_trace(
for (;;) {
target = INSTR_IP(instr, code);
// Need space for _DEOPT
max_length--;
// One for possible _DEOPT, one because _CHECK_VALIDITY itself might _DEOPT
max_length-=2;
uint32_t opcode = instr->op.code;
uint32_t oparg = instr->op.arg;
@ -1283,6 +1282,11 @@ uop_optimize(
_Py_BloomFilter_Init(&dependencies);
_PyUOpInstruction buffer[UOP_MAX_TRACE_LENGTH];
OPT_STAT_INC(attempts);
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
bool is_noopt = true;
if (env_var == NULL || *env_var == '\0' || *env_var > '0') {
is_noopt = false;
}
int length = translate_bytecode_to_trace(frame, instr, buffer, UOP_MAX_TRACE_LENGTH, &dependencies, progress_needed);
if (length <= 0) {
// Error or nothing translated
@ -1290,8 +1294,7 @@ uop_optimize(
}
assert(length < UOP_MAX_TRACE_LENGTH);
OPT_STAT_INC(traces_created);
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
if (env_var == NULL || *env_var == '\0' || *env_var > '0') {
if (!is_noopt) {
length = _Py_uop_analyze_and_optimize(frame, buffer,
length,
curr_stackentries, &dependencies);