From 8a6b841721c6caa92905e764092a83582271adb3 Mon Sep 17 00:00:00 2001 From: Leszek Swirski Date: Mon, 6 Feb 2023 16:12:41 +0100 Subject: [PATCH] [maglev] Use B instead of b on arm64 `MacroAssembler::B` registers its labels with the veneer pool, while `Assembler::b` doesn't. This meant that our JumpIf (used in particular for deopts) could run out of jump distance. As a drive by, also limit the maximum number of deopts according to the limit set by the deoptimizer. This turned out to not be the issue, but we should also do it. Bug: v8:7700 Change-Id: Ic5a8dd3b69c995375d7caab008f31ae91d9c732d Fixed: chromium:1410080 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4224931 Commit-Queue: Leszek Swirski Auto-Submit: Leszek Swirski Reviewed-by: Victor Gomes Cr-Commit-Position: refs/heads/main@{#85686} --- src/maglev/arm64/maglev-assembler-arm64-inl.h | 2 +- src/maglev/arm64/maglev-assembler-arm64.cc | 2 +- src/maglev/maglev-code-generator.cc | 11 +++++++++++ src/maglev/maglev-code-generator.h | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/maglev/arm64/maglev-assembler-arm64-inl.h b/src/maglev/arm64/maglev-assembler-arm64-inl.h index 893738b5ad..ac9d48f1f6 100644 --- a/src/maglev/arm64/maglev-assembler-arm64-inl.h +++ b/src/maglev/arm64/maglev-assembler-arm64-inl.h @@ -581,7 +581,7 @@ inline void MaglevAssembler::Jump(Label* target, Label::Distance) { B(target); } inline void MaglevAssembler::JumpIf(Condition cond, Label* target, Label::Distance) { - b(target, cond); + B(target, cond); } inline void MaglevAssembler::JumpIfRoot(Register with, RootIndex index, diff --git a/src/maglev/arm64/maglev-assembler-arm64.cc b/src/maglev/arm64/maglev-assembler-arm64.cc index 77fef9a488..0a06876a12 100644 --- a/src/maglev/arm64/maglev-assembler-arm64.cc +++ b/src/maglev/arm64/maglev-assembler-arm64.cc @@ -423,7 +423,7 @@ void MaglevAssembler::Prologue(Graph* graph) { Push(xzr, xzr); } Subs(count, count, Immediate(1)); - b(&loop, gt); + B(&loop, gt); } } if (remaining_stack_slots > 0) { diff --git a/src/maglev/maglev-code-generator.cc b/src/maglev/maglev-code-generator.cc index e9706c7387..166fb886a9 100644 --- a/src/maglev/maglev-code-generator.cc +++ b/src/maglev/maglev-code-generator.cc @@ -17,6 +17,7 @@ #include "src/common/globals.h" #include "src/compiler/backend/instruction.h" #include "src/deoptimizer/deoptimize-reason.h" +#include "src/deoptimizer/deoptimizer.h" #include "src/deoptimizer/translation-array.h" #include "src/execution/frame-constants.h" #include "src/interpreter/bytecode-register.h" @@ -1240,6 +1241,7 @@ void MaglevCodeGenerator::EmitCode() { processor.ProcessGraph(graph_); EmitDeferredCode(); EmitDeopts(); + if (code_gen_failed_) return; EmitExceptionHandlerTrampolines(); __ FinishCode(); } @@ -1258,6 +1260,13 @@ void MaglevCodeGenerator::EmitDeferredCode() { } void MaglevCodeGenerator::EmitDeopts() { + const size_t num_deopts = code_gen_state_.eager_deopts().size() + + code_gen_state_.lazy_deopts().size(); + if (num_deopts > Deoptimizer::kMaxNumberOfEntries) { + code_gen_failed_ = true; + return; + } + MaglevTranslationArrayBuilder translation_builder( local_isolate_, &masm_, &translation_array_builder_, &deopt_literals_); @@ -1351,6 +1360,8 @@ void MaglevCodeGenerator::EmitMetadata() { } MaybeHandle MaglevCodeGenerator::BuildCodeObject(Isolate* isolate) { + if (code_gen_failed_) return {}; + CodeDesc desc; masm()->GetCode(isolate, &desc, &safepoint_table_builder_, handler_table_offset_); diff --git a/src/maglev/maglev-code-generator.h b/src/maglev/maglev-code-generator.h index 719e2d1154..5966903d41 100644 --- a/src/maglev/maglev-code-generator.h +++ b/src/maglev/maglev-code-generator.h @@ -55,6 +55,8 @@ class MaglevCodeGenerator final { IdentityMap deopt_literals_; int deopt_exit_start_offset_ = -1; int handler_table_offset_ = 0; + + bool code_gen_failed_ = false; }; } // namespace maglev