diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-03-06 22:35:38 -0800 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2023-03-06 23:44:01 -0800 |
commit | eaccdc1941304d6273397b21c25213174d892185 (patch) | |
tree | 93a2ab9455ccf56c55cd01370007703d75b80627 /lib/ruby_vm/rjit/jit_state.rb | |
parent | 854546fcc468fc6a49588bdbf6df77aa185493a1 (diff) |
Rename MJIT filenames to RJIT
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7462
Diffstat (limited to 'lib/ruby_vm/rjit/jit_state.rb')
-rw-r--r-- | lib/ruby_vm/rjit/jit_state.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/ruby_vm/rjit/jit_state.rb b/lib/ruby_vm/rjit/jit_state.rb new file mode 100644 index 0000000000..decafee579 --- /dev/null +++ b/lib/ruby_vm/rjit/jit_state.rb @@ -0,0 +1,57 @@ +module RubyVM::MJIT + class JITState < Struct.new( + :iseq, # @param `RubyVM::MJIT::CPointer::Struct_rb_iseq_t` + :pc, # @param [Integer] The JIT target PC + :cfp, # @param `RubyVM::MJIT::CPointer::Struct_rb_control_frame_t` The JIT source CFP (before MJIT is called) + :block, # @param [RubyVM::MJIT::Block] + :side_exits, # @param [Hash{ Integer => Integer }] { PC => address } + :record_boundary_patch_point, # @param [TrueClass,FalseClass] + ) + def initialize(side_exits: {}, record_boundary_patch_point: false, **) = super + + def insn + Compiler.decode_insn(C.VALUE.new(pc).*) + end + + def operand(index, signed: false, ruby: false) + addr = pc + (index + 1) * Fiddle::SIZEOF_VOIDP + value = Fiddle::Pointer.new(addr)[0, Fiddle::SIZEOF_VOIDP].unpack(signed ? 'q' : 'Q')[0] + if ruby + value = C.to_ruby(value) + end + value + end + + def at_current_insn? + pc == cfp.pc.to_i + end + + 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 + value = (cfp.sp + offset).* + C.to_ruby(value) + end + + def peek_at_self + C.to_ruby(cfp.self) + end + + def peek_at_block_handler(level) + ep = ep_at_level(cfp, level:) + ep[C.VM_ENV_DATA_INDEX_SPECVAL] + 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) + end + ep + end + end +end |