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 RUNTIME_VM_SNAPSHOT_H_ | 5 #ifndef RUNTIME_VM_SNAPSHOT_H_ |
6 #define RUNTIME_VM_SNAPSHOT_H_ | 6 #define RUNTIME_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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 kInlined = 0x1, | 114 kInlined = 0x1, |
115 kObjectId = 0x3, | 115 kObjectId = 0x3, |
116 }; | 116 }; |
117 static const int8_t kHeaderTagBits = 2; | 117 static const int8_t kHeaderTagBits = 2; |
118 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); | 118 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); |
119 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); | 119 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); |
120 static const bool kAsReference = true; | 120 static const bool kAsReference = true; |
121 static const bool kAsInlinedObject = false; | 121 static const bool kAsInlinedObject = false; |
122 static const intptr_t kInvalidPatchIndex = -1; | 122 static const intptr_t kInvalidPatchIndex = -1; |
123 | 123 |
124 | |
125 class SerializedHeaderTag | 124 class SerializedHeaderTag |
126 : public BitField<intptr_t, enum SerializedHeaderType, 0, kHeaderTagBits> { | 125 : public BitField<intptr_t, enum SerializedHeaderType, 0, kHeaderTagBits> { |
127 }; | 126 }; |
128 | 127 |
129 | |
130 class SerializedHeaderData | 128 class SerializedHeaderData |
131 : public BitField<intptr_t, intptr_t, kHeaderTagBits, kObjectIdBits> {}; | 129 : public BitField<intptr_t, intptr_t, kHeaderTagBits, kObjectIdBits> {}; |
132 | 130 |
133 | |
134 enum DeserializeState { | 131 enum DeserializeState { |
135 kIsDeserialized = 0, | 132 kIsDeserialized = 0, |
136 kIsNotDeserialized = 1, | 133 kIsNotDeserialized = 1, |
137 }; | 134 }; |
138 | 135 |
139 | |
140 enum SerializeState { | 136 enum SerializeState { |
141 kIsSerialized = 0, | 137 kIsSerialized = 0, |
142 kIsNotSerialized = 1, | 138 kIsNotSerialized = 1, |
143 }; | 139 }; |
144 | 140 |
145 | |
146 #define HEAP_SPACE(kind) (kind == Snapshot::kMessage) ? Heap::kNew : Heap::kOld | 141 #define HEAP_SPACE(kind) (kind == Snapshot::kMessage) ? Heap::kNew : Heap::kOld |
147 | 142 |
148 | |
149 // Structure capturing the raw snapshot. | 143 // Structure capturing the raw snapshot. |
150 // | 144 // |
151 // TODO(turnidge): Remove this class once the snapshot does not have a | 145 // TODO(turnidge): Remove this class once the snapshot does not have a |
152 // header anymore. This is pending on making the embedder pass in the | 146 // header anymore. This is pending on making the embedder pass in the |
153 // length of their snapshot. | 147 // length of their snapshot. |
154 class Snapshot { | 148 class Snapshot { |
155 public: | 149 public: |
156 enum Kind { | 150 enum Kind { |
157 // N.B. The order of these values must be preserved to give proper error | 151 // N.B. The order of these values must be preserved to give proper error |
158 // messages for old snapshots. | 152 // messages for old snapshots. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 195 |
202 // The following fields are potentially unaligned. | 196 // The following fields are potentially unaligned. |
203 int64_t unaligned_length_; // Stream length. | 197 int64_t unaligned_length_; // Stream length. |
204 int64_t unaligned_kind_; // Kind of snapshot. | 198 int64_t unaligned_kind_; // Kind of snapshot. |
205 | 199 |
206 // Variable length data follows here. | 200 // Variable length data follows here. |
207 | 201 |
208 DISALLOW_COPY_AND_ASSIGN(Snapshot); | 202 DISALLOW_COPY_AND_ASSIGN(Snapshot); |
209 }; | 203 }; |
210 | 204 |
211 | |
212 class Image : ValueObject { | 205 class Image : ValueObject { |
213 public: | 206 public: |
214 explicit Image(const void* raw_memory) : raw_memory_(raw_memory) { | 207 explicit Image(const void* raw_memory) : raw_memory_(raw_memory) { |
215 ASSERT(Utils::IsAligned(raw_memory, OS::kMaxPreferredCodeAlignment)); | 208 ASSERT(Utils::IsAligned(raw_memory, OS::kMaxPreferredCodeAlignment)); |
216 } | 209 } |
217 | 210 |
218 void* object_start() { | 211 void* object_start() { |
219 return reinterpret_cast<void*>(reinterpret_cast<uword>(raw_memory_) + | 212 return reinterpret_cast<void*>(reinterpret_cast<uword>(raw_memory_) + |
220 kHeaderSize); | 213 kHeaderSize); |
221 } | 214 } |
222 | 215 |
223 uword object_size() { | 216 uword object_size() { |
224 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); | 217 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); |
225 return snapshot_size - kHeaderSize; | 218 return snapshot_size - kHeaderSize; |
226 } | 219 } |
227 | 220 |
228 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; | 221 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; |
229 | 222 |
230 private: | 223 private: |
231 const void* raw_memory_; // The symbol kInstructionsSnapshot. | 224 const void* raw_memory_; // The symbol kInstructionsSnapshot. |
232 | 225 |
233 DISALLOW_COPY_AND_ASSIGN(Image); | 226 DISALLOW_COPY_AND_ASSIGN(Image); |
234 }; | 227 }; |
235 | 228 |
236 | |
237 class BaseReader { | 229 class BaseReader { |
238 public: | 230 public: |
239 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} | 231 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} |
240 // Reads raw data (for basic types). | 232 // Reads raw data (for basic types). |
241 // sizeof(T) must be in {1,2,4,8}. | 233 // sizeof(T) must be in {1,2,4,8}. |
242 template <typename T> | 234 template <typename T> |
243 T Read() { | 235 T Read() { |
244 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); | 236 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); |
245 } | 237 } |
246 | 238 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 ASSERT(IsVMIsolateObject(header_val)); | 277 ASSERT(IsVMIsolateObject(header_val)); |
286 intptr_t value = -header_val; // Header is negative for VM isolate objects. | 278 intptr_t value = -header_val; // Header is negative for VM isolate objects. |
287 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); | 279 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); |
288 return SerializedHeaderData::decode(value); | 280 return SerializedHeaderData::decode(value); |
289 } | 281 } |
290 | 282 |
291 private: | 283 private: |
292 ReadStream stream_; // input stream. | 284 ReadStream stream_; // input stream. |
293 }; | 285 }; |
294 | 286 |
295 | |
296 class BackRefNode : public ValueObject { | 287 class BackRefNode : public ValueObject { |
297 public: | 288 public: |
298 BackRefNode(Object* reference, | 289 BackRefNode(Object* reference, |
299 DeserializeState state, | 290 DeserializeState state, |
300 bool defer_canonicalization) | 291 bool defer_canonicalization) |
301 : reference_(reference), | 292 : reference_(reference), |
302 state_(state), | 293 state_(state), |
303 defer_canonicalization_(defer_canonicalization), | 294 defer_canonicalization_(defer_canonicalization), |
304 patch_records_(NULL) {} | 295 patch_records_(NULL) {} |
305 Object* reference() const { return reference_; } | 296 Object* reference() const { return reference_; } |
(...skipping 20 matching lines...) Expand all Loading... |
326 } | 317 } |
327 } | 318 } |
328 | 319 |
329 private: | 320 private: |
330 Object* reference_; | 321 Object* reference_; |
331 DeserializeState state_; | 322 DeserializeState state_; |
332 bool defer_canonicalization_; | 323 bool defer_canonicalization_; |
333 ZoneGrowableArray<intptr_t>* patch_records_; | 324 ZoneGrowableArray<intptr_t>* patch_records_; |
334 }; | 325 }; |
335 | 326 |
336 | |
337 class ImageReader : public ZoneAllocated { | 327 class ImageReader : public ZoneAllocated { |
338 public: | 328 public: |
339 ImageReader(const uint8_t* instructions_buffer, const uint8_t* data_buffer) | 329 ImageReader(const uint8_t* instructions_buffer, const uint8_t* data_buffer) |
340 : instructions_buffer_(instructions_buffer), data_buffer_(data_buffer) { | 330 : instructions_buffer_(instructions_buffer), data_buffer_(data_buffer) { |
341 ASSERT(instructions_buffer != NULL); | 331 ASSERT(instructions_buffer != NULL); |
342 ASSERT(data_buffer != NULL); | 332 ASSERT(data_buffer != NULL); |
343 ASSERT(Utils::IsAligned(reinterpret_cast<uword>(instructions_buffer), | 333 ASSERT(Utils::IsAligned(reinterpret_cast<uword>(instructions_buffer), |
344 OS::PreferredCodeAlignment())); | 334 OS::PreferredCodeAlignment())); |
345 } | 335 } |
346 | 336 |
347 RawInstructions* GetInstructionsAt(int32_t offset); | 337 RawInstructions* GetInstructionsAt(int32_t offset); |
348 RawObject* GetObjectAt(int32_t offset); | 338 RawObject* GetObjectAt(int32_t offset); |
349 | 339 |
350 private: | 340 private: |
351 const uint8_t* instructions_buffer_; | 341 const uint8_t* instructions_buffer_; |
352 const uint8_t* data_buffer_; | 342 const uint8_t* data_buffer_; |
353 | 343 |
354 DISALLOW_COPY_AND_ASSIGN(ImageReader); | 344 DISALLOW_COPY_AND_ASSIGN(ImageReader); |
355 }; | 345 }; |
356 | 346 |
357 | |
358 // Reads a snapshot into objects. | 347 // Reads a snapshot into objects. |
359 class SnapshotReader : public BaseReader { | 348 class SnapshotReader : public BaseReader { |
360 public: | 349 public: |
361 Thread* thread() const { return thread_; } | 350 Thread* thread() const { return thread_; } |
362 Zone* zone() const { return zone_; } | 351 Zone* zone() const { return zone_; } |
363 Isolate* isolate() const { return thread_->isolate(); } | 352 Isolate* isolate() const { return thread_->isolate(); } |
364 Heap* heap() const { return heap_; } | 353 Heap* heap() const { return heap_; } |
365 ObjectStore* object_store() const { return isolate()->object_store(); } | 354 ObjectStore* object_store() const { return isolate()->object_store(); } |
366 ClassTable* class_table() const { return isolate()->class_table(); } | 355 ClassTable* class_table() const { return isolate()->class_table(); } |
367 PassiveObject* PassiveObjectHandle() { return &pobj_; } | 356 PassiveObject* PassiveObjectHandle() { return &pobj_; } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 friend class Type; | 511 friend class Type; |
523 friend class TypeArguments; | 512 friend class TypeArguments; |
524 friend class TypeParameter; | 513 friend class TypeParameter; |
525 friend class TypeRef; | 514 friend class TypeRef; |
526 friend class UnhandledException; | 515 friend class UnhandledException; |
527 friend class UnresolvedClass; | 516 friend class UnresolvedClass; |
528 friend class WeakProperty; | 517 friend class WeakProperty; |
529 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 518 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
530 }; | 519 }; |
531 | 520 |
532 | |
533 class ScriptSnapshotReader : public SnapshotReader { | 521 class ScriptSnapshotReader : public SnapshotReader { |
534 public: | 522 public: |
535 ScriptSnapshotReader(const uint8_t* buffer, intptr_t size, Thread* thread); | 523 ScriptSnapshotReader(const uint8_t* buffer, intptr_t size, Thread* thread); |
536 ~ScriptSnapshotReader(); | 524 ~ScriptSnapshotReader(); |
537 | 525 |
538 private: | 526 private: |
539 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotReader); | 527 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotReader); |
540 }; | 528 }; |
541 | 529 |
542 | |
543 class MessageSnapshotReader : public SnapshotReader { | 530 class MessageSnapshotReader : public SnapshotReader { |
544 public: | 531 public: |
545 MessageSnapshotReader(const uint8_t* buffer, intptr_t size, Thread* thread); | 532 MessageSnapshotReader(const uint8_t* buffer, intptr_t size, Thread* thread); |
546 ~MessageSnapshotReader(); | 533 ~MessageSnapshotReader(); |
547 | 534 |
548 private: | 535 private: |
549 DISALLOW_COPY_AND_ASSIGN(MessageSnapshotReader); | 536 DISALLOW_COPY_AND_ASSIGN(MessageSnapshotReader); |
550 }; | 537 }; |
551 | 538 |
552 | |
553 class BaseWriter : public StackResource { | 539 class BaseWriter : public StackResource { |
554 public: | 540 public: |
555 // Size of the snapshot. | 541 // Size of the snapshot. |
556 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 542 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
557 | 543 |
558 // Writes raw data to the stream (basic type). | 544 // Writes raw data to the stream (basic type). |
559 // sizeof(T) must be in {1,2,4,8}. | 545 // sizeof(T) must be in {1,2,4,8}. |
560 template <typename T> | 546 template <typename T> |
561 void Write(T value) { | 547 void Write(T value) { |
562 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 548 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 stream_.set_buffer(NULL); | 624 stream_.set_buffer(NULL); |
639 } | 625 } |
640 | 626 |
641 private: | 627 private: |
642 WriteStream stream_; | 628 WriteStream stream_; |
643 DeAlloc dealloc_; | 629 DeAlloc dealloc_; |
644 | 630 |
645 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); | 631 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); |
646 }; | 632 }; |
647 | 633 |
648 | |
649 class ForwardList { | 634 class ForwardList { |
650 public: | 635 public: |
651 explicit ForwardList(Thread* thread, intptr_t first_object_id); | 636 explicit ForwardList(Thread* thread, intptr_t first_object_id); |
652 ~ForwardList(); | 637 ~ForwardList(); |
653 | 638 |
654 class Node : public ZoneAllocated { | 639 class Node : public ZoneAllocated { |
655 public: | 640 public: |
656 Node(const Object* obj, SerializeState state) : obj_(obj), state_(state) {} | 641 Node(const Object* obj, SerializeState state) : obj_(obj), state_(state) {} |
657 const Object* obj() const { return obj_; } | 642 const Object* obj() const { return obj_; } |
658 bool is_serialized() const { return state_ == kIsSerialized; } | 643 bool is_serialized() const { return state_ == kIsSerialized; } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 Heap* heap() const { return thread_->isolate()->heap(); } | 678 Heap* heap() const { return thread_->isolate()->heap(); } |
694 | 679 |
695 Thread* thread_; | 680 Thread* thread_; |
696 const intptr_t first_object_id_; | 681 const intptr_t first_object_id_; |
697 GrowableArray<Node*> nodes_; | 682 GrowableArray<Node*> nodes_; |
698 intptr_t first_unprocessed_object_id_; | 683 intptr_t first_unprocessed_object_id_; |
699 | 684 |
700 DISALLOW_COPY_AND_ASSIGN(ForwardList); | 685 DISALLOW_COPY_AND_ASSIGN(ForwardList); |
701 }; | 686 }; |
702 | 687 |
703 | |
704 class ImageWriter : public ZoneAllocated { | 688 class ImageWriter : public ZoneAllocated { |
705 public: | 689 public: |
706 ImageWriter() | 690 ImageWriter() |
707 : next_offset_(0), next_object_offset_(0), instructions_(), objects_() { | 691 : next_offset_(0), next_object_offset_(0), instructions_(), objects_() { |
708 ResetOffsets(); | 692 ResetOffsets(); |
709 } | 693 } |
710 virtual ~ImageWriter() {} | 694 virtual ~ImageWriter() {} |
711 | 695 |
712 void ResetOffsets() { | 696 void ResetOffsets() { |
713 next_offset_ = Image::kHeaderSize; | 697 next_offset_ = Image::kHeaderSize; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 | 738 |
755 intptr_t next_offset_; | 739 intptr_t next_offset_; |
756 intptr_t next_object_offset_; | 740 intptr_t next_object_offset_; |
757 GrowableArray<InstructionsData> instructions_; | 741 GrowableArray<InstructionsData> instructions_; |
758 GrowableArray<ObjectData> objects_; | 742 GrowableArray<ObjectData> objects_; |
759 | 743 |
760 private: | 744 private: |
761 DISALLOW_COPY_AND_ASSIGN(ImageWriter); | 745 DISALLOW_COPY_AND_ASSIGN(ImageWriter); |
762 }; | 746 }; |
763 | 747 |
764 | |
765 class AssemblyImageWriter : public ImageWriter { | 748 class AssemblyImageWriter : public ImageWriter { |
766 public: | 749 public: |
767 AssemblyImageWriter(uint8_t** assembly_buffer, | 750 AssemblyImageWriter(uint8_t** assembly_buffer, |
768 ReAlloc alloc, | 751 ReAlloc alloc, |
769 intptr_t initial_size); | 752 intptr_t initial_size); |
770 void Finalize(); | 753 void Finalize(); |
771 | 754 |
772 virtual void WriteText(WriteStream* clustered_stream, bool vm); | 755 virtual void WriteText(WriteStream* clustered_stream, bool vm); |
773 virtual intptr_t text_size() { return text_size_; } | 756 virtual intptr_t text_size() { return text_size_; } |
774 | 757 |
(...skipping 13 matching lines...) Expand all Loading... |
788 text_size_ += sizeof(value); | 771 text_size_ += sizeof(value); |
789 } | 772 } |
790 | 773 |
791 WriteStream assembly_stream_; | 774 WriteStream assembly_stream_; |
792 intptr_t text_size_; | 775 intptr_t text_size_; |
793 Dwarf* dwarf_; | 776 Dwarf* dwarf_; |
794 | 777 |
795 DISALLOW_COPY_AND_ASSIGN(AssemblyImageWriter); | 778 DISALLOW_COPY_AND_ASSIGN(AssemblyImageWriter); |
796 }; | 779 }; |
797 | 780 |
798 | |
799 class BlobImageWriter : public ImageWriter { | 781 class BlobImageWriter : public ImageWriter { |
800 public: | 782 public: |
801 BlobImageWriter(uint8_t** instructions_blob_buffer, | 783 BlobImageWriter(uint8_t** instructions_blob_buffer, |
802 ReAlloc alloc, | 784 ReAlloc alloc, |
803 intptr_t initial_size) | 785 intptr_t initial_size) |
804 : ImageWriter(), | 786 : ImageWriter(), |
805 instructions_blob_stream_(instructions_blob_buffer, | 787 instructions_blob_stream_(instructions_blob_buffer, |
806 alloc, | 788 alloc, |
807 initial_size) {} | 789 initial_size) {} |
808 | 790 |
809 virtual void WriteText(WriteStream* clustered_stream, bool vm); | 791 virtual void WriteText(WriteStream* clustered_stream, bool vm); |
810 virtual intptr_t text_size() { return InstructionsBlobSize(); } | 792 virtual intptr_t text_size() { return InstructionsBlobSize(); } |
811 | 793 |
812 intptr_t InstructionsBlobSize() const { | 794 intptr_t InstructionsBlobSize() const { |
813 return instructions_blob_stream_.bytes_written(); | 795 return instructions_blob_stream_.bytes_written(); |
814 } | 796 } |
815 | 797 |
816 private: | 798 private: |
817 WriteStream instructions_blob_stream_; | 799 WriteStream instructions_blob_stream_; |
818 | 800 |
819 DISALLOW_COPY_AND_ASSIGN(BlobImageWriter); | 801 DISALLOW_COPY_AND_ASSIGN(BlobImageWriter); |
820 }; | 802 }; |
821 | 803 |
822 | |
823 class SnapshotWriter : public BaseWriter { | 804 class SnapshotWriter : public BaseWriter { |
824 protected: | 805 protected: |
825 SnapshotWriter(Thread* thread, | 806 SnapshotWriter(Thread* thread, |
826 Snapshot::Kind kind, | 807 Snapshot::Kind kind, |
827 uint8_t** buffer, | 808 uint8_t** buffer, |
828 ReAlloc alloc, | 809 ReAlloc alloc, |
829 DeAlloc dealloc, | 810 DeAlloc dealloc, |
830 intptr_t initial_size, | 811 intptr_t initial_size, |
831 ForwardList* forward_list, | 812 ForwardList* forward_list, |
832 bool can_send_any_object); | 813 bool can_send_any_object); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 friend class RawTokenStream; | 912 friend class RawTokenStream; |
932 friend class RawType; | 913 friend class RawType; |
933 friend class RawTypeArguments; | 914 friend class RawTypeArguments; |
934 friend class RawTypeParameter; | 915 friend class RawTypeParameter; |
935 friend class RawUserTag; | 916 friend class RawUserTag; |
936 friend class SnapshotWriterVisitor; | 917 friend class SnapshotWriterVisitor; |
937 friend class WriteInlinedObjectVisitor; | 918 friend class WriteInlinedObjectVisitor; |
938 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); | 919 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); |
939 }; | 920 }; |
940 | 921 |
941 | |
942 class ScriptSnapshotWriter : public SnapshotWriter { | 922 class ScriptSnapshotWriter : public SnapshotWriter { |
943 public: | 923 public: |
944 static const intptr_t kInitialSize = 64 * KB; | 924 static const intptr_t kInitialSize = 64 * KB; |
945 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); | 925 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); |
946 ~ScriptSnapshotWriter() {} | 926 ~ScriptSnapshotWriter() {} |
947 | 927 |
948 // Writes a partial snapshot of the script. | 928 // Writes a partial snapshot of the script. |
949 void WriteScriptSnapshot(const Library& lib); | 929 void WriteScriptSnapshot(const Library& lib); |
950 | 930 |
951 private: | 931 private: |
952 ForwardList forward_list_; | 932 ForwardList forward_list_; |
953 | 933 |
954 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); | 934 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); |
955 }; | 935 }; |
956 | 936 |
957 | |
958 class SerializedObjectBuffer : public StackResource { | 937 class SerializedObjectBuffer : public StackResource { |
959 public: | 938 public: |
960 SerializedObjectBuffer() | 939 SerializedObjectBuffer() |
961 : StackResource(Thread::Current()), | 940 : StackResource(Thread::Current()), |
962 object_data_(NULL), | 941 object_data_(NULL), |
963 object_length_(0) {} | 942 object_length_(0) {} |
964 | 943 |
965 virtual ~SerializedObjectBuffer() { free(object_data_); } | 944 virtual ~SerializedObjectBuffer() { free(object_data_); } |
966 | 945 |
967 void StealBuffer(uint8_t** out_data, intptr_t* out_length) { | 946 void StealBuffer(uint8_t** out_data, intptr_t* out_length) { |
968 *out_data = object_data_; | 947 *out_data = object_data_; |
969 *out_length = object_length_; | 948 *out_length = object_length_; |
970 | 949 |
971 object_data_ = NULL; | 950 object_data_ = NULL; |
972 object_length_ = 0; | 951 object_length_ = 0; |
973 } | 952 } |
974 | 953 |
975 uint8_t** data_buffer() { return &object_data_; } | 954 uint8_t** data_buffer() { return &object_data_; } |
976 intptr_t* data_length() { return &object_length_; } | 955 intptr_t* data_length() { return &object_length_; } |
977 | 956 |
978 private: | 957 private: |
979 uint8_t* object_data_; | 958 uint8_t* object_data_; |
980 intptr_t object_length_; | 959 intptr_t object_length_; |
981 }; | 960 }; |
982 | 961 |
983 | |
984 class MessageWriter : public SnapshotWriter { | 962 class MessageWriter : public SnapshotWriter { |
985 public: | 963 public: |
986 static const intptr_t kInitialSize = 512; | 964 static const intptr_t kInitialSize = 512; |
987 MessageWriter(uint8_t** buffer, | 965 MessageWriter(uint8_t** buffer, |
988 ReAlloc alloc, | 966 ReAlloc alloc, |
989 DeAlloc dealloc, | 967 DeAlloc dealloc, |
990 bool can_send_any_object, | 968 bool can_send_any_object, |
991 intptr_t* buffer_len = NULL); | 969 intptr_t* buffer_len = NULL); |
992 ~MessageWriter() {} | 970 ~MessageWriter() {} |
993 | 971 |
994 void WriteMessage(const Object& obj); | 972 void WriteMessage(const Object& obj); |
995 | 973 |
996 private: | 974 private: |
997 ForwardList forward_list_; | 975 ForwardList forward_list_; |
998 intptr_t* buffer_len_; | 976 intptr_t* buffer_len_; |
999 | 977 |
1000 DISALLOW_COPY_AND_ASSIGN(MessageWriter); | 978 DISALLOW_COPY_AND_ASSIGN(MessageWriter); |
1001 }; | 979 }; |
1002 | 980 |
1003 | |
1004 // An object pointer visitor implementation which writes out | 981 // An object pointer visitor implementation which writes out |
1005 // objects to a snap shot. | 982 // objects to a snap shot. |
1006 class SnapshotWriterVisitor : public ObjectPointerVisitor { | 983 class SnapshotWriterVisitor : public ObjectPointerVisitor { |
1007 public: | 984 public: |
1008 SnapshotWriterVisitor(SnapshotWriter* writer, bool as_references) | 985 SnapshotWriterVisitor(SnapshotWriter* writer, bool as_references) |
1009 : ObjectPointerVisitor(Isolate::Current()), | 986 : ObjectPointerVisitor(Isolate::Current()), |
1010 writer_(writer), | 987 writer_(writer), |
1011 as_references_(as_references) {} | 988 as_references_(as_references) {} |
1012 | 989 |
1013 virtual void VisitPointers(RawObject** first, RawObject** last); | 990 virtual void VisitPointers(RawObject** first, RawObject** last); |
1014 | 991 |
1015 private: | 992 private: |
1016 SnapshotWriter* writer_; | 993 SnapshotWriter* writer_; |
1017 bool as_references_; | 994 bool as_references_; |
1018 | 995 |
1019 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 996 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
1020 }; | 997 }; |
1021 | 998 |
1022 } // namespace dart | 999 } // namespace dart |
1023 | 1000 |
1024 #endif // RUNTIME_VM_SNAPSHOT_H_ | 1001 #endif // RUNTIME_VM_SNAPSHOT_H_ |
OLD | NEW |