ruby-changes:43732
From: ko1 <ko1@a...>
Date: Wed, 3 Aug 2016 10:50:56 +0900 (JST)
Subject: [ruby-changes:43732] ko1:r55804 (trunk): * vm_core.h: introduce VM_FRAME_RUBYFRAME_P()
ko1 2016-08-03 10:50:50 +0900 (Wed, 03 Aug 2016) New Revision: 55804 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55804 Log: * vm_core.h: introduce VM_FRAME_RUBYFRAME_P() and VM_FRAME_CFRAME_P(). Most of case, RUBY_VM_NORMAL_ISEQ_P() is no longer needed. * vm_core.h: introduce rb_obj_is_iseq(). * cont.c, vm.c: VM_FRAME_MAGIC_DUMMY with VM_FRAME_FLAG_CFRAME. Modified files: trunk/ChangeLog trunk/cont.c trunk/eval.c trunk/iseq.c trunk/proc.c trunk/vm.c trunk/vm_backtrace.c trunk/vm_core.h trunk/vm_dump.c trunk/vm_eval.c trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 55803) +++ ChangeLog (revision 55804) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Aug 3 10:47:07 2016 Koichi Sasada <ko1@a...> + + * vm_core.h: introduce VM_FRAME_RUBYFRAME_P() + and VM_FRAME_CFRAME_P(). + Most of case, RUBY_VM_NORMAL_ISEQ_P() is no + longer needed. + + * vm_core.h: introduce rb_obj_is_iseq(). + + * cont.c, vm.c: VM_FRAME_MAGIC_DUMMY with + VM_FRAME_FLAG_CFRAME. + Wed Aug 3 09:25:16 2016 Koichi Sasada <ko1@a...> * vm_core.h: rename macros and make them inline functions. Index: vm_core.h =================================================================== --- vm_core.h (revision 55803) +++ vm_core.h (revision 55804) @@ -1040,6 +1040,30 @@ VM_FRAME_BMETHOD_P(const rb_control_fram https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1040 return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_BMETHOD) != 0; } +static inline int +rb_obj_is_iseq(VALUE iseq) +{ + return RB_TYPE_P(iseq, T_IMEMO) && imemo_type(iseq) == imemo_iseq; +} + +#if VM_CHECK_MODE > 0 +#define RUBY_VM_NORMAL_ISEQ_P(iseq) rb_obj_is_iseq((VALUE)iseq) +#endif + +static inline int +VM_FRAME_CFRAME_P(const rb_control_frame_t *cfp) +{ + int cframe_p = VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_CFRAME) != 0; + VM_ASSERT(RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) != cframe_p); + return cframe_p; +} + +static inline int +VM_FRAME_RUBYFRAME_P(const rb_control_frame_t *cfp) +{ + return !VM_FRAME_CFRAME_P(cfp); +} + #define RUBYVM_CFUNC_FRAME_P(cfp) \ (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC) @@ -1153,8 +1177,6 @@ VALUE rb_vm_frame_block_handler(const rb https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1177 #define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \ (!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th))) -#define RUBY_VM_NORMAL_ISEQ_P(ptr) (RB_TYPE_P((VALUE)(ptr), T_IMEMO) && imemo_type((VALUE)ptr) == imemo_iseq && rb_iseq_check((rb_iseq_t *)ptr)) - static inline int VM_BH_ISEQ_BLOCK_P(VALUE block_handler) { Index: iseq.c =================================================================== --- iseq.c (revision 55803) +++ iseq.c (revision 55804) @@ -1651,7 +1651,7 @@ iseqw_s_of(VALUE klass, VALUE body) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1651 if (rb_obj_is_proc(body)) { iseq = vm_proc_iseq(body); - if (!RUBY_VM_NORMAL_ISEQ_P(iseq)) { + if (!rb_obj_is_iseq((VALUE)iseq)) { iseq = NULL; } } Index: vm_eval.c =================================================================== --- vm_eval.c (revision 55803) +++ vm_eval.c (revision 55804) @@ -262,7 +262,7 @@ vm_call_super(rb_thread_t *th, int argc, https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L262 rb_control_frame_t *cfp = th->cfp; const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp); - if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (VM_FRAME_RUBYFRAME_P(cfp)) { rb_bug("vm_call_super: should not be reached"); } Index: proc.c =================================================================== --- proc.c (revision 55803) +++ proc.c (revision 55804) @@ -395,12 +395,12 @@ static const VALUE * https://github.com/ruby/ruby/blob/trunk/proc.c#L395 get_local_variable_ptr(const rb_env_t *env, ID lid) { do { - const rb_iseq_t *iseq; - unsigned int i; + if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) { + const rb_iseq_t *iseq = env->iseq; + unsigned int i; - iseq = env->iseq; + VM_ASSERT(rb_obj_is_iseq((VALUE)iseq)); - if (iseq && RUBY_VM_NORMAL_ISEQ_P(iseq)) { for (i=0; i<iseq->body->local_table_size; i++) { if (iseq->body->local_table[i] == lid) { return &env->env[i]; Index: vm_backtrace.c =================================================================== --- vm_backtrace.c (revision 55803) +++ vm_backtrace.c (revision 55804) @@ -37,13 +37,12 @@ calc_lineno(const rb_iseq_t *iseq, const https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L37 int rb_vm_get_sourceline(const rb_control_frame_t *cfp) { - int lineno = 0; - const rb_iseq_t *iseq = cfp->iseq; - - if (RUBY_VM_NORMAL_ISEQ_P(iseq)) { - lineno = calc_lineno(cfp->iseq, cfp->pc); + if (VM_FRAME_RUBYFRAME_P(cfp) && cfp->iseq) { + return calc_lineno(cfp->iseq, cfp->pc); + } + else { + return 0; } - return lineno; } typedef struct rb_backtrace_location_struct { Index: eval.c =================================================================== --- eval.c (revision 55803) +++ eval.c (revision 55804) @@ -1454,7 +1454,7 @@ errinfo_place(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/eval.c#L1454 rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th); while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) { - if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (VM_FRAME_RUBYFRAME_P(cfp)) { if (cfp->iseq->body->type == ISEQ_TYPE_RESCUE) { return &cfp->ep[VM_ENV_INDEX_LAST_LVAR]; } Index: cont.c =================================================================== --- cont.c (revision 55803) +++ cont.c (revision 55804) @@ -1221,7 +1221,7 @@ fiber_init(VALUE fibval, VALUE proc) https://github.com/ruby/ruby/blob/trunk/cont.c#L1221 rb_vm_push_frame(th, NULL, - VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH, + VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME, Qnil, /* self */ VM_BLOCK_HANDLER_NONE, 0, /* specval */ Index: vm.c =================================================================== --- vm.c (revision 55803) +++ vm.c (revision 55804) @@ -484,7 +484,7 @@ rb_control_frame_t * https://github.com/ruby/ruby/blob/trunk/vm.c#L484 rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp) { while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) { - if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (VM_FRAME_RUBYFRAME_P(cfp)) { return (rb_control_frame_t *)cfp; } cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); @@ -495,14 +495,14 @@ rb_vm_get_ruby_level_next_cfp(const rb_t https://github.com/ruby/ruby/blob/trunk/vm.c#L495 static rb_control_frame_t * vm_get_ruby_level_caller_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp) { - if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (VM_FRAME_RUBYFRAME_P(cfp)) { return (rb_control_frame_t *)cfp; } cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) { - if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (VM_FRAME_RUBYFRAME_P(cfp)) { return (rb_control_frame_t *)cfp; } @@ -662,7 +662,7 @@ vm_make_env_each(rb_thread_t *const th, https://github.com/ruby/ruby/blob/trunk/vm.c#L662 } } - if (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (!VM_FRAME_RUBYFRAME_P(cfp)) { local_size = VM_ENV_DATA_SIZE; } else { @@ -689,14 +689,14 @@ vm_make_env_each(rb_thread_t *const th, https://github.com/ruby/ruby/blob/trunk/vm.c#L689 #if 0 for (i = 0; i < local_size; i++) { - if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (VM_FRAME_RUBYFRAME_P(cfp)) { /* clear value stack for GC */ ep[-local_size + i] = 0; } } #endif - env_iseq = RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) ? cfp->iseq : NULL; + env_iseq = VM_FRAME_RUBYFRAME_P(cfp) ? cfp->iseq : NULL; env_ep = &env_body[local_size - 1 /* specval */]; env = vm_env_new(env_ep, env_body, env_size, env_iseq); @@ -2450,7 +2450,7 @@ th_init(rb_thread_t *th, VALUE self) https://github.com/ruby/ruby/blob/trunk/vm.c#L2450 th->cfp = (void *)(th->stack + th->stack_size); - vm_push_frame(th, 0 /* dummy iseq */, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH /* dummy frame */, + vm_push_frame(th, 0 /* dummy iseq */, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME /* dummy frame */, Qnil /* dummy self */, VM_BLOCK_HANDLER_NONE /* dummy block ptr */, 0 /* dummy cref/me */, 0 /* dummy pc */, th->stack, 0, 0); @@ -3000,6 +3000,7 @@ Init_VM(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L3000 th->cfp->pc = iseq->body->iseq_encoded; th->cfp->self = th->top_self; + VM_ENV_FLAGS_UNSET(th->cfp->ep, VM_FRAME_FLAG_CFRAME); VM_STACK_ENV_WRITE(th->cfp->ep, VM_ENV_DATA_INDEX_ME_CREF, (VALUE)vm_cref_new(rb_cObject, METHOD_VISI_PRIVATE, FALSE, NULL, FALSE)); /* Index: vm_dump.c =================================================================== --- vm_dump.c (revision 55803) +++ vm_dump.c (revision 55804) @@ -240,16 +240,13 @@ vm_base_ptr(rb_control_frame_t *cfp) https://github.com/ruby/ruby/blob/trunk/vm_dump.c#L240 static void vm_stack_dump_each(rb_thread_t *th, rb_control_frame_t *cfp) { - int i; - + int i, argc = 0, local_size = 0; VALUE rstr; VALUE *sp = cfp->sp; VALUE *ep = cfp->ep; - int argc = 0, local_size = 0; - rb_iseq_t *iseq = cfp->iseq; - - if (RUBY_VM_NORMAL_ISEQ_P(iseq)) { + if (VM_FRAME_RUBYFRAME_P(cfp)) { + rb_iseq_t *iseq = cfp->iseq; argc = iseq->body->param.lead_num; local_size = iseq->body->local_size; } @@ -317,7 +314,7 @@ rb_vmdebug_debug_print_register(rb_threa https://github.com/ruby/ruby/blob/trunk/vm_dump.c#L314 ptrdiff_t ep = cfp->ep - th->stack; ptrdiff_t cfpi; - if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (VM_FRAME_RUBYFRAME_P(cfp)) { pc = cfp->pc - cfp->iseq->body->iseq_encoded; } Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 55803) +++ vm_insnhelper.c (revision 55804) @@ -1076,7 +1076,7 @@ vm_throw_start(rb_thread_t *const th, rb https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1076 } if (lep == target_lep && - RUBY_VM_NORMAL_ISEQ_P(escape_cfp->iseq) && + VM_FRAME_RUBYFRAME_P(escape_cfp) && escape_cfp->iseq->body->type == ISEQ_TYPE_CLASS) { in_class_frame = 1; target_lep = 0; @@ -1360,7 +1360,7 @@ vm_base_ptr(const rb_control_frame_t *cf https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1360 { const rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); - if (cfp->iseq && RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { + if (cfp->iseq && VM_FRAME_RUBYFRAME_P(cfp)) { VALUE *bp = prev_cfp->sp + cfp->iseq->body->local_table_size + VM_ENV_DATA_SIZE; if (cfp->iseq->body->type == ISEQ_TYPE_METHOD) { /* adjust `self' */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/