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

Side by Side Diff: runtime/vm/snapshot.h

Issue 1918313003: Split Snapshot::kFull into kCore, kAppWithJIT, and kAppNoJIT. Remove snapshot_code flag. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync Created 4 years, 7 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/raw_object_snapshot.cc ('k') | runtime/vm/snapshot.cc » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #ifndef VM_SNAPSHOT_H_ 5 #ifndef VM_SNAPSHOT_H_
6 #define VM_SNAPSHOT_H_ 6 #define VM_SNAPSHOT_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/bitfield.h" 10 #include "vm/bitfield.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 145
146 // Structure capturing the raw snapshot. 146 // Structure capturing the raw snapshot.
147 // 147 //
148 // TODO(turnidge): Remove this class once the snapshot does not have a 148 // TODO(turnidge): Remove this class once the snapshot does not have a
149 // header anymore. This is pending on making the embedder pass in the 149 // header anymore. This is pending on making the embedder pass in the
150 // length of their snapshot. 150 // length of their snapshot.
151 class Snapshot { 151 class Snapshot {
152 public: 152 public:
153 enum Kind { 153 enum Kind {
154 kFull = 0, // Full snapshot of the current dart heap. 154 kCore = 0, // Full snapshot of core libraries. No root library, no code.
155 kScript, // A partial snapshot of only the application script. 155 kAppWithJIT, // Full snapshot of core libraries and application. Has some
156 kMessage, // A partial snapshot used only for isolate messaging. 156 // code, but may compile in the future because we haven't
157 // necessarily included code for every function or to
158 // (de)optimize.
159 kAppNoJIT, // Full snapshot of core libraries and application. Has
160 // complete code for the application that never deopts. Will
161 // not compile in the future.
162 kScript, // A partial snapshot of only the application script.
163 kMessage, // A partial snapshot used only for isolate messaging.
157 }; 164 };
158 165
159 static const int kHeaderSize = 2 * sizeof(int64_t); 166 static const int kHeaderSize = 2 * sizeof(int64_t);
160 static const int kLengthIndex = 0; 167 static const int kLengthIndex = 0;
161 static const int kSnapshotFlagIndex = 1; 168 static const int kSnapshotFlagIndex = 1;
162 169
163 static const Snapshot* SetupFromBuffer(const void* raw_memory); 170 static const Snapshot* SetupFromBuffer(const void* raw_memory);
164 171
165 // Getters. 172 // Getters.
166 const uint8_t* content() const { OPEN_ARRAY_START(uint8_t, uint8_t); } 173 const uint8_t* content() const { OPEN_ARRAY_START(uint8_t, uint8_t); }
167 intptr_t length() const { 174 intptr_t length() const {
168 return static_cast<intptr_t>(ReadUnaligned(&unaligned_length_)); 175 return static_cast<intptr_t>(ReadUnaligned(&unaligned_length_));
169 } 176 }
170 Kind kind() const { 177 Kind kind() const {
171 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_)); 178 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_));
172 } 179 }
173 180
181 static bool IsFull(Kind kind) {
182 return (kind == kCore) || (kind == kAppWithJIT) || (kind == kAppNoJIT);
183 }
184 static bool IncludesCode(Kind kind) {
185 return (kind == kAppWithJIT) || (kind == kAppNoJIT);
186 }
187
174 bool IsMessageSnapshot() const { return kind() == kMessage; } 188 bool IsMessageSnapshot() const { return kind() == kMessage; }
175 bool IsScriptSnapshot() const { return kind() == kScript; } 189 bool IsScriptSnapshot() const { return kind() == kScript; }
176 bool IsFullSnapshot() const { return kind() == kFull; } 190 bool IsCoreSnapshot() const { return kind() == kCore; }
191 bool IsAppSnapshotWithJIT() const { return kind() == kAppWithJIT; }
192 bool IsAppSnapshotNoJIT() const { return kind() == kAppNoJIT; }
177 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } 193 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); }
178 194
179 static intptr_t length_offset() { 195 static intptr_t length_offset() {
180 return OFFSET_OF(Snapshot, unaligned_length_); 196 return OFFSET_OF(Snapshot, unaligned_length_);
181 } 197 }
182 static intptr_t kind_offset() { 198 static intptr_t kind_offset() {
183 return OFFSET_OF(Snapshot, unaligned_kind_); 199 return OFFSET_OF(Snapshot, unaligned_kind_);
184 } 200 }
185 201
186 private: 202 private:
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 AbstractType* TypeHandle() { return &type_; } 412 AbstractType* TypeHandle() { return &type_; }
397 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; } 413 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; }
398 GrowableObjectArray* TokensHandle() { return &tokens_; } 414 GrowableObjectArray* TokensHandle() { return &tokens_; }
399 TokenStream* StreamHandle() { return &stream_; } 415 TokenStream* StreamHandle() { return &stream_; }
400 ExternalTypedData* DataHandle() { return &data_; } 416 ExternalTypedData* DataHandle() { return &data_; }
401 TypedData* TypedDataHandle() { return &typed_data_; } 417 TypedData* TypedDataHandle() { return &typed_data_; }
402 Code* CodeHandle() { return &code_; } 418 Code* CodeHandle() { return &code_; }
403 Function* FunctionHandle() { return &function_; } 419 Function* FunctionHandle() { return &function_; }
404 MegamorphicCache* MegamorphicCacheHandle() { return &megamorphic_cache_; } 420 MegamorphicCache* MegamorphicCacheHandle() { return &megamorphic_cache_; }
405 Snapshot::Kind kind() const { return kind_; } 421 Snapshot::Kind kind() const { return kind_; }
406 bool snapshot_code() const { return snapshot_code_; }
407 422
408 // Reads an object. 423 // Reads an object.
409 RawObject* ReadObject(); 424 RawObject* ReadObject();
410 425
411 // Add object to backward references. 426 // Add object to backward references.
412 void AddBackRef(intptr_t id, 427 void AddBackRef(intptr_t id,
413 Object* obj, 428 Object* obj,
414 DeserializeState state, 429 DeserializeState state,
415 bool defer_canonicalization = false); 430 bool defer_canonicalization = false);
416 431
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 575
561 intptr_t NextAvailableObjectId() const; 576 intptr_t NextAvailableObjectId() const;
562 577
563 void SetReadException(const char* msg); 578 void SetReadException(const char* msg);
564 579
565 RawObject* VmIsolateSnapshotObject(intptr_t index) const; 580 RawObject* VmIsolateSnapshotObject(intptr_t index) const;
566 581
567 bool is_vm_isolate() const; 582 bool is_vm_isolate() const;
568 583
569 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). 584 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message).
570 bool snapshot_code_;
571 Thread* thread_; // Current thread. 585 Thread* thread_; // Current thread.
572 Zone* zone_; // Zone for allocations while reading snapshot. 586 Zone* zone_; // Zone for allocations while reading snapshot.
573 Heap* heap_; // Heap of the current isolate. 587 Heap* heap_; // Heap of the current isolate.
574 PageSpace* old_space_; // Old space of the current isolate. 588 PageSpace* old_space_; // Old space of the current isolate.
575 Class& cls_; // Temporary Class handle. 589 Class& cls_; // Temporary Class handle.
576 Object& obj_; // Temporary Object handle. 590 Object& obj_; // Temporary Object handle.
577 PassiveObject& pobj_; // Temporary PassiveObject handle. 591 PassiveObject& pobj_; // Temporary PassiveObject handle.
578 Array& array_; // Temporary Array handle. 592 Array& array_; // Temporary Array handle.
579 Field& field_; // Temporary Field handle. 593 Field& field_; // Temporary Field handle.
580 String& str_; // Temporary String handle. 594 String& str_; // Temporary String handle.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 friend class TypeRef; 648 friend class TypeRef;
635 friend class UnhandledException; 649 friend class UnhandledException;
636 friend class UnresolvedClass; 650 friend class UnresolvedClass;
637 friend class WeakProperty; 651 friend class WeakProperty;
638 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); 652 DISALLOW_COPY_AND_ASSIGN(SnapshotReader);
639 }; 653 };
640 654
641 655
642 class VmIsolateSnapshotReader : public SnapshotReader { 656 class VmIsolateSnapshotReader : public SnapshotReader {
643 public: 657 public:
644 VmIsolateSnapshotReader(const uint8_t* buffer, 658 VmIsolateSnapshotReader(Snapshot::Kind kind,
659 const uint8_t* buffer,
645 intptr_t size, 660 intptr_t size,
646 const uint8_t* instructions_buffer, 661 const uint8_t* instructions_buffer,
647 const uint8_t* data_buffer, 662 const uint8_t* data_buffer,
648 Thread* thread); 663 Thread* thread);
649 ~VmIsolateSnapshotReader(); 664 ~VmIsolateSnapshotReader();
650 665
651 RawApiError* ReadVmIsolateSnapshot(); 666 RawApiError* ReadVmIsolateSnapshot();
652 667
653 private: 668 private:
654 DISALLOW_COPY_AND_ASSIGN(VmIsolateSnapshotReader); 669 DISALLOW_COPY_AND_ASSIGN(VmIsolateSnapshotReader);
655 }; 670 };
656 671
657 672
658 class IsolateSnapshotReader : public SnapshotReader { 673 class IsolateSnapshotReader : public SnapshotReader {
659 public: 674 public:
660 IsolateSnapshotReader(const uint8_t* buffer, 675 IsolateSnapshotReader(Snapshot::Kind kind,
676 const uint8_t* buffer,
661 intptr_t size, 677 intptr_t size,
662 const uint8_t* instructions_buffer, 678 const uint8_t* instructions_buffer,
663 const uint8_t* data_buffer, 679 const uint8_t* data_buffer,
664 Thread* thread); 680 Thread* thread);
665 ~IsolateSnapshotReader(); 681 ~IsolateSnapshotReader();
666 682
667 private: 683 private:
668 DISALLOW_COPY_AND_ASSIGN(IsolateSnapshotReader); 684 DISALLOW_COPY_AND_ASSIGN(IsolateSnapshotReader);
669 }; 685 };
670 686
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 private: 971 private:
956 WriteStream instructions_blob_stream_; 972 WriteStream instructions_blob_stream_;
957 WriteStream rodata_blob_stream_; 973 WriteStream rodata_blob_stream_;
958 974
959 DISALLOW_COPY_AND_ASSIGN(BlobInstructionsWriter); 975 DISALLOW_COPY_AND_ASSIGN(BlobInstructionsWriter);
960 }; 976 };
961 977
962 978
963 class SnapshotWriter : public BaseWriter { 979 class SnapshotWriter : public BaseWriter {
964 protected: 980 protected:
965 SnapshotWriter(Snapshot::Kind kind, 981 SnapshotWriter(Thread* thread,
966 Thread* thread, 982 Snapshot::Kind kind,
967 uint8_t** buffer, 983 uint8_t** buffer,
968 ReAlloc alloc, 984 ReAlloc alloc,
969 intptr_t initial_size, 985 intptr_t initial_size,
970 ForwardList* forward_list, 986 ForwardList* forward_list,
971 InstructionsWriter* instructions_writer, 987 InstructionsWriter* instructions_writer,
972 bool can_send_any_object, 988 bool can_send_any_object,
973 bool snapshot_code,
974 bool vm_isolate_is_symbolic); 989 bool vm_isolate_is_symbolic);
975 990
976 public: 991 public:
977 // Snapshot kind. 992 // Snapshot kind.
978 Snapshot::Kind kind() const { return kind_; } 993 Snapshot::Kind kind() const { return kind_; }
979 Thread* thread() const { return thread_; } 994 Thread* thread() const { return thread_; }
980 Zone* zone() const { return thread_->zone(); } 995 Zone* zone() const { return thread_->zone(); }
981 Isolate* isolate() const { return thread_->isolate(); } 996 Isolate* isolate() const { return thread_->isolate(); }
982 Heap* heap() const { return isolate()->heap(); } 997 Heap* heap() const { return isolate()->heap(); }
983 998
984 // Serialize an object into the buffer. 999 // Serialize an object into the buffer.
985 void WriteObject(RawObject* raw); 1000 void WriteObject(RawObject* raw);
986 1001
987 uword GetObjectTags(RawObject* raw); 1002 uword GetObjectTags(RawObject* raw);
988 1003
989 Exceptions::ExceptionType exception_type() const { 1004 Exceptions::ExceptionType exception_type() const {
990 return exception_type_; 1005 return exception_type_;
991 } 1006 }
992 void set_exception_type(Exceptions::ExceptionType type) { 1007 void set_exception_type(Exceptions::ExceptionType type) {
993 exception_type_ = type; 1008 exception_type_ = type;
994 } 1009 }
995 const char* exception_msg() const { return exception_msg_; } 1010 const char* exception_msg() const { return exception_msg_; }
996 void set_exception_msg(const char* msg) { 1011 void set_exception_msg(const char* msg) {
997 exception_msg_ = msg; 1012 exception_msg_ = msg;
998 } 1013 }
999 bool can_send_any_object() const { return can_send_any_object_; } 1014 bool can_send_any_object() const { return can_send_any_object_; }
1000 bool snapshot_code() const { return snapshot_code_; }
1001 bool vm_isolate_is_symbolic() const { return vm_isolate_is_symbolic_; } 1015 bool vm_isolate_is_symbolic() const { return vm_isolate_is_symbolic_; }
1002 void ThrowException(Exceptions::ExceptionType type, const char* msg); 1016 void ThrowException(Exceptions::ExceptionType type, const char* msg);
1003 1017
1004 // Write a version string for the snapshot. 1018 // Write a version string for the snapshot.
1005 void WriteVersion(); 1019 void WriteVersion();
1006 1020
1007 static intptr_t FirstObjectId(); 1021 static intptr_t FirstObjectId();
1008 1022
1009 int32_t GetInstructionsId(RawInstructions* instructions, RawCode* code) { 1023 int32_t GetInstructionsId(RawInstructions* instructions, RawCode* code) {
1010 return instructions_writer_->GetOffsetFor(instructions, code); 1024 return instructions_writer_->GetOffsetFor(instructions, code);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 forward_list_ = forward_list; 1070 forward_list_ = forward_list;
1057 } 1071 }
1058 void ResetForwardList() { 1072 void ResetForwardList() {
1059 ASSERT(forward_list_ != NULL); 1073 ASSERT(forward_list_ != NULL);
1060 forward_list_ = NULL; 1074 forward_list_ = NULL;
1061 } 1075 }
1062 1076
1063 ObjectStore* object_store() const { return object_store_; } 1077 ObjectStore* object_store() const { return object_store_; }
1064 1078
1065 private: 1079 private:
1080 Thread* thread_;
1066 Snapshot::Kind kind_; 1081 Snapshot::Kind kind_;
1067 Thread* thread_;
1068 ObjectStore* object_store_; // Object store for common classes. 1082 ObjectStore* object_store_; // Object store for common classes.
1069 ClassTable* class_table_; // Class table for the class index to class lookup. 1083 ClassTable* class_table_; // Class table for the class index to class lookup.
1070 ForwardList* forward_list_; 1084 ForwardList* forward_list_;
1071 InstructionsWriter* instructions_writer_; 1085 InstructionsWriter* instructions_writer_;
1072 Exceptions::ExceptionType exception_type_; // Exception type. 1086 Exceptions::ExceptionType exception_type_; // Exception type.
1073 const char* exception_msg_; // Message associated with exception. 1087 const char* exception_msg_; // Message associated with exception.
1074 bool unmarked_objects_; // True if marked objects have been unmarked. 1088 bool unmarked_objects_; // True if marked objects have been unmarked.
1075 bool can_send_any_object_; // True if any Dart instance can be sent. 1089 bool can_send_any_object_; // True if any Dart instance can be sent.
1076 bool snapshot_code_;
1077 bool vm_isolate_is_symbolic_; 1090 bool vm_isolate_is_symbolic_;
1078 1091
1079 friend class FullSnapshotWriter; 1092 friend class FullSnapshotWriter;
1080 friend class RawArray; 1093 friend class RawArray;
1081 friend class RawClass; 1094 friend class RawClass;
1082 friend class RawClosureData; 1095 friend class RawClosureData;
1083 friend class RawCode; 1096 friend class RawCode;
1084 friend class RawContextScope; 1097 friend class RawContextScope;
1085 friend class RawExceptionHandlers; 1098 friend class RawExceptionHandlers;
1086 friend class RawField; 1099 friend class RawField;
(...skipping 17 matching lines...) Expand all
1104 friend class RawUserTag; 1117 friend class RawUserTag;
1105 friend class SnapshotWriterVisitor; 1118 friend class SnapshotWriterVisitor;
1106 friend class WriteInlinedObjectVisitor; 1119 friend class WriteInlinedObjectVisitor;
1107 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); 1120 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter);
1108 }; 1121 };
1109 1122
1110 1123
1111 class FullSnapshotWriter { 1124 class FullSnapshotWriter {
1112 public: 1125 public:
1113 static const intptr_t kInitialSize = 64 * KB; 1126 static const intptr_t kInitialSize = 64 * KB;
1114 FullSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer, 1127 FullSnapshotWriter(Snapshot::Kind kind,
1128 uint8_t** vm_isolate_snapshot_buffer,
1115 uint8_t** isolate_snapshot_buffer, 1129 uint8_t** isolate_snapshot_buffer,
1116 ReAlloc alloc, 1130 ReAlloc alloc,
1117 InstructionsWriter* instructions_writer, 1131 InstructionsWriter* instructions_writer,
1118 bool snapshot_code,
1119 bool vm_isolate_is_symbolic); 1132 bool vm_isolate_is_symbolic);
1120 ~FullSnapshotWriter(); 1133 ~FullSnapshotWriter();
1121 1134
1122 uint8_t** vm_isolate_snapshot_buffer() { 1135 uint8_t** vm_isolate_snapshot_buffer() {
1123 return vm_isolate_snapshot_buffer_; 1136 return vm_isolate_snapshot_buffer_;
1124 } 1137 }
1125 1138
1126 uint8_t** isolate_snapshot_buffer() { 1139 uint8_t** isolate_snapshot_buffer() {
1127 return isolate_snapshot_buffer_; 1140 return isolate_snapshot_buffer_;
1128 } 1141 }
(...skipping 14 matching lines...) Expand all
1143 } 1156 }
1144 1157
1145 private: 1158 private:
1146 // Writes a snapshot of the VM Isolate. 1159 // Writes a snapshot of the VM Isolate.
1147 void WriteVmIsolateSnapshot(); 1160 void WriteVmIsolateSnapshot();
1148 1161
1149 // Writes a full snapshot of a regular Dart Isolate. 1162 // Writes a full snapshot of a regular Dart Isolate.
1150 void WriteIsolateFullSnapshot(); 1163 void WriteIsolateFullSnapshot();
1151 1164
1152 Thread* thread_; 1165 Thread* thread_;
1166 Snapshot::Kind kind_;
1153 uint8_t** vm_isolate_snapshot_buffer_; 1167 uint8_t** vm_isolate_snapshot_buffer_;
1154 uint8_t** isolate_snapshot_buffer_; 1168 uint8_t** isolate_snapshot_buffer_;
1155 ReAlloc alloc_; 1169 ReAlloc alloc_;
1156 intptr_t vm_isolate_snapshot_size_; 1170 intptr_t vm_isolate_snapshot_size_;
1157 intptr_t isolate_snapshot_size_; 1171 intptr_t isolate_snapshot_size_;
1158 ForwardList* forward_list_; 1172 ForwardList* forward_list_;
1159 InstructionsWriter* instructions_writer_; 1173 InstructionsWriter* instructions_writer_;
1160 Array& scripts_; 1174 Array& scripts_;
1161 Array& symbol_table_; 1175 Array& symbol_table_;
1162 bool snapshot_code_;
1163 bool vm_isolate_is_symbolic_; 1176 bool vm_isolate_is_symbolic_;
1164 1177
1165 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); 1178 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter);
1166 }; 1179 };
1167 1180
1168 1181
1169 class PrecompiledSnapshotWriter : public FullSnapshotWriter { 1182 class PrecompiledSnapshotWriter : public FullSnapshotWriter {
1170 public: 1183 public:
1171 PrecompiledSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer, 1184 PrecompiledSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer,
1172 uint8_t** isolate_snapshot_buffer, 1185 uint8_t** isolate_snapshot_buffer,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 private: 1234 private:
1222 SnapshotWriter* writer_; 1235 SnapshotWriter* writer_;
1223 bool as_references_; 1236 bool as_references_;
1224 1237
1225 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 1238 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
1226 }; 1239 };
1227 1240
1228 } // namespace dart 1241 } // namespace dart
1229 1242
1230 #endif // VM_SNAPSHOT_H_ 1243 #endif // VM_SNAPSHOT_H_
OLDNEW
« no previous file with comments | « runtime/vm/raw_object_snapshot.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698