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/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
with:
results_file: results.sarif
results_format: sarif
Expand Down
4 changes: 3 additions & 1 deletion test/test_ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ def test_ipv4_compat
assert_equal(128, b.prefix)

a = IPAddr.new("192.168.0.0/16")
b = a.ipv4_compat
assert_warning(/obsolete/) {
b = a.ipv4_compat
}
assert_equal("::192.168.0.0", b.to_s)
assert_equal(Socket::AF_INET6, b.family)
assert_equal(112, b.prefix)
Expand Down
25 changes: 20 additions & 5 deletions zjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def dump_exit_locations(filename)
raise ArgumentError, "--zjit-trace-exits must be enabled to use dump_exit_locations."
end

File.binwrite(filename, Marshal.dump(RubyVM::ZJIT.exit_locations))
File.open(filename, "wb") do |file|
Marshal.dump(RubyVM::ZJIT.exit_locations, file)
end
end

# Check if `--zjit-stats` is used
Expand Down Expand Up @@ -162,9 +164,16 @@ def stats_string
print_counters_with_prefix(prefix: 'compile_error_', prompt: 'compile error reasons', buf:, stats:, limit: 20)
print_counters_with_prefix(prefix: 'exit_', prompt: 'side exit reasons', buf:, stats:, limit: 20)

# Show the most important stats ratio_in_zjit at the end
# Show no-prefix counters, having the most important stat `ratio_in_zjit` at the end
print_counters([
:send_count,
:dynamic_send_count,
:optimized_send_count,
:iseq_optimized_send_count,
:inline_cfunc_optimized_send_count,
:variadic_cfunc_optimized_send_count,
], buf:, stats:, right_align: true, base: :send_count)
print_counters([
:dynamic_getivar_count,
:dynamic_setivar_count,

Expand Down Expand Up @@ -202,12 +211,18 @@ def assert_compiles # :nodoc:
# :stopdoc:
private

def print_counters(keys, buf:, stats:)
left_pad = keys.map { |key| key.to_s.sub(/_time_ns\z/, '_time').size }.max + 1
def print_counters(keys, buf:, stats:, right_align: false, base: nil)
key_pad = keys.map { |key| key.to_s.sub(/_time_ns\z/, '_time').size }.max + 1
key_align = '-' unless right_align
value_pad = keys.filter_map { |key| stats[key] }.map { |value| number_with_delimiter(value).size }.max

keys.each do |key|
# Some stats like vm_insn_count and ratio_in_zjit are not supported on the release build
next unless stats.key?(key)
value = stats[key]
if base && key != base
ratio = " (%4.1f%%)" % (100.0 * value / stats[base])
end

case key
when :ratio_in_zjit
Expand All @@ -219,7 +234,7 @@ def print_counters(keys, buf:, stats:)
value = number_with_delimiter(value)
end

buf << "#{"%-#{left_pad}s" % "#{key}:"} #{value}\n"
buf << "%#{key_align}*s %*s%s\n" % [key_pad, "#{key}:", value_pad, value, ratio]
end
end

Expand Down
5 changes: 5 additions & 0 deletions zjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ fn gen_patch_point(jit: &mut JITState, asm: &mut Assembler, invariant: &Invarian
/// Lowering for [`Insn::CCall`]. This is a low-level raw call that doesn't know
/// anything about the callee, so handling for e.g. GC safety is dealt with elsewhere.
fn gen_ccall(asm: &mut Assembler, cfun: *const u8, args: Vec<Opnd>) -> lir::Opnd {
gen_incr_counter(asm, Counter::inline_cfunc_optimized_send_count);
asm.ccall(cfun, args)
}

Expand All @@ -675,6 +676,8 @@ fn gen_ccall_variadic(
cme: *const rb_callable_method_entry_t,
state: &FrameState,
) -> lir::Opnd {
gen_incr_counter(asm, Counter::variadic_cfunc_optimized_send_count);

gen_prepare_non_leaf_call(jit, asm, state);

let stack_growth = state.stack_size();
Expand Down Expand Up @@ -1051,6 +1054,8 @@ fn gen_send_without_block_direct(
args: Vec<Opnd>,
state: &FrameState,
) -> lir::Opnd {
gen_incr_counter(asm, Counter::iseq_optimized_send_count);

let local_size = unsafe { get_iseq_body_local_table_size(iseq) }.as_usize();
let stack_growth = state.stack_size() + local_size + unsafe { get_iseq_body_stack_max(iseq) }.as_usize();
gen_stack_overflow_check(jit, asm, state, stack_growth);
Expand Down
29 changes: 29 additions & 0 deletions zjit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ macro_rules! make_counters {
dynamic_send {
$($dynamic_send_counter_name:ident,)+
}
optimized_send {
$($optimized_send_counter_name:ident,)+
}
$($counter_name:ident,)+
) => {
/// Struct containing the counter values
Expand All @@ -29,6 +32,7 @@ macro_rules! make_counters {
$(pub $default_counter_name: u64,)+
$(pub $exit_counter_name: u64,)+
$(pub $dynamic_send_counter_name: u64,)+
$(pub $optimized_send_counter_name: u64,)+
$(pub $counter_name: u64,)+
}

Expand All @@ -39,6 +43,7 @@ macro_rules! make_counters {
$($default_counter_name,)+
$($exit_counter_name,)+
$($dynamic_send_counter_name,)+
$($optimized_send_counter_name,)+
$($counter_name,)+
}

Expand All @@ -48,6 +53,7 @@ macro_rules! make_counters {
$( Counter::$default_counter_name => stringify!($default_counter_name).to_string(), )+
$( Counter::$exit_counter_name => stringify!($exit_counter_name).to_string(), )+
$( Counter::$dynamic_send_counter_name => stringify!($dynamic_send_counter_name).to_string(), )+
$( Counter::$optimized_send_counter_name => stringify!($optimized_send_counter_name).to_string(), )+
$( Counter::$counter_name => stringify!($counter_name).to_string(), )+
}
}
Expand All @@ -60,6 +66,7 @@ macro_rules! make_counters {
$( Counter::$default_counter_name => std::ptr::addr_of_mut!(counters.$default_counter_name), )+
$( Counter::$exit_counter_name => std::ptr::addr_of_mut!(counters.$exit_counter_name), )+
$( Counter::$dynamic_send_counter_name => std::ptr::addr_of_mut!(counters.$dynamic_send_counter_name), )+
$( Counter::$optimized_send_counter_name => std::ptr::addr_of_mut!(counters.$optimized_send_counter_name), )+
$( Counter::$counter_name => std::ptr::addr_of_mut!(counters.$counter_name), )+
}
}
Expand All @@ -80,6 +87,11 @@ macro_rules! make_counters {
$( Counter::$dynamic_send_counter_name, )+
];

/// List of other counters that are summed as optimized_send_count.
pub const OPTIMIZED_SEND_COUNTERS: &'static [Counter] = &[
$( Counter::$optimized_send_counter_name, )+
];

/// List of other counters that are available only for --zjit-stats.
pub const OTHER_COUNTERS: &'static [Counter] = &[
$( Counter::$counter_name, )+
Expand Down Expand Up @@ -140,6 +152,13 @@ make_counters! {
send_fallback_not_optimized_instruction,
}

// Optimized send counters that are summed as optimized_send_count
optimized_send {
iseq_optimized_send_count,
inline_cfunc_optimized_send_count,
variadic_cfunc_optimized_send_count,
}

// compile_error_: Compile error reasons
compile_error_iseq_stack_too_large,
compile_error_exception_handler,
Expand Down Expand Up @@ -421,6 +440,16 @@ pub extern "C" fn rb_zjit_stats(_ec: EcPtr, _self: VALUE, target_key: VALUE) ->
}
set_stat_usize!(hash, "dynamic_send_count", dynamic_send_count);

// Set optimized send counters
let mut optimized_send_count = 0;
for &counter in OPTIMIZED_SEND_COUNTERS {
let count = unsafe { *counter_ptr(counter) };
optimized_send_count += count;
set_stat_usize!(hash, &counter.name(), count);
}
set_stat_usize!(hash, "optimized_send_count", optimized_send_count);
set_stat_usize!(hash, "send_count", dynamic_send_count + optimized_send_count);

// Set send fallback counters for NotOptimizedInstruction
let send_fallback_counters = ZJITState::get_send_fallback_counters();
for (op_idx, count) in send_fallback_counters.iter().enumerate().take(VM_INSTRUCTION_SIZE as usize) {
Expand Down