diff options
author | Koichi Sasada <ko1@atdot.net> | 2022-10-17 17:50:42 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2022-10-20 17:38:28 +0900 |
commit | e35c528d721d209ed8531b10b46c2ac725ea7bf5 (patch) | |
tree | 7a5fe3d73461b9e628f04226dedfffe8632a5438 /test/objspace/test_objspace.rb | |
parent | 7563604fb868d87057733f52d780d841fc1ab6bb (diff) | |
download | ruby-e35c528d721d209ed8531b10b46c2ac725ea7bf5.tar.gz |
push dummy frame for loading process
This patch pushes dummy frames when loading code for the
profiling purpose.
The following methods push a dummy frame:
* `Kernel#require`
* `Kernel#load`
* `RubyVM::InstructionSequence.compile_file`
* `RubyVM::InstructionSequence.load_from_binary`
https://bugs.ruby-lang.org/issues/18559
Diffstat (limited to 'test/objspace/test_objspace.rb')
-rw-r--r-- | test/objspace/test_objspace.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 3b90319858..5994fadeff 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -726,6 +726,65 @@ class TestObjSpace < Test::Unit::TestCase end end + def load_allocation_path_helper method, to_binary: false + + Tempfile.create(["test_ruby_load_allocation_path", ".rb"]) do |t| + path = t.path + str = "#{Time.now.to_f.to_s}_#{rand.to_s}" + t.puts script = <<~RUBY + # frozen-string-literal: true + return if Time.now.to_i > 0 + $gv = 'rnd-#{str}' # unreachable, but the string literal was written + RUBY + + t.close + + if to_binary + bin = RubyVM::InstructionSequence.compile_file(t.path).to_binary + bt = Tempfile.new(['test_ruby_load_allocation_path', '.yarb'], mode: File::Constants::WRONLY) + bt.write bin + bt.close + + path = bt.path + end + + assert_separately(%w[-robjspace -rtempfile], <<~RUBY) + GC.disable + path = "#{path}" + ObjectSpace.trace_object_allocations do + #{method} + end + + n = 0 + dump = ObjectSpace.dump_all(output: :string) + dump.each_line do |line| + if /"value":"rnd-#{str}"/ =~ line && /"frozen":true/ =~ line + assert Regexp.new('"file":"' + "#{path}") =~ line + assert Regexp.new('"line":') !~ line + n += 1 + end + rescue ArgumentError + end + + assert_equal(1, n) + RUBY + ensure + bt.unlink if bt + end + end + + def test_load_allocation_path_load + load_allocation_path_helper 'load(path)' + end + + def test_load_allocation_path_compile_file + load_allocation_path_helper 'RubyVM::InstructionSequence.compile_file(path)' + end + + def test_load_allocation_path_load_from_binary + # load_allocation_path_helper 'iseq = RubyVM::InstructionSequence.load_from_binary(File.binread(path))', to_binary: true + end + def test_utf8_method_names name = "utf8_❨╯°□°❩╯︵┻━┻" obj = ObjectSpace.trace_object_allocations do |