Skip to content

Commit 68b5f08

Browse files
authored
GH-104580: Don't cache eval breaker in interpreter (GH-104581)
Move eval-breaker to the front of the interpreter state.
1 parent 662aede commit 68b5f08

File tree

6 files changed

+260
-262
lines changed

6 files changed

+260
-262
lines changed

Include/internal/pycore_ceval_state.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ struct _pending_calls {
8181
};
8282

8383
struct _ceval_state {
84-
int recursion_limit;
85-
struct _gil_runtime_state *gil;
86-
int own_gil;
8784
/* This single variable consolidates all requests to break out of
8885
the fast path in the eval loop. */
8986
_Py_atomic_int eval_breaker;
9087
/* Request for dropping the GIL */
9188
_Py_atomic_int gil_drop_request;
89+
int recursion_limit;
90+
struct _gil_runtime_state *gil;
91+
int own_gil;
9292
/* The GC is ready to be executed */
9393
_Py_atomic_int gc_scheduled;
9494
struct _pending_calls pending;

Include/internal/pycore_interp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct _Py_long_state {
4848
*/
4949
struct _is {
5050

51+
struct _ceval_state ceval;
5152
PyInterpreterState *next;
5253

5354
uint64_t monitoring_version;
@@ -92,7 +93,6 @@ struct _is {
9293

9394
struct _obmalloc_state obmalloc;
9495

95-
struct _ceval_state ceval;
9696
struct _gc_runtime_state gc;
9797

9898
struct _import_state imports;

Python/bytecodes.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ dummy_func(
7070
_PyInterpreterFrame *frame,
7171
unsigned char opcode,
7272
unsigned int oparg,
73-
_Py_atomic_int * const eval_breaker,
7473
_PyCFrame cframe,
7574
_Py_CODEUNIT *next_instr,
7675
PyObject **stack_pointer,
@@ -143,7 +142,7 @@ dummy_func(
143142
ERROR_IF(err, error);
144143
next_instr--;
145144
}
146-
else if (_Py_atomic_load_relaxed_int32(eval_breaker) && oparg < 2) {
145+
else if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker) && oparg < 2) {
147146
goto handle_eval_breaker;
148147
}
149148
}
@@ -170,7 +169,7 @@ dummy_func(
170169
next_instr = frame->prev_instr;
171170
DISPATCH();
172171
}
173-
if (_Py_atomic_load_relaxed_int32(eval_breaker) && oparg < 2) {
172+
if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker) && oparg < 2) {
174173
goto handle_eval_breaker;
175174
}
176175
}

Python/ceval.c

-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
652652
// for the big switch below (in combination with the EXTRA_CASES macro).
653653
uint8_t opcode; /* Current opcode */
654654
int oparg; /* Current opcode argument, if any */
655-
_Py_atomic_int * const eval_breaker = &tstate->interp->ceval.eval_breaker;
656655
#ifdef LLTRACE
657656
int lltrace = 0;
658657
#endif

Python/ceval_macros.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

117117
#define CHECK_EVAL_BREAKER() \
118118
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); \
119-
if (_Py_atomic_load_relaxed_int32(eval_breaker)) { \
119+
if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker)) { \
120120
goto handle_eval_breaker; \
121121
}
122122

0 commit comments

Comments
 (0)