From cd97976328204263c464cf6846e9bafe6424da15 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Wed, 18 Jan 2023 11:08:55 -0500 Subject: Add stats so we can keep track of x86 rel32 vs register calls (#7142) * Add stats so we can keep track of x86 rel32 vs register calls To know if we get that "prime real estate" as Alan put it. * Fix bug pointed by Alan --- yjit.rb | 5 +++++ yjit/src/asm/x86_64/mod.rs | 4 ++++ yjit/src/stats.rs | 3 +++ 3 files changed, 12 insertions(+) diff --git a/yjit.rb b/yjit.rb index 062784f564..0079d8d895 100644 --- a/yjit.rb +++ b/yjit.rb @@ -253,6 +253,11 @@ module RubyVM::YJIT # Number of failed compiler invocations compilation_failure = stats[:compilation_failure] + if stats[:x86_call_rel32] != 0 || stats[:x86_call_reg] != 0 + $stderr.puts "x86_call_rel32: " + ("%10d" % stats[:x86_call_rel32]) + $stderr.puts "x86_call_reg: " + ("%10d" % stats[:x86_call_reg]) + end + $stderr.puts "bindings_allocations: " + ("%10d" % stats[:binding_allocations]) $stderr.puts "bindings_set: " + ("%10d" % stats[:binding_set]) $stderr.puts "compilation_failure: " + ("%10d" % compilation_failure) if compilation_failure != 0 diff --git a/yjit/src/asm/x86_64/mod.rs b/yjit/src/asm/x86_64/mod.rs index 1a0cb9cae7..67bb5d1ffb 100644 --- a/yjit/src/asm/x86_64/mod.rs +++ b/yjit/src/asm/x86_64/mod.rs @@ -690,6 +690,8 @@ pub fn call_rel32(cb: &mut CodeBlock, rel32: i32) { /// call - Call a pointer, encode with a 32-bit offset if possible pub fn call_ptr(cb: &mut CodeBlock, scratch_opnd: X86Opnd, dst_ptr: *const u8) { if let X86Opnd::Reg(_scratch_reg) = scratch_opnd { + use crate::stats::{incr_counter}; + // Pointer to the end of this call instruction let end_ptr = cb.get_ptr(cb.write_pos + 5); @@ -698,11 +700,13 @@ pub fn call_ptr(cb: &mut CodeBlock, scratch_opnd: X86Opnd, dst_ptr: *const u8) { // If the offset fits in 32-bit if rel64 >= i32::MIN.into() && rel64 <= i32::MAX.into() { + incr_counter!(x86_call_rel32); call_rel32(cb, rel64.try_into().unwrap()); return; } // Move the pointer into the scratch register and call + incr_counter!(x86_call_reg); mov(cb, scratch_opnd, const_ptr_opnd(dst_ptr)); call(cb, scratch_opnd); } else { diff --git a/yjit/src/stats.rs b/yjit/src/stats.rs index 8fc9245364..2145cdf923 100644 --- a/yjit/src/stats.rs +++ b/yjit/src/stats.rs @@ -299,6 +299,9 @@ make_counters! { exec_mem_non_bump_alloc, num_gc_obj_refs, + + x86_call_rel32, + x86_call_reg, } //=========================================================================== -- cgit v1.2.1