OLD | NEW |
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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 422 |
423 // Add object to backward references. | 423 // Add object to backward references. |
424 void AddBackRef(intptr_t id, | 424 void AddBackRef(intptr_t id, |
425 Object* obj, | 425 Object* obj, |
426 DeserializeState state, | 426 DeserializeState state, |
427 bool defer_canonicalization = false); | 427 bool defer_canonicalization = false); |
428 | 428 |
429 // Get an object from the backward references list. | 429 // Get an object from the backward references list. |
430 Object* GetBackRef(intptr_t id); | 430 Object* GetBackRef(intptr_t id); |
431 | 431 |
432 // Read a full snap shot. | 432 // Read a script snapshot. |
433 RawApiError* ReadFullSnapshot(); | |
434 | |
435 // Read a script snap shot. | |
436 RawObject* ReadScriptSnapshot(); | 433 RawObject* ReadScriptSnapshot(); |
437 | 434 |
438 // Read version number of snapshot and verify. | 435 // Read version number of snapshot and verify. |
439 RawApiError* VerifyVersionAndFeatures(); | 436 RawApiError* VerifyVersionAndFeatures(); |
440 | 437 |
441 // Helper functions for creating uninitialized versions | 438 // Helper functions for creating uninitialized versions |
442 // of various object types. These are used when reading a | 439 // of various object types. These are used when reading a |
443 // full snapshot. | 440 // full snapshot. |
444 RawArray* NewArray(intptr_t len); | 441 RawArray* NewArray(intptr_t len); |
445 RawImmutableArray* NewImmutableArray(intptr_t len); | 442 RawImmutableArray* NewImmutableArray(intptr_t len); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 friend class TypeArguments; | 640 friend class TypeArguments; |
644 friend class TypeParameter; | 641 friend class TypeParameter; |
645 friend class TypeRef; | 642 friend class TypeRef; |
646 friend class UnhandledException; | 643 friend class UnhandledException; |
647 friend class UnresolvedClass; | 644 friend class UnresolvedClass; |
648 friend class WeakProperty; | 645 friend class WeakProperty; |
649 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 646 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
650 }; | 647 }; |
651 | 648 |
652 | 649 |
653 class VmIsolateSnapshotReader : public SnapshotReader { | |
654 public: | |
655 VmIsolateSnapshotReader(Snapshot::Kind kind, | |
656 const uint8_t* buffer, | |
657 intptr_t size, | |
658 const uint8_t* instructions_buffer, | |
659 const uint8_t* data_buffer, | |
660 Thread* thread); | |
661 ~VmIsolateSnapshotReader(); | |
662 | |
663 RawApiError* ReadVmIsolateSnapshot(); | |
664 | |
665 private: | |
666 DISALLOW_COPY_AND_ASSIGN(VmIsolateSnapshotReader); | |
667 }; | |
668 | |
669 | |
670 class IsolateSnapshotReader : public SnapshotReader { | |
671 public: | |
672 IsolateSnapshotReader(Snapshot::Kind kind, | |
673 const uint8_t* buffer, | |
674 intptr_t size, | |
675 const uint8_t* instructions_buffer, | |
676 const uint8_t* data_buffer, | |
677 Thread* thread); | |
678 ~IsolateSnapshotReader(); | |
679 | |
680 private: | |
681 DISALLOW_COPY_AND_ASSIGN(IsolateSnapshotReader); | |
682 }; | |
683 | |
684 | |
685 class ScriptSnapshotReader : public SnapshotReader { | 650 class ScriptSnapshotReader : public SnapshotReader { |
686 public: | 651 public: |
687 ScriptSnapshotReader(const uint8_t* buffer, | 652 ScriptSnapshotReader(const uint8_t* buffer, |
688 intptr_t size, | 653 intptr_t size, |
689 Thread* thread); | 654 Thread* thread); |
690 ~ScriptSnapshotReader(); | 655 ~ScriptSnapshotReader(); |
691 | 656 |
692 private: | 657 private: |
693 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotReader); | 658 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotReader); |
694 }; | 659 }; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 private: | 807 private: |
843 intptr_t first_object_id() const { return first_object_id_; } | 808 intptr_t first_object_id() const { return first_object_id_; } |
844 intptr_t next_object_id() const { return nodes_.length() + first_object_id_; } | 809 intptr_t next_object_id() const { return nodes_.length() + first_object_id_; } |
845 Heap* heap() const { return thread_->isolate()->heap(); } | 810 Heap* heap() const { return thread_->isolate()->heap(); } |
846 | 811 |
847 Thread* thread_; | 812 Thread* thread_; |
848 const intptr_t first_object_id_; | 813 const intptr_t first_object_id_; |
849 GrowableArray<Node*> nodes_; | 814 GrowableArray<Node*> nodes_; |
850 intptr_t first_unprocessed_object_id_; | 815 intptr_t first_unprocessed_object_id_; |
851 | 816 |
852 friend class FullSnapshotWriter; | |
853 DISALLOW_COPY_AND_ASSIGN(ForwardList); | 817 DISALLOW_COPY_AND_ASSIGN(ForwardList); |
854 }; | 818 }; |
855 | 819 |
856 | 820 |
857 class InstructionsWriter : public ZoneAllocated { | 821 class InstructionsWriter : public ZoneAllocated { |
858 public: | 822 public: |
859 InstructionsWriter() | 823 InstructionsWriter() |
860 : next_offset_(InstructionsSnapshot::kHeaderSize), | 824 : next_offset_(InstructionsSnapshot::kHeaderSize), |
861 next_object_offset_(DataSnapshot::kHeaderSize), | 825 next_object_offset_(DataSnapshot::kHeaderSize), |
862 instructions_(), | 826 instructions_(), |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 ObjectStore* object_store_; // Object store for common classes. | 1032 ObjectStore* object_store_; // Object store for common classes. |
1069 ClassTable* class_table_; // Class table for the class index to class lookup. | 1033 ClassTable* class_table_; // Class table for the class index to class lookup. |
1070 ForwardList* forward_list_; | 1034 ForwardList* forward_list_; |
1071 InstructionsWriter* instructions_writer_; | 1035 InstructionsWriter* instructions_writer_; |
1072 Exceptions::ExceptionType exception_type_; // Exception type. | 1036 Exceptions::ExceptionType exception_type_; // Exception type. |
1073 const char* exception_msg_; // Message associated with exception. | 1037 const char* exception_msg_; // Message associated with exception. |
1074 bool unmarked_objects_; // True if marked objects have been unmarked. | 1038 bool unmarked_objects_; // True if marked objects have been unmarked. |
1075 bool can_send_any_object_; // True if any Dart instance can be sent. | 1039 bool can_send_any_object_; // True if any Dart instance can be sent. |
1076 bool writing_vm_isolate_; | 1040 bool writing_vm_isolate_; |
1077 | 1041 |
1078 friend class FullSnapshotWriter; | |
1079 friend class RawArray; | 1042 friend class RawArray; |
1080 friend class RawClass; | 1043 friend class RawClass; |
1081 friend class RawClosureData; | 1044 friend class RawClosureData; |
1082 friend class RawCode; | 1045 friend class RawCode; |
1083 friend class RawContextScope; | 1046 friend class RawContextScope; |
1084 friend class RawExceptionHandlers; | 1047 friend class RawExceptionHandlers; |
1085 friend class RawField; | 1048 friend class RawField; |
1086 friend class RawFunction; | 1049 friend class RawFunction; |
1087 friend class RawGrowableObjectArray; | 1050 friend class RawGrowableObjectArray; |
1088 friend class RawImmutableArray; | 1051 friend class RawImmutableArray; |
(...skipping 13 matching lines...) Expand all Loading... |
1102 friend class RawType; | 1065 friend class RawType; |
1103 friend class RawTypeArguments; | 1066 friend class RawTypeArguments; |
1104 friend class RawTypeParameter; | 1067 friend class RawTypeParameter; |
1105 friend class RawUserTag; | 1068 friend class RawUserTag; |
1106 friend class SnapshotWriterVisitor; | 1069 friend class SnapshotWriterVisitor; |
1107 friend class WriteInlinedObjectVisitor; | 1070 friend class WriteInlinedObjectVisitor; |
1108 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); | 1071 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); |
1109 }; | 1072 }; |
1110 | 1073 |
1111 | 1074 |
1112 class FullSnapshotWriter { | |
1113 public: | |
1114 static const intptr_t kInitialSize = 64 * KB; | |
1115 FullSnapshotWriter(Snapshot::Kind kind, | |
1116 uint8_t** vm_isolate_snapshot_buffer, | |
1117 uint8_t** isolate_snapshot_buffer, | |
1118 ReAlloc alloc, | |
1119 InstructionsWriter* instructions_writer); | |
1120 ~FullSnapshotWriter(); | |
1121 | |
1122 uint8_t** vm_isolate_snapshot_buffer() { | |
1123 return vm_isolate_snapshot_buffer_; | |
1124 } | |
1125 | |
1126 uint8_t** isolate_snapshot_buffer() { | |
1127 return isolate_snapshot_buffer_; | |
1128 } | |
1129 | |
1130 Thread* thread() const { return thread_; } | |
1131 Zone* zone() const { return thread_->zone(); } | |
1132 Isolate* isolate() const { return thread_->isolate(); } | |
1133 Heap* heap() const { return isolate()->heap(); } | |
1134 | |
1135 // Writes a full snapshot of the Isolate. | |
1136 void WriteFullSnapshot(); | |
1137 | |
1138 intptr_t VmIsolateSnapshotSize() const { | |
1139 return vm_isolate_snapshot_size_; | |
1140 } | |
1141 intptr_t IsolateSnapshotSize() const { | |
1142 return isolate_snapshot_size_; | |
1143 } | |
1144 | |
1145 private: | |
1146 // Writes a snapshot of the VM Isolate. | |
1147 void WriteVmIsolateSnapshot(); | |
1148 | |
1149 // Writes a full snapshot of a regular Dart Isolate. | |
1150 void WriteIsolateFullSnapshot(); | |
1151 | |
1152 Thread* thread_; | |
1153 Snapshot::Kind kind_; | |
1154 uint8_t** vm_isolate_snapshot_buffer_; | |
1155 uint8_t** isolate_snapshot_buffer_; | |
1156 ReAlloc alloc_; | |
1157 intptr_t vm_isolate_snapshot_size_; | |
1158 intptr_t isolate_snapshot_size_; | |
1159 ForwardList* forward_list_; | |
1160 InstructionsWriter* instructions_writer_; | |
1161 Array& scripts_; | |
1162 Array& saved_symbol_table_; | |
1163 Array& new_vm_symbol_table_; | |
1164 | |
1165 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); | |
1166 }; | |
1167 | |
1168 | |
1169 class ScriptSnapshotWriter : public SnapshotWriter { | 1075 class ScriptSnapshotWriter : public SnapshotWriter { |
1170 public: | 1076 public: |
1171 static const intptr_t kInitialSize = 64 * KB; | 1077 static const intptr_t kInitialSize = 64 * KB; |
1172 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); | 1078 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); |
1173 ~ScriptSnapshotWriter() { } | 1079 ~ScriptSnapshotWriter() { } |
1174 | 1080 |
1175 // Writes a partial snapshot of the script. | 1081 // Writes a partial snapshot of the script. |
1176 void WriteScriptSnapshot(const Library& lib); | 1082 void WriteScriptSnapshot(const Library& lib); |
1177 | 1083 |
1178 private: | 1084 private: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 private: | 1117 private: |
1212 SnapshotWriter* writer_; | 1118 SnapshotWriter* writer_; |
1213 bool as_references_; | 1119 bool as_references_; |
1214 | 1120 |
1215 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1121 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
1216 }; | 1122 }; |
1217 | 1123 |
1218 } // namespace dart | 1124 } // namespace dart |
1219 | 1125 |
1220 #endif // VM_SNAPSHOT_H_ | 1126 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |