diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2021-03-12 12:22:19 -0500 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:31 -0400 |
commit | 5d834bcf9fb9596fd15f9e657a94caa8716b3f10 (patch) | |
tree | 6ae91f07eb1172c40966f7631e204d827a0f17f0 /bootstraptest | |
parent | 439db7b81b588a1ee12475568cab7b8dab4e2cd3 (diff) | |
download | ruby-5d834bcf9fb9596fd15f9e657a94caa8716b3f10.tar.gz |
YJIT: lazy polymorphic getinstancevariable
Lazily compile out a chain of checks for different known classes and
whether `self` embeds its ivars or not.
* Remove trailing whitespaces
* Get proper addresss in Capstone disassembly
* Lowercase address in Capstone disassembly
Capstone uses lowercase for jump targets in generated listings. Let's
match it.
* Use the same successor in getivar guard chains
Cuts down on duplication
* Address reviews
* Fix copypasta error
* Add a comment
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_yjit.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index eac75d38a5..4750ac5fe8 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -301,3 +301,63 @@ assert_equal "good", %q{ foo } + +# Test polymorphic getinstancevariable. T_OBJECT -> T_STRING +assert_equal 'ok', %q{ + @hello = @h1 = @h2 = @h3 = @h4 = 'ok' + str = "" + str.instance_variable_set(:@hello, 'ok') + + public def get + @hello + end + + get + get + str.get + str.get +} + +# Test polymorphic getinstancevariable, two different classes +assert_equal 'ok', %q{ + class Embedded + def initialize + @ivar = 0 + end + + def get + @ivar + end + end + + class Extended < Embedded + def initialize + @v1 = @v2 = @v3 = @v4 = @ivar = 'ok' + end + end + + embed = Embedded.new + extend = Extended.new + + embed.get + embed.get + extend.get + extend.get +} + +# Test megamorphic getinstancevariable +assert_equal 'ok', %q{ + parent = Class.new do + def initialize + @hello = @h1 = @h2 = @h3 = @h4 = 'ok' + end + + def get + @hello + end + end + + subclasses = 300.times.map { Class.new(parent) } + subclasses.each { _1.new.get } + parent.new.get +} |