Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion zjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::invariants::{
};
use crate::gc::{append_gc_offsets, get_or_create_iseq_payload, get_or_create_iseq_payload_ptr, IseqCodePtrs, IseqPayload, IseqStatus};
use crate::state::ZJITState;
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};
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_without_block_fallback_counter_for_optimized_method_type, send_fallback_counter_ptr_for_opcode, CompileError};
use crate::stats::{counter_ptr, with_time_stat, Counter, Counter::{compile_time_ns, exit_compile_error}};
use crate::{asm::CodeBlock, cruby::*, options::debug, virtualmem::CodePtr};
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, SP};
Expand Down Expand Up @@ -1741,6 +1741,9 @@ fn gen_incr_send_fallback_counter(asm: &mut Assembler, reason: SendFallbackReaso
SendWithoutBlockNotOptimizedMethodType(method_type) => {
gen_incr_counter(asm, send_without_block_fallback_counter_for_method_type(method_type));
}
SendWithoutBlockNotOptimizedOptimizedMethodType(method_type) => {
gen_incr_counter(asm, send_without_block_fallback_counter_for_optimized_method_type(method_type));
}
SendNotOptimizedMethodType(method_type) => {
gen_incr_counter(asm, send_fallback_counter_for_method_type(method_type));
}
Expand Down
27 changes: 27 additions & 0 deletions zjit/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,28 @@ impl From<u32> for MethodType {
}
}

#[derive(Debug, Clone, Copy)]
pub enum OptimizedMethodType {
Send,
Call,
BlockCall,
StructAref,
StructAset,
}

impl From<u32> for OptimizedMethodType {
fn from(value: u32) -> Self {
match value {
OPTIMIZED_METHOD_TYPE_SEND => OptimizedMethodType::Send,
OPTIMIZED_METHOD_TYPE_CALL => OptimizedMethodType::Call,
OPTIMIZED_METHOD_TYPE_BLOCK_CALL => OptimizedMethodType::BlockCall,
OPTIMIZED_METHOD_TYPE_STRUCT_AREF => OptimizedMethodType::StructAref,
OPTIMIZED_METHOD_TYPE_STRUCT_ASET => OptimizedMethodType::StructAset,
_ => unreachable!("unknown send_without_block optimized method type: {}", value),
}
}
}

impl std::fmt::Display for SideExitReason {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Expand Down Expand Up @@ -539,6 +561,7 @@ pub enum SendFallbackReason {
SendWithoutBlockCfuncNotVariadic,
SendWithoutBlockCfuncArrayVariadic,
SendWithoutBlockNotOptimizedMethodType(MethodType),
SendWithoutBlockNotOptimizedOptimizedMethodType(OptimizedMethodType),
SendWithoutBlockDirectTooManyArgs,
SendPolymorphic,
SendNoProfiles,
Expand Down Expand Up @@ -2335,6 +2358,10 @@ impl Function {
}
self.push_insn(block, Insn::SetIvar { self_val: recv, id, val, state });
self.make_equal_to(insn_id, val);
} else if def_type == VM_METHOD_TYPE_OPTIMIZED {
let opt_type = unsafe { get_cme_def_body_optimized_type(cme) };
self.set_dynamic_send_reason(insn_id, SendWithoutBlockNotOptimizedOptimizedMethodType(OptimizedMethodType::from(opt_type)));
self.push_insn_id(block, insn_id); continue;
} else {
self.set_dynamic_send_reason(insn_id, SendWithoutBlockNotOptimizedMethodType(MethodType::from(def_type)));
self.push_insn_id(block, insn_id); continue;
Expand Down
23 changes: 23 additions & 0 deletions zjit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ make_counters! {
send_fallback_send_without_block_cfunc_not_variadic,
send_fallback_send_without_block_cfunc_array_variadic,
send_fallback_send_without_block_not_optimized_method_type,
send_fallback_send_without_block_not_optimized_optimized_method_type,
send_fallback_send_without_block_direct_too_many_args,
send_fallback_send_polymorphic,
send_fallback_send_no_profiles,
Expand Down Expand Up @@ -227,6 +228,13 @@ make_counters! {
unspecialized_send_without_block_def_type_refined,
unspecialized_send_without_block_def_type_null,

// Method call optimized_type related to send without block fallback to dynamic dispatch
unspecialized_send_without_block_def_type_optimized_send,
unspecialized_send_without_block_def_type_optimized_call,
unspecialized_send_without_block_def_type_optimized_block_call,
unspecialized_send_without_block_def_type_optimized_struct_aref,
unspecialized_send_without_block_def_type_optimized_struct_aset,

// Method call def_type related to send fallback to dynamic dispatch
unspecialized_send_def_type_iseq,
unspecialized_send_def_type_cfunc,
Expand Down Expand Up @@ -388,6 +396,8 @@ pub fn send_fallback_counter(reason: crate::hir::SendFallbackReason) -> Counter
SendWithoutBlockCfuncNotVariadic => send_fallback_send_without_block_cfunc_not_variadic,
SendWithoutBlockCfuncArrayVariadic => send_fallback_send_without_block_cfunc_array_variadic,
SendWithoutBlockNotOptimizedMethodType(_) => send_fallback_send_without_block_not_optimized_method_type,
SendWithoutBlockNotOptimizedOptimizedMethodType(_)
=> send_fallback_send_without_block_not_optimized_optimized_method_type,
SendWithoutBlockDirectTooManyArgs => send_fallback_send_without_block_direct_too_many_args,
SendPolymorphic => send_fallback_send_polymorphic,
SendNoProfiles => send_fallback_send_no_profiles,
Expand Down Expand Up @@ -419,6 +429,19 @@ pub fn send_without_block_fallback_counter_for_method_type(method_type: crate::h
}
}

pub fn send_without_block_fallback_counter_for_optimized_method_type(method_type: crate::hir::OptimizedMethodType) -> Counter {
use crate::hir::OptimizedMethodType::*;
use crate::stats::Counter::*;

match method_type {
Send => unspecialized_send_without_block_def_type_optimized_send,
Call => unspecialized_send_without_block_def_type_optimized_call,
BlockCall => unspecialized_send_without_block_def_type_optimized_block_call,
StructAref => unspecialized_send_without_block_def_type_optimized_struct_aref,
StructAset => unspecialized_send_without_block_def_type_optimized_struct_aset,
}
}

pub fn send_fallback_counter_for_method_type(method_type: crate::hir::MethodType) -> Counter {
use crate::hir::MethodType::*;
use crate::stats::Counter::*;
Expand Down
Loading