ruby/lib/ruby_vm/rjit/jit_state.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.0 KiB
Ruby
Raw Normal View History

2023-03-06 23:15:30 -08:00
module RubyVM::RJIT
2022-12-28 13:50:24 -08:00
class JITState < Struct.new(
2023-03-06 23:15:30 -08:00
:iseq, # @param `RubyVM::RJIT::CPointer::Struct_rb_iseq_t`
2023-02-16 22:29:58 -08:00
:pc, # @param [Integer] The JIT target PC
2023-03-06 23:15:30 -08:00
:cfp, # @param `RubyVM::RJIT::CPointer::Struct_rb_control_frame_t` The JIT source CFP (before RJIT is called)
:block, # @param [RubyVM::RJIT::Block]
:stack_size_for_pc, # @param [Integer]
:side_exit_for_pc, # @param [Hash{ Integer => Integer }] { sp_offset => address }
2023-02-16 22:29:58 -08:00
:record_boundary_patch_point, # @param [TrueClass,FalseClass]
2022-12-28 13:50:24 -08:00
)
def initialize(side_exit_for_pc: {}, record_boundary_patch_point: false, **) = super
2023-01-02 22:53:14 -08:00
2023-01-07 13:21:14 -08:00
def insn
Compiler.decode_insn(C.VALUE.new(pc).*)
end
2023-02-21 00:19:37 -08:00
def operand(index, signed: false, ruby: false)
2023-02-13 07:30:25 -08:00
addr = pc + (index + 1) * Fiddle::SIZEOF_VOIDP
2023-02-21 00:19:37 -08:00
value = Fiddle::Pointer.new(addr)[0, Fiddle::SIZEOF_VOIDP].unpack(signed ? 'q' : 'Q')[0]
if ruby
value = C.to_ruby(value)
end
value
2022-12-28 13:50:24 -08:00
end
2022-12-31 13:41:32 -08:00
def at_current_insn?
pc == cfp.pc.to_i
end
2023-01-02 22:53:14 -08:00
2023-04-03 22:52:38 -07:00
def peek_at_local(n)
local_table_size = iseq.body.local_table_size
offset = -C::VM_ENV_DATA_SIZE - local_table_size + n + 1
value = (cfp.ep + offset).*
C.to_ruby(value)
end
2023-01-07 21:24:30 -08:00
def peek_at_stack(depth_from_top)
2023-01-02 22:53:14 -08:00
raise 'not at current insn' unless at_current_insn?
2023-01-07 21:24:30 -08:00
offset = -(1 + depth_from_top)
2023-03-06 23:17:25 -08:00
# rb_rjit_branch_stub_hit updates SP, so you don't need to worry about sp_offset
2023-01-02 22:53:14 -08:00
value = (cfp.sp + offset).*
C.to_ruby(value)
end
2023-02-07 14:42:58 -08:00
def peek_at_self
C.to_ruby(cfp.self)
end
2023-03-03 21:29:20 -08:00
def peek_at_block_handler(level)
ep = ep_at_level(cfp, level:)
ep[C::VM_ENV_DATA_INDEX_SPECVAL]
2023-03-03 21:29:20 -08:00
end
private
def ep_at_level(cfp, level:)
ep = cfp.ep
level.times do
# VM_ENV_PREV_EP
ep = C.VALUE.new(ep[C::VM_ENV_DATA_INDEX_SPECVAL] & ~0x03)
2023-03-03 21:29:20 -08:00
end
ep
end
2022-12-28 13:50:24 -08:00
end
2022-12-26 14:09:45 -08:00
end