Skip to content

Commit 2d37c71

Browse files
authored
gh-124855: Don't allow the JIT and perf support to be active at the same time (#124856)
1 parent 2d9d101 commit 2d37c71

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

Doc/library/sys.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,8 @@ always available.
17571757
Activate the stack profiler trampoline *backend*.
17581758
The only supported backend is ``"perf"``.
17591759

1760+
Stack trampolines cannot be activated if the JIT is active.
1761+
17601762
.. availability:: Linux.
17611763

17621764
.. versionadded:: 3.12
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
@@ -1310,14 +1310,21 @@ init_interp_main(PyThreadState *tstate)
13101310
enabled = *env != '0';
13111311
}
13121312
if (enabled) {
1313-
PyObject *opt = _PyOptimizer_NewUOpOptimizer();
1314-
if (opt == NULL) {
1315-
return _PyStatus_ERR("can't initialize optimizer");
1316-
}
1317-
if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) {
1318-
return _PyStatus_ERR("can't install optimizer");
1313+
if (config->perf_profiling > 0) {
1314+
(void)PyErr_WarnEx(
1315+
PyExc_RuntimeWarning,
1316+
"JIT deactivated as perf profiling support is active",
1317+
0);
1318+
} else {
1319+
PyObject *opt = _PyOptimizer_NewUOpOptimizer();
1320+
if (opt == NULL) {
1321+
return _PyStatus_ERR("can't initialize optimizer");
1322+
}
1323+
if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) {
1324+
return _PyStatus_ERR("can't install optimizer");
1325+
}
1326+
Py_DECREF(opt);
13191327
}
1320-
Py_DECREF(opt);
13211328
}
13221329
}
13231330
#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_JIT
2291+
_PyOptimizerObject* optimizer = _Py_GetOptimizer();
2292+
if (optimizer != NULL) {
2293+
PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampoline 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)