Skip to content

Commit 6a3bd75

Browse files
Move all JIT fields to thread state
1 parent 209eaff commit 6a3bd75

File tree

11 files changed

+124
-104
lines changed

11 files changed

+124
-104
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,6 @@ struct _is {
930930
struct types_state types;
931931
struct callable_cache callable_cache;
932932
PyObject *common_consts[NUM_COMMON_CONSTANTS];
933-
bool jit;
934-
bool compiling;
935-
struct _PyExecutorObject *executor_list_head;
936-
struct _PyExecutorObject *executor_deletion_list_head;
937-
struct _PyExecutorObject *cold_executor;
938-
struct _PyExecutorObject *cold_dynamic_executor;
939-
int executor_deletion_list_remaining_capacity;
940-
size_t executor_creation_counter;
941933
_rare_events rare_events;
942934
PyDict_WatchCallback builtins_dict_watcher;
943935

Include/internal/pycore_optimizer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ typedef struct _PyExecutorLinkListNode {
2424
typedef struct {
2525
uint8_t opcode;
2626
uint8_t oparg;
27+
#ifdef Py_GIL_DISABLED
28+
uint8_t valid;
29+
#else
2730
uint8_t valid:1;
31+
#endif
2832
uint8_t linked:1;
2933
uint8_t chain_depth:6; // Must be big enough for MAX_CHAIN_DEPTH - 1.
3034
bool warm;
@@ -359,7 +363,7 @@ extern void _PyExecutor_Free(_PyExecutorObject *self);
359363

360364
PyAPI_FUNC(int) _PyDumpExecutors(FILE *out);
361365
#ifdef _Py_TIER2
362-
extern void _Py_ClearExecutorDeletionList(PyInterpreterState *interp);
366+
extern void _Py_ClearExecutorDeletionList(PyThreadState *tstate);
363367
#endif
364368

365369
int _PyJit_translate_single_bytecode_to_trace(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr, bool stop_tracing);

Include/internal/pycore_tstate.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ typedef struct _PyJitTracerState {
5252
_PyJitTracerInitialState initial_state;
5353
_PyJitTracerPreviousState prev_state;
5454
} _PyJitTracerState;
55+
56+
typedef struct _PyJitExecutorState {
57+
bool jit;
58+
bool compiling;
59+
struct _PyExecutorObject *executor_list_head;
60+
struct _PyExecutorObject *executor_deletion_list_head;
61+
struct _PyExecutorObject *cold_executor;
62+
struct _PyExecutorObject *cold_dynamic_executor;
63+
int executor_deletion_list_remaining_capacity;
64+
size_t executor_creation_counter;
65+
} _PyJitExecutorState;
66+
5567
#endif
5668

5769
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
@@ -120,6 +132,7 @@ typedef struct _PyThreadStateImpl {
120132
#endif
121133
#if _Py_TIER2
122134
_PyJitTracerState jit_tracer_state;
135+
_PyJitExecutorState jit_executor_state;
123136
#endif
124137
} _PyThreadStateImpl;
125138

Python/bytecodes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,7 @@ dummy_func(
29412941
specializing tier1 op(_SPECIALIZE_JUMP_BACKWARD, (--)) {
29422942
#if ENABLE_SPECIALIZATION
29432943
if (this_instr->op.code == JUMP_BACKWARD) {
2944-
uint8_t desired = tstate->interp->jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT;
2944+
uint8_t desired = ((_PyThreadStateImpl*)tstate)->jit_executor_state.jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT;
29452945
FT_ATOMIC_STORE_UINT8_RELAXED(this_instr->op.code, desired);
29462946
// Need to re-dispatch so the warmup counter isn't off by one:
29472947
next_instr = this_instr;
@@ -3035,7 +3035,7 @@ dummy_func(
30353035
}
30363036
DISPATCH_GOTO();
30373037
}
3038-
assert(executor != tstate->interp->cold_executor);
3038+
assert(executor != ((_PyThreadStateImpl *)tstate)->jit_executor_state.cold_executor);
30393039
tstate->jit_exit = NULL;
30403040
TIER1_TO_TIER2(executor);
30413041
#else
@@ -5282,7 +5282,7 @@ dummy_func(
52825282
}
52835283

52845284
tier2 op(_CHECK_VALIDITY, (--)) {
5285-
DEOPT_IF(!current_executor->vm_data.valid);
5285+
DEOPT_IF(!FT_ATOMIC_LOAD_UINT8(current_executor->vm_data.valid));
52865286
}
52875287

52885288
tier2 pure op(_LOAD_CONST_INLINE, (ptr/4 -- value)) {

Python/ceval_gil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ _Py_HandlePending(PyThreadState *tstate)
13981398
if ((breaker & _PY_EVAL_JIT_INVALIDATE_COLD_BIT) != 0) {
13991399
_Py_unset_eval_breaker_bit(tstate, _PY_EVAL_JIT_INVALIDATE_COLD_BIT);
14001400
_Py_Executors_InvalidateCold(tstate->interp);
1401-
tstate->interp->executor_creation_counter = JIT_CLEANUP_THRESHOLD;
1401+
((_PyThreadStateImpl*)tstate)->jit_executor_state.executor_creation_counter = JIT_CLEANUP_THRESHOLD;
14021402
}
14031403

14041404
/* GIL drop request */

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)