ruby-changes:47062
From: ko1 <ko1@a...>
Date: Mon, 26 Jun 2017 16:56:49 +0900 (JST)
Subject: [ruby-changes:47062] ko1:r59177 (trunk): move several fields from rb_thread_t to rb_execution_context_t.
ko1 2017-06-26 16:56:44 +0900 (Mon, 26 Jun 2017) New Revision: 59177 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59177 Log: move several fields from rb_thread_t to rb_execution_context_t. * vm_core.h (rb_thread_t): move several fields which are copied at cont.c to rb_execution_context_t. Modified files: trunk/cont.c trunk/eval.c trunk/eval_error.c trunk/eval_intern.h trunk/process.c trunk/safe.c trunk/signal.c trunk/thread.c trunk/vm.c trunk/vm_core.h trunk/vm_eval.c trunk/vm_insnhelper.c trunk/vm_trace.c Index: process.c =================================================================== --- process.c (revision 59176) +++ process.c (revision 59177) @@ -3772,7 +3772,7 @@ rb_f_exit_bang(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/process.c#L3772 void rb_exit(int status) { - if (GET_THREAD()->tag) { + if (GET_THREAD()->ec.tag) { VALUE args[2]; args[0] = INT2NUM(status); Index: eval_error.c =================================================================== --- eval_error.c (revision 59176) +++ eval_error.c (revision 59177) @@ -167,7 +167,7 @@ void https://github.com/ruby/ruby/blob/trunk/eval_error.c#L167 rb_threadptr_error_print(rb_thread_t *volatile th, volatile VALUE errinfo) { volatile VALUE errat = Qundef; - volatile int raised_flag = th->raised_flag; + volatile int raised_flag = th->ec.raised_flag; volatile VALUE eclass = Qundef, emesg = Qundef; if (NIL_P(errinfo)) Index: vm_trace.c =================================================================== --- vm_trace.c (revision 59176) +++ vm_trace.c (revision 59177) @@ -358,7 +358,7 @@ rb_threadptr_exec_event_hooks_orig(rb_tr https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L358 if (state) { if (pop_p) { if (VM_FRAME_FINISHED_P(th->ec.cfp)) { - th->tag = th->tag->prev; + th->ec.tag = th->ec.tag->prev; } rb_vm_pop_frame(th); } Index: signal.c =================================================================== --- signal.c (revision 59176) +++ signal.c (revision 59177) @@ -845,11 +845,11 @@ check_stack_overflow(int sig, const uint https://github.com/ruby/ruby/blob/trunk/signal.c#L845 if (sp_page == fault_page || sp_page == fault_page + 1 || sp_page <= fault_page && fault_page <= bp_page) { rb_thread_t *th = ruby_current_thread; - if ((uintptr_t)th->tag->buf / pagesize <= fault_page + 1) { + if ((uintptr_t)th->ec.tag->buf / pagesize <= fault_page + 1) { /* drop the last tag if it is close to the fault, * otherwise it can cause stack overflow again at the same * place. */ - th->tag = th->tag->prev; + th->ec.tag = th->ec.tag->prev; } raise_stack_overflow(sig, th); } Index: vm.c =================================================================== --- vm.c (revision 59176) +++ vm.c (revision 59177) @@ -882,7 +882,7 @@ rb_vm_make_proc_lambda(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/vm.c#L882 procval = rb_proc_create_from_captured(klass, captured, imemo_type(captured->code.val) == imemo_iseq ? block_type_iseq : block_type_ifunc, - (int8_t)th->safe_level, FALSE, is_lambda); + (int8_t)th->ec.safe_level, FALSE, is_lambda); return procval; } @@ -1139,16 +1139,16 @@ vm_invoke_proc(rb_thread_t *th, rb_proc_ https://github.com/ruby/ruby/blob/trunk/vm.c#L1139 { VALUE val = Qundef; enum ruby_tag_type state; - volatile int stored_safe = th->safe_level; + volatile int stored_safe = th->ec.safe_level; TH_PUSH_TAG(th); if ((state = EXEC_TAG()) == TAG_NONE) { - th->safe_level = proc->safe_level; + th->ec.safe_level = proc->safe_level; val = invoke_block_from_c_proc(th, proc, self, argc, argv, passed_block_handler, proc->is_lambda); } TH_POP_TAG(); - th->safe_level = stored_safe; + th->ec.safe_level = stored_safe; if (state) { TH_JUMP_TAG(th, state); @@ -1418,7 +1418,7 @@ rb_vm_make_jump_tag_but_local_jump(int s https://github.com/ruby/ruby/blob/trunk/vm.c#L1418 VALUE result = Qnil; if (val == Qundef) { - val = GET_THREAD()->tag->retval; + val = GET_THREAD()->ec.tag->retval; } switch (state) { case 0: @@ -1786,7 +1786,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L1786 if ((state = EXEC_TAG()) == TAG_NONE) { vm_loop_start: result = vm_exec_core(th, initial); - VM_ASSERT(th->tag == &_tag); + VM_ASSERT(th->ec.tag == &_tag); if ((state = _tag.state) != TAG_NONE) { err = (struct vm_throw_data *)result; _tag.state = TAG_NONE; @@ -1939,7 +1939,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L1939 #endif } th->errinfo = Qnil; - VM_ASSERT(th->tag->state == TAG_NONE); + VM_ASSERT(th->ec.tag->state == TAG_NONE); goto vm_loop_start; } } @@ -1989,7 +1989,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L1989 catch_iseq->body->stack_max); state = 0; - th->tag->state = TAG_NONE; + th->ec.tag->state = TAG_NONE; th->errinfo = Qnil; goto vm_loop_start; } Index: eval.c =================================================================== --- eval.c (revision 59176) +++ eval.c (revision 59177) @@ -173,7 +173,7 @@ ruby_cleanup(volatile int ex) https://github.com/ruby/ruby/blob/trunk/eval.c#L173 step_0: step++; errs[1] = th->errinfo; - th->safe_level = 0; + th->ec.safe_level = 0; ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]); SAVE_ROOT_JMPBUF(th, ruby_finalize_0()); @@ -865,10 +865,10 @@ rb_protect(VALUE (* proc) (VALUE), VALUE https://github.com/ruby/ruby/blob/trunk/eval.c#L865 struct rb_vm_protect_tag protect_tag; rb_jmpbuf_t org_jmpbuf; - protect_tag.prev = th->protect_tag; + protect_tag.prev = th->ec.protect_tag; TH_PUSH_TAG(th); - th->protect_tag = &protect_tag; + th->ec.protect_tag = &protect_tag; MEMCPY(&org_jmpbuf, &(th)->root_jmpbuf, rb_jmpbuf_t, 1); if ((state = TH_EXEC_TAG()) == TAG_NONE) { SAVE_ROOT_JMPBUF(th, result = (*proc) (data)); @@ -877,7 +877,7 @@ rb_protect(VALUE (* proc) (VALUE), VALUE https://github.com/ruby/ruby/blob/trunk/eval.c#L877 rb_vm_rewind_cfp(th, cfp); } MEMCPY(&(th)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1); - th->protect_tag = protect_tag.prev; + th->ec.protect_tag = protect_tag.prev; TH_POP_TAG(); if (pstate != NULL) *pstate = state; Index: vm_core.h =================================================================== --- vm_core.h (revision 59176) +++ vm_core.h (revision 59177) @@ -737,6 +737,12 @@ typedef struct rb_thread_context_struct https://github.com/ruby/ruby/blob/trunk/vm_core.h#L737 VALUE *stack; /* must free, must mark */ size_t stack_size; /* size in word (byte size / sizeof(VALUE)) */ rb_control_frame_t *cfp; + + struct rb_vm_tag *tag; + struct rb_vm_protect_tag *protect_tag; + + int safe_level; + int raised_flag; } rb_execution_context_t; typedef struct rb_thread_struct { @@ -745,8 +751,7 @@ typedef struct rb_thread_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L751 rb_vm_t *vm; rb_execution_context_t ec; - int safe_level; - int raised_flag; + VALUE last_status; /* $? */ /* for rb_iterate */ @@ -801,9 +806,6 @@ typedef struct rb_thread_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L806 VALUE locking_mutex; struct rb_mutex_struct *keeping_mutexes; - struct rb_vm_tag *tag; - struct rb_vm_protect_tag *protect_tag; - /* storage */ st_table *local_storage; VALUE local_storage_recursive_hash; Index: cont.c =================================================================== --- cont.c (revision 59176) +++ cont.c (revision 59177) @@ -164,7 +164,7 @@ static VALUE rb_eFiberError; https://github.com/ruby/ruby/blob/trunk/cont.c#L164 NOINLINE(static VALUE cont_capture(volatile int *volatile stat)); #define THREAD_MUST_BE_RUNNING(th) do { \ - if (!(th)->tag) rb_raise(rb_eThreadError, "not running thread"); \ + if (!(th)->ec.tag) rb_raise(rb_eThreadError, "not running thread"); \ } while (0) static void @@ -410,12 +410,9 @@ cont_save_thread(rb_context_t *cont, rb_ https://github.com/ruby/ruby/blob/trunk/cont.c#L410 /* save thread context */ sth->ec = th->ec; + sth->local_storage = th->local_storage; - sth->safe_level = th->safe_level; - sth->raised_flag = th->raised_flag; VM_ASSERT(th->status == THREAD_RUNNABLE); - sth->tag = th->tag; - sth->protect_tag = th->protect_tag; sth->errinfo = th->errinfo; sth->first_proc = th->first_proc; sth->root_lep = th->root_lep; @@ -548,6 +545,10 @@ cont_restore_thread(rb_context_t *cont) https://github.com/ruby/ruby/blob/trunk/cont.c#L545 /* other members of ec */ th->ec.cfp = sth->ec.cfp; + th->ec.safe_level = sth->ec.safe_level; + th->ec.raised_flag = sth->ec.raised_flag; + th->ec.tag = sth->ec.tag; + th->ec.protect_tag = sth->ec.protect_tag; } else { /* fiber */ @@ -561,10 +562,6 @@ cont_restore_thread(rb_context_t *cont) https://github.com/ruby/ruby/blob/trunk/cont.c#L562 th->fiber = (rb_fiber_t*)cont; } - th->safe_level = sth->safe_level; - th->raised_flag = sth->raised_flag; - th->tag = sth->tag; - th->protect_tag = sth->protect_tag; th->errinfo = sth->errinfo; th->first_proc = sth->first_proc; th->root_lep = sth->root_lep; @@ -1066,7 +1063,7 @@ rb_cont_call(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/cont.c#L1063 if (cont->saved_thread.self != th->self) { rb_raise(rb_eRuntimeError, "continuation called across threads"); } - if (cont->saved_thread.protect_tag != th->protect_tag) { + if (cont->saved_thread.ec.protect_tag != th->ec.protect_tag) { rb_raise(rb_eRuntimeError, "continuation called across stack rewinding barrier"); } if (cont->saved_thread.fiber) { @@ -1228,7 +1225,7 @@ fiber_init(VALUE fibval, VALUE proc) https://github.com/ruby/ruby/blob/trunk/cont.c#L1225 0, /* local_size */ 0); - th->tag = 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; @@ -1432,7 +1429,7 @@ fiber_switch(rb_fiber_t *fib, int argc, https://github.com/ruby/ruby/blob/trunk/cont.c#L1429 if (cont->saved_thread.self != th->self) { rb_raise(rb_eFiberError, "fiber called across threads"); } - else if (cont->saved_thread.protect_tag != th->protect_tag) { + else if (cont->saved_thread.ec.protect_tag != th->ec.protect_tag) { rb_raise(rb_eFiberError, "fiber called across stack rewinding barrier"); } else if (fib->status == FIBER_TERMINATED) { Index: thread.c =================================================================== --- thread.c (revision 59176) +++ thread.c (revision 59177) @@ -2038,7 +2038,7 @@ rb_threadptr_execute_interrupts(rb_threa https://github.com/ruby/ruby/blob/trunk/thread.c#L2038 rb_atomic_t interrupt; int postponed_job_interrupt = 0; - if (th->raised_flag) return; + if (th->ec.raised_flag) return; while ((interrupt = threadptr_get_interrupts(th)) != 0) { int sig; @@ -2181,20 +2181,20 @@ rb_threadptr_signal_exit(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/thread.c#L2181 int rb_threadptr_set_raised(rb_thread_t *th) { - if (th->raised_flag & RAISED_EXCEPTION) { + if (th->ec.raised_flag & RAISED_EXCEPTION) { return 1; } - th->raised_flag |= RAISED_EXCEPTION; + th->ec.raised_flag |= RAISED_EXCEPTION; return 0; } int rb_threadptr_reset_raised(rb_thread_t *th) { - if (!(th->raised_flag & RAISED_EXCEPTION)) { + if (!(th->ec.raised_flag & RAISED_EXCEPTION)) { return 0; } - th->raised_flag &= ~RAISED_EXCEPTION; + th->ec.raised_flag &= ~RAISED_EXCEPTION; return 1; } @@ -2935,7 +2935,7 @@ rb_thread_safe_level(VALUE thread) https://github.com/ruby/ruby/blob/trunk/thread.c#L2935 rb_thread_t *th; GetThreadPtr(thread, th); - return INT2NUM(th->safe_level); + return INT2NUM(th->ec.safe_level); } /* Index: vm_eval.c =================================================================== --- vm_eval.c (revision 59176) +++ vm_eval.c (revision 59177) @@ -1136,7 +1136,7 @@ rb_iterate0(VALUE (* it_proc) (VALUE), V https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1136 rb_vm_rewind_cfp(th, cfp); state = 0; - th->tag->state = TAG_NONE; + th->ec.tag->state = TAG_NONE; th->errinfo = Qnil; if (state == TAG_RETRY) goto iter_retry; @@ -1853,7 +1853,7 @@ void https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1853 rb_throw_obj(VALUE tag, VALUE value) { rb_thread_t *th = GET_THREAD(); - struct rb_vm_tag *tt = th->tag; + struct rb_vm_tag *tt = th->ec.tag; while (tt) { if (tt->tag == tag) { @@ -1976,7 +1976,7 @@ vm_catch_protect(VALUE tag, rb_block_cal https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1976 } else if (state == TAG_THROW && THROW_DATA_VAL((struct vm_throw_data *)th->errinfo) == tag) { rb_vm_rewind_cfp(th, saved_cfp); - val = th->tag->retval; + val = th->ec.tag->retval; th->errinfo = Qnil; state = 0; } Index: safe.c =================================================================== --- safe.c (revision 59176) +++ safe.c (revision 59177) @@ -34,13 +34,13 @@ ruby_safe_level_2_warning(void) https://github.com/ruby/ruby/blob/trunk/safe.c#L34 int rb_safe_level(void) { - return GET_THREAD()->safe_level; + return GET_THREAD()->ec.safe_level; } void rb_set_safe_level_force(int safe) { - GET_THREAD()->safe_level = safe; + GET_THREAD()->ec.safe_level = safe; } void @@ -48,11 +48,11 @@ rb_set_safe_level(int level) https://github.com/ruby/ruby/blob/trunk/safe.c#L48 { rb_thread_t *th = GET_THREAD(); - if (level > th->safe_level) { + if (level > th->ec.safe_level) { if (level > SAFE_LEVEL_MAX) { rb_raise(rb_eArgError, "$SAFE=2 to 4 are obsolete"); } - th->safe_level = level; + th->ec.safe_level = level; } } @@ -68,15 +68,15 @@ safe_setter(VALUE val) https://github.com/ruby/ruby/blob/trunk/safe.c#L68 int level = NUM2INT(val); rb_thread_t *th = GET_THREAD(); - if (level < th->safe_level) { + if (level < th->ec.safe_level) { rb_raise(rb_eSecurityError, "tried to downgrade safe level from %d to %d", - th->safe_level, level); + th->ec.safe_level, level); } if (level > SAFE_LEVEL_MAX) { rb_raise(rb_eArgError, "$SAFE=2 to 4 are obsolete"); } - th->safe_level = level; + th->ec.safe_level = level; } void Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 59176) +++ vm_insnhelper.c (revision 59177) @@ -35,7 +35,7 @@ static void https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L35 threadptr_stack_overflow(rb_thread_t *th, int setup) { VALUE mesg = th->vm->special_exceptions[ruby_error_sysstack]; - th->raised_flag = 0; + th->ec.raised_flag = 0; if (setup) { VALUE at = rb_threadptr_backtrace_object(th); mesg = ruby_vm_special_exception_copy(mesg); @@ -1029,16 +1029,16 @@ vm_throw_continue(rb_thread_t *th, VALUE https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1029 /* continue throw */ if (FIXNUM_P(err)) { - th->tag->state = FIX2INT(err); + th->ec.tag->state = FIX2INT(err); } else if (SYMBOL_P(err)) { - th->tag->state = TAG_THROW; + th->ec.tag->state = TAG_THROW; } else if (THROW_DATA_P(err)) { - th->tag->state = THROW_DATA_STATE((struct vm_throw_data *)err); + th->ec.tag->state = THROW_DATA_STATE((struct vm_throw_data *)err); } else { - th->tag->state = TAG_RAISE; + th->ec.tag->state = TAG_RAISE; } return err; } @@ -1177,7 +1177,7 @@ vm_throw_start(rb_thread_t *const th, rb https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1177 rb_bug("isns(throw): unsupport throw type"); } - th->tag->state = state; + th->ec.tag->state = state; return (VALUE)THROW_DATA_NEW(throwobj, escape_cfp, state); } Index: eval_intern.h =================================================================== --- eval_intern.h (revision 59176) +++ eval_intern.h (revision 59177) @@ -133,16 +133,16 @@ LONG WINAPI rb_w32_stack_overflow_handle https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L133 struct rb_vm_tag _tag; \ _tag.state = TAG_NONE; \ _tag.tag = Qundef; \ - _tag.prev = _th->tag; + _tag.prev = _th->ec.tag; #define TH_POP_TAG() \ - _th->tag = _tag.prev; \ + _th->ec.tag = _tag.prev; \ } while (0) #define TH_TMPPOP_TAG() \ - _th->tag = _tag.prev + _th->ec.tag = _tag.prev -#define TH_REPUSH_TAG() (void)(_th->tag = &_tag) +#define TH_REPUSH_TAG() (void)(_th->ec.tag = &_tag) #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD()) #define POP_TAG() TH_POP_TAG() @@ -157,12 +157,12 @@ LONG WINAPI rb_w32_stack_overflow_handle https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L157 # define VAR_NOCLOBBERED(var) var #endif -/* clear th->tag->state, and return the value */ +/* clear th->ec.tag->state, and return the value */ static inline int rb_threadptr_tag_state(rb_thread_t *th) { - enum ruby_tag_type state = th->tag->state; - th->tag->state = TAG_NONE; + enum ruby_tag_type state = th->ec.tag->state; + th->ec.tag->state = TAG_NONE; return state; } @@ -170,8 +170,8 @@ NORETURN(static inline void rb_threadptr https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L170 static inline void rb_threadptr_tag_jump(rb_thread_t *th, enum ruby_tag_type st) { - th->tag->state = st; - ruby_longjmp(th->tag->buf, 1); + th->ec.tag->state = st; + ruby_longjmp(th->ec.tag->buf, 1); } /* @@ -265,10 +265,10 @@ enum { https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L265 }; int rb_threadptr_set_raised(rb_thread_t *th); int rb_threadptr_reset_raised(rb_thread_t *th); -#define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f)) -#define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f)) -#define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0) -#define rb_thread_raised_clear(th) ((th)->raised_flag = 0) +#define rb_thread_raised_set(th, f) ((th)->ec.raised_flag |= (f)) +#define rb_thread_raised_reset(th, f) ((th)->ec.raised_flag &= ~(f)) +#define rb_thread_raised_p(th, f) (((th)->ec.raised_flag & (f)) != 0) +#define rb_thread_raised_clear(th) ((th)->ec.raised_flag = 0) int rb_threadptr_stack_check(rb_thread_t *th); VALUE rb_f_eval(int argc, const VALUE *argv, VALUE self); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/