mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-115999: Stop the world when invalidating function versions (#124997)
Stop the world when invalidating function versions The tier1 interpreter specializes `CALL` instructions based on the values of certain function attributes (e.g. `__code__`, `__defaults__`). The tier1 interpreter uses function versions to verify that the attributes of a function during execution of a specialization match those seen during specialization. A function's version is initialized in `MAKE_FUNCTION` and is invalidated when any of the critical function attributes are changed. The tier1 interpreter stores the function version in the inline cache during specialization. A guard is used by the specialized instruction to verify that the version of the function on the operand stack matches the cached version (and therefore has all of the expected attributes). It is assumed that once the guard passes, all attributes will remain unchanged while executing the rest of the specialized instruction. Stopping the world when invalidating function versions ensures that all critical function attributes will remain unchanged after the function version guard passes in free-threaded builds. It's important to note that this is only true if the remainder of the specialized instruction does not enter and exit a stop-the-world point. We will stop the world the first time any of the following function attributes are mutated: - defaults - vectorcall - kwdefaults - closure - code This should happen rarely and only happens once per function, so the performance impact on majority of code should be minimal. Additionally, refactor the API for manipulating function versions to more clearly match the stated semantics.
This commit is contained in:
parent
65ce228d63
commit
e99f159be4
4 changed files with 74 additions and 40 deletions
|
@ -11,6 +11,7 @@ extern "C" {
|
|||
#include "pycore_ceval_state.h" // _PyEval_RUNTIME_PERF_INIT
|
||||
#include "pycore_faulthandler.h" // _faulthandler_runtime_state_INIT
|
||||
#include "pycore_floatobject.h" // _py_float_format_unknown
|
||||
#include "pycore_function.h"
|
||||
#include "pycore_object.h" // _PyObject_HEAD_INIT
|
||||
#include "pycore_obmalloc_init.h" // _obmalloc_global_state_INIT
|
||||
#include "pycore_parser.h" // _parser_runtime_state_INIT
|
||||
|
@ -243,7 +244,7 @@ extern PyTypeObject _PyExc_MemoryError;
|
|||
.dict_state = _dict_state_INIT, \
|
||||
.mem_free_queue = _Py_mem_free_queue_INIT(INTERP.mem_free_queue), \
|
||||
.func_state = { \
|
||||
.next_version = 1, \
|
||||
.next_version = FUNC_VERSION_FIRST_VALID, \
|
||||
}, \
|
||||
.types = { \
|
||||
.next_version_tag = _Py_TYPE_BASE_VERSION_TAG, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue