diff options
author | Mark Shannon <mark@hotpy.org> | 2023-06-22 08:48:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 08:48:19 (GMT) |
commit | 04492cbc9aa45ac2c12d22083c406a0364c39f5b (patch) | |
tree | 4eb26dc0dca29519cabe1086aec523bc29e8f4b5 /Include | |
parent | c01da2896ab92ba7193bcd6ae56908c5c7277e75 (diff) | |
download | cpython-04492cbc9aa45ac2c12d22083c406a0364c39f5b.zip cpython-04492cbc9aa45ac2c12d22083c406a0364c39f5b.tar.gz cpython-04492cbc9aa45ac2c12d22083c406a0364c39f5b.tar.bz2 |
GH-91095: Specialize calls to normal Python classes. (GH-99331)
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/object.h | 1 | ||||
-rw-r--r-- | Include/internal/pycore_frame.h | 24 | ||||
-rw-r--r-- | Include/internal/pycore_object.h | 2 | ||||
-rw-r--r-- | Include/internal/pycore_opcode.h | 46 | ||||
-rw-r--r-- | Include/opcode.h | 108 |
5 files changed, 105 insertions, 76 deletions
diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 7d69231..71d268f 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -246,6 +246,7 @@ struct _specialization_cache { // *args nor **kwargs (as required by BINARY_SUBSCR_GETITEM): PyObject *getitem; uint32_t getitem_version; + PyObject *init; }; /* The *real* layout of a type object when allocated on the heap */ diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index caff86c..952a960 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -272,6 +272,30 @@ _PyFrame_PushUnchecked(PyThreadState *tstate, PyFunctionObject *func, int null_l return new_frame; } +/* Pushes a trampoline frame without checking for space. + * Must be guarded by _PyThreadState_HasStackSpace() */ +static inline _PyInterpreterFrame * +_PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int stackdepth, int prev_instr) +{ + CALL_STAT_INC(frames_pushed); + _PyInterpreterFrame *frame = (_PyInterpreterFrame *)tstate->datastack_top; + tstate->datastack_top += code->co_framesize; + assert(tstate->datastack_top < tstate->datastack_limit); + frame->f_funcobj = Py_None; + frame->f_executable = Py_NewRef(code); +#ifdef Py_DEBUG + frame->f_builtins = NULL; + frame->f_globals = NULL; +#endif + frame->f_locals = NULL; + frame->stacktop = code->co_nlocalsplus + stackdepth; + frame->frame_obj = NULL; + frame->prev_instr = _PyCode_CODE(code) + prev_instr; + frame->owner = FRAME_OWNED_BY_THREAD; + frame->return_offset = 0; + return frame; +} + static inline PyGenObject *_PyFrame_GetGenerator(_PyInterpreterFrame *frame) { diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 3ac7e89..2358f48 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -355,8 +355,10 @@ static inline int _PyType_SUPPORTS_WEAKREFS(PyTypeObject *type) { } extern PyObject* _PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems); +PyObject *_PyType_NewManagedObject(PyTypeObject *type); extern int _PyObject_InitializeDict(PyObject *obj); +int _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp); extern int _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values, PyObject *name, PyObject *value); PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values, diff --git a/Include/internal/pycore_opcode.h b/Include/internal/pycore_opcode.h index 6b269e3..cab5b58 100644 --- a/Include/internal/pycore_opcode.h +++ b/Include/internal/pycore_opcode.h @@ -68,6 +68,7 @@ const uint8_t _PyOpcode_Deopt[256] = { [CALL_INTRINSIC_1] = CALL_INTRINSIC_1, [CALL_INTRINSIC_2] = CALL_INTRINSIC_2, [CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS] = CALL, + [CALL_NO_KW_ALLOC_AND_ENTER_INIT] = CALL, [CALL_NO_KW_BUILTIN_FAST] = CALL, [CALL_NO_KW_BUILTIN_O] = CALL, [CALL_NO_KW_ISINSTANCE] = CALL, @@ -104,6 +105,7 @@ const uint8_t _PyOpcode_Deopt[256] = { [END_FOR] = END_FOR, [END_SEND] = END_SEND, [ENTER_EXECUTOR] = ENTER_EXECUTOR, + [EXIT_INIT_CHECK] = EXIT_INIT_CHECK, [EXTENDED_ARG] = EXTENDED_ARG, [FORMAT_SIMPLE] = FORMAT_SIMPLE, [FORMAT_WITH_SPEC] = FORMAT_WITH_SPEC, @@ -251,39 +253,39 @@ static const char *const _PyOpcode_OpName[267] = { [BINARY_OP_ADD_FLOAT] = "BINARY_OP_ADD_FLOAT", [BINARY_OP_SUBTRACT_FLOAT] = "BINARY_OP_SUBTRACT_FLOAT", [UNARY_INVERT] = "UNARY_INVERT", - [BINARY_OP_ADD_UNICODE] = "BINARY_OP_ADD_UNICODE", + [EXIT_INIT_CHECK] = "EXIT_INIT_CHECK", [RESERVED] = "RESERVED", + [BINARY_OP_ADD_UNICODE] = "BINARY_OP_ADD_UNICODE", [BINARY_OP_INPLACE_ADD_UNICODE] = "BINARY_OP_INPLACE_ADD_UNICODE", [BINARY_SUBSCR_DICT] = "BINARY_SUBSCR_DICT", [BINARY_SUBSCR_GETITEM] = "BINARY_SUBSCR_GETITEM", [BINARY_SUBSCR_LIST_INT] = "BINARY_SUBSCR_LIST_INT", [BINARY_SUBSCR_TUPLE_INT] = "BINARY_SUBSCR_TUPLE_INT", - [STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT", [MAKE_FUNCTION] = "MAKE_FUNCTION", [BINARY_SUBSCR] = "BINARY_SUBSCR", [BINARY_SLICE] = "BINARY_SLICE", [STORE_SLICE] = "STORE_SLICE", + [STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT", [STORE_SUBSCR_LIST_INT] = "STORE_SUBSCR_LIST_INT", - [SEND_GEN] = "SEND_GEN", [GET_LEN] = "GET_LEN", [MATCH_MAPPING] = "MATCH_MAPPING", [MATCH_SEQUENCE] = "MATCH_SEQUENCE", [MATCH_KEYS] = "MATCH_KEYS", - [UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE", + [SEND_GEN] = "SEND_GEN", [PUSH_EXC_INFO] = "PUSH_EXC_INFO", [CHECK_EXC_MATCH] = "CHECK_EXC_MATCH", [CHECK_EG_MATCH] = "CHECK_EG_MATCH", + [UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE", [UNPACK_SEQUENCE_TUPLE] = "UNPACK_SEQUENCE_TUPLE", - [UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST", [FORMAT_SIMPLE] = "FORMAT_SIMPLE", [FORMAT_WITH_SPEC] = "FORMAT_WITH_SPEC", + [UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST", [STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE", [STORE_ATTR_SLOT] = "STORE_ATTR_SLOT", [STORE_ATTR_WITH_HINT] = "STORE_ATTR_WITH_HINT", [LOAD_GLOBAL_MODULE] = "LOAD_GLOBAL_MODULE", [LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN", [LOAD_SUPER_ATTR_ATTR] = "LOAD_SUPER_ATTR_ATTR", - [LOAD_SUPER_ATTR_METHOD] = "LOAD_SUPER_ATTR_METHOD", [WITH_EXCEPT_START] = "WITH_EXCEPT_START", [GET_AITER] = "GET_AITER", [GET_ANEXT] = "GET_ANEXT", @@ -291,39 +293,39 @@ static const char *const _PyOpcode_OpName[267] = { [BEFORE_WITH] = "BEFORE_WITH", [END_ASYNC_FOR] = "END_ASYNC_FOR", [CLEANUP_THROW] = "CLEANUP_THROW", + [LOAD_SUPER_ATTR_METHOD] = "LOAD_SUPER_ATTR_METHOD", [LOAD_ATTR_INSTANCE_VALUE] = "LOAD_ATTR_INSTANCE_VALUE", [LOAD_ATTR_MODULE] = "LOAD_ATTR_MODULE", [LOAD_ATTR_WITH_HINT] = "LOAD_ATTR_WITH_HINT", - [LOAD_ATTR_SLOT] = "LOAD_ATTR_SLOT", [STORE_SUBSCR] = "STORE_SUBSCR", [DELETE_SUBSCR] = "DELETE_SUBSCR", + [LOAD_ATTR_SLOT] = "LOAD_ATTR_SLOT", [LOAD_ATTR_CLASS] = "LOAD_ATTR_CLASS", [LOAD_ATTR_PROPERTY] = "LOAD_ATTR_PROPERTY", [LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = "LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN", [LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES", [LOAD_ATTR_METHOD_NO_DICT] = "LOAD_ATTR_METHOD_NO_DICT", - [LOAD_ATTR_METHOD_LAZY_DICT] = "LOAD_ATTR_METHOD_LAZY_DICT", [GET_ITER] = "GET_ITER", [GET_YIELD_FROM_ITER] = "GET_YIELD_FROM_ITER", - [COMPARE_OP_FLOAT] = "COMPARE_OP_FLOAT", + [LOAD_ATTR_METHOD_LAZY_DICT] = "LOAD_ATTR_METHOD_LAZY_DICT", [LOAD_BUILD_CLASS] = "LOAD_BUILD_CLASS", + [COMPARE_OP_FLOAT] = "COMPARE_OP_FLOAT", [COMPARE_OP_INT] = "COMPARE_OP_INT", - [COMPARE_OP_STR] = "COMPARE_OP_STR", [LOAD_ASSERTION_ERROR] = "LOAD_ASSERTION_ERROR", [RETURN_GENERATOR] = "RETURN_GENERATOR", + [COMPARE_OP_STR] = "COMPARE_OP_STR", [FOR_ITER_LIST] = "FOR_ITER_LIST", [FOR_ITER_TUPLE] = "FOR_ITER_TUPLE", [FOR_ITER_RANGE] = "FOR_ITER_RANGE", [FOR_ITER_GEN] = "FOR_ITER_GEN", [CALL_BOUND_METHOD_EXACT_ARGS] = "CALL_BOUND_METHOD_EXACT_ARGS", [CALL_PY_EXACT_ARGS] = "CALL_PY_EXACT_ARGS", - [CALL_PY_WITH_DEFAULTS] = "CALL_PY_WITH_DEFAULTS", [RETURN_VALUE] = "RETURN_VALUE", - [CALL_NO_KW_TYPE_1] = "CALL_NO_KW_TYPE_1", + [CALL_PY_WITH_DEFAULTS] = "CALL_PY_WITH_DEFAULTS", [SETUP_ANNOTATIONS] = "SETUP_ANNOTATIONS", - [CALL_NO_KW_STR_1] = "CALL_NO_KW_STR_1", + [CALL_NO_KW_TYPE_1] = "CALL_NO_KW_TYPE_1", [LOAD_LOCALS] = "LOAD_LOCALS", - [CALL_NO_KW_TUPLE_1] = "CALL_NO_KW_TUPLE_1", + [CALL_NO_KW_STR_1] = "CALL_NO_KW_STR_1", [POP_EXCEPT] = "POP_EXCEPT", [STORE_NAME] = "STORE_NAME", [DELETE_NAME] = "DELETE_NAME", @@ -346,9 +348,9 @@ static const char *const _PyOpcode_OpName[267] = { [IMPORT_NAME] = "IMPORT_NAME", [IMPORT_FROM] = "IMPORT_FROM", [JUMP_FORWARD] = "JUMP_FORWARD", + [CALL_NO_KW_TUPLE_1] = "CALL_NO_KW_TUPLE_1", [CALL_BUILTIN_CLASS] = "CALL_BUILTIN_CLASS", [CALL_NO_KW_BUILTIN_O] = "CALL_NO_KW_BUILTIN_O", - [CALL_NO_KW_BUILTIN_FAST] = "CALL_NO_KW_BUILTIN_FAST", [POP_JUMP_IF_FALSE] = "POP_JUMP_IF_FALSE", [POP_JUMP_IF_TRUE] = "POP_JUMP_IF_TRUE", [LOAD_GLOBAL] = "LOAD_GLOBAL", @@ -367,7 +369,7 @@ static const char *const _PyOpcode_OpName[267] = { [POP_JUMP_IF_NONE] = "POP_JUMP_IF_NONE", [RAISE_VARARGS] = "RAISE_VARARGS", [GET_AWAITABLE] = "GET_AWAITABLE", - [CALL_BUILTIN_FAST_WITH_KEYWORDS] = "CALL_BUILTIN_FAST_WITH_KEYWORDS", + [CALL_NO_KW_BUILTIN_FAST] = "CALL_NO_KW_BUILTIN_FAST", [BUILD_SLICE] = "BUILD_SLICE", [JUMP_BACKWARD_NO_INTERRUPT] = "JUMP_BACKWARD_NO_INTERRUPT", [MAKE_CELL] = "MAKE_CELL", @@ -383,26 +385,26 @@ static const char *const _PyOpcode_OpName[267] = { [LIST_APPEND] = "LIST_APPEND", [SET_ADD] = "SET_ADD", [MAP_ADD] = "MAP_ADD", - [CALL_NO_KW_LEN] = "CALL_NO_KW_LEN", + [CALL_BUILTIN_FAST_WITH_KEYWORDS] = "CALL_BUILTIN_FAST_WITH_KEYWORDS", [COPY_FREE_VARS] = "COPY_FREE_VARS", [YIELD_VALUE] = "YIELD_VALUE", [RESUME] = "RESUME", [MATCH_CLASS] = "MATCH_CLASS", + [CALL_NO_KW_LEN] = "CALL_NO_KW_LEN", [CALL_NO_KW_ISINSTANCE] = "CALL_NO_KW_ISINSTANCE", [CALL_NO_KW_LIST_APPEND] = "CALL_NO_KW_LIST_APPEND", - [CALL_NO_KW_METHOD_DESCRIPTOR_O] = "CALL_NO_KW_METHOD_DESCRIPTOR_O", [BUILD_CONST_KEY_MAP] = "BUILD_CONST_KEY_MAP", [BUILD_STRING] = "BUILD_STRING", [CONVERT_VALUE] = "CONVERT_VALUE", + [CALL_NO_KW_METHOD_DESCRIPTOR_O] = "CALL_NO_KW_METHOD_DESCRIPTOR_O", [CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS] = "CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS", [CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS] = "CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS", - [CALL_NO_KW_METHOD_DESCRIPTOR_FAST] = "CALL_NO_KW_METHOD_DESCRIPTOR_FAST", [LIST_EXTEND] = "LIST_EXTEND", [SET_UPDATE] = "SET_UPDATE", [DICT_MERGE] = "DICT_MERGE", [DICT_UPDATE] = "DICT_UPDATE", - [166] = "<166>", - [167] = "<167>", + [CALL_NO_KW_METHOD_DESCRIPTOR_FAST] = "CALL_NO_KW_METHOD_DESCRIPTOR_FAST", + [CALL_NO_KW_ALLOC_AND_ENTER_INIT] = "CALL_NO_KW_ALLOC_AND_ENTER_INIT", [LOAD_FAST_LOAD_FAST] = "LOAD_FAST_LOAD_FAST", [STORE_FAST_LOAD_FAST] = "STORE_FAST_LOAD_FAST", [STORE_FAST_STORE_FAST] = "STORE_FAST_STORE_FAST", @@ -506,8 +508,6 @@ static const char *const _PyOpcode_OpName[267] = { #endif #define EXTRA_CASES \ - case 166: \ - case 167: \ case 178: \ case 179: \ case 180: \ diff --git a/Include/opcode.h b/Include/opcode.h index 39bb70a..3fe4fc0 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -18,6 +18,7 @@ extern "C" { #define UNARY_NEGATIVE 11 #define UNARY_NOT 12 #define UNARY_INVERT 15 +#define EXIT_INIT_CHECK 16 #define RESERVED 17 #define MAKE_FUNCTION 24 #define BINARY_SUBSCR 25 @@ -164,59 +165,60 @@ extern "C" { #define BINARY_OP_MULTIPLY_FLOAT 10 #define BINARY_OP_ADD_FLOAT 13 #define BINARY_OP_SUBTRACT_FLOAT 14 -#define BINARY_OP_ADD_UNICODE 16 -#define BINARY_OP_INPLACE_ADD_UNICODE 18 -#define BINARY_SUBSCR_DICT 19 -#define BINARY_SUBSCR_GETITEM 20 -#define BINARY_SUBSCR_LIST_INT 21 -#define BINARY_SUBSCR_TUPLE_INT 22 -#define STORE_SUBSCR_DICT 23 -#define STORE_SUBSCR_LIST_INT 28 -#define SEND_GEN 29 -#define UNPACK_SEQUENCE_TWO_TUPLE 34 -#define UNPACK_SEQUENCE_TUPLE 38 -#define UNPACK_SEQUENCE_LIST 39 -#define STORE_ATTR_INSTANCE_VALUE 42 -#define STORE_ATTR_SLOT 43 -#define STORE_ATTR_WITH_HINT 44 -#define LOAD_GLOBAL_MODULE 45 -#define LOAD_GLOBAL_BUILTIN 46 -#define LOAD_SUPER_ATTR_ATTR 47 -#define LOAD_SUPER_ATTR_METHOD 48 -#define LOAD_ATTR_INSTANCE_VALUE 56 -#define LOAD_ATTR_MODULE 57 -#define LOAD_ATTR_WITH_HINT 58 -#define LOAD_ATTR_SLOT 59 -#define LOAD_ATTR_CLASS 62 -#define LOAD_ATTR_PROPERTY 63 -#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 64 -#define LOAD_ATTR_METHOD_WITH_VALUES 65 -#define LOAD_ATTR_METHOD_NO_DICT 66 -#define LOAD_ATTR_METHOD_LAZY_DICT 67 -#define COMPARE_OP_FLOAT 70 -#define COMPARE_OP_INT 72 -#define COMPARE_OP_STR 73 -#define FOR_ITER_LIST 76 -#define FOR_ITER_TUPLE 77 -#define FOR_ITER_RANGE 78 -#define FOR_ITER_GEN 79 -#define CALL_BOUND_METHOD_EXACT_ARGS 80 -#define CALL_PY_EXACT_ARGS 81 -#define CALL_PY_WITH_DEFAULTS 82 -#define CALL_NO_KW_TYPE_1 84 -#define CALL_NO_KW_STR_1 86 -#define CALL_NO_KW_TUPLE_1 88 -#define CALL_BUILTIN_CLASS 111 -#define CALL_NO_KW_BUILTIN_O 112 -#define CALL_NO_KW_BUILTIN_FAST 113 -#define CALL_BUILTIN_FAST_WITH_KEYWORDS 132 -#define CALL_NO_KW_LEN 148 -#define CALL_NO_KW_ISINSTANCE 153 -#define CALL_NO_KW_LIST_APPEND 154 -#define CALL_NO_KW_METHOD_DESCRIPTOR_O 155 -#define CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 159 -#define CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS 160 -#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST 161 +#define BINARY_OP_ADD_UNICODE 18 +#define BINARY_OP_INPLACE_ADD_UNICODE 19 +#define BINARY_SUBSCR_DICT 20 +#define BINARY_SUBSCR_GETITEM 21 +#define BINARY_SUBSCR_LIST_INT 22 +#define BINARY_SUBSCR_TUPLE_INT 23 +#define STORE_SUBSCR_DICT 28 +#define STORE_SUBSCR_LIST_INT 29 +#define SEND_GEN 34 +#define UNPACK_SEQUENCE_TWO_TUPLE 38 +#define UNPACK_SEQUENCE_TUPLE 39 +#define UNPACK_SEQUENCE_LIST 42 +#define STORE_ATTR_INSTANCE_VALUE 43 +#define STORE_ATTR_SLOT 44 +#define STORE_ATTR_WITH_HINT 45 +#define LOAD_GLOBAL_MODULE 46 +#define LOAD_GLOBAL_BUILTIN 47 +#define LOAD_SUPER_ATTR_ATTR 48 +#define LOAD_SUPER_ATTR_METHOD 56 +#define LOAD_ATTR_INSTANCE_VALUE 57 +#define LOAD_ATTR_MODULE 58 +#define LOAD_ATTR_WITH_HINT 59 +#define LOAD_ATTR_SLOT 62 +#define LOAD_ATTR_CLASS 63 +#define LOAD_ATTR_PROPERTY 64 +#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 65 +#define LOAD_ATTR_METHOD_WITH_VALUES 66 +#define LOAD_ATTR_METHOD_NO_DICT 67 +#define LOAD_ATTR_METHOD_LAZY_DICT 70 +#define COMPARE_OP_FLOAT 72 +#define COMPARE_OP_INT 73 +#define COMPARE_OP_STR 76 +#define FOR_ITER_LIST 77 +#define FOR_ITER_TUPLE 78 +#define FOR_ITER_RANGE 79 +#define FOR_ITER_GEN 80 +#define CALL_BOUND_METHOD_EXACT_ARGS 81 +#define CALL_PY_EXACT_ARGS 82 +#define CALL_PY_WITH_DEFAULTS 84 +#define CALL_NO_KW_TYPE_1 86 +#define CALL_NO_KW_STR_1 88 +#define CALL_NO_KW_TUPLE_1 111 +#define CALL_BUILTIN_CLASS 112 +#define CALL_NO_KW_BUILTIN_O 113 +#define CALL_NO_KW_BUILTIN_FAST 132 +#define CALL_BUILTIN_FAST_WITH_KEYWORDS 148 +#define CALL_NO_KW_LEN 153 +#define CALL_NO_KW_ISINSTANCE 154 +#define CALL_NO_KW_LIST_APPEND 155 +#define CALL_NO_KW_METHOD_DESCRIPTOR_O 159 +#define CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 160 +#define CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS 161 +#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST 166 +#define CALL_NO_KW_ALLOC_AND_ENTER_INIT 167 #define NB_ADD 0 #define NB_AND 1 |