From 4d811d7a2b92d110e3e70cb77e5f499acfa7112a Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 10 Aug 2022 17:22:55 -0400 Subject: Fix code invalidation while OOM and OOM simulation (https://github.com/Shopify/ruby/pull/395) `YJIT.simulate_oom!` used to leave one byte of space in the code block, so our test didn't expose a problem with asserting that the write position is in bounds in `CodeBlock::set_pos`. We do the following when patching code: 1. save current write position 2. seek to middle of the code block and patch 3. restore old write position The bounds check fails on (3) when the code block is already filled up. Leaving one byte of space also meant that when we write that byte, we need to fill the entire code region with trapping instruction in `VirtualMem`, which made the OOM tests unnecessarily slow. Remove the incorrect bounds check and stop leaving space in the code block when simulating OOM. --- bootstraptest/test_yjit.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'bootstraptest') diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index d44fe25800..89d7c9a038 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -2901,11 +2901,20 @@ assert_equal 'new', %q{ foo end + def bar + :bar + end + + test test RubyVM::YJIT.simulate_oom! if defined?(RubyVM::YJIT) + # Old simulat_omm! leaves one byte of space and this fills it up + bar + bar + def foo :new end -- cgit v1.2.3