diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2022-08-08 14:49:46 -0400 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2022-08-29 08:47:08 -0700 |
commit | a3757842752e78a5f53b5dfcdcf9601c037f8c76 (patch) | |
tree | 0125b93a821aef45458d9ff70c9bde7a676fa91a /yjit/src | |
parent | 726a4519550fd9191833e482122e3c7bf9a468be (diff) | |
download | ruby-a3757842752e78a5f53b5dfcdcf9601c037f8c76.tar.gz |
Use new assembler to support global invalidation on A64
Previously, we patched in an x64 JMP even on A64, which resulted in
invalid machine code. Use the new assembler to generate a jump instead.
Add an assert to make sure patches don't step on each other since it's
less clear cut on A64, where the size of the jump varies depending on
its placement relative to the target.
Fixes a lot of tests that use `set_trace_func` in `test_insns.rb`.
PR: https://github.com/Shopify/ruby/pull/379
Diffstat (limited to 'yjit/src')
-rw-r--r-- | yjit/src/invariants.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/yjit/src/invariants.rs b/yjit/src/invariants.rs index 6329c70f87..9cdef0d8bb 100644 --- a/yjit/src/invariants.rs +++ b/yjit/src/invariants.rs @@ -528,8 +528,6 @@ pub extern "C" fn rb_yjit_tracing_invalidate_all() { return; } - use crate::asm::x86_64::jmp_ptr; - // Stop other ractors since we are going to patch machine code. with_vm_lock(src_loc!(), || { // Make it so all live block versions are no longer valid branch targets @@ -561,13 +559,18 @@ pub extern "C" fn rb_yjit_tracing_invalidate_all() { // Apply patches let old_pos = cb.get_write_pos(); - let patches = CodegenGlobals::take_global_inval_patches(); + let mut patches = CodegenGlobals::take_global_inval_patches(); + patches.sort_by_cached_key(|patch| patch.inline_patch_pos.raw_ptr()); + let mut last_patch_end = std::ptr::null(); for patch in &patches { - cb.set_write_ptr(patch.inline_patch_pos); - jmp_ptr(cb, patch.outlined_target_pos); + assert!(last_patch_end <= patch.inline_patch_pos.raw_ptr(), "patches should not overlap"); - // FIXME: Can't easily check we actually wrote out the JMP at the moment. - // assert!(!cb.has_dropped_bytes(), "patches should have space and jump offsets should fit in JMP rel32"); + let mut asm = crate::backend::ir::Assembler::new(); + asm.jmp(patch.outlined_target_pos.into()); + + cb.set_write_ptr(patch.inline_patch_pos); + asm.compile(cb); + last_patch_end = cb.get_write_ptr().raw_ptr(); } cb.set_pos(old_pos); |