Commit b5e9b829 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr] Add a header for pointer compression related code

Bug: v8:7703
Change-Id: I96fd746291aa2e1386ed40068d38f5140bb1e44f
Reviewed-on: https://chromium-review.googlesource.com/c/1342031Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57612}
parent b76bf22c
......@@ -2410,6 +2410,7 @@ v8_source_set("v8_base") {
"src/property.cc",
"src/property.h",
"src/prototype.h",
"src/ptr-compr.h",
"src/regexp/bytecodes-irregexp.h",
"src/regexp/interpreter-irregexp.cc",
"src/regexp/interpreter-irregexp.h",
......
......@@ -5,6 +5,7 @@
#include "src/isolate-allocator.h"
#include "src/base/bounded-page-allocator.h"
#include "src/isolate.h"
#include "src/ptr-compr.h"
#include "src/utils.h"
namespace v8 {
......@@ -43,15 +44,15 @@ Address IsolateAllocator::InitReservation() {
// Reserve a 4Gb region so that the middle is 4Gb aligned.
// The VirtualMemory API does not support such an constraint so we have to
// implement it manually here.
size_t reservation_size = size_t{4} * GB;
size_t base_alignment = size_t{4} * GB;
size_t reservation_size = kPtrComprHeapReservationSize;
size_t base_alignment = kPtrComprIsolateRootAlignment;
const int kMaxAttempts = 3;
for (int attempt = 0; attempt < kMaxAttempts; ++attempt) {
Address hint = RoundDown(reinterpret_cast<Address>(
platform_page_allocator->GetRandomMmapAddr()),
base_alignment) +
base_alignment / 2;
kPtrComprIsolateRootBias;
// Within this reservation there will be a sub-region with proper alignment.
VirtualMemory padded_reservation(platform_page_allocator,
......@@ -62,9 +63,9 @@ Address IsolateAllocator::InitReservation() {
// Find such a sub-region inside the reservation that it's middle is
// |base_alignment|-aligned.
Address address =
RoundUp(padded_reservation.address() + reservation_size / 2,
RoundUp(padded_reservation.address() + kPtrComprIsolateRootBias,
base_alignment) -
reservation_size / 2;
kPtrComprIsolateRootBias;
CHECK(padded_reservation.InVM(address, reservation_size));
// Now free the padded reservation and immediately try to reserve an exact
......@@ -81,8 +82,9 @@ Address IsolateAllocator::InitReservation() {
// The reservation could still be somewhere else but we can accept it
// if the reservation has the required alignment.
Address aligned_address =
RoundUp(reservation.address() + reservation_size / 2, base_alignment) -
reservation_size / 2;
RoundUp(reservation.address() + kPtrComprIsolateRootBias,
base_alignment) -
kPtrComprIsolateRootBias;
if (reservation.address() == aligned_address) {
reservation_ = std::move(reservation);
......@@ -96,7 +98,7 @@ Address IsolateAllocator::InitReservation() {
CHECK_EQ(reservation_.size(), reservation_size);
Address heap_base = reservation_.address() + reservation_size / 2;
Address heap_base = reservation_.address() + kPtrComprIsolateRootBias;
CHECK(IsAligned(heap_base, base_alignment));
return heap_base;
......
......@@ -52,6 +52,7 @@
#include "src/objects/stack-frame-info-inl.h"
#include "src/profiler/tracing-cpu-profiler.h"
#include "src/prototype.h"
#include "src/ptr-compr.h"
#include "src/regexp/regexp-stack.h"
#include "src/runtime-profiler.h"
#include "src/setup-isolate.h"
......@@ -2728,8 +2729,9 @@ Isolate* Isolate::New(IsolateAllocationMode mode) {
void* isolate_ptr = isolate_allocator->isolate_memory();
Isolate* isolate = new (isolate_ptr) Isolate(std::move(isolate_allocator));
#ifdef V8_TARGET_ARCH_64_BIT
DCHECK_IMPLIES(mode == IsolateAllocationMode::kInV8Heap,
IsAligned(isolate->isolate_root(), size_t{4} * GB));
DCHECK_IMPLIES(
mode == IsolateAllocationMode::kInV8Heap,
IsAligned(isolate->isolate_root(), kPtrComprIsolateRootAlignment));
#endif
#ifdef DEBUG
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_PTR_COMPR_H_
#define V8_PTR_COMPR_H_
#if V8_TARGET_ARCH_64_BIT
#include "src/globals.h"
namespace v8 {
namespace internal {
constexpr size_t kPtrComprHeapReservationSize = size_t{4} * GB;
constexpr size_t kPtrComprIsolateRootBias = kPtrComprHeapReservationSize / 2;
constexpr size_t kPtrComprIsolateRootAlignment = size_t{4} * GB;
} // namespace internal
} // namespace v8
#endif // V8_TARGET_ARCH_64_BIT
#endif // V8_PTR_COMPR_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment