Rename references to "external pages" as "image pages" to avoid confusion with the kind of external memory associated with finalizers.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2654183002 .
This commit is contained in:
Ryan Macnak 2017-01-26 09:53:06 -08:00
parent 15cf5cb017
commit 8b217ec519
25 changed files with 157 additions and 214 deletions

View file

@ -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);

View file

@ -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());

View file

@ -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<RawObject*> 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_;

View file

@ -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

View file

@ -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;
}

View file

@ -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();

View file

@ -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.

View file

@ -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<uword>(snapshot.instructions_start()),
reinterpret_cast<uword>(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<uword>(snapshot.data_start()),
reinterpret_cast<uword>(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);
}

View file

@ -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();

View file

@ -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.
}
}

View file

@ -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;
};

View file

@ -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());

View file

@ -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<void*>(reinterpret_cast<uword>(pointer) - offset);
size += offset;
VirtualMemory* memory = VirtualMemory::ForExternalPage(pointer, size);
VirtualMemory* memory = VirtualMemory::ForImagePage(pointer, size);
ASSERT(memory != NULL);
HeapPage* page = reinterpret_cast<HeapPage*>(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);
}
}

View file

@ -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.

View file

@ -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;
};

View file

@ -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);
}

View file

@ -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<void*>(reinterpret_cast<uword>(raw_memory_) +
kHeaderSize);
}
uword instructions_size() {
uword object_size() {
uword snapshot_size = *reinterpret_cast<const uword*>(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<void*>(reinterpret_cast<uword>(raw_memory_) +
kHeaderSize);
}
uword data_size() {
uword snapshot_size = *reinterpret_cast<const uword*>(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<ObjectData> 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);
};

View file

@ -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();
}

View file

@ -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;
}

View file

@ -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);
};

View file

@ -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_);
}
}

View file

@ -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<mx_handle_t>(handle());
mx_status_t status = mx_vmar_destroy(vmar);
if (status != NO_ERROR) {

View file

@ -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_);
}
}

View file

@ -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_);
}
}

View file

@ -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) {