YJIT: Fix potential infinite loop when OOM #13186
Merged
+102
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes https://bugs.ruby-lang.org/issues/21257 [Bug #21257]
Avoid generating an infinite loop in the case where:
first
is adjacent to blocksecond
, and the branch fromfirst
tosecond
is a fallthrough, andsecond
immediately exits to the interpreter, andsecond
is invalidated and YJIT is OOMWhile pondering how to fix this, I think I've stumbled on another related edge case:
incoming_one
andincoming_two
both branch to blocksecond
. Blockincoming_one
has a fallthroughsecond
immediately exits to the interpreter (so it starts with its exit)second
is invalidated, the incoming fallthrough branch fromincoming_one
might be rewritten first, which overwrites the start of blocksecond
with a jump to a new branch stub.incoming_two
is then rewritten, but because we're OOM we can't generate a new stub, so we usesecond
's exit as the branch target. Howeversecond
's exit was already overwritten with a jump to the branch stub forincoming_one
, soincoming_two
will end up jumping toincoming_one
's branch stub.I'm not sure what the consequences of calling the wrong branch stub are, but the comments in invalidate_block_version suggest the stubs are supposed to be unique.
I've attempted to address both of these cases with this change, but I can split it up if that would be preferable.