Commit 3e546664 authored by Maciej Goszczycki's avatar Maciej Goszczycki Committed by Commit Bot

[roheap] Move read_only_heap() from heap to isolate

Once read-only space is not a Heap space it makes little sense to have
it in the Heap class.

Bug: v8:7464
Change-Id: I2230ce7cbf1cec3c83065c91bc14a9c23f72478b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1688841Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Maciej Goszczycki <goszczycki@google.com>
Cr-Commit-Position: refs/heads/master@{#62540}
parent 347092ac
......@@ -2864,6 +2864,13 @@ void Isolate::Delete(Isolate* isolate) {
SetIsolateThreadLocals(saved_isolate, saved_data);
}
void Isolate::SetUpFromReadOnlyHeap(ReadOnlyHeap* ro_heap) {
DCHECK_NOT_NULL(ro_heap);
DCHECK_IMPLIES(read_only_heap_ != nullptr, read_only_heap_ == ro_heap);
read_only_heap_ = ro_heap;
heap_.SetUpFromReadOnlyHeap(ro_heap);
}
v8::PageAllocator* Isolate::page_allocator() {
return isolate_allocator_->page_allocator();
}
......@@ -3456,7 +3463,7 @@ bool Isolate::Init(ReadOnlyDeserializer* read_only_deserializer,
if (create_heap_objects) {
heap_.read_only_space()->ClearStringPaddingIfNeeded();
heap_.read_only_heap()->OnCreateHeapObjectsComplete(this);
read_only_heap_->OnCreateHeapObjectsComplete(this);
} else {
startup_deserializer->DeserializeInto(this);
}
......
......@@ -517,6 +517,8 @@ class Isolate final : private HiddenFactory {
// for legacy API reasons.
static void Delete(Isolate* isolate);
void SetUpFromReadOnlyHeap(ReadOnlyHeap* ro_heap);
// Returns allocation mode of this isolate.
V8_INLINE IsolateAllocationMode isolate_allocation_mode();
......@@ -902,6 +904,7 @@ class Isolate final : private HiddenFactory {
}
StackGuard* stack_guard() { return &stack_guard_; }
Heap* heap() { return &heap_; }
ReadOnlyHeap* read_only_heap() const { return read_only_heap_; }
static Isolate* FromHeap(Heap* heap) {
return reinterpret_cast<Isolate*>(reinterpret_cast<Address>(heap) -
OFFSET_OF(Isolate, heap_));
......@@ -1652,6 +1655,7 @@ class Isolate final : private HiddenFactory {
std::unique_ptr<IsolateAllocator> isolate_allocator_;
Heap heap_;
ReadOnlyHeap* read_only_heap_ = nullptr;
const int id_;
EntryStackItem* entry_stack_ = nullptr;
......
......@@ -3,10 +3,16 @@
// found in the LICENSE file.
#include "src/heap/combined-heap.h"
#include "src/heap/heap-inl.h"
namespace v8 {
namespace internal {
CombinedHeapObjectIterator::CombinedHeapObjectIterator(
Heap* heap, HeapObjectIterator::HeapObjectsFiltering filtering)
: heap_iterator_(heap, filtering),
ro_heap_iterator_(heap->isolate()->read_only_heap()) {}
HeapObject CombinedHeapObjectIterator::Next() {
HeapObject object = ro_heap_iterator_.Next();
if (!object.is_null()) {
......
......@@ -20,9 +20,7 @@ class V8_EXPORT_PRIVATE CombinedHeapObjectIterator final {
public:
CombinedHeapObjectIterator(
Heap* heap, HeapObjectIterator::HeapObjectsFiltering filtering =
HeapObjectIterator::HeapObjectsFiltering::kNoFiltering)
: heap_iterator_(heap, filtering),
ro_heap_iterator_(heap->read_only_heap()) {}
HeapObjectIterator::HeapObjectsFiltering::kNoFiltering);
HeapObject Next();
private:
......
......@@ -4950,7 +4950,6 @@ void Heap::SetUpFromReadOnlyHeap(ReadOnlyHeap* ro_heap) {
DCHECK_NOT_NULL(ro_heap);
DCHECK_IMPLIES(read_only_space_ != nullptr,
read_only_space_ == ro_heap->read_only_space());
read_only_heap_ = ro_heap;
space_[RO_SPACE] = read_only_space_ = ro_heap->read_only_space();
}
......@@ -5236,7 +5235,7 @@ void Heap::TearDown() {
tracer_.reset();
read_only_heap_->OnHeapTearDown();
isolate()->read_only_heap()->OnHeapTearDown();
space_[RO_SPACE] = read_only_space_ = nullptr;
for (int i = FIRST_MUTABLE_SPACE; i <= LAST_MUTABLE_SPACE; i++) {
delete space_[i];
......
......@@ -677,8 +677,6 @@ class Heap {
// Getters to other components. ==============================================
// ===========================================================================
ReadOnlyHeap* read_only_heap() const { return read_only_heap_; }
GCTracer* tracer() { return tracer_.get(); }
MemoryAllocator* memory_allocator() { return memory_allocator_.get(); }
......@@ -1864,8 +1862,6 @@ class Heap {
// and after context disposal.
int number_of_disposed_maps_ = 0;
ReadOnlyHeap* read_only_heap_ = nullptr;
NewSpace* new_space_ = nullptr;
OldSpace* old_space_ = nullptr;
CodeSpace* code_space_ = nullptr;
......
......@@ -63,7 +63,7 @@ void ReadOnlyHeap::SetUp(Isolate* isolate, ReadOnlyDeserializer* des) {
}
#endif // DEBUG
isolate->heap()->SetUpFromReadOnlyHeap(shared_ro_heap_);
isolate->SetUpFromReadOnlyHeap(shared_ro_heap_);
if (des != nullptr) {
void* const isolate_ro_roots = reinterpret_cast<void*>(
isolate->roots_table().read_only_roots_begin().address());
......@@ -91,7 +91,7 @@ void ReadOnlyHeap::OnCreateHeapObjectsComplete(Isolate* isolate) {
// static
ReadOnlyHeap* ReadOnlyHeap::CreateAndAttachToIsolate(Isolate* isolate) {
auto* ro_heap = new ReadOnlyHeap(new ReadOnlySpace(isolate->heap()));
isolate->heap()->SetUpFromReadOnlyHeap(ro_heap);
isolate->SetUpFromReadOnlyHeap(ro_heap);
return ro_heap;
}
......
......@@ -819,8 +819,7 @@ TSlot Deserializer::ReadDataCase(Isolate* isolate, TSlot current,
} else if (bytecode == kReadOnlyObjectCache) {
int cache_index = source_.GetInt();
heap_object = HeapObject::cast(
isolate->heap()->read_only_heap()->cached_read_only_object(
cache_index));
isolate->read_only_heap()->cached_read_only_object(cache_index));
DCHECK(!Heap::InYoungGeneration(heap_object));
emit_write_barrier = false;
} else if (bytecode == kPartialSnapshotCache) {
......
......@@ -21,7 +21,7 @@ void ReadOnlyDeserializer::DeserializeInto(Isolate* isolate) {
V8::FatalProcessOutOfMemory(isolate, "ReadOnlyDeserializer");
}
ReadOnlyHeap* ro_heap = isolate->heap()->read_only_heap();
ReadOnlyHeap* ro_heap = isolate->read_only_heap();
// No active threads.
DCHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse());
......
......@@ -67,7 +67,7 @@ void ReadOnlySerializer::FinalizeSerialization() {
#ifdef DEBUG
// Check that every object on read-only heap is reachable (and was
// serialized).
ReadOnlyHeapObjectIterator iterator(isolate()->heap()->read_only_heap());
ReadOnlyHeapObjectIterator iterator(isolate()->read_only_heap());
for (HeapObject object = iterator.Next(); !object.is_null();
object = iterator.Next()) {
CHECK(serialized_objects_.count(object));
......
......@@ -121,7 +121,9 @@ void CcTest::Run() {
}
i::Heap* CcTest::heap() { return i_isolate()->heap(); }
i::ReadOnlyHeap* CcTest::read_only_heap() { return heap()->read_only_heap(); }
i::ReadOnlyHeap* CcTest::read_only_heap() {
return i_isolate()->read_only_heap();
}
void CcTest::CollectGarbage(i::AllocationSpace space) {
heap()->CollectGarbage(space, i::GarbageCollectionReason::kTesting);
......
......@@ -27,7 +27,7 @@ TEST(HeapObjectIteratorNullPastEnd) {
}
TEST(ReadOnlyHeapObjectIteratorNullPastEnd) {
ReadOnlyHeapObjectIterator iterator(CcTest::heap()->read_only_heap());
ReadOnlyHeapObjectIterator iterator(CcTest::read_only_heap());
while (!iterator.Next().is_null()) {
}
for (int i = 0; i < 20; i++) {
......
......@@ -110,6 +110,8 @@ static int DumpHeapConstants(const char* argv0) {
{
Isolate::Scope scope(isolate);
i::Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap();
i::ReadOnlyHeap* read_only_heap =
reinterpret_cast<i::Isolate*>(isolate)->read_only_heap();
i::PrintF("%s", kHeader);
#define DUMP_TYPE(T) i::PrintF(" %d: \"%s\",\n", i::T, #T);
i::PrintF("INSTANCE_TYPES = {\n");
......@@ -121,7 +123,7 @@ static int DumpHeapConstants(const char* argv0) {
// Dump the KNOWN_MAP table to the console.
i::PrintF("\n# List of known V8 maps.\n");
i::PrintF("KNOWN_MAPS = {\n");
i::ReadOnlyHeapObjectIterator ro_iterator(heap->read_only_heap());
i::ReadOnlyHeapObjectIterator ro_iterator(read_only_heap);
for (i::HeapObject object = ro_iterator.Next(); !object.is_null();
object = ro_iterator.Next()) {
if (!object.IsMap()) continue;
......@@ -140,7 +142,7 @@ static int DumpHeapConstants(const char* argv0) {
// Dump the KNOWN_OBJECTS table to the console.
i::PrintF("\n# List of known V8 objects.\n");
i::PrintF("KNOWN_OBJECTS = {\n");
i::ReadOnlyHeapObjectIterator ro_iterator(heap->read_only_heap());
i::ReadOnlyHeapObjectIterator ro_iterator(read_only_heap);
for (i::HeapObject object = ro_iterator.Next(); !object.is_null();
object = ro_iterator.Next()) {
// Skip read-only heap maps, they will be reported elsewhere.
......
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