mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
GH-133231: Add JIT utilities in sys._jit (GH-133233)
This commit is contained in:
parent
f9b22bb79d
commit
b1aa515bd6
11 changed files with 296 additions and 54 deletions
86
Python/clinic/sysmodule.c.h
generated
86
Python/clinic/sysmodule.c.h
generated
|
|
@ -1821,6 +1821,90 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_jit_is_available__doc__,
|
||||
"is_available($module, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return True if the current Python executable supports JIT compilation, and False otherwise.");
|
||||
|
||||
#define _JIT_IS_AVAILABLE_METHODDEF \
|
||||
{"is_available", (PyCFunction)_jit_is_available, METH_NOARGS, _jit_is_available__doc__},
|
||||
|
||||
static int
|
||||
_jit_is_available_impl(PyObject *module);
|
||||
|
||||
static PyObject *
|
||||
_jit_is_available(PyObject *module, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int _return_value;
|
||||
|
||||
_return_value = _jit_is_available_impl(module);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyBool_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_jit_is_enabled__doc__,
|
||||
"is_enabled($module, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return True if JIT compilation is enabled for the current Python process (implies sys._jit.is_available()), and False otherwise.");
|
||||
|
||||
#define _JIT_IS_ENABLED_METHODDEF \
|
||||
{"is_enabled", (PyCFunction)_jit_is_enabled, METH_NOARGS, _jit_is_enabled__doc__},
|
||||
|
||||
static int
|
||||
_jit_is_enabled_impl(PyObject *module);
|
||||
|
||||
static PyObject *
|
||||
_jit_is_enabled(PyObject *module, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int _return_value;
|
||||
|
||||
_return_value = _jit_is_enabled_impl(module);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyBool_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_jit_is_active__doc__,
|
||||
"is_active($module, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return True if the topmost Python frame is currently executing JIT code (implies sys._jit.is_enabled()), and False otherwise.");
|
||||
|
||||
#define _JIT_IS_ACTIVE_METHODDEF \
|
||||
{"is_active", (PyCFunction)_jit_is_active, METH_NOARGS, _jit_is_active__doc__},
|
||||
|
||||
static int
|
||||
_jit_is_active_impl(PyObject *module);
|
||||
|
||||
static PyObject *
|
||||
_jit_is_active(PyObject *module, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int _return_value;
|
||||
|
||||
_return_value = _jit_is_active_impl(module);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyBool_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
#ifndef SYS_GETWINDOWSVERSION_METHODDEF
|
||||
#define SYS_GETWINDOWSVERSION_METHODDEF
|
||||
#endif /* !defined(SYS_GETWINDOWSVERSION_METHODDEF) */
|
||||
|
|
@ -1864,4 +1948,4 @@ exit:
|
|||
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#define SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
|
||||
/*[clinic end generated code: output=1aca52cefbeb800f input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=449d16326e69dcf6 input=a9049054013a1b77]*/
|
||||
|
|
|
|||
|
|
@ -3986,6 +3986,71 @@ _PySys_SetPreliminaryStderr(PyObject *sysdict)
|
|||
|
||||
PyObject *_Py_CreateMonitoringObject(void);
|
||||
|
||||
/*[clinic input]
|
||||
module _jit
|
||||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=10952f74d7bbd972]*/
|
||||
|
||||
PyDoc_STRVAR(_jit_doc, "Utilities for observing just-in-time compilation.");
|
||||
|
||||
/*[clinic input]
|
||||
_jit.is_available -> bool
|
||||
Return True if the current Python executable supports JIT compilation, and False otherwise.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_jit_is_available_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=6849a9cd2ff4aac9 input=03add84aa8347cf1]*/
|
||||
{
|
||||
(void)module;
|
||||
#ifdef _Py_TIER2
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_jit.is_enabled -> bool
|
||||
Return True if JIT compilation is enabled for the current Python process (implies sys._jit.is_available()), and False otherwise.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_jit_is_enabled_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=55865f8de993fe42 input=02439394da8e873f]*/
|
||||
{
|
||||
(void)module;
|
||||
return _PyInterpreterState_GET()->jit;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_jit.is_active -> bool
|
||||
Return True if the topmost Python frame is currently executing JIT code (implies sys._jit.is_enabled()), and False otherwise.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_jit_is_active_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=7facca06b10064d4 input=be2fcd8a269d9b72]*/
|
||||
{
|
||||
(void)module;
|
||||
return _PyThreadState_GET()->current_executor != NULL;
|
||||
}
|
||||
|
||||
static PyMethodDef _jit_methods[] = {
|
||||
_JIT_IS_AVAILABLE_METHODDEF
|
||||
_JIT_IS_ENABLED_METHODDEF
|
||||
_JIT_IS_ACTIVE_METHODDEF
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef _jit_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
.m_name = "sys._jit",
|
||||
.m_doc = _jit_doc,
|
||||
.m_size = -1,
|
||||
.m_methods = _jit_methods,
|
||||
};
|
||||
|
||||
/* Create sys module without all attributes.
|
||||
_PySys_UpdateConfig() should be called later to add remaining attributes. */
|
||||
PyStatus
|
||||
|
|
@ -4047,6 +4112,16 @@ _PySys_Create(PyThreadState *tstate, PyObject **sysmod_p)
|
|||
goto error;
|
||||
}
|
||||
|
||||
PyObject *_jit = _PyModule_CreateInitialized(&_jit_module, PYTHON_API_VERSION);
|
||||
if (_jit == NULL) {
|
||||
goto error;
|
||||
}
|
||||
err = PyDict_SetItemString(sysdict, "_jit", _jit);
|
||||
Py_DECREF(_jit);
|
||||
if (err) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
assert(!_PyErr_Occurred(tstate));
|
||||
|
||||
*sysmod_p = sysmod;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue