ruby-changes:47075
From: ko1 <ko1@a...>
Date: Wed, 28 Jun 2017 11:51:00 +0900 (JST)
Subject: [ruby-changes:47075] ko1:r59190 (trunk): move storages to ec.
ko1 2017-06-28 11:50:56 +0900 (Wed, 28 Jun 2017) New Revision: 59190 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59190 Log: move storages to ec. * vm_core.h (rb_thread_t): move storages to rb_execution_context_t. Modified files: trunk/cont.c trunk/thread.c trunk/vm.c trunk/vm_core.h trunk/vm_trace.c Index: vm_core.h =================================================================== --- vm_core.h (revision 59189) +++ vm_core.h (revision 59190) @@ -743,6 +743,11 @@ typedef struct rb_thread_context_struct https://github.com/ruby/ruby/blob/trunk/vm_core.h#L743 int safe_level; int raised_flag; + + /* storage (ec (fiber) local) */ + st_table *local_storage; + VALUE local_storage_recursive_hash; + VALUE local_storage_recursive_hash_for_trace; } rb_execution_context_t; typedef struct rb_thread_struct { @@ -806,11 +811,6 @@ typedef struct rb_thread_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L811 VALUE locking_mutex; struct rb_mutex_struct *keeping_mutexes; - /* storage */ - st_table *local_storage; - VALUE local_storage_recursive_hash; - VALUE local_storage_recursive_hash_for_trace; - rb_thread_list_t *join_list; VALUE first_proc; Index: thread.c =================================================================== --- thread.c (revision 59189) +++ thread.c (revision 59190) @@ -3033,12 +3033,13 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/thread.c#L3033 threadptr_local_aref(rb_thread_t *th, ID id) { if (id == recursive_key) { - return th->local_storage_recursive_hash; + return th->ec.local_storage_recursive_hash; } else { st_data_t val; + st_table *local_storage = th->ec.local_storage; - if (th->local_storage && st_lookup(th->local_storage, id, &val)) { + if (local_storage != NULL && st_lookup(local_storage, id, &val)) { return (VALUE)val; } else { @@ -3143,37 +3144,44 @@ rb_thread_fetch(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/thread.c#L3144 GetThreadPtr(self, th); if (id == recursive_key) { - return th->local_storage_recursive_hash; + return th->ec.local_storage_recursive_hash; } - if (id && th->local_storage && st_lookup(th->local_storage, id, &val)) { + else if (id && th->ec.local_storage && st_lookup(th->ec.local_storage, id, &val)) { return val; } - if (block_given) + else if (block_given) { return rb_yield(key); - else if (argc == 1) + } + else if (argc == 1) { rb_raise(rb_eKeyError, "key not found: %"PRIsVALUE, key); - else + } + else { return argv[1]; + } } static VALUE threadptr_local_aset(rb_thread_t *th, ID id, VALUE val) { if (id == recursive_key) { - th->local_storage_recursive_hash = val; + th->ec.local_storage_recursive_hash = val; return val; } - else if (NIL_P(val)) { - if (!th->local_storage) return Qnil; - st_delete_wrap(th->local_storage, id); - return Qnil; - } else { - if (!th->local_storage) { - th->local_storage = st_init_numtable(); + st_table *local_storage = th->ec.local_storage; + + if (NIL_P(val)) { + if (!local_storage) return Qnil; + st_delete_wrap(local_storage, id); + return Qnil; + } + else { + if (local_storage == NULL) { + th->ec.local_storage = local_storage = st_init_numtable(); + } + st_insert(local_storage, id, val); + return val; } - st_insert(th->local_storage, id, val); - return val; } } @@ -3286,16 +3294,20 @@ rb_thread_key_p(VALUE self, VALUE key) https://github.com/ruby/ruby/blob/trunk/thread.c#L3294 { rb_thread_t *th; ID id = rb_check_id(&key); + st_table *local_storage; GetThreadPtr(self, th); + local_storage= th->ec.local_storage; - if (!id || !th->local_storage) { + if (!id || local_storage == NULL) { return Qfalse; } - if (st_lookup(th->local_storage, id, 0)) { + else if (st_lookup(local_storage, id, 0)) { return Qtrue; } - return Qfalse; + else { + return Qfalse; + } } static int @@ -3332,8 +3344,8 @@ rb_thread_keys(VALUE self) https://github.com/ruby/ruby/blob/trunk/thread.c#L3344 VALUE ary = rb_ary_new(); GetThreadPtr(self, th); - if (th->local_storage) { - st_foreach(th->local_storage, thread_keys_i, ary); + if (th->ec.local_storage) { + st_foreach(th->ec.local_storage, thread_keys_i, ary); } return ary; } @@ -4512,13 +4524,13 @@ rb_thread_shield_destroy(VALUE self) https://github.com/ruby/ruby/blob/trunk/thread.c#L4524 static VALUE threadptr_recursive_hash(rb_thread_t *th) { - return th->local_storage_recursive_hash; + return th->ec.local_storage_recursive_hash; } static void threadptr_recursive_hash_set(rb_thread_t *th, VALUE hash) { - th->local_storage_recursive_hash = hash; + th->ec.local_storage_recursive_hash = hash; } ID rb_frame_last_func(void); Index: vm_trace.c =================================================================== --- vm_trace.c (revision 59189) +++ vm_trace.c (revision 59190) @@ -329,10 +329,10 @@ rb_threadptr_exec_event_hooks_orig(rb_tr https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L329 if (th->trace_arg == 0 && /* check reentrant */ trace_arg->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) { const VALUE errinfo = th->errinfo; - const VALUE old_recursive = th->local_storage_recursive_hash; + const VALUE old_recursive = th->ec.local_storage_recursive_hash; int state = 0; - th->local_storage_recursive_hash = th->local_storage_recursive_hash_for_trace; + th->ec.local_storage_recursive_hash = th->ec.local_storage_recursive_hash_for_trace; th->errinfo = Qnil; th->vm->trace_running++; @@ -352,8 +352,8 @@ rb_threadptr_exec_event_hooks_orig(rb_tr https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L352 th->trace_arg = 0; th->vm->trace_running--; - th->local_storage_recursive_hash_for_trace = th->local_storage_recursive_hash; - th->local_storage_recursive_hash = old_recursive; + th->ec.local_storage_recursive_hash_for_trace = th->ec.local_storage_recursive_hash; + th->ec.local_storage_recursive_hash = old_recursive; if (state) { if (pop_p) { Index: cont.c =================================================================== --- cont.c (revision 59189) +++ cont.c (revision 59190) @@ -319,8 +319,8 @@ fiber_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L319 rb_fiber_t *fib = ptr; RUBY_FREE_ENTER("fiber"); if (fib->cont.type != ROOT_FIBER_CONTEXT && - fib->cont.saved_thread.local_storage) { - st_free_table(fib->cont.saved_thread.local_storage); + fib->cont.saved_thread.ec.local_storage) { + st_free_table(fib->cont.saved_thread.ec.local_storage); } cont_free(&fib->cont); @@ -335,8 +335,8 @@ fiber_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L335 size = sizeof(*fib); if (fib->cont.type != ROOT_FIBER_CONTEXT && - fib->cont.saved_thread.local_storage != NULL) { - size += st_memsize(fib->cont.saved_thread.local_storage); + fib->cont.saved_thread.ec.local_storage != NULL) { + size += st_memsize(fib->cont.saved_thread.ec.local_storage); } size += cont_memsize(&fib->cont); return size; @@ -411,7 +411,6 @@ cont_save_thread(rb_context_t *cont, rb_ https://github.com/ruby/ruby/blob/trunk/cont.c#L411 /* save thread context */ sth->ec = th->ec; - sth->local_storage = th->local_storage; VM_ASSERT(th->status == THREAD_RUNNABLE); sth->errinfo = th->errinfo; sth->first_proc = th->first_proc; @@ -439,9 +438,9 @@ cont_init(rb_context_t *cont, rb_thread_ https://github.com/ruby/ruby/blob/trunk/cont.c#L438 cont->saved_thread.self = th->self; cont->saved_thread.machine.stack_maxsize = th->machine.stack_maxsize; cont->saved_thread.fiber = th->fiber; - cont->saved_thread.local_storage = 0; - cont->saved_thread.local_storage_recursive_hash = Qnil; - cont->saved_thread.local_storage_recursive_hash_for_trace = Qnil; + cont->saved_thread.ec.local_storage = NULL; + cont->saved_thread.ec.local_storage_recursive_hash = Qnil; + cont->saved_thread.ec.local_storage_recursive_hash_for_trace = Qnil; } static rb_context_t * @@ -554,11 +553,6 @@ cont_restore_thread(rb_context_t *cont) https://github.com/ruby/ruby/blob/trunk/cont.c#L553 /* fiber */ th->ec = sth->ec; sth->ec.stack = NULL; - - th->local_storage = sth->local_storage; - th->local_storage_recursive_hash = sth->local_storage_recursive_hash; - th->local_storage_recursive_hash_for_trace = sth->local_storage_recursive_hash_for_trace; - th->fiber = (rb_fiber_t*)cont; } @@ -1225,10 +1219,10 @@ fiber_init(VALUE fibval, VALUE proc) https://github.com/ruby/ruby/blob/trunk/cont.c#L1219 0, /* local_size */ 0); - th->ec.tag = 0; - th->local_storage = st_init_numtable(); - th->local_storage_recursive_hash = Qnil; - th->local_storage_recursive_hash_for_trace = Qnil; + th->ec.tag = NULL; + th->ec.local_storage = NULL; + th->ec.local_storage_recursive_hash = Qnil; + th->ec.local_storage_recursive_hash_for_trace = Qnil; th->first_proc = proc; @@ -1524,7 +1518,7 @@ rb_fiber_reset_root_local_storage(VALUE https://github.com/ruby/ruby/blob/trunk/cont.c#L1518 GetThreadPtr(thval, th); if (th->root_fiber && th->root_fiber != th->fiber) { - th->local_storage = th->root_fiber->cont.saved_thread.local_storage; + th->ec.local_storage = th->root_fiber->cont.saved_thread.ec.local_storage; } } Index: vm.c =================================================================== --- vm.c (revision 59189) +++ vm.c (revision 59190) @@ -2417,9 +2417,9 @@ rb_thread_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L2417 RUBY_MARK_UNLESS_NULL(th->locking_mutex); - rb_mark_tbl(th->local_storage); - RUBY_MARK_UNLESS_NULL(th->local_storage_recursive_hash); - RUBY_MARK_UNLESS_NULL(th->local_storage_recursive_hash_for_trace); + rb_mark_tbl(th->ec.local_storage); + RUBY_MARK_UNLESS_NULL(th->ec.local_storage_recursive_hash); + RUBY_MARK_UNLESS_NULL(th->ec.local_storage_recursive_hash_for_trace); RUBY_MARK_UNLESS_NULL(th->name); @@ -2445,8 +2445,8 @@ thread_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L2445 rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes); } - if (th->local_storage) { - st_free_table(th->local_storage); + if (th->ec.local_storage) { + st_free_table(th->ec.local_storage); } if (th->vm && th->vm->main_thread == th) { @@ -2475,8 +2475,8 @@ thread_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L2475 if (!th->root_fiber) { size += th->ec.stack_size * sizeof(VALUE); } - if (th->local_storage) { - size += st_memsize(th->local_storage); + if (th->ec.local_storage) { + size += st_memsize(th->ec.local_storage); } return size; } @@ -2540,8 +2540,8 @@ th_init(rb_thread_t *th, VALUE self) https://github.com/ruby/ruby/blob/trunk/vm.c#L2540 th->errinfo = Qnil; th->last_status = Qnil; th->root_svar = Qfalse; - th->local_storage_recursive_hash = Qnil; - th->local_storage_recursive_hash_for_trace = Qnil; + th->ec.local_storage_recursive_hash = Qnil; + th->ec.local_storage_recursive_hash_for_trace = Qnil; #ifdef NON_SCALAR_THREAD_ID th->thread_id_string[0] = '\0'; #endif -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/