Skip to content

Commit

Permalink
RJIT: Lazily compile global ocb
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 10, 2023
1 parent 5e27d82 commit 35fd79a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions lib/ruby_vm/rjit/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ def initialize(mem_block, mem_size)
@exit_compiler = ExitCompiler.new
@insn_compiler = InsnCompiler.new(@cb, @ocb, @exit_compiler)
Invariants.initialize(@cb, @ocb, self, @exit_compiler)

@leave_exit = Assembler.new.then do |asm|
@exit_compiler.compile_leave_exit(asm)
@ocb.write(asm)
end
end

# Compile an ISEQ from its entry point.
Expand Down Expand Up @@ -208,7 +203,7 @@ def compile_prologue(asm)
asm.mov(SP, [CFP, C.rb_control_frame_t.offsetof(:sp)]) # rbx = cfp->sp

# Setup cfp->jit_return
asm.mov(:rax, @leave_exit)
asm.mov(:rax, leave_exit)
asm.mov([CFP, C.rb_control_frame_t.offsetof(:jit_return)], :rax)
end

Expand Down Expand Up @@ -265,6 +260,13 @@ def compile_block(asm, jit:, pc: jit.iseq.body.iseq_encoded.to_i, ctx: Context.n
set_block(iseq, block)
end

def leave_exit
@leave_exit ||= Assembler.new.then do |asm|
@exit_compiler.compile_leave_exit(asm)
@ocb.write(asm)
end
end

def incr_counter(name)
if C.rjit_opts.stats
C.rb_rjit_counters[name][0] += 1
Expand Down
14 changes: 8 additions & 6 deletions lib/ruby_vm/rjit/insn_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ def initialize(cb, ocb, exit_compiler)
@ocb = ocb
@exit_compiler = exit_compiler

@full_cfunc_return = Assembler.new.then do |asm|
@exit_compiler.compile_full_cfunc_return(asm)
@ocb.write(asm)
end

@cfunc_codegen_table = {}
register_cfunc_codegen_funcs
# freeze # workaround a binding.irb issue. TODO: resurrect this
Expand Down Expand Up @@ -3357,7 +3352,7 @@ def jit_call_cfunc_with_frame(jit, ctx, asm, cme, flags, argc, block_handler, kn
asm.call(:rax) # TODO: use rel32 if close enough
ctx.stack_pop(1 + argc)

Invariants.record_global_inval_patch(asm, @full_cfunc_return)
Invariants.record_global_inval_patch(asm, full_cfunc_return)

asm.comment('push the return value')
stack_ret = ctx.stack_push
Expand Down Expand Up @@ -3966,5 +3961,12 @@ def to_value(obj)
GC_REFS << obj
C.to_value(obj)
end

def full_cfunc_return
@full_cfunc_return ||= Assembler.new.then do |asm|
@exit_compiler.compile_full_cfunc_return(asm)
@ocb.write(asm)
end
end
end
end

0 comments on commit 35fd79a

Please sign in to comment.