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" |
11 #include "vm/datastream.h" | 11 #include "vm/datastream.h" |
12 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
13 #include "vm/globals.h" | 13 #include "vm/globals.h" |
14 #include "vm/growable_array.h" | 14 #include "vm/growable_array.h" |
15 #include "vm/isolate.h" | 15 #include "vm/isolate.h" |
16 #include "vm/visitor.h" | 16 #include "vm/visitor.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 | 19 |
20 // Forward declarations. | 20 // Forward declarations. |
21 class AbstractType; | 21 class AbstractType; |
22 class Array; | 22 class Array; |
23 class Class; | 23 class Class; |
24 class ClassTable; | 24 class ClassTable; |
25 class Code; | |
25 class ExternalTypedData; | 26 class ExternalTypedData; |
26 class GrowableObjectArray; | 27 class GrowableObjectArray; |
27 class Heap; | 28 class Heap; |
29 class Instructions; | |
28 class LanguageError; | 30 class LanguageError; |
29 class Library; | 31 class Library; |
30 class Object; | 32 class Object; |
31 class PassiveObject; | 33 class PassiveObject; |
32 class ObjectStore; | 34 class ObjectStore; |
33 class PageSpace; | 35 class PageSpace; |
34 class RawApiError; | 36 class RawApiError; |
35 class RawArray; | 37 class RawArray; |
36 class RawBigint; | 38 class RawBigint; |
37 class RawBoundedType; | 39 class RawBoundedType; |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 friend class FullSnapshotWriter; | 772 friend class FullSnapshotWriter; |
771 DISALLOW_COPY_AND_ASSIGN(ForwardList); | 773 DISALLOW_COPY_AND_ASSIGN(ForwardList); |
772 }; | 774 }; |
773 | 775 |
774 | 776 |
775 class InstructionsWriter : public ZoneAllocated { | 777 class InstructionsWriter : public ZoneAllocated { |
776 public: | 778 public: |
777 InstructionsWriter(uint8_t** buffer, | 779 InstructionsWriter(uint8_t** buffer, |
778 ReAlloc alloc, | 780 ReAlloc alloc, |
779 intptr_t initial_size) | 781 intptr_t initial_size) |
780 : stream_(buffer, alloc, initial_size) { | 782 : stream_(buffer, alloc, initial_size), |
783 next_offset_(0), | |
784 instructions_() { | |
781 ASSERT(buffer != NULL); | 785 ASSERT(buffer != NULL); |
782 ASSERT(alloc != NULL); | 786 ASSERT(alloc != NULL); |
783 } | 787 } |
784 | 788 |
785 // Size of the snapshot. | 789 // Size of the snapshot. |
786 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 790 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
787 | 791 |
788 int32_t GetOffsetFor(RawInstructions* instructions); | 792 int32_t GetOffsetFor(RawInstructions* instructions); |
789 | 793 |
794 void SetInstructionsCode(RawInstructions* insns, RawCode* code) { | |
rmacnak
2015/09/03 20:17:53
Must not use the back pointer in Instructions beca
| |
795 for (intptr_t i = 0; i < instructions_.length(); i++) { | |
796 if (instructions_[i].raw_insns_ == insns) { | |
797 instructions_[i].raw_code_ = code; | |
798 return; | |
799 } | |
800 } | |
801 UNREACHABLE(); | |
802 } | |
803 | |
804 void WriteAssembly(); | |
805 | |
790 private: | 806 private: |
807 struct InstructionsData { | |
808 explicit InstructionsData(RawInstructions* insns) | |
809 : raw_insns_(insns), raw_code_(NULL) { } | |
810 | |
811 union { | |
812 RawInstructions* raw_insns_; | |
813 const Instructions* insns_; | |
814 }; | |
815 union { | |
816 RawCode* raw_code_; | |
817 const Code* code_; | |
818 }; | |
819 }; | |
820 | |
821 | |
791 WriteStream stream_; | 822 WriteStream stream_; |
823 intptr_t next_offset_; | |
824 GrowableArray<InstructionsData> instructions_; | |
792 | 825 |
793 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); | 826 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); |
794 }; | 827 }; |
795 | 828 |
796 | 829 |
797 class SnapshotWriter : public BaseWriter { | 830 class SnapshotWriter : public BaseWriter { |
798 protected: | 831 protected: |
799 SnapshotWriter(Snapshot::Kind kind, | 832 SnapshotWriter(Snapshot::Kind kind, |
800 uint8_t** buffer, | 833 uint8_t** buffer, |
801 ReAlloc alloc, | 834 ReAlloc alloc, |
(...skipping 30 matching lines...) Expand all Loading... | |
832 | 865 |
833 // Write a version string for the snapshot. | 866 // Write a version string for the snapshot. |
834 void WriteVersion(); | 867 void WriteVersion(); |
835 | 868 |
836 static intptr_t FirstObjectId(); | 869 static intptr_t FirstObjectId(); |
837 | 870 |
838 int32_t GetInstructionsId(RawInstructions* instructions) { | 871 int32_t GetInstructionsId(RawInstructions* instructions) { |
839 return instructions_writer_->GetOffsetFor(instructions); | 872 return instructions_writer_->GetOffsetFor(instructions); |
840 } | 873 } |
841 | 874 |
875 void SetInstructionsCode(RawInstructions* instructions, RawCode* code) { | |
876 return instructions_writer_->SetInstructionsCode(instructions, code); | |
877 } | |
878 | |
842 protected: | 879 protected: |
843 void UnmarkAll() { | 880 void UnmarkAll() { |
844 if (!unmarked_objects_ && forward_list_ != NULL) { | 881 if (!unmarked_objects_ && forward_list_ != NULL) { |
845 forward_list_->UnmarkAll(); | 882 forward_list_->UnmarkAll(); |
846 unmarked_objects_ = true; | 883 unmarked_objects_ = true; |
847 } | 884 } |
848 } | 885 } |
849 | 886 |
850 bool CheckAndWritePredefinedObject(RawObject* raw); | 887 bool CheckAndWritePredefinedObject(RawObject* raw); |
851 bool HandleVMIsolateObject(RawObject* raw); | 888 bool HandleVMIsolateObject(RawObject* raw); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1050 private: | 1087 private: |
1051 SnapshotWriter* writer_; | 1088 SnapshotWriter* writer_; |
1052 bool as_references_; | 1089 bool as_references_; |
1053 | 1090 |
1054 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1091 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
1055 }; | 1092 }; |
1056 | 1093 |
1057 } // namespace dart | 1094 } // namespace dart |
1058 | 1095 |
1059 #endif // VM_SNAPSHOT_H_ | 1096 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |