RJIT: Lazily compile global ocb

This commit is contained in:
Takashi Kokubun 2023-03-09 21:55:14 -08:00
parent 5e27d82dd0
commit 35fd79ac37
2 changed files with 16 additions and 12 deletions

View File

@ -47,11 +47,6 @@ module RubyVM::RJIT
@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.
@ -208,7 +203,7 @@ module RubyVM::RJIT
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
@ -265,6 +260,13 @@ module RubyVM::RJIT
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

View File

@ -6,11 +6,6 @@ module RubyVM::RJIT
@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
@ -3357,7 +3352,7 @@ module RubyVM::RJIT
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
@ -3966,5 +3961,12 @@ module RubyVM::RJIT
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