From 13d1ded253940585a993e92648ab9f77d355586d Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Thu, 4 Nov 2021 12:30:30 -0400 Subject: YJIT: Make block invalidation more robust This commit adds an entry_exit field to block_t for use in invalidate_block_version(). By patching the start of the block while invalidating it, invalidate_block_version() can function correctly while there is no executable memory left for new branch stubs. This change additionally fixes correctness for situations where we cannot patch incoming jumps to the invalidated block. In situations such as Shopify/yjit#226, the address to the start of the block is saved and used later, possibly after the block is invalidated. The assume_* family of function now generate block->entry_exit before remembering blocks for invalidation. RubyVM::YJIT.simulate_oom! is introduced for testing out of memory conditions. The test for it is disabled for now because OOM triggers other failure conditions not addressed by this commit. Fixes Shopify/yjit#226 --- yjit_codegen.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'yjit_codegen.h') diff --git a/yjit_codegen.h b/yjit_codegen.h index 1e87c85393..4ae2536423 100644 --- a/yjit_codegen.h +++ b/yjit_codegen.h @@ -10,6 +10,8 @@ typedef enum codegen_status { // Code generation function signature typedef codegen_status_t (*codegen_fn)(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb); +static void jit_ensure_block_entry_exit(jitstate_t *jit); + static uint8_t *yjit_entry_prologue(codeblock_t *cb, const rb_iseq_t *iseq); static void yjit_gen_block(block_t *block, rb_execution_context_t *ec); -- cgit v1.2.3