mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c5b6c189d2
commit
e4c58251b7
5 changed files with 38 additions and 4 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
Tue May 28 00:34:23 2013 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* 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@atdot.net>
|
||||
|
||||
* vm_trace.c (rb_postponed_job_flush): remove a wrong comment.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
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 tpval, void *data)
|
|||
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 tpval, void *data)
|
|||
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 self)
|
|||
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]);
|
||||
}
|
||||
|
|
2
gc.c
2
gc.c
|
@ -2328,6 +2328,8 @@ after_gc_sweep(rb_objspace_t *objspace)
|
|||
}
|
||||
|
||||
free_unused_heaps(objspace);
|
||||
|
||||
gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_END, 0 /* TODO: pass minor/immediate flag? */);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -1731,7 +1731,8 @@ int ruby_native_thread_p(void);
|
|||
#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;
|
||||
|
|
|
@ -17,7 +17,7 @@ class TestTracepointObj < Test::Unit::TestCase
|
|||
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::TestCase
|
|||
}
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue