summaryrefslogtreecommitdiffstats
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-06-14 10:04:09 (GMT)
committerGitHub <noreply@github.com>2021-06-14 10:04:09 (GMT)
commiteecbc7c3900a7f40d8498b151db543a202c72f74 (patch)
tree6be5d67366f8df3e24c3dbed0786ec3c4a29bf1b /Objects/codeobject.c
parentfafcfff9262ae9dee03a00006638dfcbcfc23a7b (diff)
downloadcpython-eecbc7c3900a7f40d8498b151db543a202c72f74.zip
cpython-eecbc7c3900a7f40d8498b151db543a202c72f74.tar.gz
cpython-eecbc7c3900a7f40d8498b151db543a202c72f74.tar.bz2
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 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c74
1 files changed, 6 insertions, 68 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 701a37d..e054c43 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -350,10 +350,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
/* not set */
co->co_weakreflist = NULL;
co->co_extra = NULL;
- co->co_opcache_map = NULL;
- co->co_opcache = NULL;
- co->co_opcache_flag = 0;
- co->co_opcache_size = 0;
+
co->co_warmup = QUICKENING_INITIAL_WARMUP_VALUE;
co->co_quickened = NULL;
}
@@ -912,55 +909,6 @@ new_linesiterator(PyCodeObject *code)
return li;
}
-
-/******************
- * the opcache
- ******************/
-
-int
-_PyCode_InitOpcache(PyCodeObject *co)
-{
- Py_ssize_t co_size = PyBytes_Size(co->co_code) / sizeof(_Py_CODEUNIT);
- co->co_opcache_map = (unsigned char *)PyMem_Calloc(co_size, 1);
- if (co->co_opcache_map == NULL) {
- return -1;
- }
-
- const _Py_CODEUNIT *opcodes = (const _Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
- Py_ssize_t opts = 0;
-
- for (Py_ssize_t i = 0; i < co_size;) {
- unsigned char opcode = _Py_OPCODE(opcodes[i]);
- i++; // 'i' is now aligned to (next_instr - first_instr)
-
- // TODO: LOAD_METHOD
- if (opcode == LOAD_GLOBAL || opcode == LOAD_ATTR) {
- opts++;
- co->co_opcache_map[i] = (unsigned char)opts;
- if (opts > 254) {
- break;
- }
- }
- }
-
- if (opts) {
- co->co_opcache = (_PyOpcache *)PyMem_Calloc(opts, sizeof(_PyOpcache));
- if (co->co_opcache == NULL) {
- PyMem_Free(co->co_opcache_map);
- return -1;
- }
- }
- else {
- PyMem_Free(co->co_opcache_map);
- co->co_opcache_map = NULL;
- co->co_opcache = NULL;
- }
-
- co->co_opcache_size = (unsigned char)opts;
- return 0;
-}
-
-
/******************
* "extra" frame eval info (see PEP 523)
******************/
@@ -1207,15 +1155,6 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
static void
code_dealloc(PyCodeObject *co)
{
- if (co->co_opcache != NULL) {
- PyMem_Free(co->co_opcache);
- }
- if (co->co_opcache_map != NULL) {
- PyMem_Free(co->co_opcache_map);
- }
- co->co_opcache_flag = 0;
- co->co_opcache_size = 0;
-
if (co->co_extra != NULL) {
PyInterpreterState *interp = _PyInterpreterState_GET();
_PyCodeObjectExtra *co_extra = co->co_extra;
@@ -1442,12 +1381,11 @@ code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args))
res += co->co_ncellvars * sizeof(Py_ssize_t);
}
- if (co->co_opcache != NULL) {
- assert(co->co_opcache_map != NULL);
- // co_opcache_map
- res += PyBytes_GET_SIZE(co->co_code) / sizeof(_Py_CODEUNIT);
- // co_opcache
- res += co->co_opcache_size * sizeof(_PyOpcache);
+ if (co->co_quickened != NULL) {
+ Py_ssize_t count = co->co_quickened[0].entry.zero.cache_count;
+ count += (PyBytes_GET_SIZE(co->co_code)+sizeof(SpecializedCacheEntry)-1)/
+ sizeof(SpecializedCacheEntry);
+ res += count * sizeof(SpecializedCacheEntry);
}
return PyLong_FromSsize_t(res);