Skip to content

Commit 2b7aad1

Browse files
committed
Remove old opcache; it is no longer used.
1 parent b970dfc commit 2b7aad1

File tree

4 files changed

+5
-198
lines changed

4 files changed

+5
-198
lines changed

Include/cpython/code.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,6 @@ struct PyCodeObject {
106106
interpreter. */
107107
union _cache_or_instruction *co_quickened;
108108

109-
/* Per opcodes just-in-time cache
110-
*
111-
* To reduce cache size, we use indirect mapping from opcode index to
112-
* cache object:
113-
* cache = co_opcache[co_opcache_map[next_instr - first_instr] - 1]
114-
*/
115-
116-
// co_opcache_map is indexed by (next_instr - first_instr).
117-
// * 0 means there is no cache for this opcode.
118-
// * n > 0 means there is cache in co_opcache[n-1].
119-
unsigned char *co_opcache_map;
120-
_PyOpcache *co_opcache;
121-
int co_opcache_flag; // used to determine when create a cache.
122-
unsigned char co_opcache_size; // length of co_opcache.
123109
};
124110

125111
/* Masks for co_flags above */

Include/internal/pycore_code.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ PyAPI_FUNC(PyCodeObject *) _PyCode_New(struct _PyCodeConstructor *);
260260

261261
/* Private API */
262262

263-
int _PyCode_InitOpcache(PyCodeObject *co);
264-
265263
/* Getters for internal PyCodeObject data. */
266264
PyAPI_FUNC(PyObject *) _PyCode_GetVarnames(PyCodeObject *);
267265
PyAPI_FUNC(PyObject *) _PyCode_GetCellvars(PyCodeObject *);

Objects/codeobject.c

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
350350
/* not set */
351351
co->co_weakreflist = NULL;
352352
co->co_extra = NULL;
353-
co->co_opcache_map = NULL;
354-
co->co_opcache = NULL;
355-
co->co_opcache_flag = 0;
356-
co->co_opcache_size = 0;
353+
357354
co->co_warmup = QUICKENING_INITIAL_WARMUP_VALUE;
358355
co->co_quickened = NULL;
359356
}
@@ -912,55 +909,6 @@ new_linesiterator(PyCodeObject *code)
912909
return li;
913910
}
914911

915-
916-
/******************
917-
* the opcache
918-
******************/
919-
920-
int
921-
_PyCode_InitOpcache(PyCodeObject *co)
922-
{
923-
Py_ssize_t co_size = PyBytes_Size(co->co_code) / sizeof(_Py_CODEUNIT);
924-
co->co_opcache_map = (unsigned char *)PyMem_Calloc(co_size, 1);
925-
if (co->co_opcache_map == NULL) {
926-
return -1;
927-
}
928-
929-
_Py_CODEUNIT *opcodes = (_Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
930-
Py_ssize_t opts = 0;
931-
932-
for (Py_ssize_t i = 0; i < co_size;) {
933-
unsigned char opcode = _Py_OPCODE(opcodes[i]);
934-
i++; // 'i' is now aligned to (next_instr - first_instr)
935-
936-
// TODO: LOAD_METHOD
937-
if (opcode == LOAD_GLOBAL || opcode == LOAD_ATTR) {
938-
opts++;
939-
co->co_opcache_map[i] = (unsigned char)opts;
940-
if (opts > 254) {
941-
break;
942-
}
943-
}
944-
}
945-
946-
if (opts) {
947-
co->co_opcache = (_PyOpcache *)PyMem_Calloc(opts, sizeof(_PyOpcache));
948-
if (co->co_opcache == NULL) {
949-
PyMem_Free(co->co_opcache_map);
950-
return -1;
951-
}
952-
}
953-
else {
954-
PyMem_Free(co->co_opcache_map);
955-
co->co_opcache_map = NULL;
956-
co->co_opcache = NULL;
957-
}
958-
959-
co->co_opcache_size = (unsigned char)opts;
960-
return 0;
961-
}
962-
963-
964912
/******************
965913
* "extra" frame eval info (see PEP 523)
966914
******************/
@@ -1207,15 +1155,6 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
12071155
static void
12081156
code_dealloc(PyCodeObject *co)
12091157
{
1210-
if (co->co_opcache != NULL) {
1211-
PyMem_Free(co->co_opcache);
1212-
}
1213-
if (co->co_opcache_map != NULL) {
1214-
PyMem_Free(co->co_opcache_map);
1215-
}
1216-
co->co_opcache_flag = 0;
1217-
co->co_opcache_size = 0;
1218-
12191158
if (co->co_extra != NULL) {
12201159
PyInterpreterState *interp = _PyInterpreterState_GET();
12211160
_PyCodeObjectExtra *co_extra = co->co_extra;
@@ -1442,12 +1381,9 @@ code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args))
14421381
res += co->co_ncellvars * sizeof(Py_ssize_t);
14431382
}
14441383

