-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-137838: Fix JIT trace buffer overrun by increasing possible exit stubs #138177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
31a5157
gh-137838: Fix JIT trace buffer overrun by increasing possible exit s…
corona10 650e55d
fix
corona10 5d816a2
fix
corona10 b4aad3c
Address code review
corona10 a6fd711
nit
corona10 917c6f0
Update
corona10 57f6c39
Address code review
corona10 ef3c108
Add comment
corona10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Core_and_Builtins/2025-08-27-17-51-38.gh-issue-137838.lK6T0j.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix JIT trace buffer overrun by increasing possible exit stubs. | ||
Patch by Donghee Na. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -550,7 +550,8 @@ translate_bytecode_to_trace( | |
_Py_CODEUNIT *instr, | ||
_PyUOpInstruction *trace, | ||
int buffer_size, | ||
_PyBloomFilter *dependencies, bool progress_needed) | ||
_PyBloomFilter *dependencies, bool progress_needed, | ||
bool is_noopt) | ||
{ | ||
bool first = true; | ||
PyCodeObject *code = _PyFrame_GetCode(frame); | ||
|
@@ -591,9 +592,12 @@ translate_bytecode_to_trace( | |
|
||
for (;;) { | ||
target = INSTR_IP(instr, code); | ||
// Need space for _DEOPT | ||
max_length--; | ||
|
||
if (is_noopt) { | ||
max_length-=2; | ||
} | ||
else { | ||
max_length--; | ||
} | ||
corona10 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
uint32_t opcode = instr->op.code; | ||
uint32_t oparg = instr->op.arg; | ||
|
||
|
@@ -1283,15 +1287,19 @@ uop_optimize( | |
_Py_BloomFilter_Init(&dependencies); | ||
_PyUOpInstruction buffer[UOP_MAX_TRACE_LENGTH]; | ||
OPT_STAT_INC(attempts); | ||
int length = translate_bytecode_to_trace(frame, instr, buffer, UOP_MAX_TRACE_LENGTH, &dependencies, progress_needed); | ||
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; | ||
} | ||
Comment on lines
+1285
to
+1289
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this change made? I think the previous code (without the additional variable) made more sense. |
||
int length = translate_bytecode_to_trace(frame, instr, buffer, UOP_MAX_TRACE_LENGTH, &dependencies, progress_needed, is_noopt); | ||
if (length <= 0) { | ||
// Error or nothing translated | ||
return length; | ||
} | ||
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); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, why/how does the behavior differ? Sounds like a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should open another issue for this.