Skip to content

Commit e40cd39

Browse files
authored
ZJIT: Measure reading/writing locals with level > 0 (ruby#14601)
ZJIT: Measure writing to locals with level > 0
1 parent 1663e2f commit e40cd39

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

zjit.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def stats_string
6464
:vm_write_sp_count,
6565
:vm_write_locals_count,
6666
:vm_write_stack_count,
67+
:vm_write_to_parent_iseq_local_count,
68+
:vm_read_from_parent_iseq_local_count,
6769

6870
:code_region_bytes,
6971
:side_exit_count,

zjit/src/codegen.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ fn gen_defined(jit: &JITState, asm: &mut Assembler, op_type: usize, obj: VALUE,
532532
/// We generate this instruction with level=0 only when the local variable is on the heap, so we
533533
/// can't optimize the level=0 case using the SP register.
534534
fn gen_getlocal_with_ep(asm: &mut Assembler, local_ep_offset: u32, level: u32) -> lir::Opnd {
535+
if level > 0 {
536+
gen_incr_counter(asm, Counter::vm_read_from_parent_iseq_local_count);
537+
}
535538
let ep = gen_get_ep(asm, level);
536539
let offset = -(SIZEOF_VALUE_I32 * i32::try_from(local_ep_offset).unwrap_or_else(|_| panic!("Could not convert local_ep_offset {local_ep_offset} to i32")));
537540
asm.load(Opnd::mem(64, ep, offset))
@@ -541,6 +544,9 @@ fn gen_getlocal_with_ep(asm: &mut Assembler, local_ep_offset: u32, level: u32) -
541544
/// We generate this instruction with level=0 only when the local variable is on the heap, so we
542545
/// can't optimize the level=0 case using the SP register.
543546
fn gen_setlocal_with_ep(asm: &mut Assembler, val: Opnd, val_type: Type, local_ep_offset: u32, level: u32) {
547+
if level > 0 {
548+
gen_incr_counter(asm, Counter::vm_write_to_parent_iseq_local_count);
549+
}
544550
let ep = gen_get_ep(asm, level);
545551

546552
// When we've proved that we're writing an immediate,

zjit/src/stats.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ make_counters! {
156156
vm_write_sp_count,
157157
vm_write_locals_count,
158158
vm_write_stack_count,
159+
vm_write_to_parent_iseq_local_count,
160+
vm_read_from_parent_iseq_local_count,
161+
// TODO(max): Implement
162+
// vm_reify_stack_count,
159163
}
160164

161165
/// Increase a counter by a specified amount

0 commit comments

Comments
 (0)