Skip to content

Commit

Permalink
Add counters to measure branch_stub_hit instances on old ISEQs
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Sep 12, 2023
1 parent 160e044 commit 6ebb200
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ def _print_stats(out: $stderr) # :nodoc:
if stats[:compiled_blockid_count] != 0
out.puts "versions_per_block: " + ("%10.3f" % stats[:compiled_block_count].fdiv(stats[:compiled_blockid_count]))
end
out.puts "branch_stub_hit: " + ("%10d" % stats[:branch_stub_hit])
out.puts "branch_stub_hit_old: " + ("%10d" % stats[:branch_stub_hit_old])

out.puts "compiled_branch_count: " + ("%10d" % stats[:compiled_branch_count])
out.puts "compile_time_ms: " + ("%10d" % stats[:compile_time_ns].div(1000 * 1000))
out.puts "block_next_count: " + ("%10d" % stats[:block_next_count])
Expand Down
16 changes: 16 additions & 0 deletions yjit/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ pub struct IseqPayload {
// Blocks that are invalidated but are not yet deallocated.
// The code GC will free them later.
pub dead_blocks: Vec<BlockRef>,

// How many blocks were compiled when we last hit a branch stub
// for this ISEQ
pub block_count_last_stub: u64,
}

impl IseqPayload {
Expand Down Expand Up @@ -1908,6 +1912,7 @@ c_callable! {
/// Called by the generated code when a branch stub is executed
/// Triggers compilation of branches and code patching
fn branch_stub_hit_body(branch_ptr: *const c_void, target_idx: u32, ec: EcPtr) -> *const u8 {
incr_counter!(branch_stub_hit);
if get_option!(dump_insns) {
println!("branch_stub_hit");
}
Expand All @@ -1925,6 +1930,17 @@ fn branch_stub_hit_body(branch_ptr: *const c_void, target_idx: u32, ec: EcPtr) -
let mut branch = branch_rc.borrow_mut();
let branch_size_on_entry = branch.code_size();

// Compute how many blocks were compiled since the last branch stub was hit
let compiled_block_count = unsafe { crate::stats::COUNTERS.compiled_block_count };
let payload = get_iseq_payload(branch.block.borrow().blockid.iseq).unwrap();
let last_count = payload.block_count_last_stub;
let num_blocks_since = if payload.block_count_last_stub != 0 { compiled_block_count - last_count } else { 0 };
payload.block_count_last_stub = compiled_block_count;

if num_blocks_since > 20000 {
incr_counter!(branch_stub_hit_old);
}

let target_idx: usize = target_idx.as_usize();
let target = branch.targets[target_idx].as_ref().unwrap();
let target_id = target.id;
Expand Down
2 changes: 2 additions & 0 deletions yjit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ make_counters! {
defer_count,
freed_iseq_count,

branch_stub_hit,
branch_stub_hit_old,
exit_from_branch_stub,

invalidation_count,
Expand Down

0 comments on commit 6ebb200

Please sign in to comment.