Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/yjit-macos.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: YJIT macOS Arm64
name: YJIT macOS
on:
push:
branches:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zjit-macos.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ZJIT macOS Arm64
name: ZJIT macOS
on:
push:
branches:
Expand Down
22 changes: 22 additions & 0 deletions test/ruby/test_zjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,28 @@ def test = 1
}, stats: true
end

def test_reset_stats
assert_runs 'true', %q{
def test = 1
100.times { test }

# Get initial stats and verify they're non-zero
initial_stats = RubyVM::ZJIT.stats

# Reset the stats
RubyVM::ZJIT.reset_stats!

# Get stats after reset
reset_stats = RubyVM::ZJIT.stats

[
# After reset, counters should be zero or at least much smaller
# (some instructions might execute between reset and reading stats)
:zjit_insn_count.then { |s| initial_stats[s] > 0 && reset_stats[s] < initial_stats[s] },
].all?
}, stats: true
end

def test_zjit_option_uses_array_each_in_ruby
omit 'ZJIT wrongly compiles Array#each, so it is disabled for now'
assert_runs '"<internal:array>"', %q{
Expand Down
2 changes: 1 addition & 1 deletion variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ rb_alias_variable(ID name1, ID name2)
RB_VM_LOCKING() {
entry2 = rb_global_entry(name2);
if (!rb_id_table_lookup(gtbl, name1, &data1)) {
entry1 = ALLOC(struct rb_global_entry);
entry1 = ZALLOC(struct rb_global_entry);
entry1->id = name1;
rb_id_table_insert(gtbl, name1, (VALUE)entry1);
}
Expand Down
21 changes: 2 additions & 19 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,6 @@ fn gen_expandarray(
jit_guard_known_klass(
jit,
asm,
comptime_recv.class_of(),
array_opnd,
array_opnd.into(),
comptime_recv,
Expand Down Expand Up @@ -3672,7 +3671,6 @@ fn gen_equality_specialized(
jit_guard_known_klass(
jit,
asm,
unsafe { rb_cString },
a_opnd,
a_opnd.into(),
comptime_a,
Expand All @@ -3698,7 +3696,6 @@ fn gen_equality_specialized(
jit_guard_known_klass(
jit,
asm,
unsafe { rb_cString },
b_opnd,
b_opnd.into(),
comptime_b,
Expand Down Expand Up @@ -3795,7 +3792,6 @@ fn gen_opt_aref(
jit_guard_known_klass(
jit,
asm,
unsafe { rb_cArray },
recv_opnd,
recv_opnd.into(),
comptime_recv,
Expand Down Expand Up @@ -3835,7 +3831,6 @@ fn gen_opt_aref(
jit_guard_known_klass(
jit,
asm,
unsafe { rb_cHash },
recv_opnd,
recv_opnd.into(),
comptime_recv,
Expand Down Expand Up @@ -3888,7 +3883,6 @@ fn gen_opt_aset(
jit_guard_known_klass(
jit,
asm,
unsafe { rb_cArray },
recv,
recv.into(),
comptime_recv,
Expand All @@ -3900,7 +3894,6 @@ fn gen_opt_aset(
jit_guard_known_klass(
jit,
asm,
unsafe { rb_cInteger },
key,
key.into(),
comptime_key,
Expand Down Expand Up @@ -3933,7 +3926,6 @@ fn gen_opt_aset(
jit_guard_known_klass(
jit,
asm,
unsafe { rb_cHash },
recv,
recv.into(),
comptime_recv,
Expand Down Expand Up @@ -4853,7 +4845,6 @@ fn gen_opt_new(
perf_call!("opt_new: ", jit_guard_known_klass(
jit,
asm,
comptime_recv_klass,
recv,
recv.into(),
comptime_recv,
Expand Down Expand Up @@ -4924,13 +4915,13 @@ fn gen_jump(
fn jit_guard_known_klass(
jit: &mut JITState,
asm: &mut Assembler,
known_klass: VALUE,
obj_opnd: Opnd,
insn_opnd: YARVOpnd,
sample_instance: VALUE,
max_chain_depth: u8,
counter: Counter,
) {
let known_klass = sample_instance.class_of();
let val_type = asm.ctx.get_opnd_type(insn_opnd);

if val_type.known_class() == Some(known_klass) {
Expand Down Expand Up @@ -5036,7 +5027,7 @@ fn jit_guard_known_klass(
assert_eq!(sample_instance.class_of(), rb_cString, "context says class is exactly ::String")
};
} else {
assert!(!val_type.is_imm());
assert!(!val_type.is_imm(), "{insn_opnd:?} should be a heap object, but was {val_type:?} for {sample_instance:?}");

// Check that the receiver is a heap object
// Note: if we get here, the class doesn't have immediate instances.
Expand Down Expand Up @@ -5680,7 +5671,6 @@ fn jit_rb_float_plus(
jit_guard_known_klass(
jit,
asm,
comptime_obj.class_of(),
obj,
obj.into(),
comptime_obj,
Expand Down Expand Up @@ -5722,7 +5712,6 @@ fn jit_rb_float_minus(
jit_guard_known_klass(
jit,
asm,
comptime_obj.class_of(),
obj,
obj.into(),
comptime_obj,
Expand Down Expand Up @@ -5764,7 +5753,6 @@ fn jit_rb_float_mul(
jit_guard_known_klass(
jit,
asm,
comptime_obj.class_of(),
obj,
obj.into(),
comptime_obj,
Expand Down Expand Up @@ -5806,7 +5794,6 @@ fn jit_rb_float_div(
jit_guard_known_klass(
jit,
asm,
comptime_obj.class_of(),
obj,
obj.into(),
comptime_obj,
Expand Down Expand Up @@ -6070,7 +6057,6 @@ fn jit_rb_str_getbyte(
jit_guard_known_klass(
jit,
asm,
comptime_idx.class_of(),
idx,
idx.into(),
comptime_idx,
Expand Down Expand Up @@ -9085,7 +9071,6 @@ fn gen_send_general(
perf_call!("gen_send_general: ", jit_guard_known_klass(
jit,
asm,
comptime_recv_klass,
recv,
recv_opnd,
comptime_recv,
Expand Down Expand Up @@ -10016,7 +10001,6 @@ fn gen_objtostring(
jit_guard_known_klass(
jit,
asm,
comptime_recv.class_of(),
recv,
recv.into(),
comptime_recv,
Expand All @@ -10030,7 +10014,6 @@ fn gen_objtostring(
jit_guard_known_klass(
jit,
asm,
comptime_recv.class_of(),
recv,
recv.into(),
comptime_recv,
Expand Down
1 change: 1 addition & 0 deletions zjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ rb_zjit_insn_leaf(int insn, const VALUE *opes)
// Primitives used by zjit.rb. Don't put other functions below, which wouldn't use them.
VALUE rb_zjit_assert_compiles(rb_execution_context_t *ec, VALUE self);
VALUE rb_zjit_stats(rb_execution_context_t *ec, VALUE self, VALUE target_key);
VALUE rb_zjit_reset_stats_bang(rb_execution_context_t *ec, VALUE self);
VALUE rb_zjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self);
VALUE rb_zjit_print_stats_p(rb_execution_context_t *ec, VALUE self);

Expand Down
5 changes: 5 additions & 0 deletions zjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def stats(target_key = nil)
Primitive.rb_zjit_stats(target_key)
end

# Discard statistics collected for `--zjit-stats`.
def reset_stats!
Primitive.rb_zjit_reset_stats_bang
end

# Get the summary of ZJIT statistics as a String
def stats_string
buf = +"***ZJIT: Printing ZJIT statistics on exit***\n"
Expand Down
7 changes: 5 additions & 2 deletions zjit/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,15 @@ impl fmt::LowerHex for CodeBlock {
impl CodeBlock {
/// Stubbed CodeBlock for testing. Can't execute generated code.
pub fn new_dummy() -> Self {
const DEFAULT_MEM_SIZE: usize = 1024;
CodeBlock::new_dummy_sized(DEFAULT_MEM_SIZE)
}

pub fn new_dummy_sized(mem_size: usize) -> Self {
use std::ptr::NonNull;
use crate::virtualmem::*;
use crate::virtualmem::tests::TestingAllocator;

let mem_size = 1024;
let alloc = TestingAllocator::new(mem_size);
let mem_start: *const u8 = alloc.mem_start();
let virt_mem = VirtualMem::new(alloc, 1, NonNull::new(mem_start as *mut u8).unwrap(), mem_size, 128 * 1024 * 1024);
Expand Down Expand Up @@ -388,4 +392,3 @@ mod tests
assert_eq!(uimm_num_bits(u64::MAX), 64);
}
}

Loading