Commit 04beaf63 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[roheap][ptr-compr] Move ReadOnlyHeap::GetReadOnlyRoots() to inl file

The implementation is already quite trivial and in addition in case of
ptr-compr this implementation becomes even simpler and C++ compiler
gets the opportunity to hoist common computation of isolate root.

Tbr: yangguo@chromium.org
Bug: v8:7464, v8:7703
Change-Id: I6e59cd43253c9ade5a0e27025ea7fabecd5b7af7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1647171
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62024}
parent 5a39c2d6
......@@ -2264,6 +2264,7 @@ v8_source_set("v8_base_without_compiler") {
"src/heap/objects-visiting-inl.h",
"src/heap/objects-visiting.cc",
"src/heap/objects-visiting.h",
"src/heap/read-only-heap-inl.h",
"src/heap/read-only-heap.cc",
"src/heap/read-only-heap.h",
"src/heap/remembered-set.h",
......
......@@ -16,6 +16,7 @@ include_rules = [
"+src/heap/heap-inl.h",
"+src/heap/heap-write-barrier-inl.h",
"+src/heap/heap-write-barrier.h",
"+src/heap/read-only-heap-inl.h",
"+src/heap/read-only-heap.h",
"-src/inspector",
"-src/interpreter",
......
// Copyright 2019 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_HEAP_READ_ONLY_HEAP_INL_H_
#define V8_HEAP_READ_ONLY_HEAP_INL_H_
#include "src/heap/read-only-heap.h"
#include "src/heap/heap-write-barrier-inl.h"
#include "src/roots/roots-inl.h"
namespace v8 {
namespace internal {
// static
ReadOnlyRoots ReadOnlyHeap::GetReadOnlyRoots(HeapObject object) {
#ifdef V8_SHARED_RO_HEAP
// This fails if we are creating heap objects and the roots haven't yet been
// copied into the read-only heap or it has been cleared for testing.
if (shared_ro_heap_ != nullptr && shared_ro_heap_->init_complete_) {
return ReadOnlyRoots(shared_ro_heap_->read_only_roots_);
}
#endif
return ReadOnlyRoots(GetHeapFromWritableObject(object));
}
} // namespace internal
} // namespace v8
#endif // V8_HEAP_READ_ONLY_HEAP_INL_H_
......@@ -21,7 +21,7 @@ namespace internal {
#ifdef V8_SHARED_RO_HEAP
V8_DECLARE_ONCE(setup_ro_heap_once);
ReadOnlyHeap* shared_ro_heap = nullptr;
ReadOnlyHeap* ReadOnlyHeap::shared_ro_heap_ = nullptr;
#endif
// static
......@@ -32,18 +32,18 @@ void ReadOnlyHeap::SetUp(Isolate* isolate, ReadOnlyDeserializer* des) {
// we would be trying to create heap objects inside an already initialized
// read-only space. Use ClearSharedHeapForTest if you need a new read-only
// space.
DCHECK_IMPLIES(shared_ro_heap != nullptr, des != nullptr);
DCHECK_IMPLIES(shared_ro_heap_ != nullptr, des != nullptr);
base::CallOnce(&setup_ro_heap_once, [isolate, des]() {
shared_ro_heap = CreateAndAttachToIsolate(isolate);
if (des != nullptr) shared_ro_heap->DeseralizeIntoIsolate(isolate, des);
shared_ro_heap_ = CreateAndAttachToIsolate(isolate);
if (des != nullptr) shared_ro_heap_->DeseralizeIntoIsolate(isolate, des);
});
isolate->heap()->SetUpFromReadOnlyHeap(shared_ro_heap);
isolate->heap()->SetUpFromReadOnlyHeap(shared_ro_heap_);
if (des != nullptr) {
void* const isolate_ro_roots = reinterpret_cast<void*>(
isolate->roots_table().read_only_roots_begin().address());
std::memcpy(isolate_ro_roots, shared_ro_heap->read_only_roots_,
std::memcpy(isolate_ro_roots, shared_ro_heap_->read_only_roots_,
kEntriesCount * sizeof(Address));
}
#else
......@@ -98,10 +98,10 @@ void ReadOnlyHeap::OnHeapTearDown() {
// static
void ReadOnlyHeap::ClearSharedHeapForTest() {
#ifdef V8_SHARED_RO_HEAP
DCHECK_NOT_NULL(shared_ro_heap);
DCHECK_NOT_NULL(shared_ro_heap_);
// TODO(v8:7464): Just leak read-only space for now. The paged-space heap
// is null so there isn't a nice way to do this.
shared_ro_heap = nullptr;
shared_ro_heap_ = nullptr;
setup_ro_heap_once = 0;
#endif
}
......@@ -111,18 +111,6 @@ bool ReadOnlyHeap::Contains(HeapObject object) {
return MemoryChunk::FromHeapObject(object)->InReadOnlySpace();
}
// static
ReadOnlyRoots ReadOnlyHeap::GetReadOnlyRoots(HeapObject object) {
#ifdef V8_SHARED_RO_HEAP
// This fails if we are creating heap objects and the roots haven't yet been
// copied into the read-only heap or it has been cleared for testing.
if (shared_ro_heap != nullptr && shared_ro_heap->init_complete_) {
return ReadOnlyRoots(shared_ro_heap->read_only_roots_);
}
#endif
return ReadOnlyRoots(GetHeapFromWritableObject(object));
}
Object* ReadOnlyHeap::ExtendReadOnlyObjectCache() {
read_only_object_cache_.push_back(Smi::kZero);
return &read_only_object_cache_.back();
......
......@@ -44,7 +44,8 @@ class ReadOnlyHeap final {
// Gets read-only roots from an appropriate root list: shared read-only root
// list if the shared read-only heap has been initialized or the isolate
// specific roots table.
V8_EXPORT_PRIVATE static ReadOnlyRoots GetReadOnlyRoots(HeapObject object);
V8_EXPORT_PRIVATE inline static ReadOnlyRoots GetReadOnlyRoots(
HeapObject object);
// Clears any shared read-only heap artifacts for testing, forcing read-only
// heap to be re-created on next set up.
......@@ -77,6 +78,8 @@ class ReadOnlyHeap final {
#ifdef V8_SHARED_RO_HEAP
Address read_only_roots_[kEntriesCount];
V8_EXPORT_PRIVATE static ReadOnlyHeap* shared_ro_heap_;
#endif
explicit ReadOnlyHeap(ReadOnlySpace* ro_space) : read_only_space_(ro_space) {}
......
......@@ -20,6 +20,7 @@
#include "src/handles/handles-inl.h"
#include "src/heap/factory.h"
#include "src/heap/heap-write-barrier-inl.h"
#include "src/heap/read-only-heap-inl.h"
#include "src/numbers/conversions.h"
#include "src/numbers/double.h"
#include "src/objects/bigint.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