Skip to content

Commit f331137

Browse files
miladfarcav8-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
PPC: Fix safepoint record
This patch is needed after http://crrev.com/c/7899697 started failing this test intermittently during GC on pntr compressed debug builds: ``` === mjsunit/compiler/regress-crbug-1464516 === --- stderr --- # # Fatal error in ../../src/objects/tagged-impl.h, line 138 # Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_)). ``` PPC could emit a trampoline pool right after `MacroAssembler::Call` returns which could make any subsequent `DefineSafepoint` calls record the incorrect `pc_offset` as it then points to after the emitted pool. This CL patches every "MacroAssembler::Call" site to record the pc_offset before the trampoline pool is emitted similar to how it's done on riscv. It's essentially porting the following changes to PPC: f385232 2c6618f Change-Id: I2095bce8b69b0c4f064117ed95ee2f3245436e62 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7918866 Reviewed-by: Darius Mercadier <[email protected]> Reviewed-by: John <[email protected]> Commit-Queue: Milad Farazmand <[email protected]> Cr-Commit-Position: refs/heads/main@{#107921}
1 parent d212697 commit f331137

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎src/codegen/assembler.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,12 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced {
393393

394394
void skip_bytes(int num_bytes) { pc_ += num_bytes; }
395395

396-
// MIPS, LOONG, and RISC-V need to use their own implementations to avoid the
397-
// influence of branch trampolines. They provide their implementations in the
398-
// architecture-specific assembler subclasses.
399-
#if !defined(V8_TARGET_ARCH_MIPS64) && !defined(V8_TARGET_ARCH_LOONG64) && \
400-
!defined(V8_TARGET_ARCH_RISCV32) && !defined(V8_TARGET_ARCH_RISCV64)
396+
// MIPS, LOONG, RISC-V, and PPC64 need to use their own implementations to avoid
397+
// the influence of branch trampolines. They provide their implementations in
398+
// the architecture-specific assembler subclasses.
399+
#if !defined(V8_TARGET_ARCH_MIPS64) && !defined(V8_TARGET_ARCH_LOONG64) && \
400+
!defined(V8_TARGET_ARCH_RISCV32) && !defined(V8_TARGET_ARCH_RISCV64) && \
401+
!defined(V8_TARGET_ARCH_PPC64)
401402
int pc_offset_for_safepoint() const { return pc_offset(); }
402403
#endif
403404

‎src/codegen/ppc/assembler-ppc.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ class Assembler : public AssemblerBase {
209209
// Unused on this architecture.
210210
void ClearInternalState() {}
211211

212+
// On PPC64, we sometimes need to emit branch trampolines between emitting
213+
// a call instruction (bctrl) and recording a safepoint. This means that
214+
// we have to be careful to make sure the safepoint is recorded at the right
215+
// position. So we record the pc right after emitting the call instruction
216+
// and use this for the safepoint.
217+
int pc_offset_for_safepoint() const { return pc_offset_for_safepoint_; }
218+
212219
inline void CheckTrampolinePoolQuick(int extra_space = 0) {
213220
if (pc_offset() >= next_trampoline_check_ - extra_space) {
214221
CheckTrampolinePool();
@@ -1381,6 +1388,8 @@ class Assembler : public AssemblerBase {
13811388

13821389
// Record reloc info for current pc_
13831390
void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
1391+
1392+
void RecordPcForSafepoint() { pc_offset_for_safepoint_ = pc_offset(); }
13841393
ConstantPoolEntry::Access ConstantPoolAddEntry(RelocInfo::Mode rmode,
13851394
intptr_t value) {
13861395
bool sharing_ok =
@@ -1459,6 +1468,11 @@ class Assembler : public AssemblerBase {
14591468

14601469
// The bound position, before this we cannot do instruction elimination.
14611470
int last_bound_pos_;
1471+
1472+
// Keep track of the last call instruction (bctrl/bl) position to ensure that
1473+
// we can generate a correct safepoint even in the presence of a branch
1474+
// trampoline between emitting the call and recording the safepoint.
1475+
int pc_offset_for_safepoint_ = -1;
14621476
// Optimizable cmpi information.
14631477
int optimizable_cmpi_pos_;
14641478
CRegister cmpi_cr_ = CRegister::no_reg();

‎src/codegen/ppc/macro-assembler-ppc.cc‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ void MacroAssembler::Call(Register target) {
261261
// branch via link register and set LK bit for return point
262262
mtctr(target);
263263
bctrl();
264+
RecordPcForSafepoint();
264265
}
265266

266267
void MacroAssembler::CallJSEntry(Register target) {
@@ -288,6 +289,7 @@ void MacroAssembler::Call(Address target, RelocInfo::Mode rmode,
288289
mov(ip, Operand(target, rmode));
289290
mtctr(ip);
290291
bctrl();
292+
RecordPcForSafepoint();
291293
}
292294

293295
void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
@@ -421,7 +423,10 @@ Operand MacroAssembler::ClearedValue() const {
421423
return Operand(static_cast<int32_t>(i::kClearedWeakValue.ptr()));
422424
}
423425

424-
void MacroAssembler::Call(Label* target) { b(target, SetLK); }
426+
void MacroAssembler::Call(Label* target) {
427+
b(target, SetLK);
428+
RecordPcForSafepoint();
429+
}
425430

426431
void MacroAssembler::Push(Handle<HeapObject> handle) {
427432
mov(r0, Operand(handle));

0 commit comments

Comments
 (0)