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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 | 743 |
744 private: | 744 private: |
745 WriteStream stream_; | 745 WriteStream stream_; |
746 | 746 |
747 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); | 747 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); |
748 }; | 748 }; |
749 | 749 |
750 | 750 |
751 class ForwardList { | 751 class ForwardList { |
752 public: | 752 public: |
753 explicit ForwardList(intptr_t first_object_id); | 753 explicit ForwardList(Thread* thread, intptr_t first_object_id); |
754 ~ForwardList(); | 754 ~ForwardList(); |
755 | 755 |
756 class Node : public ZoneAllocated { | 756 class Node : public ZoneAllocated { |
757 public: | 757 public: |
758 Node(RawObject* raw, uword tags, SerializeState state) | 758 Node(const Object* obj, SerializeState state) : obj_(obj), state_(state) {} |
759 : raw_(raw), tags_(tags), state_(state) {} | 759 const Object* obj() const { return obj_; } |
760 RawObject* raw() const { return raw_; } | |
761 uword tags() const { return tags_; } | |
762 bool is_serialized() const { return state_ == kIsSerialized; } | 760 bool is_serialized() const { return state_ == kIsSerialized; } |
763 | 761 |
764 private: | 762 private: |
765 // Private to ensure the invariant of first_unprocessed_object_id_. | 763 // Private to ensure the invariant of first_unprocessed_object_id_. |
766 void set_state(SerializeState value) { state_ = value; } | 764 void set_state(SerializeState value) { state_ = value; } |
767 | 765 |
768 RawObject* raw_; | 766 const Object* obj_; |
769 uword tags_; | |
770 SerializeState state_; | 767 SerializeState state_; |
771 | 768 |
772 friend class ForwardList; | 769 friend class ForwardList; |
773 DISALLOW_COPY_AND_ASSIGN(Node); | 770 DISALLOW_COPY_AND_ASSIGN(Node); |
774 }; | 771 }; |
775 | 772 |
776 Node* NodeForObjectId(intptr_t object_id) const { | 773 Node* NodeForObjectId(intptr_t object_id) const { |
777 return nodes_[object_id - first_object_id_]; | 774 return nodes_[object_id - first_object_id_]; |
778 } | 775 } |
779 | 776 |
780 // Returns the id for the added object. | 777 // Returns the id for the added object. |
781 intptr_t MarkAndAddObject(RawObject* raw, SerializeState state); | 778 intptr_t AddObject(Zone* zone, RawObject* raw, SerializeState state); |
782 | |
783 // Returns the id for the added object without marking it. | |
784 intptr_t AddObject(RawObject* raw, SerializeState state); | |
785 | 779 |
786 // Returns the id for the object it it exists in the list. | 780 // Returns the id for the object it it exists in the list. |
787 intptr_t FindObject(RawObject* raw); | 781 intptr_t FindObject(RawObject* raw); |
788 | 782 |
789 // Exhaustively processes all unserialized objects in this list. 'writer' may | 783 // Exhaustively processes all unserialized objects in this list. 'writer' may |
790 // concurrently add more objects. | 784 // concurrently add more objects. |
791 void SerializeAll(ObjectVisitor* writer); | 785 void SerializeAll(ObjectVisitor* writer); |
792 | 786 |
793 // Restores the tags of all objects in this list. | |
794 void UnmarkAll() const; | |
795 | |
796 // Set state of object in forward list. | 787 // Set state of object in forward list. |
797 void SetState(RawObject* raw, SerializeState state); | 788 void SetState(intptr_t object_id, SerializeState state) { |
| 789 NodeForObjectId(object_id)->set_state(state); |
| 790 } |
798 | 791 |
799 private: | 792 private: |
800 intptr_t first_object_id() const { return first_object_id_; } | 793 intptr_t first_object_id() const { return first_object_id_; } |
801 intptr_t next_object_id() const { return nodes_.length() + first_object_id_; } | 794 intptr_t next_object_id() const { return nodes_.length() + first_object_id_; } |
| 795 Heap* heap() const { return thread_->isolate()->heap(); } |
802 | 796 |
| 797 Thread* thread_; |
803 const intptr_t first_object_id_; | 798 const intptr_t first_object_id_; |
804 GrowableArray<Node*> nodes_; | 799 GrowableArray<Node*> nodes_; |
805 intptr_t first_unprocessed_object_id_; | 800 intptr_t first_unprocessed_object_id_; |
806 | 801 |
807 friend class FullSnapshotWriter; | 802 friend class FullSnapshotWriter; |
808 DISALLOW_COPY_AND_ASSIGN(ForwardList); | 803 DISALLOW_COPY_AND_ASSIGN(ForwardList); |
809 }; | 804 }; |
810 | 805 |
811 | 806 |
812 class InstructionsWriter : public ZoneAllocated { | 807 class InstructionsWriter : public ZoneAllocated { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 intptr_t next_offset_; | 861 intptr_t next_offset_; |
867 GrowableArray<InstructionsData> instructions_; | 862 GrowableArray<InstructionsData> instructions_; |
868 | 863 |
869 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); | 864 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); |
870 }; | 865 }; |
871 | 866 |
872 | 867 |
873 class SnapshotWriter : public BaseWriter { | 868 class SnapshotWriter : public BaseWriter { |
874 protected: | 869 protected: |
875 SnapshotWriter(Snapshot::Kind kind, | 870 SnapshotWriter(Snapshot::Kind kind, |
| 871 Thread* thread, |
876 uint8_t** buffer, | 872 uint8_t** buffer, |
877 ReAlloc alloc, | 873 ReAlloc alloc, |
878 intptr_t initial_size, | 874 intptr_t initial_size, |
879 ForwardList* forward_list, | 875 ForwardList* forward_list, |
880 InstructionsWriter* instructions_writer, | 876 InstructionsWriter* instructions_writer, |
881 bool can_send_any_object, | 877 bool can_send_any_object, |
882 bool snapshot_code, | 878 bool snapshot_code, |
883 bool vm_isolate_is_symbolic); | 879 bool vm_isolate_is_symbolic); |
884 | 880 |
885 public: | 881 public: |
886 // Snapshot kind. | 882 // Snapshot kind. |
887 Snapshot::Kind kind() const { return kind_; } | 883 Snapshot::Kind kind() const { return kind_; } |
| 884 Thread* thread() const { return thread_; } |
| 885 Zone* zone() const { return thread_->zone(); } |
| 886 Isolate* isolate() const { return thread_->isolate(); } |
| 887 Heap* heap() const { return isolate()->heap(); } |
888 | 888 |
889 // Serialize an object into the buffer. | 889 // Serialize an object into the buffer. |
890 void WriteObject(RawObject* raw); | 890 void WriteObject(RawObject* raw); |
891 | 891 |
892 uword GetObjectTags(RawObject* raw); | 892 uword GetObjectTags(RawObject* raw); |
893 | 893 |
894 intptr_t GetObjectId(RawObject* raw); | |
895 | |
896 Exceptions::ExceptionType exception_type() const { | 894 Exceptions::ExceptionType exception_type() const { |
897 return exception_type_; | 895 return exception_type_; |
898 } | 896 } |
899 void set_exception_type(Exceptions::ExceptionType type) { | 897 void set_exception_type(Exceptions::ExceptionType type) { |
900 exception_type_ = type; | 898 exception_type_ = type; |
901 } | 899 } |
902 const char* exception_msg() const { return exception_msg_; } | 900 const char* exception_msg() const { return exception_msg_; } |
903 void set_exception_msg(const char* msg) { | 901 void set_exception_msg(const char* msg) { |
904 exception_msg_ = msg; | 902 exception_msg_ = msg; |
905 } | 903 } |
(...skipping 11 matching lines...) Expand all Loading... |
917 return instructions_writer_->GetOffsetFor(instructions); | 915 return instructions_writer_->GetOffsetFor(instructions); |
918 } | 916 } |
919 | 917 |
920 void SetInstructionsCode(RawInstructions* instructions, RawCode* code) { | 918 void SetInstructionsCode(RawInstructions* instructions, RawCode* code) { |
921 return instructions_writer_->SetInstructionsCode(instructions, code); | 919 return instructions_writer_->SetInstructionsCode(instructions, code); |
922 } | 920 } |
923 | 921 |
924 void WriteFunctionId(RawFunction* func, bool owner_is_class); | 922 void WriteFunctionId(RawFunction* func, bool owner_is_class); |
925 | 923 |
926 protected: | 924 protected: |
927 void UnmarkAll() { | |
928 if (!unmarked_objects_ && forward_list_ != NULL) { | |
929 forward_list_->UnmarkAll(); | |
930 unmarked_objects_ = true; | |
931 } | |
932 } | |
933 | |
934 bool CheckAndWritePredefinedObject(RawObject* raw); | 925 bool CheckAndWritePredefinedObject(RawObject* raw); |
935 bool HandleVMIsolateObject(RawObject* raw); | 926 bool HandleVMIsolateObject(RawObject* raw); |
936 | 927 |
937 void WriteClassId(RawClass* cls); | 928 void WriteClassId(RawClass* cls); |
938 void WriteStaticImplicitClosure(intptr_t object_id, | 929 void WriteStaticImplicitClosure(intptr_t object_id, |
939 RawFunction* func, | 930 RawFunction* func, |
940 intptr_t tags); | 931 intptr_t tags); |
941 void WriteObjectImpl(RawObject* raw, bool as_reference); | 932 void WriteObjectImpl(RawObject* raw, bool as_reference); |
942 void WriteMarkedObjectImpl(RawObject* raw, | 933 void WriteMarkedObjectImpl(RawObject* raw, |
943 intptr_t tags, | 934 intptr_t tags, |
(...skipping 21 matching lines...) Expand all Loading... |
965 | 956 |
966 void InitializeForwardList(ForwardList* forward_list) { | 957 void InitializeForwardList(ForwardList* forward_list) { |
967 ASSERT(forward_list_ == NULL); | 958 ASSERT(forward_list_ == NULL); |
968 forward_list_ = forward_list; | 959 forward_list_ = forward_list; |
969 } | 960 } |
970 void ResetForwardList() { | 961 void ResetForwardList() { |
971 ASSERT(forward_list_ != NULL); | 962 ASSERT(forward_list_ != NULL); |
972 forward_list_ = NULL; | 963 forward_list_ = NULL; |
973 } | 964 } |
974 | 965 |
975 Thread* thread() const { return thread_; } | |
976 Isolate* isolate() const { return thread_->isolate(); } | |
977 ObjectStore* object_store() const { return object_store_; } | 966 ObjectStore* object_store() const { return object_store_; } |
978 | 967 |
979 private: | 968 private: |
980 Snapshot::Kind kind_; | 969 Snapshot::Kind kind_; |
981 Thread* thread_; | 970 Thread* thread_; |
982 ObjectStore* object_store_; // Object store for common classes. | 971 ObjectStore* object_store_; // Object store for common classes. |
983 ClassTable* class_table_; // Class table for the class index to class lookup. | 972 ClassTable* class_table_; // Class table for the class index to class lookup. |
984 ForwardList* forward_list_; | 973 ForwardList* forward_list_; |
985 InstructionsWriter* instructions_writer_; | 974 InstructionsWriter* instructions_writer_; |
986 Exceptions::ExceptionType exception_type_; // Exception type. | 975 Exceptions::ExceptionType exception_type_; // Exception type. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 ~FullSnapshotWriter(); | 1022 ~FullSnapshotWriter(); |
1034 | 1023 |
1035 uint8_t** vm_isolate_snapshot_buffer() { | 1024 uint8_t** vm_isolate_snapshot_buffer() { |
1036 return vm_isolate_snapshot_buffer_; | 1025 return vm_isolate_snapshot_buffer_; |
1037 } | 1026 } |
1038 | 1027 |
1039 uint8_t** isolate_snapshot_buffer() { | 1028 uint8_t** isolate_snapshot_buffer() { |
1040 return isolate_snapshot_buffer_; | 1029 return isolate_snapshot_buffer_; |
1041 } | 1030 } |
1042 | 1031 |
| 1032 Thread* thread() const { return thread_; } |
| 1033 Zone* zone() const { return thread_->zone(); } |
| 1034 Isolate* isolate() const { return thread_->isolate(); } |
| 1035 Heap* heap() const { return isolate()->heap(); } |
| 1036 |
1043 // Writes a full snapshot of the Isolate. | 1037 // Writes a full snapshot of the Isolate. |
1044 void WriteFullSnapshot(); | 1038 void WriteFullSnapshot(); |
1045 | 1039 |
1046 intptr_t VmIsolateSnapshotSize() const { | 1040 intptr_t VmIsolateSnapshotSize() const { |
1047 return vm_isolate_snapshot_size_; | 1041 return vm_isolate_snapshot_size_; |
1048 } | 1042 } |
1049 intptr_t IsolateSnapshotSize() const { | 1043 intptr_t IsolateSnapshotSize() const { |
1050 return isolate_snapshot_size_; | 1044 return isolate_snapshot_size_; |
1051 } | 1045 } |
1052 intptr_t InstructionsSnapshotSize() const { | 1046 intptr_t InstructionsSnapshotSize() const { |
1053 return instructions_snapshot_size_; | 1047 return instructions_snapshot_size_; |
1054 } | 1048 } |
1055 | 1049 |
1056 private: | 1050 private: |
1057 // Writes a snapshot of the VM Isolate. | 1051 // Writes a snapshot of the VM Isolate. |
1058 void WriteVmIsolateSnapshot(); | 1052 void WriteVmIsolateSnapshot(); |
1059 | 1053 |
1060 // Writes a full snapshot of a regular Dart Isolate. | 1054 // Writes a full snapshot of a regular Dart Isolate. |
1061 void WriteIsolateFullSnapshot(); | 1055 void WriteIsolateFullSnapshot(); |
1062 | 1056 |
1063 Isolate* isolate_; | 1057 Thread* thread_; |
1064 uint8_t** vm_isolate_snapshot_buffer_; | 1058 uint8_t** vm_isolate_snapshot_buffer_; |
1065 uint8_t** isolate_snapshot_buffer_; | 1059 uint8_t** isolate_snapshot_buffer_; |
1066 uint8_t** instructions_snapshot_buffer_; | 1060 uint8_t** instructions_snapshot_buffer_; |
1067 ReAlloc alloc_; | 1061 ReAlloc alloc_; |
1068 intptr_t vm_isolate_snapshot_size_; | 1062 intptr_t vm_isolate_snapshot_size_; |
1069 intptr_t isolate_snapshot_size_; | 1063 intptr_t isolate_snapshot_size_; |
1070 intptr_t instructions_snapshot_size_; | 1064 intptr_t instructions_snapshot_size_; |
1071 ForwardList* forward_list_; | 1065 ForwardList* forward_list_; |
1072 InstructionsWriter* instructions_writer_; | 1066 InstructionsWriter* instructions_writer_; |
1073 Array& scripts_; | 1067 Array& scripts_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 private: | 1128 private: |
1135 SnapshotWriter* writer_; | 1129 SnapshotWriter* writer_; |
1136 bool as_references_; | 1130 bool as_references_; |
1137 | 1131 |
1138 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1132 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
1139 }; | 1133 }; |
1140 | 1134 |
1141 } // namespace dart | 1135 } // namespace dart |
1142 | 1136 |
1143 #endif // VM_SNAPSHOT_H_ | 1137 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |