ruby-changes:43682
From: ko1 <ko1@a...>
Date: Tue, 26 Jul 2016 19:28:26 +0900 (JST)
Subject: [ruby-changes:43682] ko1:r55755 (trunk): * vm_insnhelper.c: introduce rb_vm_pop_frame() and use it
ko1 2016-07-26 19:28:21 +0900 (Tue, 26 Jul 2016) New Revision: 55755 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55755 Log: * vm_insnhelper.c: introduce rb_vm_pop_frame() and use it instead of setting rb_thread_t::cfp directly. * vm_insnhelper.c (vm_pop_frame): return the result of finish frame or not. Modified files: trunk/ChangeLog trunk/eval.c trunk/insns.def trunk/vm.c trunk/vm_args.c trunk/vm_core.h trunk/vm_eval.c trunk/vm_insnhelper.c trunk/vm_trace.c Index: eval.c =================================================================== --- eval.c (revision 55754) +++ eval.c (revision 55755) @@ -737,7 +737,7 @@ rb_raise_jump(VALUE mesg, VALUE cause) https://github.com/ruby/ruby/blob/trunk/eval.c#L737 VALUE self = cfp->self; ID mid = me->called_id; - th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); + rb_vm_pop_frame(th); EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, mid, klass, Qnil); setup_exception(th, TAG_RAISE, mesg, cause); Index: vm_core.h =================================================================== --- vm_core.h (revision 55754) +++ vm_core.h (revision 55755) @@ -1023,6 +1023,7 @@ void rb_vm_inc_const_missing_count(void) https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1023 void rb_vm_gvl_destroy(rb_vm_t *vm); VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me); +void rb_vm_pop_frame(rb_thread_t *th); void rb_thread_start_timer_thread(void); void rb_thread_stop_timer_thread(void); Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 55754) +++ vm_insnhelper.c (revision 55755) @@ -207,16 +207,28 @@ vm_push_frame(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L207 return cfp; } -static inline void -vm_pop_frame(rb_thread_t *th) +static inline int +vm_pop_frame(rb_thread_t *th, rb_control_frame_t *cfp, const VALUE *ep /* we'll use ep soon */) { - th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); + if (VM_CHECK_MODE >= 4) rb_gc_verify_internal_consistency(); + if (VMDEBUG == 2) SDR(); + + th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); - if (VMDEBUG == 2) { - SDR(); + if (UNLIKELY(VM_FRAME_TYPE_FINISH_P(cfp))) { + return TRUE; + } + else { + return FALSE; } } +void +rb_vm_pop_frame(rb_thread_t *th) +{ + vm_pop_frame(th, th->cfp, th->cfp->ep); +} + /* method dispatch */ static inline VALUE rb_arity_error_new(int argc, int min, int max) @@ -1425,7 +1437,8 @@ vm_call_iseq_setup_tailcall(rb_thread_t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1437 VALUE *sp_orig, *sp; VALUE finish_flag = VM_FRAME_TYPE_FINISH_P(cfp) ? VM_FRAME_FLAG_FINISH : 0; - cfp = th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); /* pop cf */ + vm_pop_frame(th, cfp, cfp->ep); + cfp = th->cfp; RUBY_VM_CHECK_INTS(th); @@ -1644,7 +1657,7 @@ vm_call_cfunc_with_frame(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1657 rb_bug("vm_call_cfunc - cfp consistency error"); } - vm_pop_frame(th); + rb_vm_pop_frame(th); EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, me->owner, val); RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, me->called_id); @@ -1679,7 +1692,7 @@ vm_call_cfunc_latter(rb_thread_t *th, rb https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1692 if (UNLIKELY(reg_cfp != RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp))) { rb_bug("vm_call_cfunc_latter: cfp consistency error (%p, %p)", reg_cfp, th->cfp+1); } - vm_pop_frame(th); + vm_pop_frame(th, reg_cfp, reg_cfp->ep); VM_PROFILE_UP(R2C_POPF); } @@ -2338,8 +2351,8 @@ vm_yield_with_cfunc(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2351 data = (VALUE)ifunc->data; } val = (*func)(arg, data, argc, argv, blockarg); + rb_vm_pop_frame(th); - th->cfp++; return val; } Index: vm_eval.c =================================================================== --- vm_eval.c (revision 55754) +++ vm_eval.c (revision 55755) @@ -95,7 +95,7 @@ vm_call0_cfunc(rb_thread_t* th, struct r https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L95 rb_bug("vm_call0_cfunc: cfp consistency error"); } VM_PROFILE_UP(C2C_POPF); - vm_pop_frame(th); + rb_vm_pop_frame(th); } } EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, calling->recv, ci->mid, callnig->cc->me->owner, val); @@ -134,7 +134,7 @@ vm_call0_cfunc_with_frame(rb_thread_t* t https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L134 rb_bug("vm_call0_cfunc_with_frame: cfp consistency error"); } VM_PROFILE_UP(C2C_POPF); - vm_pop_frame(th); + rb_vm_pop_frame(th); } EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, mid, me->owner, val); RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, mid); Index: vm_trace.c =================================================================== --- vm_trace.c (revision 55754) +++ vm_trace.c (revision 55755) @@ -362,7 +362,7 @@ rb_threadptr_exec_event_hooks_orig(rb_tr https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L362 if (VM_FRAME_TYPE_FINISH_P(th->cfp)) { th->tag = th->tag->prev; } - th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); + rb_vm_pop_frame(th); } TH_JUMP_TAG(th, state); } Index: vm_args.c =================================================================== --- vm_args.c (revision 55754) +++ vm_args.c (revision 55755) @@ -702,7 +702,7 @@ raise_argument_error(rb_thread_t *th, co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L702 VM_ENVVAL_BLOCK_PTR(0) /* specval*/, Qfalse /* me or cref */, iseq->body->iseq_encoded, th->cfp->sp, 1 /* local_size (cref/me) */, 0 /* stack_max */); at = rb_vm_backtrace_object(); - vm_pop_frame(th); + rb_vm_pop_frame(th); } else { at = rb_vm_backtrace_object(); Index: vm.c =================================================================== --- vm.c (revision 55754) +++ vm.c (revision 55755) @@ -434,11 +434,12 @@ void https://github.com/ruby/ruby/blob/trunk/vm.c#L434 rb_vm_pop_cfunc_frame(void) { rb_thread_t *th = GET_THREAD(); - const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(th->cfp); + rb_control_frame_t *cfp = th->cfp; + const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, me->called_id, me->owner, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, cfp->self, me->called_id, me->owner, Qnil); RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, me->called_id); - vm_pop_frame(th); + vm_pop_frame(th, cfp, cfp->ep); } void @@ -450,7 +451,7 @@ rb_vm_rewind_cfp(rb_thread_t *th, rb_con https://github.com/ruby/ruby/blob/trunk/vm.c#L451 printf("skipped frame: %s\n", vm_frametype_name(th->cfp)); #endif if (VM_FRAME_TYPE(th->cfp) != VM_FRAME_MAGIC_CFUNC) { - vm_pop_frame(th); + rb_vm_pop_frame(th); } else { /* unlikely path */ rb_vm_pop_cfunc_frame(); @@ -900,7 +901,7 @@ rb_binding_add_dynavars(rb_binding_t *bi https://github.com/ruby/ruby/blob/trunk/vm.c#L901 vm_set_eval_stack(th, iseq, 0, base_block); bind->env = vm_make_env_object(th, th->cfp); - vm_pop_frame(th); + rb_vm_pop_frame(th); GetEnvPtr(bind->env, env); return env->env; @@ -1682,7 +1683,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L1683 rb_vm_frame_method_entry(th->cfp)->owner, rb_vm_frame_method_entry(th->cfp)->called_id); } - th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); + rb_vm_pop_frame(th); } cfp = th->cfp; @@ -1715,7 +1716,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L1716 th->errinfo = Qnil; result = THROW_DATA_VAL(err); hook_before_rewind(th, th->cfp, TRUE); - vm_pop_frame(th); + rb_vm_pop_frame(th); goto finish_vme; } } @@ -1858,13 +1859,13 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L1859 hook_before_rewind(th, th->cfp, FALSE); if (VM_FRAME_TYPE_FINISH_P(th->cfp)) { - vm_pop_frame(th); + rb_vm_pop_frame(th); th->errinfo = (VALUE)err; TH_TMPPOP_TAG(); TH_JUMP_TAG(th, state); } else { - th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); + rb_vm_pop_frame(th); goto exception_handler; } } @@ -1964,7 +1965,7 @@ rb_vm_call_cfunc(VALUE recv, VALUE (*fun https://github.com/ruby/ruby/blob/trunk/vm.c#L1965 val = (*func)(arg); - vm_pop_frame(th); + rb_vm_pop_frame(th); return val; } Index: ChangeLog =================================================================== --- ChangeLog (revision 55754) +++ ChangeLog (revision 55755) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jul 26 19:26:00 2016 Koichi Sasada <ko1@a...> + + * vm_insnhelper.c: introduce rb_vm_pop_frame() and use it + instead of setting rb_thread_t::cfp directly. + + * vm_insnhelper.c (vm_pop_frame): return the result of + finish frame or not. + Tue Jul 26 19:06:39 2016 Koichi Sasada <ko1@a...> * gc.c (rb_raw_obj_info): support to show Proc obj. Index: insns.def =================================================================== --- insns.def (revision 55754) +++ insns.def (revision 55755) @@ -1128,9 +1128,7 @@ leave https://github.com/ruby/ruby/blob/trunk/insns.def#L1128 RUBY_VM_CHECK_INTS(th); - if (UNLIKELY(VM_FRAME_TYPE_FINISH_P(GET_CFP()))) { - vm_pop_frame(th); - + if (vm_pop_frame(th, GET_CFP(), GET_EP())) { #if OPT_CALL_THREADED_CODE th->retval = val; return 0; @@ -1139,7 +1137,6 @@ leave https://github.com/ruby/ruby/blob/trunk/insns.def#L1137 #endif } else { - vm_pop_frame(th); RESTORE_REGS(); } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/