mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
s/mjit/rjit/
This commit is contained in:
parent
2e875549a9
commit
23ec248e48
Notes:
git
2023-03-07 07:44:22 +00:00
63 changed files with 1070 additions and 1072 deletions
|
@ -911,9 +911,9 @@ module RubyVM::RJIT
|
|||
end
|
||||
|
||||
def incr_counter(name)
|
||||
if C.mjit_opts.stats
|
||||
if C.rjit_opts.stats
|
||||
comment("increment counter #{name}")
|
||||
mov(:rax, C.rb_mjit_counters[name].to_i)
|
||||
mov(:rax, C.rb_rjit_counters[name].to_i)
|
||||
add([:rax], 1) # TODO: lock
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,9 +18,9 @@ module RubyVM::RJIT
|
|||
start_addr = write_addr
|
||||
|
||||
# Write machine code
|
||||
C.mjit_mark_writable
|
||||
C.rjit_mark_writable
|
||||
@write_pos += asm.assemble(start_addr)
|
||||
C.mjit_mark_executable
|
||||
C.rjit_mark_executable
|
||||
|
||||
end_addr = write_addr
|
||||
|
||||
|
@ -30,8 +30,8 @@ module RubyVM::RJIT
|
|||
end
|
||||
asm.comments.clear
|
||||
|
||||
# Dump disasm if --mjit-dump-disasm
|
||||
if C.mjit_opts.dump_disasm && start_addr < end_addr
|
||||
# Dump disasm if --rjit-dump-disasm
|
||||
if C.rjit_opts.dump_disasm && start_addr < end_addr
|
||||
dump_disasm(start_addr, end_addr)
|
||||
end
|
||||
start_addr
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require 'ruby_vm/mjit/assembler'
|
||||
require 'ruby_vm/mjit/block'
|
||||
require 'ruby_vm/mjit/branch_stub'
|
||||
require 'ruby_vm/mjit/code_block'
|
||||
require 'ruby_vm/mjit/context'
|
||||
require 'ruby_vm/mjit/exit_compiler'
|
||||
require 'ruby_vm/mjit/insn_compiler'
|
||||
require 'ruby_vm/mjit/instruction'
|
||||
require 'ruby_vm/mjit/invariants'
|
||||
require 'ruby_vm/mjit/jit_state'
|
||||
require 'ruby_vm/rjit/assembler'
|
||||
require 'ruby_vm/rjit/block'
|
||||
require 'ruby_vm/rjit/branch_stub'
|
||||
require 'ruby_vm/rjit/code_block'
|
||||
require 'ruby_vm/rjit/context'
|
||||
require 'ruby_vm/rjit/exit_compiler'
|
||||
require 'ruby_vm/rjit/insn_compiler'
|
||||
require 'ruby_vm/rjit/instruction'
|
||||
require 'ruby_vm/rjit/invariants'
|
||||
require 'ruby_vm/rjit/jit_state'
|
||||
|
||||
module RubyVM::RJIT
|
||||
# Compilation status
|
||||
|
@ -266,45 +266,45 @@ module RubyVM::RJIT
|
|||
end
|
||||
|
||||
def incr_counter(name)
|
||||
if C.mjit_opts.stats
|
||||
C.rb_mjit_counters[name][0] += 1
|
||||
if C.rjit_opts.stats
|
||||
C.rb_rjit_counters[name][0] += 1
|
||||
end
|
||||
end
|
||||
|
||||
def list_blocks(iseq, pc)
|
||||
mjit_blocks(iseq)[pc].values
|
||||
rjit_blocks(iseq)[pc].values
|
||||
end
|
||||
|
||||
# @param [Integer] pc
|
||||
# @param [RubyVM::RJIT::Context] ctx
|
||||
# @return [RubyVM::RJIT::Block,NilClass]
|
||||
def find_block(iseq, pc, ctx)
|
||||
mjit_blocks(iseq)[pc][ctx]
|
||||
rjit_blocks(iseq)[pc][ctx]
|
||||
end
|
||||
|
||||
# @param [RubyVM::RJIT::Block] block
|
||||
def set_block(iseq, block)
|
||||
mjit_blocks(iseq)[block.pc][block.ctx] = block
|
||||
rjit_blocks(iseq)[block.pc][block.ctx] = block
|
||||
end
|
||||
|
||||
# @param [RubyVM::RJIT::Block] block
|
||||
def remove_block(iseq, block)
|
||||
mjit_blocks(iseq)[block.pc].delete(block.ctx)
|
||||
rjit_blocks(iseq)[block.pc].delete(block.ctx)
|
||||
end
|
||||
|
||||
def mjit_blocks(iseq)
|
||||
def rjit_blocks(iseq)
|
||||
# Guard against ISEQ GC at random moments
|
||||
if C.imemo_type(iseq) != C.imemo_iseq
|
||||
return Hash.new { |h, k| h[k] = {} }
|
||||
end
|
||||
|
||||
unless iseq.body.mjit_blocks
|
||||
iseq.body.mjit_blocks = Hash.new { |h, k| h[k] = {} }
|
||||
# For some reason, rb_mjit_iseq_mark didn't protect this Hash
|
||||
unless iseq.body.rjit_blocks
|
||||
iseq.body.rjit_blocks = Hash.new { |h, k| h[k] = {} }
|
||||
# For some reason, rb_rjit_iseq_mark didn't protect this Hash
|
||||
# from being freed. So we rely on GC_REFS to keep the Hash.
|
||||
GC_REFS << iseq.body.mjit_blocks
|
||||
GC_REFS << iseq.body.rjit_blocks
|
||||
end
|
||||
iseq.body.mjit_blocks
|
||||
iseq.body.rjit_blocks
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -81,17 +81,17 @@ module RubyVM::RJIT
|
|||
# @param branch_stub [RubyVM::RJIT::BranchStub]
|
||||
# @param target0_p [TrueClass,FalseClass]
|
||||
def compile_branch_stub(ctx, asm, branch_stub, target0_p)
|
||||
# Call rb_mjit_branch_stub_hit
|
||||
# Call rb_rjit_branch_stub_hit
|
||||
iseq = branch_stub.iseq
|
||||
if C.mjit_opts.dump_disasm && C.imemo_type(iseq) == C.imemo_iseq # Guard against ISEQ GC at random moments
|
||||
if C.rjit_opts.dump_disasm && C.imemo_type(iseq) == C.imemo_iseq # Guard against ISEQ GC at random moments
|
||||
asm.comment("branch stub hit: #{iseq.body.location.label}@#{C.rb_iseq_path(iseq)}:#{iseq_lineno(iseq, target0_p ? branch_stub.target0.pc : branch_stub.target1.pc)}")
|
||||
end
|
||||
asm.mov(:rdi, to_value(branch_stub))
|
||||
asm.mov(:esi, ctx.sp_offset)
|
||||
asm.mov(:edx, target0_p ? 1 : 0)
|
||||
asm.call(C.rb_mjit_branch_stub_hit)
|
||||
asm.call(C.rb_rjit_branch_stub_hit)
|
||||
|
||||
# Jump to the address returned by rb_mjit_stub_hit
|
||||
# Jump to the address returned by rb_rjit_stub_hit
|
||||
asm.jmp(:rax)
|
||||
end
|
||||
|
||||
|
@ -104,10 +104,10 @@ module RubyVM::RJIT
|
|||
# @param pc [Integer]
|
||||
# @param asm [RubyVM::RJIT::Assembler]
|
||||
def incr_insn_exit(pc, asm)
|
||||
if C.mjit_opts.stats
|
||||
if C.rjit_opts.stats
|
||||
insn = Compiler.decode_insn(C.VALUE.new(pc).*)
|
||||
asm.comment("increment insn exit: #{insn.name}")
|
||||
asm.mov(:rax, (C.mjit_insn_exits + insn.bin).to_i)
|
||||
asm.mov(:rax, (C.rjit_insn_exits + insn.bin).to_i)
|
||||
asm.add([:rax], 1) # TODO: lock
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module RubyVM::RJIT
|
||||
module Hooks # :nodoc: all
|
||||
def self.on_bop_redefined(_redefined_flag, _bop)
|
||||
# C.mjit_cancel_all("BOP is redefined")
|
||||
# C.rjit_cancel_all("BOP is redefined")
|
||||
end
|
||||
|
||||
def self.on_cme_invalidate(cme)
|
||||
|
@ -10,7 +10,7 @@ module RubyVM::RJIT
|
|||
end
|
||||
|
||||
def self.on_ractor_spawn
|
||||
# C.mjit_cancel_all("Ractor is spawned")
|
||||
# C.rjit_cancel_all("Ractor is spawned")
|
||||
end
|
||||
|
||||
# Global constant changes like const_set
|
||||
|
|
|
@ -21,7 +21,7 @@ module RubyVM::RJIT
|
|||
# @param asm [RubyVM::RJIT::Assembler]
|
||||
# @param insn `RubyVM::RJIT::Instruction`
|
||||
def compile(jit, ctx, asm, insn)
|
||||
asm.incr_counter(:mjit_insns_count)
|
||||
asm.incr_counter(:rjit_insns_count)
|
||||
asm.comment("Insn: #{insn.name}")
|
||||
|
||||
# 72/101
|
||||
|
@ -512,7 +512,7 @@ module RubyVM::RJIT
|
|||
idlist = ic.segments
|
||||
|
||||
# Make sure there is an exit for this block as the interpreter might want
|
||||
# to invalidate this block from rb_mjit_constant_ic_update().
|
||||
# to invalidate this block from rb_rjit_constant_ic_update().
|
||||
# For now, we always take an entry exit even if it was a side exit.
|
||||
Invariants.ensure_block_entry_exit(jit, cause: 'opt_getconstant_path')
|
||||
|
||||
|
@ -3296,7 +3296,7 @@ module RubyVM::RJIT
|
|||
end
|
||||
|
||||
# EXEC_EVENT_HOOK: RUBY_EVENT_C_CALL and RUBY_EVENT_C_RETURN
|
||||
if C.rb_mjit_global_events & (C.RUBY_EVENT_C_CALL | C.RUBY_EVENT_C_RETURN) != 0
|
||||
if C.rb_rjit_global_events & (C.RUBY_EVENT_C_CALL | C.RUBY_EVENT_C_RETURN) != 0
|
||||
asm.incr_counter(:send_c_tracing)
|
||||
return CantCompile
|
||||
end
|
||||
|
|
|
@ -130,11 +130,11 @@ module RubyVM::RJIT
|
|||
end
|
||||
@patches.clear
|
||||
|
||||
C.mjit_for_each_iseq do |iseq|
|
||||
C.rjit_for_each_iseq do |iseq|
|
||||
# Avoid entering past code
|
||||
iseq.body.jit_func = 0
|
||||
# Avoid reusing past code
|
||||
iseq.body.mjit_blocks.clear if iseq.body.mjit_blocks
|
||||
iseq.body.rjit_blocks.clear if iseq.body.rjit_blocks
|
||||
# Compile this again if not converted to trace_* insns
|
||||
iseq.body.total_calls = 0
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ module RubyVM::RJIT
|
|||
def peek_at_stack(depth_from_top)
|
||||
raise 'not at current insn' unless at_current_insn?
|
||||
offset = -(1 + depth_from_top)
|
||||
# rb_mjit_branch_stub_hit updates SP, so you don't need to worry about sp_offset
|
||||
# rb_rjit_branch_stub_hit updates SP, so you don't need to worry about sp_offset
|
||||
value = (cfp.sp + offset).*
|
||||
C.to_ruby(value)
|
||||
end
|
||||
|
|
|
@ -5,23 +5,23 @@ module RubyVM::RJIT
|
|||
|
||||
# Insn exits
|
||||
INSNS.each_value do |insn|
|
||||
exits = C.mjit_insn_exits[insn.bin]
|
||||
exits = C.rjit_insn_exits[insn.bin]
|
||||
if exits > 0
|
||||
stats[:"exit_#{insn.name}"] = exits
|
||||
end
|
||||
end
|
||||
|
||||
# Runtime stats
|
||||
C.rb_mjit_runtime_counters.members.each do |member|
|
||||
stats[member] = C.rb_mjit_counters.public_send(member)
|
||||
C.rb_rjit_runtime_counters.members.each do |member|
|
||||
stats[member] = C.rb_rjit_counters.public_send(member)
|
||||
end
|
||||
|
||||
# Other stats are calculated here
|
||||
stats[:side_exit_count] = stats.select { |name, _count| name.start_with?('exit_') }.sum(&:last)
|
||||
if stats[:vm_insns_count] > 0
|
||||
retired_in_mjit = stats[:mjit_insns_count] - stats[:side_exit_count]
|
||||
stats[:total_insns_count] = retired_in_mjit + stats[:vm_insns_count]
|
||||
stats[:ratio_in_mjit] = 100.0 * retired_in_mjit / stats[:total_insns_count]
|
||||
retired_in_rjit = stats[:rjit_insns_count] - stats[:side_exit_count]
|
||||
stats[:total_insns_count] = retired_in_rjit + stats[:vm_insns_count]
|
||||
stats[:ratio_in_rjit] = 100.0 * retired_in_rjit / stats[:total_insns_count]
|
||||
end
|
||||
|
||||
stats
|
||||
|
@ -47,8 +47,8 @@ module RubyVM::RJIT
|
|||
$stderr.puts "side_exit_count: #{format_number(13, stats[:side_exit_count])}"
|
||||
$stderr.puts "total_insns_count: #{format_number(13, stats[:total_insns_count])}" if stats.key?(:total_insns_count)
|
||||
$stderr.puts "vm_insns_count: #{format_number(13, stats[:vm_insns_count])}" if stats.key?(:vm_insns_count)
|
||||
$stderr.puts "mjit_insns_count: #{format_number(13, stats[:mjit_insns_count])}"
|
||||
$stderr.puts "ratio_in_mjit: #{format('%12.1f', stats[:ratio_in_mjit])}%" if stats.key?(:ratio_in_mjit)
|
||||
$stderr.puts "rjit_insns_count: #{format_number(13, stats[:rjit_insns_count])}"
|
||||
$stderr.puts "ratio_in_rjit: #{format('%12.1f', stats[:ratio_in_rjit])}%" if stats.key?(:ratio_in_rjit)
|
||||
|
||||
print_exit_counts(stats)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue