ruby-changes:28911
From: ko1 <ko1@a...>
Date: Tue, 28 May 2013 00:40:41 +0900 (JST)
Subject: [ruby-changes:28911] ko1:r40963 (trunk): * include/ruby/ruby.h, gc.c: add new internal event
ko1 2013-05-28 00:40:27 +0900 (Tue, 28 May 2013) New Revision: 40963 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40963 Log: * include/ruby/ruby.h, gc.c: add new internal event RUBY_INTERNAL_EVENT_GC_END. This event invokes at the end of after_sweep(). Time chart with lazy sweep is here: (1) Kick RUBY_INTERNAL_EVENT_GC_START (2) [gc_marks()] (3) [lazy_sweep()] (4) [... run Ruby program (mutator) with lazy_sweep() ...] (5) [after_sweep()] (6) Kick RUBY_INTERNAL_EVENT_GC_END (7) [... run Ruby program (mutator), and go to (1) ...] * ext/-test-/tracepoint/tracepoint.c, test/-ext-/tracepoint/test_tracepoint.rb: modify a test. Modified files: trunk/ChangeLog trunk/ext/-test-/tracepoint/tracepoint.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 40962) +++ include/ruby/ruby.h (revision 40963) @@ -1731,7 +1731,8 @@ int ruby_native_thread_p(void); https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1731 #define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000 #define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000 #define RUBY_INTERNAL_EVENT_GC_START 0x400000 -#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0x700000 +#define RUBY_INTERNAL_EVENT_GC_END 0x800000 +#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0xf00000 #define RUBY_INTERNAL_EVENT_MASK 0xfffe0000 typedef unsigned long rb_event_flag_t; Index: ChangeLog =================================================================== --- ChangeLog (revision 40962) +++ ChangeLog (revision 40963) @@ -1,3 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue May 28 00:34:23 2013 Koichi Sasada <ko1@a...> + + * include/ruby/ruby.h, gc.c: add new internal event + RUBY_INTERNAL_EVENT_GC_END. This event invokes at the end of + after_sweep(). + Time chart with lazy sweep is here: + (1) Kick RUBY_INTERNAL_EVENT_GC_START + (2) [gc_marks()] + (3) [lazy_sweep()] + (4) [... run Ruby program (mutator) with lazy_sweep() ...] + (5) [after_sweep()] + (6) Kick RUBY_INTERNAL_EVENT_GC_END + (7) [... run Ruby program (mutator), and go to (1) ...] + + * ext/-test-/tracepoint/tracepoint.c, + test/-ext-/tracepoint/test_tracepoint.rb: modify a test. + Tue May 28 00:18:57 2013 Koichi Sasada <ko1@a...> * vm_trace.c (rb_postponed_job_flush): remove a wrong comment. Index: gc.c =================================================================== --- gc.c (revision 40962) +++ gc.c (revision 40963) @@ -2328,6 +2328,8 @@ after_gc_sweep(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L2328 } free_unused_heaps(objspace); + + gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_END, 0 /* TODO: pass minor/immediate flag? */); } static int Index: ext/-test-/tracepoint/tracepoint.c =================================================================== --- ext/-test-/tracepoint/tracepoint.c (revision 40962) +++ ext/-test-/tracepoint/tracepoint.c (revision 40963) @@ -4,6 +4,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L4 static size_t newobj_count; static size_t free_count; static size_t gc_start_count; +static size_t gc_end_count; static size_t objects_count; static VALUE objects[10]; @@ -29,6 +30,11 @@ tracepoint_track_objspace_events_i(VALUE https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L30 gc_start_count++; break; } + case RUBY_INTERNAL_EVENT_GC_END: + { + gc_end_count++; + break; + } default: rb_raise(rb_eRuntimeError, "unknown event"); } @@ -37,7 +43,9 @@ tracepoint_track_objspace_events_i(VALUE https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L43 VALUE tracepoint_track_objspace_events(VALUE self) { - VALUE tpval = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ | RUBY_INTERNAL_EVENT_FREEOBJ | RUBY_INTERNAL_EVENT_GC_START, tracepoint_track_objspace_events_i, 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, + tracepoint_track_objspace_events_i, 0); VALUE result = rb_ary_new(); int i; @@ -50,6 +58,7 @@ tracepoint_track_objspace_events(VALUE s https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L58 rb_ary_push(result, SIZET2NUM(newobj_count)); rb_ary_push(result, SIZET2NUM(free_count)); rb_ary_push(result, SIZET2NUM(gc_start_count)); + rb_ary_push(result, SIZET2NUM(gc_end_count)); for (i=0; i<objects_count; i++) { rb_ary_push(result, objects[i]); } Index: test/-ext-/tracepoint/test_tracepoint.rb =================================================================== --- test/-ext-/tracepoint/test_tracepoint.rb (revision 40962) +++ test/-ext-/tracepoint/test_tracepoint.rb (revision 40963) @@ -17,7 +17,7 @@ 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, *newobjs = *result + newobj_count, free_count, gc_start_count, gc_end_count, *newobjs = *result assert_equal 2, newobj_count assert_equal 2, newobjs.size assert_equal 'foobar', newobjs[0] @@ -31,10 +31,15 @@ class TestTracepointObj < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/tracepoint/test_tracepoint.rb#L31 } GC.stat(stat2) - newobj_count, free_count, gc_start_count, *newobjs = *result + newobj_count, free_count, gc_start_count, gc_end_count, *newobjs = *result assert_operator stat2[:total_allocated_object] - stat1[:total_allocated_object], :>=, newobj_count + assert_operator 1_000_000, :<=, newobj_count + assert_operator stat2[:total_freed_object] - 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 end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/