1445-
if (co->co_opcache != NULL) {
1446-
assert(co->co_opcache_map != NULL);
1447-
// co_opcache_map
1448-
res += PyBytes_GET_SIZE(co->co_code) / sizeof(_Py_CODEUNIT);
1449-
// co_opcache
1450-
res += co->co_opcache_size * sizeof(_PyOpcache);
1384+
if (co->co_quickened != NULL) {
1385+
res += co->co_quickened[0].entry.zero.cache_count * sizeof(SpecializedCacheEntry);
1386+
res += PyBytes_GET_SIZE(co->co_code);
14511387
}
14521388

14531389
return PyLong_FromSsize_t(res);

Python/ceval.c

Lines changed: 1 addition & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "pycore_abstract.h" // _PyIndex_Check()
1414
#include "pycore_call.h" // _PyObject_FastCallDictTstate()
1515
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
16-
#include "pycore_code.h" // _PyCode_InitOpcache()
16+
#include "pycore_code.h"
1717
#include "pycore_initconfig.h" // _PyStatus_OK()
1818
#include "pycore_object.h" // _PyObject_GC_TRACK()
1919
#include "pycore_moduleobject.h"
@@ -1448,108 +1448,11 @@ eval_frame_handle_pending(PyThreadState *tstate)
14481448
GETLOCAL(i) = value; \
14491449
Py_XDECREF(tmp); } while (0)
14501450

