Skip to content

Commit 2116909

Browse files
authored
Minor fixes to specialization stats. (GH-27457)
* Use class, not value for fail stats for BINARY_SUBSCR. * Fix counts for unquickened instructions.
1 parent 7e311e4 commit 2116909

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,14 @@ typedef struct _stats {
320320

321321
extern SpecializationStats _specialization_stats[256];
322322
#define STAT_INC(opname, name) _specialization_stats[opname].name++
323+
#define STAT_DEC(opname, name) _specialization_stats[opname].name--
323324
void _Py_PrintSpecializationStats(void);
324325

325326
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
326327

327328
#else
328329
#define STAT_INC(opname, name) ((void)0)
330+
#define STAT_DEC(opname, name) ((void)0)
329331
#endif
330332

331333

Python/ceval.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
19311931
UPDATE_PREV_INSTR_OPARG(next_instr, oparg - 1);
19321932
assert(_Py_OPCODE(next_instr[-1]) == BINARY_SUBSCR_ADAPTIVE);
19331933
assert(_Py_OPARG(next_instr[-1]) == oparg - 1);
1934+
STAT_DEC(BINARY_SUBSCR, unquickened);
19341935
JUMP_TO_INSTRUCTION(BINARY_SUBSCR);
19351936
}
19361937
}
@@ -2943,6 +2944,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
29432944
STAT_INC(LOAD_GLOBAL, deferred);
29442945
cache->adaptive.counter--;
29452946
oparg = cache->adaptive.original_oparg;
2947+
STAT_DEC(LOAD_GLOBAL, unquickened);
29462948
JUMP_TO_INSTRUCTION(LOAD_GLOBAL);
29472949
}
29482950
}
@@ -3380,6 +3382,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
33803382
STAT_INC(LOAD_ATTR, deferred);
33813383
cache->adaptive.counter--;
33823384
oparg = cache->adaptive.original_oparg;
3385+
STAT_DEC(LOAD_ATTR, unquickened);
33833386
JUMP_TO_INSTRUCTION(LOAD_ATTR);
33843387
}
33853388
}

Python/specialize.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ _Py_IncrementTypeCounter(int opcode, PyObject *type, PyObject *name, const char
203203
Py_XDECREF(key);
204204
}
205205

206-
#define SPECIALIZATION_FAIL(opcode, type, attribute, kind) _Py_IncrementTypeCounter(opcode, (PyObject *)(type), attribute, kind)
206+
#define SPECIALIZATION_FAIL(opcode, type, attribute, kind) _Py_IncrementTypeCounter(opcode, (PyObject *)(type), (PyObject *)(attribute), kind)
207+
207208

208209
#endif
209210
#endif
@@ -722,6 +723,7 @@ _Py_Specialize_LoadGlobal(
722723
return 0;
723724
}
724725

726+
725727
int
726728
_Py_Specialize_BinarySubscr(
727729
PyObject *container, PyObject *sub, _Py_CODEUNIT *instr)
@@ -732,23 +734,24 @@ _Py_Specialize_BinarySubscr(
732734
*instr = _Py_MAKECODEUNIT(BINARY_SUBSCR_LIST_INT, saturating_start());
733735
goto success;
734736
} else {
735-
SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), sub, "list; non-integer subscr");
737+
SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), Py_TYPE(sub), "list; non-integer subscr");
738+
goto fail;
736739
}
737740
}
738741
if (container_type == &PyTuple_Type) {
739742
if (PyLong_CheckExact(sub)) {
740743
*instr = _Py_MAKECODEUNIT(BINARY_SUBSCR_TUPLE_INT, saturating_start());
741744
goto success;
742745
} else {
743-
SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), sub, "tuple; non-integer subscr");
746+
SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), Py_TYPE(sub), "tuple; non-integer subscr");
747+
goto fail;
744748
}
745749
}
746750
if (container_type == &PyDict_Type) {
747751
*instr = _Py_MAKECODEUNIT(BINARY_SUBSCR_DICT, saturating_start());
748752
goto success;
749753
}
750-
751-
SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), sub, "not list|tuple|dict");
754+
SPECIALIZATION_FAIL(BINARY_SUBSCR, Py_TYPE(container), Py_TYPE(sub), "not list|tuple|dict");
752755
goto fail;
753756
fail:
754757
STAT_INC(BINARY_SUBSCR, specialization_failure);

0 commit comments

Comments
 (0)