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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // This valus is serialized as a positive number. | 90 // This valus is serialized as a positive number. |
91 // - Object that is seen for the first time (inlined in the stream): | 91 // - Object that is seen for the first time (inlined in the stream): |
92 // (a unique id for this object | 0x1) | 92 // (a unique id for this object | 0x1) |
93 enum SerializedHeaderType { | 93 enum SerializedHeaderType { |
94 kInlined = 0x1, | 94 kInlined = 0x1, |
95 kObjectId = 0x3, | 95 kObjectId = 0x3, |
96 }; | 96 }; |
97 static const int8_t kHeaderTagBits = 2; | 97 static const int8_t kHeaderTagBits = 2; |
98 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); | 98 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); |
99 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); | 99 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); |
| 100 static const bool kAsReference = true; |
| 101 static const bool kAsInlinedObject = false; |
100 | 102 |
101 | 103 |
102 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, | 104 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, |
103 0, | 105 0, |
104 kHeaderTagBits> { | 106 kHeaderTagBits> { |
105 }; | 107 }; |
106 | 108 |
107 | 109 |
108 class SerializedHeaderData : public BitField<intptr_t, | 110 class SerializedHeaderData : public BitField<intptr_t, |
109 kHeaderTagBits, | 111 kHeaderTagBits, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 362 } |
361 void ResetBackwardReferenceTable() { backward_references_ = NULL; } | 363 void ResetBackwardReferenceTable() { backward_references_ = NULL; } |
362 PageSpace* old_space() const { return old_space_; } | 364 PageSpace* old_space() const { return old_space_; } |
363 | 365 |
364 private: | 366 private: |
365 // Allocate uninitialized objects, this is used when reading a full snapshot. | 367 // Allocate uninitialized objects, this is used when reading a full snapshot. |
366 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size); | 368 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size); |
367 | 369 |
368 RawClass* ReadClassId(intptr_t object_id); | 370 RawClass* ReadClassId(intptr_t object_id); |
369 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); | 371 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); |
370 RawObject* ReadObjectImpl(); | 372 |
371 RawObject* ReadObjectImpl(intptr_t header); | 373 // Implementation to read an object. |
372 RawObject* ReadObjectRef(); | 374 RawObject* ReadObjectImpl(bool as_reference); |
| 375 RawObject* ReadObjectImpl(intptr_t header, bool as_reference); |
| 376 |
| 377 // Read an object reference from the stream. |
| 378 RawObject* ReadObjectRef(intptr_t object_id, |
| 379 intptr_t class_header, |
| 380 intptr_t tags); |
| 381 |
| 382 // Read an inlined object from the stream. |
| 383 RawObject* ReadInlinedObject(intptr_t object_id, |
| 384 intptr_t class_header, |
| 385 intptr_t tags); |
373 | 386 |
374 // Read a VM isolate object that was serialized as an Id. | 387 // Read a VM isolate object that was serialized as an Id. |
375 RawObject* ReadVMIsolateObject(intptr_t object_id); | 388 RawObject* ReadVMIsolateObject(intptr_t object_id); |
376 | 389 |
377 // Read an object that was serialized as an Id (singleton in object store, | 390 // Read an object that was serialized as an Id (singleton in object store, |
378 // or an object that was already serialized before). | 391 // or an object that was already serialized before). |
379 RawObject* ReadIndexedObject(intptr_t object_id); | 392 RawObject* ReadIndexedObject(intptr_t object_id); |
380 | 393 |
381 // Read an inlined object from the stream. | |
382 RawObject* ReadInlinedObject(intptr_t object_id); | |
383 | |
384 // Decode class id from the header field. | 394 // Decode class id from the header field. |
385 intptr_t LookupInternalClass(intptr_t class_header); | 395 intptr_t LookupInternalClass(intptr_t class_header); |
386 | 396 |
387 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); | 397 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); |
388 | 398 |
389 intptr_t NextAvailableObjectId() const; | 399 intptr_t NextAvailableObjectId() const; |
390 | 400 |
391 void SetReadException(const char* msg); | 401 void SetReadException(const char* msg); |
392 | 402 |
393 RawObject* VmIsolateSnapshotObject(intptr_t index) const; | 403 RawObject* VmIsolateSnapshotObject(intptr_t index) const; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 void UnmarkAll() { | 706 void UnmarkAll() { |
697 if (!unmarked_objects_ && forward_list_ != NULL) { | 707 if (!unmarked_objects_ && forward_list_ != NULL) { |
698 forward_list_->UnmarkAll(); | 708 forward_list_->UnmarkAll(); |
699 unmarked_objects_ = true; | 709 unmarked_objects_ = true; |
700 } | 710 } |
701 } | 711 } |
702 | 712 |
703 bool CheckAndWritePredefinedObject(RawObject* raw); | 713 bool CheckAndWritePredefinedObject(RawObject* raw); |
704 void HandleVMIsolateObject(RawObject* raw); | 714 void HandleVMIsolateObject(RawObject* raw); |
705 | 715 |
706 void WriteObjectRef(RawObject* raw); | |
707 void WriteClassId(RawClass* cls); | 716 void WriteClassId(RawClass* cls); |
708 void WriteStaticImplicitClosure(intptr_t object_id, | 717 void WriteStaticImplicitClosure(intptr_t object_id, |
709 RawFunction* func, | 718 RawFunction* func, |
710 intptr_t tags); | 719 intptr_t tags); |
711 void WriteObjectImpl(RawObject* raw); | 720 void WriteObjectImpl(RawObject* raw, bool as_reference); |
| 721 void WriteObjectRef(RawObject* raw); |
712 void WriteInlinedObject(RawObject* raw); | 722 void WriteInlinedObject(RawObject* raw); |
713 void WriteForwardedObjects(); | 723 void WriteForwardedObjects(); |
714 void ArrayWriteTo(intptr_t object_id, | 724 void ArrayWriteTo(intptr_t object_id, |
715 intptr_t array_kind, | 725 intptr_t array_kind, |
716 intptr_t tags, | 726 intptr_t tags, |
717 RawSmi* length, | 727 RawSmi* length, |
718 RawTypeArguments* type_arguments, | 728 RawTypeArguments* type_arguments, |
719 RawObject* data[]); | 729 RawObject* data[]); |
720 RawFunction* IsSerializableClosure(RawClass* cls, RawObject* obj); | 730 RawFunction* IsSerializableClosure(RawClass* cls, RawObject* obj); |
721 RawClass* GetFunctionOwner(RawFunction* func); | 731 RawClass* GetFunctionOwner(RawFunction* func); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 private: | 884 private: |
875 SnapshotWriter* writer_; | 885 SnapshotWriter* writer_; |
876 bool as_references_; | 886 bool as_references_; |
877 | 887 |
878 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 888 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
879 }; | 889 }; |
880 | 890 |
881 } // namespace dart | 891 } // namespace dart |
882 | 892 |
883 #endif // VM_SNAPSHOT_H_ | 893 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |