[前][次][番号順一覧][スレッド一覧]

ruby-changes:45908

From: ko1 <ko1@a...>
Date: Wed, 15 Mar 2017 17:26:09 +0900 (JST)
Subject: [ruby-changes:45908] ko1:r57980 (trunk): add several counters to analyze ivar inline caches.

ko1	2017-03-15 17:25:58 +0900 (Wed, 15 Mar 2017)

  New Revision: 57980

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57980

  Log:
    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.

  Modified files:
    trunk/debug_counter.h
    trunk/variable.c
    trunk/vm_insnhelper.c
Index: debug_counter.h
===================================================================
--- debug_counter.h	(revision 57979)
+++ debug_counter.h	(revision 57980)
@@ -22,12 +22,19 @@ RB_DEBUG_COUNTER(mc_class_serial_miss) https://github.com/ruby/ruby/blob/trunk/debug_counter.h#L22
 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
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 57979)
+++ vm_insnhelper.c	(revision 57980)
@@ -884,7 +884,10 @@ vm_getivar(VALUE obj, ID id, IC ic, stru https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L884
 #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, stru https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L895
 	  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, stru https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L922
 	    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, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L944
 	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, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L973
 	    /* 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);
 }
 
Index: variable.c
===================================================================
--- variable.c	(revision 57979)
+++ variable.c	(revision 57980)
@@ -1210,7 +1210,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L1210
 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) https://github.com/ruby/ruby/blob/trunk/variable.c#L1317
     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);
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]