aboutsummaryrefslogtreecommitdiffstats
path: root/vm.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-12 20:49:10 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-12 20:49:10 +0000
commit89e668f2571612d231084f329d264dbc9c877763 (patch)
treef923db7caf3476b3d907307dc7a4ad6ec31317a7 /vm.c
parent2b26ace900d51129072ee6391037e9951ff2ca48 (diff)
downloadruby-89e668f2571612d231084f329d264dbc9c877763.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.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/vm.c b/vm.c
index 5c33cfb300..da9afe2fc7 100644
--- a/vm.c
+++ b/vm.c
@@ -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);