ruby-changes:34387
From: nagachika <ko1@a...>
Date: Fri, 20 Jun 2014 00:57:09 +0900 (JST)
Subject: [ruby-changes:34387] nagachika:r46468 (ruby_2_1): merge revision(s) r44712, r44715, r44716, r44722, r44725, r44726, r44753: [Backport #9454] [Backport #9828]
nagachika 2014-06-20 00:56:56 +0900 (Fri, 20 Jun 2014) New Revision: 46468 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46468 Log: merge revision(s) r44712,r44715,r44716,r44722,r44725,r44726,r44753: [Backport #9454] [Backport #9828] * thread_pthread.c: get current main thread stack size, which may be expanded than allocated size at initialization, by rlimit(). [ruby-core:60113] [Bug #9454] * thread_pthread.c: rlimit is only available on Linux. At least r44712 breaks FreeBSD. [ruby-core:60113] [Bug #9454] * thread_pthread.c (ruby_init_stack, ruby_stack_overflowed_p): place get_stack above others to get stack boundary information. [ruby-core:60113] [Bug #9454] Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/cont.c branches/ruby_2_1/gc.c branches/ruby_2_1/test/ruby/test_exception.rb branches/ruby_2_1/thread.c branches/ruby_2_1/thread_pthread.c branches/ruby_2_1/thread_win32.c branches/ruby_2_1/version.h branches/ruby_2_1/vm.c branches/ruby_2_1/vm_core.h Index: ruby_2_1/thread_win32.c =================================================================== --- ruby_2_1/thread_win32.c (revision 46467) +++ ruby_2_1/thread_win32.c (revision 46468) @@ -571,8 +571,8 @@ native_thread_init_stack(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_win32.c#L571 size = end - base; space = size / 5; if (space > 1024*1024) space = 1024*1024; - th->machine_stack_start = (VALUE *)end - 1; - th->machine_stack_maxsize = size - space; + th->machine.stack_start = (VALUE *)end - 1; + th->machine.stack_maxsize = size - space; } #ifndef InterlockedExchangePointer @@ -600,7 +600,7 @@ thread_start_func_1(void *th_ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_win32.c#L600 thread_debug("thread created (th: %p, thid: %p, event: %p)\n", th, th->thread_id, th->native_thread_data.interrupt_event); - thread_start_func_2(th, th->machine_stack_start, rb_ia64_bsp()); + thread_start_func_2(th, th->machine.stack_start, rb_ia64_bsp()); w32_close_handle(thread_id); thread_debug("thread deleted (th: %p)\n", th); Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 46467) +++ ruby_2_1/ChangeLog (revision 46468) @@ -1,3 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Fri Jun 20 00:40:06 2014 Nobuyoshi Nakada <nobu@r...> + + * thread_pthread.c (ruby_init_stack, ruby_stack_overflowed_p): + place get_stack above others to get stack boundary information. + [ruby-core:60113] [Bug #9454] + +Fri Jun 20 00:40:06 2014 NARUSE, Yui <naruse@r...> + + * thread_pthread.c: rlimit is only available on Linux. + At least r44712 breaks FreeBSD. + [ruby-core:60113] [Bug #9454] + +Fri Jun 20 00:40:06 2014 Nobuyoshi Nakada <nobu@r...> + + * thread_pthread.c: get current main thread stack size, which may + be expanded than allocated size at initialization, by rlimit(). + [ruby-core:60113] [Bug #9454] + Fri Jun 20 00:20:02 2014 Hiroshi Shirosaki <h.shirosaki@g...> * configure.in: enable SSE2 on mingw. target='i386-pc-mingw32'. Index: ruby_2_1/thread_pthread.c =================================================================== --- ruby_2_1/thread_pthread.c (revision 46467) +++ ruby_2_1/thread_pthread.c (revision 46468) @@ -661,6 +661,18 @@ ruby_init_stack(volatile VALUE *addr https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L661 ) { native_main_thread.id = pthread_self(); +#if MAINSTACKADDR_AVAILABLE + if (native_main_thread.stack_maxsize) return; + { + void* stackaddr; + size_t size; + if (get_main_stack(&stackaddr, &size) == 0) { + native_main_thread.stack_maxsize = size; + native_main_thread.stack_start = stackaddr; + return; + } + } +#endif #ifdef STACK_END_ADDRESS native_main_thread.stack_start = STACK_END_ADDRESS; #else @@ -677,18 +689,6 @@ ruby_init_stack(volatile VALUE *addr https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L689 native_main_thread.register_stack_start = (VALUE*)bsp; } #endif -#if MAINSTACKADDR_AVAILABLE - if (native_main_thread.stack_maxsize) return; - { - void* stackaddr; - size_t size; - if (get_main_stack(&stackaddr, &size) == 0) { - native_main_thread.stack_maxsize = size; - native_main_thread.stack_start = stackaddr; - return; - } - } -#endif { #if defined(HAVE_GETRLIMIT) #if defined(PTHREAD_STACK_DEFAULT) @@ -749,8 +749,8 @@ native_thread_init_stack(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L749 rb_nativethread_id_t curr = pthread_self(); if (pthread_equal(curr, native_main_thread.id)) { - th->machine_stack_start = native_main_thread.stack_start; - th->machine_stack_maxsize = native_main_thread.stack_maxsize; + th->machine.stack_start = native_main_thread.stack_start; + th->machine.stack_maxsize = native_main_thread.stack_maxsize; } else { #ifdef STACKADDR_AVAILABLE @@ -758,11 +758,11 @@ native_thread_init_stack(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L758 size_t size; if (get_stack(&start, &size) == 0) { - th->machine_stack_start = start; - th->machine_stack_maxsize = size; + th->machine.stack_start = start; + th->machine.stack_maxsize = size; } #elif defined get_stack_of - if (!th->machine_stack_maxsize) { + if (!th->machine.stack_maxsize) { native_mutex_lock(&th->interrupt_lock); native_mutex_unlock(&th->interrupt_lock); } @@ -771,9 +771,9 @@ native_thread_init_stack(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L771 #endif } #ifdef __ia64 - th->machine_register_stack_start = native_main_thread.register_stack_start; - th->machine_stack_maxsize /= 2; - th->machine_register_stack_maxsize = th->machine_stack_maxsize; + th->machine.register_stack_start = native_main_thread.register_stack_start; + th->machine.stack_maxsize /= 2; + th->machine.register_stack_maxsize = th->machine.stack_maxsize; #endif return 0; } @@ -800,7 +800,7 @@ thread_start_func_1(void *th_ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L800 native_thread_init(th); /* run */ #if defined USE_NATIVE_THREAD_INIT - thread_start_func_2(th, th->machine_stack_start, rb_ia64_bsp()); + thread_start_func_2(th, th->machine.stack_start, rb_ia64_bsp()); #else thread_start_func_2(th, &stack_start, rb_ia64_bsp()); #endif @@ -922,10 +922,10 @@ native_thread_create(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L922 const size_t stack_size = th->vm->default_params.thread_machine_stack_size; const size_t space = space_size(stack_size); - th->machine_stack_maxsize = stack_size - space; + th->machine.stack_maxsize = stack_size - space; #ifdef __ia64 - th->machine_stack_maxsize /= 2; - th->machine_register_stack_maxsize = th->machine_stack_maxsize; + th->machine.stack_maxsize /= 2; + th->machine.register_stack_maxsize = th->machine.stack_maxsize; #endif #ifdef HAVE_PTHREAD_ATTR_INIT @@ -948,8 +948,8 @@ native_thread_create(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L948 #ifdef get_stack_of if (!err) { get_stack_of(th->thread_id, - &th->machine_stack_start, - &th->machine_stack_maxsize); + &th->machine.stack_start, + &th->machine.stack_maxsize); } native_mutex_unlock(&th->interrupt_lock); #endif @@ -1558,15 +1558,24 @@ ruby_stack_overflowed_p(const rb_thread_ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread_pthread.c#L1558 const size_t water_mark = 1024 * 1024; STACK_GROW_DIR_DETECTION; - if (th) { - size = th->machine_stack_maxsize; - base = (char *)th->machine_stack_start - STACK_DIR_UPPER(0, size); - } #ifdef STACKADDR_AVAILABLE - else if (get_stack(&base, &size) == 0) { - STACK_DIR_UPPER((void)(base = (char *)base + size), (void)0); + if (get_stack(&base, &size) == 0) { +# ifdef __APPLE__ + if (pthread_equal(th->thread_id, native_main_thread.id)) { + struct rlimit rlim; + if (getrlimit(RLIMIT_STACK, &rlim) == 0 && rlim.rlim_cur > size) { + size = (size_t)rlim.rlim_cur; + } + } +# endif + base = (char *)base + STACK_DIR_UPPER(+size, -size); } + else #endif + if (th) { + size = th->machine.stack_maxsize; + base = (char *)th->machine.stack_start - STACK_DIR_UPPER(0, size); + } else { return 0; } Index: ruby_2_1/vm_core.h =================================================================== --- ruby_2_1/vm_core.h (revision 46467) +++ ruby_2_1/vm_core.h (revision 46468) @@ -617,15 +617,17 @@ typedef struct rb_thread_struct { https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm_core.h#L617 VALUE (*first_func)(ANYARGS); /* for GC */ - VALUE *machine_stack_start; - VALUE *machine_stack_end; - size_t machine_stack_maxsize; + struct { + VALUE *stack_start; + VALUE *stack_end; + size_t stack_maxsize; #ifdef __ia64 - VALUE *machine_register_stack_start; - VALUE *machine_register_stack_end; - size_t machine_register_stack_maxsize; + VALUE *register_stack_start; + VALUE *register_stack_end; + size_t register_stack_maxsize; #endif - jmp_buf machine_regs; + jmp_buf regs; + } machine; int mark_stack_len; /* statistics data for profiler */ Index: ruby_2_1/thread.c =================================================================== --- ruby_2_1/thread.c (revision 46467) +++ ruby_2_1/thread.c (revision 46468) @@ -121,7 +121,7 @@ static inline void blocking_region_end(r https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread.c#L121 #ifdef __ia64 #define RB_GC_SAVE_MACHINE_REGISTER_STACK(th) \ - do{(th)->machine_register_stack_end = rb_ia64_bsp();}while(0) + do{(th)->machine.register_stack_end = rb_ia64_bsp();}while(0) #else #define RB_GC_SAVE_MACHINE_REGISTER_STACK(th) #endif @@ -129,8 +129,8 @@ static inline void blocking_region_end(r https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread.c#L129 do { \ FLUSH_REGISTER_WINDOWS; \ RB_GC_SAVE_MACHINE_REGISTER_STACK(th); \ - setjmp((th)->machine_regs); \ - SET_MACHINE_STACK_END(&(th)->machine_stack_end); \ + setjmp((th)->machine.regs); \ + SET_MACHINE_STACK_END(&(th)->machine.stack_end); \ } while (0) #define GVL_UNLOCK_BEGIN() do { \ @@ -465,9 +465,9 @@ thread_cleanup_func_before_exec(void *th https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread.c#L465 { rb_thread_t *th = th_ptr; th->status = THREAD_KILLED; - th->machine_stack_start = th->machine_stack_end = 0; + th->machine.stack_start = th->machine.stack_end = 0; #ifdef __ia64 - th->machine_register_stack_start = th->machine_register_stack_end = 0; + th->machine.register_stack_start = th->machine.register_stack_end = 0; #endif } @@ -519,9 +519,9 @@ thread_start_func_2(rb_thread_t *th, VAL https://github.com/ruby/ruby/blob/trunk/ruby_2_1/thread.c#L519 ruby_thread_set_native(th); - th->machine_stack_start = stack_start; + th->machine.stack_start = stack_start; #ifdef __ia64 - th->machine_register_stack_start = register_stack_start; + th->machine.register_stack_start = register_stack_start; #endif thread_debug("thread start: %p\n", (void *)th); Index: ruby_2_1/gc.c =================================================================== --- ruby_2_1/gc.c (revision 46467) +++ ruby_2_1/gc.c (revision 46468) @@ -3210,14 +3210,14 @@ init_mark_stack(mark_stack_t *stack) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/gc.c#L3210 /* Marking */ #ifdef __ia64 -#define SET_STACK_END (SET_MACHINE_STACK_END(&th->machine_stack_end), th->machine_register_stack_end = rb_ia64_bsp()) +#define SET_STACK_END (SET_MACHINE_STACK_END(&th->machine.stack_end), th->machine.register_stack_end = rb_ia64_bsp()) #else -#define SET_STACK_END SET_MACHINE_STACK_END(&th->machine_stack_end) +#define SET_STACK_END SET_MACHINE_STACK_END(&th->machine.stack_end) #endif -#define STACK_START (th->machine_stack_start) -#define STACK_END (th->machine_stack_end) -#define STACK_LEVEL_MAX (th->machine_stack_maxsize/sizeof(VALUE)) +#define STACK_START (th->machine.stack_start) +#define STACK_END (th->machine.stack_end) +#define STACK_LEVEL_MAX (th->machine.stack_maxsize/sizeof(VALUE)) #if STACK_GROW_DIRECTION < 0 # define STACK_LENGTH (size_t)(STACK_START - STACK_END) @@ -3259,8 +3259,8 @@ stack_check(int water_mark) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/gc.c#L3259 ret = STACK_LENGTH > STACK_LEVEL_MAX - water_mark; #ifdef __ia64 if (!ret) { - ret = (VALUE*)rb_ia64_bsp() - th->machine_register_stack_start > - th->machine_register_stack_maxsize/sizeof(VALUE) - water_mark; + ret = (VALUE*)rb_ia64_bsp() - th->machine.register_stack_start > + th->machine.register_stack_maxsize/sizeof(VALUE) - water_mark; } #endif return ret; @@ -3484,7 +3484,7 @@ mark_current_machine_context(rb_objspace https://github.com/ruby/ruby/blob/trunk/ruby_2_1/gc.c#L3484 rb_gc_mark_locations(stack_start, stack_end); #ifdef __ia64 - rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end); + rb_gc_mark_locations(th->machine.register_stack_start, th->machine.register_stack_end); #endif #if defined(__mc68000__) mark_locations_array(objspace, (VALUE*)((char*)STACK_END + 2), @@ -3501,7 +3501,7 @@ rb_gc_mark_machine_stack(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/ruby_2_1/gc.c#L3501 GET_STACK_BOUNDS(stack_start, stack_end, 0); rb_gc_mark_locations(stack_start, stack_end); #ifdef __ia64 - rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end); + rb_gc_mark_locations(th->machine.register_stack_start, th->machine.register_stack_end); #endif } Index: ruby_2_1/cont.c =================================================================== --- ruby_2_1/cont.c (revision 46467) +++ ruby_2_1/cont.c (revision 46468) @@ -97,16 +97,18 @@ typedef struct rb_context_struct { https://github.com/ruby/ruby/blob/trunk/ruby_2_1/cont.c#L97 size_t vm_stack_slen; /* length of stack (head of th->stack) */ size_t vm_stack_clen; /* length of control frames (tail of th->stack) */ #endif - VALUE *machine_stack; - VALUE *machine_stack_src; + struct { + VALUE *stack; + VALUE *stack_src; + size_t stack_size; #ifdef __ia64 - VALUE *machine_register_stack; - VALUE *machine_register_stack_src; - int machine_register_stack_size; + VALUE *register_stack; + VALUE *register_stack_src; + int register_stack_size; #endif + } machine; rb_thread_t saved_thread; rb_jmpbuf_t jmpbuf; - size_t machine_stack_size; rb_ensure_entry_t *ensure_array; rb_ensure_list_t *ensure_list; } rb_context_t; @@ -188,11 +190,11 @@ cont_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/cont.c#L190 #endif } - if (cont->machine_stack) { + if (cont->machine.stack) { if (cont->type == CONTINUATION_CONTEXT) { /* cont */ - rb_gc_mark_locations(cont->machine_stack, - cont->machine_stack + cont->machine_stack_size); + rb_gc_mark_locations(cont->machine.stack, + cont->machine.stack + cont->machine.stack_size); } else { /* fiber */ @@ -200,15 +202,15 @@ cont_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/cont.c#L202 rb_fiber_t *fib = (rb_fiber_t*)cont; GetThreadPtr(cont->saved_thread.self, th); if ((th->fiber != cont->self) && fib->status == RUNNING) { - rb_gc_mark_locations(cont->machine_stack, - cont->machine_stack + cont->machine_stack_size); + rb_gc_mark_locations(cont->machine.stack, + cont->machine.stack + cont->machine.stack_size); } } } #ifdef __ia64 - if (cont->machine_register_stack) { - rb_gc_mark_locations(cont->machine_register_stack, - cont->machine_register_stack + cont->machine_register_stack_size); + if (cont->machine.register_stack) { + rb_gc_mark_locations(cont->machine.register_stack, + cont->machine.register_stack + cont->machine.register_stack_size); } #endif } @@ -226,7 +228,7 @@ cont_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/cont.c#L228 if (cont->type == CONTINUATION_CONTEXT) { /* cont */ ruby_xfree(cont->ensure_array); - RUBY_FREE_UNLESS_NULL(cont->machine_stack); + RUBY_FREE_UNLESS_NULL(cont->machine.stack); } else { /* fiber */ @@ -257,10 +259,10 @@ cont_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/cont.c#L259 } #else /* not FIBER_USE_NATIVE */ ruby_xfree(cont->ensure_array); - RUBY_FREE_UNLESS_NULL(cont->machine_stack); + RUBY_FREE_UNLESS_NULL(cont->machine.stack); #endif #ifdef __ia64 - RUBY_FREE_UNLESS_NULL(cont->machine_register_stack); + RUBY_FREE_UNLESS_NULL(cont->machine.register_stack); #endif RUBY_FREE_UNLESS_NULL(cont->vm_stack); @@ -286,12 +288,12 @@ cont_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/cont.c#L288 size += n * sizeof(*cont->vm_stack); } - if (cont->machine_stack) { - size += cont->machine_stack_size * sizeof(*cont->machine_stack); + if (cont->machine.stack) { + size += cont->machine.stack_size * sizeof(*cont->machine.stack); } #ifdef __ia64 - if (cont->machine_register_stack) { - size += cont->machine_register_stack_size * sizeof(*cont->machine_register_stack); + if (cont->machine.register_stack) { + size += cont->machine.register_stack_size * sizeof(*cont->machine.register_stack); } #endif } @@ -380,42 +382,42 @@ cont_save_machine_stack(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/cont.c#L382 { size_t size; - SET_MACHINE_STACK_END(&th->machine_stack_end); + SET_MACHINE_STACK_END(&th->machine.stack_end); #ifdef __ia64 - th->machine_register_stack_end = rb_ia64_bsp(); + th->machine.register_stack_end = rb_ia64_bsp(); #endif - if (th->machine_stack_start > th->machine_stack_end) { - size = cont->machine_stack_size = th->machine_stack_start - th->machine_stack_end; - cont->machine_stack_src = th->machine_stack_end; + if (th->machine.stack_start > th->machine.stack_end) { + size = cont->machine.stack_size = th->machine.stack_start - th->machine.stack_end; + cont->machine.stack_src = th->machine.stack_end; } else { - size = cont->machine_stack_size = th->machine_stack_end - th->machine_stack_start; - cont->machine_stack_src = th->machine_stack_start; + size = cont->machine.stack_size = th->machine.stack_end - th->machine.stack_start; + cont->machine.stack_src = th->machine.stack_start; } - if (cont->machine_stack) { - REALLOC_N(cont->machine_stack, VALUE, size); + if (cont->machine.stack) { + REALLOC_N(cont->machine.stack, VALUE, size); } else { - cont->machine_stack = ALLOC_N(VALUE, size); + cont->machine.stack = ALLOC_N(VALUE, size); } FLUSH_REGISTER_WINDOWS; - MEMCPY(cont->machine_stack, cont->machine_stack_src, VALUE, size); + MEMCPY(cont->machine.stack, cont->machine.stack_src, VALUE, size); #ifdef __ia64 rb_ia64_flushrs(); - size = cont->machine_register_stack_size = th->machine_register_stack_end - th->machine_register_stack_start; - cont->machine_register_stack_src = th->machine_register_stack_start; - if (cont->machine_register_stack) { - REALLOC_N(cont->machine_register_stack, VALUE, size); + size = cont->machine.register_stack_size = th->machine.register_stack_end - th->machine.register_stack_start; + cont->machine.register_stack_src = th->machine.register_stack_start; + if (cont->machine.register_stack) { + REALLOC_N(cont->machine.register_stack, VALUE, size); } else { - cont->machine_register_stack = ALLOC_N(VALUE, size); + cont->machine.register_stack = ALLOC_N(VALUE, size); } - MEMCPY(cont->machine_register_stack, cont->machine_register_stack_src, VALUE, size); + MEMCPY(cont->machine.register_stack, cont->machine.register_stack_src, VALUE, size); #endif } @@ -430,13 +432,13 @@ cont_save_thread(rb_context_t *cont, rb_ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/cont.c#L432 { /* save thread context */ cont->saved_thread = *th; - /* saved_thread->machine_stack_(start|end) should be NULL */ + /* saved_thread->machine.stack_(start|end) should be NULL */ /* because it may happen GC afterward */ - cont->saved_thread.machine_stack_start = 0; - cont->saved_thread.machine_stack_end = 0; + cont->saved_thread.machine.stack_start = 0; + cont->saved_thread.machine.stack_end = 0; #ifdef __ia64 - cont->saved_thread.machine_register_stack_start = 0; - cont->saved_thread.machine_register_stack_end = 0; + cont->saved_thread.machine.re (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/