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

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

Powered by Google App Engine
This is Rietveld 408576698