ruby/yjit
Alan Wu 5fa608ed79
YJIT: Fix code GC freeing stubs with a trampoline (#6937)
Stubs we generate for invalidation don't necessarily co-locate with the
code that jump to the stub. Since we rely on co-location to keep stubs
alive as they are in the outlined code block, it used to be possible for
code GC inside branch_stub_hit() to free the stub that's its direct
caller, leading us to return to freed code after.

Stubs used to look like:

```
mov arg0, branch_ptr
mov arg1, target_idx
mov arg2, ec
call branch_stub_hit
jmp return_reg
```

Since the call and the jump after the call is the same for all stubs, we
can extract them and use a static trampoline for them. That makes
branch_stub_hit() always return to static code. Stubs now look like:

```
mov arg0, branch_ptr
mov arg1, target_idx
jmp trampoline
```

Where the trampoline is:

```
mov arg2, ec
call branch_stub_hit
jmp return_reg
```

Code GC can now free stubs without problems since we'll always return
to the trampoline, which we generate once on boot and lives forever.

This might save a small bit of memory due to factoring out the static
part of stubs, but it's probably minor.

[Bug #19234]

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-12-15 15:10:14 -05:00
..
bindgen Transition complex objects to "too complex" shape 2022-12-15 10:06:04 -08:00
src YJIT: Fix code GC freeing stubs with a trampoline (#6937) 2022-12-15 15:10:14 -05:00
.gitignore
Cargo.lock YJIT: Instrument global allocations on stats build (#6712) 2022-11-13 12:54:41 -05:00
Cargo.toml YJIT: Generate debug info in release builds (#6910) 2022-12-12 15:59:29 -05:00
not_gmake.mk YJIT: Support MAKE=bmake for release build 2022-09-20 14:17:27 -04:00
yjit.mk Suppress the output of if [ 'xyes' = xyes ]; code 2022-12-13 22:26:24 -08:00