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 #include "vm/snapshot.h" | 5 #include "vm/snapshot.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 ASSERT((value & kSmiTagMask) == 0); | 129 ASSERT((value & kSmiTagMask) == 0); |
130 return reinterpret_cast<RawSmi*>(value); | 130 return reinterpret_cast<RawSmi*>(value); |
131 } | 131 } |
132 | 132 |
133 | 133 |
134 intptr_t BaseReader::ReadSmiValue() { | 134 intptr_t BaseReader::ReadSmiValue() { |
135 return Smi::Value(ReadAsSmi()); | 135 return Smi::Value(ReadAsSmi()); |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 SnapshotReader::SnapshotReader(const Snapshot* snapshot, Isolate* isolate) | 139 SnapshotReader::SnapshotReader(const uint8_t* buffer, |
140 : BaseReader(snapshot->content(), snapshot->length()), | 140 intptr_t size, |
141 kind_(snapshot->kind()), | 141 Snapshot::Kind kind, |
| 142 Isolate* isolate) |
| 143 : BaseReader(buffer, size), |
| 144 kind_(kind), |
142 isolate_(isolate), | 145 isolate_(isolate), |
143 cls_(Class::Handle()), | 146 cls_(Class::Handle()), |
144 obj_(Object::Handle()), | 147 obj_(Object::Handle()), |
145 str_(String::Handle()), | 148 str_(String::Handle()), |
146 library_(Library::Handle()), | 149 library_(Library::Handle()), |
147 type_(AbstractType::Handle()), | 150 type_(AbstractType::Handle()), |
148 type_arguments_(AbstractTypeArguments::Handle()), | 151 type_arguments_(AbstractTypeArguments::Handle()), |
149 tokens_(Array::Handle()), | 152 tokens_(Array::Handle()), |
150 backward_references_((snapshot->kind() == Snapshot::kFull) ? | 153 backward_references_((kind == Snapshot::kFull) ? |
151 kNumInitialReferencesInFullSnapshot : | 154 kNumInitialReferencesInFullSnapshot : |
152 kNumInitialReferences) { | 155 kNumInitialReferences) { |
153 } | 156 } |
154 | 157 |
155 | 158 |
156 RawObject* SnapshotReader::ReadObject() { | 159 RawObject* SnapshotReader::ReadObject() { |
157 Object& obj = Object::Handle(ReadObjectImpl()); | 160 Object& obj = Object::Handle(ReadObjectImpl()); |
158 for (intptr_t i = 0; i < backward_references_.length(); i++) { | 161 for (intptr_t i = 0; i < backward_references_.length(); i++) { |
159 if (!backward_references_[i]->is_deserialized()) { | 162 if (!backward_references_[i]->is_deserialized()) { |
160 ReadObjectImpl(); | 163 ReadObjectImpl(); |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 } \ | 833 } \ |
831 | 834 |
832 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) | 835 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) |
833 #undef SNAPSHOT_WRITE | 836 #undef SNAPSHOT_WRITE |
834 default: break; | 837 default: break; |
835 } | 838 } |
836 UNREACHABLE(); | 839 UNREACHABLE(); |
837 } | 840 } |
838 | 841 |
839 | 842 |
840 void SnapshotWriter::WriteFullSnapshot() { | 843 void FullSnapshotWriter::WriteFullSnapshot() { |
841 ASSERT(kind_ == Snapshot::kFull); | |
842 Isolate* isolate = Isolate::Current(); | 844 Isolate* isolate = Isolate::Current(); |
843 ASSERT(isolate != NULL); | 845 ASSERT(isolate != NULL); |
844 ObjectStore* object_store = isolate->object_store(); | 846 ObjectStore* object_store = isolate->object_store(); |
845 ASSERT(object_store != NULL); | 847 ASSERT(object_store != NULL); |
846 | 848 |
| 849 // Reserve space in the output buffer for a snapshot header. |
| 850 ReserveHeader(); |
| 851 |
847 // Write out all the objects in the object store of the isolate which | 852 // Write out all the objects in the object store of the isolate which |
848 // is the root set for all dart allocated objects at this point. | 853 // is the root set for all dart allocated objects at this point. |
849 SnapshotWriterVisitor visitor(this, false); | 854 SnapshotWriterVisitor visitor(this, false); |
850 object_store->VisitObjectPointers(&visitor); | 855 object_store->VisitObjectPointers(&visitor); |
851 | 856 |
852 // Write out all forwarded objects. | 857 // Write out all forwarded objects. |
853 WriteForwardedObjects(); | 858 WriteForwardedObjects(); |
854 | 859 |
855 // Finalize the snapshot buffer. | 860 FillHeader(kind()); |
856 FinalizeBuffer(); | 861 UnmarkAll(); |
857 } | 862 } |
858 | 863 |
859 | 864 |
860 uword SnapshotWriter::GetObjectTags(RawObject* raw) { | 865 uword SnapshotWriter::GetObjectTags(RawObject* raw) { |
861 uword tags = raw->ptr()->tags_; | 866 uword tags = raw->ptr()->tags_; |
862 if (SerializedHeaderTag::decode(tags) == kObjectId) { | 867 if (SerializedHeaderTag::decode(tags) == kObjectId) { |
863 intptr_t id = SerializedHeaderData::decode(tags); | 868 intptr_t id = SerializedHeaderData::decode(tags); |
864 return forward_list_[id - kMaxPredefinedObjectIds]->tags(); | 869 return forward_list_[id - kMaxPredefinedObjectIds]->tags(); |
865 } else { | 870 } else { |
866 return tags; | 871 return tags; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 for (intptr_t i = 0; i < len; i++) { | 1106 for (intptr_t i = 0; i < len; i++) { |
1102 WriteObjectRef(data[i]); | 1107 WriteObjectRef(data[i]); |
1103 } | 1108 } |
1104 } | 1109 } |
1105 | 1110 |
1106 | 1111 |
1107 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { | 1112 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { |
1108 ASSERT(kind() == Snapshot::kScript); | 1113 ASSERT(kind() == Snapshot::kScript); |
1109 | 1114 |
1110 // Write out the library object. | 1115 // Write out the library object. |
| 1116 ReserveHeader(); |
1111 WriteObject(lib.raw()); | 1117 WriteObject(lib.raw()); |
1112 | 1118 FillHeader(kind()); |
1113 // Finalize the snapshot buffer. | 1119 UnmarkAll(); |
1114 FinalizeBuffer(); | |
1115 } | 1120 } |
1116 | 1121 |
1117 | 1122 |
1118 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { | 1123 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { |
1119 for (RawObject** current = first; current <= last; current++) { | 1124 for (RawObject** current = first; current <= last; current++) { |
1120 RawObject* raw_obj = *current; | 1125 RawObject* raw_obj = *current; |
1121 if (as_references_) { | 1126 if (as_references_) { |
1122 writer_->WriteObjectRef(raw_obj); | 1127 writer_->WriteObjectRef(raw_obj); |
1123 } else { | 1128 } else { |
1124 writer_->WriteObjectImpl(raw_obj); | 1129 writer_->WriteObjectImpl(raw_obj); |
1125 } | 1130 } |
1126 } | 1131 } |
1127 } | 1132 } |
1128 | 1133 |
| 1134 |
| 1135 void MessageWriter::WriteMessage(const Object& obj) { |
| 1136 ASSERT(kind() == Snapshot::kMessage); |
| 1137 WriteObject(obj.raw()); |
| 1138 UnmarkAll(); |
| 1139 } |
| 1140 |
| 1141 |
1129 } // namespace dart | 1142 } // namespace dart |
OLD | NEW |