@@ -157,6 +157,7 @@ dummy_func(
157157 if (_Py_atomic_load_uintptr_relaxed (& tstate -> eval_breaker ) & _PY_EVAL_EVENTS_MASK ) {
158158 int err = _Py_HandlePending (tstate );
159159 ERROR_IF (err != 0 , error );
160+ LOAD_NEXT_OP_F ();
160161 }
161162 }
162163
@@ -167,6 +168,7 @@ dummy_func(
167168 if (_Py_atomic_load_uintptr_relaxed (& tstate -> eval_breaker ) & _PY_EVAL_EVENTS_MASK ) {
168169 int err = _Py_HandlePending (tstate );
169170 ERROR_IF (err != 0 , error );
171+ LOAD_NEXT_OP_F ();
170172 }
171173 }
172174 }
@@ -189,6 +191,7 @@ dummy_func(
189191 ERROR_NO_POP ();
190192 }
191193 next_instr = this_instr ;
194+ LOAD_NEXT_OP_F ();
192195 DISPATCH ();
193196 }
194197 }
@@ -241,8 +244,8 @@ dummy_func(
241244 if (frame -> instr_ptr != this_instr ) {
242245 /* Instrumentation has jumped */
243246 next_instr = frame -> instr_ptr ;
244- LOAD_NEXT_OP_F ();
245247 }
248+ LOAD_NEXT_OP_F (); // maybe needs to be unconditional?
246249 }
247250
248251 macro (INSTRUMENTED_RESUME ) =
@@ -364,6 +367,7 @@ dummy_func(
364367
365368 pure inst (POP_TOP , (value -- )) {
366369 DECREF_INPUTS ();
370+ LOAD_NEXT_OP_F ();
367371 }
368372
369373 pure inst (PUSH_NULL , (-- res )) {
@@ -445,7 +449,6 @@ dummy_func(
445449 #if ENABLE_SPECIALIZATION_FT
446450 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
447451 next_instr = this_instr ;
448- LOAD_NEXT_OP_F ();
449452 _Py_Specialize_ToBool (value , next_instr );
450453 DISPATCH_SAME_OPARG ();
451454 }
@@ -838,6 +841,7 @@ dummy_func(
838841 }
839842 else {
840843 err = PyObject_SetItem (PyStackRef_AsPyObjectBorrow (container ), slice , PyStackRef_AsPyObjectBorrow (v ));
844+ LOAD_NEXT_OP_F ();
841845 Py_DECREF (slice );
842846 }
843847 DECREF_INPUTS ();
@@ -983,7 +987,6 @@ dummy_func(
983987 #if ENABLE_SPECIALIZATION_FT
984988 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
985989 next_instr = this_instr ;
986- LOAD_NEXT_OP_F ();
987990 _Py_Specialize_StoreSubscr (container , sub , next_instr );
988991 DISPATCH_SAME_OPARG ();
989992 }
@@ -995,6 +998,7 @@ dummy_func(
995998 op (_STORE_SUBSCR , (v , container , sub -- )) {
996999 /* container[sub] = v */
9971000 int err = PyObject_SetItem (PyStackRef_AsPyObjectBorrow (container ), PyStackRef_AsPyObjectBorrow (sub ), PyStackRef_AsPyObjectBorrow (v ));
1001+ LOAD_NEXT_OP_F ();
9981002 DECREF_INPUTS ();
9991003 ERROR_IF (err , error );
10001004 }
@@ -1183,7 +1187,6 @@ dummy_func(
11831187 #if ENABLE_SPECIALIZATION_FT
11841188 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
11851189 next_instr = this_instr ;
1186- LOAD_NEXT_OP_F ();
11871190 _Py_Specialize_Send (receiver , next_instr );
11881191 DISPATCH_SAME_OPARG ();
11891192 }
@@ -1239,6 +1242,7 @@ dummy_func(
12391242 }
12401243 PyStackRef_CLOSE (v );
12411244 retval = PyStackRef_FromPyObjectSteal (retval_o );
1245+ LOAD_NEXT_OP_F ();
12421246 }
12431247
12441248 macro (SEND ) = _SPECIALIZE_SEND + _SEND ;
@@ -1424,6 +1428,7 @@ dummy_func(
14241428 }
14251429 else {
14261430 err = PyObject_SetItem (ns , name , PyStackRef_AsPyObjectBorrow (v ));
1431+ LOAD_NEXT_OP_F ();
14271432 }
14281433 DECREF_INPUTS ();
14291434 ERROR_IF (err , error );
@@ -1458,7 +1463,6 @@ dummy_func(
14581463 #if ENABLE_SPECIALIZATION_FT
14591464 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
14601465 next_instr = this_instr ;
1461- LOAD_NEXT_OP_F ();
14621466 _Py_Specialize_UnpackSequence (seq , next_instr , oparg );
14631467 DISPATCH_SAME_OPARG ();
14641468 }
@@ -1536,7 +1540,6 @@ dummy_func(
15361540 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
15371541 PyObject * name = GETITEM (FRAME_CO_NAMES , oparg );
15381542 next_instr = this_instr ;
1539- LOAD_NEXT_OP_F ();
15401543 _Py_Specialize_StoreAttr (owner , next_instr , name );
15411544 DISPATCH_SAME_OPARG ();
15421545 }
@@ -1549,6 +1552,8 @@ dummy_func(
15491552 PyObject * name = GETITEM (FRAME_CO_NAMES , oparg );
15501553 int err = PyObject_SetAttr (PyStackRef_AsPyObjectBorrow (owner ),
15511554 name , PyStackRef_AsPyObjectBorrow (v ));
1555+ // SetAttr can call into specialize
1556+ LOAD_NEXT_OP_F ();
15521557 DECREF_INPUTS ();
15531558 ERROR_IF (err , error );
15541559 }
@@ -1654,7 +1659,6 @@ dummy_func(
16541659 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
16551660 PyObject * name = GETITEM (FRAME_CO_NAMES , oparg >>1 );
16561661 next_instr = this_instr ;
1657- LOAD_NEXT_OP_F ();
16581662 _Py_Specialize_LoadGlobal (GLOBALS (), BUILTINS (), next_instr , name );
16591663 DISPATCH_SAME_OPARG ();
16601664 }
@@ -1768,6 +1772,7 @@ dummy_func(
17681772 _PyStackRef tmp = GETLOCAL (oparg );
17691773 GETLOCAL (oparg ) = PyStackRef_NULL ;
17701774 PyStackRef_XCLOSE (tmp );
1775+ LOAD_NEXT_OP_F ();
17711776 }
17721777
17731778 inst (MAKE_CELL , (-- )) {
@@ -1959,6 +1964,7 @@ dummy_func(
19591964 ERROR_IF (ann_dict == NULL , error );
19601965 err = PyObject_SetItem (LOCALS (), & _Py_ID (__annotations__ ),
19611966 ann_dict );
1967+ LOAD_NEXT_OP_F ();
19621968 Py_DECREF (ann_dict );
19631969 ERROR_IF (err , error );
19641970 }
@@ -2027,7 +2033,6 @@ dummy_func(
20272033 int load_method = oparg & 1 ;
20282034 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
20292035 next_instr = this_instr ;
2030- LOAD_NEXT_OP_F ();
20312036 _Py_Specialize_LoadSuperAttr (global_super_st , class_st , next_instr , load_method );
20322037 DISPATCH_SAME_OPARG ();
20332038 }
@@ -2151,7 +2156,6 @@ dummy_func(
21512156 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
21522157 PyObject * name = GETITEM (FRAME_CO_NAMES , oparg >>1 );
21532158 next_instr = this_instr ;
2154- LOAD_NEXT_OP_F ();
21552159 _Py_Specialize_LoadAttr (owner , next_instr , name );
21562160 DISPATCH_SAME_OPARG ();
21572161 }
@@ -2191,6 +2195,7 @@ dummy_func(
21912195 else {
21922196 /* Classic, pushes one value. */
21932197 attr_o = PyObject_GetAttr (PyStackRef_AsPyObjectBorrow (owner ), name );
2198+ LOAD_NEXT_OP_F ();
21942199 DECREF_INPUTS ();
21952200 ERROR_IF (attr_o == NULL , error );
21962201 }
@@ -2558,7 +2563,6 @@ dummy_func(
25582563 #if ENABLE_SPECIALIZATION_FT
25592564 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
25602565 next_instr = this_instr ;
2561- LOAD_NEXT_OP_F ();
25622566 _Py_Specialize_CompareOp (left , right , next_instr , oparg );
25632567 DISPATCH_SAME_OPARG ();
25642568 }
@@ -2680,7 +2684,6 @@ dummy_func(
26802684 #if ENABLE_SPECIALIZATION_FT
26812685 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
26822686 next_instr = this_instr ;
2683- LOAD_NEXT_OP_F ();
26842687 _Py_Specialize_ContainsOp (right , next_instr );
26852688 DISPATCH_SAME_OPARG ();
26862689 }
@@ -2790,7 +2793,6 @@ dummy_func(
27902793 this_instr -> op .code = tstate -> interp -> jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT ;
27912794 // Need to re-dispatch so the warmup counter isn't off by one:
27922795 next_instr = this_instr ;
2793- LOAD_NEXT_OP_F ();
27942796 DISPATCH_SAME_OPARG ();
27952797 }
27962798 #endif
@@ -2873,9 +2875,9 @@ dummy_func(
28732875 * involving _RESUME_CHECK */
28742876 if (_Py_atomic_load_uintptr_relaxed (& tstate -> eval_breaker ) & _PY_EVAL_EVENTS_MASK ) {
28752877 opcode = executor -> vm_data .opcode ;
2878+ LOAD_NEXT_OP_F_OPCODE ();
28762879 oparg = (oparg & ~255 ) | executor -> vm_data .oparg ;
28772880 next_instr = this_instr ;
2878- LOAD_NEXT_OP_F ();
28792881 if (_PyOpcode_Caches [_PyOpcode_Deopt [opcode ]]) {
28802882 PAUSE_ADAPTIVE_COUNTER (this_instr [1 ].counter );
28812883 }
@@ -2983,6 +2985,7 @@ dummy_func(
29832985 inst (GET_ITER , (iterable -- iter )) {
29842986 /* before: [obj]; after [getiter(obj)] */
29852987 PyObject * iter_o = PyObject_GetIter (PyStackRef_AsPyObjectBorrow (iterable ));
2988+ LOAD_NEXT_OP_F ();
29862989 DECREF_INPUTS ();
29872990 ERROR_IF (iter_o == NULL , error );
29882991 iter = PyStackRef_FromPyObjectSteal (iter_o );
@@ -3036,9 +3039,7 @@ dummy_func(
30363039 #if ENABLE_SPECIALIZATION
30373040 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
30383041 next_instr = this_instr ;
3039- LOAD_NEXT_OP_F (); // TODO this is redundand with DISPATCH_SAME_ARG now,
3040- // though maybe is good to load it before the following func call
3041- _Py_Specialize_ForIter (iter , next_instr , oparg );
3042+ _Py_Specialize_ForIter (iter , next_instr , oparg ); // <- this can modify next_instr!
30423043 DISPATCH_SAME_OPARG ();
30433044 }
30443045 OPCODE_DEFERRED_INC (FOR_ITER );
@@ -3333,6 +3334,7 @@ dummy_func(
33333334 (3 + has_self ) | PY_VECTORCALL_ARGUMENTS_OFFSET , NULL );
33343335 ERROR_IF (res_o == NULL , error );
33353336 res = PyStackRef_FromPyObjectSteal (res_o );
3337+ LOAD_NEXT_OP_F ();
33363338 }
33373339
33383340 pseudo (SETUP_FINALLY , (-- unused ), (HAS_ARG )) = {
@@ -3506,7 +3508,6 @@ dummy_func(
35063508 #if ENABLE_SPECIALIZATION_FT
35073509 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
35083510 next_instr = this_instr ;
3509- LOAD_NEXT_OP_F ();
35103511 _Py_Specialize_Call (callable [0 ], next_instr , oparg + !PyStackRef_IsNull (self_or_null [0 ]));
35113512 DISPATCH_SAME_OPARG ();
35123513 }
@@ -3592,6 +3593,8 @@ dummy_func(
35923593 DECREF_INPUTS ();
35933594 ERROR_IF (res_o == NULL , error );
35943595 res = PyStackRef_FromPyObjectSteal (res_o );
3596+ // when vectorcall calls into eg sys_settrace, our code can be modified
3597+ LOAD_NEXT_OP_F ();
35953598 }
35963599
35973600 op (_MONITOR_CALL , (func [1 ], maybe_self [1 ], args [oparg ] -- func [1 ], maybe_self [1 ], args [oparg ])) {
@@ -3728,6 +3731,7 @@ dummy_func(
37283731 DECREF_INPUTS ();
37293732 ERROR_IF (res_o == NULL , error );
37303733 res = PyStackRef_FromPyObjectSteal (res_o );
3734+ LOAD_NEXT_OP_F ();
37313735 }
37323736
37333737 macro (CALL_NON_PY_GENERAL ) =
@@ -4044,6 +4048,7 @@ dummy_func(
40444048 DECREF_INPUTS ();
40454049 ERROR_IF (res_o == NULL , error );
40464050 res = PyStackRef_FromPyObjectSteal (res_o );
4051+ LOAD_NEXT_OP_F ();
40474052 }
40484053
40494054 macro (CALL_BUILTIN_FAST ) =
@@ -4517,7 +4522,6 @@ dummy_func(
45174522 #if ENABLE_SPECIALIZATION_FT
45184523 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
45194524 next_instr = this_instr ;
4520- LOAD_NEXT_OP_F ();
45214525 _Py_Specialize_CallKw (callable [0 ], next_instr , oparg + !PyStackRef_IsNull (self_or_null [0 ]));
45224526 DISPATCH_SAME_OPARG ();
45234527 }
@@ -4800,7 +4804,6 @@ dummy_func(
48004804 #if ENABLE_SPECIALIZATION_FT
48014805 if (ADAPTIVE_COUNTER_TRIGGERS (counter )) {
48024806 next_instr = this_instr ;
4803- LOAD_NEXT_OP_F ();
48044807 _Py_Specialize_BinaryOp (lhs , rhs , next_instr , oparg , LOCALS_ARRAY );
48054808 DISPATCH_SAME_OPARG ();
48064809 }
@@ -4859,7 +4862,7 @@ dummy_func(
48594862 PAUSE_ADAPTIVE_COUNTER (cache -> counter );
48604863 }
48614864 opcode = original_opcode ;
4862- LOAD_NEXT_OP_F ();
4865+ LOAD_NEXT_OP_F_OPCODE ();
48634866 DISPATCH_GOTO ();
48644867 }
48654868
@@ -4868,12 +4871,12 @@ dummy_func(
48684871 tstate , frame , this_instr );
48694872 ERROR_IF (next_opcode < 0 , error );
48704873 next_instr = this_instr ;
4871- LOAD_NEXT_OP_F ();
48724874 if (_PyOpcode_Caches [next_opcode ]) {
48734875 PAUSE_ADAPTIVE_COUNTER (next_instr [1 ].counter );
48744876 }
48754877 assert (next_opcode > 0 && next_opcode < 256 );
48764878 opcode = next_opcode ;
4879+ LOAD_NEXT_OP_F_OPCODE ();
48774880 DISPATCH_GOTO ();
48784881 }
48794882
@@ -4940,6 +4943,7 @@ dummy_func(
49404943 tier1 inst (EXTENDED_ARG , ( -- )) {
49414944 assert (oparg );
49424945 opcode = next_instr -> op .code ;
4946+ LOAD_NEXT_OP_F_OPCODE ();
49434947 oparg = oparg << 8 | next_instr -> op .arg ;
49444948 PRE_DISPATCH_GOTO ();
49454949 DISPATCH_GOTO ();
0 commit comments