FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-157875: Fix a reference leak when rewinding JIT traces by Wulian233 · Pull Request #157888 · python/cpython · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 22 additions & 0 deletions Lib/test/test_capi/test_opt.py
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
Expand Up @@ -6016,6 +6016,28 @@ def f1():
"""), 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

# https://github.com/python/cpython/issues/157875
import weakref

def run():
class C:
def __iter__(self):
return self

def __next__(self):
raise StopIteration

obj = C()
for _ in range(TIER2_THRESHOLD):
for _ in obj:
pass
return weakref.ref(C)

ref = run()
gc.collect()
self.assertIsNone(ref())

def test_144068_daemon_thread_jit_cleanup(self):
result = script_helper.run_python_until_end('-c', textwrap.dedent("""
import threading
Expand Down
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 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It seems too detailed. We can ask others?👀

3 changes: 3 additions & 0 deletions Python/optimizer.c
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
Expand Up @@ -789,6 +789,9 @@ _PyJit_translate_single_bytecode_to_trace(
{
_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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

}
trace->next--;
curr = uop_buffer_last(trace);
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL