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 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 class SnapshotWriter : public BaseWriter { | 982 class SnapshotWriter : public BaseWriter { |
983 protected: | 983 protected: |
984 SnapshotWriter(Thread* thread, | 984 SnapshotWriter(Thread* thread, |
985 Snapshot::Kind kind, | 985 Snapshot::Kind kind, |
986 uint8_t** buffer, | 986 uint8_t** buffer, |
987 ReAlloc alloc, | 987 ReAlloc alloc, |
988 intptr_t initial_size, | 988 intptr_t initial_size, |
989 ForwardList* forward_list, | 989 ForwardList* forward_list, |
990 InstructionsWriter* instructions_writer, | 990 InstructionsWriter* instructions_writer, |
991 bool can_send_any_object, | 991 bool can_send_any_object, |
992 bool vm_isolate_is_symbolic); | 992 bool writing_vm_isolate = false); |
993 | 993 |
994 public: | 994 public: |
995 // Snapshot kind. | 995 // Snapshot kind. |
996 Snapshot::Kind kind() const { return kind_; } | 996 Snapshot::Kind kind() const { return kind_; } |
997 Thread* thread() const { return thread_; } | 997 Thread* thread() const { return thread_; } |
998 Zone* zone() const { return thread_->zone(); } | 998 Zone* zone() const { return thread_->zone(); } |
999 Isolate* isolate() const { return thread_->isolate(); } | 999 Isolate* isolate() const { return thread_->isolate(); } |
1000 Heap* heap() const { return isolate()->heap(); } | 1000 Heap* heap() const { return isolate()->heap(); } |
1001 | 1001 |
1002 // Serialize an object into the buffer. | 1002 // Serialize an object into the buffer. |
1003 void WriteObject(RawObject* raw); | 1003 void WriteObject(RawObject* raw); |
1004 | 1004 |
1005 uword GetObjectTags(RawObject* raw); | 1005 uword GetObjectTags(RawObject* raw); |
1006 | 1006 |
1007 Exceptions::ExceptionType exception_type() const { | 1007 Exceptions::ExceptionType exception_type() const { |
1008 return exception_type_; | 1008 return exception_type_; |
1009 } | 1009 } |
1010 void set_exception_type(Exceptions::ExceptionType type) { | 1010 void set_exception_type(Exceptions::ExceptionType type) { |
1011 exception_type_ = type; | 1011 exception_type_ = type; |
1012 } | 1012 } |
1013 const char* exception_msg() const { return exception_msg_; } | 1013 const char* exception_msg() const { return exception_msg_; } |
1014 void set_exception_msg(const char* msg) { | 1014 void set_exception_msg(const char* msg) { |
1015 exception_msg_ = msg; | 1015 exception_msg_ = msg; |
1016 } | 1016 } |
1017 bool can_send_any_object() const { return can_send_any_object_; } | 1017 bool can_send_any_object() const { return can_send_any_object_; } |
1018 bool vm_isolate_is_symbolic() const { return vm_isolate_is_symbolic_; } | 1018 bool writing_vm_isolate() const { return writing_vm_isolate_; } |
1019 void ThrowException(Exceptions::ExceptionType type, const char* msg); | 1019 void ThrowException(Exceptions::ExceptionType type, const char* msg); |
1020 | 1020 |
1021 // Write a version string for the snapshot. | 1021 // Write a version string for the snapshot. |
1022 void WriteVersion(); | 1022 void WriteVersion(); |
1023 | 1023 |
1024 static intptr_t FirstObjectId(); | |
1025 | |
1026 int32_t GetInstructionsId(RawInstructions* instructions, RawCode* code) { | 1024 int32_t GetInstructionsId(RawInstructions* instructions, RawCode* code) { |
1027 return instructions_writer_->GetOffsetFor(instructions, code); | 1025 return instructions_writer_->GetOffsetFor(instructions, code); |
1028 } | 1026 } |
1029 | 1027 |
1030 int32_t GetObjectId(RawObject* raw) { | 1028 int32_t GetObjectId(RawObject* raw) { |
1031 return instructions_writer_->GetObjectOffsetFor(raw); | 1029 return instructions_writer_->GetObjectOffsetFor(raw); |
1032 } | 1030 } |
1033 | 1031 |
1034 void WriteFunctionId(RawFunction* func, bool owner_is_class); | 1032 void WriteFunctionId(RawFunction* func, bool owner_is_class); |
1035 | 1033 |
(...skipping 25 matching lines...) Expand all Loading... |
1061 void CheckForNativeFields(RawClass* cls); | 1059 void CheckForNativeFields(RawClass* cls); |
1062 void SetWriteException(Exceptions::ExceptionType type, const char* msg); | 1060 void SetWriteException(Exceptions::ExceptionType type, const char* msg); |
1063 void WriteInstance(RawObject* raw, | 1061 void WriteInstance(RawObject* raw, |
1064 RawClass* cls, | 1062 RawClass* cls, |
1065 intptr_t tags, | 1063 intptr_t tags, |
1066 intptr_t object_id, | 1064 intptr_t object_id, |
1067 bool as_reference); | 1065 bool as_reference); |
1068 bool AllowObjectsInDartLibrary(RawLibrary* library); | 1066 bool AllowObjectsInDartLibrary(RawLibrary* library); |
1069 intptr_t FindVmSnapshotObject(RawObject* rawobj); | 1067 intptr_t FindVmSnapshotObject(RawObject* rawobj); |
1070 | 1068 |
1071 void InitializeForwardList(ForwardList* forward_list) { | |
1072 ASSERT(forward_list_ == NULL); | |
1073 forward_list_ = forward_list; | |
1074 } | |
1075 void ResetForwardList() { | |
1076 ASSERT(forward_list_ != NULL); | |
1077 forward_list_ = NULL; | |
1078 } | |
1079 | |
1080 ObjectStore* object_store() const { return object_store_; } | 1069 ObjectStore* object_store() const { return object_store_; } |
1081 | 1070 |
1082 private: | 1071 private: |
1083 Thread* thread_; | 1072 Thread* thread_; |
1084 Snapshot::Kind kind_; | 1073 Snapshot::Kind kind_; |
1085 ObjectStore* object_store_; // Object store for common classes. | 1074 ObjectStore* object_store_; // Object store for common classes. |
1086 ClassTable* class_table_; // Class table for the class index to class lookup. | 1075 ClassTable* class_table_; // Class table for the class index to class lookup. |
1087 ForwardList* forward_list_; | 1076 ForwardList* forward_list_; |
1088 InstructionsWriter* instructions_writer_; | 1077 InstructionsWriter* instructions_writer_; |
1089 Exceptions::ExceptionType exception_type_; // Exception type. | 1078 Exceptions::ExceptionType exception_type_; // Exception type. |
1090 const char* exception_msg_; // Message associated with exception. | 1079 const char* exception_msg_; // Message associated with exception. |
1091 bool unmarked_objects_; // True if marked objects have been unmarked. | 1080 bool unmarked_objects_; // True if marked objects have been unmarked. |
1092 bool can_send_any_object_; // True if any Dart instance can be sent. | 1081 bool can_send_any_object_; // True if any Dart instance can be sent. |
1093 bool vm_isolate_is_symbolic_; | 1082 bool writing_vm_isolate_; |
1094 | 1083 |
1095 friend class FullSnapshotWriter; | 1084 friend class FullSnapshotWriter; |
1096 friend class RawArray; | 1085 friend class RawArray; |
1097 friend class RawClass; | 1086 friend class RawClass; |
1098 friend class RawClosureData; | 1087 friend class RawClosureData; |
1099 friend class RawCode; | 1088 friend class RawCode; |
1100 friend class RawContextScope; | 1089 friend class RawContextScope; |
1101 friend class RawExceptionHandlers; | 1090 friend class RawExceptionHandlers; |
1102 friend class RawField; | 1091 friend class RawField; |
1103 friend class RawFunction; | 1092 friend class RawFunction; |
(...skipping 20 matching lines...) Expand all Loading... |
1124 }; | 1113 }; |
1125 | 1114 |
1126 | 1115 |
1127 class FullSnapshotWriter { | 1116 class FullSnapshotWriter { |
1128 public: | 1117 public: |
1129 static const intptr_t kInitialSize = 64 * KB; | 1118 static const intptr_t kInitialSize = 64 * KB; |
1130 FullSnapshotWriter(Snapshot::Kind kind, | 1119 FullSnapshotWriter(Snapshot::Kind kind, |
1131 uint8_t** vm_isolate_snapshot_buffer, | 1120 uint8_t** vm_isolate_snapshot_buffer, |
1132 uint8_t** isolate_snapshot_buffer, | 1121 uint8_t** isolate_snapshot_buffer, |
1133 ReAlloc alloc, | 1122 ReAlloc alloc, |
1134 InstructionsWriter* instructions_writer, | 1123 InstructionsWriter* instructions_writer); |
1135 bool vm_isolate_is_symbolic); | |
1136 ~FullSnapshotWriter(); | 1124 ~FullSnapshotWriter(); |
1137 | 1125 |
1138 uint8_t** vm_isolate_snapshot_buffer() { | 1126 uint8_t** vm_isolate_snapshot_buffer() { |
1139 return vm_isolate_snapshot_buffer_; | 1127 return vm_isolate_snapshot_buffer_; |
1140 } | 1128 } |
1141 | 1129 |
1142 uint8_t** isolate_snapshot_buffer() { | 1130 uint8_t** isolate_snapshot_buffer() { |
1143 return isolate_snapshot_buffer_; | 1131 return isolate_snapshot_buffer_; |
1144 } | 1132 } |
1145 | 1133 |
(...skipping 22 matching lines...) Expand all Loading... |
1168 Thread* thread_; | 1156 Thread* thread_; |
1169 Snapshot::Kind kind_; | 1157 Snapshot::Kind kind_; |
1170 uint8_t** vm_isolate_snapshot_buffer_; | 1158 uint8_t** vm_isolate_snapshot_buffer_; |
1171 uint8_t** isolate_snapshot_buffer_; | 1159 uint8_t** isolate_snapshot_buffer_; |
1172 ReAlloc alloc_; | 1160 ReAlloc alloc_; |
1173 intptr_t vm_isolate_snapshot_size_; | 1161 intptr_t vm_isolate_snapshot_size_; |
1174 intptr_t isolate_snapshot_size_; | 1162 intptr_t isolate_snapshot_size_; |
1175 ForwardList* forward_list_; | 1163 ForwardList* forward_list_; |
1176 InstructionsWriter* instructions_writer_; | 1164 InstructionsWriter* instructions_writer_; |
1177 Array& scripts_; | 1165 Array& scripts_; |
1178 Array& symbol_table_; | 1166 Array& saved_symbol_table_; |
1179 bool vm_isolate_is_symbolic_; | 1167 Array& new_vm_symbol_table_; |
1180 | 1168 |
1181 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); | 1169 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); |
1182 }; | 1170 }; |
1183 | 1171 |
1184 | 1172 |
1185 class ScriptSnapshotWriter : public SnapshotWriter { | 1173 class ScriptSnapshotWriter : public SnapshotWriter { |
1186 public: | 1174 public: |
1187 static const intptr_t kInitialSize = 64 * KB; | 1175 static const intptr_t kInitialSize = 64 * KB; |
1188 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); | 1176 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); |
1189 ~ScriptSnapshotWriter() { } | 1177 ~ScriptSnapshotWriter() { } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 private: | 1215 private: |
1228 SnapshotWriter* writer_; | 1216 SnapshotWriter* writer_; |
1229 bool as_references_; | 1217 bool as_references_; |
1230 | 1218 |
1231 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1219 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
1232 }; | 1220 }; |
1233 | 1221 |
1234 } // namespace dart | 1222 } // namespace dart |
1235 | 1223 |
1236 #endif // VM_SNAPSHOT_H_ | 1224 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |