diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-14 20:59:21 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-14 20:59:21 +0000 |
commit | c4457e03c665a48f1d953fbbe4499b65e7b1149b (patch) | |
tree | 496075643b1a70ab381c6c1b3c4bbdc70e0fee3e /vm_insnhelper.c | |
parent | 8f08e61bad1d745dc7a10ff216ad5ca2e92b3ded (diff) | |
download | ruby-c4457e03c665a48f1d953fbbe4499b65e7b1149b.tar.gz |
* vm_insnhelper.h CI_SET_FASTPATH: introduce new macro
`CI_SET_FASTPATH(ci, func)'. This macro set `ci->call' as `func'.
`func' (ci->call) is called at the last of `send'
(and `invokesuper') instruction.
`CI_SET_FASTPATH' does not set `ci->call' when the method
(stored in `ci->me') is `protected'.
* vm_insnhelper.c (vm_call_method): use `CI_SET_FASTPATH'.
After several checking (visibility, argc checking), the result of
checking can be reused until re-definition of this method
with inline method cache.
Note that this optimization is now experimental.
If you find any problem about it, please tell us.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 8d94e469db..6866409992 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1066,18 +1066,6 @@ vm_caller_setup_args(const rb_thread_t *th, rb_control_frame_t *cfp, rb_call_inf } } -#define VM_CALLEE_SETUP_ARG(th, ci, iseq, argv) \ - if (LIKELY((iseq)->arg_simple & 0x01)) { \ - /* simple check */ \ - if ((ci)->argc != (iseq)->argc) { \ - argument_error((iseq), ((ci)->argc), (iseq)->argc, (iseq)->argc); \ - } \ - (ci)->opt_pc = 0; \ - } \ - else { \ - (ci)->opt_pc = vm_callee_setup_arg_complex((th), (ci), (iseq), (argv)); \ - } - static int vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t *iseq, VALUE *orig_argv) { @@ -1188,6 +1176,19 @@ vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t static VALUE vm_call_iseq_setup_2(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci); +#define VM_CALLEE_SETUP_ARG(th, ci, iseq, argv) \ + if (LIKELY((iseq)->arg_simple & 0x01)) { \ + /* simple check */ \ + if ((ci)->argc != (iseq)->argc) { \ + argument_error((iseq), ((ci)->argc), (iseq)->argc, (iseq)->argc); \ + } \ + (ci)->opt_pc = 0; \ + CI_SET_FASTPATH((ci), vm_call_iseq_setup_2); \ + } \ + else { \ + (ci)->opt_pc = vm_callee_setup_arg_complex((th), (ci), (iseq), (argv)); \ + } + static VALUE vm_call_iseq_setup(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) { @@ -1365,9 +1366,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci) static VALUE vm_call_ivar(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) { - VALUE val; - rb_check_arity(ci->argc, 0, 0); - val = rb_attr_get(ci->recv, ci->me->def->body.attr.id); + VALUE val = rb_attr_get(ci->recv, ci->me->def->body.attr.id); cfp->sp -= 1; return val; } @@ -1375,9 +1374,7 @@ vm_call_ivar(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) static VALUE vm_call_attrset(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) { - VALUE val; - rb_check_arity(ci->argc, 1, 1); - val = rb_ivar_set(ci->recv, ci->me->def->body.attr.id, *(cfp->sp - 1)); + VALUE val = rb_ivar_set(ci->recv, ci->me->def->body.attr.id, *(cfp->sp - 1)); cfp->sp -= 2; return val; } @@ -1499,26 +1496,34 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) normal_method_dispatch: switch (ci->me->def->type) { case VM_METHOD_TYPE_ISEQ:{ + CI_SET_FASTPATH(ci, vm_call_iseq_setup); return vm_call_iseq_setup(th, cfp, ci); } case VM_METHOD_TYPE_NOTIMPLEMENTED: case VM_METHOD_TYPE_CFUNC:{ + CI_SET_FASTPATH(ci, vm_call_cfunc); val = vm_call_cfunc(th, cfp, ci); break; } case VM_METHOD_TYPE_ATTRSET:{ + rb_check_arity(ci->argc, 0, 1); + CI_SET_FASTPATH(ci, vm_call_attrset); val = vm_call_attrset(th, cfp, ci); break; } case VM_METHOD_TYPE_IVAR:{ + rb_check_arity(ci->argc, 0, 0); + CI_SET_FASTPATH(ci, vm_call_ivar); val = vm_call_ivar(th, cfp, ci); break; } case VM_METHOD_TYPE_MISSING:{ + CI_SET_FASTPATH(ci, vm_call_missing); val = vm_call_missing(th, cfp, ci); break; } case VM_METHOD_TYPE_BMETHOD:{ + CI_SET_FASTPATH(ci, vm_call_bmethod); val = vm_call_bmethod(th, cfp, ci); break; } @@ -1539,10 +1544,12 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) case VM_METHOD_TYPE_OPTIMIZED:{ switch (ci->me->def->body.optimize_type) { case OPTIMIZED_METHOD_TYPE_SEND: { + CI_SET_FASTPATH(ci, vm_call_opt_send); val = vm_call_opt_send(th, cfp, ci); break; } case OPTIMIZED_METHOD_TYPE_CALL: { + CI_SET_FASTPATH(ci, vm_call_opt_call); val = vm_call_opt_call(th, cfp, ci); break; } |