@@ -14,7 +14,7 @@ use std::{
1414use crate :: hir_type:: { Type , types} ;
1515use crate :: bitset:: BitSet ;
1616use crate :: profile:: { TypeDistributionSummary , ProfiledType } ;
17- use crate :: stats:: Counter ;
17+ use crate :: stats:: { Counter , get_or_create_unoptimized_cfunc_counter_ptr } ;
1818
1919/// An index of an [`Insn`] in a [`Function`]. This is a popular
2020/// type since this effectively acts as a pointer to an [`Insn`].
@@ -698,7 +698,7 @@ pub enum Insn {
698698 IncrCounter ( Counter ) ,
699699
700700 /// Increment a counter in ZJIT stats for the given C function
701- CountUnoptimizedCFunc { cme : * const rb_callable_method_entry_struct } ,
701+ CountUnoptimizedCFunc { signature : String , counter_ptr : * mut u64 } ,
702702
703703 /// Equivalent of RUBY_VM_CHECK_INTS. Automatically inserted by the compiler before jumps and
704704 /// return instructions.
@@ -959,7 +959,7 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
959959 }
960960 Ok ( ( ) )
961961 } ,
962- Insn :: CountUnoptimizedCFunc { .. } => write ! ( f, "CountUnoptimizedCFunc" ) ,
962+ Insn :: CountUnoptimizedCFunc { signature , counter_ptr : _ } => write ! ( f, "CountUnoptimizedCFunc {}" , signature ) ,
963963 Insn :: Snapshot { state } => write ! ( f, "Snapshot {}" , state. print( self . ptr_map) ) ,
964964 Insn :: Defined { op_type, v, .. } => {
965965 // op_type (enum defined_type) printing logic from iseq.c.
@@ -2219,7 +2219,18 @@ impl Function {
22192219 match reduce_to_ccall ( self , block, recv_type, send, insn_id) {
22202220 Ok ( ( ) ) => continue ,
22212221 Err ( Some ( cme) ) => {
2222- self . push_insn ( block, Insn :: CountUnoptimizedCFunc { cme } ) ;
2222+ // Extract class and method from CME to build signature
2223+ let class = unsafe { ( * cme) . owner } ;
2224+ let method = unsafe { ( * cme) . called_id } ;
2225+
2226+ let class_name = get_class_name ( class) ;
2227+ let method_name = method. contents_lossy ( ) ;
2228+ let signature = format ! ( "{}#{}" , class_name, method_name) ;
2229+
2230+ // Get or create counter pointer for this signature
2231+ let counter_ptr = get_or_create_unoptimized_cfunc_counter_ptr ( signature. clone ( ) ) ;
2232+
2233+ self . push_insn ( block, Insn :: CountUnoptimizedCFunc { signature, counter_ptr } ) ;
22232234 }
22242235 _ => { }
22252236 }
@@ -8088,7 +8099,7 @@ mod opt_tests {
80888099 bb0(v0:BasicObject):
80898100 v4:Fixnum[1] = Const Value(1)
80908101 v5:Fixnum[0] = Const Value(0)
8091- CountUnoptimizedCFunc
8102+ CountUnoptimizedCFunc Unknown#itself
80928103 v7:BasicObject = SendWithoutBlock v4, :itself, v5
80938104 CheckInterrupts
80948105 Return v7
@@ -8726,7 +8737,7 @@ mod opt_tests {
87268737 fn test@<compiled>:2:
87278738 bb0(v0:BasicObject):
87288739 v5:HashExact = NewHash
8729- CountUnoptimizedCFunc
8740+ CountUnoptimizedCFunc Unknown#dup
87308741 v7:BasicObject = SendWithoutBlock v5, :dup
87318742 v9:BasicObject = SendWithoutBlock v7, :freeze
87328743 CheckInterrupts
@@ -8744,7 +8755,7 @@ mod opt_tests {
87448755 bb0(v0:BasicObject):
87458756 v5:HashExact = NewHash
87468757 v6:NilClass = Const Value(nil)
8747- CountUnoptimizedCFunc
8758+ CountUnoptimizedCFunc Hash#freeze
87488759 v8:BasicObject = SendWithoutBlock v5, :freeze, v6
87498760 CheckInterrupts
87508761 Return v8
@@ -8791,7 +8802,7 @@ mod opt_tests {
87918802 fn test@<compiled>:2:
87928803 bb0(v0:BasicObject):
87938804 v5:ArrayExact = NewArray
8794- CountUnoptimizedCFunc
8805+ CountUnoptimizedCFunc Unknown#dup
87958806 v7:BasicObject = SendWithoutBlock v5, :dup
87968807 v9:BasicObject = SendWithoutBlock v7, :freeze
87978808 CheckInterrupts
@@ -8809,7 +8820,7 @@ mod opt_tests {
88098820 bb0(v0:BasicObject):
88108821 v5:ArrayExact = NewArray
88118822 v6:NilClass = Const Value(nil)
8812- CountUnoptimizedCFunc
8823+ CountUnoptimizedCFunc Array#freeze
88138824 v8:BasicObject = SendWithoutBlock v5, :freeze, v6
88148825 CheckInterrupts
88158826 Return v8
@@ -8857,7 +8868,7 @@ mod opt_tests {
88578868 bb0(v0:BasicObject):
88588869 v4:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
88598870 v6:StringExact = StringCopy v4
8860- CountUnoptimizedCFunc
8871+ CountUnoptimizedCFunc String#dup
88618872 v8:BasicObject = SendWithoutBlock v6, :dup
88628873 v10:BasicObject = SendWithoutBlock v8, :freeze
88638874 CheckInterrupts
@@ -8876,7 +8887,7 @@ mod opt_tests {
88768887 v4:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
88778888 v6:StringExact = StringCopy v4
88788889 v7:NilClass = Const Value(nil)
8879- CountUnoptimizedCFunc
8890+ CountUnoptimizedCFunc String#freeze
88808891 v9:BasicObject = SendWithoutBlock v6, :freeze, v7
88818892 CheckInterrupts
88828893 Return v9
@@ -8924,7 +8935,7 @@ mod opt_tests {
89248935 bb0(v0:BasicObject):
89258936 v4:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
89268937 v6:StringExact = StringCopy v4
8927- CountUnoptimizedCFunc
8938+ CountUnoptimizedCFunc String#dup
89288939 v8:BasicObject = SendWithoutBlock v6, :dup
89298940 v10:BasicObject = SendWithoutBlock v8, :-@
89308941 CheckInterrupts
@@ -9024,7 +9035,7 @@ mod opt_tests {
90249035 bb0(v0:BasicObject, v1:BasicObject):
90259036 v5:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
90269037 v17:BasicObject = GuardTypeNot v1, String
9027- CountUnoptimizedCFunc
9038+ CountUnoptimizedCFunc Array#to_s
90289039 v18:BasicObject = SendWithoutBlock v1, :to_s
90299040 v9:String = AnyToString v1, str: v18
90309041 v11:StringExact = StringConcat v5, v9
0 commit comments