Skip to content

Commit 40bda91

Browse files
committed
ZJIT: Add stat for def_type of send_without_block fallbacks
1 parent eaf64af commit 40bda91

4 files changed

Lines changed: 123 additions & 78 deletions

File tree

‎zjit.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def stats_string
4545
print_counters_with_prefix(prefix: 'compile_error_', prompt: 'compile error reasons', buf:, stats:, limit: 20)
4646
print_counters_with_prefix(prefix: 'exit_', prompt: 'side exit reasons', buf:, stats:, limit: 20)
4747
print_counters_with_prefix(prefix: 'dynamic_send_type_', prompt: 'dynamic send types', buf:, stats:, limit: 20)
48+
print_counters_with_prefix(prefix: 'send_fallback_', prompt: 'send fallback def_types', buf:, stats:, limit: 20)
4849

4950
# Show the most important stats ratio_in_zjit at the end
5051
print_counters([

‎zjit/src/codegen.rs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
364364
Insn::IfTrue { val, target } => no_output!(gen_if_true(jit, asm, opnd!(val), target)),
365365
Insn::IfFalse { val, target } => no_output!(gen_if_false(jit, asm, opnd!(val), target)),
366366
&Insn::Send { cd, blockiseq, state, .. } => gen_send(jit, asm, cd, blockiseq, &function.frame_state(state)),
367-
Insn::SendWithoutBlock { cd, state, .. } => gen_send_without_block(jit, asm, *cd, &function.frame_state(*state)),
367+
Insn::SendWithoutBlock { cd, state, def_type, .. } => {
368+
if let Some(def_type) = def_type { update_send_fallback_counter(asm, *def_type); }
369+
gen_send_without_block(jit, asm, *cd, &function.frame_state(*state))
370+
}
368371
// Give up SendWithoutBlockDirect for 6+ args since asm.ccall() doesn't support it.
369372
Insn::SendWithoutBlockDirect { cd, state, args, .. } if args.len() + 1 > C_ARG_OPNDS.len() => // +1 for self
370373
gen_send_without_block(jit, asm, *cd, &function.frame_state(*state)),
@@ -1995,6 +1998,24 @@ fn aligned_stack_bytes(num_slots: usize) -> usize {
19951998
num_slots * SIZEOF_VALUE
19961999
}
19972000

2001+
fn update_send_fallback_counter(asm: &mut Assembler, def_type: u32) {
2002+
match def_type {
2003+
VM_METHOD_TYPE_ISEQ => { gen_incr_counter(asm, Counter::send_fallback_iseq); }
2004+
VM_METHOD_TYPE_CFUNC => { gen_incr_counter(asm, Counter::send_fallback_cfunc); }
2005+
VM_METHOD_TYPE_ATTRSET => { gen_incr_counter(asm, Counter::send_fallback_attrset); }
2006+
VM_METHOD_TYPE_IVAR => { gen_incr_counter(asm, Counter::send_fallback_ivar); }
2007+
VM_METHOD_TYPE_BMETHOD => { gen_incr_counter(asm, Counter::send_fallback_bmethod); }
2008+
VM_METHOD_TYPE_ZSUPER => { gen_incr_counter(asm, Counter::send_fallback_zsuper); }
2009+
VM_METHOD_TYPE_ALIAS => { gen_incr_counter(asm, Counter::send_fallback_alias); }
2010+
VM_METHOD_TYPE_UNDEF => { gen_incr_counter(asm, Counter::send_fallback_undef); }
2011+
VM_METHOD_TYPE_NOTIMPLEMENTED => { gen_incr_counter(asm, Counter::send_fallback_not_implemented); }
2012+
VM_METHOD_TYPE_OPTIMIZED => { gen_incr_counter(asm, Counter::send_fallback_optimized); }
2013+
VM_METHOD_TYPE_MISSING => { gen_incr_counter(asm, Counter::send_fallback_missing); }
2014+
VM_METHOD_TYPE_REFINED => { gen_incr_counter(asm, Counter::send_fallback_refined); }
2015+
_ => unreachable!("unknown method type: {def_type}"),
2016+
}
2017+
}
2018+
19982019
impl Assembler {
19992020
/// Make a C call while marking the start and end positions for IseqCall
20002021
fn ccall_with_iseq_call(&mut self, fptr: *const u8, opnds: Vec<Opnd>, iseq_call: &Rc<RefCell<IseqCall>>) -> Opnd {

0 commit comments

Comments
 (0)