From 8d5af353b2ab6c774a473fdb010dcbe3d4e90f0e Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Mon, 18 Dec 2023 22:21:31 -0800 Subject: [PATCH] RJIT: Avoid retaining comments unless --rjit-dump-disasm This significantly reduces retained objects on RJIT. --- lib/ruby_vm/rjit/code_block.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ruby_vm/rjit/code_block.rb b/lib/ruby_vm/rjit/code_block.rb index 6260ec8b4b..260bd98671 100644 --- a/lib/ruby_vm/rjit/code_block.rb +++ b/lib/ruby_vm/rjit/code_block.rb @@ -4,7 +4,7 @@ module RubyVM::RJIT # @param mem_size [Integer] JIT buffer size # @param outliend [TrueClass,FalseClass] true for outlined CodeBlock def initialize(mem_block:, mem_size:, outlined: false) - @comments = Hash.new { |h, k| h[k] = [] } + @comments = Hash.new { |h, k| h[k] = [] } if dump_disasm? @mem_block = mem_block @mem_size = mem_size @write_pos = 0 @@ -26,7 +26,7 @@ module RubyVM::RJIT # Convert comment indexes to addresses asm.comments.each do |index, comments| - @comments[start_addr + index] += comments + @comments[start_addr + index] += comments if dump_disasm? end asm.comments.clear @@ -39,7 +39,7 @@ module RubyVM::RJIT def set_write_addr(addr) @write_pos = addr - @mem_block - @comments.delete(addr) # TODO: clean up old comments for all the overwritten range? + @comments.delete(addr) if dump_disasm? end def with_write_addr(addr) @@ -83,5 +83,9 @@ module RubyVM::RJIT def bold(text) "\e[1m#{text}\e[0m" end + + def dump_disasm? + C.rjit_opts.dump_disasm + end end end