ruby-changes:31928
From: tmm1 <ko1@a...>
Date: Thu, 5 Dec 2013 18:24:10 +0900 (JST)
Subject: [ruby-changes:31928] tmm1:r44007 (trunk): ext/objspace: remove OS.after_gc_start_hook= and move internal test
tmm1 2013-12-05 18:24:02 +0900 (Thu, 05 Dec 2013) New Revision: 44007 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44007 Log: ext/objspace: remove OS.after_gc_start_hook= and move internal test * ext/objspace/gc_hook.c: remove this file * ext/-test-/tracepoint/gc_hook.c: new filename for above * ext/objspace/objspace.c: remove ObjectSpace.after_gc_start_hook= * test/objspace/test_objspace.rb: remove test * test/-ext-/tracepoint/test_tracepoint.rb: add above test for tracepoint re-entry Added files: trunk/ext/-test-/tracepoint/gc_hook.c Removed files: trunk/ext/objspace/gc_hook.c Modified files: trunk/ChangeLog trunk/ext/-test-/tracepoint/tracepoint.c trunk/ext/objspace/objspace.c trunk/test/-ext-/tracepoint/test_tracepoint.rb trunk/test/objspace/test_objspace.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 44006) +++ ChangeLog (revision 44007) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Dec 5 18:18:08 2013 Aman Gupta <ruby@t...> + + * ext/objspace/gc_hook.c: remove this file + * ext/-test-/tracepoint/gc_hook.c: new filename for above + * ext/objspace/objspace.c: remove ObjectSpace.after_gc_start_hook= + * test/objspace/test_objspace.rb: remove test + * test/-ext-/tracepoint/test_tracepoint.rb: add above test for + tracepoint re-entry + Thu Dec 5 17:44:53 2013 Koichi Sasada <ko1@a...> * gc.c: change function names vm_ prefix to objspace_ prefix. Index: ext/objspace/gc_hook.c =================================================================== --- ext/objspace/gc_hook.c (revision 44006) +++ ext/objspace/gc_hook.c (revision 44007) @@ -1,95 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/objspace/gc_hook.c#L0 -/********************************************************************** - - gc_hook.c - GC hook mechanism/ObjectSpace extender for MRI. - - $Author$ - created at: Tue May 28 01:34:25 2013 - - NOTE: This extension library is not expected to exist except C Ruby. - NOTE: This feature is an example usage of internal event tracing APIs. - - All the files in this distribution are covered under the Ruby's - license (see the file COPYING). - -**********************************************************************/ - -#include "ruby/ruby.h" -#include "ruby/debug.h" - -static int invoking; /* TODO: should not be global variable */ - -static VALUE -invoke_proc_ensure(void *dmy) -{ - invoking = 0; - return Qnil; -} - -static VALUE -invoke_proc_begin(VALUE proc) -{ - return rb_proc_call(proc, rb_ary_new()); -} - -static void -invoke_proc(void *data) -{ - VALUE proc = (VALUE)data; - invoking += 1; - rb_ensure(invoke_proc_begin, proc, invoke_proc_ensure, 0); -} - -static void -gc_start_end_i(VALUE tpval, void *data) -{ - if (0) { - rb_trace_arg_t *tparg = rb_tracearg_from_tracepoint(tpval); - fprintf(stderr, "trace: %s\n", rb_tracearg_event_flag(tparg) == RUBY_INTERNAL_EVENT_GC_START ? "gc_start" : "gc_end"); - } - - if (invoking == 0) { - rb_postponed_job_register(0, invoke_proc, data); - } -} - -static VALUE -set_gc_hook(VALUE rb_mObjSpace, VALUE proc, rb_event_flag_t event, const char *tp_str, const char *proc_str) -{ - VALUE tpval; - ID tp_key = rb_intern(tp_str); - ID proc_key = rb_intern(proc_str); - - /* disable previous keys */ - if (rb_ivar_defined(rb_mObjSpace, tp_key) != 0 && - RTEST(tpval = rb_ivar_get(rb_mObjSpace, tp_key))) { - rb_tracepoint_disable(tpval); - rb_ivar_set(rb_mObjSpace, tp_key, Qnil); - rb_ivar_set(rb_mObjSpace, proc_key, Qnil); - } - - if (RTEST(proc)) { - if (!rb_obj_is_proc(proc)) { - rb_raise(rb_eTypeError, "trace_func needs to be Proc"); - } - - tpval = rb_tracepoint_new(0, event, gc_start_end_i, (void *)proc); - rb_ivar_set(rb_mObjSpace, tp_key, tpval); - rb_ivar_set(rb_mObjSpace, proc_key, proc); /* GC guard */ - rb_tracepoint_enable(tpval); - } - - return proc; -} - -static VALUE -set_after_gc_start(VALUE rb_mObjSpace, VALUE proc) -{ - return set_gc_hook(rb_mObjSpace, proc, RUBY_INTERNAL_EVENT_GC_START, - "__set_after_gc_start_tpval__", "__set_after_gc_start_proc__"); -} - -void -Init_gc_hook(VALUE rb_mObjSpace) -{ - rb_define_module_function(rb_mObjSpace, "after_gc_start_hook=", set_after_gc_start, 1); -} Index: ext/objspace/objspace.c =================================================================== --- ext/objspace/objspace.c (revision 44006) +++ ext/objspace/objspace.c (revision 44007) @@ -716,7 +716,6 @@ reachable_objects_from_root(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L716 } void Init_object_tracing(VALUE rb_mObjSpace); -void Init_gc_hook(VALUE rb_mObjSpace); void Init_objspace_dump(VALUE rb_mObjSpace); /* @@ -768,6 +767,5 @@ Init_objspace(void) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L767 rb_define_method(rb_mInternalObjectWrapper, "internal_object_id", iow_internal_object_id, 0); Init_object_tracing(rb_mObjSpace); - Init_gc_hook(rb_mObjSpace); Init_objspace_dump(rb_mObjSpace); } Index: ext/-test-/tracepoint/tracepoint.c =================================================================== --- ext/-test-/tracepoint/tracepoint.c (revision 44006) +++ ext/-test-/tracepoint/tracepoint.c (revision 44007) @@ -85,10 +85,13 @@ tracepoint_specify_normal_and_internal_e https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/tracepoint.c#L85 return Qnil; /* should not be reached */ } +void Init_gc_hook(VALUE); + void Init_tracepoint(void) { VALUE mBug = rb_define_module("Bug"); + Init_gc_hook(mBug); rb_define_module_function(mBug, "tracepoint_track_objspace_events", tracepoint_track_objspace_events, 0); rb_define_module_function(mBug, "tracepoint_specify_normal_and_internal_events", tracepoint_specify_normal_and_internal_events, 0); } Index: ext/-test-/tracepoint/gc_hook.c =================================================================== --- ext/-test-/tracepoint/gc_hook.c (revision 0) +++ ext/-test-/tracepoint/gc_hook.c (revision 44007) @@ -0,0 +1,80 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/gc_hook.c#L1 +#include "ruby/ruby.h" +#include "ruby/debug.h" + +static int invoking; /* TODO: should not be global variable */ + +static VALUE +invoke_proc_ensure(void *dmy) +{ + invoking = 0; + return Qnil; +} + +static VALUE +invoke_proc_begin(VALUE proc) +{ + return rb_proc_call(proc, rb_ary_new()); +} + +static void +invoke_proc(void *data) +{ + VALUE proc = (VALUE)data; + invoking += 1; + rb_ensure(invoke_proc_begin, proc, invoke_proc_ensure, 0); +} + +static void +gc_start_end_i(VALUE tpval, void *data) +{ + if (0) { + rb_trace_arg_t *tparg = rb_tracearg_from_tracepoint(tpval); + fprintf(stderr, "trace: %s\n", rb_tracearg_event_flag(tparg) == RUBY_INTERNAL_EVENT_GC_START ? "gc_start" : "gc_end"); + } + + if (invoking == 0) { + rb_postponed_job_register(0, invoke_proc, data); + } +} + +static VALUE +set_gc_hook(VALUE module, VALUE proc, rb_event_flag_t event, const char *tp_str, const char *proc_str) +{ + VALUE tpval; + ID tp_key = rb_intern(tp_str); + ID proc_key = rb_intern(proc_str); + + /* disable previous keys */ + if (rb_ivar_defined(module, tp_key) != 0 && + RTEST(tpval = rb_ivar_get(module, tp_key))) { + rb_tracepoint_disable(tpval); + rb_ivar_set(module, tp_key, Qnil); + rb_ivar_set(module, proc_key, Qnil); + } + + if (RTEST(proc)) { + if (!rb_obj_is_proc(proc)) { + rb_raise(rb_eTypeError, "trace_func needs to be Proc"); + } + + tpval = rb_tracepoint_new(0, event, gc_start_end_i, (void *)proc); + rb_ivar_set(module, tp_key, tpval); + rb_ivar_set(module, proc_key, proc); /* GC guard */ + rb_tracepoint_enable(tpval); + } + + return proc; +} + +static VALUE +set_after_gc_start(VALUE module, VALUE proc) +{ + return set_gc_hook(module, proc, RUBY_INTERNAL_EVENT_GC_START, + "__set_after_gc_start_tpval__", "__set_after_gc_start_proc__"); +} + +void +Init_gc_hook(VALUE module) +{ + rb_define_module_function(module, "after_gc_start_hook=", set_after_gc_start, 1); +} Property changes on: ext/-test-/tracepoint/gc_hook.c ___________________________________________________________________ Added: svn:eol-style + LF Index: test/-ext-/tracepoint/test_tracepoint.rb =================================================================== --- test/-ext-/tracepoint/test_tracepoint.rb (revision 44006) +++ test/-ext-/tracepoint/test_tracepoint.rb (revision 44007) @@ -1,5 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/tracepoint/test_tracepoint.rb#L1 require 'test/unit' require '-test-/tracepoint' +require_relative '../../ruby/envutil' class TestTracepointObj < Test::Unit::TestCase def test_not_available_from_ruby @@ -56,4 +57,24 @@ class TestTracepointObj < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/tracepoint/test_tracepoint.rb#L57 def test_tracepoint_specify_normal_and_internal_events assert_raise(TypeError){ Bug.tracepoint_specify_normal_and_internal_events } end + + def test_after_gc_start_hook_with_GC_stress + bug8492 = '[ruby-dev:47400] [Bug #8492]: infinite after_gc_start_hook reentrance' + assert_nothing_raised(Timeout::Error, bug8492) do + assert_in_out_err(%w[-r-test-/tracepoint], <<-'end;', /\A[1-9]/, timeout: 2) + stress, GC.stress = GC.stress, false + count = 0 + Bug.after_gc_start_hook = proc {count += 1} + begin + GC.stress = true + 3.times {Object.new} + ensure + GC.stress = stress + Bug.after_gc_start_hook = nil + end + puts count + end; + end + end + end Index: test/objspace/test_objspace.rb =================================================================== --- test/objspace/test_objspace.rb (revision 44006) +++ test/objspace/test_objspace.rb (revision 44007) @@ -193,25 +193,6 @@ class TestObjSpace < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L193 assert_equal(nil, ObjectSpace.allocation_sourcefile(obj3)) end - def test_after_gc_start_hook_with_GC_stress - bug8492 = '[ruby-dev:47400] [Bug #8492]: infinite after_gc_start_hook reentrance' - assert_nothing_raised(Timeout::Error, bug8492) do - assert_in_out_err(%w[-robjspace], <<-'end;', /\A[1-9]/, timeout: 2) - stress, GC.stress = GC.stress, false - count = 0 - ObjectSpace.after_gc_start_hook = proc {count += 1} - begin - GC.stress = true - 3.times {Object.new} - ensure - GC.stress = stress - ObjectSpace.after_gc_start_hook = nil - end - puts count - end; - end - end - def test_dump_to_default line = nil info = nil -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/