ruby-changes:25134
From: ko1 <ko1@a...>
Date: Mon, 15 Oct 2012 05:59:35 +0900 (JST)
Subject: [ruby-changes:25134] ko1:r37186 (trunk): * vm_insnhelper.h CI_SET_FASTPATH: introduce new macro
ko1 2012-10-15 05:59:21 +0900 (Mon, 15 Oct 2012) New Revision: 37186 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37186 Log: * 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. Modified files: trunk/ChangeLog trunk/vm_insnhelper.c trunk/vm_insnhelper.h Index: ChangeLog =================================================================== --- ChangeLog (revision 37185) +++ ChangeLog (revision 37186) @@ -1,3 +1,20 @@ +Mon Oct 15 05:20:13 2012 Koichi Sasada <ko1@a...> + + * 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. + Mon Oct 15 04:51:55 2012 Koichi Sasada <ko1@a...> * vm_insnhelper.c: refactoring. Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 37185) +++ vm_insnhelper.c (revision 37186) @@ -1066,18 +1066,6 @@ } } -#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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; } Index: vm_insnhelper.h =================================================================== --- vm_insnhelper.h (revision 37185) +++ vm_insnhelper.h (revision 37186) @@ -200,6 +200,13 @@ } \ } while (0) +/* set fastpath when cached method is *NOT* protected + * because inline method cache does not care about receiver. + */ +#define CI_SET_FASTPATH(ci, func) do { \ + if (!(((ci)->me->flag & NOEX_MASK) & NOEX_PROTECTED)) ((ci)->call = (func)); \ +} while (0) + #define GET_BLOCK_PTR() ((rb_block_t *)(GC_GUARDED_PTR_REF(GET_LEP()[0]))) /**********************************************************/ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/