From 6aa2aabd8b8c948d1f9eb2fb367ef24a24f237ce Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 4 Oct 2012 07:31:31 +0000 Subject: [PATCH] gc.c: self-referencing finalizers * gc.c (rb_objspace_call_finalizer): mark self-referencing finalizers before run finalizers, to fix SEGV from btest on 32bit. * gc.c (gc_mark_stacked_objects): extract from gc_marks(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ gc.c | 25 +++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2aa5c12bd..9b902afbe1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Oct 4 16:31:29 2012 Nobuyoshi Nakada + + * gc.c (rb_objspace_call_finalizer): mark self-referencing finalizers + before run finalizers, to fix SEGV from btest on 32bit. + + * gc.c (gc_mark_stacked_objects): extract from gc_marks(). + Thu Oct 4 11:43:28 2012 Nobuyoshi Nakada * thread_pthread.c (ruby_init_stack): round stack limit to page size diff --git a/gc.c b/gc.c index 9a6f6eede7..661f48d008 100644 --- a/gc.c +++ b/gc.c @@ -358,6 +358,7 @@ static int garbage_collect(rb_objspace_t *); static int gc_lazy_sweep(rb_objspace_t *); static void mark_tbl(rb_objspace_t *, st_table *); static void rest_sweep(rb_objspace_t *); +static void gc_mark_stacked_objects(rb_objspace_t *); static double getrusage_time(void); static inline void gc_prof_timer_start(rb_objspace_t *); @@ -1483,6 +1484,9 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace) RVALUE *final_list = 0; size_t i; + mark_tbl(objspace, finalizer_table); + gc_mark_stacked_objects(objspace); + /* run finalizers */ rest_sweep(objspace); @@ -2830,13 +2834,25 @@ gc_mark_children(rb_objspace_t *objspace, VALUE ptr) } } +static void +gc_mark_stacked_objects(rb_objspace_t *objspace) +{ + mark_stack_t *mstack = &objspace->mark_stack; + VALUE obj = 0; + + if (!mstack->index) return; + while (pop_mark_stack(mstack, &obj)) { + gc_mark_children(objspace, obj); + } + shrink_stack_chunk_cache(mstack); +} + static void gc_marks(rb_objspace_t *objspace) { struct gc_list *list; rb_thread_t *th = GET_THREAD(); - mark_stack_t *mstack = &objspace->mark_stack; - VALUE obj = 0; + gc_prof_mark_timer_start(objspace); objspace->heap.live_num = 0; @@ -2870,10 +2886,7 @@ gc_marks(rb_objspace_t *objspace) rb_gc_mark_unlinked_live_method_entries(th->vm); /* marking-loop */ - while (pop_mark_stack(mstack, &obj)) { - gc_mark_children(objspace, obj); - } - shrink_stack_chunk_cache(mstack); + gc_mark_stacked_objects(objspace); gc_prof_mark_timer_stop(objspace); }