@@ -60,6 +60,21 @@ struct _stoptheworld_state {
6060
6161/* cross-interpreter data registry */
6262
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 ;
6378
6479/* interpreter state */
6580
@@ -217,6 +232,7 @@ struct _is {
217232 uint16_t optimizer_resume_threshold ;
218233 uint16_t optimizer_backedge_threshold ;
219234 uint32_t next_func_version ;
235+ _rare_events rare_events ;
220236
221237 _Py_GlobalMonitors monitors ;
222238 bool sys_profile_initialized ;
@@ -347,6 +363,19 @@ PyAPI_FUNC(PyStatus) _PyInterpreterState_New(
347363 PyInterpreterState * * pinterp );
348364
349365
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+
350379#ifdef __cplusplus
351380}
352381#endif
0 commit comments