Skip to content

Commit 6a8b862

Browse files
authored
Revert "Move observability-relevant structure fields to the top" (#105512)
1 parent a8eb737 commit 6a8b862

File tree

3 files changed

+51
-63
lines changed

3 files changed

+51
-63
lines changed

Include/internal/pycore_frame.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,16 @@ enum _frameowner {
4949
typedef struct _PyInterpreterFrame {
5050
PyCodeObject *f_code; /* Strong reference */
5151
struct _PyInterpreterFrame *previous;
52-
// NOTE: This is not necessarily the last instruction started in the given
53-
// frame. Rather, it is the code unit *prior to* the *next* instruction. For
54-
// example, it may be an inline CACHE entry, an instruction we just jumped
55-
// over, or (in the case of a newly-created frame) a totally invalid value:
56-
_Py_CODEUNIT *prev_instr;
57-
58-
/* The fields above this line are declared as early as possible to
59-
facilitate out-of-process observability tools. */
60-
6152
PyObject *f_funcobj; /* Strong reference. Only valid if not on C stack */
6253
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
6354
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
6455
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
6556
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
57+
// NOTE: This is not necessarily the last instruction started in the given
58+
// frame. Rather, it is the code unit *prior to* the *next* instruction. For
59+
// example, it may be an inline CACHE entry, an instruction we just jumped
60+
// over, or (in the case of a newly-created frame) a totally invalid value:
61+
_Py_CODEUNIT *prev_instr;
6662
int stacktop; /* Offset of TOS from localsplus */
6763
/* The return_offset determines where a `RETURN` should go in the caller,
6864
* relative to `prev_instr`.

Include/internal/pycore_interp.h

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,13 @@ struct _Py_long_state {
4747
The PyInterpreterState typedef is in Include/pytypedefs.h.
4848
*/
4949
struct _is {
50-
PyInterpreterState *next;
51-
52-
int64_t id;
53-
int64_t id_refcount;
54-
int requires_idref;
55-
PyThread_type_lock id_mutex;
56-
57-
/* Has been initialized to a safe state.
5850

59-
In order to be effective, this must be set to 0 during or right
60-
after allocation. */
61-
int _initialized;
62-
int finalizing;
51+
struct _ceval_state ceval;
52+
PyInterpreterState *next;
6353

6454
uint64_t monitoring_version;
6555
uint64_t last_restart_version;
6656

67-
/* The fields above this line are declared as early as possible to
68-
facilitate out-of-process observability tools. */
69-
70-
/* Set by Py_EndInterpreter().
71-
72-
Use _PyInterpreterState_GetFinalizing()
73-
and _PyInterpreterState_SetFinalizing()
74-
to access it, don't access it directly. */
75-
_Py_atomic_address _finalizing;
76-
77-
PyCodeObject *interpreter_trampoline;
78-
7957
struct pythreads {
8058
uint64_t next_unique_id;
8159
/* The linked list of threads, newest first. */
@@ -94,22 +72,30 @@ struct _is {
9472
Get runtime from tstate: tstate->interp->runtime. */
9573
struct pyruntimestate *runtime;
9674

97-
struct _gc_runtime_state gc;
75+
int64_t id;
76+
int64_t id_refcount;
77+
int requires_idref;
78+
PyThread_type_lock id_mutex;
9879

99-
/* The following fields are here to avoid allocation during init.
100-
The data is exposed through PyInterpreterState pointer fields.
101-
These fields should not be accessed directly outside of init.
80+
/* Has been initialized to a safe state.
10281
103-
All other PyInterpreterState pointer fields are populated when
104-
needed and default to NULL.
82+
In order to be effective, this must be set to 0 during or right
83+
after allocation. */
84+
int _initialized;
85+
int finalizing;
10586

106-
For now there are some exceptions to that rule, which require
107-
allocation during init. These will be addressed on a case-by-case
108-
basis. Also see _PyRuntimeState regarding the various mutex fields.
109-
*/
87+
/* Set by Py_EndInterpreter().
11088
111-
/* The per-interpreter GIL, which might not be used. */
112-
struct _gil_runtime_state _gil;
89+
Use _PyInterpreterState_GetFinalizing()
90+
and _PyInterpreterState_SetFinalizing()
91+
to access it, don't access it directly. */
92+
_Py_atomic_address _finalizing;
93+
94+
struct _obmalloc_state obmalloc;
95+
96+
struct _gc_runtime_state gc;
97+
98+
struct _import_state imports;
11399

114100
// Dictionary of the sys module
115101
PyObject *sysdict;
@@ -147,12 +133,6 @@ struct _is {
147133
struct _warnings_runtime_state warnings;
148134
struct atexit_state atexit;
149135

150-
struct _ceval_state ceval;
151-
152-
struct _obmalloc_state obmalloc;
153-
154-
struct _import_state imports;
155-
156136
PyObject *audit_hooks;
157137
PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS];
158138
PyCode_WatchCallback code_watchers[CODE_MAX_WATCHERS];
@@ -179,6 +159,7 @@ struct _is {
179159
struct ast_state ast;
180160
struct types_state types;
181161
struct callable_cache callable_cache;
162+
PyCodeObject *interpreter_trampoline;
182163
_PyOptimizerObject *optimizer;
183164
uint16_t optimizer_resume_threshold;
184165
uint16_t optimizer_backedge_threshold;
@@ -195,6 +176,21 @@ struct _is {
195176
struct _Py_interp_cached_objects cached_objects;
196177
struct _Py_interp_static_objects static_objects;
197178

179+
/* The following fields are here to avoid allocation during init.
180+
The data is exposed through PyInterpreterState pointer fields.
181+
These fields should not be accessed directly outside of init.
182+
183+
All other PyInterpreterState pointer fields are populated when
184+
needed and default to NULL.
185+
186+
For now there are some exceptions to that rule, which require
187+
allocation during init. These will be addressed on a case-by-case
188+
basis. Also see _PyRuntimeState regarding the various mutex fields.
189+
*/
190+
191+
/* The per-interpreter GIL, which might not be used. */
192+
struct _gil_runtime_state _gil;
193+
198194
/* the initial PyInterpreterState.threads.head */
199195
PyThreadState _initial_thread;
200196
};

Include/internal/pycore_runtime.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ typedef struct pyruntimestate {
8484
to access it, don't access it directly. */
8585
_Py_atomic_address _finalizing;
8686

87+
struct _pymem_allocators allocators;
88+
struct _obmalloc_global_state obmalloc;
89+
struct pyhash_runtime_state pyhash_state;
90+
struct _time_runtime_state time;
91+
struct _pythread_runtime_state threads;
92+
struct _signals_runtime_state signals;
93+
8794
struct pyinterpreters {
8895
PyThread_type_lock mutex;
8996
/* The linked list of interpreters, newest first. */
@@ -102,24 +109,13 @@ typedef struct pyruntimestate {
102109
using a Python int. */
103110
int64_t next_id;
104111
} interpreters;
105-
106-
unsigned long main_thread;
107-
108-
/* The fields above this line are declared as early as possible to
109-
facilitate out-of-process observability tools. */
110-
111112
// XXX Remove this field once we have a tp_* slot.
112113
struct _xidregistry {
113114
PyThread_type_lock mutex;
114115
struct _xidregitem *head;
115116
} xidregistry;
116117

117-
struct _pymem_allocators allocators;
118-
struct _obmalloc_global_state obmalloc;
119-
struct pyhash_runtime_state pyhash_state;
120-
struct _time_runtime_state time;
121-
struct _pythread_runtime_state threads;
122-
struct _signals_runtime_state signals;
118+
unsigned long main_thread;
123119

124120
/* Used for the thread state bound to the current thread. */
125121
Py_tss_t autoTSSkey;

0 commit comments

Comments
 (0)