Skip to content

Commit 92a12fd

Browse files
committed
Add a CC fastpath for forwardable methods
1 parent 1f117e2 commit 92a12fd

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

vm_insnhelper.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,6 +2916,26 @@ args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *cons
29162916
VALUE *const passed_values, const int passed_keyword_len, const VALUE *const passed_keywords,
29172917
VALUE *const locals);
29182918

2919+
static VALUE
2920+
vm_call_iseq_forwardable(rb_execution_context_t *ec, rb_control_frame_t *cfp,
2921+
struct rb_calling_info *calling)
2922+
{
2923+
const struct rb_callcache *cc = calling->cc;
2924+
const rb_iseq_t *iseq = def_iseq_ptr(vm_cc_cme(cc)->def);
2925+
int param_size = ISEQ_BODY(iseq)->param.size;
2926+
int local_size = ISEQ_BODY(iseq)->local_table_size;
2927+
2928+
// Setting up local size and param size
2929+
VM_ASSERT(ISEQ_BODY(iseq)->param.flags.forwardable);
2930+
2931+
local_size = local_size + vm_ci_argc(calling->cd->ci);
2932+
param_size = param_size + vm_ci_argc(calling->cd->ci);
2933+
2934+
cfp->sp[0] = (VALUE)calling->cd->ci;
2935+
2936+
return vm_call_iseq_setup_normal(ec, cfp, calling, vm_cc_cme(cc), 0, param_size, local_size);
2937+
}
2938+
29192939
static VALUE
29202940
vm_call_iseq_setup_kwparm_kwarg(rb_execution_context_t *ec, rb_control_frame_t *cfp,
29212941
struct rb_calling_info *calling)
@@ -3171,6 +3191,8 @@ vm_callee_setup_arg(rb_execution_context_t *ec, struct rb_calling_info *calling,
31713191
// => type
31723192
//
31733193
if (ISEQ_BODY(iseq)->param.flags.forwardable) {
3194+
bool can_fastpath = true;
3195+
31743196
if ((vm_ci_flag(ci) & VM_CALL_FORWARDING)) {
31753197
struct rb_forwarding_call_data * forward_cd = (struct rb_forwarding_call_data *)calling->cd;
31763198
if (vm_ci_argc(ci) != vm_ci_argc(forward_cd->caller_ci)) {
@@ -3182,6 +3204,7 @@ vm_callee_setup_arg(rb_execution_context_t *ec, struct rb_calling_info *calling,
31823204
} else {
31833205
ci = forward_cd->caller_ci;
31843206
}
3207+
can_fastpath = false;
31853208
}
31863209
// C functions calling iseqs will stack allocate a CI,
31873210
// so we need to convert it to heap allocated
@@ -3191,8 +3214,10 @@ vm_callee_setup_arg(rb_execution_context_t *ec, struct rb_calling_info *calling,
31913214
vm_ci_flag(ci),
31923215
vm_ci_argc(ci),
31933216
vm_ci_kwarg(ci));
3217+
can_fastpath = false;
31943218
}
31953219
argv[param_size - 1] = (VALUE)ci;
3220+
CC_SET_FASTPATH(cc, vm_call_iseq_forwardable, can_fastpath);
31963221
return 0;
31973222
}
31983223

0 commit comments

Comments
 (0)