diff --git a/runtime/vm/benchmark_test.cc b/runtime/vm/benchmark_test.cc index 4b34e20abcb..83cd23f7c14 100644 --- a/runtime/vm/benchmark_test.cc +++ b/runtime/vm/benchmark_test.cc @@ -521,7 +521,7 @@ BENCHMARK_SIZE(CoreSnapshotSize) { // Write snapshot with object content. FullSnapshotWriter writer(Snapshot::kCore, &vm_snapshot_data_buffer, &isolate_snapshot_data_buffer, &malloc_allocator, - NULL, NULL /* instructions_writer */); + NULL, NULL /* image_writer */); writer.WriteFullSnapshot(); const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer); @@ -559,7 +559,7 @@ BENCHMARK_SIZE(StandaloneSnapshotSize) { // Write snapshot with object content. FullSnapshotWriter writer(Snapshot::kCore, &vm_snapshot_data_buffer, &isolate_snapshot_data_buffer, &malloc_allocator, - NULL, NULL /* instructions_writer */); + NULL, NULL /* image_writer */); writer.WriteFullSnapshot(); const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer); diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc index 40e8987152f..9929c3d49f4 100644 --- a/runtime/vm/clustered_snapshot.cc +++ b/runtime/vm/clustered_snapshot.cc @@ -4466,13 +4466,13 @@ Serializer::Serializer(Thread* thread, uint8_t** buffer, ReAlloc alloc, intptr_t initial_size, - InstructionsWriter* instructions_writer) + ImageWriter* image_writer) : StackResource(thread), heap_(thread->isolate()->heap()), zone_(thread->zone()), kind_(kind), stream_(buffer, alloc, initial_size), - instructions_writer_(instructions_writer), + image_writer_(image_writer), clusters_by_cid_(NULL), stack_(), num_cids_(0), @@ -5280,13 +5280,12 @@ class SnapshotTokenStreamVisitor : public ObjectVisitor { }; -FullSnapshotWriter::FullSnapshotWriter( - Snapshot::Kind kind, - uint8_t** vm_snapshot_data_buffer, - uint8_t** isolate_snapshot_data_buffer, - ReAlloc alloc, - InstructionsWriter* vm_instructions_writer, - InstructionsWriter* isolate_instructions_writer) +FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind, + uint8_t** vm_snapshot_data_buffer, + uint8_t** isolate_snapshot_data_buffer, + ReAlloc alloc, + ImageWriter* vm_image_writer, + ImageWriter* isolate_image_writer) : thread_(Thread::Current()), kind_(kind), vm_snapshot_data_buffer_(vm_snapshot_data_buffer), @@ -5294,8 +5293,8 @@ FullSnapshotWriter::FullSnapshotWriter( alloc_(alloc), vm_isolate_snapshot_size_(0), isolate_snapshot_size_(0), - vm_instructions_writer_(vm_instructions_writer), - isolate_instructions_writer_(isolate_instructions_writer), + vm_image_writer_(vm_image_writer), + isolate_image_writer_(isolate_image_writer), token_streams_(Array::Handle(zone())), saved_symbol_table_(Array::Handle(zone())), new_vm_symbol_table_(Array::Handle(zone())), @@ -5369,7 +5368,7 @@ intptr_t FullSnapshotWriter::WriteVMSnapshot() { ASSERT(vm_snapshot_data_buffer_ != NULL); Serializer serializer(thread(), kind_, vm_snapshot_data_buffer_, alloc_, - kInitialSize, vm_instructions_writer_); + kInitialSize, vm_image_writer_); serializer.ReserveHeader(); serializer.WriteVersionAndFeatures(); @@ -5383,10 +5382,10 @@ intptr_t FullSnapshotWriter::WriteVMSnapshot() { clustered_vm_size_ = serializer.bytes_written(); if (Snapshot::IncludesCode(kind_)) { - vm_instructions_writer_->Write(serializer.stream(), true); - mapped_data_size_ += vm_instructions_writer_->data_size(); - mapped_instructions_size_ += vm_instructions_writer_->text_size(); - vm_instructions_writer_->ResetOffsets(); + vm_image_writer_->Write(serializer.stream(), true); + mapped_data_size_ += vm_image_writer_->data_size(); + mapped_instructions_size_ += vm_image_writer_->text_size(); + vm_image_writer_->ResetOffsets(); } // The clustered part + the direct mapped data part. @@ -5400,7 +5399,7 @@ void FullSnapshotWriter::WriteIsolateSnapshot(intptr_t num_base_objects) { thread(), Timeline::GetIsolateStream(), "WriteIsolateSnapshot")); Serializer serializer(thread(), kind_, isolate_snapshot_data_buffer_, alloc_, - kInitialSize, isolate_instructions_writer_); + kInitialSize, isolate_image_writer_); ObjectStore* object_store = isolate()->object_store(); ASSERT(object_store != NULL); @@ -5413,10 +5412,10 @@ void FullSnapshotWriter::WriteIsolateSnapshot(intptr_t num_base_objects) { clustered_isolate_size_ = serializer.bytes_written(); if (Snapshot::IncludesCode(kind_)) { - isolate_instructions_writer_->Write(serializer.stream(), false); - mapped_data_size_ += isolate_instructions_writer_->data_size(); - mapped_instructions_size_ += isolate_instructions_writer_->text_size(); - isolate_instructions_writer_->ResetOffsets(); + isolate_image_writer_->Write(serializer.stream(), false); + mapped_data_size_ += isolate_image_writer_->data_size(); + mapped_instructions_size_ += isolate_image_writer_->text_size(); + isolate_image_writer_->ResetOffsets(); } // The clustered part + the direct mapped data part. @@ -5481,9 +5480,11 @@ RawApiError* FullSnapshotReader::ReadVMSnapshot() { if (Snapshot::IncludesCode(kind_)) { ASSERT(instructions_buffer_ != NULL); - thread_->isolate()->SetupInstructionsSnapshotPage(instructions_buffer_); + thread_->isolate()->SetupImagePage(instructions_buffer_, + /* is_executable */ true); ASSERT(data_buffer_ != NULL); - thread_->isolate()->SetupDataSnapshotPage(data_buffer_); + thread_->isolate()->SetupImagePage(data_buffer_, + /* is_executable */ false); } deserializer.ReadVMSnapshot(); @@ -5503,9 +5504,11 @@ RawApiError* FullSnapshotReader::ReadIsolateSnapshot() { if (Snapshot::IncludesCode(kind_)) { ASSERT(instructions_buffer_ != NULL); - thread_->isolate()->SetupInstructionsSnapshotPage(instructions_buffer_); + thread_->isolate()->SetupImagePage(instructions_buffer_, + /* is_executable */ true); ASSERT(data_buffer_ != NULL); - thread_->isolate()->SetupDataSnapshotPage(data_buffer_); + thread_->isolate()->SetupImagePage(data_buffer_, + /* is_executable */ false); } deserializer.ReadIsolateSnapshot(thread_->isolate()->object_store()); diff --git a/runtime/vm/clustered_snapshot.h b/runtime/vm/clustered_snapshot.h index f6ef6fbf6e2..e110f74e001 100644 --- a/runtime/vm/clustered_snapshot.h +++ b/runtime/vm/clustered_snapshot.h @@ -119,7 +119,7 @@ class Serializer : public StackResource { uint8_t** buffer, ReAlloc alloc, intptr_t initial_size, - InstructionsWriter* instructions_writer_); + ImageWriter* image_writer_); ~Serializer(); intptr_t WriteVMSnapshot(const Array& symbols, const Array& scripts); @@ -259,11 +259,11 @@ class Serializer : public StackResource { } int32_t GetTextOffset(RawInstructions* instr, RawCode* code) { - return instructions_writer_->GetOffsetFor(instr, code); + return image_writer_->GetOffsetFor(instr, code); } int32_t GetRODataOffset(RawObject* object) { - return instructions_writer_->GetObjectOffsetFor(object); + return image_writer_->GetObjectOffsetFor(object); } Snapshot::Kind kind() const { return kind_; } @@ -273,7 +273,7 @@ class Serializer : public StackResource { Zone* zone_; Snapshot::Kind kind_; WriteStream stream_; - InstructionsWriter* instructions_writer_; + ImageWriter* image_writer_; SerializationCluster** clusters_by_cid_; GrowableArray stack_; intptr_t num_cids_; @@ -392,8 +392,8 @@ class FullSnapshotWriter { uint8_t** vm_snapshot_data_buffer, uint8_t** isolate_snapshot_data_buffer, ReAlloc alloc, - InstructionsWriter* vm_instructions_writer, - InstructionsWriter* iso_instructions_writer); + ImageWriter* vm_image_writer, + ImageWriter* iso_image_writer); ~FullSnapshotWriter(); uint8_t** vm_snapshot_data_buffer() const { return vm_snapshot_data_buffer_; } @@ -428,8 +428,8 @@ class FullSnapshotWriter { intptr_t vm_isolate_snapshot_size_; intptr_t isolate_snapshot_size_; ForwardList* forward_list_; - InstructionsWriter* vm_instructions_writer_; - InstructionsWriter* isolate_instructions_writer_; + ImageWriter* vm_image_writer_; + ImageWriter* isolate_image_writer_; Array& token_streams_; Array& saved_symbol_table_; Array& new_vm_symbol_table_; diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index bd29493e904..2b4b954e9d9 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -1600,8 +1600,8 @@ Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer, FullSnapshotWriter writer(Snapshot::kCore, vm_snapshot_data_buffer, isolate_snapshot_data_buffer, ApiReallocate, - NULL /* vm_instructions_writer */, - NULL /* isolate_instructions_writer */); + NULL /* vm_image_writer */, + NULL /* isolate_image_writer */); writer.WriteFullSnapshot(); if (vm_snapshot_data_buffer != NULL) { *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); @@ -6658,16 +6658,16 @@ Dart_CreateAppAOTSnapshotAsAssembly(uint8_t** assembly_buffer, NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), "WriteAppAOTSnapshot")); - AssemblyInstructionsWriter instructions_writer(assembly_buffer, ApiReallocate, - 2 * MB /* initial_size */); + AssemblyImageWriter image_writer(assembly_buffer, ApiReallocate, + 2 * MB /* initial_size */); uint8_t* vm_snapshot_data_buffer = NULL; uint8_t* isolate_snapshot_data_buffer = NULL; FullSnapshotWriter writer(Snapshot::kAppAOT, &vm_snapshot_data_buffer, &isolate_snapshot_data_buffer, ApiReallocate, - &instructions_writer, &instructions_writer); + &image_writer, &image_writer); writer.WriteFullSnapshot(); - *assembly_size = instructions_writer.AssemblySize(); + *assembly_size = image_writer.AssemblySize(); return Api::Success(); #endif @@ -6727,23 +6727,21 @@ Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_snapshot_data_buffer, NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), "WriteAppAOTSnapshot")); - BlobInstructionsWriter vm_instructions_writer(vm_snapshot_instructions_buffer, - ApiReallocate, - 2 * MB /* initial_size */); - BlobInstructionsWriter isolate_instructions_writer( - isolate_snapshot_instructions_buffer, ApiReallocate, - 2 * MB /* initial_size */); - FullSnapshotWriter writer( - Snapshot::kAppAOT, vm_snapshot_data_buffer, isolate_snapshot_data_buffer, - ApiReallocate, &vm_instructions_writer, &isolate_instructions_writer); + BlobImageWriter vm_image_writer(vm_snapshot_instructions_buffer, + ApiReallocate, 2 * MB /* initial_size */); + BlobImageWriter isolate_image_writer(isolate_snapshot_instructions_buffer, + ApiReallocate, + 2 * MB /* initial_size */); + FullSnapshotWriter writer(Snapshot::kAppAOT, vm_snapshot_data_buffer, + isolate_snapshot_data_buffer, ApiReallocate, + &vm_image_writer, &isolate_image_writer); writer.WriteFullSnapshot(); *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); - *vm_snapshot_instructions_size = - vm_instructions_writer.InstructionsBlobSize(); + *vm_snapshot_instructions_size = vm_image_writer.InstructionsBlobSize(); *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); *isolate_snapshot_instructions_size = - isolate_instructions_writer.InstructionsBlobSize(); + isolate_image_writer.InstructionsBlobSize(); return Api::Success(); #endif @@ -6792,17 +6790,17 @@ Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer, NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), "WriteAppJITSnapshot")); - BlobInstructionsWriter isolate_instructions_writer( - isolate_snapshot_instructions_buffer, ApiReallocate, - 2 * MB /* initial_size */); + BlobImageWriter isolate_image_writer(isolate_snapshot_instructions_buffer, + ApiReallocate, + 2 * MB /* initial_size */); FullSnapshotWriter writer(Snapshot::kAppJIT, NULL, isolate_snapshot_data_buffer, ApiReallocate, NULL, - &isolate_instructions_writer); + &isolate_image_writer); writer.WriteFullSnapshot(); *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); *isolate_snapshot_instructions_size = - isolate_instructions_writer.InstructionsBlobSize(); + isolate_image_writer.InstructionsBlobSize(); return Api::Success(); #endif diff --git a/runtime/vm/gc_sweeper.cc b/runtime/vm/gc_sweeper.cc index 609afb9aa9e..738e1b874ef 100644 --- a/runtime/vm/gc_sweeper.cc +++ b/runtime/vm/gc_sweeper.cc @@ -16,7 +16,7 @@ namespace dart { bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) { - if (page->embedder_allocated()) { + if (page->is_image_page()) { // Don't clear mark bits. return true; } diff --git a/runtime/vm/heap.cc b/runtime/vm/heap.cc index 4c9b73b1eb2..d8ce15740a9 100644 --- a/runtime/vm/heap.cc +++ b/runtime/vm/heap.cc @@ -189,14 +189,14 @@ void Heap::VisitObjects(ObjectVisitor* visitor) const { } -void Heap::VisitObjectsNoExternalPages(ObjectVisitor* visitor) const { +void Heap::VisitObjectsNoImagePages(ObjectVisitor* visitor) const { new_space_.VisitObjects(visitor); - old_space_.VisitObjectsNoExternalPages(visitor); + old_space_.VisitObjectsNoImagePages(visitor); } -void Heap::VisitObjectsExternalPages(ObjectVisitor* visitor) const { - old_space_.VisitObjectsExternalPages(visitor); +void Heap::VisitObjectsImagePages(ObjectVisitor* visitor) const { + old_space_.VisitObjectsImagePages(visitor); } @@ -258,9 +258,9 @@ void Heap::IterateOldObjects(ObjectVisitor* visitor) const { } -void Heap::IterateOldObjectsNoExternalPages(ObjectVisitor* visitor) const { +void Heap::IterateOldObjectsNoImagePages(ObjectVisitor* visitor) const { HeapIterationScope heap_iteration_scope; - old_space_.VisitObjectsNoExternalPages(visitor); + old_space_.VisitObjectsNoImagePages(visitor); } @@ -531,12 +531,12 @@ ObjectSet* Heap::CreateAllocatedObjectSet( { VerifyObjectVisitor object_visitor(isolate(), allocated_set, mark_expectation); - this->VisitObjectsNoExternalPages(&object_visitor); + this->VisitObjectsNoImagePages(&object_visitor); } { VerifyObjectVisitor object_visitor(isolate(), allocated_set, kRequireMarked); - this->VisitObjectsExternalPages(&object_visitor); + this->VisitObjectsImagePages(&object_visitor); } Isolate* vm_isolate = Dart::vm_isolate(); diff --git a/runtime/vm/heap.h b/runtime/vm/heap.h index 5cd6fc41129..80265fceb33 100644 --- a/runtime/vm/heap.h +++ b/runtime/vm/heap.h @@ -92,7 +92,7 @@ class Heap { void IterateObjects(ObjectVisitor* visitor) const; void IterateOldObjects(ObjectVisitor* visitor) const; - void IterateOldObjectsNoExternalPages(ObjectVisitor* visitor) const; + void IterateOldObjectsNoImagePages(ObjectVisitor* visitor) const; void IterateObjectPointers(ObjectVisitor* visitor) const; // Find an object by visiting all pointers in the specified heap space, @@ -245,8 +245,8 @@ class Heap { Monitor* barrier() const { return barrier_; } Monitor* barrier_done() const { return barrier_done_; } - void SetupExternalPage(void* pointer, uword size, bool is_executable) { - old_space_.SetupExternalPage(pointer, size, is_executable); + void SetupImagePage(void* pointer, uword size, bool is_executable) { + old_space_.SetupImagePage(pointer, size, is_executable); } private: @@ -296,8 +296,8 @@ class Heap { // Visit all objects, including FreeListElement "objects". Caller must ensure // concurrent sweeper is not running, and the visitor must not allocate. void VisitObjects(ObjectVisitor* visitor) const; - void VisitObjectsNoExternalPages(ObjectVisitor* visitor) const; - void VisitObjectsExternalPages(ObjectVisitor* visitor) const; + void VisitObjectsNoImagePages(ObjectVisitor* visitor) const; + void VisitObjectsImagePages(ObjectVisitor* visitor) const; // Like Verify, but does not wait for concurrent sweeper, so caller must // ensure thread-safety. diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc index 120b1d353b1..c2a4e54bc72 100644 --- a/runtime/vm/isolate.cc +++ b/runtime/vm/isolate.cc @@ -998,35 +998,10 @@ Thread* Isolate::mutator_thread() const { } -void Isolate::SetupInstructionsSnapshotPage( - const uint8_t* instructions_snapshot_buffer) { - InstructionsSnapshot snapshot(instructions_snapshot_buffer); -#if defined(DEBUG) - if (FLAG_trace_isolates) { - OS::Print("Precompiled instructions are at [0x%" Px ", 0x%" Px ")\n", - reinterpret_cast(snapshot.instructions_start()), - reinterpret_cast(snapshot.instructions_start()) + - snapshot.instructions_size()); - } -#endif - heap_->SetupExternalPage(snapshot.instructions_start(), - snapshot.instructions_size(), - /* is_executable = */ true); -} - - -void Isolate::SetupDataSnapshotPage(const uint8_t* data_snapshot_buffer) { - DataSnapshot snapshot(data_snapshot_buffer); -#if defined(DEBUG) - if (FLAG_trace_isolates) { - OS::Print( - "Precompiled rodata are at [0x%" Px ", 0x%" Px ")\n", - reinterpret_cast(snapshot.data_start()), - reinterpret_cast(snapshot.data_start()) + snapshot.data_size()); - } -#endif - heap_->SetupExternalPage(snapshot.data_start(), snapshot.data_size(), - /* is_executable = */ false); +void Isolate::SetupImagePage(const uint8_t* image_buffer, bool is_executable) { + Image image(image_buffer); + heap_->SetupImagePage(image.object_start(), image.object_size(), + is_executable); } diff --git a/runtime/vm/isolate.h b/runtime/vm/isolate.h index dcdf8288c08..fe4da0816b6 100644 --- a/runtime/vm/isolate.h +++ b/runtime/vm/isolate.h @@ -254,9 +254,7 @@ class Isolate : public BaseIsolate { library_tag_handler_ = value; } - void SetupInstructionsSnapshotPage( - const uint8_t* instructions_snapshot_buffer); - void SetupDataSnapshotPage(const uint8_t* instructions_snapshot_buffer); + void SetupImagePage(const uint8_t* snapshot_buffer, bool is_executable); void ScheduleMessageInterrupts(); diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 389132ed78c..865e67f08b2 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -1051,8 +1051,9 @@ void Object::FinalizeVMIsolate(Isolate* isolate) { WritableVMIsolateScope scope(Thread::Current()); PremarkingVisitor premarker; ASSERT(isolate->heap()->UsedInWords(Heap::kNew) == 0); - isolate->heap()->IterateOldObjectsNoExternalPages(&premarker); + isolate->heap()->IterateOldObjectsNoImagePages(&premarker); // Make the VM isolate read-only again after setting all objects as marked. + // Note objects in image pages are already pre-marked. } } diff --git a/runtime/vm/object.h b/runtime/vm/object.h index fdfb693d220..d010ec3da83 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -4219,8 +4219,8 @@ class Instructions : public Object { FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); friend class Class; friend class Code; - friend class AssemblyInstructionsWriter; - friend class BlobInstructionsWriter; + friend class AssemblyImageWriter; + friend class BlobImageWriter; }; diff --git a/runtime/vm/object_graph.cc b/runtime/vm/object_graph.cc index 89f2dd8a220..cd9fdeef36e 100644 --- a/runtime/vm/object_graph.cc +++ b/runtime/vm/object_graph.cc @@ -149,7 +149,7 @@ class Unmarker : public ObjectVisitor { static void UnmarkAll(Isolate* isolate) { Unmarker unmarker; - isolate->heap()->VisitObjectsNoExternalPages(&unmarker); + isolate->heap()->VisitObjectsNoImagePages(&unmarker); } private: @@ -213,7 +213,7 @@ void ObjectGraph::IterateObjectsFrom(intptr_t class_id, Stack stack(isolate()); InstanceAccumulator accumulator(&stack, class_id); - isolate()->heap()->VisitObjectsNoExternalPages(&accumulator); + isolate()->heap()->VisitObjectsNoImagePages(&accumulator); stack.TraverseGraph(visitor); Unmarker::UnmarkAll(isolate()); diff --git a/runtime/vm/pages.cc b/runtime/vm/pages.cc index 287d4cf6a4e..9768bc5f251 100644 --- a/runtime/vm/pages.cc +++ b/runtime/vm/pages.cc @@ -93,9 +93,9 @@ HeapPage* HeapPage::Allocate(intptr_t size_in_words, PageType type) { void HeapPage::Deallocate() { - bool is_embedder_allocated = embedder_allocated(); + bool image_page = is_image_page(); - if (!is_embedder_allocated) { + if (!image_page) { LSAN_UNREGISTER_ROOT_REGION(this, sizeof(*this)); } @@ -105,7 +105,7 @@ void HeapPage::Deallocate() { // For a heap page from a snapshot, the HeapPage object lives in the malloc // heap rather than the page itself. - if (is_embedder_allocated) { + if (image_page) { free(this); } } @@ -156,7 +156,7 @@ RawObject* HeapPage::FindObject(FindObjectVisitor* visitor) const { void HeapPage::WriteProtect(bool read_only) { - ASSERT(!embedder_allocated()); + ASSERT(!is_image_page()); VirtualMemory::Protection prot; if (read_only) { @@ -251,11 +251,11 @@ HeapPage* PageSpace::AllocatePage(HeapPage::PageType type) { if (exec_pages_ == NULL) { exec_pages_ = page; } else { - if (FLAG_write_protect_code && !exec_pages_tail_->embedder_allocated()) { + if (FLAG_write_protect_code && !exec_pages_tail_->is_image_page()) { exec_pages_tail_->WriteProtect(false); } exec_pages_tail_->set_next(page); - if (FLAG_write_protect_code && !exec_pages_tail_->embedder_allocated()) { + if (FLAG_write_protect_code && !exec_pages_tail_->is_image_page()) { exec_pages_tail_->WriteProtect(true); } } @@ -643,18 +643,18 @@ void PageSpace::VisitObjects(ObjectVisitor* visitor) const { } -void PageSpace::VisitObjectsNoExternalPages(ObjectVisitor* visitor) const { +void PageSpace::VisitObjectsNoImagePages(ObjectVisitor* visitor) const { for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { - if (!it.page()->embedder_allocated()) { + if (!it.page()->is_image_page()) { it.page()->VisitObjects(visitor); } } } -void PageSpace::VisitObjectsExternalPages(ObjectVisitor* visitor) const { +void PageSpace::VisitObjectsImagePages(ObjectVisitor* visitor) const { for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { - if (it.page()->embedder_allocated()) { + if (it.page()->is_image_page()) { it.page()->VisitObjects(visitor); } } @@ -708,7 +708,7 @@ void PageSpace::WriteProtect(bool read_only) { AbandonBumpAllocation(); } for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { - if (!it.page()->embedder_allocated()) { + if (!it.page()->is_image_page()) { it.page()->WriteProtect(read_only); } } @@ -828,15 +828,14 @@ void PageSpace::WriteProtectCode(bool read_only) { HeapPage* page = exec_pages_; while (page != NULL) { ASSERT(page->type() == HeapPage::kExecutable); - if (!page->embedder_allocated()) { + if (!page->is_image_page()) { page->WriteProtect(read_only); } page = page->next(); } page = large_pages_; while (page != NULL) { - if (page->type() == HeapPage::kExecutable && - !page->embedder_allocated()) { + if (page->type() == HeapPage::kExecutable && !page->is_image_page()) { page->WriteProtect(read_only); } page = page->next(); @@ -1098,9 +1097,7 @@ uword PageSpace::TryAllocatePromoLocked(intptr_t size, } -void PageSpace::SetupExternalPage(void* pointer, - uword size, - bool is_executable) { +void PageSpace::SetupImagePage(void* pointer, uword size, bool is_executable) { // Setup a HeapPage so precompiled Instructions can be traversed. // Instructions are contiguous at [pointer, pointer + size). HeapPage // expects to find objects at [memory->start() + ObjectStartOffset, @@ -1109,7 +1106,7 @@ void PageSpace::SetupExternalPage(void* pointer, pointer = reinterpret_cast(reinterpret_cast(pointer) - offset); size += offset; - VirtualMemory* memory = VirtualMemory::ForExternalPage(pointer, size); + VirtualMemory* memory = VirtualMemory::ForImagePage(pointer, size); ASSERT(memory != NULL); HeapPage* page = reinterpret_cast(malloc(sizeof(HeapPage))); page->memory_ = memory; @@ -1131,13 +1128,11 @@ void PageSpace::SetupExternalPage(void* pointer, if (*first == NULL) { *first = page; } else { - if (is_executable && FLAG_write_protect_code && - !(*tail)->embedder_allocated()) { + if (is_executable && FLAG_write_protect_code && !(*tail)->is_image_page()) { (*tail)->WriteProtect(false); } (*tail)->set_next(page); - if (is_executable && FLAG_write_protect_code && - !(*tail)->embedder_allocated()) { + if (is_executable && FLAG_write_protect_code && !(*tail)->is_image_page()) { (*tail)->WriteProtect(true); } } diff --git a/runtime/vm/pages.h b/runtime/vm/pages.h index 289e05d0b34..0cf4388cbfd 100644 --- a/runtime/vm/pages.h +++ b/runtime/vm/pages.h @@ -40,7 +40,7 @@ class HeapPage { PageType type() const { return type_; } - bool embedder_allocated() const { return memory_->embedder_allocated(); } + bool is_image_page() const { return !memory_->vm_owns_region(); } void VisitObjects(ObjectVisitor* visitor) const; void VisitObjectPointers(ObjectPointerVisitor* visitor) const; @@ -231,8 +231,8 @@ class PageSpace { bool IsValidAddress(uword addr) const { return Contains(addr); } void VisitObjects(ObjectVisitor* visitor) const; - void VisitObjectsNoExternalPages(ObjectVisitor* visitor) const; - void VisitObjectsExternalPages(ObjectVisitor* visitor) const; + void VisitObjectsNoImagePages(ObjectVisitor* visitor) const; + void VisitObjectsImagePages(ObjectVisitor* visitor) const; void VisitObjectPointers(ObjectPointerVisitor* visitor) const; RawObject* FindObject(FindObjectVisitor* visitor, @@ -318,7 +318,7 @@ class PageSpace { static intptr_t top_offset() { return OFFSET_OF(PageSpace, bump_top_); } static intptr_t end_offset() { return OFFSET_OF(PageSpace, bump_end_); } - void SetupExternalPage(void* pointer, uword size, bool is_executable); + void SetupImagePage(void* pointer, uword size, bool is_executable); private: // Ids for time and data records in Heap::GCStats. diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h index a3edb301136..b6945186ce4 100644 --- a/runtime/vm/raw_object.h +++ b/runtime/vm/raw_object.h @@ -609,9 +609,9 @@ class RawObject { friend class RetainingPathVisitor; // GetClassId friend class SkippedCodeFunctions; // StorePointer friend class InstructionsReader; // tags_ check - friend class InstructionsWriter; - friend class AssemblyInstructionsWriter; - friend class BlobInstructionsWriter; + friend class ImageWriter; + friend class AssemblyImageWriter; + friend class BlobImageWriter; friend class SnapshotReader; friend class Deserializer; friend class SnapshotWriter; @@ -1214,7 +1214,7 @@ class RawInstructions : public RawObject { friend class SkippedCodeFunctions; friend class Function; friend class InstructionsReader; - friend class InstructionsWriter; + friend class ImageWriter; }; diff --git a/runtime/vm/snapshot.cc b/runtime/vm/snapshot.cc index 669df78bd8b..97f0d847dcd 100644 --- a/runtime/vm/snapshot.cc +++ b/runtime/vm/snapshot.cc @@ -679,8 +679,8 @@ RawObject* SnapshotReader::NewInteger(int64_t value) { } -int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions, - RawCode* code) { +int32_t ImageWriter::GetOffsetFor(RawInstructions* instructions, + RawCode* code) { #if defined(PRODUCT) // Instructions are only dedup in product mode because it obfuscates profiler // results. @@ -700,7 +700,7 @@ int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions, } -int32_t InstructionsWriter::GetObjectOffsetFor(RawObject* raw_object) { +int32_t ImageWriter::GetObjectOffsetFor(RawObject* raw_object) { intptr_t heap_size = raw_object->Size(); intptr_t offset = next_object_offset_; next_object_offset_ += heap_size; @@ -709,7 +709,7 @@ int32_t InstructionsWriter::GetObjectOffsetFor(RawObject* raw_object) { } -void InstructionsWriter::Write(WriteStream* clustered_stream, bool vm) { +void ImageWriter::Write(WriteStream* clustered_stream, bool vm) { Thread* thread = Thread::Current(); Zone* zone = thread->zone(); NOT_IN_PRODUCT(TimelineDurationScope tds(thread, Timeline::GetIsolateStream(), @@ -735,7 +735,7 @@ void InstructionsWriter::Write(WriteStream* clustered_stream, bool vm) { } -void InstructionsWriter::WriteROData(WriteStream* stream) { +void ImageWriter::WriteROData(WriteStream* stream) { stream->Align(OS::kMaxPreferredCodeAlignment); // Heap page starts here. @@ -778,8 +778,7 @@ static void EnsureIdentifier(char* label) { } -void AssemblyInstructionsWriter::WriteText(WriteStream* clustered_stream, - bool vm) { +void AssemblyImageWriter::WriteText(WriteStream* clustered_stream, bool vm) { Zone* zone = Thread::Current()->zone(); const char* instructions_symbol = @@ -795,7 +794,7 @@ void AssemblyInstructionsWriter::WriteText(WriteStream* clustered_stream, // look like a HeapPage. intptr_t instructions_length = next_offset_; WriteWordLiteralText(instructions_length); - intptr_t header_words = InstructionsSnapshot::kHeaderSize / sizeof(uword); + intptr_t header_words = Image::kHeaderSize / sizeof(uword); for (intptr_t i = 1; i < header_words; i++) { WriteWordLiteralText(0); } @@ -896,12 +895,12 @@ void AssemblyInstructionsWriter::WriteText(WriteStream* clustered_stream, } -void BlobInstructionsWriter::WriteText(WriteStream* clustered_stream, bool vm) { +void BlobImageWriter::WriteText(WriteStream* clustered_stream, bool vm) { // This header provides the gap to make the instructions snapshot look like a // HeapPage. intptr_t instructions_length = next_offset_; instructions_blob_stream_.WriteWord(instructions_length); - intptr_t header_words = InstructionsSnapshot::kHeaderSize / sizeof(uword); + intptr_t header_words = Image::kHeaderSize / sizeof(uword); for (intptr_t i = 1; i < header_words; i++) { instructions_blob_stream_.WriteWord(0); } diff --git a/runtime/vm/snapshot.h b/runtime/vm/snapshot.h index 400a479960d..487aaa990b2 100644 --- a/runtime/vm/snapshot.h +++ b/runtime/vm/snapshot.h @@ -211,19 +211,18 @@ class Snapshot { }; -class InstructionsSnapshot : ValueObject { +class Image : ValueObject { public: - explicit InstructionsSnapshot(const void* raw_memory) - : raw_memory_(raw_memory) { + explicit Image(const void* raw_memory) : raw_memory_(raw_memory) { ASSERT(Utils::IsAligned(raw_memory, OS::kMaxPreferredCodeAlignment)); } - void* instructions_start() { + void* object_start() { return reinterpret_cast(reinterpret_cast(raw_memory_) + kHeaderSize); } - uword instructions_size() { + uword object_size() { uword snapshot_size = *reinterpret_cast(raw_memory_); return snapshot_size - kHeaderSize; } @@ -233,34 +232,7 @@ class InstructionsSnapshot : ValueObject { private: const void* raw_memory_; // The symbol kInstructionsSnapshot. - DISALLOW_COPY_AND_ASSIGN(InstructionsSnapshot); -}; - - -class DataSnapshot : ValueObject { - public: - explicit DataSnapshot(const void* raw_memory) : raw_memory_(raw_memory) { - ASSERT(Utils::IsAligned(raw_memory, 2 * kWordSize)); // kObjectAlignment - } - - void* data_start() { - return reinterpret_cast(reinterpret_cast(raw_memory_) + - kHeaderSize); - } - - uword data_size() { - uword snapshot_size = *reinterpret_cast(raw_memory_); - return snapshot_size - kHeaderSize; - } - - // Header: data length and padding for alignment. We use the same alignment - // as for code for now. - static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; - - private: - const void* raw_memory_; // The symbol kDataSnapshot. - - DISALLOW_COPY_AND_ASSIGN(DataSnapshot); + DISALLOW_COPY_AND_ASSIGN(Image); }; @@ -728,17 +700,17 @@ class ForwardList { }; -class InstructionsWriter : public ZoneAllocated { +class ImageWriter : public ZoneAllocated { public: - InstructionsWriter() + ImageWriter() : next_offset_(0), next_object_offset_(0), instructions_(), objects_() { ResetOffsets(); } - virtual ~InstructionsWriter() {} + virtual ~ImageWriter() {} void ResetOffsets() { - next_offset_ = InstructionsSnapshot::kHeaderSize; - next_object_offset_ = DataSnapshot::kHeaderSize; + next_offset_ = Image::kHeaderSize; + next_object_offset_ = Image::kHeaderSize; instructions_.Clear(); objects_.Clear(); } @@ -785,16 +757,16 @@ class InstructionsWriter : public ZoneAllocated { GrowableArray objects_; private: - DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); + DISALLOW_COPY_AND_ASSIGN(ImageWriter); }; -class AssemblyInstructionsWriter : public InstructionsWriter { +class AssemblyImageWriter : public ImageWriter { public: - AssemblyInstructionsWriter(uint8_t** assembly_buffer, - ReAlloc alloc, - intptr_t initial_size) - : InstructionsWriter(), + AssemblyImageWriter(uint8_t** assembly_buffer, + ReAlloc alloc, + intptr_t initial_size) + : ImageWriter(), assembly_stream_(assembly_buffer, alloc, initial_size), text_size_(0) {} @@ -817,16 +789,16 @@ class AssemblyInstructionsWriter : public InstructionsWriter { WriteStream assembly_stream_; intptr_t text_size_; - DISALLOW_COPY_AND_ASSIGN(AssemblyInstructionsWriter); + DISALLOW_COPY_AND_ASSIGN(AssemblyImageWriter); }; -class BlobInstructionsWriter : public InstructionsWriter { +class BlobImageWriter : public ImageWriter { public: - BlobInstructionsWriter(uint8_t** instructions_blob_buffer, - ReAlloc alloc, - intptr_t initial_size) - : InstructionsWriter(), + BlobImageWriter(uint8_t** instructions_blob_buffer, + ReAlloc alloc, + intptr_t initial_size) + : ImageWriter(), instructions_blob_stream_(instructions_blob_buffer, alloc, initial_size) {} @@ -841,7 +813,7 @@ class BlobInstructionsWriter : public InstructionsWriter { private: WriteStream instructions_blob_stream_; - DISALLOW_COPY_AND_ASSIGN(BlobInstructionsWriter); + DISALLOW_COPY_AND_ASSIGN(BlobImageWriter); }; diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc index 7b4a5d3a0ce..6d5b6e6ecab 100644 --- a/runtime/vm/snapshot_test.cc +++ b/runtime/vm/snapshot_test.cc @@ -1186,7 +1186,7 @@ UNIT_TEST_CASE(FullSnapshot) { { FullSnapshotWriter writer( Snapshot::kCore, NULL, &isolate_snapshot_data_buffer, - &malloc_allocator, NULL, NULL /* instructions_writer */); + &malloc_allocator, NULL, NULL /* image_writer */); writer.WriteFullSnapshot(); } } @@ -1243,7 +1243,7 @@ UNIT_TEST_CASE(FullSnapshot1) { { FullSnapshotWriter writer( Snapshot::kCore, NULL, &isolate_snapshot_data_buffer, - &malloc_allocator, NULL, NULL /* instructions_writer */); + &malloc_allocator, NULL, NULL /* image_writer */); writer.WriteFullSnapshot(); } diff --git a/runtime/vm/virtual_memory.cc b/runtime/vm/virtual_memory.cc index 93e3b84e08c..38bb4b3fd37 100644 --- a/runtime/vm/virtual_memory.cc +++ b/runtime/vm/virtual_memory.cc @@ -28,12 +28,12 @@ void VirtualMemory::Truncate(intptr_t new_size, bool try_unmap) { } -VirtualMemory* VirtualMemory::ForExternalPage(void* pointer, uword size) { +VirtualMemory* VirtualMemory::ForImagePage(void* pointer, uword size) { // Memory for precompilated instructions was allocated by the embedder, so // create a VirtualMemory without allocating. MemoryRegion region(pointer, size); VirtualMemory* memory = new VirtualMemory(region); - memory->embedder_allocated_ = true; + memory->vm_owns_region_ = false; return memory; } diff --git a/runtime/vm/virtual_memory.h b/runtime/vm/virtual_memory.h index baa714d96b1..4a7ecd27b3d 100644 --- a/runtime/vm/virtual_memory.h +++ b/runtime/vm/virtual_memory.h @@ -64,9 +64,9 @@ class VirtualMemory { // Commit a reserved memory area, so that the memory can be accessed. bool Commit(uword addr, intptr_t size, bool is_executable); - bool embedder_allocated() const { return embedder_allocated_; } + bool vm_owns_region() const { return vm_owns_region_; } - static VirtualMemory* ForExternalPage(void* pointer, uword size); + static VirtualMemory* ForImagePage(void* pointer, uword size); private: static VirtualMemory* ReserveInternal(intptr_t size); @@ -81,7 +81,7 @@ class VirtualMemory { : region_(region.pointer(), region.size()), reserved_size_(region.size()), handle_(handle), - embedder_allocated_(false) {} + vm_owns_region_(true) {} MemoryRegion region_; @@ -93,8 +93,10 @@ class VirtualMemory { static uword page_size_; - // True for a region provided by the embedder. - bool embedder_allocated_; + // False for a part of a snapshot added directly to the Dart heap, which + // belongs to the the embedder and must not be deallocated or have its + // protection status changed by the VM. + bool vm_owns_region_; DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); }; diff --git a/runtime/vm/virtual_memory_android.cc b/runtime/vm/virtual_memory_android.cc index bae5a82d5d3..6a151b27373 100644 --- a/runtime/vm/virtual_memory_android.cc +++ b/runtime/vm/virtual_memory_android.cc @@ -54,7 +54,7 @@ static void unmap(void* address, intptr_t size) { VirtualMemory::~VirtualMemory() { - if (!embedder_allocated()) { + if (vm_owns_region()) { unmap(address(), reserved_size_); } } diff --git a/runtime/vm/virtual_memory_fuchsia.cc b/runtime/vm/virtual_memory_fuchsia.cc index 058bbac4e4c..08919db6e1b 100644 --- a/runtime/vm/virtual_memory_fuchsia.cc +++ b/runtime/vm/virtual_memory_fuchsia.cc @@ -171,7 +171,7 @@ VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) { VirtualMemory::~VirtualMemory() { - if (!embedder_allocated()) { + if (vm_owns_region()) { mx_handle_t vmar = static_cast(handle()); mx_status_t status = mx_vmar_destroy(vmar); if (status != NO_ERROR) { diff --git a/runtime/vm/virtual_memory_linux.cc b/runtime/vm/virtual_memory_linux.cc index 3c4abec3d29..cc571396fdb 100644 --- a/runtime/vm/virtual_memory_linux.cc +++ b/runtime/vm/virtual_memory_linux.cc @@ -53,7 +53,7 @@ static void unmap(void* address, intptr_t size) { VirtualMemory::~VirtualMemory() { - if (!embedder_allocated()) { + if (vm_owns_region()) { unmap(address(), reserved_size_); } } diff --git a/runtime/vm/virtual_memory_macos.cc b/runtime/vm/virtual_memory_macos.cc index c3b004d8086..5e33bb3a9a3 100644 --- a/runtime/vm/virtual_memory_macos.cc +++ b/runtime/vm/virtual_memory_macos.cc @@ -54,7 +54,7 @@ static void unmap(void* address, intptr_t size) { VirtualMemory::~VirtualMemory() { - if (!embedder_allocated()) { + if (!vm_owns_region()) { unmap(address(), reserved_size_); } } diff --git a/runtime/vm/virtual_memory_win.cc b/runtime/vm/virtual_memory_win.cc index 7e876a4281c..0f4b1797d60 100644 --- a/runtime/vm/virtual_memory_win.cc +++ b/runtime/vm/virtual_memory_win.cc @@ -35,7 +35,7 @@ VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) { VirtualMemory::~VirtualMemory() { - if (embedder_allocated() || (reserved_size_ == 0)) { + if (!vm_owns_region() || (reserved_size_ == 0)) { return; } if (VirtualFree(address(), 0, MEM_RELEASE) == 0) {