Class: RubyVM::RJIT::JITState

Inherits:
Struct show all
Defined in:
lib/ruby_vm/rjit/jit_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#as_json, json_create, #pretty_print, #pretty_print_cycle, #to_json

Constructor Details

#initialize(side_exit_for_pc: {}, record_boundary_patch_point: false) ⇒ JITState

Returns a new instance of JITState.



11
# File 'lib/ruby_vm/rjit/jit_state.rb', line 11

def initialize(side_exit_for_pc: {}, record_boundary_patch_point: false, **) = super

Instance Attribute Details

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



2
3
4
# File 'lib/ruby_vm/rjit/jit_state.rb', line 2

def block
  @block
end

#cfpObject

Returns the value of attribute cfp

Returns:

  • (Object)

    the current value of cfp



2
3
4
# File 'lib/ruby_vm/rjit/jit_state.rb', line 2

def cfp
  @cfp
end

#iseqObject

Returns the value of attribute iseq

Returns:

  • (Object)

    the current value of iseq



2
3
4
# File 'lib/ruby_vm/rjit/jit_state.rb', line 2

def iseq
  @iseq
end

#pcObject

Returns the value of attribute pc

Returns:

  • (Object)

    the current value of pc



2
3
4
# File 'lib/ruby_vm/rjit/jit_state.rb', line 2

def pc
  @pc
end

#record_boundary_patch_pointObject

Returns the value of attribute record_boundary_patch_point

Returns:

  • (Object)

    the current value of record_boundary_patch_point



2
3
4
# File 'lib/ruby_vm/rjit/jit_state.rb', line 2

def record_boundary_patch_point
  @record_boundary_patch_point
end

#side_exit_for_pcObject

Returns the value of attribute side_exit_for_pc

Returns:

  • (Object)

    the current value of side_exit_for_pc



2
3
4
# File 'lib/ruby_vm/rjit/jit_state.rb', line 2

def side_exit_for_pc
  @side_exit_for_pc
end

#stack_size_for_pcObject

Returns the value of attribute stack_size_for_pc

Returns:

  • (Object)

    the current value of stack_size_for_pc



2
3
4
# File 'lib/ruby_vm/rjit/jit_state.rb', line 2

def stack_size_for_pc
  @stack_size_for_pc
end

Instance Method Details

#at_current_insn?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ruby_vm/rjit/jit_state.rb', line 26

def at_current_insn?
  pc == cfp.pc.to_i
end

#insnObject



13
14
15
# File 'lib/ruby_vm/rjit/jit_state.rb', line 13

def insn
  Compiler.decode_insn(C.VALUE.new(pc).*)
end

#operand(index, signed: false, ruby: false) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/ruby_vm/rjit/jit_state.rb', line 17

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

#peek_at_block_handler(level) ⇒ Object



49
50
51
52
# File 'lib/ruby_vm/rjit/jit_state.rb', line 49

def peek_at_block_handler(level)
  ep = ep_at_level(cfp, level:)
  ep[C::VM_ENV_DATA_INDEX_SPECVAL]
end

#peek_at_local(n) ⇒ Object



30
31
32
33
34
35
# File 'lib/ruby_vm/rjit/jit_state.rb', line 30

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

#peek_at_selfObject



45
46
47
# File 'lib/ruby_vm/rjit/jit_state.rb', line 45

def peek_at_self
  C.to_ruby(cfp.self)
end

#peek_at_stack(depth_from_top) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ruby_vm/rjit/jit_state.rb', line 37

def peek_at_stack(depth_from_top)
  raise 'not at current insn' unless at_current_insn?
  offset = -(1 + depth_from_top)
  # 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