diff options
author | Inada Naoki <songofacandy@gmail.com> | 2019-06-03 12:30:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-03 12:30:58 (GMT) |
commit | 91234a16367b56ca03ee289f7c03a34d4cfec4c8 (patch) | |
tree | 81d13661e09df4712009641eaba30e4599f1b776 /Include/code.h | |
parent | 29ec4228106ed5f970d1c3666614f4a51bad192c (diff) | |
download | cpython-91234a16367b56ca03ee289f7c03a34d4cfec4c8.zip cpython-91234a16367b56ca03ee289f7c03a34d4cfec4c8.tar.gz cpython-91234a16367b56ca03ee289f7c03a34d4cfec4c8.tar.bz2 |
bpo-26219: per opcode cache for LOAD_GLOBAL (GH-12884)
This patch implements per opcode cache mechanism, and use it in
only LOAD_GLOBAL opcode.
Based on Yury's opcache3.patch in bpo-26219.
Diffstat (limited to 'Include/code.h')
-rw-r--r-- | Include/code.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Include/code.h b/Include/code.h index 933de97..b79d977 100644 --- a/Include/code.h +++ b/Include/code.h @@ -17,6 +17,8 @@ typedef uint16_t _Py_CODEUNIT; # define _Py_OPARG(word) ((word) >> 8) #endif +typedef struct _PyOpcache _PyOpcache; + /* Bytecode object */ typedef struct { PyObject_HEAD @@ -49,6 +51,21 @@ typedef struct { Type is a void* to keep the format private in codeobject.c to force people to go through the proper APIs. */ void *co_extra; + + /* 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. } PyCodeObject; /* Masks for co_flags above */ |