diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2023-10-18 19:46:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-18 23:46:35 +0000 |
commit | d2b0c9da2e0148c8c12ca58e21c482c1e66c2358 (patch) | |
tree | 7f0ae18acae1a6d389b449498175cdf82bd66e20 | |
parent | 0ac6fb225d15cbcd35b8122b151a17eaa92fafaf (diff) | |
download | ruby-d2b0c9da2e0148c8c12ca58e21c482c1e66c2358.tar.gz |
YJIT: Add a live ISeq counter
It's an estimator for application size and could be used as a
compilation heuristic later.
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
-rw-r--r-- | common.mk | 1 | ||||
-rw-r--r-- | compile.c | 6 | ||||
-rw-r--r-- | iseq.c | 2 | ||||
-rw-r--r-- | yjit.h | 1 | ||||
-rw-r--r-- | yjit.rb | 1 | ||||
-rw-r--r-- | yjit/src/stats.rs | 6 |
6 files changed, 17 insertions, 0 deletions
@@ -3429,6 +3429,7 @@ compile.$(OBJEXT): {$(VPATH)}vm_callinfo.h compile.$(OBJEXT): {$(VPATH)}vm_core.h compile.$(OBJEXT): {$(VPATH)}vm_debug.h compile.$(OBJEXT): {$(VPATH)}vm_opts.h +compile.$(OBJEXT): {$(VPATH)}yjit.h complex.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h complex.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h complex.$(OBJEXT): $(CCAN_DIR)/list/list.h @@ -39,6 +39,7 @@ #include "vm_core.h" #include "vm_callinfo.h" #include "vm_debug.h" +#include "yjit.h" #include "builtin.h" #include "insns.inc" @@ -1019,6 +1020,11 @@ rb_iseq_translate_threaded_code(rb_iseq_t *iseq) } FL_SET((VALUE)iseq, ISEQ_TRANSLATED); #endif + +#if USE_YJIT + rb_yjit_live_iseq_count++; +#endif + return COMPILE_OK; } @@ -168,6 +168,8 @@ rb_iseq_free(const rb_iseq_t *iseq) rb_rjit_free_iseq(iseq); /* Notify RJIT */ #if USE_YJIT rb_yjit_iseq_free(body->yjit_payload); + RUBY_ASSERT(rb_yjit_live_iseq_count > 0); + rb_yjit_live_iseq_count--; #endif ruby_xfree((void *)body->iseq_encoded); ruby_xfree((void *)body->insns_info.body); @@ -27,6 +27,7 @@ // Expose these as declarations since we are building YJIT. extern uint64_t rb_yjit_call_threshold; extern uint64_t rb_yjit_cold_threshold; +extern uint64_t rb_yjit_live_iseq_count; void rb_yjit_incr_counter(const char *counter_name); bool rb_yjit_enabled_p(void); bool rb_yjit_compile_new_iseqs(void); @@ -316,6 +316,7 @@ module RubyVM::YJIT out.puts "bindings_allocations: " + format_number(13, stats[:binding_allocations]) out.puts "bindings_set: " + format_number(13, stats[:binding_set]) out.puts "compilation_failure: " + format_number(13, compilation_failure) if compilation_failure != 0 + out.puts "live_iseq_count: " + format_number(13, stats[:live_iseq_count]) out.puts "compiled_iseq_entry: " + format_number(13, stats[:compiled_iseq_entry]) out.puts "cold_iseq_entry: " + format_number_pct(13, stats[:cold_iseq_entry], stats[:compiled_iseq_entry] + stats[:cold_iseq_entry]) out.puts "compiled_iseq_count: " + format_number(13, stats[:compiled_iseq_count]) diff --git a/yjit/src/stats.rs b/yjit/src/stats.rs index 7d44b388cd..d35cdc22a4 100644 --- a/yjit/src/stats.rs +++ b/yjit/src/stats.rs @@ -14,6 +14,10 @@ use crate::cruby::*; use crate::options::*; use crate::yjit::yjit_enabled_p; +/// A running total of how many ISeqs are in the system. +#[no_mangle] +pub static mut rb_yjit_live_iseq_count: u64 = 0; + /// A middleware to count Rust-allocated bytes as yjit_alloc_size. #[global_allocator] static GLOBAL_ALLOCATOR: StatsAlloc = StatsAlloc { alloc_size: AtomicUsize::new(0) }; @@ -635,6 +639,8 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE { // VM instructions count hash_aset_usize!(hash, "vm_insns_count", rb_vm_insns_count as usize); + + hash_aset_usize!(hash, "live_iseq_count", rb_yjit_live_iseq_count as usize); } // If we're not generating stats, put only default counters |