Skip to content

Commit 07f9140

Browse files
committed
Remove _get_tlbc_blocks
1 parent c107495 commit 07f9140

File tree

3 files changed

+1
-110
lines changed

3 files changed

+1
-110
lines changed

Lib/test/test_thread_local_bytecode.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -193,43 +193,6 @@ def f(q):
193193
""")
194194
assert_python_ok("-X", "tlbc=1", "-c", code)
195195

196-
def test_tlbc_cleanup(self):
197-
code = textwrap.dedent("""
198-
import gc
199-
import sys
200-
import threading
201-
202-
def f(barrier, callee):
203-
barrier.wait()
204-
return callee()
205-
206-
# Define callee dynamically so that the module body's constants don't
207-
# hold a strong reference to the code object.
208-
ns = {}
209-
exec('def func(): return 42', globals=ns)
210-
callee = ns.pop('func')
211-
212-
# Create 5 copies of callee's bytecode
213-
threads = []
214-
barrier = threading.Barrier(5)
215-
for _ in range(barrier.parties):
216-
t = threading.Thread(target=f, args=(barrier, callee))
217-
t.start()
218-
threads.append(t)
219-
for t in threads:
220-
t.join()
221-
222-
# Destroy the only reference to callee's code object. All the tlbc
223-
# copies should be destroyed when the code object is destroyed in the
224-
# call to gc.collect below.
225-
before = sys._get_tlbc_blocks()
226-
callee.__code__ = f.__code__
227-
gc.collect()
228-
after = sys._get_tlbc_blocks()
229-
assert (before - after) == len(threads)
230-
""")
231-
assert_python_ok("-X", "tlbc=1", "-c", code)
232-
233196

234197
if __name__ == "__main__":
235198
unittest.main()

Python/clinic/sysmodule.c.h

Lines changed: 1 addition & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/sysmodule.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,41 +2448,6 @@ sys__is_gil_enabled_impl(PyObject *module)
24482448
#endif
24492449
}
24502450

2451-
#ifdef Py_GIL_DISABLED
2452-
static int
2453-
count_tlbc_blocks(PyObject *obj, Py_ssize_t *count)
2454-
{
2455-
if (PyCode_Check(obj)) {
2456-
_PyCodeArray *tlbc = ((PyCodeObject *)obj)->co_tlbc;
2457-
// First entry always points to the bytecode at the end of the code
2458-
// object. Exclude it from the count as it is allocated as part of
2459-
// creating the code object.
2460-
for (Py_ssize_t i = 1; i < tlbc->size; i++) {
2461-
if (tlbc->entries[i] != NULL) {
2462-
(*count)++;
2463-
}
2464-
}
2465-
}
2466-
return 1;
2467-
}
2468-
2469-
/*[clinic input]
2470-
sys._get_tlbc_blocks -> Py_ssize_t
2471-
2472-
Return the total number of thread-local bytecode copies, excluding the copies that are embedded in the code object.
2473-
[clinic start generated code]*/
2474-
2475-
static Py_ssize_t
2476-
sys__get_tlbc_blocks_impl(PyObject *module)
2477-
/*[clinic end generated code: output=4b4e350583cbd643 input=37c14e47d8905a95]*/
2478-
{
2479-
Py_ssize_t count = 0;
2480-
PyUnstable_GC_VisitObjects((gcvisitobjects_t) count_tlbc_blocks, &count);
2481-
return count;
2482-
}
2483-
#endif /* Py_GIL_DISABLED */
2484-
2485-
24862451

24872452
static PerfMapState perf_map_state;
24882453

@@ -2658,7 +2623,6 @@ static PyMethodDef sys_methods[] = {
26582623
#endif
26592624
SYS__GET_CPU_COUNT_CONFIG_METHODDEF
26602625
SYS__IS_GIL_ENABLED_METHODDEF
2661-
SYS__GET_TLBC_BLOCKS_METHODDEF
26622626
{NULL, NULL} // sentinel
26632627
};
26642628

0 commit comments

Comments
 (0)