diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-08-21 10:15:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-21 10:15:01 -0700 |
commit | 48c8df9e0eb295af06d593ce37ce1933c0ee1d90 (patch) | |
tree | 4a8092796f397a12835f89c4f220a84fa8f5f867 /test | |
parent | f51a6ace06cecd193bf00747a63809849e254050 (diff) | |
download | ruby-48c8df9e0eb295af06d593ce37ce1933c0ee1d90.tar.gz |
Allow tracing of optimized methods
This updates the trace instructions to directly dispatch to
opt_send_without_block. So this should cause no slowdown in
non-trace mode.
To enable the tracing of the optimized methods, RUBY_EVENT_C_CALL
and RUBY_EVENT_C_RETURN are added as events to the specialized
instructions.
Fixes [Bug #14870]
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_optimization.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index b0090d654a..226fb44261 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -150,6 +150,51 @@ class TestRubyOptimization < Test::Unit::TestCase assert_redefine_method('String', '-@', 'assert_nil(-"foo")') end + def test_trace_optimized_methods + bug14870 = "[ruby-core:87638]" + expected = [:-@, :max, :min, :+, :-, :*, :/, :%, :==, :<, :<=, :>, :>=, :<<, + :&, :|, :[], :[]=, :length, :empty?, :nil?, :succ, :!, :=~] + [:c_call, :c_return].each do |type| + methods = [] + tp = TracePoint.new(type) { |tp| methods << tp.method_id } + tp.enable do + x = "a"; -x + [1].max + [1].min + x = 42 + 2 + x = 42 - 2 + x = 42 * 2 + x = 42 / 2 + x = 42 % 2 + x == 42 + x < 42 + x <= 42 + x > 42 + x >= 42 + x = x << 1 + x = x & 1 + x = x | 1 + x = []; x[1] + x[1] = 2 + x.length + x.empty? + x.nil? + x = 1; x.succ + !x + x = 'a'; x =~ /a/ + end + assert_equal(expected, methods, bug14870) + end + + methods = [] + tp = TracePoint.new(:c_call, :c_return) { |tp| methods << tp.method_id } + tp.enable do + x = 1 + x != 42 + end + assert_equal([:!=, :==, :==, :!=], methods, bug14870) + end + def test_string_freeze_saves_memory n = 16384 data = '.'.freeze |