diff options
Diffstat (limited to 'deps/v8/src/init/isolate-allocator.cc')
-rw-r--r-- | deps/v8/src/init/isolate-allocator.cc | 110 |
1 files changed, 17 insertions, 93 deletions
diff --git a/deps/v8/src/init/isolate-allocator.cc b/deps/v8/src/init/isolate-allocator.cc index b7b98804b0..e80a332d09 100644 --- a/deps/v8/src/init/isolate-allocator.cc +++ b/deps/v8/src/init/isolate-allocator.cc @@ -5,6 +5,7 @@ #include "src/init/isolate-allocator.h" #include "src/base/bounded-page-allocator.h" +#include "src/common/ptr-compr-inl.h" #include "src/execution/isolate.h" #include "src/heap/code-range.h" #include "src/sandbox/sandbox.h" @@ -15,42 +16,21 @@ namespace v8 { namespace internal { #ifdef V8_COMPRESS_POINTERS -namespace { - -// "IsolateRootBiasPage" is an optional region before the 4Gb aligned -// reservation. This "IsolateRootBiasPage" page is supposed to be used for -// storing part of the Isolate object when Isolate::isolate_root_bias() is -// not zero. -inline size_t GetIsolateRootBiasPageSize( - v8::PageAllocator* platform_page_allocator) { - return RoundUp(Isolate::isolate_root_bias(), - platform_page_allocator->AllocatePageSize()); -} - -} // namespace - struct PtrComprCageReservationParams : public VirtualMemoryCage::ReservationParams { PtrComprCageReservationParams() { page_allocator = GetPlatformPageAllocator(); - // This is only used when there is a per-Isolate cage, in which case the - // Isolate is allocated within the cage, and the Isolate root is also the - // cage base. - const size_t kIsolateRootBiasPageSize = - COMPRESS_POINTERS_IN_ISOLATE_CAGE_BOOL - ? GetIsolateRootBiasPageSize(page_allocator) - : 0; - reservation_size = kPtrComprCageReservationSize + kIsolateRootBiasPageSize; + reservation_size = kPtrComprCageReservationSize; base_alignment = kPtrComprCageBaseAlignment; - base_bias_size = kIsolateRootBiasPageSize; // Simplify BoundedPageAllocator's life by configuring it to use same page // size as the Heap will use (MemoryChunk::kPageSize). page_size = RoundUp(size_t{1} << kPageSizeBits, page_allocator->AllocatePageSize()); - requested_start_hint = - reinterpret_cast<Address>(page_allocator->GetRandomMmapAddr()); + requested_start_hint = RoundDown( + reinterpret_cast<Address>(page_allocator->GetRandomMmapAddr()), + base_alignment); jit = JitPermission::kNoJit; } }; @@ -63,8 +43,7 @@ DEFINE_LAZY_LEAKY_OBJECT_GETTER(VirtualMemoryCage, GetProcessWidePtrComprCage) // static void IsolateAllocator::FreeProcessWidePtrComprCageForTesting() { - if (std::shared_ptr<CodeRange> code_range = - CodeRange::GetProcessWideCodeRange()) { + if (CodeRange* code_range = CodeRange::GetProcessWideCodeRange()) { code_range->Free(); } GetProcessWidePtrComprCage()->Free(); @@ -94,7 +73,14 @@ void IsolateAllocator::InitializeOncePerProcess() { "Failed to reserve virtual memory for process-wide V8 " "pointer compression cage"); } -#endif + V8HeapCompressionScheme::InitBase(GetProcessWidePtrComprCage()->base()); +#ifdef V8_EXTERNAL_CODE_SPACE + // Speculatively set the code cage base to the same value in case jitless + // mode will be used. Once the process-wide CodeRange instance is created + // the code cage base will be set accordingly. + ExternalCodeCompressionScheme::InitBase(V8HeapCompressionScheme::base()); +#endif // V8_EXTERNAL_CODE_SPACE +#endif // V8_COMPRESS_POINTERS_IN_SHARED_CAGE } IsolateAllocator::IsolateAllocator() { @@ -106,30 +92,20 @@ IsolateAllocator::IsolateAllocator() { "Failed to reserve memory for Isolate V8 pointer compression cage"); } page_allocator_ = isolate_ptr_compr_cage_.page_allocator(); - CommitPagesForIsolate(); #elif defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE) - // Allocate Isolate in C++ heap when sharing a cage. CHECK(GetProcessWidePtrComprCage()->IsReserved()); page_allocator_ = GetProcessWidePtrComprCage()->page_allocator(); - isolate_memory_ = ::operator new(sizeof(Isolate)); #else - // Allocate Isolate in C++ heap. page_allocator_ = GetPlatformPageAllocator(); - isolate_memory_ = ::operator new(sizeof(Isolate)); #endif // V8_COMPRESS_POINTERS + // Allocate Isolate in C++ heap. + isolate_memory_ = ::operator new(sizeof(Isolate)); + CHECK_NOT_NULL(page_allocator_); } IsolateAllocator::~IsolateAllocator() { -#ifdef V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE - if (isolate_ptr_compr_cage_.reservation()->IsReserved()) { - // The actual memory will be freed when the |isolate_ptr_compr_cage_| will - // die. - return; - } -#endif - // The memory was allocated in C++ heap. ::operator delete(isolate_memory_); } @@ -148,57 +124,5 @@ const VirtualMemoryCage* IsolateAllocator::GetPtrComprCage() const { return const_cast<IsolateAllocator*>(this)->GetPtrComprCage(); } -#ifdef V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE -void IsolateAllocator::CommitPagesForIsolate() { - v8::PageAllocator* platform_page_allocator = GetPlatformPageAllocator(); - - CHECK(isolate_ptr_compr_cage_.IsReserved()); - Address isolate_root = isolate_ptr_compr_cage_.base(); - CHECK(IsAligned(isolate_root, kPtrComprCageBaseAlignment)); - CHECK_GE(isolate_ptr_compr_cage_.reservation()->size(), - kPtrComprCageReservationSize + - GetIsolateRootBiasPageSize(platform_page_allocator)); - CHECK(isolate_ptr_compr_cage_.reservation()->InVM( - isolate_root, kPtrComprCageReservationSize)); - - size_t page_size = page_allocator_->AllocatePageSize(); - Address isolate_address = isolate_root - Isolate::isolate_root_bias(); - Address isolate_end = isolate_address + sizeof(Isolate); - - // Inform the bounded page allocator about reserved pages. - { - Address reserved_region_address = isolate_root; - size_t reserved_region_size = - RoundUp(isolate_end, page_size) - reserved_region_address; - - CHECK(isolate_ptr_compr_cage_.page_allocator()->AllocatePagesAt( - reserved_region_address, reserved_region_size, - PageAllocator::Permission::kNoAccess)); - } - - // Commit pages where the Isolate will be stored. - { - size_t commit_page_size = platform_page_allocator->CommitPageSize(); - Address committed_region_address = - RoundDown(isolate_address, commit_page_size); - size_t committed_region_size = - RoundUp(isolate_end, commit_page_size) - committed_region_address; - - // We are using |isolate_ptr_compr_cage_.reservation()| directly here - // because |page_allocator_| has bigger commit page size than we actually - // need. - CHECK(isolate_ptr_compr_cage_.reservation()->SetPermissions( - committed_region_address, committed_region_size, - PageAllocator::kReadWrite)); - - if (Heap::ShouldZapGarbage()) { - MemsetPointer(reinterpret_cast<Address*>(committed_region_address), - kZapValue, committed_region_size / kSystemPointerSize); - } - } - isolate_memory_ = reinterpret_cast<void*>(isolate_address); -} -#endif // V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE - } // namespace internal } // namespace v8 |