diff options
author | Koichi Sasada <ko1@atdot.net> | 2021-11-16 17:57:49 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2021-11-17 22:21:42 +0900 |
commit | b2255153cf2fe9d7b851c59cc09b358c0630e0a2 (patch) | |
tree | 7d4142a5872963a91d94bbc5103e904258eb83c6 /vm_insnhelper.c | |
parent | 84aba250315d7fea728a6708e33ae8bf11f607b2 (diff) |
`vm_empty_cc_for_super`
Same as `vm_empty_cc`, introduce a global variable which has
`.call_ = vm_call_super_method`. Use it if the `cme == NULL` on
`vm_search_super_method`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5122
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 5e5554cb67..ff02f14141 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -38,6 +38,7 @@ extern VALUE rb_make_no_method_exception(VALUE exc, VALUE format, VALUE obj, #ifndef MJIT_HEADER static const struct rb_callcache vm_empty_cc; +static const struct rb_callcache vm_empty_cc_for_super; #endif /* control stack frame */ @@ -3711,6 +3712,11 @@ vm_call_super_method(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, st { RB_DEBUG_COUNTER_INC(ccf_super_method); + // This line is introduced to make different from `vm_call_general` because some compilers (VC we found) + // can merge the function and the address of the function becomes same. + // The address of `vm_call_super_method` is used in `search_refined_method`, so it should be different. + if (ec == NULL) rb_bug("unreachable"); + /* this check is required to distinguish with other functions. */ VM_ASSERT(vm_cc_call(calling->cc) == vm_call_super_method); return vm_call_method(ec, reg_cfp, calling); @@ -3738,6 +3744,16 @@ vm_super_outside(void) } static const struct rb_callcache * +empty_cc_for_super(void) +{ +#ifdef MJIT_HEADER + return rb_vm_empty_cc_for_super(); +#else + return &vm_empty_cc_for_super; +#endif +} + +static const struct rb_callcache * vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *cd, VALUE recv) { VALUE current_defined_class; @@ -3800,19 +3816,18 @@ vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *c // define_method can cache for different method id if (cached_cme == NULL) { - // temporary CC. revisit it - static const struct rb_callcache *empty_cc_for_super = NULL; - if (empty_cc_for_super == NULL) { - empty_cc_for_super = vm_cc_new(0, NULL, vm_call_super_method); - FL_SET_RAW((VALUE)empty_cc_for_super, VM_CALLCACHE_UNMARKABLE); - rb_gc_register_mark_object((VALUE)empty_cc_for_super); - } - RB_OBJ_WRITE(reg_cfp->iseq, &cd->cc, cc = empty_cc_for_super); + // empty_cc_for_super is not markable object + cd->cc = empty_cc_for_super(); } else if (cached_cme->called_id != mid) { const rb_callable_method_entry_t *cme = rb_callable_method_entry(klass, mid); - cc = vm_cc_new(klass, cme, vm_call_super_method); - RB_OBJ_WRITE(reg_cfp->iseq, &cd->cc, cc); + if (cme) { + cc = vm_cc_new(klass, cme, vm_call_super_method); + RB_OBJ_WRITE(reg_cfp->iseq, &cd->cc, cc); + } + else { + cd->cc = cc = empty_cc_for_super(); + } } else { switch (cached_cme->def->type) { @@ -3829,6 +3844,8 @@ vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *c } } + VM_ASSERT((vm_cc_cme(cc), true)); + return cc; } |