diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-15 08:25:58 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-15 08:25:58 +0000 |
commit | c3cf4effed211250aeec563a6261cd99895f4392 (patch) | |
tree | d021467aaa3111c04f12872a0aa109644ac8e569 | |
parent | 71388fa4e159f614b52371ef1f35e3d1e5789c70 (diff) | |
download | ruby-c3cf4effed211250aeec563a6261cd99895f4392.tar.gz |
add several counters to analyze ivar inline caches.
* debug_counter.h: add (and renamed) several counters:
ivar_get_ic_hit
ivar_get_ic_miss
ivar_get_ic_miss_serial
ivar_get_ic_miss_unset
ivar_get_ic_miss_noobject
ivar_set_ic_hit
ivar_set_ic_miss
ivar_set_ic_miss_serial
ivar_set_ic_miss_unset
ivar_set_ic_miss_oorange
ivar_set_ic_miss_noobject
ivar_get_base
ivar_set_base
See related source code to know what counters mean.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | debug_counter.h | 19 | ||||
-rw-r--r-- | variable.c | 4 | ||||
-rw-r--r-- | vm_insnhelper.c | 27 |
3 files changed, 33 insertions, 17 deletions
diff --git a/debug_counter.h b/debug_counter.h index 718486bf34..be2138d3bb 100644 --- a/debug_counter.h +++ b/debug_counter.h @@ -22,12 +22,19 @@ RB_DEBUG_COUNTER(mc_class_serial_miss) RB_DEBUG_COUNTER(mc_cme_complement) RB_DEBUG_COUNTER(mc_cme_complement_hit) RB_DEBUG_COUNTER(mc_search_super) -RB_DEBUG_COUNTER(ivar_get_hit) -RB_DEBUG_COUNTER(ivar_get_miss) -RB_DEBUG_COUNTER(ivar_set_hit) -RB_DEBUG_COUNTER(ivar_set_miss) -RB_DEBUG_COUNTER(ivar_get) -RB_DEBUG_COUNTER(ivar_set) +RB_DEBUG_COUNTER(ivar_get_ic_hit) +RB_DEBUG_COUNTER(ivar_get_ic_miss) +RB_DEBUG_COUNTER(ivar_get_ic_miss_serial) +RB_DEBUG_COUNTER(ivar_get_ic_miss_unset) +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_serial) +RB_DEBUG_COUNTER(ivar_set_ic_miss_unset) +RB_DEBUG_COUNTER(ivar_set_ic_miss_oorange) +RB_DEBUG_COUNTER(ivar_set_ic_miss_noobject) +RB_DEBUG_COUNTER(ivar_get_base) +RB_DEBUG_COUNTER(ivar_set_base) #endif #ifndef RUBY_DEBUG_COUNTER_H diff --git a/variable.c b/variable.c index d1d96284a1..cfc987eb9e 100644 --- a/variable.c +++ b/variable.c @@ -1210,7 +1210,7 @@ VALUE rb_ivar_get(VALUE obj, ID id) { VALUE iv = rb_ivar_lookup(obj, id, Qundef); - RB_DEBUG_COUNTER_INC(ivar_get); + RB_DEBUG_COUNTER_INC(ivar_get_base); if (iv == Qundef) { if (RTEST(ruby_verbose)) @@ -1317,7 +1317,7 @@ rb_ivar_set(VALUE obj, ID id, VALUE val) struct ivar_update ivup; uint32_t i, len; - RB_DEBUG_COUNTER_INC(ivar_set); + RB_DEBUG_COUNTER_INC(ivar_set_base); rb_check_frozen(obj); diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 61d0289ad5..0ad784ed5a 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -884,7 +884,10 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr) #if USE_IC_FOR_IVAR if (LIKELY(RB_TYPE_P(obj, T_OBJECT))) { VALUE val = Qundef; - if (LIKELY(is_attr ? cc->aux.index > 0 : ic->ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass))) { + if (LIKELY(is_attr ? + RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_unset, cc->aux.index > 0) : + RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_serial, + ic->ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass)))) { st_index_t index = !is_attr ? ic->ic_value.index : (cc->aux.index - 1); if (LIKELY(index < ROBJECT_NUMIV(obj))) { val = ROBJECT_IVPTR(obj)[index]; @@ -892,10 +895,10 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr) undef_check: if (UNLIKELY(val == Qundef)) { if (!is_attr && RTEST(ruby_verbose)) - rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id)); + rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id)); val = Qnil; } - RB_DEBUG_COUNTER_INC(ivar_get_hit); + RB_DEBUG_COUNTER_INC(ivar_get_ic_hit); return val; } else { @@ -919,8 +922,11 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr) goto undef_check; } } + else { + RB_DEBUG_COUNTER_INC(ivar_get_ic_miss_noobject); + } #endif /* USE_IC_FOR_IVAR */ - RB_DEBUG_COUNTER_INC(ivar_get_miss); + RB_DEBUG_COUNTER_INC(ivar_get_ic_miss); if (is_attr) return rb_attr_get(obj, id); @@ -938,14 +944,14 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic, struct rb_call_cache *cc, int is_ st_data_t index; if (LIKELY( - (!is_attr && ic->ic_serial == RCLASS_SERIAL(klass)) || - (is_attr && cc->aux.index > 0))) { + (!is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_serial, ic->ic_serial == RCLASS_SERIAL(klass))) || + ( is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_unset, cc->aux.index > 0)))) { VALUE *ptr = ROBJECT_IVPTR(obj); index = !is_attr ? ic->ic_value.index : cc->aux.index-1; - if (index < ROBJECT_NUMIV(obj)) { + if (RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_oorange, index < ROBJECT_NUMIV(obj))) { RB_OBJ_WRITE(obj, &ptr[index], val); - RB_DEBUG_COUNTER_INC(ivar_set_hit); + RB_DEBUG_COUNTER_INC(ivar_set_ic_hit); return val; /* inline cache hit */ } } @@ -967,8 +973,11 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic, struct rb_call_cache *cc, int is_ /* fall through */ } } + else { + RB_DEBUG_COUNTER_INC(ivar_set_ic_miss_noobject); + } #endif /* USE_IC_FOR_IVAR */ - RB_DEBUG_COUNTER_INC(ivar_set_miss); + RB_DEBUG_COUNTER_INC(ivar_set_ic_miss); return rb_ivar_set(obj, id, val); } |