ruby-changes:31918
From: tmm1 <ko1@a...>
Date: Thu, 5 Dec 2013 13:26:21 +0900 (JST)
Subject: [ruby-changes:31918] tmm1:r43997 (trunk): gc.c: split GC_END event into GC_END_MARK and GC_END_SWEEP
tmm1 2013-12-05 13:26:04 +0900 (Thu, 05 Dec 2013) New Revision: 43997 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43997 Log: gc.c: split GC_END event into GC_END_MARK and GC_END_SWEEP * include/ruby/ruby.h: remove INTERNAL_EVENT_GC_END and replace with two new events: GC_END_MARK and GC_END_SWEEP * gc.c (gc_after_sweep): emit GC_END_SWEEP after lazy sweep is done * gc.c (gc_marks_body): emit GC_END_MARK at end of minor/major mark * ext/-test-/tracepoint/tracepoint.c (struct tracepoint_track): tests for new events. * test/-ext-/tracepoint/test_tracepoint.rb (class TestTracepointObj): ditto. * NEWS: remove ObjectSpace.after_gc_*_hook. These are only a sample, and will be removed before ruby 2.1. * ext/objspace/gc_hook.c: remove ObjectSpace.after_gc_end_hook= Modified files: trunk/ChangeLog trunk/NEWS trunk/ext/-test-/tracepoint/tracepoint.c trunk/ext/objspace/gc_hook.c trunk/gc.c trunk/include/ruby/ruby.h trunk/test/-ext-/tracepoint/test_tracepoint.rb Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 43996) +++ include/ruby/ruby.h (revision 43997) @@ -1712,15 +1712,16 @@ int ruby_native_thread_p(void); https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1712 #define RUBY_EVENT_COVERAGE 0x020000 /* internal events */ -#define RUBY_INTERNAL_EVENT_SWITCH 0x040000 -#define RUBY_EVENT_SWITCH 0x040000 /* obsolete name. this macro is for compatibility */ - /* 0x080000 */ -#define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000 -#define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000 -#define RUBY_INTERNAL_EVENT_GC_START 0x400000 -#define RUBY_INTERNAL_EVENT_GC_END 0x800000 -#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0xf00000 -#define RUBY_INTERNAL_EVENT_MASK 0xfffe0000 +#define RUBY_INTERNAL_EVENT_SWITCH 0x040000 +#define RUBY_EVENT_SWITCH 0x040000 /* obsolete name. this macro is for compatibility */ + /* 0x080000 */ +#define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000 +#define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000 +#define RUBY_INTERNAL_EVENT_GC_START 0x400000 +#define RUBY_INTERNAL_EVENT_GC_END_MARK 0x800000 +#define RUBY_INTERNAL_EVENT_GC_END_SWEEP 0x1000000 +#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0x1f00000 +#define RUBY_INTERNAL_EVENT_MASK 0xfffe0000 typedef unsigned long rb_event_flag_t; typedef void (*rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass); Index: ChangeLog =================================================================== --- ChangeLog (revision 43996) +++ ChangeLog (revision 43997) @@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Dec 5 13:19:03 2013 Aman Gupta <ruby@t...> + + * include/ruby/ruby.h: remove INTERNAL_EVENT_GC_END and replace with + two new events: GC_END_MARK and GC_END_SWEEP + * gc.c (gc_after_sweep): emit GC_END_SWEEP after lazy sweep is done + * gc.c (gc_marks_body): emit GC_END_MARK at end of minor/major mark + * ext/-test-/tracepoint/tracepoint.c (struct tracepoint_track): tests + for new events. + * test/-ext-/tracepoint/test_tracepoint.rb (class TestTracepointObj): + ditto. + * NEWS: remove ObjectSpace.after_gc_*_hook. These are only a sample, + and will be removed before ruby 2.1. + * ext/objspace/gc_hook.c: remove ObjectSpace.after_gc_end_hook= + Thu Dec 5 10:47:56 2013 Nobuyoshi Nakada <nobu@r...> * ruby_atomic.h (ATOMIC_PTR_EXCHANGE): atomic exchange function for Index: gc.c =================================================================== --- gc.c (revision 43996) +++ gc.c (revision 43997) @@ -2954,7 +2954,7 @@ gc_after_sweep(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L2954 } #endif - gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_END, 0 /* TODO: pass minor/immediate flag? */); + gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_END_SWEEP, 0); } static int @@ -4122,7 +4122,7 @@ gc_marks_body(rb_objspace_t *objspace, i https://github.com/ruby/ruby/blob/trunk/gc.c#L4122 gc_mark_roots(objspace, full_mark, 0); gc_mark_stacked_objects(objspace); - /* cleanup */ + gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_END_MARK, 0); rgengc_report(1, objspace, "gc_marks_body: end (%s)\n", full_mark ? "full" : "minor"); } Index: ext/objspace/gc_hook.c =================================================================== --- ext/objspace/gc_hook.c (revision 43996) +++ ext/objspace/gc_hook.c (revision 43997) @@ -88,16 +88,8 @@ set_after_gc_start(VALUE rb_mObjSpace, V https://github.com/ruby/ruby/blob/trunk/ext/objspace/gc_hook.c#L88 "__set_after_gc_start_tpval__", "__set_after_gc_start_proc__"); } -static VALUE -set_after_gc_end(VALUE rb_mObjSpace, VALUE proc) -{ - return set_gc_hook(rb_mObjSpace, proc, RUBY_INTERNAL_EVENT_GC_END, - "__set_after_gc_end_tpval__", "__set_after_gc_end_proc__"); -} - void Init_gc_hook(VALUE rb_mObjSpace) { rb_define_module_function(rb_mObjSpace, "after_gc_start_hook=", set_after_gc_start, 1); - rb_define_module_function(rb_mObjSpace, "after_gc_end_hook=", set_after_gc_end, 1); } Index: ext/-test-/tracepoint/tracepoint.c =================================================================== --- ext/-test-/tracepoint/tracepoint.c (revision 43996) +++ ext/-test-/tracepoint/tracepoint.c (revision 43997) @@ -5,7 +5,8 @@ struct tracepoint_track { https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L5 size_t newobj_count; size_t free_count; size_t gc_start_count; - size_t gc_end_count; + size_t gc_end_mark_count; + size_t gc_end_sweep_count; size_t objects_count; VALUE objects[10]; }; @@ -37,9 +38,14 @@ tracepoint_track_objspace_events_i(VALUE https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L38 track->gc_start_count++; break; } - case RUBY_INTERNAL_EVENT_GC_END: + case RUBY_INTERNAL_EVENT_GC_END_MARK: { - track->gc_end_count++; + track->gc_end_mark_count++; + break; + } + case RUBY_INTERNAL_EVENT_GC_END_SWEEP: + { + track->gc_end_sweep_count++; break; } default: @@ -52,7 +58,8 @@ tracepoint_track_objspace_events(VALUE s https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L58 { struct tracepoint_track track = {0, 0, 0, 0, 0,}; VALUE tpval = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ | RUBY_INTERNAL_EVENT_FREEOBJ | - RUBY_INTERNAL_EVENT_GC_START | RUBY_INTERNAL_EVENT_GC_END, + RUBY_INTERNAL_EVENT_GC_START | RUBY_INTERNAL_EVENT_GC_END_MARK | + RUBY_INTERNAL_EVENT_GC_END_SWEEP, tracepoint_track_objspace_events_i, &track); VALUE result = rb_ary_new(); @@ -63,7 +70,8 @@ tracepoint_track_objspace_events(VALUE s https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L70 rb_ary_push(result, SIZET2NUM(track.newobj_count)); rb_ary_push(result, SIZET2NUM(track.free_count)); rb_ary_push(result, SIZET2NUM(track.gc_start_count)); - rb_ary_push(result, SIZET2NUM(track.gc_end_count)); + rb_ary_push(result, SIZET2NUM(track.gc_end_mark_count)); + rb_ary_push(result, SIZET2NUM(track.gc_end_sweep_count)); rb_ary_cat(result, track.objects, track.objects_count); return result; Index: NEWS =================================================================== --- NEWS (revision 43996) +++ NEWS (revision 43997) @@ -187,8 +187,6 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L187 * ObjectSpace.allocation_method_id * ObjectSpace.allocation_generation * ObjectSpace.reachable_objects_from_root - * ObjectSpace.after_gc_start_hook= - * ObjectSpace.after_gc_end_hook= * ObjectSpace.dump * ObjectSpace.dump_all Index: test/-ext-/tracepoint/test_tracepoint.rb =================================================================== --- test/-ext-/tracepoint/test_tracepoint.rb (revision 43996) +++ test/-ext-/tracepoint/test_tracepoint.rb (revision 43997) @@ -17,13 +17,14 @@ class TestTracepointObj < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/tracepoint/test_tracepoint.rb#L17 nil } - newobj_count, free_count, gc_start_count, gc_end_count, *newobjs = *result + newobj_count, free_count, gc_start_count, gc_end_mark_count, gc_end_sweep_count, *newobjs = *result assert_equal 2, newobj_count assert_equal 2, newobjs.size assert_equal 'foobar', newobjs[0] assert_equal Object, newobjs[1].class assert_operator free_count, :>=, 0 - assert_operator gc_start_count, :>=, gc_end_count + assert_operator gc_start_count, :==, gc_end_mark_count + assert_operator gc_start_count, :>=, gc_end_sweep_count end def test_tracks_objspace_count @@ -39,7 +40,7 @@ class TestTracepointObj < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/tracepoint/test_tracepoint.rb#L40 GC.stat(stat2) GC.enable - newobj_count, free_count, gc_start_count, gc_end_count, *_newobjs = *result + newobj_count, free_count, gc_start_count, gc_end_mark_count, gc_end_sweep_count, *newobjs = *result assert_operator stat2[:total_allocated_object] - stat1[:total_allocated_object], :>=, newobj_count assert_operator 1_000_000, :<=, newobj_count @@ -47,8 +48,9 @@ class TestTracepointObj < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/tracepoint/test_tracepoint.rb#L48 assert_operator stat2[:total_freed_object] + stat2[:heap_final_slot] - stat1[:total_freed_object], :>=, free_count assert_operator stat2[:count] - stat1[:count], :==, gc_start_count - assert_operator gc_start_count, :>=, gc_end_count - assert_operator stat2[:count] - stat1[:count] - 1, :<=, gc_end_count + assert_operator gc_start_count, :==, gc_end_mark_count + assert_operator gc_start_count, :>=, gc_end_sweep_count + assert_operator stat2[:count] - stat1[:count] - 1, :<=, gc_end_sweep_count end def test_tracepoint_specify_normal_and_internal_events -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/