summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-02-07 14:30:34 (GMT)
committerGitHub <noreply@github.com>2022-02-07 14:30:34 (GMT)
commit062460e8fd54e53c9a1a6f175ef49c9d730851b8 (patch)
treec0796bb321afb4b1d01a09d8ef4ef5dc8be9b6b5 /Python/specialize.c
parent4cce1352bb47babaeefb68fcfcc48ffa073745c3 (diff)
downloadcpython-062460e8fd54e53c9a1a6f175ef49c9d730851b8.zip
cpython-062460e8fd54e53c9a1a6f175ef49c9d730851b8.tar.gz
cpython-062460e8fd54e53c9a1a6f175ef49c9d730851b8.tar.bz2
bpo-46072: Improve LOAD_METHOD stats (GH-31104)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index b7ef478..b95bdf7 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -503,6 +503,10 @@ initial_counter_value(void) {
#define SPEC_FAIL_BUILTIN_CLASS_METHOD 17
#define SPEC_FAIL_CLASS_METHOD_OBJ 18
#define SPEC_FAIL_OBJECT_SLOT 19
+#define SPEC_FAIL_HAS_DICT 20
+#define SPEC_FAIL_HAS_MANAGED_DICT 21
+#define SPEC_FAIL_INSTANCE_ATTRIBUTE 22
+#define SPEC_FAIL_METACLASS_ATTRIBUTE 23
/* Binary subscr */
@@ -973,7 +977,7 @@ load_method_fail_kind(DescriptorClassification kind)
case NON_DESCRIPTOR:
return SPEC_FAIL_NOT_DESCRIPTOR;
case ABSENT:
- return SPEC_FAIL_EXPECTED_ERROR;
+ return SPEC_FAIL_INSTANCE_ATTRIBUTE;
}
Py_UNREACHABLE();
}
@@ -994,6 +998,16 @@ specialize_class_load_method(PyObject *owner, _Py_CODEUNIT *instr, PyObject *nam
cache2->obj = descr;
*instr = _Py_MAKECODEUNIT(LOAD_METHOD_CLASS, _Py_OPARG(*instr));
return 0;
+#ifdef Py_STATS
+ case ABSENT:
+ if (_PyType_Lookup(Py_TYPE(owner), name) != NULL) {
+ SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_METACLASS_ATTRIBUTE);
+ }
+ else {
+ SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_EXPECTED_ERROR);
+ }
+ return -1;
+#endif
default:
SPECIALIZATION_FAIL(LOAD_METHOD, load_method_fail_kind(kind));
return -1;
@@ -1043,7 +1057,7 @@ _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name,
if (owner_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
PyObject **owner_dictptr = _PyObject_ManagedDictPointer(owner);
if (*owner_dictptr) {
- SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_IS_ATTR);
+ SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_HAS_MANAGED_DICT);
goto fail;
}
PyDictKeysObject *keys = ((PyHeapTypeObject *)owner_cls)->ht_cached_keys;
@@ -1065,7 +1079,7 @@ _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name,
*instr = _Py_MAKECODEUNIT(LOAD_METHOD_NO_DICT, _Py_OPARG(*instr));
}
else {
- SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_IS_ATTR);
+ SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_HAS_DICT);
goto fail;
}
}