diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2022-11-03 08:42:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-03 11:42:28 -0400 |
commit | 68ef97d788cf8bff42d981bda41cd26128220740 (patch) | |
tree | a47646a42fbfc7e7bc6a8fa88b74940bbd2dfeb8 | |
parent | 0468136a1b07d693cf60abd0c5ccd125fc361039 (diff) | |
download | ruby-68ef97d788cf8bff42d981bda41cd26128220740.tar.gz |
YJIT: Stop incrementing write_pos if cb.has_dropped_bytes (#6664)
Co-Authored-By: Alan Wu <alansi.xingwu@shopify.com>
Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
-rw-r--r-- | yjit/src/asm/mod.rs | 12 | ||||
-rw-r--r-- | yjit/src/backend/arm64/mod.rs | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/yjit/src/asm/mod.rs b/yjit/src/asm/mod.rs index 6b2dd7da9a..1be4488006 100644 --- a/yjit/src/asm/mod.rs +++ b/yjit/src/asm/mod.rs @@ -418,12 +418,11 @@ impl CodeBlock { /// Write a single byte at the current position. pub fn write_byte(&mut self, byte: u8) { let write_ptr = self.get_write_ptr(); - if !self.has_capacity(1) || self.mem_block.borrow_mut().write_byte(write_ptr, byte).is_err() { + if self.has_capacity(1) && self.mem_block.borrow_mut().write_byte(write_ptr, byte).is_ok() { + self.write_pos += 1; + } else { self.dropped_bytes = true; } - - // Always advance write_pos since arm64 PadEntryExit needs this to stop the loop. - self.write_pos += 1; } /// Write multiple bytes starting from the current position. @@ -489,10 +488,11 @@ impl CodeBlock { self.label_refs.push(LabelRef { pos: self.write_pos, label_idx, num_bytes, encode }); // Move past however many bytes the instruction takes up - if !self.has_capacity(num_bytes) { + if self.has_capacity(num_bytes) { + self.write_pos += num_bytes; + } else { self.dropped_bytes = true; // retry emitting the Insn after next_page } - self.write_pos += num_bytes; } // Link internal label references diff --git a/yjit/src/backend/arm64/mod.rs b/yjit/src/backend/arm64/mod.rs index ce1dd2e43c..c899f6871f 100644 --- a/yjit/src/backend/arm64/mod.rs +++ b/yjit/src/backend/arm64/mod.rs @@ -1028,7 +1028,7 @@ impl Assembler } Insn::LiveReg { .. } => (), // just a reg alloc signal, no code Insn::PadInvalPatch => { - while (cb.get_write_pos().saturating_sub(std::cmp::max(start_write_pos, cb.page_start_pos()))) < JMP_PTR_BYTES { + while (cb.get_write_pos().saturating_sub(std::cmp::max(start_write_pos, cb.page_start_pos()))) < JMP_PTR_BYTES && !cb.has_dropped_bytes() { nop(cb); } } |