1451-
/* macros for opcode cache */
1452-
#define OPCACHE_CHECK() \
1453-
do { \
1454-
co_opcache = NULL; \
1455-
if (co->co_opcache != NULL) { \
1456-
unsigned char co_opcache_offset = \
1457-
co->co_opcache_map[next_instr - first_instr]; \
1458-
if (co_opcache_offset > 0) { \
1459-
assert(co_opcache_offset <= co->co_opcache_size); \
1460-
co_opcache = &co->co_opcache[co_opcache_offset - 1]; \
1461-
assert(co_opcache != NULL); \
1462-
} \
1463-
} \
1464-
} while (0)
1465-
1466-
#define OPCACHE_DEOPT() \
1467-
do { \
1468-
if (co_opcache != NULL) { \
1469-
co_opcache->optimized = -1; \
1470-
unsigned char co_opcache_offset = \
1471-
co->co_opcache_map[next_instr - first_instr]; \
1472-
assert(co_opcache_offset <= co->co_opcache_size); \
1473-
co->co_opcache_map[co_opcache_offset] = 0; \
1474-
co_opcache = NULL; \
1475-
} \
1476-
} while (0)
1477-
1478-
#define OPCACHE_DEOPT_LOAD_ATTR() \
1479-
do { \
1480-
if (co_opcache != NULL) { \
1481-
OPCACHE_STAT_ATTR_DEOPT(); \
1482-
OPCACHE_DEOPT(); \
1483-
} \
1484-
} while (0)
1485-
1486-
#define OPCACHE_MAYBE_DEOPT_LOAD_ATTR() \
1487-
do { \
1488-
if (co_opcache != NULL && --co_opcache->optimized <= 0) { \
1489-
OPCACHE_DEOPT_LOAD_ATTR(); \
1490-
} \
1491-
} while (0)
1492-
1493-
#if OPCACHE_STATS
1494-
1495-
#define OPCACHE_STAT_GLOBAL_HIT() \
1496-
do { \
1497-
if (co->co_opcache != NULL) opcache_global_hits++; \
1498-
} while (0)
1499-
1500-
#define OPCACHE_STAT_GLOBAL_MISS() \
1501-
do { \
1502-
if (co->co_opcache != NULL) opcache_global_misses++; \
1503-
} while (0)
1504-
1505-
#define OPCACHE_STAT_GLOBAL_OPT() \
1506-
do { \
1507-
if (co->co_opcache != NULL) opcache_global_opts++; \
1508-
} while (0)
1509-
1510-
#define OPCACHE_STAT_ATTR_HIT() \
1511-
do { \
1512-
if (co->co_opcache != NULL) opcache_attr_hits++; \
1513-
} while (0)
1514-
1515-
#define OPCACHE_STAT_ATTR_MISS() \
1516-
do { \
1517-
if (co->co_opcache != NULL) opcache_attr_misses++; \
1518-
} while (0)
1519-
1520-
#define OPCACHE_STAT_ATTR_OPT() \
1521-
do { \
1522-
if (co->co_opcache!= NULL) opcache_attr_opts++; \
1523-
} while (0)
1524-
1525-
#define OPCACHE_STAT_ATTR_DEOPT() \
1526-
do { \
1527-
if (co->co_opcache != NULL) opcache_attr_deopts++; \
1528-
} while (0)
1529-
1530-
#define OPCACHE_STAT_ATTR_TOTAL() \
1531-
do { \
1532-
if (co->co_opcache != NULL) opcache_attr_total++; \
1533-
} while (0)
1534-
1535-
#else /* OPCACHE_STATS */
1536-
1537-
#define OPCACHE_STAT_GLOBAL_HIT()
1538-
#define OPCACHE_STAT_GLOBAL_MISS()
1539-
#define OPCACHE_STAT_GLOBAL_OPT()
1540-
1541-
#define OPCACHE_STAT_ATTR_HIT()
1542-
#define OPCACHE_STAT_ATTR_MISS()
1543-
#define OPCACHE_STAT_ATTR_OPT()
1544-
#define OPCACHE_STAT_ATTR_DEOPT()
1545-
#define OPCACHE_STAT_ATTR_TOTAL()
1546-
15471451
#define JUMP_TO_INSTRUCTION(op) goto PREDICT_ID(op)
15481452

15491453
#define GET_CACHE() \
15501454
_GetSpecializedCacheEntryForInstruction(first_instr, INSTR_OFFSET(), oparg)
15511455

1552-
#endif
15531456

15541457
#define DEOPT_IF(cond, instname) if (cond) { goto instname ## _miss; }
15551458

@@ -1582,7 +1485,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
15821485
_Py_CODEUNIT *first_instr;
15831486
PyObject *names;
15841487
PyObject *consts;
1585-
_PyOpcache *co_opcache;
15861488

15871489
#ifdef LLTRACE
15881490
_Py_IDENTIFIER(__ltrace__);
@@ -1690,21 +1592,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
16901592
f->f_stackdepth = -1;
16911593
f->f_state = FRAME_EXECUTING;
16921594

1693-
if (co->co_opcache_flag < opcache_min_runs) {
1694-
co->co_opcache_flag++;
1695-
if (co->co_opcache_flag == opcache_min_runs) {
1696-
if (_PyCode_InitOpcache(co) < 0) {
1697-
goto exit_eval_frame;
1698-
}
1699-
#if OPCACHE_STATS
1700-
opcache_code_objects_extra_mem +=
1701-
PyBytes_Size(co->co_code) / sizeof(_Py_CODEUNIT) +
1702-
sizeof(_PyOpcache) * co->co_opcache_size;
1703-
opcache_code_objects++;
1704-
#endif
1705-
}
1706-
}
1707-
17081595
#ifdef LLTRACE
17091596
{
17101597
int r = _PyDict_ContainsId(GLOBALS(), &PyId___ltrace__);

0 commit comments

Comments
 (0)