From 3ba66cd26a1eda249c93c637c7aa6b40adf8dec3 Mon Sep 17 00:00:00 2001 From: Igor Sheludko Date: Wed, 25 May 2022 21:01:04 +0200 Subject: [PATCH] [ext-code-space][arm64] Increase max code range size to 256Mb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... when external code space is enabled. Since we are using near jump/call instruction only for [tail]calling builtins, we can increase the code range as long as we can guarantee that the remapped builtins are always reachable. We can do that by remapping embedded builtins into the middle of the code range. Bug: v8:11880, v8:12689 Change-Id: I69901634586df3c35618ea7bd5311102e4675f6c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3669107 Reviewed-by: Dominik Inführ Commit-Queue: Igor Sheludko Cr-Commit-Position: refs/heads/main@{#80810} --- src/common/globals.h | 3 ++- src/heap/code-range.cc | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/common/globals.h b/src/common/globals.h index c79a9d01e5..4443f92c82 100644 --- a/src/common/globals.h +++ b/src/common/globals.h @@ -304,7 +304,8 @@ constexpr bool kPlatformRequiresCodeRange = true; constexpr size_t kMaximalCodeRangeSize = 512 * MB; constexpr size_t kMinExpectedOSPageSize = 64 * KB; // OS page on PPC Linux #elif V8_TARGET_ARCH_ARM64 -constexpr size_t kMaximalCodeRangeSize = 128 * MB; +constexpr size_t kMaximalCodeRangeSize = + V8_EXTERNAL_CODE_SPACE_BOOL ? 256 * MB : 128 * MB; constexpr size_t kMinExpectedOSPageSize = 4 * KB; // OS page. #else constexpr size_t kMaximalCodeRangeSize = diff --git a/src/heap/code-range.cc b/src/heap/code-range.cc index 889f7f8dba..badef8e17f 100644 --- a/src/heap/code-range.cc +++ b/src/heap/code-range.cc @@ -6,6 +6,7 @@ #include "src/base/bits.h" #include "src/base/lazy-instance.h" +#include "src/codegen/constants-arch.h" #include "src/common/globals.h" #include "src/flags/flags.h" #include "src/heap/heap-inl.h" @@ -204,8 +205,13 @@ uint8_t* CodeRange::RemapEmbeddedBuiltins(Isolate* isolate, size_t allocate_code_size = RoundUp(embedded_blob_code_size, kAllocatePageSize); - // Allocate the re-embedded code blob in the end. - void* hint = reinterpret_cast(code_region.end() - allocate_code_size); + // Allocate the re-embedded code blob in such a way that it will be reachable + // by PC-relative addressing from biggest possible region. + const size_t max_pc_relative_code_range = kMaxPCRelativeCodeRangeInMB * MB; + size_t hint_offset = + std::min(max_pc_relative_code_range, code_region.size()) - + allocate_code_size; + void* hint = reinterpret_cast(code_region.begin() + hint_offset); embedded_blob_code_copy = reinterpret_cast(page_allocator()->AllocatePages( @@ -216,6 +222,25 @@ uint8_t* CodeRange::RemapEmbeddedBuiltins(Isolate* isolate, V8::FatalProcessOutOfMemory( isolate, "Can't allocate space for re-embedded builtins"); } + CHECK_EQ(embedded_blob_code_copy, hint); + + if (code_region.size() > max_pc_relative_code_range) { + // The re-embedded code blob might not be reachable from the end part of + // the code range, so ensure that code pages will never be allocated in + // the "unreachable" area. + Address unreachable_start = + reinterpret_cast
(embedded_blob_code_copy) + + max_pc_relative_code_range; + + if (code_region.contains(unreachable_start)) { + size_t unreachable_size = code_region.end() - unreachable_start; + + void* result = page_allocator()->AllocatePages( + reinterpret_cast(unreachable_start), unreachable_size, + kAllocatePageSize, PageAllocator::kNoAccess); + CHECK_EQ(reinterpret_cast
(result), unreachable_start); + } + } size_t code_size = RoundUp(embedded_blob_code_size, kCommitPageSize); if constexpr (base::OS::IsRemapPageSupported()) {