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=

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tmm1 2013-12-05 04:26:04 +00:00
parent fb29aefc7a
commit 393b9e65e9
7 changed files with 46 additions and 31 deletions

View File

@ -1,3 +1,17 @@
Thu Dec 5 13:19:03 2013 Aman Gupta <ruby@tmm1.net>
* 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@ruby-lang.org> Thu Dec 5 10:47:56 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby_atomic.h (ATOMIC_PTR_EXCHANGE): atomic exchange function for * ruby_atomic.h (ATOMIC_PTR_EXCHANGE): atomic exchange function for

2
NEWS
View File

@ -187,8 +187,6 @@ with all sufficient information, see the ChangeLog file.
* ObjectSpace.allocation_method_id * ObjectSpace.allocation_method_id
* ObjectSpace.allocation_generation * ObjectSpace.allocation_generation
* ObjectSpace.reachable_objects_from_root * ObjectSpace.reachable_objects_from_root
* ObjectSpace.after_gc_start_hook=
* ObjectSpace.after_gc_end_hook=
* ObjectSpace.dump * ObjectSpace.dump
* ObjectSpace.dump_all * ObjectSpace.dump_all

View File

@ -5,7 +5,8 @@ struct tracepoint_track {
size_t newobj_count; size_t newobj_count;
size_t free_count; size_t free_count;
size_t gc_start_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; size_t objects_count;
VALUE objects[10]; VALUE objects[10];
}; };
@ -37,9 +38,14 @@ tracepoint_track_objspace_events_i(VALUE tpval, void *data)
track->gc_start_count++; track->gc_start_count++;
break; 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; break;
} }
default: default:
@ -52,7 +58,8 @@ tracepoint_track_objspace_events(VALUE self)
{ {
struct tracepoint_track track = {0, 0, 0, 0, 0,}; struct tracepoint_track track = {0, 0, 0, 0, 0,};
VALUE tpval = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ | RUBY_INTERNAL_EVENT_FREEOBJ | 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); tracepoint_track_objspace_events_i, &track);
VALUE result = rb_ary_new(); VALUE result = rb_ary_new();
@ -63,7 +70,8 @@ tracepoint_track_objspace_events(VALUE self)
rb_ary_push(result, SIZET2NUM(track.newobj_count)); rb_ary_push(result, SIZET2NUM(track.newobj_count));
rb_ary_push(result, SIZET2NUM(track.free_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_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); rb_ary_cat(result, track.objects, track.objects_count);
return result; return result;

View File

@ -88,16 +88,8 @@ set_after_gc_start(VALUE rb_mObjSpace, VALUE proc)
"__set_after_gc_start_tpval__", "__set_after_gc_start_proc__"); "__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 void
Init_gc_hook(VALUE rb_mObjSpace) 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_start_hook=", set_after_gc_start, 1);
rb_define_module_function(rb_mObjSpace, "after_gc_end_hook=", set_after_gc_end, 1);
} }

4
gc.c
View File

@ -2954,7 +2954,7 @@ gc_after_sweep(rb_objspace_t *objspace)
} }
#endif #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 static int
@ -4122,7 +4122,7 @@ gc_marks_body(rb_objspace_t *objspace, int full_mark)
gc_mark_roots(objspace, full_mark, 0); gc_mark_roots(objspace, full_mark, 0);
gc_mark_stacked_objects(objspace); 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"); rgengc_report(1, objspace, "gc_marks_body: end (%s)\n", full_mark ? "full" : "minor");
} }

View File

@ -1718,8 +1718,9 @@ int ruby_native_thread_p(void);
#define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000 #define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000
#define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000 #define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000
#define RUBY_INTERNAL_EVENT_GC_START 0x400000 #define RUBY_INTERNAL_EVENT_GC_START 0x400000
#define RUBY_INTERNAL_EVENT_GC_END 0x800000 #define RUBY_INTERNAL_EVENT_GC_END_MARK 0x800000
#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0xf00000 #define RUBY_INTERNAL_EVENT_GC_END_SWEEP 0x1000000
#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0x1f00000
#define RUBY_INTERNAL_EVENT_MASK 0xfffe0000 #define RUBY_INTERNAL_EVENT_MASK 0xfffe0000
typedef unsigned long rb_event_flag_t; typedef unsigned long rb_event_flag_t;

View File

@ -17,13 +17,14 @@ class TestTracepointObj < Test::Unit::TestCase
nil 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, newobj_count
assert_equal 2, newobjs.size assert_equal 2, newobjs.size
assert_equal 'foobar', newobjs[0] assert_equal 'foobar', newobjs[0]
assert_equal Object, newobjs[1].class assert_equal Object, newobjs[1].class
assert_operator free_count, :>=, 0 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 end
def test_tracks_objspace_count def test_tracks_objspace_count
@ -39,7 +40,7 @@ class TestTracepointObj < Test::Unit::TestCase
GC.stat(stat2) GC.stat(stat2)
GC.enable 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 stat2[:total_allocated_object] - stat1[:total_allocated_object], :>=, newobj_count
assert_operator 1_000_000, :<=, newobj_count assert_operator 1_000_000, :<=, newobj_count
@ -47,8 +48,9 @@ class TestTracepointObj < Test::Unit::TestCase
assert_operator stat2[:total_freed_object] + stat2[:heap_final_slot] - stat1[:total_freed_object], :>=, free_count 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 stat2[:count] - stat1[:count], :==, gc_start_count
assert_operator gc_start_count, :>=, gc_end_count assert_operator gc_start_count, :==, gc_end_mark_count
assert_operator stat2[:count] - stat1[:count] - 1, :<=, gc_end_count assert_operator gc_start_count, :>=, gc_end_sweep_count
assert_operator stat2[:count] - stat1[:count] - 1, :<=, gc_end_sweep_count
end end
def test_tracepoint_specify_normal_and_internal_events def test_tracepoint_specify_normal_and_internal_events