mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
ZJIT: Optimize class guards by directly reading klass field (#14136)
Replace `rb_yarv_class_of` call with: - a constant check for special constants (nil, fixnums, symbols, etc) - a check for false - direct memory read at offset 8 for regular heap objects for the class check
This commit is contained in:
parent
96c9e1e93a
commit
d25eb1eb5c
3 changed files with 43 additions and 7 deletions
|
@ -1432,6 +1432,30 @@ class TestZJIT < Test::Unit::TestCase
|
|||
}, call_threshold: 2, insns: [:opt_nil_p]
|
||||
end
|
||||
|
||||
def test_basic_object_guard_works_with_immediate
|
||||
assert_compiles 'NilClass', %q{
|
||||
class Foo; end
|
||||
|
||||
def test(val) = val.class
|
||||
|
||||
test(Foo.new)
|
||||
test(Foo.new)
|
||||
test(nil)
|
||||
}, call_threshold: 2
|
||||
end
|
||||
|
||||
def test_basic_object_guard_works_with_false
|
||||
assert_compiles 'FalseClass', %q{
|
||||
class Foo; end
|
||||
|
||||
def test(val) = val.class
|
||||
|
||||
test(Foo.new)
|
||||
test(Foo.new)
|
||||
test(false)
|
||||
}, call_threshold: 2
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Assert that every method call in `test_script` can be compiled by ZJIT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue