8000 gh-84436: Make Interned Strings Immortal by ericsnowcurrently · Pull Request #102887 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-84436: Make Interned Strings Immortal #102887

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

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
546b934
Factor out add_threadstate().
ericsnowcurrently Mar 21, 2023
0bcd136 8000
Add _PyThreadState_InitDetached().
ericsnowcurrently Mar 21, 2023
35d5310
Add _PyThreadState_ClearDetached().
ericsnowcurrently Mar 21, 2023
cba9e34
Add _PyRuntime.cached_objects.main_tstate.
ericsnowcurrently Mar 21, 2023
3b1bb8b
Add _Py_AcquireGlobalObjectsState() and _Py_ReleaseGlobalObjectsState().
ericsnowcurrently Mar 22, 2023
eb42aa1
Add _Py_AddToGlobalDict().
ericsnowcurrently Mar 22, 2023
4e9da2d
Drop _Py_AcquireGlobalObjectsState() and _Py_ReleaseGlobalObjectsStat…
ericsnowcurrently Mar 22, 2023
6216207
Add acquire_global_objects_lock() and release_global_objects_lock().
ericsnowcurrently Mar 22, 2023
3c007c0
Add some TODO comments.
ericsnowcurrently Mar 13, 2023
7d95514
Factor out store_interned().
ericsnowcurrently Mar 20, 2023
5c20b84
Store a thread state to use just for interned strings.
ericsnowcurrently Mar 20, 2023
a3ae02a
Always use the main interpreter when possibly resizing the interned d…
ericsnowcurrently Mar 20, 2023
d5fbc37
Use _PyRuntime.cached_objects.main_tstate instead.
ericsnowcurrently Mar 21, 2023
459325f
Add _PyThreadState_IsBound() and _PyThreadState_Unbind().
ericsnowcurrently Mar 21, 2023
4f25244
Make sure the one-off tstate is bound before using it.
ericsnowcurrently Mar 21, 2023
e68535a
Use _Py_AcquireGlobalObjectsState() in store_interned().
ericsnowcurrently Mar 22, 2023
22753b3
Use _Py_AddToGlobalDict().
ericsnowcurrently Mar 22, 2023
b649a84
Make objects stored in global containers immortal.
ericsnowcurrently Mar 20, 2023
9b0dc99
Immortalize the interned strings dict.
ericsnowcurrently Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add _PyRuntime.cached_objects.main_tstate.
  • Loading branch information
ericsnowcurrently committed Mar 22, 2023
commit cba9e34b991f77d28510dc63c636896a21c257fd
4 changes: 4 additions & 0 deletions Include/internal/pycore_global_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ extern "C" {

struct _Py_cached_objects {
PyObject *interned_strings;
/* A thread state tied to the main interpreter,
used exclusively for when a global object (e.g. interned strings)
is resized (i.e. deallocated + allocated) from an arbitrary thread. */
PyThreadState main_tstate;
};

#define _Py_GLOBAL_OBJECT(NAME) \
Expand Down
3 changes: 3 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ extern PyTypeObject _PyExc_MemoryError;
.types = { \
.next_version_tag = 1, \
}, \
.cached_objects = { \
.main_tstate = _PyThreadState_INIT, \
}, \
.static_objects = { \
.singletons = { \
.small_ints = _Py_small_ints_INIT, \
Expand Down
4 changes: 4 additions & 0 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return status;
}

_PyThreadState_InitDetached(&runtime->cached_objects.main_tstate, interp);

*tstate_p = tstate;
return _PyStatus_OK();
}
Expand Down Expand Up @@ -1928,6 +1930,8 @@ Py_FinalizeEx(void)
// XXX Do this sooner during finalization.
// XXX Ensure finalizer errors are handled properly.

_PyThreadState_ClearDetached(&runtime->cached_objects.main_tstate);

finalize_interp_clear(tstate);
finalize_interp_delete(tstate->interp);

Expand Down
0