Skip to content

gh-157875: Fix a reference leak when rewinding JIT traces - #157888

Open
Wulian233 wants to merge 3 commits into
python:mainfrom
Wulian233:trace
Open

Wulian233 wants to merge 3 commits into
python:mainfrom
Wulian233:trace

Conversation

@Wulian233

@Wulian233 Wulian233 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Comment thread Lib/test/test_capi/test_opt.py Outdated
@Wulian233

Copy link
Copy Markdown
Contributor Author

gently ping @markshannon

"""), PYTHON_JIT="1")
self.assertEqual(result[0].rc, 0, result)

def test_157875_rewound_trace_reference_leak(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test assert that the rewinding happened? Or would that make the test too brittle?

@@ -0,0 +1,2 @@
Fix a reference leak in the JIT when a trace is rewound after encountering
unsupported bytecode.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just say when tracing is rewound? I think this get's triggered for standard supported JIT traces hit natural endings such as jumps

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems too detailed. We can ask others?👀

Comment thread Python/optimizer.c
_PyUOpInstruction *curr = uop_buffer_last(trace);
while (curr->opcode != _SET_IP && uop_buffer_length(trace) > 2) {
if (_PyUop_Flags[curr->opcode] & HAS_RECORDS_VALUE_FLAG) {
Py_XDECREF((PyObject *)(uintptr_t)curr->operand0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now have a very similar pattern three times in this file, maybe worth seeing if it's worth to make it a common operation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to focus on the bug fix scope of this PR. However, currently the JIT has been suspended and only bug fixes are accepted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants