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

Side by Side Diff: runtime/vm/clustered_snapshot.cc

Issue 2140333002: Collect TokenStreams into the vm isolate snapshot instead of Scripts. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/clustered_snapshot.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/clustered_snapshot.h" 5 #include "vm/clustered_snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bootstrap.h" 8 #include "vm/bootstrap.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 4792 matching lines...) Expand 10 before | Expand all | Expand 10 after
4803 for (intptr_t i = 0; i < num_clusters_; i++) { 4803 for (intptr_t i = 0; i < num_clusters_; i++) {
4804 clusters_[i]->PostLoad(refs, kind_, zone_); 4804 clusters_[i]->PostLoad(refs, kind_, zone_);
4805 } 4805 }
4806 } 4806 }
4807 4807
4808 // Setup native resolver for bootstrap impl. 4808 // Setup native resolver for bootstrap impl.
4809 Bootstrap::SetupNativeResolver(); 4809 Bootstrap::SetupNativeResolver();
4810 } 4810 }
4811 4811
4812 4812
4813 // An object visitor which will iterate over all the script objects in the heap 4813 // An object visitor which will iterate over all the token stream objects in the
4814 // and either count them or collect them into an array. This is used during 4814 // heap and either count them or collect them into an array. This is used during
4815 // full snapshot generation of the VM isolate to write out all script 4815 // full snapshot generation of the VM isolate to write out all token streams so
4816 // objects and their accompanying token streams. 4816 // they will be shared across all isolates.
4817 class ScriptVisitor : public ObjectVisitor { 4817 class TokenStreamVisitor : public ObjectVisitor {
4818 public: 4818 public:
4819 explicit ScriptVisitor(Thread* thread) : 4819 explicit TokenStreamVisitor(Thread* thread) :
4820 objHandle_(Object::Handle(thread->zone())), 4820 objHandle_(Object::Handle(thread->zone())),
4821 count_(0), 4821 count_(0),
4822 scripts_(NULL) {} 4822 token_streams_(NULL) {}
4823 4823
4824 ScriptVisitor(Thread* thread, const Array* scripts) : 4824 TokenStreamVisitor(Thread* thread, const Array* token_streams) :
4825 objHandle_(Object::Handle(thread->zone())), 4825 objHandle_(Object::Handle(thread->zone())),
4826 count_(0), 4826 count_(0),
4827 scripts_(scripts) {} 4827 token_streams_(token_streams) {}
4828 4828
4829 void VisitObject(RawObject* obj) { 4829 void VisitObject(RawObject* obj) {
4830 if (obj->IsScript()) { 4830 if (obj->IsTokenStream()) {
4831 if (scripts_ != NULL) { 4831 if (token_streams_ != NULL) {
4832 objHandle_ = obj; 4832 objHandle_ = obj;
4833 scripts_->SetAt(count_, objHandle_); 4833 token_streams_->SetAt(count_, objHandle_);
4834 } 4834 }
4835 count_ += 1; 4835 count_ += 1;
4836 } 4836 }
4837 } 4837 }
4838 4838
4839 intptr_t count() const { return count_; } 4839 intptr_t count() const { return count_; }
4840 4840
4841 private: 4841 private:
4842 Object& objHandle_; 4842 Object& objHandle_;
4843 intptr_t count_; 4843 intptr_t count_;
4844 const Array* scripts_; 4844 const Array* token_streams_;
4845 }; 4845 };
4846 4846
4847 4847
4848 FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind, 4848 FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind,
4849 uint8_t** vm_isolate_snapshot_buffer, 4849 uint8_t** vm_isolate_snapshot_buffer,
4850 uint8_t** isolate_snapshot_buffer, 4850 uint8_t** isolate_snapshot_buffer,
4851 ReAlloc alloc, 4851 ReAlloc alloc,
4852 InstructionsWriter* instructions_writer) 4852 InstructionsWriter* instructions_writer)
4853 : thread_(Thread::Current()), 4853 : thread_(Thread::Current()),
4854 kind_(kind), 4854 kind_(kind),
4855 vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer), 4855 vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer),
4856 isolate_snapshot_buffer_(isolate_snapshot_buffer), 4856 isolate_snapshot_buffer_(isolate_snapshot_buffer),
4857 alloc_(alloc), 4857 alloc_(alloc),
4858 vm_isolate_snapshot_size_(0), 4858 vm_isolate_snapshot_size_(0),
4859 isolate_snapshot_size_(0), 4859 isolate_snapshot_size_(0),
4860 instructions_writer_(instructions_writer), 4860 instructions_writer_(instructions_writer),
4861 scripts_(Array::Handle(zone())), 4861 token_streams_(Array::Handle(zone())),
4862 saved_symbol_table_(Array::Handle(zone())), 4862 saved_symbol_table_(Array::Handle(zone())),
4863 new_vm_symbol_table_(Array::Handle(zone())) { 4863 new_vm_symbol_table_(Array::Handle(zone())) {
4864 ASSERT(isolate_snapshot_buffer_ != NULL); 4864 ASSERT(isolate_snapshot_buffer_ != NULL);
4865 ASSERT(alloc_ != NULL); 4865 ASSERT(alloc_ != NULL);
4866 ASSERT(isolate() != NULL); 4866 ASSERT(isolate() != NULL);
4867 ASSERT(ClassFinalizer::AllClassesFinalized()); 4867 ASSERT(ClassFinalizer::AllClassesFinalized());
4868 ASSERT(isolate() != NULL); 4868 ASSERT(isolate() != NULL);
4869 ASSERT(heap() != NULL); 4869 ASSERT(heap() != NULL);
4870 ObjectStore* object_store = isolate()->object_store(); 4870 ObjectStore* object_store = isolate()->object_store();
4871 ASSERT(object_store != NULL); 4871 ASSERT(object_store != NULL);
4872 4872
4873 #if defined(DEBUG) 4873 #if defined(DEBUG)
4874 // Ensure the class table is valid. 4874 // Ensure the class table is valid.
4875 isolate()->ValidateClassTable(); 4875 isolate()->ValidateClassTable();
4876 #endif 4876 #endif
4877 // Can't have any mutation happening while we're serializing. 4877 // Can't have any mutation happening while we're serializing.
4878 ASSERT(isolate()->background_compiler() == NULL); 4878 ASSERT(isolate()->background_compiler() == NULL);
4879 4879
4880 if (vm_isolate_snapshot_buffer != NULL) { 4880 if (vm_isolate_snapshot_buffer != NULL) {
4881 NOT_IN_PRODUCT(TimelineDurationScope tds(thread(), 4881 NOT_IN_PRODUCT(TimelineDurationScope tds(thread(),
4882 Timeline::GetIsolateStream(), "PrepareNewVMIsolate")); 4882 Timeline::GetIsolateStream(), "PrepareNewVMIsolate"));
4883 4883
4884 // Collect all the script objects and their accompanying token stream 4884 // Collect all the script objects and their accompanying token stream
Florian Schneider 2016/07/12 22:36:08 Update comment here as well.
rmacnak 2016/07/12 23:22:35 Done.
4885 // objects into an array so that we can write it out as part of the VM 4885 // objects into an array so that we can write it out as part of the VM
4886 // isolate snapshot. We first count the number of script objects, allocate 4886 // isolate snapshot. We first count the number of script objects, allocate
4887 // an array and then fill it up with the script objects. 4887 // an array and then fill it up with the script objects.
4888 ScriptVisitor scripts_counter(thread()); 4888 TokenStreamVisitor token_streams_counter(thread());
4889 heap()->IterateOldObjects(&scripts_counter); 4889 heap()->IterateOldObjects(&token_streams_counter);
4890 Dart::vm_isolate()->heap()->IterateOldObjects(&scripts_counter); 4890 Dart::vm_isolate()->heap()->IterateOldObjects(&token_streams_counter);
4891 intptr_t count = scripts_counter.count(); 4891 intptr_t count = token_streams_counter.count();
4892 scripts_ = Array::New(count, Heap::kOld); 4892 token_streams_ = Array::New(count, Heap::kOld);
4893 ScriptVisitor script_visitor(thread(), &scripts_); 4893 TokenStreamVisitor script_visitor(thread(), &token_streams_);
4894 heap()->IterateOldObjects(&script_visitor); 4894 heap()->IterateOldObjects(&script_visitor);
4895 Dart::vm_isolate()->heap()->IterateOldObjects(&script_visitor); 4895 Dart::vm_isolate()->heap()->IterateOldObjects(&script_visitor);
4896 ASSERT(script_visitor.count() == count); 4896 ASSERT(script_visitor.count() == count);
4897 4897
4898 // Tuck away the current symbol table. 4898 // Tuck away the current symbol table.
4899 saved_symbol_table_ = object_store->symbol_table(); 4899 saved_symbol_table_ = object_store->symbol_table();
4900 4900
4901 // Create a unified symbol table that will be written as the vm isolate's 4901 // Create a unified symbol table that will be written as the vm isolate's
4902 // symbol table. 4902 // symbol table.
4903 new_vm_symbol_table_ = Symbols::UnifiedSymbolTable(); 4903 new_vm_symbol_table_ = Symbols::UnifiedSymbolTable();
4904 4904
4905 // Create an empty symbol table that will be written as the isolate's symbol 4905 // Create an empty symbol table that will be written as the isolate's symbol
4906 // table. 4906 // table.
4907 Symbols::SetupSymbolTable(isolate()); 4907 Symbols::SetupSymbolTable(isolate());
4908 } else { 4908 } else {
4909 // Reuse the current vm isolate. 4909 // Reuse the current vm isolate.
4910 } 4910 }
4911 } 4911 }
4912 4912
4913 FullSnapshotWriter::~FullSnapshotWriter() { 4913 FullSnapshotWriter::~FullSnapshotWriter() {
4914 // We may run Dart code afterwards, restore the symbol table if needed. 4914 // We may run Dart code afterwards, restore the symbol table if needed.
4915 if (!saved_symbol_table_.IsNull()) { 4915 if (!saved_symbol_table_.IsNull()) {
4916 isolate()->object_store()->set_symbol_table(saved_symbol_table_); 4916 isolate()->object_store()->set_symbol_table(saved_symbol_table_);
4917 saved_symbol_table_ = Array::null(); 4917 saved_symbol_table_ = Array::null();
4918 } 4918 }
4919 new_vm_symbol_table_ = Array::null(); 4919 new_vm_symbol_table_ = Array::null();
4920 scripts_ = Array::null(); 4920 token_streams_ = Array::null();
4921 } 4921 }
4922 4922
4923 4923
4924 intptr_t FullSnapshotWriter::WriteVmIsolateSnapshot() { 4924 intptr_t FullSnapshotWriter::WriteVmIsolateSnapshot() {
4925 NOT_IN_PRODUCT(TimelineDurationScope tds(thread(), 4925 NOT_IN_PRODUCT(TimelineDurationScope tds(thread(),
4926 Timeline::GetIsolateStream(), "WriteVmIsolateSnapshot")); 4926 Timeline::GetIsolateStream(), "WriteVmIsolateSnapshot"));
4927 4927
4928 ASSERT(vm_isolate_snapshot_buffer_ != NULL); 4928 ASSERT(vm_isolate_snapshot_buffer_ != NULL);
4929 Serializer serializer(thread(), 4929 Serializer serializer(thread(),
4930 kind_, 4930 kind_,
4931 vm_isolate_snapshot_buffer_, 4931 vm_isolate_snapshot_buffer_,
4932 alloc_, 4932 alloc_,
4933 kInitialSize, 4933 kInitialSize,
4934 instructions_writer_); 4934 instructions_writer_);
4935 4935
4936 serializer.ReserveHeader(); 4936 serializer.ReserveHeader();
4937 serializer.WriteVersionAndFeatures(); 4937 serializer.WriteVersionAndFeatures();
4938 /* 4938 /*
4939 * Now Write out the following 4939 * Now Write out the following
4940 * - the symbol table 4940 * - the symbol table
4941 * - all the scripts and token streams for these scripts 4941 * - all the token streams
4942 * - the stub code (precompiled snapshots only) 4942 * - the stub code (precompiled snapshots only)
4943 **/ 4943 **/
4944 intptr_t num_objects = serializer.WriteVMSnapshot(new_vm_symbol_table_, 4944 intptr_t num_objects = serializer.WriteVMSnapshot(new_vm_symbol_table_,
4945 scripts_); 4945 token_streams_);
4946 serializer.FillHeader(serializer.kind()); 4946 serializer.FillHeader(serializer.kind());
4947 4947
4948 vm_isolate_snapshot_size_ = serializer.bytes_written(); 4948 vm_isolate_snapshot_size_ = serializer.bytes_written();
4949 return num_objects; 4949 return num_objects;
4950 } 4950 }
4951 4951
4952 4952
4953 void FullSnapshotWriter::WriteIsolateFullSnapshot( 4953 void FullSnapshotWriter::WriteIsolateFullSnapshot(
4954 intptr_t num_base_objects) { 4954 intptr_t num_base_objects) {
4955 NOT_IN_PRODUCT(TimelineDurationScope tds(thread(), 4955 NOT_IN_PRODUCT(TimelineDurationScope tds(thread(),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
5033 5033
5034 deserializer.ReadVMSnapshot(); 5034 deserializer.ReadVMSnapshot();
5035 5035
5036 Dart::set_instructions_snapshot_buffer(instructions_buffer_); 5036 Dart::set_instructions_snapshot_buffer(instructions_buffer_);
5037 Dart::set_data_snapshot_buffer(data_buffer_); 5037 Dart::set_data_snapshot_buffer(data_buffer_);
5038 5038
5039 return ApiError::null(); 5039 return ApiError::null();
5040 } 5040 }
5041 5041
5042 } // namespace dart 5042 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/clustered_snapshot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698