Skip to content

Commit 398e38f

Browse files
committed
gh-124855: Don't allow the JIT and perf support to be active at the same time
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parent 60ff67d commit 398e38f

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Don't allow the JIT and perf support to be active at the same time. Patch by
2+
Pablo Galindo

Python/pylifecycle.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,14 +1300,21 @@ init_interp_main(PyThreadState *tstate)
13001300
enabled = *env != '0';
13011301
}
13021302
if (enabled) {
1303-
PyObject *opt = _PyOptimizer_NewUOpOptimizer();
1304-
if (opt == NULL) {
1305-
return _PyStatus_ERR("can't initialize optimizer");
1306-
}
1307-
if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) {
1308-
return _PyStatus_ERR("can't install optimizer");
1303+
if (config->perf_profiling > 0) {
1304+
(void)PyErr_WarnEx(
1305+
PyExc_RuntimeWarning,
1306+
"JIT deactivated as perf profiling support is active",
1307+
0);
1308+
} else {
1309+
PyObject *opt = _PyOptimizer_NewUOpOptimizer();
1310+
if (opt == NULL) {
1311+
return _PyStatus_ERR("can't initialize optimizer");
1312+
}
1313+
if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) {
1314+
return _PyStatus_ERR("can't install optimizer");
1315+
}
1316+
Py_DECREF(opt);
13091317
}
1310-
Py_DECREF(opt);
13111318
}
13121319
}
13131320
#endif

Python/sysmodule.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,14 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend)
22872287
/*[clinic end generated code: output=5783cdeb51874b43 input=a12df928758a82b4]*/
22882288
{
22892289
#ifdef PY_HAVE_PERF_TRAMPOLINE
2290+
#ifdef _Py_TIER2
2291+
_PyOptimizerObject* optimizer = _Py_GetOptimizer();
2292+
if (optimizer != NULL) {
2293+
PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampiline if the JIT is active");
2294+
return NULL;
2295+
}
2296+
#endif
2297+
22902298
if (strcmp(backend, "perf") == 0) {
22912299
_PyPerf_Callbacks cur_cb;
22922300
_PyPerfTrampoline_GetCallbacks(&cur_cb);

0 commit comments

Comments
 (0)