gh-92777: Add LOAD_METHOD_LAZY_DICT (GH-92778)

This commit is contained in:
Ken Jin 2022-05-25 21:06:15 +08:00 committed by GitHub
parent db3ef0c82a
commit 5e6e5b98a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 49 deletions

View file

@ -4673,6 +4673,29 @@ handle_eval_breaker:
NOTRACE_DISPATCH();
}
TARGET(LOAD_METHOD_LAZY_DICT) {
assert(cframe.use_tracing == 0);
PyObject *self = TOP();
PyTypeObject *self_cls = Py_TYPE(self);
_PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
uint32_t type_version = read_u32(cache->type_version);
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_METHOD);
int dictoffset = cache->dict_offset;
PyObject *dict = *(PyObject **)((char *)self + dictoffset);
assert(dictoffset == self_cls->tp_dictoffset && dictoffset > 0);
/* This object has a __dict__, just not yet created */
DEOPT_IF(dict != NULL, LOAD_METHOD);
STAT_INC(LOAD_METHOD, hit);
PyObject *res = read_obj(cache->descr);
assert(res != NULL);
assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
Py_INCREF(res);
SET_TOP(res);
PUSH(self);
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_METHOD);
NOTRACE_DISPATCH();
}
TARGET(LOAD_METHOD_MODULE) {
/* LOAD_METHOD, for module methods */
assert(cframe.use_tracing == 0);