ruby-changes:74329
From: Takashi <ko1@a...>
Date: Fri, 4 Nov 2022 00:42:46 +0900 (JST)
Subject: [ruby-changes:74329] 68ef97d788 (master): YJIT: Stop incrementing write_pos if cb.has_dropped_bytes (#6664)
https://git.ruby-lang.org/ruby.git/commit/?id=68ef97d788 From 68ef97d788cf8bff42d981bda41cd26128220740 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Thu, 3 Nov 2022 08:42:28 -0700 Subject: YJIT: Stop incrementing write_pos if cb.has_dropped_bytes (#6664) Co-Authored-By: Alan Wu <alansi.xingwu@s...> Co-authored-by: Alan Wu <alansi.xingwu@s...> --- yjit/src/asm/mod.rs | 12 ++++++------ 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 { https://github.com/ruby/ruby/blob/trunk/yjit/src/asm/mod.rs#L418 /// 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 { https://github.com/ruby/ruby/blob/trunk/yjit/src/asm/mod.rs#L488 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 https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L1028 } 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); } } -- cgit v1.2.3 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/