@@ -1559,7 +1559,11 @@ eval_frame_handle_pending(PyThreadState *tstate)
1559
1559
dtrace_function_entry(frame); \
1560
1560
}
1561
1561
1562
+ #define ADAPTIVE_COUNTER_IS_ZERO (cache ) \
1563
+ (cache)->counter < (1<<ADAPTIVE_BACKOFF_BITS)
1562
1564
1565
+ #define DECREMENT_ADAPTIVE_COUNTER (cache ) \
1566
+ (cache)->counter -= (1<<ADAPTIVE_BACKOFF_BITS)
1563
1567
1564
1568
static int
1565
1569
trace_function_entry (PyThreadState * tstate , _PyInterpreterFrame * frame )
@@ -2154,7 +2158,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
2154
2158
2155
2159
TARGET (BINARY_SUBSCR_ADAPTIVE ) {
2156
2160
_PyBinarySubscrCache * cache = (_PyBinarySubscrCache * )next_instr ;
2157
- if (cache -> counter == 0 ) {
2161
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
2158
2162
PyObject * sub = TOP ();
2159
2163
PyObject * container = SECOND ();
2160
2164
next_instr -- ;
@@ -2165,7 +2169,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
2165
2169
}
2166
2170
else {
2167
2171
STAT_INC (BINARY_SUBSCR , deferred );
2168
- cache -> counter -- ;
2172
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
2169
2173
JUMP_TO_INSTRUCTION (BINARY_SUBSCR );
2170
2174
}
2171
2175
}
@@ -2319,7 +2323,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
2319
2323
2320
2324
TARGET (STORE_SUBSCR_ADAPTIVE ) {
2321
2325
_PyStoreSubscrCache * cache = (_PyStoreSubscrCache * )next_instr ;
2322
- if (cache -> counter == 0 ) {
2326
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
2323
2327
PyObject * sub = TOP ();
2324
2328
PyObject * container = SECOND ();
2325
2329
next_instr -- ;
@@ -2330,7 +2334,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
2330
2334
}
2331
2335
else {
2332
2336
STAT_INC (STORE_SUBSCR , deferred );
2333
- cache -> counter -- ;
2337
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
2334
2338
JUMP_TO_INSTRUCTION (STORE_SUBSCR );
2335
2339
}
2336
2340
}
@@ -2812,15 +2816,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
2812
2816
TARGET (UNPACK_SEQUENCE_ADAPTIVE ) {
2813
2817
assert (cframe .use_tracing == 0 );
2814
2818
_PyUnpackSequenceCache * cache = (_PyUnpackSequenceCache * )next_instr ;
2815
- if (cache -> counter == 0 ) {
2819
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
2816
2820
PyObject * seq = TOP ();
2817
2821
next_instr -- ;
2818
2822
_Py_Specialize_UnpackSequence (seq , next_instr , oparg );
2819
2823
NOTRACE_DISPATCH_SAME_OPARG ();
2820
2824
}
2821
2825
else {
2822
2826
STAT_INC (UNPACK_SEQUENCE , deferred );
2823
- cache -> counter -- ;
2827
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
2824
2828
JUMP_TO_INSTRUCTION (UNPACK_SEQUENCE );
2825
2829
}
2826
2830
}
@@ -3053,7 +3057,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3053
3057
TARGET (LOAD_GLOBAL_ADAPTIVE ) {
3054
3058
assert (cframe .use_tracing == 0 );
3055
3059
_PyLoadGlobalCache * cache = (_PyLoadGlobalCache * )next_instr ;
3056
- if (cache -> counter == 0 ) {
3060
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
3057
3061
PyObject * name = GETITEM (names , oparg >>1 );
3058
3062
next_instr -- ;
3059
3063
if (_Py_Specialize_LoadGlobal (GLOBALS (), BUILTINS (), next_instr , name ) < 0 ) {
@@ -3063,7 +3067,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3063
3067
}
3064
3068
else {
3065
3069
STAT_INC (LOAD_GLOBAL , deferred );
3066
- cache -> counter -- ;
3070
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
3067
3071
JUMP_TO_INSTRUCTION (LOAD_GLOBAL );
3068
3072
}
3069
3073
}
@@ -3477,7 +3481,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3477
3481
TARGET (LOAD_ATTR_ADAPTIVE ) {
3478
3482
assert (cframe .use_tracing == 0 );
3479
3483
_PyAttrCache * cache = (_PyAttrCache * )next_instr ;
3480
- if (cache -> counter == 0 ) {
3484
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
3481
3485
PyObject * owner = TOP ();
3482
3486
PyObject * name = GETITEM (names , oparg );
3483
3487
next_instr -- ;
@@ -3488,7 +3492,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3488
3492
}
3489
3493
else {
3490
3494
STAT_INC (LOAD_ATTR , deferred );
3491
- cache -> counter -- ;
3495
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
3492
3496
JUMP_TO_INSTRUCTION (LOAD_ATTR );
3493
3497
}
3494
3498
}
@@ -3586,7 +3590,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3586
3590
TARGET (STORE_ATTR_ADAPTIVE ) {
3587
3591
assert (cframe .use_tracing == 0 );
3588
3592
_PyAttrCache * cache = (_PyAttrCache * )next_instr ;
3589
- if (cache -> counter == 0 ) {
3593
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
3590
3594
PyObject * owner = TOP ();
3591
3595
PyObject * name = GETITEM (names , oparg );
3592
3596
next_instr -- ;
@@ -3597,7 +3601,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3597
3601
}
3598
3602
else {
3599
3603
STAT_INC (STORE_ATTR , deferred );
3600
- cache -> counter -- ;
3604
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
3601
3605
JUMP_TO_INSTRUCTION (STORE_ATTR );
3602
3606
}
3603
3607
}
@@ -3716,7 +3720,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3716
3720
TARGET (COMPARE_OP_ADAPTIVE ) {
3717
3721
assert (cframe .use_tracing == 0 );
3718
3722
_PyCompareOpCache * cache = (_PyCompareOpCache * )next_instr ;
3719
- if (cache -> counter == 0 ) {
3723
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
3720
3724
PyObject * right = TOP ();
3721
3725
PyObject * left = SECOND ();
3722
3726
next_instr -- ;
@@ -3725,7 +3729,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
3725
3729
}
3726
3730
else {
3727
3731
STAT_INC (COMPARE_OP , deferred );
3728
- cache -> counter -- ;
3732
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
3729
3733
JUMP_TO_INSTRUCTION (COMPARE_OP );
3730
3734
}
3731
3735
}
@@ -4523,7 +4527,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
4523
4527
TARGET (LOAD_METHOD_ADAPTIVE ) {
4524
4528
assert (cframe .use_tracing == 0 );
4525
4529
_PyLoadMethodCache * cache = (_PyLoadMethodCache * )next_instr ;
4526
- if (cache -> counter == 0 ) {
4530
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
4527
4531
PyObject * owner = TOP ();
4528
4532
PyObject * name = GETITEM (names , oparg );
4529
4533
next_instr -- ;
@@ -4534,7 +4538,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
4534
4538
}
4535
4539
else {
4536
4540
STAT_INC (LOAD_METHOD , deferred );
4537
- cache -> counter -- ;
4541
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
4538
4542
JUMP_TO_INSTRUCTION (LOAD_METHOD );
4539
4543
}
4540
4544
}
@@ -4815,7 +4819,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
4815
4819
4816
4820
TARGET (CALL_ADAPTIVE ) {
4817
4821
_PyCallCache * cache = (_PyCallCache * )next_instr ;
4818
- if (cache -> counter == 0 ) {
4822
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
4819
4823
next_instr -- ;
4820
4824
int is_meth = is_method (stack_pointer , oparg );
4821
4825
int nargs = oparg + is_meth ;
@@ -4829,7 +4833,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
4829
4833
}
4830
4834
else {
4831
4835
STAT_INC (CALL , deferred );
4832
- cache -> counter -- ;
4836
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
4833
4837
goto call_function ;
4834
4838
}
4835
4839
}
@@ -5560,7 +5564,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5560
5564
TARGET (BINARY_OP_ADAPTIVE ) {
5561
5565
assert (cframe .use_tracing == 0 );
5562
5566
_PyBinaryOpCache * cache = (_PyBinaryOpCache * )next_instr ;
5563
- if (cache -> counter == 0 ) {
5567
+ if (ADAPTIVE_COUNTER_IS_ZERO ( cache ) ) {
5564
5568
PyObject * lhs = SECOND ();
5565
5569
PyObject * rhs = TOP ();
5566
5570
next_instr -- ;
@@ -5569,7 +5573,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5569
5573
}
5570
5574
else {
5571
5575
STAT_INC (BINARY_OP , deferred );
5572
- cache -> counter -- ;
5576
+ DECREMENT_ADAPTIVE_COUNTER ( cache ) ;
5573
5577
JUMP_TO_INSTRUCTION (BINARY_OP );
5574
5578
}
5575
5579
}
@@ -5690,7 +5694,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5690
5694
assert (adaptive_opcode );
5691
5695
_Py_SET_OPCODE (next_instr [-1 ], adaptive_opcode );
5692
5696
STAT_INC (opcode , deopt );
5693
- * counter = ADAPTIVE_CACHE_BACKOFF ;
5697
+ * counter = adaptive_counter_start () ;
5694
5698
}
5695
5699
next_instr -- ;
5696
5700
DISPATCH_GOTO ();
0 commit comments