[Python-checkins] Minor fixes to specialization stats. (GH-27457)

markshannon webhook-mailer at python.org
Thu Jul 29 15:50:07 EDT 2021


https://github.com/python/cpython/commit/2116909b3e1f044c268cebea78c92c7f593f99fe
commit: 2116909b3e1f044c268cebea78c92c7f593f99fe
branch: main
author: Mark Shannon <mark at hotpy.org>
committer: markshannon <mark at hotpy.org>
date: 2021-07-29T20:50:03+01:00
summary:

Minor fixes to specialization stats. (GH-27457)

* Use class, not value for fail stats for BINARY_SUBSCR.

* Fix counts for unquickened instructions.

files:
M Include/internal/pycore_code.h
M Python/ceval.c
M Python/specialize.c

diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index 2cd7c70650f93..2a50a0700feaa 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -320,12 +320,14 @@ typedef struct _stats {
 
 extern SpecializationStats _specialization_stats[256];
 #define STAT_INC(opname, name) _specialization_stats[opname].name++
+#define STAT_DEC(opname, name) _specialization_stats[opname].name--
 void _Py_PrintSpecializationStats(void);
 
 PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
 
 #else
 #define STAT_INC(opname, name) ((void)0)
+#define STAT_DEC(opname, name) ((void)0)
 #endif
 
 
diff --git a/Python/ceval.c b/Python/ceval.c
index 02eef9bc1c272..4f7edb84fc369 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1931,6 +1931,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 UPDATE_PREV_INSTR_OPARG(next_instr, oparg - 1);
                 assert(_Py_OPCODE(next_instr[-1]) == BINARY_SUBSCR_ADAPTIVE);
                 assert(_Py_OPARG(next_instr[-1]) == oparg - 1);
+                STAT_DEC(BINARY_SUBSCR, unquickened);
                 JUMP_TO_INSTRUCTION(BINARY_SUBSCR);
             }
         }
@@ -2943,6 +2944,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 STAT_INC(LOAD_GLOBAL, deferred);
                 cache->adaptive.counter--;
                 oparg = cache->adaptive.original_oparg;
+                STAT_DEC(LOAD_GLOBAL, unquickened);
                 JUMP_TO_INSTRUCTION(LOAD_GLOBAL);
             }
         }
@@ -3380,6 +3382,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 STAT_INC(LOAD_ATTR, deferred);
                 cache->adaptive.counter--;
                 oparg = cache->adaptive.original_oparg;
+                STAT_DEC(LOAD_ATTR, unquickened);
                 JUMP_TO_INSTRUCTION(LOAD_ATTR);
             }
         }
diff --git a/Python/specialize.c b/Python/specialize.c
index f699065b4c667..680ffb428e444 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -203,7 +203,8 @@ _Py_IncrementTypeCounter(int opcode, PyObject *type, PyObject *name, const char
     Py_XDECREF(key);
 }
 
-#define SPECIALIZATION_FAIL(opcode, type, attribute, kind) _Py_IncrementTypeCounter(opcode, (PyObject *)(type), attribute, kind)
+#define SPECIALIZATION_FAIL(opcode, type, attribute, kind) _Py_IncrementTypeCounter(opcode, (PyObject *)(type), (PyObject *)(attribute), kind)
+
 
 #endif
 #endif
@@ -722,6 +723,7 @@ _Py_Specialize_LoadGlobal(
     return 0;
 }
 
+
 int
 _Py_Specialize_BinarySubscr(
      PyObject *container, PyObject *sub, _Py_CODEUNIT *instr)
@@ -732,7 +734,8 @@ _Py_Specialize_BinarySubscr(
             *instr = _Py_MAKECODEUNIT(BINARY_SUBSCR_LIST_INT, saturating_start());
             goto success;
         } else {
-            SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), sub, "list; non-integer subscr");
+            SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), Py_TYPE(sub), "list; non-integer subscr");
+            goto fail;
         }
     }
     if (container_type == &PyTuple_Type) {
@@ -740,15 +743,15 @@ _Py_Specialize_BinarySubscr(
             *instr = _Py_MAKECODEUNIT(BINARY_SUBSCR_TUPLE_INT, saturating_start());
             goto success;
         } else {
-            SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), sub, "tuple; non-integer subscr");
+            SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), Py_TYPE(sub), "tuple; non-integer subscr");
+            goto fail;
         }
     }
     if (container_type == &PyDict_Type) {
         *instr = _Py_MAKECODEUNIT(BINARY_SUBSCR_DICT, saturating_start());
         goto success;
     }
-
-    SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), sub, "not list|tuple|dict");
+    SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), Py_TYPE(sub), "not list|tuple|dict");
     goto fail;
 fail:
     STAT_INC(BINARY_SUBSCR, specialization_failure);



More information about the Python-checkins mailing list