Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Include/internal/pycore_tstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ typedef struct _PyJitTracerState {
_PyJitTracerInitialState initial_state;
_PyJitTracerPreviousState prev_state;
_PyJitTracerTranslatorState translator_state;
JitOptContext opt_context;
_PyUOpInstruction code_buffer[UOP_MAX_TRACE_LENGTH];
JitOptContext *opt_context;
_PyUOpInstruction *code_buffer;
} _PyJitTracerState;

#endif
Expand Down
7 changes: 7 additions & 0 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,13 @@ _PyJit_TryInitializeTracing(
if (oparg > 0xFFFF) {
return 0;
}
if (_tstate->jit_tracer_state.code_buffer == NULL) {
_tstate->jit_tracer_state.code_buffer = (_PyUOpInstruction *)_PyObject_VirtualAlloc(UOP_BUFFER_SIZE);
if (_tstate->jit_tracer_state.code_buffer == NULL) {
// Don't error, just go to next instruction.
return 0;
}
}
PyObject *func = PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
if (func == NULL) {
return 0;
Expand Down
10 changes: 9 additions & 1 deletion Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,15 @@ optimize_uops(
assert(!PyErr_Occurred());
PyFunctionObject *func = tstate->jit_tracer_state.initial_state.func;

JitOptContext *ctx = &tstate->jit_tracer_state.opt_context;
JitOptContext *ctx = tstate->jit_tracer_state.opt_context;
if (ctx == NULL) {
ctx = (JitOptContext *)_PyObject_VirtualAlloc(sizeof(JitOptContext));
if (ctx == NULL) {
// Don't error, just bail.
return 0;
}
tstate->jit_tracer_state.opt_context = ctx;
}
uint32_t opcode = UINT16_MAX;

// Make sure that watchers are set up
Expand Down
14 changes: 14 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,8 @@ init_threadstate(_PyThreadStateImpl *_tstate,
init_policy(&_tstate->policy.jit.side_exit_initial_backoff,
"PYTHON_JIT_SIDE_EXIT_INITIAL_BACKOFF",
SIDE_EXIT_INITIAL_BACKOFF, 0, MAX_BACKOFF);
_tstate->jit_tracer_state.code_buffer = NULL;
_tstate->jit_tracer_state.opt_context = NULL;
#endif
tstate->delete_later = NULL;

Expand Down Expand Up @@ -1867,6 +1869,18 @@ tstate_delete_common(PyThreadState *tstate, int release_gil)
assert(tstate_impl->refcounts.values == NULL);
#endif

#if _Py_TIER2
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
if (_tstate->jit_tracer_state.code_buffer != NULL) {
_PyObject_VirtualFree(_tstate->jit_tracer_state.code_buffer, UOP_BUFFER_SIZE);
_tstate->jit_tracer_state.code_buffer = NULL;
}
if (_tstate->jit_tracer_state.opt_context != NULL) {
_PyObject_VirtualFree(_tstate->jit_tracer_state.opt_context, sizeof(JitOptContext));
_tstate->jit_tracer_state.opt_context = NULL;
}
#endif

HEAD_UNLOCK(runtime);

// XXX Unbind in PyThreadState_Clear(), or earlier
Expand Down
Loading