@@ -60,6 +60,21 @@ struct _stoptheworld_state {
60
60
61
61
/* cross-interpreter data registry */
62
62
63
+ /* Tracks some rare events per-interpreter, used by the optimizer to turn on/off
64
+ specific optimizations. */
65
+ typedef struct _rare_events {
66
+ /* Setting an object's class, obj.__class__ = ... */
67
+ uint8_t set_class ;
68
+ /* Setting the bases of a class, cls.__bases__ = ... */
69
+ uint8_t set_bases ;
70
+ /* Setting the PEP 523 frame eval function, _PyInterpreterState_SetFrameEvalFunc() */
71
+ uint8_t set_eval_frame_func ;
72
+ /* Modifying the builtins, __builtins__.__dict__[var] = ... */
73
+ uint8_t builtin_dict ;
74
+ int builtins_dict_watcher_id ;
75
+ /* Modifying a function, e.g. func.__defaults__ = ..., etc. */
76
+ uint8_t func_modification ;
77
+ } _rare_events ;
63
78
64
79
/* interpreter state */
65
80
@@ -217,6 +232,7 @@ struct _is {
217
232
uint16_t optimizer_resume_threshold ;
218
233
uint16_t optimizer_backedge_threshold ;
219
234
uint32_t next_func_version ;
235
+ _rare_events rare_events ;
220
236
221
237
_Py_GlobalMonitors monitors ;
222
238
bool sys_profile_initialized ;
@@ -347,6 +363,19 @@ PyAPI_FUNC(PyStatus) _PyInterpreterState_New(
347
363
PyInterpreterState * * pinterp );
348
364
349
365
366
+ #define RARE_EVENT_INTERP_INC (interp , name ) \
367
+ do { \
368
+ /* saturating add */ \
369
+ if (interp -> rare_events .name < UINT8_MAX ) interp -> rare_events .name ++ ; \
370
+ RARE_EVENT_STAT_INC (name ); \
371
+ } while (0 ); \
372
+
373
+ #define RARE_EVENT_INC (name ) \
374
+ do { \
375
+ PyInterpreterState *interp = PyInterpreterState_Get(); \
376
+ RARE_EVENT_INTERP_INC(interp, name); \
377
+ } while (0); \
378
+
350
379
#ifdef __cplusplus
351
380
}
352
381
#endif
0 commit comments