ruby-changes:34255
From: ko1 <ko1@a...>
Date: Tue, 3 Jun 2014 18:01:00 +0900 (JST)
Subject: [ruby-changes:34255] ko1:r46336 (trunk): * gc.c: change the counting method for young objects.
ko1 2014-06-03 18:00:53 +0900 (Tue, 03 Jun 2014) New Revision: 46336 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46336 Log: * gc.c: change the counting method for young objects. clear counter at the beggining of every GC and count promoted (infant->young) objects. Some promotions (infant->young) are transition of promoting to old objects. We should not count such promotions. With this technique, we don't need to check young objects at obj_free(). Modified files: trunk/ChangeLog trunk/gc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 46335) +++ ChangeLog (revision 46336) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jun 3 17:54:21 2014 Koichi Sasada <ko1@a...> + + * gc.c: change the counting method for young objects. + clear counter at the beggining of every GC and + count promoted (infant->young) objects. + + Some promotions (infant->young) are transition of promoting to old + objects. We should not count such promotions. + + With this technique, we don't need to check young objects + at obj_free(). + Tue Jun 3 16:38:19 2014 Koichi Sasada <ko1@a...> * gc.c: add verifying counters code in gc_verify_internal_consistency(). Index: gc.c =================================================================== --- gc.c (revision 46335) +++ gc.c (revision 46336) @@ -801,7 +801,7 @@ RVALUE_PROMOTED_P(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L801 } static inline void -RVALUE_PROMOTE_INFANT(rb_objspace_t *objspace, VALUE obj) +RVALUE_PROMOTE_INFANT(rb_objspace_t *objspace, VALUE obj, int add) { check_gen_consistency(obj); @@ -810,7 +810,9 @@ RVALUE_PROMOTE_INFANT(rb_objspace_t *obj https://github.com/ruby/ruby/blob/trunk/gc.c#L810 #if RGENGC_AGE2_PROMOTION /* infant -> young */ - objspace->rgengc.young_object_count++; + if (add) { + objspace->rgengc.young_object_count++; + } #else /* infant -> old */ objspace->rgengc.old_object_count++; @@ -857,7 +859,6 @@ RVALUE_PROMOTE_YOUNG(rb_objspace_t *objs https://github.com/ruby/ruby/blob/trunk/gc.c#L859 MARK_IN_BITMAP(GET_HEAP_OLDGEN_BITS(obj), obj); - objspace->rgengc.young_object_count--; objspace->rgengc.old_object_count++; check_gen_consistency(obj); @@ -1553,11 +1554,6 @@ obj_free(rb_objspace_t *objspace, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L1554 } #if USE_RGENGC -#if RGENGC_AGE2_PROMOTION - if (RVALUE_YOUNG_P(obj)) { - objspace->rgengc.young_object_count--; - } -#endif if (MARKED_IN_BITMAP(GET_HEAP_OLDGEN_BITS(obj), obj)) { CLEAR_IN_BITMAP(GET_HEAP_OLDGEN_BITS(obj), obj); } @@ -3638,7 +3634,7 @@ rgengc_check_relation(rb_objspace_t *obj https://github.com/ruby/ruby/blob/trunk/gc.c#L3634 } else { if (RVALUE_INFANT_P(obj)) { - RVALUE_PROMOTE_INFANT(objspace, obj); + RVALUE_PROMOTE_INFANT(objspace, obj, FALSE); } } } @@ -3697,6 +3693,12 @@ rb_gc_resurrect(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3693 if (RVALUE_OLD_P(obj)) { objspace->rgengc.old_object_count++; } +#if RGENGC_AGE2_PROMOTION + /* similar reason of old object counts */ + else if (RVALUE_YOUNG_P(obj)) { + objspace->rgengc.young_object_count++; + } +#endif } } @@ -3729,7 +3731,7 @@ gc_mark_children(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L3731 if (RVALUE_WB_PROTECTED(obj)) { if (RVALUE_INFANT_P((VALUE)obj)) { /* infant -> young */ - RVALUE_PROMOTE_INFANT(objspace, (VALUE)obj); + RVALUE_PROMOTE_INFANT(objspace, (VALUE)obj, TRUE); #if RGENGC_AGE2_PROMOTION objspace->rgengc.parent_object_is_old = FALSE; #else @@ -4221,6 +4223,10 @@ gc_marks_body(rb_objspace_t *objspace, i https://github.com/ruby/ruby/blob/trunk/gc.c#L4223 objspace->rgengc.parent_object_is_old = FALSE; objspace->rgengc.during_minor_gc = full_mark ? FALSE : TRUE; +#if RGENGC_AGE2_PROMOTION + objspace->rgengc.young_object_count = 0; +#endif + if (objspace->rgengc.during_minor_gc) { objspace->profile.minor_gc_count++; rgengc_rememberset_mark(objspace, heap_eden); @@ -4797,7 +4803,7 @@ rgengc_rememberset_mark(rb_objspace_t *o https://github.com/ruby/ruby/blob/trunk/gc.c#L4803 rgengc_report(2, objspace, "rgengc_rememberset_mark: clear %p (%s)\n", p, obj_type_name((VALUE)p)); #if RGENGC_AGE2_PROMOTION if (RVALUE_INFANT_P((VALUE)p)) { - RVALUE_PROMOTE_INFANT(objspace, (VALUE)p); + RVALUE_PROMOTE_INFANT(objspace, (VALUE)p, FALSE); RVALUE_PROMOTE_YOUNG(objspace, (VALUE)p); } else if (RVALUE_YOUNG_P((VALUE)p)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/