summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2021-09-20 14:55:10 -0400
committerAlan Wu <[email protected]>2021-10-20 18:19:41 -0400
commitc46bda6f191b01121ebbc8afa88b35683b6417a9 (patch)
tree5ef1ccfe896bdc6cae6e5b17f13b1a31aaba7bb6 /test
parent6ef1609fab0f5bee0592ef9c9cb82e34af8d5efd (diff)
Fix excessive invalidation for opt_getinlinecache
YJIT expects the VM to invalidate opt_getinlinecache when updating the constant cache, and the invalidation used to happen even when YJIT can't use the cached value. Once the first invalidation happens, the block for opt_getinlinecache becomes a stub. When the stub is hit, YJIT fails to compile the instruction as the cache is not usable. The stub becomes a block that exits for opt_getinlinecache which can be invalidated again. Some workloads that bust the interpreter's constant cache can create an invalidation loop with this behavior. Check if the cache is usable become doing invalidation to fix this problem. In the test harness, evaluate the test script in a lambda instead of a proc so `return` doesn't return out of the harness.
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_yjit.rb27
1 files changed, 26 insertions, 1 deletions
diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
index ed83bd681a..e6325a4d1c 100644
--- a/test/ruby/test_yjit.rb
+++ b/test/ruby/test_yjit.rb
@@ -394,6 +394,31 @@ class TestYJIT < Test::Unit::TestCase
RUBY
end
+ def test_no_excessive_opt_getinlinecache_invalidation
+ assert_compiles(<<~'RUBY', exits: :any, result: :ok)
+ objects = [Object.new, Object.new]
+
+ objects.each do |o|
+ class << o
+ def foo
+ Object
+ end
+ end
+ end
+
+ 9000.times {
+ objects[0].foo
+ objects[1].foo
+ }
+
+ stats = YJIT.runtime_stats
+ return :ok unless stats[:all_stats]
+ return :ok if stats[:invalidation_count] < 10
+
+ :fail
+ RUBY
+ end
+
def assert_no_exits(script)
assert_compiles(script)
end
@@ -437,7 +462,7 @@ class TestYJIT < Test::Unit::TestCase
script = <<~RUBY
#{"# frozen_string_literal: true" if frozen_string_literal}
- _test_proc = proc {
+ _test_proc = -> {
#{test_script}
}
#{reset_stats}