| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // allows the two low bits in the header to be used for snapshotting. | 123 // allows the two low bits in the header to be used for snapshotting. |
| 124 ASSERT(kObjectId == | 124 ASSERT(kObjectId == |
| 125 ((1 << RawObject::kWatchedBit) | (1 << RawObject::kMarkBit))); | 125 ((1 << RawObject::kWatchedBit) | (1 << RawObject::kMarkBit))); |
| 126 ASSERT((kObjectAlignmentMask & kObjectId) == kObjectId); | 126 ASSERT((kObjectAlignmentMask & kObjectId) == kObjectId); |
| 127 const Snapshot* snapshot = reinterpret_cast<const Snapshot*>(raw_memory); | 127 const Snapshot* snapshot = reinterpret_cast<const Snapshot*>(raw_memory); |
| 128 return snapshot; | 128 return snapshot; |
| 129 } | 129 } |
| 130 | 130 |
| 131 | 131 |
| 132 RawSmi* BaseReader::ReadAsSmi() { | 132 RawSmi* BaseReader::ReadAsSmi() { |
| 133 intptr_t value = ReadIntptrValue(); | 133 intptr_t value = Read<int32_t>(); |
| 134 ASSERT((value & kSmiTagMask) == kSmiTag); | 134 ASSERT((value & kSmiTagMask) == kSmiTag); |
| 135 return reinterpret_cast<RawSmi*>(value); | 135 return reinterpret_cast<RawSmi*>(value); |
| 136 } | 136 } |
| 137 | 137 |
| 138 | 138 |
| 139 intptr_t BaseReader::ReadSmiValue() { | 139 intptr_t BaseReader::ReadSmiValue() { |
| 140 return Smi::Value(ReadAsSmi()); | 140 return Smi::Value(ReadAsSmi()); |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 const Error& err = Error::Handle(isolate()->object_store()->sticky_error()); | 185 const Error& err = Error::Handle(isolate()->object_store()->sticky_error()); |
| 186 isolate()->object_store()->clear_sticky_error(); | 186 isolate()->object_store()->clear_sticky_error(); |
| 187 return err.raw(); | 187 return err.raw(); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 | 191 |
| 192 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { | 192 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { |
| 193 ASSERT(kind_ != Snapshot::kFull); | 193 ASSERT(kind_ != Snapshot::kFull); |
| 194 // Read the class header information and lookup the class. | 194 // Read the class header information and lookup the class. |
| 195 intptr_t class_header = ReadIntptrValue(); | 195 intptr_t class_header = Read<int32_t>(); |
| 196 ASSERT((class_header & kSmiTagMask) != kSmiTag); | 196 ASSERT((class_header & kSmiTagMask) != kSmiTag); |
| 197 ASSERT(!IsVMIsolateObject(class_header) || | 197 ASSERT(!IsVMIsolateObject(class_header) || |
| 198 !IsSingletonClassId(GetVMIsolateObjectId(class_header))); | 198 !IsSingletonClassId(GetVMIsolateObjectId(class_header))); |
| 199 ASSERT((SerializedHeaderTag::decode(class_header) != kObjectId) || | 199 ASSERT((SerializedHeaderTag::decode(class_header) != kObjectId) || |
| 200 !IsObjectStoreClassId(SerializedHeaderData::decode(class_header))); | 200 !IsObjectStoreClassId(SerializedHeaderData::decode(class_header))); |
| 201 Class& cls = Class::ZoneHandle(isolate(), Class::null()); | 201 Class& cls = Class::ZoneHandle(isolate(), Class::null()); |
| 202 AddBackRef(object_id, &cls, kIsDeserialized); | 202 AddBackRef(object_id, &cls, kIsDeserialized); |
| 203 // Read the library/class information and lookup the class. | 203 // Read the library/class information and lookup the class. |
| 204 str_ ^= ReadObjectImpl(class_header); | 204 str_ ^= ReadObjectImpl(class_header); |
| 205 library_ = Library::LookupLibrary(str_); | 205 library_ = Library::LookupLibrary(str_); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (IsVMIsolateObject(header_value)) { | 244 if (IsVMIsolateObject(header_value)) { |
| 245 return ReadVMIsolateObject(header_value); | 245 return ReadVMIsolateObject(header_value); |
| 246 } else if (SerializedHeaderTag::decode(header_value) == kObjectId) { | 246 } else if (SerializedHeaderTag::decode(header_value) == kObjectId) { |
| 247 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); | 247 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); |
| 248 } | 248 } |
| 249 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); | 249 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); |
| 250 intptr_t object_id = SerializedHeaderData::decode(header_value); | 250 intptr_t object_id = SerializedHeaderData::decode(header_value); |
| 251 ASSERT(GetBackRef(object_id) == NULL); | 251 ASSERT(GetBackRef(object_id) == NULL); |
| 252 | 252 |
| 253 // Read the class header information and lookup the class. | 253 // Read the class header information and lookup the class. |
| 254 intptr_t class_header = ReadIntptrValue(); | 254 intptr_t class_header = Read<int32_t>(); |
| 255 | 255 |
| 256 // Since we are only reading an object reference, If it is an instance kind | 256 // Since we are only reading an object reference, If it is an instance kind |
| 257 // then we only need to figure out the class of the object and allocate an | 257 // then we only need to figure out the class of the object and allocate an |
| 258 // instance of it. The individual fields will be read later. | 258 // instance of it. The individual fields will be read later. |
| 259 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 259 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 260 Instance& result = Instance::ZoneHandle(isolate(), Instance::null()); | 260 Instance& result = Instance::ZoneHandle(isolate(), Instance::null()); |
| 261 AddBackRef(object_id, &result, kIsNotDeserialized); | 261 AddBackRef(object_id, &result, kIsNotDeserialized); |
| 262 | 262 |
| 263 cls_ ^= ReadObjectImpl(); // Read class information. | 263 cls_ ^= ReadObjectImpl(); // Read class information. |
| 264 ASSERT(!cls_.IsNull()); | 264 ASSERT(!cls_.IsNull()); |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 return GetType(object_store(), object_id); // return type obj. | 806 return GetType(object_store(), object_id); // return type obj. |
| 807 } | 807 } |
| 808 } | 808 } |
| 809 Object* object = GetBackRef(object_id); | 809 Object* object = GetBackRef(object_id); |
| 810 return object->raw(); | 810 return object->raw(); |
| 811 } | 811 } |
| 812 | 812 |
| 813 | 813 |
| 814 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { | 814 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { |
| 815 // Read the class header information and lookup the class. | 815 // Read the class header information and lookup the class. |
| 816 intptr_t class_header = ReadIntptrValue(); | 816 intptr_t class_header = Read<int32_t>(); |
| 817 intptr_t tags = ReadTags(); | 817 intptr_t tags = ReadTags(); |
| 818 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 818 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 819 // Object is regular dart instance. | 819 // Object is regular dart instance. |
| 820 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); | 820 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); |
| 821 intptr_t instance_size = 0; | 821 intptr_t instance_size = 0; |
| 822 if (result == NULL) { | 822 if (result == NULL) { |
| 823 result = &(Instance::ZoneHandle(isolate(), Instance::null())); | 823 result = &(Instance::ZoneHandle(isolate(), Instance::null())); |
| 824 AddBackRef(object_id, result, kIsDeserialized); | 824 AddBackRef(object_id, result, kIsDeserialized); |
| 825 cls_ ^= ReadObjectImpl(); | 825 cls_ ^= ReadObjectImpl(); |
| 826 ASSERT(!cls_.IsNull()); | 826 ASSERT(!cls_.IsNull()); |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 | 1465 |
| 1466 // Object is regular dart instance. | 1466 // Object is regular dart instance. |
| 1467 intptr_t next_field_offset = | 1467 intptr_t next_field_offset = |
| 1468 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; | 1468 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; |
| 1469 ASSERT(next_field_offset > 0); | 1469 ASSERT(next_field_offset > 0); |
| 1470 | 1470 |
| 1471 // Write out the serialization header value for this object. | 1471 // Write out the serialization header value for this object. |
| 1472 WriteInlinedObjectHeader(object_id); | 1472 WriteInlinedObjectHeader(object_id); |
| 1473 | 1473 |
| 1474 // Indicate this is an instance object. | 1474 // Indicate this is an instance object. |
| 1475 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | 1475 Write<int32_t>(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1476 | 1476 |
| 1477 // Write out the tags. | 1477 // Write out the tags. |
| 1478 WriteTags(tags); | 1478 WriteTags(tags); |
| 1479 | 1479 |
| 1480 // Write out the class information for this object. | 1480 // Write out the class information for this object. |
| 1481 WriteObjectImpl(cls); | 1481 WriteObjectImpl(cls); |
| 1482 | 1482 |
| 1483 // Write out all the fields for the object. | 1483 // Write out all the fields for the object. |
| 1484 // Instance::NextFieldOffset() returns the offset of the first field in | 1484 // Instance::NextFieldOffset() returns the offset of the first field in |
| 1485 // a Dart object. | 1485 // a Dart object. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1500 // Object is being referenced, add it to the forward ref list and mark | 1500 // Object is being referenced, add it to the forward ref list and mark |
| 1501 // it so that future references to this object in the snapshot will use | 1501 // it so that future references to this object in the snapshot will use |
| 1502 // this object id. Mark it as not having been serialized yet so that we | 1502 // this object id. Mark it as not having been serialized yet so that we |
| 1503 // will serialize the object when we go through the forward list. | 1503 // will serialize the object when we go through the forward list. |
| 1504 intptr_t object_id = MarkObject(raw, kIsNotSerialized); | 1504 intptr_t object_id = MarkObject(raw, kIsNotSerialized); |
| 1505 | 1505 |
| 1506 // Write out the serialization header value for this object. | 1506 // Write out the serialization header value for this object. |
| 1507 WriteInlinedObjectHeader(object_id); | 1507 WriteInlinedObjectHeader(object_id); |
| 1508 | 1508 |
| 1509 // Indicate this is an instance object. | 1509 // Indicate this is an instance object. |
| 1510 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | 1510 Write<int32_t>(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1511 | 1511 |
| 1512 // Write out the class information for this object. | 1512 // Write out the class information for this object. |
| 1513 WriteObjectImpl(cls); | 1513 WriteObjectImpl(cls); |
| 1514 } | 1514 } |
| 1515 | 1515 |
| 1516 | 1516 |
| 1517 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, | 1517 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, |
| 1518 const char* msg) { | 1518 const char* msg) { |
| 1519 Isolate::Current()->object_store()->clear_sticky_error(); | 1519 Isolate::Current()->object_store()->clear_sticky_error(); |
| 1520 UnmarkAll(); | 1520 UnmarkAll(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1576 NoGCScope no_gc; | 1576 NoGCScope no_gc; |
| 1577 WriteObject(obj.raw()); | 1577 WriteObject(obj.raw()); |
| 1578 UnmarkAll(); | 1578 UnmarkAll(); |
| 1579 } else { | 1579 } else { |
| 1580 ThrowException(exception_type(), exception_msg()); | 1580 ThrowException(exception_type(), exception_msg()); |
| 1581 } | 1581 } |
| 1582 } | 1582 } |
| 1583 | 1583 |
| 1584 | 1584 |
| 1585 } // namespace dart | 1585 } // namespace dart |
| OLD | NEW |