diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-09-12 20:49:10 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-09-12 20:49:10 +0000 |
commit | c99b9eb03952284f213b714acaf7f4885ce177c2 (patch) | |
tree | f923db7caf3476b3d907307dc7a4ad6ec31317a7 /vm.c | |
parent | 2bd4c5145572a507541702327cbf13c8e91af3da (diff) | |
download | ruby-c99b9eb03952284f213b714acaf7f4885ce177c2.tar.gz |
share VM stack between threads and fibers if identical in size
ec->vm_stack is always allocated with malloc, so stack cache for
root fiber (thread stack) and non-root fibers can be shared as
long as the size is the same. The purpose of this change is to
reduce dependencies on ROOT_FIBER_CONTEXT.
[Feature #15095] [Bug #15050]
v2: vm.c: fix build with USE_THREAD_DATA_RECYCLE==0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -2340,23 +2340,20 @@ vm_init2(rb_vm_t *vm) #define RECYCLE_MAX 64 static VALUE *thread_recycle_stack_slot[RECYCLE_MAX]; static int thread_recycle_stack_count = 0; +#endif /* USE_THREAD_DATA_RECYCLE */ -static VALUE * -thread_recycle_stack(size_t size) +VALUE * +rb_thread_recycle_stack(size_t size) { +#if USE_THREAD_DATA_RECYCLE if (thread_recycle_stack_count > 0) { /* TODO: check stack size if stack sizes are variable */ return thread_recycle_stack_slot[--thread_recycle_stack_count]; } - else { - return ALLOC_N(VALUE, size); - } +#endif /* USE_THREAD_DATA_RECYCLE */ + return ALLOC_N(VALUE, size); } -#else -#define thread_recycle_stack(size) ALLOC_N(VALUE, (size)) -#endif - void rb_thread_recycle_stack_release(VALUE *stack) { @@ -2536,7 +2533,7 @@ th_init(rb_thread_t *th, VALUE self) /* vm_stack_size is word number. * th->vm->default_params.thread_vm_stack_size is byte size. */ size_t size = th->vm->default_params.thread_vm_stack_size / sizeof(VALUE); - ec_set_vm_stack(th->ec, thread_recycle_stack(size), size); + ec_set_vm_stack(th->ec, rb_thread_recycle_stack(size), size); } th->ec->cfp = (void *)(th->ec->vm_stack + th->ec->vm_stack_size); |