Skip to content

Commit f13260e

Browse files
committed
Address code review
1 parent 07e6ba1 commit f13260e

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern "C" {
1414
#include "pycore_structs.h" // PyHamtObject
1515
#include "pycore_tstate.h" // _PyThreadStateImpl
1616
#include "pycore_typedefs.h" // _PyRuntimeState
17+
#include "pycore_uop.h" // struct _PyUOpInstruction
1718

1819

1920
#define CODE_MAX_WATCHERS 8
@@ -898,6 +899,10 @@ struct _is {
898899
struct _stoptheworld_state stoptheworld;
899900
struct _qsbr_shared qsbr;
900901

902+
#ifdef _Py_TIER2
903+
struct _PyUOpInstruction *jit_uop_buffer;
904+
#endif
905+
901906
#if defined(Py_GIL_DISABLED)
902907
struct _mimalloc_interp_state mimalloc;
903908
struct _brc_state brc; // biased reference counting state

Include/internal/pycore_tstate.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern "C" {
1212
#include "pycore_freelist_state.h" // struct _Py_freelists
1313
#include "pycore_mimalloc.h" // struct _mimalloc_thread_state
1414
#include "pycore_qsbr.h" // struct qsbr
15-
#include "pycore_uop.h" // struct _PyUOpInstruction
1615

1716

1817
#ifdef Py_GIL_DISABLED
@@ -77,10 +76,6 @@ typedef struct _PyThreadStateImpl {
7776
Py_ssize_t reftotal; // this thread's total refcount operations
7877
#endif
7978

80-
#ifdef _Py_TIER2
81-
struct _PyUOpInstruction *jit_uop_buffer;
82-
#endif
83-
8479
} _PyThreadStateImpl;
8580

8681
#ifdef __cplusplus

Python/optimizer.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,14 +1280,14 @@ uop_optimize(
12801280
{
12811281
_PyBloomFilter dependencies;
12821282
_Py_BloomFilter_Init(&dependencies);
1283-
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
1284-
if (tstate->jit_uop_buffer == NULL) {
1285-
tstate->jit_uop_buffer = (_PyUOpInstruction *)PyMem_RawMalloc(UOP_MAX_TRACE_LENGTH*sizeof(_PyUOpInstruction));
1286-
if (tstate->jit_uop_buffer == NULL) {
1283+
PyInterpreterState *interp = _PyInterpreterState_GET();
1284+
if (interp->jit_uop_buffer == NULL) {
1285+
interp->jit_uop_buffer = (_PyUOpInstruction *)PyMem_RawMalloc(UOP_MAX_TRACE_LENGTH*sizeof(_PyUOpInstruction));
1286+
if (interp->jit_uop_buffer == NULL) {
12871287
return 0;
12881288
}
12891289
}
1290-
_PyUOpInstruction *buffer = tstate->jit_uop_buffer;
1290+
_PyUOpInstruction *buffer = interp->jit_uop_buffer;
12911291
OPT_STAT_INC(attempts);
12921292
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
12931293
bool is_noopt = true;

Python/pystate.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ init_interpreter(PyInterpreterState *interp,
556556
#ifdef Py_GIL_DISABLED
557557
_Py_brc_init_state(interp);
558558
#endif
559+
560+
#ifdef _Py_TIER2
561+
// Ensure the buffer is to be set as NULL.
562+
interp->jit_uop_buffer = NULL;
563+
#endif
559564
llist_init(&interp->mem_free_queue.head);
560565
llist_init(&interp->asyncio_tasks_head);
561566
interp->asyncio_tasks_lock = (PyMutex){0};
@@ -803,6 +808,10 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
803808

804809
#ifdef _Py_TIER2
805810
_Py_ClearExecutorDeletionList(interp);
811+
if (interp->jit_uop_buffer != NULL) {
812+
PyMem_RawFree(interp->jit_uop_buffer);
813+
interp->jit_uop_buffer = NULL;
814+
}
806815
#endif
807816
_PyAST_Fini(interp);
808817
_PyAtExit_Fini(interp);
@@ -1536,11 +1545,6 @@ new_threadstate(PyInterpreterState *interp, int whence)
15361545
}
15371546
#endif
15381547

1539-
#ifdef _Py_TIER2
1540-
// Ensure the buffer is to be set as NULL.
1541-
tstate->jit_uop_buffer = NULL;
1542-
#endif
1543-
15441548
/* We serialize concurrent creation to protect global state. */
15451549
HEAD_LOCK(interp->runtime);
15461550

@@ -1731,14 +1735,6 @@ PyThreadState_Clear(PyThreadState *tstate)
17311735
_Py_ClearTLBCIndex((_PyThreadStateImpl *)tstate);
17321736
#endif
17331737

1734-
#ifdef _Py_TIER2
1735-
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
1736-
if (_tstate->jit_uop_buffer != NULL) {
1737-
PyMem_RawFree(_tstate->jit_uop_buffer);
1738-
_tstate->jit_uop_buffer = NULL;
1739-
}
1740-
#endif
1741-
17421738
// Merge our queue of pointers to be freed into the interpreter queue.
17431739
_PyMem_AbandonDelayed(tstate);
17441740

0 commit comments

Comments
 (0)