Skip to content

Commit 5680a07

Browse files
committed
ZJIT: Create dedicated def_type counter for Send
1 parent 632d384 commit 5680a07

3 files changed

Lines changed: 70 additions & 30 deletions

File tree

zjit.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def stats_string
159159
print_counters_with_prefix(prefix: 'not_annotated_cfuncs_', prompt: 'not annotated C methods', buf:, stats:, limit: 20)
160160

161161
# Show fallback counters, ordered by the typical amount of fallbacks for the prefix at the time
162-
print_counters_with_prefix(prefix: 'unspecialized_def_type_', prompt: 'not optimized method types', buf:, stats:, limit: 20)
162+
print_counters_with_prefix(prefix: 'unspecialized_send_def_type_', prompt: 'not optimized method types for send', buf:, stats:, limit: 20)
163+
print_counters_with_prefix(prefix: 'unspecialized_send_without_block_def_type_', prompt: 'not optimized method types for send_without_block', buf:, stats:, limit: 20)
163164
print_counters_with_prefix(prefix: 'not_optimized_yarv_insn_', prompt: 'not optimized instructions', buf:, stats:, limit: 20)
164165
print_counters_with_prefix(prefix: 'send_fallback_', prompt: 'send fallback reasons', buf:, stats:, limit: 20)
165166

