Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Unified Diff: runtime/vm/snapshot.cc

Issue 2032153003: Use clustered serialization for full snapshots. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: round2 Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/snapshot.cc
diff --git a/runtime/vm/snapshot.cc b/runtime/vm/snapshot.cc
index e5c5b0bbbc4cfa5c0e8a88597a37432d35b71824..a041609c391f29f5137bc2b24ba97e3e343ab93c 100644
--- a/runtime/vm/snapshot.cc
+++ b/runtime/vm/snapshot.cc
@@ -29,8 +29,6 @@
namespace dart {
-static const int kNumVmIsolateSnapshotReferences = 32 * KB;
-static const int kNumInitialReferencesInFullSnapshot = 160 * KB;
static const int kNumInitialReferences = 64;
@@ -586,82 +584,6 @@ class HeapLocker : public StackResource {
};
-RawApiError* SnapshotReader::ReadFullSnapshot() {
- ASSERT(Snapshot::IsFull(kind_));
- Thread* thread = Thread::Current();
- Isolate* isolate = thread->isolate();
- ASSERT(isolate != NULL);
- ObjectStore* object_store = isolate->object_store();
- ASSERT(object_store != NULL);
-
- // First read the version string, and check that it matches.
- RawApiError* error = VerifyVersionAndFeatures();
- if (error != ApiError::null()) {
- return error;
- }
-
- // The version string matches. Read the rest of the snapshot.
-
- // TODO(asiva): Add a check here to ensure we have the right heap
- // size for the full snapshot being read.
- {
- NoSafepointScope no_safepoint;
- HeapLocker hl(thread, old_space());
-
- // Read in all the objects stored in the object store.
- intptr_t num_flds =
- (object_store->to_snapshot(kind_) - object_store->from());
- for (intptr_t i = 0; i <= num_flds; i++) {
- *(object_store->from() + i) = ReadObjectImpl(kAsInlinedObject);
- }
- for (intptr_t i = 0; i < backward_references_->length(); i++) {
- if (!(*backward_references_)[i].is_deserialized()) {
- ReadObjectImpl(kAsInlinedObject);
- (*backward_references_)[i].set_state(kIsDeserialized);
- }
- }
-
- if (kind_ == Snapshot::kAppNoJIT) {
- ICData& ic = ICData::Handle(thread->zone());
- Object& funcOrCode = Object::Handle(thread->zone());
- Code& code = Code::Handle(thread->zone());
- Smi& entry_point = Smi::Handle(thread->zone());
- for (intptr_t i = 0; i < backward_references_->length(); i++) {
- if ((*backward_references_)[i].reference()->IsICData()) {
- ic ^= (*backward_references_)[i].reference()->raw();
- for (intptr_t j = 0; j < ic.NumberOfChecks(); j++) {
- funcOrCode = ic.GetTargetOrCodeAt(j);
- if (funcOrCode.IsCode()) {
- code ^= funcOrCode.raw();
- entry_point = Smi::FromAlignedAddress(code.EntryPoint());
- ic.SetEntryPointAt(j, entry_point);
- }
- }
- }
- }
- }
-
- // Validate the class table.
-#if defined(DEBUG)
- isolate->ValidateClassTable();
-#endif
-
- // Setup native resolver for bootstrap impl.
- Bootstrap::SetupNativeResolver();
- }
-
- Class& cls = Class::Handle(thread->zone());
- for (intptr_t i = 0; i < backward_references_->length(); i++) {
- if ((*backward_references_)[i].reference()->IsClass()) {
- cls ^= (*backward_references_)[i].reference()->raw();
- cls.RehashConstants(thread->zone());
- }
- }
-
- return ApiError::null();
-}
-
-
RawObject* SnapshotReader::ReadScriptSnapshot() {
ASSERT(kind_ == Snapshot::kScript);
@@ -1702,108 +1624,6 @@ void SnapshotReader::ArrayReadFrom(intptr_t object_id,
}
-VmIsolateSnapshotReader::VmIsolateSnapshotReader(
- Snapshot::Kind kind,
- const uint8_t* buffer,
- intptr_t size,
- const uint8_t* instructions_buffer,
- const uint8_t* data_buffer,
- Thread* thread)
- : SnapshotReader(buffer,
- size,
- instructions_buffer,
- data_buffer,
- kind,
- new ZoneGrowableArray<BackRefNode>(
- kNumVmIsolateSnapshotReferences),
- thread) {
- ASSERT(Snapshot::IsFull(kind));
-}
-
-
-VmIsolateSnapshotReader::~VmIsolateSnapshotReader() {
- intptr_t len = GetBackwardReferenceTable()->length();
- Object::InitVmIsolateSnapshotObjectTable(len);
- ZoneGrowableArray<BackRefNode>* backrefs = GetBackwardReferenceTable();
- for (intptr_t i = 0; i < len; i++) {
- Object::vm_isolate_snapshot_object_table().SetAt(
- i, *(backrefs->At(i).reference()));
- }
- ResetBackwardReferenceTable();
- Dart::set_instructions_snapshot_buffer(instructions_buffer_);
- Dart::set_data_snapshot_buffer(data_buffer_);
-}
-
-
-RawApiError* VmIsolateSnapshotReader::ReadVmIsolateSnapshot() {
- ASSERT(Snapshot::IsFull(kind()));
- Thread* thread = Thread::Current();
- Isolate* isolate = thread->isolate();
- ASSERT(isolate != NULL);
- ASSERT(isolate == Dart::vm_isolate());
- ObjectStore* object_store = isolate->object_store();
- ASSERT(object_store != NULL);
-
- // First read the version string, and check that it matches.
- RawApiError* error = VerifyVersionAndFeatures();
- if (error != ApiError::null()) {
- return error;
- }
-
- // The version string matches. Read the rest of the snapshot.
-
- {
- NoSafepointScope no_safepoint;
- HeapLocker hl(thread, old_space());
-
- // Read in the symbol table.
- object_store->symbol_table_ = reinterpret_cast<RawArray*>(ReadObject());
-
- Symbols::InitOnceFromSnapshot(isolate);
-
- // Read in all the script objects and the accompanying token streams
- // for bootstrap libraries so that they are in the VM isolate's read
- // only memory.
- *(ArrayHandle()) ^= ReadObject();
-
- if (Snapshot::IncludesCode(kind())) {
- StubCode::ReadFrom(this);
- }
-
- // Validate the class table.
-#if defined(DEBUG)
- isolate->ValidateClassTable();
-#endif
-
- return ApiError::null();
- }
-}
-
-
-IsolateSnapshotReader::IsolateSnapshotReader(Snapshot::Kind kind,
- const uint8_t* buffer,
- intptr_t size,
- const uint8_t* instructions_buffer,
- const uint8_t* data_buffer,
- Thread* thread)
- : SnapshotReader(buffer,
- size,
- instructions_buffer,
- data_buffer,
- kind,
- new ZoneGrowableArray<BackRefNode>(
- kNumInitialReferencesInFullSnapshot),
- thread) {
- isolate()->set_compilation_allowed(kind != Snapshot::kAppNoJIT);
- ASSERT(Snapshot::IsFull(kind));
-}
-
-
-IsolateSnapshotReader::~IsolateSnapshotReader() {
- ResetBackwardReferenceTable();
-}
-
-
ScriptSnapshotReader::ScriptSnapshotReader(const uint8_t* buffer,
intptr_t size,
Thread* thread)
@@ -2039,212 +1859,6 @@ class ScriptVisitor : public ObjectVisitor {
};
-FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind,
- uint8_t** vm_isolate_snapshot_buffer,
- uint8_t** isolate_snapshot_buffer,
- ReAlloc alloc,
- InstructionsWriter* instructions_writer)
- : thread_(Thread::Current()),
- kind_(kind),
- vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer),
- isolate_snapshot_buffer_(isolate_snapshot_buffer),
- alloc_(alloc),
- vm_isolate_snapshot_size_(0),
- isolate_snapshot_size_(0),
- forward_list_(NULL),
- instructions_writer_(instructions_writer),
- scripts_(Array::Handle(zone())),
- saved_symbol_table_(Array::Handle(zone())),
- new_vm_symbol_table_(Array::Handle(zone())) {
- ASSERT(isolate_snapshot_buffer_ != NULL);
- ASSERT(alloc_ != NULL);
- ASSERT(isolate() != NULL);
- ASSERT(ClassFinalizer::AllClassesFinalized());
- ASSERT(isolate() != NULL);
- ASSERT(heap() != NULL);
- ObjectStore* object_store = isolate()->object_store();
- ASSERT(object_store != NULL);
-
-#if defined(DEBUG)
- // Ensure the class table is valid.
- isolate()->ValidateClassTable();
-#endif
- // Can't have any mutation happening while we're serializing.
- ASSERT(isolate()->background_compiler() == NULL);
-
- intptr_t first_object_id = -1;
- if (vm_isolate_snapshot_buffer != NULL) {
- NOT_IN_PRODUCT(TimelineDurationScope tds(thread(),
- Timeline::GetIsolateStream(), "PrepareNewVMIsolate"));
-
- // Collect all the script objects and their accompanying token stream
- // objects into an array so that we can write it out as part of the VM
- // isolate snapshot. We first count the number of script objects, allocate
- // an array and then fill it up with the script objects.
- ScriptVisitor scripts_counter(thread());
- heap()->IterateOldObjects(&scripts_counter);
- Dart::vm_isolate()->heap()->IterateOldObjects(&scripts_counter);
- intptr_t count = scripts_counter.count();
- scripts_ = Array::New(count, Heap::kOld);
- ScriptVisitor script_visitor(thread(), &scripts_);
- heap()->IterateOldObjects(&script_visitor);
- Dart::vm_isolate()->heap()->IterateOldObjects(&script_visitor);
- ASSERT(script_visitor.count() == count);
-
- // Tuck away the current symbol table.
- saved_symbol_table_ = object_store->symbol_table();
-
- // Create a unified symbol table that will be written as the vm isolate's
- // symbol table.
- new_vm_symbol_table_ = Symbols::UnifiedSymbolTable();
-
- // Create an empty symbol table that will be written as the isolate's symbol
- // table.
- Symbols::SetupSymbolTable(isolate());
-
- first_object_id = kMaxPredefinedObjectIds;
- } else {
- intptr_t max_vm_isolate_object_id =
- Object::vm_isolate_snapshot_object_table().Length();
- first_object_id = kMaxPredefinedObjectIds + max_vm_isolate_object_id;
- }
-
- forward_list_ = new ForwardList(thread(), first_object_id);
- ASSERT(forward_list_ != NULL);
-}
-
-
-FullSnapshotWriter::~FullSnapshotWriter() {
- delete forward_list_;
- // We may run Dart code afterwards, restore the symbol table if needed.
- if (!saved_symbol_table_.IsNull()) {
- isolate()->object_store()->set_symbol_table(saved_symbol_table_);
- saved_symbol_table_ = Array::null();
- }
- new_vm_symbol_table_ = Array::null();
- scripts_ = Array::null();
-}
-
-
-void FullSnapshotWriter::WriteVmIsolateSnapshot() {
- NOT_IN_PRODUCT(TimelineDurationScope tds(thread(),
- Timeline::GetIsolateStream(), "WriteVmIsolateSnapshot"));
-
- ASSERT(vm_isolate_snapshot_buffer_ != NULL);
- SnapshotWriter writer(thread(),
- kind_,
- vm_isolate_snapshot_buffer_,
- alloc_,
- kInitialSize,
- forward_list_,
- instructions_writer_,
- true, /* can_send_any_object */
- true /* writing_vm_isolate */);
- // Write full snapshot for the VM isolate.
- // Setup for long jump in case there is an exception while writing
- // the snapshot.
- LongJumpScope jump;
- if (setjmp(*jump.Set()) == 0) {
- // Reserve space in the output buffer for a snapshot header.
- writer.ReserveHeader();
-
- // Write out the version string.
- writer.WriteVersionAndFeatures();
-
- /*
- * Now Write out the following
- * - the symbol table
- * - all the scripts and token streams for these scripts
- * - the stub code (precompiled snapshots only)
- **/
- // Write out the symbol table.
- writer.WriteObject(new_vm_symbol_table_.raw());
-
- // Write out all the script objects and the accompanying token streams
- // for the bootstrap libraries so that they are in the VM isolate
- // read only memory.
- writer.WriteObject(scripts_.raw());
-
- if (Snapshot::IncludesCode(kind_)) {
- StubCode::WriteTo(&writer);
- }
-
- writer.FillHeader(writer.kind());
-
- vm_isolate_snapshot_size_ = writer.BytesWritten();
- } else {
- writer.ThrowException(writer.exception_type(), writer.exception_msg());
- }
-}
-
-
-void FullSnapshotWriter::WriteIsolateFullSnapshot() {
- NOT_IN_PRODUCT(TimelineDurationScope tds(thread(),
- Timeline::GetIsolateStream(), "WriteIsolateFullSnapshot"));
-
- SnapshotWriter writer(thread(),
- kind_,
- isolate_snapshot_buffer_,
- alloc_,
- kInitialSize,
- forward_list_,
- instructions_writer_,
- true, /* can_send_any_object */
- false /* writing_vm_isolate */);
- ObjectStore* object_store = isolate()->object_store();
- ASSERT(object_store != NULL);
-
- // Write full snapshot for a regular isolate.
- // Setup for long jump in case there is an exception while writing
- // the snapshot.
- LongJumpScope jump;
- if (setjmp(*jump.Set()) == 0) {
- // Reserve space in the output buffer for a snapshot header.
- writer.ReserveHeader();
-
- // Write out the version string.
- writer.WriteVersionAndFeatures();
-
- // Write out the full snapshot.
-
- // Write out all the objects in the object store of the isolate which
- // is the root set for all dart allocated objects at this point.
- SnapshotWriterVisitor visitor(&writer, false);
- visitor.VisitPointers(object_store->from(),
- object_store->to_snapshot(kind_));
-
- // Write out all forwarded objects.
- writer.WriteForwardedObjects();
-
- writer.FillHeader(writer.kind());
-
- isolate_snapshot_size_ = writer.BytesWritten();
- } else {
- writer.ThrowException(writer.exception_type(), writer.exception_msg());
- }
-}
-
-
-void FullSnapshotWriter::WriteFullSnapshot() {
- if (vm_isolate_snapshot_buffer() != NULL) {
- WriteVmIsolateSnapshot();
- }
- WriteIsolateFullSnapshot();
- if (Snapshot::IncludesCode(kind_)) {
- instructions_writer_->Write();
-
- OS::Print("VMIsolate(CodeSize): %" Pd "\n", VmIsolateSnapshotSize());
- OS::Print("Isolate(CodeSize): %" Pd "\n", IsolateSnapshotSize());
- OS::Print("Instructions(CodeSize): %" Pd "\n",
- instructions_writer_->binary_size());
- intptr_t total = VmIsolateSnapshotSize() +
- IsolateSnapshotSize() +
- instructions_writer_->binary_size();
- OS::Print("Total(CodeSize): %" Pd "\n", total);
- }
-}
-
-
ForwardList::ForwardList(Thread* thread, intptr_t first_object_id)
: thread_(thread),
first_object_id_(first_object_id),
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698