From 984e05a11b761186c50971d6ef40e6207669fc7e Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Wed, 27 Aug 2025 17:50:58 -0400 Subject: ZJIT: Count dynamic dispatch (SendWithoutBlock) --- zjit.rb | 1 + zjit/src/codegen.rs | 4 ++++ zjit/src/stats.rs | 3 +++ 3 files changed, 8 insertions(+) diff --git a/zjit.rb b/zjit.rb index 3476c1cb38..86d6643df2 100644 --- a/zjit.rb +++ b/zjit.rb @@ -56,6 +56,7 @@ class << RubyVM::ZJIT :total_insn_count, :vm_insn_count, :zjit_insn_count, + :zjit_dynamic_dispatch, :ratio_in_zjit, ], buf:, stats:) print_counters_with_prefix(prefix: 'exit_', prompt: 'side exit reasons', buf:, stats:, limit: 20) diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs index 2b71596a17..fd804e5a42 100644 --- a/zjit/src/codegen.rs +++ b/zjit/src/codegen.rs @@ -858,6 +858,10 @@ fn gen_send_without_block( cd: *const rb_call_data, state: &FrameState, ) -> lir::Opnd { + if get_option!(stats) { + gen_incr_counter(asm, Counter::zjit_dynamic_dispatch); + } + // Note that it's incorrect to use this frame state to side exit because // the state might not be on the boundary of an interpreter instruction. // For example, `opt_str_uminus` pushes to the stack and then sends. diff --git a/zjit/src/stats.rs b/zjit/src/stats.rs index c6b1ed29d6..10692d83f5 100644 --- a/zjit/src/stats.rs +++ b/zjit/src/stats.rs @@ -72,6 +72,9 @@ make_counters! { // The number of times YARV instructions are executed on JIT code zjit_insn_count, + // The number of times we do a dynamic dispatch from JIT code + zjit_dynamic_dispatch, + // failed_: Compilation failure reasons failed_iseq_stack_too_large, failed_hir_compile, -- cgit v1.2.3