zjit/src/codegen.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::invariants::{
1515
};
1616
use crate::gc::{append_gc_offsets, get_or_create_iseq_payload, get_or_create_iseq_payload_ptr, IseqCodePtrs, IseqPayload, IseqStatus};
1717
use crate::state::ZJITState;
18-
use crate::stats::{send_fallback_counter, exit_counter_for_compile_error, incr_counter, incr_counter_by, send_fallback_counter_for_method_type, send_fallback_counter_ptr_for_opcode, CompileError};
18+
use crate::stats::{send_fallback_counter, exit_counter_for_compile_error, incr_counter, incr_counter_by, send_fallback_counter_for_method_type, send_without_block_fallback_counter_for_method_type, send_fallback_counter_ptr_for_opcode, CompileError};
1919
use crate::stats::{counter_ptr, with_time_stat, Counter, Counter::{compile_time_ns, exit_compile_error}};
2020
use crate::{asm::CodeBlock, cruby::*, options::debug, virtualmem::CodePtr};
2121
use crate::backend::lir::{self, asm_comment, asm_ccall, Assembler, Opnd, Target, CFP, C_ARG_OPNDS, C_RET_OPND, EC, NATIVE_STACK_PTR, NATIVE_BASE_PTR, SCRATCH_OPND, SP};
@@ -1616,7 +1616,10 @@ fn gen_incr_send_fallback_counter(asm: &mut Assembler, reason: SendFallbackReaso
16161616
NotOptimizedInstruction(opcode) => {
16171617
gen_incr_counter_ptr(asm, send_fallback_counter_ptr_for_opcode(opcode));
16181618
}
1619-
SendWithoutBlockNotOptimizedMethodType(method_type) | SendNotOptimizedMethodType(method_type) => {
1619+
SendWithoutBlockNotOptimizedMethodType(method_type) => {
1620+
gen_incr_counter(asm, send_without_block_fallback_counter_for_method_type(method_type));
1621+
}
1622+
SendNotOptimizedMethodType(method_type) => {
16201623
gen_incr_counter(asm, send_fallback_counter_for_method_type(method_type));
16211624
}
16221625
_ => {}

zjit/src/stats.rs

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,35 @@ make_counters! {
188188
dynamic_getivar_count,
189189
dynamic_setivar_count,
190190

191-
// Method call def_type related to fallback to dynamic dispatch
192-
unspecialized_def_type_iseq,
193-
unspecialized_def_type_cfunc,
194-
unspecialized_def_type_attrset,
195-
unspecialized_def_type_ivar,
196-
unspecialized_def_type_bmethod,
197-
unspecialized_def_type_zsuper,
198-
unspecialized_def_type_alias,
199-
unspecialized_def_type_undef,
200-
unspecialized_def_type_not_implemented,
201-
unspecialized_def_type_optimized,
202-
unspecialized_def_type_missing,
203-
unspecialized_def_type_refined,
204-
unspecialized_def_type_null,
191+
// Method call def_type related to send without block fallback to dynamic dispatch
192+
unspecialized_send_without_block_def_type_iseq,
193+
unspecialized_send_without_block_def_type_cfunc,
194+
unspecialized_send_without_block_def_type_attrset,
195+
unspecialized_send_without_block_def_type_ivar,
196+
unspecialized_send_without_block_def_type_bmethod,
197+
unspecialized_send_without_block_def_type_zsuper,
198+
unspecialized_send_without_block_def_type_alias,
199+
unspecialized_send_without_block_def_type_undef,
200+
unspecialized_send_without_block_def_type_not_implemented,
201+
unspecialized_send_without_block_def_type_optimized,
202+
unspecialized_send_without_block_def_type_missing,
203+
unspecialized_send_without_block_def_type_refined,
204+
unspecialized_send_without_block_def_type_null,
205+
206+
// Method call def_type related to send fallback to dynamic dispatch
207+
unspecialized_send_def_type_iseq,
208+
unspecialized_send_def_type_cfunc,
209+
unspecialized_send_def_type_attrset,
210+
unspecialized_send_def_type_ivar,
211+
unspecialized_send_def_type_bmethod,
212+
unspecialized_send_def_type_zsuper,
213+
unspecialized_send_def_type_alias,
214+
unspecialized_send_def_type_undef,
215+
unspecialized_send_def_type_not_implemented,
216+
unspecialized_send_def_type_optimized,
217+
unspecialized_send_def_type_missing,
218+
unspecialized_send_def_type_refined,
219+
unspecialized_send_def_type_null,
205220

206221
// Writes to the VM frame
207222
vm_write_pc_count,
@@ -332,24 +347,45 @@ pub fn send_fallback_counter(reason: crate::hir::SendFallbackReason) -> Counter
332347
}
333348
}
334349

350+
pub fn send_without_block_fallback_counter_for_method_type(method_type: crate::hir::MethodType) -> Counter {
351+
use crate::hir::MethodType::*;
352+
use crate::stats::Counter::*;
353+
354+
match method_type {
355+
Iseq => unspecialized_send_without_block_def_type_iseq,
356+
Cfunc => unspecialized_send_without_block_def_type_cfunc,
357+
Attrset => unspecialized_send_without_block_def_type_attrset,
358+
Ivar => unspecialized_send_without_block_def_type_ivar,
359+
Bmethod => unspecialized_send_without_block_def_type_bmethod,
360+
Zsuper => unspecialized_send_without_block_def_type_zsuper,
361+
Alias => unspecialized_send_without_block_def_type_alias,
362+
Undefined => unspecialized_send_without_block_def_type_undef,
363+
NotImplemented => unspecialized_send_without_block_def_type_not_implemented,
364+
Optimized => unspecialized_send_without_block_def_type_optimized,
365+
Missing => unspecialized_send_without_block_def_type_missing,
366+
Refined => unspecialized_send_without_block_def_type_refined,
367+
Null => unspecialized_send_without_block_def_type_null,
368+
}
369+
}
370+
335371
pub fn send_fallback_counter_for_method_type(method_type: crate::hir::MethodType) -> Counter {
336372
use crate::hir::MethodType::*;
337373
use crate::stats::Counter::*;
338374

339375
match method_type {
340-
Iseq => unspecialized_def_type_iseq,
341-
Cfunc => unspecialized_def_type_cfunc,
342-
Attrset => unspecialized_def_type_attrset,
343-
Ivar => unspecialized_def_type_ivar,
344-
Bmethod => unspecialized_def_type_bmethod,
345-
Zsuper => unspecialized_def_type_zsuper,
346-
Alias => unspecialized_def_type_alias,
347-
Undefined => unspecialized_def_type_undef,
348-
NotImplemented => unspecialized_def_type_not_implemented,
349-
Optimized => unspecialized_def_type_optimized,
350-
Missing => unspecialized_def_type_missing,
351-
Refined => unspecialized_def_type_refined,
352-
Null => unspecialized_def_type_null,
376+
Iseq => unspecialized_send_def_type_iseq,
377+
Cfunc => unspecialized_send_def_type_cfunc,
378+
Attrset => unspecialized_send_def_type_attrset,
379+
Ivar => unspecialized_send_def_type_ivar,
380+
Bmethod => unspecialized_send_def_type_bmethod,
381+
Zsuper => unspecialized_send_def_type_zsuper,
382+
Alias => unspecialized_send_def_type_alias,
383+
Undefined => unspecialized_send_def_type_undef,
384+
NotImplemented => unspecialized_send_def_type_not_implemented,
385+
Optimized => unspecialized_send_def_type_optimized,
386+
Missing => unspecialized_send_def_type_missing,
387+
Refined => unspecialized_send_def_type_refined,
388+
Null => unspecialized_send_def_type_null,
353389
}
354390
}
355391

0 commit comments

Comments
 (0)