diff options
| author | Mark Shannon <mark@hotpy.org> | 2021-06-14 11:04:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-14 11:04:09 +0100 |
| commit | eecbc7c3900a7f40d8498b151db543a202c72f74 (patch) | |
| tree | 6be5d67366f8df3e24c3dbed0786ec3c4a29bf1b /Include | |
| parent | fafcfff9262ae9dee03a00006638dfcbcfc23a7b (diff) | |
| download | cpython-git-eecbc7c3900a7f40d8498b151db543a202c72f74.tar.gz | |
bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter (GH-26638)
* Add specializations of LOAD_GLOBAL.
* Add more stats.
* Remove old opcache; it is no longer used.
* Add NEWS
Diffstat (limited to 'Include')
| -rw-r--r-- | Include/cpython/code.h | 14 | ||||
| -rw-r--r-- | Include/internal/pycore_code.h | 25 | ||||
| -rw-r--r-- | Include/opcode.h | 3 |
3 files changed, 18 insertions, 24 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h index f6e789dd4d..df79ddbc1b 100644 --- a/Include/cpython/code.h +++ b/Include/cpython/code.h @@ -106,20 +106,6 @@ struct PyCodeObject { interpreter. */ union _cache_or_instruction *co_quickened; - /* Per opcodes just-in-time cache - * - * To reduce cache size, we use indirect mapping from opcode index to - * cache object: - * cache = co_opcache[co_opcache_map[next_instr - first_instr] - 1] - */ - - // co_opcache_map is indexed by (next_instr - first_instr). - // * 0 means there is no cache for this opcode. - // * n > 0 means there is cache in co_opcache[n-1]. - unsigned char *co_opcache_map; - _PyOpcache *co_opcache; - int co_opcache_flag; // used to determine when create a cache. - unsigned char co_opcache_size; // length of co_opcache. }; /* Masks for co_flags above */ diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h index bfc2deb1b6..098fbe4775 100644 --- a/Include/internal/pycore_code.h +++ b/Include/internal/pycore_code.h @@ -48,6 +48,11 @@ typedef struct { uint32_t dk_version_or_hint; } _PyLoadAttrCache; +typedef struct { + uint32_t module_keys_version; + uint32_t builtin_keys_version; +} _PyLoadGlobalCache; + /* Add specialized versions of entries to this union. * * Do not break the invariant: sizeof(SpecializedCacheEntry) == 8 @@ -62,6 +67,7 @@ typedef union { _PyEntryZero zero; _PyAdaptiveEntry adaptive; _PyLoadAttrCache load_attr; + _PyLoadGlobalCache load_global; } SpecializedCacheEntry; #define INSTRUCTIONS_PER_ENTRY (sizeof(SpecializedCacheEntry)/sizeof(_Py_CODEUNIT)) @@ -254,8 +260,6 @@ PyAPI_FUNC(PyCodeObject *) _PyCode_New(struct _PyCodeConstructor *); /* Private API */ -int _PyCode_InitOpcache(PyCodeObject *co); - /* Getters for internal PyCodeObject data. */ PyAPI_FUNC(PyObject *) _PyCode_GetVarnames(PyCodeObject *); PyAPI_FUNC(PyObject *) _PyCode_GetCellvars(PyCodeObject *); @@ -318,24 +322,25 @@ cache_backoff(_PyAdaptiveEntry *entry) { /* Specialization functions */ int _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache); +int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache); #define SPECIALIZATION_STATS 0 #if SPECIALIZATION_STATS -typedef struct _specialization_stats { +typedef struct _stats { uint64_t specialization_success; uint64_t specialization_failure; - uint64_t loadattr_hit; - uint64_t loadattr_deferred; - uint64_t loadattr_miss; - uint64_t loadattr_deopt; + uint64_t hit; + uint64_t deferred; + uint64_t miss; + uint64_t deopt; } SpecializationStats; -extern SpecializationStats _specialization_stats; -#define STAT_INC(name) _specialization_stats.name++ +extern SpecializationStats _specialization_stats[256]; +#define STAT_INC(opname, name) _specialization_stats[opname].name++ void _Py_PrintSpecializationStats(void); #else -#define STAT_INC(name) ((void)0) +#define STAT_INC(opname, name) ((void)0) #endif diff --git a/Include/opcode.h b/Include/opcode.h index 8f5be99cae..7f8376ff15 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -142,6 +142,9 @@ extern "C" { #define LOAD_ATTR_WITH_HINT 14 #define LOAD_ATTR_SLOT 18 #define LOAD_ATTR_MODULE 21 +#define LOAD_GLOBAL_ADAPTIVE 36 +#define LOAD_GLOBAL_MODULE 38 +#define LOAD_GLOBAL_BUILTIN 39 #ifdef NEED_OPCODE_JUMP_TABLES static uint32_t _PyOpcode_RelativeJump[8] = { 0U, |
