diff options
author | Gabriele N. Tornetta <P403n1x87@users.noreply.github.com> | 2023-06-08 10:41:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 10:41:24 (GMT) |
commit | 410c2f13e50ea53074cb1fb8074ac0c4d3564cc8 (patch) | |
tree | a278dbd76ed58d4a8752c0d7cf75c9adc808db02 /Include/internal/pycore_interp.h | |
parent | 9d35a71a76cb033598ce136ea655d9e452fe3af0 (diff) | |
download | cpython-410c2f13e50ea53074cb1fb8074ac0c4d3564cc8.zip cpython-410c2f13e50ea53074cb1fb8074ac0c4d3564cc8.tar.gz cpython-410c2f13e50ea53074cb1fb8074ac0c4d3564cc8.tar.bz2 |
Move observability-relevant structure fields to the top (#105271)
Diffstat (limited to 'Include/internal/pycore_interp.h')
-rw-r--r-- | Include/internal/pycore_interp.h | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index a6f4677..90580b7 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -47,13 +47,35 @@ struct _Py_long_state { The PyInterpreterState typedef is in Include/pytypedefs.h. */ struct _is { - - struct _ceval_state ceval; PyInterpreterState *next; + int64_t id; + int64_t id_refcount; + int requires_idref; + PyThread_type_lock id_mutex; + + /* Has been initialized to a safe state. + + In order to be effective, this must be set to 0 during or right + after allocation. */ + int _initialized; + int finalizing; + uint64_t monitoring_version; uint64_t last_restart_version; + /* The fields above this line are declared as early as possible to + facilitate out-of-process observability tools. */ + + /* Set by Py_EndInterpreter(). + + Use _PyInterpreterState_GetFinalizing() + and _PyInterpreterState_SetFinalizing() + to access it, don't access it directly. */ + _Py_atomic_address _finalizing; + + PyCodeObject *interpreter_trampoline; + struct pythreads { uint64_t next_unique_id; /* The linked list of threads, newest first. */ @@ -72,30 +94,22 @@ struct _is { Get runtime from tstate: tstate->interp->runtime. */ struct pyruntimestate *runtime; - int64_t id; - int64_t id_refcount; - int requires_idref; - PyThread_type_lock id_mutex; - - /* Has been initialized to a safe state. - - In order to be effective, this must be set to 0 during or right - after allocation. */ - int _initialized; - int finalizing; - - /* Set by Py_EndInterpreter(). + struct _gc_runtime_state gc; - Use _PyInterpreterState_GetFinalizing() - and _PyInterpreterState_SetFinalizing() - to access it, don't access it directly. */ - _Py_atomic_address _finalizing; + /* The following fields are here to avoid allocation during init. + The data is exposed through PyInterpreterState pointer fields. + These fields should not be accessed directly outside of init. - struct _obmalloc_state obmalloc; + All other PyInterpreterState pointer fields are populated when + needed and default to NULL. - struct _gc_runtime_state gc; + For now there are some exceptions to that rule, which require + allocation during init. These will be addressed on a case-by-case + basis. Also see _PyRuntimeState regarding the various mutex fields. + */ - struct _import_state imports; + /* The per-interpreter GIL, which might not be used. */ + struct _gil_runtime_state _gil; // Dictionary of the sys module PyObject *sysdict; @@ -133,6 +147,12 @@ struct _is { struct _warnings_runtime_state warnings; struct atexit_state atexit; + struct _ceval_state ceval; + + struct _obmalloc_state obmalloc; + + struct _import_state imports; + PyObject *audit_hooks; PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS]; PyCode_WatchCallback code_watchers[CODE_MAX_WATCHERS]; @@ -159,7 +179,6 @@ struct _is { struct ast_state ast; struct types_state types; struct callable_cache callable_cache; - PyCodeObject *interpreter_trampoline; _PyOptimizerObject *optimizer; uint16_t optimizer_resume_threshold; uint16_t optimizer_backedge_threshold; @@ -176,21 +195,6 @@ struct _is { struct _Py_interp_cached_objects cached_objects; struct _Py_interp_static_objects static_objects; - /* The following fields are here to avoid allocation during init. - The data is exposed through PyInterpreterState pointer fields. - These fields should not be accessed directly outside of init. - - All other PyInterpreterState pointer fields are populated when - needed and default to NULL. - - For now there are some exceptions to that rule, which require - allocation during init. These will be addressed on a case-by-case - basis. Also see _PyRuntimeState regarding the various mutex fields. - */ - - /* The per-interpreter GIL, which might not be used. */ - struct _gil_runtime_state _gil; - /* the initial PyInterpreterState.threads.head */ PyThreadState _initial_thread; }; |