Skip to content

Commit a334077

Browse files
k0kubunmaximecb
andauthored
YJIT: Make compiled_* stats available by default (ruby#8379)
* YJIT: Make compiled_* stats available by default * Update comment about default counters [ci skip] Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> --------- Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
1 parent dee383b commit a334077

3 files changed

Lines changed: 30 additions & 18 deletions

File tree

yjit/src/asm/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::core::IseqPayload;
66
use crate::core::for_each_off_stack_iseq_payload;
77
use crate::core::for_each_on_stack_iseq_payload;
88
use crate::invariants::rb_yjit_tracing_invalidate_all;
9+
use crate::stats::incr_counter;
910
use crate::virtualmem::WriteError;
1011

1112
#[cfg(feature = "disasm")]
@@ -652,7 +653,7 @@ impl CodeBlock {
652653
ocb.unwrap().freed_pages = new_freed_pages;
653654
assert_eq!(1, Rc::strong_count(&old_freed_pages)); // will deallocate
654655

655-
CodegenGlobals::incr_code_gc_count();
656+
incr_counter!(code_gc_count);
656657
}
657658

658659
pub fn inline(&self) -> bool {

yjit/src/codegen.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ pub enum JCCKinds {
249249

250250
#[inline(always)]
251251
fn gen_counter_incr(asm: &mut Assembler, counter: Counter) {
252+
// Assert that default counters are not incremented by generated code as this would impact performance
253+
assert!(!DEFAULT_COUNTERS.contains(&counter), "gen_counter_incr incremented {:?}", counter);
254+
252255
if get_option!(gen_stats) {
253256
asm.comment(&format!("increment counter {}", counter.get_name()));
254257
let ptr = get_counter_ptr(&counter.get_name());
@@ -8581,9 +8584,6 @@ pub struct CodegenGlobals {
85818584

85828585
/// Page indexes for outlined code that are not associated to any ISEQ.
85838586
ocb_pages: Vec<usize>,
8584-
8585-
/// How many times code GC has been executed.
8586-
code_gc_count: usize,
85878587
}
85888588

85898589
/// For implementing global code invalidation. A position in the inline
@@ -8679,7 +8679,6 @@ impl CodegenGlobals {
86798679
global_inval_patches: Vec::new(),
86808680
method_codegen_table: HashMap::new(),
86818681
ocb_pages,
8682-
code_gc_count: 0,
86838682
};
86848683

86858684
// Register the method codegen functions
@@ -8841,14 +8840,6 @@ impl CodegenGlobals {
88418840
pub fn get_ocb_pages() -> &'static Vec<usize> {
88428841
&CodegenGlobals::get_instance().ocb_pages
88438842
}
8844-
8845-
pub fn incr_code_gc_count() {
8846-
CodegenGlobals::get_instance().code_gc_count += 1;
8847-
}
8848-
8849-
pub fn get_code_gc_count() -> usize {
8850-
CodegenGlobals::get_instance().code_gc_count
8851-
}
88528843
}
88538844

88548845
#[cfg(test)]

yjit/src/stats.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ macro_rules! make_counters {
163163
}
164164
}
165165

166+
/// The list of counters that are available without --yjit-stats.
167+
/// They are incremented only by `incr_counter!` and don't use `gen_counter_incr`.
168+
pub const DEFAULT_COUNTERS: [Counter; 6] = [
169+
Counter::code_gc_count,
170+
Counter::compiled_iseq_entry,
171+
Counter::compiled_iseq_count,
172+
Counter::compiled_blockid_count,
173+
Counter::compiled_block_count,
174+
Counter::compiled_branch_count,
175+
];
176+
166177
/// Macro to increase a counter by name and count
167178
macro_rules! incr_counter_by {
168179
// Unsafe is ok here because options are initialized
@@ -424,6 +435,8 @@ make_counters! {
424435
// executable memory, so this should be 0.
425436
exec_mem_non_bump_alloc,
426437

438+
code_gc_count,
439+
427440
num_gc_obj_refs,
428441

429442
num_send,
@@ -571,9 +584,6 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE {
571584
// Live pages
572585
hash_aset_usize!(hash, "live_page_count", cb.num_mapped_pages() - freed_page_count);
573586

574-
// Code GC count
575-
hash_aset_usize!(hash, "code_gc_count", CodegenGlobals::get_code_gc_count());
576-
577587
// Size of memory region allocated for JIT code
578588
hash_aset_usize!(hash, "code_region_size", cb.mapped_region_size());
579589

@@ -594,13 +604,23 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE {
594604
hash_aset_usize!(hash, "vm_insns_count", rb_vm_insns_count as usize);
595605
}
596606

597-
// If we're not generating stats, the hash is done
607+
// If we're not generating stats, put only default counters
598608
if !get_option!(gen_stats) {
609+
for counter in DEFAULT_COUNTERS {
610+
// Get the counter value
611+
let counter_ptr = get_counter_ptr(&counter.get_name());
612+
let counter_val = unsafe { *counter_ptr };
613+
614+
// Put counter into hash
615+
let key = rust_str_to_sym(&counter.get_name());
616+
let value = VALUE::fixnum_from_usize(counter_val as usize);
617+
unsafe { rb_hash_aset(hash, key, value); }
618+
}
619+
599620
return hash;
600621
}
601622

602623
// If the stats feature is enabled
603-
604624
unsafe {
605625
// Indicate that the complete set of stats is available
606626
rb_hash_aset(hash, rust_str_to_sym("all_stats"), Qtrue);

0 commit comments

Comments
 (0)