Refactor / document instance variable debug counters

This commit is refactoring and documenting the debug counters related to
instance variables.
This commit is contained in:
Aaron Patterson 2023-02-14 14:41:23 -08:00 коммит произвёл Aaron Patterson
Родитель 847a0df058
Коммит ae2340c9d7
2 изменённых файлов: 33 добавлений и 26 удалений

Просмотреть файл

@ -127,29 +127,22 @@ RB_DEBUG_COUNTER(frame_R2C)
RB_DEBUG_COUNTER(frame_C2C)
RB_DEBUG_COUNTER(frame_C2R)
/* instance variable counts
*
* * ivar_get_ic_hit/miss: ivar_get inline cache (ic) hit/miss counts (VM insn)
* * ivar_get_ic_miss_unset: ... by unset (VM insn)
* * ivar_get_ic_miss_noobject: ... by "not T_OBJECT" (VM insn)
* * ivar_set_...: same counts with ivar_set (VM insn)
* * ivar_get/set_base: call counts of "rb_ivar_get/set()".
* because of (1) ic miss.
* (2) direct call by C extensions.
*/
RB_DEBUG_COUNTER(ivar_get_ic_hit)
RB_DEBUG_COUNTER(ivar_get_ic_miss)
RB_DEBUG_COUNTER(ivar_get_ic_miss_noobject)
RB_DEBUG_COUNTER(ivar_set_ic_hit)
RB_DEBUG_COUNTER(ivar_set_ic_miss)
RB_DEBUG_COUNTER(ivar_set_ic_miss_iv_hit)
RB_DEBUG_COUNTER(ivar_set_ic_miss_noobject)
RB_DEBUG_COUNTER(ivar_get_base)
RB_DEBUG_COUNTER(ivar_set_base)
RB_DEBUG_COUNTER(ivar_get_ic_miss_set)
RB_DEBUG_COUNTER(ivar_get_cc_miss_set)
RB_DEBUG_COUNTER(ivar_get_ic_miss_unset)
RB_DEBUG_COUNTER(ivar_get_cc_miss_unset)
/* instance variable counts */
RB_DEBUG_COUNTER(ivar_get_obj_hit) // Only T_OBJECT hits
RB_DEBUG_COUNTER(ivar_get_obj_miss) // Only T_OBJECT misses
RB_DEBUG_COUNTER(ivar_get_ic_hit) // All hits
RB_DEBUG_COUNTER(ivar_get_ic_miss) // All misses
RB_DEBUG_COUNTER(ivar_set_ic_hit) // All hits
RB_DEBUG_COUNTER(ivar_set_obj_hit) // Only T_OBJECT hits
RB_DEBUG_COUNTER(ivar_set_obj_miss) // Only T_OBJECT misses
RB_DEBUG_COUNTER(ivar_set_ic_miss) // All misses
RB_DEBUG_COUNTER(ivar_set_ic_miss_noobject) // Miss because non T_OBJECT
RB_DEBUG_COUNTER(ivar_get_base) // Calls to `rb_ivar_get` (very slow path)
RB_DEBUG_COUNTER(ivar_set_base) // Calls to `ivar_set` (very slow path)
RB_DEBUG_COUNTER(ivar_get_ic_miss_set) // Misses on IV reads where the cache was wrong
RB_DEBUG_COUNTER(ivar_get_cc_miss_set) // Misses on attr_reader where the cache was wrong
RB_DEBUG_COUNTER(ivar_get_ic_miss_unset) // Misses on IV read where the cache wasn't set
RB_DEBUG_COUNTER(ivar_get_cc_miss_unset) // Misses on attr_reader where the cache wasn't set
/* local variable counts
*

Просмотреть файл

@ -1231,10 +1231,17 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call
}
val = ivar_list[index];
#if USE_DEBUG_COUNTER
RB_DEBUG_COUNTER_INC(ivar_get_ic_hit);
if (RB_TYPE_P(obj, T_OBJECT)) {
RB_DEBUG_COUNTER_INC(ivar_get_obj_hit);
}
#endif
RUBY_ASSERT(!UNDEF_P(val));
}
else { // cache miss case
#if RUBY_DEBUG
#if USE_DEBUG_COUNTER
if (is_attr) {
if (cached_id != INVALID_SHAPE_ID) {
RB_DEBUG_COUNTER_INC(ivar_get_cc_miss_set);
@ -1251,6 +1258,11 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call
RB_DEBUG_COUNTER_INC(ivar_get_ic_miss_unset);
}
}
RB_DEBUG_COUNTER_INC(ivar_get_ic_miss);
if (RB_TYPE_P(obj, T_OBJECT)) {
RB_DEBUG_COUNTER_INC(ivar_get_obj_miss);
}
#endif
rb_shape_t *shape = rb_shape_get_shape_by_id(shape_id);
@ -1322,6 +1334,8 @@ static VALUE
vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, int is_attr)
{
#if OPT_IC_FOR_IVAR
RB_DEBUG_COUNTER_INC(ivar_set_ic_miss);
switch (BUILTIN_TYPE(obj)) {
case T_OBJECT:
{
@ -1335,7 +1349,7 @@ vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic,
populate_cache(index, next_shape_id, id, iseq, ic, cc, is_attr);
}
RB_DEBUG_COUNTER_INC(ivar_set_ic_miss_iv_hit);
RB_DEBUG_COUNTER_INC(ivar_set_obj_miss);
return val;
}
case T_CLASS:
@ -1363,7 +1377,6 @@ vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic,
}
}
#endif
RB_DEBUG_COUNTER_INC(ivar_set_ic_miss);
return rb_ivar_set(obj, id, val);
}
@ -1469,6 +1482,7 @@ vm_setivar(VALUE obj, ID id, VALUE val, shape_id_t dest_shape_id, attr_index_t i
RB_OBJ_WRITE(obj, &ptr[index], val);
RB_DEBUG_COUNTER_INC(ivar_set_ic_hit);
RB_DEBUG_COUNTER_INC(ivar_set_obj_hit);
return val;
}
break;