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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // The following fields are potentially unaligned. | 204 // The following fields are potentially unaligned. |
205 int64_t unaligned_length_; // Stream length. | 205 int64_t unaligned_length_; // Stream length. |
206 int64_t unaligned_kind_; // Kind of snapshot. | 206 int64_t unaligned_kind_; // Kind of snapshot. |
207 | 207 |
208 // Variable length data follows here. | 208 // Variable length data follows here. |
209 | 209 |
210 DISALLOW_COPY_AND_ASSIGN(Snapshot); | 210 DISALLOW_COPY_AND_ASSIGN(Snapshot); |
211 }; | 211 }; |
212 | 212 |
213 | 213 |
214 class InstructionsSnapshot : ValueObject { | 214 class Image : ValueObject { |
215 public: | 215 public: |
216 explicit InstructionsSnapshot(const void* raw_memory) | 216 explicit Image(const void* raw_memory) : raw_memory_(raw_memory) { |
217 : raw_memory_(raw_memory) { | |
218 ASSERT(Utils::IsAligned(raw_memory, OS::kMaxPreferredCodeAlignment)); | 217 ASSERT(Utils::IsAligned(raw_memory, OS::kMaxPreferredCodeAlignment)); |
219 } | 218 } |
220 | 219 |
221 void* instructions_start() { | 220 void* object_start() { |
222 return reinterpret_cast<void*>(reinterpret_cast<uword>(raw_memory_) + | 221 return reinterpret_cast<void*>(reinterpret_cast<uword>(raw_memory_) + |
223 kHeaderSize); | 222 kHeaderSize); |
224 } | 223 } |
225 | 224 |
226 uword instructions_size() { | 225 uword object_size() { |
227 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); | 226 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); |
228 return snapshot_size - kHeaderSize; | 227 return snapshot_size - kHeaderSize; |
229 } | 228 } |
230 | 229 |
231 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; | 230 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; |
232 | 231 |
233 private: | 232 private: |
234 const void* raw_memory_; // The symbol kInstructionsSnapshot. | 233 const void* raw_memory_; // The symbol kInstructionsSnapshot. |
235 | 234 |
236 DISALLOW_COPY_AND_ASSIGN(InstructionsSnapshot); | 235 DISALLOW_COPY_AND_ASSIGN(Image); |
237 }; | 236 }; |
238 | 237 |
239 | 238 |
240 class DataSnapshot : ValueObject { | |
241 public: | |
242 explicit DataSnapshot(const void* raw_memory) : raw_memory_(raw_memory) { | |
243 ASSERT(Utils::IsAligned(raw_memory, 2 * kWordSize)); // kObjectAlignment | |
244 } | |
245 | |
246 void* data_start() { | |
247 return reinterpret_cast<void*>(reinterpret_cast<uword>(raw_memory_) + | |
248 kHeaderSize); | |
249 } | |
250 | |
251 uword data_size() { | |
252 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); | |
253 return snapshot_size - kHeaderSize; | |
254 } | |
255 | |
256 // Header: data length and padding for alignment. We use the same alignment | |
257 // as for code for now. | |
258 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; | |
259 | |
260 private: | |
261 const void* raw_memory_; // The symbol kDataSnapshot. | |
262 | |
263 DISALLOW_COPY_AND_ASSIGN(DataSnapshot); | |
264 }; | |
265 | |
266 | |
267 class BaseReader { | 239 class BaseReader { |
268 public: | 240 public: |
269 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} | 241 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} |
270 // Reads raw data (for basic types). | 242 // Reads raw data (for basic types). |
271 // sizeof(T) must be in {1,2,4,8}. | 243 // sizeof(T) must be in {1,2,4,8}. |
272 template <typename T> | 244 template <typename T> |
273 T Read() { | 245 T Read() { |
274 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); | 246 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); |
275 } | 247 } |
276 | 248 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 | 693 |
722 Thread* thread_; | 694 Thread* thread_; |
723 const intptr_t first_object_id_; | 695 const intptr_t first_object_id_; |
724 GrowableArray<Node*> nodes_; | 696 GrowableArray<Node*> nodes_; |
725 intptr_t first_unprocessed_object_id_; | 697 intptr_t first_unprocessed_object_id_; |
726 | 698 |
727 DISALLOW_COPY_AND_ASSIGN(ForwardList); | 699 DISALLOW_COPY_AND_ASSIGN(ForwardList); |
728 }; | 700 }; |
729 | 701 |
730 | 702 |
731 class InstructionsWriter : public ZoneAllocated { | 703 class ImageWriter : public ZoneAllocated { |
732 public: | 704 public: |
733 InstructionsWriter() | 705 ImageWriter() |
734 : next_offset_(0), next_object_offset_(0), instructions_(), objects_() { | 706 : next_offset_(0), next_object_offset_(0), instructions_(), objects_() { |
735 ResetOffsets(); | 707 ResetOffsets(); |
736 } | 708 } |
737 virtual ~InstructionsWriter() {} | 709 virtual ~ImageWriter() {} |
738 | 710 |
739 void ResetOffsets() { | 711 void ResetOffsets() { |
740 next_offset_ = InstructionsSnapshot::kHeaderSize; | 712 next_offset_ = Image::kHeaderSize; |
741 next_object_offset_ = DataSnapshot::kHeaderSize; | 713 next_object_offset_ = Image::kHeaderSize; |
742 instructions_.Clear(); | 714 instructions_.Clear(); |
743 objects_.Clear(); | 715 objects_.Clear(); |
744 } | 716 } |
745 int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code); | 717 int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code); |
746 int32_t GetObjectOffsetFor(RawObject* raw_object); | 718 int32_t GetObjectOffsetFor(RawObject* raw_object); |
747 | 719 |
748 void Write(WriteStream* clustered_stream, bool vm); | 720 void Write(WriteStream* clustered_stream, bool vm); |
749 virtual intptr_t text_size() = 0; | 721 virtual intptr_t text_size() = 0; |
750 intptr_t data_size() { return next_object_offset_; } | 722 intptr_t data_size() { return next_object_offset_; } |
751 | 723 |
(...skipping 26 matching lines...) Expand all Loading... |
778 const Object* obj_; | 750 const Object* obj_; |
779 }; | 751 }; |
780 }; | 752 }; |
781 | 753 |
782 intptr_t next_offset_; | 754 intptr_t next_offset_; |
783 intptr_t next_object_offset_; | 755 intptr_t next_object_offset_; |
784 GrowableArray<InstructionsData> instructions_; | 756 GrowableArray<InstructionsData> instructions_; |
785 GrowableArray<ObjectData> objects_; | 757 GrowableArray<ObjectData> objects_; |
786 | 758 |
787 private: | 759 private: |
788 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); | 760 DISALLOW_COPY_AND_ASSIGN(ImageWriter); |
789 }; | 761 }; |
790 | 762 |
791 | 763 |
792 class AssemblyInstructionsWriter : public InstructionsWriter { | 764 class AssemblyImageWriter : public ImageWriter { |
793 public: | 765 public: |
794 AssemblyInstructionsWriter(uint8_t** assembly_buffer, | 766 AssemblyImageWriter(uint8_t** assembly_buffer, |
795 ReAlloc alloc, | 767 ReAlloc alloc, |
796 intptr_t initial_size) | 768 intptr_t initial_size) |
797 : InstructionsWriter(), | 769 : ImageWriter(), |
798 assembly_stream_(assembly_buffer, alloc, initial_size), | 770 assembly_stream_(assembly_buffer, alloc, initial_size), |
799 text_size_(0) {} | 771 text_size_(0) {} |
800 | 772 |
801 virtual void WriteText(WriteStream* clustered_stream, bool vm); | 773 virtual void WriteText(WriteStream* clustered_stream, bool vm); |
802 virtual intptr_t text_size() { return text_size_; } | 774 virtual intptr_t text_size() { return text_size_; } |
803 | 775 |
804 intptr_t AssemblySize() const { return assembly_stream_.bytes_written(); } | 776 intptr_t AssemblySize() const { return assembly_stream_.bytes_written(); } |
805 | 777 |
806 private: | 778 private: |
807 void WriteWordLiteralText(uword value) { | 779 void WriteWordLiteralText(uword value) { |
808 // Padding is helpful for comparing the .S with --disassemble. | 780 // Padding is helpful for comparing the .S with --disassemble. |
809 #if defined(ARCH_IS_64_BIT) | 781 #if defined(ARCH_IS_64_BIT) |
810 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); | 782 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); |
811 #else | 783 #else |
812 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); | 784 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); |
813 #endif | 785 #endif |
814 text_size_ += sizeof(value); | 786 text_size_ += sizeof(value); |
815 } | 787 } |
816 | 788 |
817 WriteStream assembly_stream_; | 789 WriteStream assembly_stream_; |
818 intptr_t text_size_; | 790 intptr_t text_size_; |
819 | 791 |
820 DISALLOW_COPY_AND_ASSIGN(AssemblyInstructionsWriter); | 792 DISALLOW_COPY_AND_ASSIGN(AssemblyImageWriter); |
821 }; | 793 }; |
822 | 794 |
823 | 795 |
824 class BlobInstructionsWriter : public InstructionsWriter { | 796 class BlobImageWriter : public ImageWriter { |
825 public: | 797 public: |
826 BlobInstructionsWriter(uint8_t** instructions_blob_buffer, | 798 BlobImageWriter(uint8_t** instructions_blob_buffer, |
827 ReAlloc alloc, | 799 ReAlloc alloc, |
828 intptr_t initial_size) | 800 intptr_t initial_size) |
829 : InstructionsWriter(), | 801 : ImageWriter(), |
830 instructions_blob_stream_(instructions_blob_buffer, | 802 instructions_blob_stream_(instructions_blob_buffer, |
831 alloc, | 803 alloc, |
832 initial_size) {} | 804 initial_size) {} |
833 | 805 |
834 virtual void WriteText(WriteStream* clustered_stream, bool vm); | 806 virtual void WriteText(WriteStream* clustered_stream, bool vm); |
835 virtual intptr_t text_size() { return InstructionsBlobSize(); } | 807 virtual intptr_t text_size() { return InstructionsBlobSize(); } |
836 | 808 |
837 intptr_t InstructionsBlobSize() const { | 809 intptr_t InstructionsBlobSize() const { |
838 return instructions_blob_stream_.bytes_written(); | 810 return instructions_blob_stream_.bytes_written(); |
839 } | 811 } |
840 | 812 |
841 private: | 813 private: |
842 WriteStream instructions_blob_stream_; | 814 WriteStream instructions_blob_stream_; |
843 | 815 |
844 DISALLOW_COPY_AND_ASSIGN(BlobInstructionsWriter); | 816 DISALLOW_COPY_AND_ASSIGN(BlobImageWriter); |
845 }; | 817 }; |
846 | 818 |
847 | 819 |
848 class SnapshotWriter : public BaseWriter { | 820 class SnapshotWriter : public BaseWriter { |
849 protected: | 821 protected: |
850 SnapshotWriter(Thread* thread, | 822 SnapshotWriter(Thread* thread, |
851 Snapshot::Kind kind, | 823 Snapshot::Kind kind, |
852 uint8_t** buffer, | 824 uint8_t** buffer, |
853 ReAlloc alloc, | 825 ReAlloc alloc, |
854 DeAlloc dealloc, | 826 DeAlloc dealloc, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 private: | 1011 private: |
1040 SnapshotWriter* writer_; | 1012 SnapshotWriter* writer_; |
1041 bool as_references_; | 1013 bool as_references_; |
1042 | 1014 |
1043 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1015 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
1044 }; | 1016 }; |
1045 | 1017 |
1046 } // namespace dart | 1018 } // namespace dart |
1047 | 1019 |
1048 #endif // RUNTIME_VM_SNAPSHOT_H_ | 1020 #endif // RUNTIME_VM_SNAPSHOT_H_ |
OLD | NEW |