]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-124855: Don't allow the JIT and perf support to be active at the same time (#124856)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Wed, 30 Oct 2024 00:12:45 +0000 (00:12 +0000)
committerGitHub <noreply@github.com>
Wed, 30 Oct 2024 00:12:45 +0000 (00:12 +0000)
Doc/library/sys.rst
Misc/NEWS.d/next/Core_and_Builtins/2024-10-01-17-31-32.gh-issue-124855.sdsv_H.rst [new file with mode: 0644]
Python/pylifecycle.c
Python/sysmodule.c

index 37f1719db607de90df629de2fd61e484aa3feb39..d83816ec1502ca62b3133a2a01d61fba372b2b2d 100644 (file)
@@ -1757,6 +1757,8 @@ always available.
    Activate the stack profiler trampoline *backend*.
    The only supported backend is ``"perf"``.
 
+   Stack trampolines cannot be activated if the JIT is active.
+
    .. availability:: Linux.
 
    .. versionadded:: 3.12
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-01-17-31-32.gh-issue-124855.sdsv_H.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-01-17-31-32.gh-issue-124855.sdsv_H.rst
new file mode 100644 (file)
index 0000000..b65a5e6
--- /dev/null
@@ -0,0 +1,2 @@
+Don't allow the JIT and perf support to be active at the same time. Patch by
+Pablo Galindo
index 8f38fbedae9842f45810aaf1d05290940f8b3f8b..2efaa9db7d7d58092754f71e06518d4cbe49bb20 100644 (file)
@@ -1310,14 +1310,21 @@ init_interp_main(PyThreadState *tstate)
             enabled = *env != '0';
         }
         if (enabled) {
-            PyObject *opt = _PyOptimizer_NewUOpOptimizer();
-            if (opt == NULL) {
-                return _PyStatus_ERR("can't initialize optimizer");
-            }
-            if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) {
-                return _PyStatus_ERR("can't install optimizer");
+            if (config->perf_profiling > 0) {
+                (void)PyErr_WarnEx(
+                    PyExc_RuntimeWarning,
+                    "JIT deactivated as perf profiling support is active",
+                    0);
+            } else {
+                PyObject *opt = _PyOptimizer_NewUOpOptimizer();
+                if (opt == NULL) {
+                    return _PyStatus_ERR("can't initialize optimizer");
+                }
+                if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) {
+                    return _PyStatus_ERR("can't install optimizer");
+                }
+                Py_DECREF(opt);
             }
-            Py_DECREF(opt);
         }
     }
 #endif
index 24af4798eeac3bcb7452f93ce2285c8b7334a84a..cbb73977e1aae60063465ff3c4ef014a0b5c4e73 100644 (file)
@@ -2287,6 +2287,14 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend)
 /*[clinic end generated code: output=5783cdeb51874b43 input=a12df928758a82b4]*/
 {
 #ifdef PY_HAVE_PERF_TRAMPOLINE
+#ifdef _Py_JIT
+    _PyOptimizerObject* optimizer = _Py_GetOptimizer();
+    if (optimizer != NULL) {
+        PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampoline if the JIT is active");
+        return NULL;
+    }
+#endif
+
     if (strcmp(backend, "perf") == 0) {
         _PyPerf_Callbacks cur_cb;
         _PyPerfTrampoline_GetCallbacks(&cur_cb);