Skip to content

Commit 4e7a918

Browse files
committed
add _PyJitOptState
1 parent 9717629 commit 4e7a918

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Include/internal/pycore_tstate.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ typedef struct _PyJitTracerTranslatorState {
5151
int jump_backward_seen;
5252
} _PyJitTracerTranslatorState;
5353

54+
typedef struct _PyJitOptState {
55+
struct _JitOptContext *opt_context;
56+
} _PyJitOptState;
57+
5458
typedef struct _PyJitTracerState {
5559
_PyUOpInstruction *code_buffer;
56-
struct _JitOptContext *opt_context;
60+
_PyJitOptState opt_state;
5761
_PyJitTracerInitialState initial_state;
5862
_PyJitTracerPreviousState prev_state;
5963
_PyJitTracerTranslatorState translator_state;

Python/optimizer_analysis.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,13 @@ optimize_uops(
345345
assert(!PyErr_Occurred());
346346
PyFunctionObject *func = tstate->jit_tracer_state.initial_state.func;
347347

348-
// Use thread-local JitOptContext to avoid stack overflow
349-
JitOptContext *ctx = tstate->jit_tracer_state.opt_context;
348+
JitOptContext *ctx = tstate->jit_tracer_state.opt_state.opt_context;
350349
if (ctx == NULL) {
351350
ctx = (JitOptContext *)PyMem_RawMalloc(sizeof(JitOptContext));
352351
if (ctx == NULL) {
353352
return 0;
354353
}
355-
tstate->jit_tracer_state.opt_context = ctx;
354+
tstate->jit_tracer_state.opt_state.opt_context = ctx;
356355
}
357356
uint32_t opcode = UINT16_MAX;
358357

Python/pystate.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ init_threadstate(_PyThreadStateImpl *_tstate,
15541554
"PYTHON_JIT_SIDE_EXIT_INITIAL_BACKOFF",
15551555
SIDE_EXIT_INITIAL_BACKOFF, 0, MAX_BACKOFF);
15561556
_tstate->jit_tracer_state.code_buffer = NULL;
1557-
_tstate->jit_tracer_state.opt_context = NULL;
1557+
_tstate->jit_tracer_state.opt_state.opt_context = NULL;
15581558
#endif
15591559
tstate->delete_later = NULL;
15601560

@@ -1875,11 +1875,9 @@ tstate_delete_common(PyThreadState *tstate, int release_gil)
18751875
_PyObject_VirtualFree(_tstate->jit_tracer_state.code_buffer, UOP_BUFFER_SIZE);
18761876
_tstate->jit_tracer_state.code_buffer = NULL;
18771877
}
1878-
if (_tstate->jit_tracer_state.opt_context != NULL) {
1879-
// Ensure any resources in opt_context are cleaned up
1880-
_Py_uop_abstractcontext_fini(_tstate->jit_tracer_state.opt_context);
1881-
PyMem_RawFree(_tstate->jit_tracer_state.opt_context);
1882-
_tstate->jit_tracer_state.opt_context = NULL;
1878+
if (_tstate->jit_tracer_state.opt_state.opt_context != NULL) {
1879+
PyMem_RawFree(_tstate->jit_tracer_state.opt_state.opt_context);
1880+
_tstate->jit_tracer_state.opt_state.opt_context = NULL;
18831881
}
18841882
#endif
18851883

0 commit comments

Comments
 (0)