Skip to content

Commit fb56baa

Browse files
check env var when re-enabling
1 parent 8df9aed commit fb56baa

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

Include/internal/pycore_pylifecycle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ PyAPI_FUNC(int) _PyInterpreterConfig_UpdateFromDict(
129129
PyInterpreterConfig *,
130130
PyObject *);
131131

132+
extern void _PyInterpreter_SetJitWithEnvVar(PyConfig *config, PyInterpreterState *interp);
132133

133134
#ifdef __cplusplus
134135
}

Python/pylifecycle.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,34 @@ run_presite(PyThreadState *tstate)
11941194
}
11951195
#endif
11961196

1197+
void
1198+
_PyInterpreter_SetJitWithEnvVar(PyConfig *config, PyInterpreterState *interp)
1199+
{
1200+
int enabled = 1;
1201+
#if _Py_TIER2 & 2
1202+
enabled = 0;
1203+
#endif
1204+
char *env = Py_GETENV("PYTHON_JIT");
1205+
if (env && *env != '\0') {
1206+
// PYTHON_JIT=0|1 overrides the default
1207+
enabled = *env != '0';
1208+
}
1209+
if (enabled) {
1210+
#ifdef _Py_JIT
1211+
// perf profiler works fine with tier 2 interpreter, so
1212+
// only checking for a "real JIT".
1213+
if (config->perf_profiling > 0) {
1214+
(void)PyErr_WarnEx(
1215+
PyExc_RuntimeWarning,
1216+
"JIT deactivated as perf profiling support is active",
1217+
0);
1218+
} else
1219+
#endif
1220+
{
1221+
FT_ATOMIC_STORE_CHAR_RELAXED(interp->jit, 1);
1222+
}
1223+
}
1224+
}
11971225

11981226
static PyStatus
11991227
init_interp_main(PyThreadState *tstate)
@@ -1345,30 +1373,7 @@ init_interp_main(PyThreadState *tstate)
13451373
// This is also needed when the JIT is enabled
13461374
#ifdef _Py_TIER2
13471375
if (is_main_interp) {
1348-
int enabled = 1;
1349-
#if _Py_TIER2 & 2
1350-
enabled = 0;
1351-
#endif
1352-
char *env = Py_GETENV("PYTHON_JIT");
1353-
if (env && *env != '\0') {
1354-
// PYTHON_JIT=0|1 overrides the default
1355-
enabled = *env != '0';
1356-
}
1357-
if (enabled) {
1358-
#ifdef _Py_JIT
1359-
// perf profiler works fine with tier 2 interpreter, so
1360-
// only checking for a "real JIT".
1361-
if (config->perf_profiling > 0) {
1362-
(void)PyErr_WarnEx(
1363-
PyExc_RuntimeWarning,
1364-
"JIT deactivated as perf profiling support is active",
1365-
0);
1366-
} else
1367-
#endif
1368-
{
1369-
interp->jit = 1;
1370-
}
1371-
}
1376+
_PyInterpreter_SetJitWithEnvVar(config, interp);
13721377
}
13731378
#endif
13741379

Python/pystate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,9 +1880,9 @@ tstate_delete_common(PyThreadState *tstate, int release_gil)
18801880
// There's only one thread. Re-enable JIT.
18811881
PyThreadState *curr = interp->threads.head;
18821882
if (curr != NULL && curr->prev == NULL && curr->next == NULL) {
1883-
FT_ATOMIC_STORE_UINT8(interp->jit, 1);
1883+
_PyInterpreter_SetJitWithEnvVar(_PyInterpreterState_GetConfig(interp), interp);
18841884
}
1885-
# endif
1885+
# endif
18861886
#endif
18871887

18881888
HEAD_UNLOCK(runtime);

0 commit comments

Comments
 (0)