| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_)); | 183 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_)); |
| 184 } | 184 } |
| 185 | 185 |
| 186 static bool IsFull(Kind kind) { | 186 static bool IsFull(Kind kind) { |
| 187 return (kind == kCore) || (kind == kAppJIT) || (kind == kAppAOT); | 187 return (kind == kCore) || (kind == kAppJIT) || (kind == kAppAOT); |
| 188 } | 188 } |
| 189 static bool IncludesCode(Kind kind) { | 189 static bool IncludesCode(Kind kind) { |
| 190 return (kind == kAppJIT) || (kind == kAppAOT); | 190 return (kind == kAppJIT) || (kind == kAppAOT); |
| 191 } | 191 } |
| 192 | 192 |
| 193 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } | 193 const uint8_t* Addr() const { return reinterpret_cast<const uint8_t*>(this); } |
| 194 | 194 |
| 195 static intptr_t length_offset() { | 195 static intptr_t length_offset() { |
| 196 return OFFSET_OF(Snapshot, unaligned_length_); | 196 return OFFSET_OF(Snapshot, unaligned_length_); |
| 197 } | 197 } |
| 198 static intptr_t kind_offset() { return OFFSET_OF(Snapshot, unaligned_kind_); } | 198 static intptr_t kind_offset() { return OFFSET_OF(Snapshot, unaligned_kind_); } |
| 199 | 199 |
| 200 private: | 200 private: |
| 201 // Prevent Snapshot from ever being allocated directly. | 201 // Prevent Snapshot from ever being allocated directly. |
| 202 Snapshot(); | 202 Snapshot(); |
| 203 | 203 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 public: | 368 public: |
| 369 InstructionsReader(const uint8_t* instructions_buffer, | 369 InstructionsReader(const uint8_t* instructions_buffer, |
| 370 const uint8_t* data_buffer) | 370 const uint8_t* data_buffer) |
| 371 : instructions_buffer_(instructions_buffer), data_buffer_(data_buffer) { | 371 : instructions_buffer_(instructions_buffer), data_buffer_(data_buffer) { |
| 372 ASSERT(instructions_buffer != NULL); | 372 ASSERT(instructions_buffer != NULL); |
| 373 ASSERT(data_buffer != NULL); | 373 ASSERT(data_buffer != NULL); |
| 374 ASSERT(Utils::IsAligned(reinterpret_cast<uword>(instructions_buffer), | 374 ASSERT(Utils::IsAligned(reinterpret_cast<uword>(instructions_buffer), |
| 375 OS::PreferredCodeAlignment())); | 375 OS::PreferredCodeAlignment())); |
| 376 } | 376 } |
| 377 | 377 |
| 378 uword GetInstructionsAt(int32_t offset); | 378 RawInstructions* GetInstructionsAt(int32_t offset); |
| 379 RawObject* GetObjectAt(int32_t offset); | 379 RawObject* GetObjectAt(int32_t offset); |
| 380 | 380 |
| 381 private: | 381 private: |
| 382 const uint8_t* instructions_buffer_; | 382 const uint8_t* instructions_buffer_; |
| 383 const uint8_t* data_buffer_; | 383 const uint8_t* data_buffer_; |
| 384 | 384 |
| 385 DISALLOW_COPY_AND_ASSIGN(InstructionsReader); | 385 DISALLOW_COPY_AND_ASSIGN(InstructionsReader); |
| 386 }; | 386 }; |
| 387 | 387 |
| 388 | 388 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 GrowableArray<Node*> nodes_; | 721 GrowableArray<Node*> nodes_; |
| 722 intptr_t first_unprocessed_object_id_; | 722 intptr_t first_unprocessed_object_id_; |
| 723 | 723 |
| 724 DISALLOW_COPY_AND_ASSIGN(ForwardList); | 724 DISALLOW_COPY_AND_ASSIGN(ForwardList); |
| 725 }; | 725 }; |
| 726 | 726 |
| 727 | 727 |
| 728 class InstructionsWriter : public ZoneAllocated { | 728 class InstructionsWriter : public ZoneAllocated { |
| 729 public: | 729 public: |
| 730 InstructionsWriter() | 730 InstructionsWriter() |
| 731 : next_offset_(InstructionsSnapshot::kHeaderSize), | 731 : next_offset_(0), next_object_offset_(0), instructions_(), objects_() { |
| 732 next_object_offset_(DataSnapshot::kHeaderSize), | 732 ResetOffsets(); |
| 733 instructions_(), | 733 } |
| 734 objects_() {} | |
| 735 virtual ~InstructionsWriter() {} | 734 virtual ~InstructionsWriter() {} |
| 736 | 735 |
| 736 void ResetOffsets() { |
| 737 next_offset_ = InstructionsSnapshot::kHeaderSize; |
| 738 next_object_offset_ = DataSnapshot::kHeaderSize; |
| 739 instructions_.Clear(); |
| 740 objects_.Clear(); |
| 741 } |
| 737 int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code); | 742 int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code); |
| 738 | |
| 739 int32_t GetObjectOffsetFor(RawObject* raw_object); | 743 int32_t GetObjectOffsetFor(RawObject* raw_object); |
| 740 | 744 |
| 741 virtual void Write(uint8_t* vmisolate_buffer, | 745 void Write(WriteStream* clustered_stream, bool vm); |
| 742 intptr_t vmisolate_length, | |
| 743 uint8_t* isolate_buffer, | |
| 744 intptr_t isolate_length) = 0; | |
| 745 virtual intptr_t text_size() = 0; | 746 virtual intptr_t text_size() = 0; |
| 746 virtual intptr_t data_size() = 0; | 747 intptr_t data_size() { return next_object_offset_; } |
| 747 | 748 |
| 748 protected: | 749 protected: |
| 750 void WriteROData(WriteStream* stream); |
| 751 virtual void WriteText(WriteStream* clustered_stream, bool vm) = 0; |
| 752 |
| 749 struct InstructionsData { | 753 struct InstructionsData { |
| 750 explicit InstructionsData(RawInstructions* insns, | 754 explicit InstructionsData(RawInstructions* insns, |
| 751 RawCode* code, | 755 RawCode* code, |
| 752 intptr_t offset) | 756 intptr_t offset) |
| 753 : raw_insns_(insns), raw_code_(code), offset_(offset) {} | 757 : raw_insns_(insns), raw_code_(code), offset_(offset) {} |
| 754 | 758 |
| 755 union { | 759 union { |
| 756 RawInstructions* raw_insns_; | 760 RawInstructions* raw_insns_; |
| 757 const Instructions* insns_; | 761 const Instructions* insns_; |
| 758 }; | 762 }; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 782 }; | 786 }; |
| 783 | 787 |
| 784 | 788 |
| 785 class AssemblyInstructionsWriter : public InstructionsWriter { | 789 class AssemblyInstructionsWriter : public InstructionsWriter { |
| 786 public: | 790 public: |
| 787 AssemblyInstructionsWriter(uint8_t** assembly_buffer, | 791 AssemblyInstructionsWriter(uint8_t** assembly_buffer, |
| 788 ReAlloc alloc, | 792 ReAlloc alloc, |
| 789 intptr_t initial_size) | 793 intptr_t initial_size) |
| 790 : InstructionsWriter(), | 794 : InstructionsWriter(), |
| 791 assembly_stream_(assembly_buffer, alloc, initial_size), | 795 assembly_stream_(assembly_buffer, alloc, initial_size), |
| 792 text_size_(0), | 796 text_size_(0) {} |
| 793 data_size_(0) {} | |
| 794 | 797 |
| 795 virtual void Write(uint8_t* vmisolate_buffer, | 798 virtual void WriteText(WriteStream* clustered_stream, bool vm); |
| 796 intptr_t vmisolate_length, | |
| 797 uint8_t* isolate_buffer, | |
| 798 intptr_t isolate_length); | |
| 799 virtual intptr_t text_size() { return text_size_; } | 799 virtual intptr_t text_size() { return text_size_; } |
| 800 virtual intptr_t data_size() { return data_size_; } | |
| 801 | 800 |
| 802 intptr_t AssemblySize() const { return assembly_stream_.bytes_written(); } | 801 intptr_t AssemblySize() const { return assembly_stream_.bytes_written(); } |
| 803 | 802 |
| 804 private: | 803 private: |
| 805 void WriteWordLiteralText(uword value) { | 804 void WriteWordLiteralText(uword value) { |
| 806 // Padding is helpful for comparing the .S with --disassemble. | 805 // Padding is helpful for comparing the .S with --disassemble. |
| 807 #if defined(ARCH_IS_64_BIT) | 806 #if defined(ARCH_IS_64_BIT) |
| 808 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); | 807 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); |
| 809 #else | 808 #else |
| 810 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); | 809 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); |
| 811 #endif | 810 #endif |
| 812 text_size_ += sizeof(value); | 811 text_size_ += sizeof(value); |
| 813 } | 812 } |
| 814 | 813 |
| 815 void WriteWordLiteralData(uword value) { | |
| 816 // Padding is helpful for comparing the .S with --disassemble. | |
| 817 #if defined(ARCH_IS_64_BIT) | |
| 818 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); | |
| 819 #else | |
| 820 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); | |
| 821 #endif | |
| 822 data_size_ += sizeof(value); | |
| 823 } | |
| 824 | |
| 825 WriteStream assembly_stream_; | 814 WriteStream assembly_stream_; |
| 826 intptr_t text_size_; | 815 intptr_t text_size_; |
| 827 intptr_t data_size_; | |
| 828 | 816 |
| 829 DISALLOW_COPY_AND_ASSIGN(AssemblyInstructionsWriter); | 817 DISALLOW_COPY_AND_ASSIGN(AssemblyInstructionsWriter); |
| 830 }; | 818 }; |
| 831 | 819 |
| 832 | 820 |
| 833 class BlobInstructionsWriter : public InstructionsWriter { | 821 class BlobInstructionsWriter : public InstructionsWriter { |
| 834 public: | 822 public: |
| 835 BlobInstructionsWriter(uint8_t** instructions_blob_buffer, | 823 BlobInstructionsWriter(uint8_t** instructions_blob_buffer, |
| 836 uint8_t** rodata_blob_buffer, | |
| 837 ReAlloc alloc, | 824 ReAlloc alloc, |
| 838 intptr_t initial_size) | 825 intptr_t initial_size) |
| 839 : InstructionsWriter(), | 826 : InstructionsWriter(), |
| 840 instructions_blob_stream_(instructions_blob_buffer, | 827 instructions_blob_stream_(instructions_blob_buffer, |
| 841 alloc, | 828 alloc, |
| 842 initial_size), | 829 initial_size) {} |
| 843 rodata_blob_stream_(rodata_blob_buffer, alloc, initial_size) {} | |
| 844 | 830 |
| 845 virtual void Write(uint8_t* vmisolate_buffer, | 831 virtual void WriteText(WriteStream* clustered_stream, bool vm); |
| 846 intptr_t vmisolate_length, | |
| 847 uint8_t* isolate_buffer, | |
| 848 intptr_t isolate_length); | |
| 849 virtual intptr_t text_size() { return InstructionsBlobSize(); } | 832 virtual intptr_t text_size() { return InstructionsBlobSize(); } |
| 850 virtual intptr_t data_size() { return RodataBlobSize(); } | |
| 851 | 833 |
| 852 intptr_t InstructionsBlobSize() const { | 834 intptr_t InstructionsBlobSize() const { |
| 853 return instructions_blob_stream_.bytes_written(); | 835 return instructions_blob_stream_.bytes_written(); |
| 854 } | 836 } |
| 855 intptr_t RodataBlobSize() const { | |
| 856 return rodata_blob_stream_.bytes_written(); | |
| 857 } | |
| 858 | 837 |
| 859 private: | 838 private: |
| 860 WriteStream instructions_blob_stream_; | 839 WriteStream instructions_blob_stream_; |
| 861 WriteStream rodata_blob_stream_; | |
| 862 | 840 |
| 863 DISALLOW_COPY_AND_ASSIGN(BlobInstructionsWriter); | 841 DISALLOW_COPY_AND_ASSIGN(BlobInstructionsWriter); |
| 864 }; | 842 }; |
| 865 | 843 |
| 866 | 844 |
| 867 class SnapshotWriter : public BaseWriter { | 845 class SnapshotWriter : public BaseWriter { |
| 868 protected: | 846 protected: |
| 869 SnapshotWriter(Thread* thread, | 847 SnapshotWriter(Thread* thread, |
| 870 Snapshot::Kind kind, | 848 Snapshot::Kind kind, |
| 871 uint8_t** buffer, | 849 uint8_t** buffer, |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 private: | 1008 private: |
| 1031 SnapshotWriter* writer_; | 1009 SnapshotWriter* writer_; |
| 1032 bool as_references_; | 1010 bool as_references_; |
| 1033 | 1011 |
| 1034 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1012 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 1035 }; | 1013 }; |
| 1036 | 1014 |
| 1037 } // namespace dart | 1015 } // namespace dart |
| 1038 | 1016 |
| 1039 #endif // RUNTIME_VM_SNAPSHOT_H_ | 1017 #endif // RUNTIME_VM_SNAPSHOT_H_ |
| OLD | NEW |