From 04f0325c47e1403882661f9010741bcc6d8c86aa Mon Sep 17 00:00:00 2001 From: Suraj N. Kurapati Date: Fri, 30 Oct 2009 22:00:34 -0700 Subject: [PATCH 1/2] * gc.c: refactor common code from mark_current_machine_context() and rb_gc_mark_machine_stack() into get_machine_stack_bounds(). --- ChangeLog | 5 +++++ gc.c | 55 +++++++++++++++++++++++++++---------------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index f0100d4..01fae7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -311,6 +311,11 @@ Sun Oct 25 13:33:58 2009 Nobuyoshi Nakada * io.c (io_cntl): F_DUPFD is platform dependent. +Mon Oct 25 13:28:00 2009 Suraj N. Kurapati + + * gc.c: refactor common code from mark_current_machine_context() + and rb_gc_mark_machine_stack() into get_machine_stack_bounds(). + Sun Oct 25 10:19:09 2009 Nobuyoshi Nakada * ext/dl/handle.c (rb_dlhandle_close): fixed an invalid local diff --git a/gc.c b/gc.c index 2568d42..0b588dc 100644 --- a/gc.c +++ b/gc.c @@ -2090,6 +2090,27 @@ obj_free(rb_objspace_t *objspace, VALUE obj) void rb_vm_mark(void *ptr); static void +get_machine_stack_bounds(rb_thread_t *th, VALUE **stack_start, VALUE **stack_end, unsigned stack_end_increment) +{ +#if STACK_GROW_DIRECTION < 0 + *stack_start = th->machine_stack_end; + *stack_end = th->machine_stack_start; +#elif STACK_GROW_DIRECTION > 0 + *stack_start = th->machine_stack_start; + *stack_end = th->machine_stack_end + stack_end_increment; +#else + if (th->machine_stack_end < th->machine_stack_start) { + *stack_start = th->machine_stack_end; + *stack_end = th->machine_stack_start; + } + else { + *stack_start = th->machine_stack_start; + *stack_end = th->machine_stack_end + stack_end_increment; + } +#endif +} + +static void mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th) { rb_jmp_buf save_regs_gc_mark; @@ -2100,22 +2121,7 @@ mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th) rb_setjmp(save_regs_gc_mark); SET_STACK_END; -#if STACK_GROW_DIRECTION < 0 - stack_start = th->machine_stack_end; - stack_end = th->machine_stack_start; -#elif STACK_GROW_DIRECTION > 0 - stack_start = th->machine_stack_start; - stack_end = th->machine_stack_end + 1; -#else - if (th->machine_stack_end < th->machine_stack_start) { - stack_start = th->machine_stack_end; - stack_end = th->machine_stack_start; - } - else { - stack_start = th->machine_stack_start; - stack_end = th->machine_stack_end + 1; - } -#endif + get_machine_stack_bounds(th, &stack_start, &stack_end, 1); mark_locations_array(objspace, (VALUE*)save_regs_gc_mark, @@ -2219,19 +2225,12 @@ rb_garbage_collect(void) void rb_gc_mark_machine_stack(rb_thread_t *th) { + VALUE *stack_start, *stack_end; + get_machine_stack_bounds(th, &stack_start, &stack_end, 0); + rb_objspace_t *objspace = &rb_objspace; -#if STACK_GROW_DIRECTION < 0 - rb_gc_mark_locations(th->machine_stack_end, th->machine_stack_start); -#elif STACK_GROW_DIRECTION > 0 - rb_gc_mark_locations(th->machine_stack_start, th->machine_stack_end); -#else - if (th->machine_stack_start < th->machine_stack_end) { - rb_gc_mark_locations(th->machine_stack_start, th->machine_stack_end); - } - else { - rb_gc_mark_locations(th->machine_stack_end, th->machine_stack_start); - } -#endif + rb_gc_mark_locations(stack_start, stack_end); + #ifdef __ia64 rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end); #endif -- 1.6.5.1