Skip to content

Commit 39f3cab

Browse files
authored
YJIT: Stop sharing rb_vm_send among different instructions (ruby#14393)
1 parent 99bf47a commit 39f3cab

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

vm_insnhelper.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6093,27 +6093,28 @@ vm_sendish(
60936093

60946094
VALUE
60956095
rb_vm_send(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, CALL_DATA cd, ISEQ blockiseq)
6096+
{
6097+
stack_check(ec);
6098+
VALUE bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, false);
6099+
VALUE val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
6100+
VM_EXEC(ec, val);
6101+
return val;
6102+
}
6103+
6104+
VALUE
6105+
rb_vm_sendforward(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, CALL_DATA cd, ISEQ blockiseq)
60966106
{
60976107
stack_check(ec);
60986108

60996109
struct rb_forwarding_call_data adjusted_cd;
61006110
struct rb_callinfo adjusted_ci;
61016111

6102-
VALUE bh;
6103-
VALUE val;
6104-
6105-
if (vm_ci_flag(cd->ci) & VM_CALL_FORWARDING) {
6106-
bh = vm_caller_setup_fwd_args(GET_EC(), GET_CFP(), cd, blockiseq, false, &adjusted_cd, &adjusted_ci);
6112+
VALUE bh = vm_caller_setup_fwd_args(GET_EC(), GET_CFP(), cd, blockiseq, false, &adjusted_cd, &adjusted_ci);
61076113

6108-
val = vm_sendish(ec, GET_CFP(), &adjusted_cd.cd, bh, mexp_search_method);
6114+
VALUE val = vm_sendish(ec, GET_CFP(), &adjusted_cd.cd, bh, mexp_search_method);
61096115

6110-
if (cd->cc != adjusted_cd.cd.cc && vm_cc_markable(adjusted_cd.cd.cc)) {
6111-
RB_OBJ_WRITE(GET_ISEQ(), &cd->cc, adjusted_cd.cd.cc);
6112-
}
6113-
}
6114-
else {
6115-
bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, false);
6116-
val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
6116+
if (cd->cc != adjusted_cd.cd.cc && vm_cc_markable(adjusted_cd.cd.cc)) {
6117+
RB_OBJ_WRITE(GET_ISEQ(), &cd->cc, adjusted_cd.cd.cc);
61176118
}
61186119

61196120
VM_EXEC(ec, val);

yjit/src/codegen.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9564,7 +9564,24 @@ fn gen_sendforward(
95649564
jit: &mut JITState,
95659565
asm: &mut Assembler,
95669566
) -> Option<CodegenStatus> {
9567-
return gen_send(jit, asm);
9567+
// Generate specialized code if possible
9568+
let cd = jit.get_arg(0).as_ptr();
9569+
let block = jit.get_arg(1).as_optional_ptr().map(|iseq| BlockHandler::BlockISeq(iseq));
9570+
if let Some(status) = perf_call! { gen_send_general(jit, asm, cd, block) } {
9571+
return Some(status);
9572+
}
9573+
9574+
// Otherwise, fallback to dynamic dispatch using the interpreter's implementation of sendforward
9575+
let blockiseq = jit.get_arg(1).as_iseq();
9576+
gen_send_dynamic(jit, asm, cd, unsafe { rb_yjit_sendish_sp_pops((*cd).ci) }, |asm| {
9577+
extern "C" {
9578+
fn rb_vm_sendforward(ec: EcPtr, cfp: CfpPtr, cd: VALUE, blockiseq: IseqPtr) -> VALUE;
9579+
}
9580+
asm.ccall(
9581+
rb_vm_sendforward as *const u8,
9582+
vec![EC, CFP, (cd as usize).into(), VALUE(blockiseq as usize).into()],
9583+
)
9584+
})
95689585
}
95699586

95709587
fn gen_invokeblock(

0 commit comments

Comments
 (0)