ruby-changes:47358
From: ko1 <ko1@a...>
Date: Thu, 3 Aug 2017 06:49:00 +0900 (JST)
Subject: [ruby-changes:47358] ko1:r59474 (trunk): fix stack storing for root fibers.
ko1 2017-08-03 06:48:51 +0900 (Thu, 03 Aug 2017) New Revision: 59474 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59474 Log: fix stack storing for root fibers. * cont.c (root_fiber_alloc): this function is called by fiber_current() and fiber_store(). fiber_current() should clear VM stack information in a fiber data because runnning thread knows stack information and has responsibility to manage it. However fiber_store() requires to remain VM stack information in a fiber data because the responsibility to manage VM stack is moved to the Fiber from the Thread (and switch to another fiber). * cont.c (root_fiber_alloc): save thread's fiber and root_fiber information. Modified files: trunk/cont.c trunk/vm.c Index: vm.c =================================================================== --- vm.c (revision 59473) +++ vm.c (revision 59474) @@ -90,6 +90,8 @@ VM_CFP_IN_HEAP_P(const rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/vm.c#L90 { const VALUE *start = th->ec.stack; const VALUE *end = (VALUE *)th->ec.stack + th->ec.stack_size; + VM_ASSERT(start != NULL); + if (start <= (VALUE *)cfp && (VALUE *)cfp < end) { return FALSE; } @@ -103,6 +105,8 @@ VM_EP_IN_HEAP_P(const rb_thread_t *th, c https://github.com/ruby/ruby/blob/trunk/vm.c#L105 { const VALUE *start = th->ec.stack; const VALUE *end = (VALUE *)th->ec.cfp; + VM_ASSERT(start != NULL); + if (start <= ep && ep < end) { return FALSE; } Index: cont.c =================================================================== --- cont.c (revision 59473) +++ cont.c (revision 59474) @@ -556,6 +556,7 @@ cont_restore_thread(rb_context_t *cont) https://github.com/ruby/ruby/blob/trunk/cont.c#L556 th->fiber = (rb_fiber_t*)cont; } + VM_ASSERT(th->ec.stack != NULL); VM_ASSERT(sth->status == THREAD_RUNNABLE); } @@ -1288,7 +1289,6 @@ root_fiber_alloc(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/cont.c#L1289 rb_fiber_t *fib; /* no need to allocate vm stack */ fib = fiber_t_alloc(fiber_alloc(rb_cFiber)); - fib->cont.saved_thread.ec.stack = NULL; fib->cont.type = ROOT_FIBER_CONTEXT; #if FIBER_USE_NATIVE #ifdef _WIN32 @@ -1297,6 +1297,7 @@ root_fiber_alloc(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/cont.c#L1297 #endif fib->status = FIBER_RUNNING; + th->root_fiber = th->fiber = fib; return fib; } @@ -1305,9 +1306,9 @@ fiber_current(void) https://github.com/ruby/ruby/blob/trunk/cont.c#L1306 { rb_thread_t *th = GET_THREAD(); if (th->fiber == 0) { - /* save root */ rb_fiber_t *fib = root_fiber_alloc(th); - th->root_fiber = th->fiber = fib; + /* Running thread object has stack management responsibility */ + fib->cont.saved_thread.ec.stack = NULL; } return th->fiber; } @@ -1348,9 +1349,8 @@ fiber_store(rb_fiber_t *next_fib, rb_thr https://github.com/ruby/ruby/blob/trunk/cont.c#L1349 cont_save_thread(&fib->cont, th); } else { - /* create current fiber */ + /* create root fiber */ fib = root_fiber_alloc(th); - th->root_fiber = th->fiber = fib; } #if FIBER_USE_NATIVE -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/