Skip to content

Commit

Permalink
Remove _get_tlbc_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Oct 24, 2024
1 parent c107495 commit 07f9140
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 110 deletions.
37 changes: 0 additions & 37 deletions Lib/test/test_thread_local_bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,43 +193,6 @@ def f(q):
""")
assert_python_ok("-X", "tlbc=1", "-c", code)

def test_tlbc_cleanup(self):
code = textwrap.dedent("""
import gc
import sys
import threading
def f(barrier, callee):
barrier.wait()
return callee()
# Define callee dynamically so that the module body's constants don't
# hold a strong reference to the code object.
ns = {}
exec('def func(): return 42', globals=ns)
callee = ns.pop('func')
# Create 5 copies of callee's bytecode
threads = []
barrier = threading.Barrier(5)
for _ in range(barrier.parties):
t = threading.Thread(target=f, args=(barrier, callee))
t.start()
threads.append(t)
for t in threads:
t.join()
# Destroy the only reference to callee's code object. All the tlbc
# copies should be destroyed when the code object is destroyed in the
# call to gc.collect below.
before = sys._get_tlbc_blocks()
callee.__code__ = f.__code__
gc.collect()
after = sys._get_tlbc_blocks()
assert (before - after) == len(threads)
""")
assert_python_ok("-X", "tlbc=1", "-c", code)


if __name__ == "__main__":
unittest.main()
38 changes: 1 addition & 37 deletions Python/clinic/sysmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 0 additions & 36 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2448,41 +2448,6 @@ sys__is_gil_enabled_impl(PyObject *module)
#endif
}

#ifdef Py_GIL_DISABLED
static int
count_tlbc_blocks(PyObject *obj, Py_ssize_t *count)
{
if (PyCode_Check(obj)) {
_PyCodeArray *tlbc = ((PyCodeObject *)obj)->co_tlbc;
// First entry always points to the bytecode at the end of the code
// object. Exclude it from the count as it is allocated as part of
// creating the code object.
for (Py_ssize_t i = 1; i < tlbc->size; i++) {
if (tlbc->entries[i] != NULL) {
(*count)++;
}
}
}
return 1;
}

/*[clinic input]
sys._get_tlbc_blocks -> Py_ssize_t
Return the total number of thread-local bytecode copies, excluding the copies that are embedded in the code object.
[clinic start generated code]*/

static Py_ssize_t
sys__get_tlbc_blocks_impl(PyObject *module)
/*[clinic end generated code: output=4b4e350583cbd643 input=37c14e47d8905a95]*/
{
Py_ssize_t count = 0;
PyUnstable_GC_VisitObjects((gcvisitobjects_t) count_tlbc_blocks, &count);
return count;
}
#endif /* Py_GIL_DISABLED */



static PerfMapState perf_map_state;

Expand Down Expand Up @@ -2658,7 +2623,6 @@ static PyMethodDef sys_methods[] = {
#endif
SYS__GET_CPU_COUNT_CONFIG_METHODDEF
SYS__IS_GIL_ENABLED_METHODDEF
SYS__GET_TLBC_BLOCKS_METHODDEF
{NULL, NULL} // sentinel
};

Expand Down

0 comments on commit 07f9140

Please sign in to comment.