@@ -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 , get_or_create_unoptimized_cfunc_counter_ptr } ;
17+ use crate :: stats:: Counter ;
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`].
@@ -707,8 +707,8 @@ pub enum Insn {
707707 /// Increment a counter in ZJIT stats
708708 IncrCounter ( Counter ) ,
709709
710- /// Increment a counter in ZJIT stats for the given unoptimized C function
711- CountUnoptimizedCFunc { signature : String , counter_ptr : * mut u64 } ,
710+ /// Increment a counter in ZJIT stats for the given counter pointer
711+ IncrDynamicCounter { counter_ptr : * mut u64 } ,
712712
713713 /// Equivalent of RUBY_VM_CHECK_INTS. Automatically inserted by the compiler before jumps and
714714 /// return instructions.
@@ -723,7 +723,7 @@ impl Insn {
723723 | Insn :: IfTrue { .. } | Insn :: IfFalse { .. } | Insn :: EntryPoint { .. } | Insn :: Return { .. }
724724 | Insn :: PatchPoint { .. } | Insn :: SetIvar { .. } | Insn :: ArrayExtend { .. }
725725 | Insn :: ArrayPush { .. } | Insn :: SideExit { .. } | Insn :: SetGlobal { .. }
726- | Insn :: SetLocal { .. } | Insn :: Throw { .. } | Insn :: IncrCounter ( _) | Insn :: CountUnoptimizedCFunc { .. }
726+ | Insn :: SetLocal { .. } | Insn :: Throw { .. } | Insn :: IncrCounter ( _) | Insn :: IncrDynamicCounter { .. }
727727 | Insn :: CheckInterrupts { .. } | Insn :: GuardBlockParamProxy { .. } => false ,
728728 _ => true ,
729729 }
@@ -975,7 +975,7 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
975975 }
976976 Ok ( ( ) )
977977 } ,
978- Insn :: CountUnoptimizedCFunc { signature , .. } => write ! ( f, "CountUnoptimizedCFunc {}" , signature ) ,
978+ Insn :: IncrDynamicCounter { .. } => write ! ( f, "IncrDynamicCounter" ) ,
979979 Insn :: Snapshot { state } => write ! ( f, "Snapshot {}" , state. print( self . ptr_map) ) ,
980980 Insn :: Defined { op_type, v, .. } => {
981981 // op_type (enum defined_type) printing logic from iseq.c.
@@ -1380,7 +1380,7 @@ impl Function {
13801380 | SideExit { ..}
13811381 | EntryPoint { ..}
13821382 | LoadPC
1383- | CountUnoptimizedCFunc { ..}
1383+ | IncrDynamicCounter { ..}
13841384 | IncrCounter ( _) ) => result. clone ( ) ,
13851385 & Snapshot { state : FrameState { iseq, insn_idx, pc, ref stack, ref locals } } =>
13861386 Snapshot {
@@ -1530,7 +1530,7 @@ impl Function {
15301530 | Insn :: IfTrue { .. } | Insn :: IfFalse { .. } | Insn :: Return { .. } | Insn :: Throw { .. }
15311531 | Insn :: PatchPoint { .. } | Insn :: SetIvar { .. } | Insn :: ArrayExtend { .. }
15321532 | Insn :: ArrayPush { .. } | Insn :: SideExit { .. } | Insn :: SetLocal { .. } | Insn :: IncrCounter ( _)
1533- | Insn :: CheckInterrupts { .. } | Insn :: GuardBlockParamProxy { .. } | Insn :: CountUnoptimizedCFunc { .. } =>
1533+ | Insn :: CheckInterrupts { .. } | Insn :: GuardBlockParamProxy { .. } | Insn :: IncrDynamicCounter { .. } =>
15341534 panic ! ( "Cannot infer type of instruction with no output: {}" , self . insns[ insn. 0 ] ) ,
15351535 Insn :: Const { val : Const :: Value ( val) } => Type :: from_value ( * val) ,
15361536 Insn :: Const { val : Const :: CBool ( val) } => Type :: from_cbool ( * val) ,
@@ -2284,10 +2284,12 @@ impl Function {
22842284 let called_id = unsafe { ( * cme) . called_id } ;
22852285 let class_name = get_class_name ( owner) ;
22862286 let method_name = called_id. contents_lossy ( ) ;
2287- let signature = format ! ( "{}#{}" , class_name, method_name) ;
2288- let counter_ptr = get_or_create_unoptimized_cfunc_counter_ptr ( signature. clone ( ) ) ;
2287+ let qualified_method_name = format ! ( "{}#{}" , class_name, method_name) ;
2288+ let unoptimized_cfunc_counter_pointers = ZJITState :: get_unoptimized_cfunc_counter_pointers ( ) ;
2289+ let counter_ptr = unoptimized_cfunc_counter_pointers. entry ( qualified_method_name. clone ( ) ) . or_insert_with ( || Box :: new ( 0 ) ) ;
2290+ let counter_ptr = & mut * * counter_ptr as * mut u64 ;
22892291
2290- self . push_insn ( block, Insn :: CountUnoptimizedCFunc { signature , counter_ptr } ) ;
2292+ self . push_insn ( block, Insn :: IncrDynamicCounter { counter_ptr } ) ;
22912293 }
22922294 _ => { }
22932295 }
@@ -2435,7 +2437,7 @@ impl Function {
24352437 | & Insn :: GetLocal { .. }
24362438 | & Insn :: PutSpecialObject { .. }
24372439 | & Insn :: IncrCounter ( _)
2438- | & Insn :: CountUnoptimizedCFunc { .. } =>
2440+ | & Insn :: IncrDynamicCounter { .. } =>
24392441 { }
24402442 & Insn :: PatchPoint { state, .. }
24412443 | & Insn :: CheckInterrupts { state }
@@ -9502,7 +9504,7 @@ mod opt_tests {
95029504 bb2(v6:BasicObject):
95039505 v10:Fixnum[1] = Const Value(1)
95049506 v11:Fixnum[0] = Const Value(0)
9505- CountUnoptimizedCFunc Kernel#itself
9507+ IncrDynamicCounter
95069508 v13:BasicObject = SendWithoutBlock v10, :itself, v11
95079509 CheckInterrupts
95089510 Return v13
@@ -10341,7 +10343,7 @@ mod opt_tests {
1034110343 Jump bb2(v4)
1034210344 bb2(v6:BasicObject):
1034310345 v11:HashExact = NewHash
10344- CountUnoptimizedCFunc Kernel#dup
10346+ IncrDynamicCounter
1034510347 v13:BasicObject = SendWithoutBlock v11, :dup
1034610348 v15:BasicObject = SendWithoutBlock v13, :freeze
1034710349 CheckInterrupts
@@ -10365,7 +10367,7 @@ mod opt_tests {
1036510367 bb2(v6:BasicObject):
1036610368 v11:HashExact = NewHash
1036710369 v12:NilClass = Const Value(nil)
10368- CountUnoptimizedCFunc Hash#freeze
10370+ IncrDynamicCounter
1036910371 v14:BasicObject = SendWithoutBlock v11, :freeze, v12
1037010372 CheckInterrupts
1037110373 Return v14
@@ -10430,7 +10432,7 @@ mod opt_tests {
1043010432 Jump bb2(v4)
1043110433 bb2(v6:BasicObject):
1043210434 v11:ArrayExact = NewArray
10433- CountUnoptimizedCFunc Kernel#dup
10435+ IncrDynamicCounter
1043410436 v13:BasicObject = SendWithoutBlock v11, :dup
1043510437 v15:BasicObject = SendWithoutBlock v13, :freeze
1043610438 CheckInterrupts
@@ -10454,7 +10456,7 @@ mod opt_tests {
1045410456 bb2(v6:BasicObject):
1045510457 v11:ArrayExact = NewArray
1045610458 v12:NilClass = Const Value(nil)
10457- CountUnoptimizedCFunc Array#freeze
10459+ IncrDynamicCounter
1045810460 v14:BasicObject = SendWithoutBlock v11, :freeze, v12
1045910461 CheckInterrupts
1046010462 Return v14
@@ -10520,7 +10522,7 @@ mod opt_tests {
1052010522 bb2(v6:BasicObject):
1052110523 v10:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
1052210524 v12:StringExact = StringCopy v10
10523- CountUnoptimizedCFunc String#dup
10525+ IncrDynamicCounter
1052410526 v14:BasicObject = SendWithoutBlock v12, :dup
1052510527 v16:BasicObject = SendWithoutBlock v14, :freeze
1052610528 CheckInterrupts
@@ -10545,7 +10547,7 @@ mod opt_tests {
1054510547 v10:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
1054610548 v12:StringExact = StringCopy v10
1054710549 v13:NilClass = Const Value(nil)
10548- CountUnoptimizedCFunc String#freeze
10550+ IncrDynamicCounter
1054910551 v15:BasicObject = SendWithoutBlock v12, :freeze, v13
1055010552 CheckInterrupts
1055110553 Return v15
@@ -10611,7 +10613,7 @@ mod opt_tests {
1061110613 bb2(v6:BasicObject):
1061210614 v10:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
1061310615 v12:StringExact = StringCopy v10
10614- CountUnoptimizedCFunc String#dup
10616+ IncrDynamicCounter
1061510617 v14:BasicObject = SendWithoutBlock v12, :dup
1061610618 v16:BasicObject = SendWithoutBlock v14, :-@
1061710619 CheckInterrupts
@@ -10741,7 +10743,7 @@ mod opt_tests {
1074110743 bb2(v8:BasicObject, v9:BasicObject):
1074210744 v13:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
1074310745 v25:BasicObject = GuardTypeNot v9, String
10744- CountUnoptimizedCFunc Array#to_s
10746+ IncrDynamicCounter
1074510747 v26:BasicObject = SendWithoutBlock v9, :to_s
1074610748 v17:String = AnyToString v9, str: v26
1074710749 v19:StringExact = StringConcat v13, v17
0 commit comments