@@ -417,7 +417,7 @@ impl ProfiledType {
417417
418418/// Per-instruction profile entry, stored sparsely in a sorted Vec.
419419#[ derive( Debug ) ]
420- struct ProfileEntry {
420+ pub struct ProfileEntry {
421421 /// YARV instruction index
422422 insn_idx : u32 ,
423423 /// Type information of YARV instruction operands
@@ -426,6 +426,12 @@ struct ProfileEntry {
426426 profiles_remaining : NumProfiles ,
427427}
428428
429+ impl ProfileEntry {
430+ pub fn set_profiles_remaining ( & mut self , num_profiles : NumProfiles ) {
431+ self . profiles_remaining = num_profiles;
432+ }
433+ }
434+
429435#[ derive( Debug ) ]
430436pub struct IseqProfile {
431437 /// Sparse storage of per-instruction profile data, sorted by instruction index.
@@ -445,7 +451,7 @@ impl IseqProfile {
445451 }
446452
447453 /// Get or create a mutable profile entry for the given instruction index.
448- fn entry_mut ( & mut self , insn_idx : YarvInsnIdx ) -> & mut ProfileEntry {
454+ pub fn entry_mut ( & mut self , insn_idx : YarvInsnIdx ) -> & mut ProfileEntry {
449455 let idx = insn_idx as u32 ;
450456 match self . entries . binary_search_by_key ( & idx, |e| e. insn_idx ) {
451457 Ok ( i) => & mut self . entries [ i] ,
@@ -479,6 +485,11 @@ impl IseqProfile {
479485 pub fn profile_send_at ( & mut self , iseq : IseqPtr , insn_idx : YarvInsnIdx , sp : * const VALUE , argc : usize ) -> bool {
480486 let n = argc + 1 ; // args + receiver
481487 let entry = self . entry_mut ( insn_idx) ;
488+ // Reset profiling if the previous round already finished (stale YARV profiles).
489+ // This ensures we collect num_profiles samples of the new shapes before recompiling.
490+ if entry. profiles_remaining == 0 {
491+ entry. profiles_remaining = get_option ! ( num_profiles) ;
492+ }
482493 if entry. opnd_types . is_empty ( ) {
483494 entry. opnd_types . resize ( n, TypeDistribution :: new ( ) ) ;
484495 }
0 commit comments