diff options
author | Mark Shannon <mark@hotpy.org> | 2022-05-31 10:58:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 10:58:26 (GMT) |
commit | eb618d5ff0371efead28a3afa91834e4beebf73d (patch) | |
tree | 23562ace1776332b7145a70fe42e6201c6a7be05 /Python/specialize.c | |
parent | a565ab0fd58bcd4bbc01084b74ef704a75084274 (diff) | |
download | cpython-eb618d5ff0371efead28a3afa91834e4beebf73d.zip cpython-eb618d5ff0371efead28a3afa91834e4beebf73d.tar.gz cpython-eb618d5ff0371efead28a3afa91834e4beebf73d.tar.bz2 |
GH-93354: Use exponential backoff to avoid excessive specialization attempts. (GH-93355)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index a2fb460..4d30a2a 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -321,7 +321,7 @@ _PyCode_Quicken(PyCodeObject *code) } static inline int -initial_counter_value(void) { +miss_counter_start(void) { /* Starting value for the counter. * This value needs to be not too low, otherwise * it would cause excessive de-optimization. @@ -743,12 +743,12 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name) fail: STAT_INC(LOAD_ATTR, failure); assert(!PyErr_Occurred()); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return 0; success: STAT_INC(LOAD_ATTR, success); assert(!PyErr_Occurred()); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); return 0; } @@ -825,12 +825,12 @@ _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name) fail: STAT_INC(STORE_ATTR, failure); assert(!PyErr_Occurred()); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return 0; success: STAT_INC(STORE_ATTR, success); assert(!PyErr_Occurred()); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); return 0; } @@ -1041,14 +1041,13 @@ _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name) success: STAT_INC(LOAD_METHOD, success); assert(!PyErr_Occurred()); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); return 0; fail: STAT_INC(LOAD_METHOD, failure); assert(!PyErr_Occurred()); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return 0; - } int @@ -1124,12 +1123,12 @@ _Py_Specialize_LoadGlobal( fail: STAT_INC(LOAD_GLOBAL, failure); assert(!PyErr_Occurred()); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return 0; success: STAT_INC(LOAD_GLOBAL, success); assert(!PyErr_Occurred()); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); return 0; } @@ -1253,12 +1252,12 @@ _Py_Specialize_BinarySubscr( fail: STAT_INC(BINARY_SUBSCR, failure); assert(!PyErr_Occurred()); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return 0; success: STAT_INC(BINARY_SUBSCR, success); assert(!PyErr_Occurred()); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); return 0; } @@ -1357,12 +1356,12 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins fail: STAT_INC(STORE_SUBSCR, failure); assert(!PyErr_Occurred()); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return 0; success: STAT_INC(STORE_SUBSCR, success); assert(!PyErr_Occurred()); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); return 0; } @@ -1674,12 +1673,12 @@ _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr, int nargs, if (fail) { STAT_INC(CALL, failure); assert(!PyErr_Occurred()); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); } else { STAT_INC(CALL, success); assert(!PyErr_Occurred()); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); } return 0; } @@ -1827,11 +1826,11 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, } SPECIALIZATION_FAIL(BINARY_OP, binary_op_fail_kind(oparg, lhs, rhs)); STAT_INC(BINARY_OP, failure); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return; success: STAT_INC(BINARY_OP, success); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); } @@ -1953,11 +1952,11 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, SPECIALIZATION_FAIL(COMPARE_OP, compare_op_fail_kind(lhs, rhs)); failure: STAT_INC(COMPARE_OP, failure); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return; success: STAT_INC(COMPARE_OP, success); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); } #ifdef Py_STATS @@ -2003,11 +2002,11 @@ _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr, int oparg) SPECIALIZATION_FAIL(UNPACK_SEQUENCE, unpack_sequence_fail_kind(seq)); failure: STAT_INC(UNPACK_SEQUENCE, failure); - cache->counter = ADAPTIVE_CACHE_BACKOFF; + cache->counter = adaptive_counter_backoff(cache->counter); return; success: STAT_INC(UNPACK_SEQUENCE, success); - cache->counter = initial_counter_value(); + cache->counter = miss_counter_start(); } #ifdef Py_STATS |