From 1f1b554113accf48d3d0cd086c43446d6a6bca44 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:35:13 +0800 Subject: [PATCH 1/8] Fix failing tier 2 interpreter tests on main --- Python/pylifecycle.c | 5 ++++- Python/sysmodule.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 2efaa9db7d7d58..31ccd0db768e1e 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1310,12 +1310,15 @@ init_interp_main(PyThreadState *tstate) enabled = *env != '0'; } if (enabled) { +#ifdef _Py_JIT if (config->perf_profiling > 0) { (void)PyErr_WarnEx( PyExc_RuntimeWarning, "JIT deactivated as perf profiling support is active", 0); - } else { + } else +#endif + { PyObject *opt = _PyOptimizer_NewUOpOptimizer(); if (opt == NULL) { return _PyStatus_ERR("can't initialize optimizer"); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index cbb73977e1aae6..a4abd7c3c45709 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2290,6 +2290,7 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend) #ifdef _Py_JIT _PyOptimizerObject* optimizer = _Py_GetOptimizer(); if (optimizer != NULL) { + Py_DECREF(optimizer); PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampoline if the JIT is active"); return NULL; } From 636975df2ab38d2702e007cc8e6e7b3322ebe619 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:36:36 +0800 Subject: [PATCH 2/8] Update jit.yml --- .github/workflows/jit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 754f179f105591..6469d88b25197a 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -5,6 +5,7 @@ on: - '**jit**' - 'Python/bytecodes.c' - 'Python/optimizer*.c' + - 'Python/pylifecycle.c' - '!Python/perf_jit_trampoline.c' - '!**/*.md' - '!**/*.ini' @@ -13,6 +14,7 @@ on: - '**jit**' - 'Python/bytecodes.c' - 'Python/optimizer*.c' + - 'Python/pylifecycle.c' - '!Python/perf_jit_trampoline.c' - '!**/*.md' - '!**/*.ini' From e1cb96f47e6de5d39829c96427a29e7d3c0503fa Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:16:18 +0800 Subject: [PATCH 3/8] fix failing test --- Lib/test/test_embed.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 4ea43edccda63e..688848bdd45d25 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1768,6 +1768,8 @@ def test_init_set_config(self): self.check_all_configs("test_init_set_config", config, api=API_ISOLATED) + @unittest.skipIf("-D_Py_JIT" in (sysconfig.get_config_var('PY_CORE_CFLAGS') or ''), + "JIT and perf don't work together") def test_initconfig_api(self): preconfig = { 'configure_locale': True, From 8ed27a063060cb04523692f4a610bf5953455605 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Wed, 30 Oct 2024 11:37:41 +0000 Subject: [PATCH 4/8] Fix tests Signed-off-by: Pablo Galindo --- Lib/test/test_embed.py | 4 +--- Lib/test/test_perf_profiler.py | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 688848bdd45d25..7089bc6497a24b 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1768,8 +1768,6 @@ def test_init_set_config(self): self.check_all_configs("test_init_set_config", config, api=API_ISOLATED) - @unittest.skipIf("-D_Py_JIT" in (sysconfig.get_config_var('PY_CORE_CFLAGS') or ''), - "JIT and perf don't work together") def test_initconfig_api(self): preconfig = { 'configure_locale': True, @@ -1783,7 +1781,7 @@ def test_initconfig_api(self): } config_dev_mode(preconfig, config) self.check_all_configs("test_initconfig_api", config, preconfig, - api=API_ISOLATED) + api=API_ISOLATED, env={'PYTHON_JIT': '0'}) def test_initconfig_get_api(self): self.run_embedded_interpreter("test_initconfig_get_api") diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py index b55d441759eb69..1e74990878007a 100644 --- a/Lib/test/test_perf_profiler.py +++ b/Lib/test/test_perf_profiler.py @@ -210,14 +210,14 @@ def test_sys_api_with_existing_trampoline(self): sys.activate_stack_trampoline("perf") sys.activate_stack_trampoline("perf") """ - assert_python_ok("-c", code) + assert_python_ok("-c", code, PYTHON_JIT="0") def test_sys_api_with_invalid_trampoline(self): code = """if 1: import sys sys.activate_stack_trampoline("invalid") """ - rc, out, err = assert_python_failure("-c", code) + rc, out, err = assert_python_failure("-c", code, PYTHON_JIT="0") self.assertIn("invalid backend: invalid", err.decode()) def test_sys_api_get_status(self): @@ -228,7 +228,7 @@ def test_sys_api_get_status(self): sys.deactivate_stack_trampoline() assert sys.is_stack_trampoline_active() is False """ - assert_python_ok("-c", code) + assert_python_ok("-c", code, PYTHON_JIT="0") def is_unwinding_reliable_with_frame_pointers(): From f6e67450dba734f4ceeffd4959b0558b2f042928 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Wed, 30 Oct 2024 13:54:43 +0000 Subject: [PATCH 5/8] fix --- Lib/test/test_embed.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 7089bc6497a24b..f2ec2244107e37 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1780,8 +1780,11 @@ def test_initconfig_api(self): 'perf_profiling': 2, } config_dev_mode(preconfig, config) + is_using_jit = "-D_Py_JIT" in (sysconfig.get_config_var('PY_CORE_CFLAGS') or '') + if is_using_jit: + stderr = ":0: RuntimeWarning: JIT deactivated as perf profiling support is active" self.check_all_configs("test_initconfig_api", config, preconfig, - api=API_ISOLATED, env={'PYTHON_JIT': '0'}) + api=API_ISOLATED, env={'PYTHON_JIT': '0'}, stderr=stderr) def test_initconfig_get_api(self): self.run_embedded_interpreter("test_initconfig_get_api") From c1a2ba4ec42e60dd56aa5759765df75d610bef9b Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:56:58 +0800 Subject: [PATCH 6/8] fix --- Lib/test/test_embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index f2ec2244107e37..28cab2e203271c 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1784,7 +1784,7 @@ def test_initconfig_api(self): if is_using_jit: stderr = ":0: RuntimeWarning: JIT deactivated as perf profiling support is active" self.check_all_configs("test_initconfig_api", config, preconfig, - api=API_ISOLATED, env={'PYTHON_JIT': '0'}, stderr=stderr) + api=API_ISOLATED, env={'PYTHON_JIT': '0'}, stderr=sys.stderr) def test_initconfig_get_api(self): self.run_embedded_interpreter("test_initconfig_get_api") From 491e16154de100379271918099f7dae8ff945257 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 23:06:21 +0800 Subject: [PATCH 7/8] woops --- Lib/test/test_embed.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 28cab2e203271c..e721df6a4ddc8a 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1783,8 +1783,10 @@ def test_initconfig_api(self): is_using_jit = "-D_Py_JIT" in (sysconfig.get_config_var('PY_CORE_CFLAGS') or '') if is_using_jit: stderr = ":0: RuntimeWarning: JIT deactivated as perf profiling support is active" + else: + stderr = "" self.check_all_configs("test_initconfig_api", config, preconfig, - api=API_ISOLATED, env={'PYTHON_JIT': '0'}, stderr=sys.stderr) + api=API_ISOLATED, env={'PYTHON_JIT': '0'}, stderr=stderr) def test_initconfig_get_api(self): self.run_embedded_interpreter("test_initconfig_get_api") From 329ad20af15e31d501d8e37e8a1596e9151b2ac9 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 30 Oct 2024 23:45:47 +0800 Subject: [PATCH 8/8] try fix for Windows? --- Lib/test/test_embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index e721df6a4ddc8a..39bcac6ea3a6f5 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1780,7 +1780,7 @@ def test_initconfig_api(self): 'perf_profiling': 2, } config_dev_mode(preconfig, config) - is_using_jit = "-D_Py_JIT" in (sysconfig.get_config_var('PY_CORE_CFLAGS') or '') + is_using_jit = "_Py_JIT" in (sysconfig.get_config_var('PY_CORE_CFLAGS') or '') if is_using_jit: stderr = ":0: RuntimeWarning: JIT deactivated as perf profiling support is active" else: