Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-126204: Add a sys._jit_enabled helper#126247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
43740f765e6cfa718b21ef4f174820d51dca3e6dda40c001c81994a916184331773d9e9a50db74b4e21219ddff291b7a78e79e0df759321b49e4fdc169831ec83ea491dec18a02d1f60a9c5b415423c7149336ab67123ee4ddcd62aa8f5bb0b5bce80ffcd9fb6c097bb4dc9dc46a4a7fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Allow to determine whether the JIT is enabled at runtime via :func:`sys._jit_enabled`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2264,12 +2264,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) { | ||
| Py_DECREF(optimizer); | ||
| PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampoline if the JIT is active"); | ||
| return NULL; | ||
| #if defined(_Py_TIER2) && (_Py_TIER2 % 2 != 0) | ||
| if (_PySys_JITEnabled()) { | ||
| _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; | ||
| } | ||
| } | ||
| #endif | ||
| @@ -2533,6 +2535,46 @@ PyAPI_FUNC(int) PyUnstable_CopyPerfMapFile(const char* parent_filename) { | ||
| } | ||
| #ifdef _Py_TIER2 | ||
| // _Py_TIER2 is set to 4 or 6 in tier 2 builds. | ||
| #if _Py_TIER2 % 2 != 0 | ||
| int | ||
| _PySys_JITEnabled(void) | ||
| { | ||
| const char *env = Py_GETENV("PYTHON_JIT"); | ||
| if (_Py_TIER2 == 1) { | ||
| // Interpreter was built with enabled jit, but it can be disabled via PYTHON_JIT=0 | ||
| if (env && *env != '\0') { | ||
| return *env != '0'; | ||
| } | ||
| return 1; | ||
| } | ||
| else if (_Py_TIER2 == 3) { | ||
| // Interpreter was built with disabled jit, but it can be enabled via PYTHON_JIT=1 | ||
| if (env && *env != '\0') { | ||
| return *env == '1'; | ||
| } | ||
| return 0; | ||
| } | ||
| Py_UNREACHABLE(); | ||
| } | ||
| /*[clinic input] | ||
| sys._jit_enabled -> bool | ||
| Returns True if JIT is enabled, False otherwise. | ||
| [clinic start generated code]*/ | ||
| static int | ||
| sys__jit_enabled_impl(PyObject *module) | ||
| /*[clinic end generated code: output=e8adca3fa5011880 input=f2bdfa820c11f65b]*/ | ||
| { | ||
| return _PySys_JITEnabled(); | ||
| } | ||
| #endif | ||
| #endif // _Py_TIER2 | ||
| static PyMethodDef sys_methods[] = { | ||
| /* Might as well keep this in alphabetic order */ | ||
| SYS_ADDAUDITHOOK_METHODDEF | ||
| @@ -2603,6 +2645,7 @@ static PyMethodDef sys_methods[] = { | ||
| #endif | ||
| SYS__GET_CPU_COUNT_CONFIG_METHODDEF | ||
| SYS__IS_GIL_ENABLED_METHODDEF | ||
| SYS__JIT_ENABLED_METHODDEF | ||
picnixz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| {NULL, NULL} // sentinel | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fun. Due to incorrect assumptions, where JIT is actually enabled or not, this hack is no longer needed. Just setting PYTHON_JIT=0 is enough here.