Skip to content

Commit 3364d79

Browse files
authored
YJIT: Stop sharing rb_vm_invokesuper among different instructions (ruby#14492)
1 parent c0e01a2 commit 3364d79

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

vm_insnhelper.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6139,26 +6139,29 @@ rb_vm_opt_send_without_block(rb_execution_context_t *ec, rb_control_frame_t *reg
61396139

61406140
VALUE
61416141
rb_vm_invokesuper(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, CALL_DATA cd, ISEQ blockiseq)
6142+
{
6143+
stack_check(ec);
6144+
6145+
VALUE bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, true);
6146+
VALUE val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_super);
6147+
6148+
VM_EXEC(ec, val);
6149+
return val;
6150+
}
6151+
6152+
VALUE
6153+
rb_vm_invokesuperforward(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, CALL_DATA cd, ISEQ blockiseq)
61426154
{
61436155
stack_check(ec);
61446156
struct rb_forwarding_call_data adjusted_cd;
61456157
struct rb_callinfo adjusted_ci;
61466158

6147-
VALUE bh;
6148-
VALUE val;
6149-
6150-
if (vm_ci_flag(cd->ci) & VM_CALL_FORWARDING) {
6151-
bh = vm_caller_setup_fwd_args(GET_EC(), GET_CFP(), cd, blockiseq, true, &adjusted_cd, &adjusted_ci);
6159+
VALUE bh = vm_caller_setup_fwd_args(GET_EC(), GET_CFP(), cd, blockiseq, true, &adjusted_cd, &adjusted_ci);
61526160

6153-
val = vm_sendish(ec, GET_CFP(), &adjusted_cd.cd, bh, mexp_search_super);
6161+
VALUE val = vm_sendish(ec, GET_CFP(), &adjusted_cd.cd, bh, mexp_search_super);
61546162

6155-
if (cd->cc != adjusted_cd.cd.cc && vm_cc_markable(adjusted_cd.cd.cc)) {
6156-
RB_OBJ_WRITE(GET_ISEQ(), &cd->cc, adjusted_cd.cd.cc);
6157-
}
6158-
}
6159-
else {
6160-
bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, true);
6161-
val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_super);
6163+
if (cd->cc != adjusted_cd.cd.cc && vm_cc_markable(adjusted_cd.cd.cc)) {
6164+
RB_OBJ_WRITE(GET_ISEQ(), &cd->cc, adjusted_cd.cd.cc);
61626165
}
61636166

61646167
VM_EXEC(ec, val);

yjit/src/codegen.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9731,7 +9731,7 @@ fn gen_invokesuper(
97319731
return Some(status);
97329732
}
97339733

9734-
// Otherwise, fallback to dynamic dispatch using the interpreter's implementation of send
9734+
// Otherwise, fallback to dynamic dispatch using the interpreter's implementation of invokesuper
97359735
let blockiseq = jit.get_arg(1).as_iseq();
97369736
gen_send_dynamic(jit, asm, cd, unsafe { rb_yjit_sendish_sp_pops((*cd).ci) }, |asm| {
97379737
extern "C" {
@@ -9748,7 +9748,23 @@ fn gen_invokesuperforward(
97489748
jit: &mut JITState,
97499749
asm: &mut Assembler,
97509750
) -> Option<CodegenStatus> {
9751-
return gen_invokesuper(jit, asm);
9751+
// Generate specialized code if possible
9752+
let cd = jit.get_arg(0).as_ptr();
9753+
if let Some(status) = gen_invokesuper_specialized(jit, asm, cd) {
9754+
return Some(status);
9755+
}
9756+
9757+
// Otherwise, fallback to dynamic dispatch using the interpreter's implementation of invokesuperforward
9758+
let blockiseq = jit.get_arg(1).as_iseq();
9759+
gen_send_dynamic(jit, asm, cd, unsafe { rb_yjit_sendish_sp_pops((*cd).ci) }, |asm| {
9760+
extern "C" {
9761+
fn rb_vm_invokesuperforward(ec: EcPtr, cfp: CfpPtr, cd: VALUE, blockiseq: IseqPtr) -> VALUE;
9762+
}
9763+
asm.ccall(
9764+
rb_vm_invokesuperforward as *const u8,
9765+
vec![EC, CFP, (cd as usize).into(), VALUE(blockiseq as usize).into()],
9766+
)
9767+
})
97529768
}
97539769

97549770
fn gen_invokesuper_specialized(

0 commit comments

Comments
 (0)