| 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/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // handle, then signal an error. | 142 // handle, then signal an error. |
| 143 int64_t snapshot_length = ReadUnaligned(&snapshot->unaligned_length_); | 143 int64_t snapshot_length = ReadUnaligned(&snapshot->unaligned_length_); |
| 144 if ((snapshot_length < 0) || (snapshot_length > kIntptrMax)) { | 144 if ((snapshot_length < 0) || (snapshot_length > kIntptrMax)) { |
| 145 return NULL; | 145 return NULL; |
| 146 } | 146 } |
| 147 return snapshot; | 147 return snapshot; |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 RawSmi* BaseReader::ReadAsSmi() { | 151 RawSmi* BaseReader::ReadAsSmi() { |
| 152 intptr_t value = ReadIntptrValue(); | 152 intptr_t value = Read<int32_t>(); |
| 153 ASSERT((value & kSmiTagMask) == kSmiTag); | 153 ASSERT((value & kSmiTagMask) == kSmiTag); |
| 154 return reinterpret_cast<RawSmi*>(value); | 154 return reinterpret_cast<RawSmi*>(value); |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 intptr_t BaseReader::ReadSmiValue() { | 158 intptr_t BaseReader::ReadSmiValue() { |
| 159 return Smi::Value(ReadAsSmi()); | 159 return Smi::Value(ReadAsSmi()); |
| 160 } | 160 } |
| 161 | 161 |
| 162 | 162 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 const Error& err = Error::Handle(isolate()->object_store()->sticky_error()); | 205 const Error& err = Error::Handle(isolate()->object_store()->sticky_error()); |
| 206 isolate()->object_store()->clear_sticky_error(); | 206 isolate()->object_store()->clear_sticky_error(); |
| 207 return err.raw(); | 207 return err.raw(); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 | 211 |
| 212 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { | 212 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { |
| 213 ASSERT(kind_ != Snapshot::kFull); | 213 ASSERT(kind_ != Snapshot::kFull); |
| 214 // Read the class header information and lookup the class. | 214 // Read the class header information and lookup the class. |
| 215 intptr_t class_header = ReadIntptrValue(); | 215 intptr_t class_header = Read<int32_t>(); |
| 216 ASSERT((class_header & kSmiTagMask) != kSmiTag); | 216 ASSERT((class_header & kSmiTagMask) != kSmiTag); |
| 217 ASSERT(!IsVMIsolateObject(class_header) || | 217 ASSERT(!IsVMIsolateObject(class_header) || |
| 218 !IsSingletonClassId(GetVMIsolateObjectId(class_header))); | 218 !IsSingletonClassId(GetVMIsolateObjectId(class_header))); |
| 219 ASSERT((SerializedHeaderTag::decode(class_header) != kObjectId) || | 219 ASSERT((SerializedHeaderTag::decode(class_header) != kObjectId) || |
| 220 !IsObjectStoreClassId(SerializedHeaderData::decode(class_header))); | 220 !IsObjectStoreClassId(SerializedHeaderData::decode(class_header))); |
| 221 Class& cls = Class::ZoneHandle(isolate(), Class::null()); | 221 Class& cls = Class::ZoneHandle(isolate(), Class::null()); |
| 222 AddBackRef(object_id, &cls, kIsDeserialized); | 222 AddBackRef(object_id, &cls, kIsDeserialized); |
| 223 // Read the library/class information and lookup the class. | 223 // Read the library/class information and lookup the class. |
| 224 str_ ^= ReadObjectImpl(class_header); | 224 str_ ^= ReadObjectImpl(class_header); |
| 225 library_ = Library::LookupLibrary(str_); | 225 library_ = Library::LookupLibrary(str_); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 return ReadIndexedObject(SerializedHeaderData::decode(value)); | 277 return ReadIndexedObject(SerializedHeaderData::decode(value)); |
| 278 } | 278 } |
| 279 ASSERT(SerializedHeaderTag::decode(value) == kInlined); | 279 ASSERT(SerializedHeaderTag::decode(value) == kInlined); |
| 280 intptr_t object_id = SerializedHeaderData::decode(value); | 280 intptr_t object_id = SerializedHeaderData::decode(value); |
| 281 if (object_id == kOmittedObjectId) { | 281 if (object_id == kOmittedObjectId) { |
| 282 object_id = NextAvailableObjectId(); | 282 object_id = NextAvailableObjectId(); |
| 283 } | 283 } |
| 284 ASSERT(GetBackRef(object_id) == NULL); | 284 ASSERT(GetBackRef(object_id) == NULL); |
| 285 | 285 |
| 286 // Read the class header information and lookup the class. | 286 // Read the class header information and lookup the class. |
| 287 intptr_t class_header = ReadIntptrValue(); | 287 intptr_t class_header = Read<int32_t>(); |
| 288 | 288 |
| 289 // Since we are only reading an object reference, If it is an instance kind | 289 // Since we are only reading an object reference, If it is an instance kind |
| 290 // then we only need to figure out the class of the object and allocate an | 290 // then we only need to figure out the class of the object and allocate an |
| 291 // instance of it. The individual fields will be read later. | 291 // instance of it. The individual fields will be read later. |
| 292 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 292 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 293 Instance& result = Instance::ZoneHandle(isolate(), Instance::null()); | 293 Instance& result = Instance::ZoneHandle(isolate(), Instance::null()); |
| 294 AddBackRef(object_id, &result, kIsNotDeserialized); | 294 AddBackRef(object_id, &result, kIsNotDeserialized); |
| 295 | 295 |
| 296 cls_ ^= ReadObjectImpl(); // Read class information. | 296 cls_ ^= ReadObjectImpl(); // Read class information. |
| 297 ASSERT(!cls_.IsNull()); | 297 ASSERT(!cls_.IsNull()); |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 return GetType(object_store(), object_id); // return type obj. | 925 return GetType(object_store(), object_id); // return type obj. |
| 926 } | 926 } |
| 927 } | 927 } |
| 928 Object* object = GetBackRef(object_id); | 928 Object* object = GetBackRef(object_id); |
| 929 return object->raw(); | 929 return object->raw(); |
| 930 } | 930 } |
| 931 | 931 |
| 932 | 932 |
| 933 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { | 933 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { |
| 934 // Read the class header information and lookup the class. | 934 // Read the class header information and lookup the class. |
| 935 intptr_t class_header = ReadIntptrValue(); | 935 intptr_t class_header = Read<int32_t>(); |
| 936 intptr_t tags = ReadTags(); | 936 intptr_t tags = ReadTags(); |
| 937 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 937 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 938 // Object is regular dart instance. | 938 // Object is regular dart instance. |
| 939 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); | 939 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); |
| 940 intptr_t instance_size = 0; | 940 intptr_t instance_size = 0; |
| 941 if (result == NULL) { | 941 if (result == NULL) { |
| 942 result = &(Instance::ZoneHandle(isolate(), Instance::null())); | 942 result = &(Instance::ZoneHandle(isolate(), Instance::null())); |
| 943 AddBackRef(object_id, result, kIsDeserialized); | 943 AddBackRef(object_id, result, kIsDeserialized); |
| 944 cls_ ^= ReadObjectImpl(); | 944 cls_ ^= ReadObjectImpl(); |
| 945 ASSERT(!cls_.IsNull()); | 945 ASSERT(!cls_.IsNull()); |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1647 | 1647 |
| 1648 // Object is regular dart instance. | 1648 // Object is regular dart instance. |
| 1649 intptr_t next_field_offset = | 1649 intptr_t next_field_offset = |
| 1650 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; | 1650 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; |
| 1651 ASSERT(next_field_offset > 0); | 1651 ASSERT(next_field_offset > 0); |
| 1652 | 1652 |
| 1653 // Write out the serialization header value for this object. | 1653 // Write out the serialization header value for this object. |
| 1654 WriteInlinedObjectHeader(object_id); | 1654 WriteInlinedObjectHeader(object_id); |
| 1655 | 1655 |
| 1656 // Indicate this is an instance object. | 1656 // Indicate this is an instance object. |
| 1657 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | 1657 Write<int32_t>(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1658 | 1658 |
| 1659 // Write out the tags. | 1659 // Write out the tags. |
| 1660 WriteTags(tags); | 1660 WriteTags(tags); |
| 1661 | 1661 |
| 1662 // Write out the class information for this object. | 1662 // Write out the class information for this object. |
| 1663 WriteObjectImpl(cls); | 1663 WriteObjectImpl(cls); |
| 1664 | 1664 |
| 1665 // Write out all the fields for the object. | 1665 // Write out all the fields for the object. |
| 1666 // Instance::NextFieldOffset() returns the offset of the first field in | 1666 // Instance::NextFieldOffset() returns the offset of the first field in |
| 1667 // a Dart object. | 1667 // a Dart object. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1682 // Object is being referenced, add it to the forward ref list and mark | 1682 // Object is being referenced, add it to the forward ref list and mark |
| 1683 // it so that future references to this object in the snapshot will use | 1683 // it so that future references to this object in the snapshot will use |
| 1684 // this object id. Mark it as not having been serialized yet so that we | 1684 // this object id. Mark it as not having been serialized yet so that we |
| 1685 // will serialize the object when we go through the forward list. | 1685 // will serialize the object when we go through the forward list. |
| 1686 forward_list_.MarkAndAddObject(raw, kIsNotSerialized); | 1686 forward_list_.MarkAndAddObject(raw, kIsNotSerialized); |
| 1687 | 1687 |
| 1688 // Write out the serialization header value for this object. | 1688 // Write out the serialization header value for this object. |
| 1689 WriteInlinedObjectHeader(kOmittedObjectId); | 1689 WriteInlinedObjectHeader(kOmittedObjectId); |
| 1690 | 1690 |
| 1691 // Indicate this is an instance object. | 1691 // Indicate this is an instance object. |
| 1692 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | 1692 Write<int32_t>(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1693 | 1693 |
| 1694 // Write out the class information for this object. | 1694 // Write out the class information for this object. |
| 1695 WriteObjectImpl(cls); | 1695 WriteObjectImpl(cls); |
| 1696 } | 1696 } |
| 1697 | 1697 |
| 1698 | 1698 |
| 1699 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, | 1699 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, |
| 1700 const char* msg) { | 1700 const char* msg) { |
| 1701 isolate()->object_store()->clear_sticky_error(); | 1701 isolate()->object_store()->clear_sticky_error(); |
| 1702 UnmarkAll(); | 1702 UnmarkAll(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 NoGCScope no_gc; | 1774 NoGCScope no_gc; |
| 1775 WriteObject(obj.raw()); | 1775 WriteObject(obj.raw()); |
| 1776 UnmarkAll(); | 1776 UnmarkAll(); |
| 1777 } else { | 1777 } else { |
| 1778 ThrowException(exception_type(), exception_msg()); | 1778 ThrowException(exception_type(), exception_msg()); |
| 1779 } | 1779 } |
| 1780 } | 1780 } |
| 1781 | 1781 |
| 1782 | 1782 |
| 1783 } // namespace dart | 1783 } // namespace dart |
| OLD | NEW |