| 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 30 matching lines...) Expand all Loading... |
| 295 Array& array = Array::ZoneHandle( | 295 Array& array = Array::ZoneHandle( |
| 296 isolate(), | 296 isolate(), |
| 297 (kind_ == Snapshot::kFull) ? | 297 (kind_ == Snapshot::kFull) ? |
| 298 NewImmutableArray(len) : ImmutableArray::New(len, HEAP_SPACE(kind_))); | 298 NewImmutableArray(len) : ImmutableArray::New(len, HEAP_SPACE(kind_))); |
| 299 AddBackRef(object_id, &array, kIsNotDeserialized); | 299 AddBackRef(object_id, &array, kIsNotDeserialized); |
| 300 | 300 |
| 301 return array.raw(); | 301 return array.raw(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 // For all other internal VM classes we read the object inline. | 304 // For all other internal VM classes we read the object inline. |
| 305 intptr_t tags = ReadIntptrValue(); | 305 intptr_t tags = Read<int32_t>(); |
| 306 switch (class_id) { | 306 switch (class_id) { |
| 307 #define SNAPSHOT_READ(clazz) \ | 307 #define SNAPSHOT_READ(clazz) \ |
| 308 case clazz::kClassId: { \ | 308 case clazz::kClassId: { \ |
| 309 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ | 309 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ |
| 310 break; \ | 310 break; \ |
| 311 } | 311 } |
| 312 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) | 312 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) |
| 313 #undef SNAPSHOT_READ | 313 #undef SNAPSHOT_READ |
| 314 #define SNAPSHOT_READ(clazz) \ | 314 #define SNAPSHOT_READ(clazz) \ |
| 315 case kTypedData##clazz##Cid: \ | 315 case kTypedData##clazz##Cid: \ |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 return GetType(object_store(), object_id); // return type obj. | 804 return GetType(object_store(), object_id); // return type obj. |
| 805 } | 805 } |
| 806 } | 806 } |
| 807 Object* object = GetBackRef(object_id); | 807 Object* object = GetBackRef(object_id); |
| 808 return object->raw(); | 808 return object->raw(); |
| 809 } | 809 } |
| 810 | 810 |
| 811 | 811 |
| 812 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { | 812 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { |
| 813 // Read the class header information and lookup the class. | 813 // Read the class header information and lookup the class. |
| 814 intptr_t class_header = ReadIntptrValue(); | 814 intptr_t class_header = Read<int32_t>(); |
| 815 intptr_t tags = ReadIntptrValue(); | 815 intptr_t tags = Read<int32_t>(); |
| 816 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 816 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 817 // Object is regular dart instance. | 817 // Object is regular dart instance. |
| 818 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); | 818 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); |
| 819 intptr_t instance_size = 0; | 819 intptr_t instance_size = 0; |
| 820 if (result == NULL) { | 820 if (result == NULL) { |
| 821 result = &(Instance::ZoneHandle(isolate(), Instance::null())); | 821 result = &(Instance::ZoneHandle(isolate(), Instance::null())); |
| 822 AddBackRef(object_id, result, kIsDeserialized); | 822 AddBackRef(object_id, result, kIsDeserialized); |
| 823 cls_ ^= ReadObjectImpl(); | 823 cls_ ^= ReadObjectImpl(); |
| 824 ASSERT(!cls_.IsNull()); | 824 ASSERT(!cls_.IsNull()); |
| 825 instance_size = cls_.instance_size(); | 825 instance_size = cls_.instance_size(); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 | 1381 |
| 1382 | 1382 |
| 1383 void SnapshotWriter::WriteClassId(RawClass* cls) { | 1383 void SnapshotWriter::WriteClassId(RawClass* cls) { |
| 1384 ASSERT(kind_ != Snapshot::kFull); | 1384 ASSERT(kind_ != Snapshot::kFull); |
| 1385 int class_id = cls->ptr()->id_; | 1385 int class_id = cls->ptr()->id_; |
| 1386 ASSERT(!IsSingletonClassId(class_id) && !IsObjectStoreClassId(class_id)); | 1386 ASSERT(!IsSingletonClassId(class_id) && !IsObjectStoreClassId(class_id)); |
| 1387 // TODO(5411462): Should restrict this to only core-lib classes in this | 1387 // TODO(5411462): Should restrict this to only core-lib classes in this |
| 1388 // case. | 1388 // case. |
| 1389 // Write out the class and tags information. | 1389 // Write out the class and tags information. |
| 1390 WriteVMIsolateObject(kClassCid); | 1390 WriteVMIsolateObject(kClassCid); |
| 1391 WriteIntptrValue(GetObjectTags(cls)); | 1391 Write<int32_t>(GetObjectTags(cls)); |
| 1392 | 1392 |
| 1393 // Write out the library url and class name. | 1393 // Write out the library url and class name. |
| 1394 RawLibrary* library = cls->ptr()->library_; | 1394 RawLibrary* library = cls->ptr()->library_; |
| 1395 ASSERT(library != Library::null()); | 1395 ASSERT(library != Library::null()); |
| 1396 WriteObjectImpl(library->ptr()->url_); | 1396 WriteObjectImpl(library->ptr()->url_); |
| 1397 WriteObjectImpl(cls->ptr()->name_); | 1397 WriteObjectImpl(cls->ptr()->name_); |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 | 1400 |
| 1401 void SnapshotWriter::ArrayWriteTo(intptr_t object_id, | 1401 void SnapshotWriter::ArrayWriteTo(intptr_t object_id, |
| 1402 intptr_t array_kind, | 1402 intptr_t array_kind, |
| 1403 intptr_t tags, | 1403 intptr_t tags, |
| 1404 RawSmi* length, | 1404 RawSmi* length, |
| 1405 RawTypeArguments* type_arguments, | 1405 RawTypeArguments* type_arguments, |
| 1406 RawObject* data[]) { | 1406 RawObject* data[]) { |
| 1407 intptr_t len = Smi::Value(length); | 1407 intptr_t len = Smi::Value(length); |
| 1408 | 1408 |
| 1409 // Write out the serialization header value for this object. | 1409 // Write out the serialization header value for this object. |
| 1410 WriteInlinedObjectHeader(object_id); | 1410 WriteInlinedObjectHeader(object_id); |
| 1411 | 1411 |
| 1412 // Write out the class and tags information. | 1412 // Write out the class and tags information. |
| 1413 WriteIndexedObject(array_kind); | 1413 WriteIndexedObject(array_kind); |
| 1414 WriteIntptrValue(tags); | 1414 Write<int32_t>(tags); |
| 1415 | 1415 |
| 1416 // Write out the length field. | 1416 // Write out the length field. |
| 1417 Write<RawObject*>(length); | 1417 Write<RawObject*>(length); |
| 1418 | 1418 |
| 1419 // Write out the type arguments. | 1419 // Write out the type arguments. |
| 1420 WriteObjectImpl(type_arguments); | 1420 WriteObjectImpl(type_arguments); |
| 1421 | 1421 |
| 1422 // Write out the individual object ids. | 1422 // Write out the individual object ids. |
| 1423 for (intptr_t i = 0; i < len; i++) { | 1423 for (intptr_t i = 0; i < len; i++) { |
| 1424 WriteObjectRef(data[i]); | 1424 WriteObjectRef(data[i]); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 | 1461 |
| 1462 // Object is regular dart instance. | 1462 // Object is regular dart instance. |
| 1463 intptr_t next_field_offset = | 1463 intptr_t next_field_offset = |
| 1464 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; | 1464 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; |
| 1465 ASSERT(next_field_offset > 0); | 1465 ASSERT(next_field_offset > 0); |
| 1466 | 1466 |
| 1467 // Write out the serialization header value for this object. | 1467 // Write out the serialization header value for this object. |
| 1468 WriteInlinedObjectHeader(object_id); | 1468 WriteInlinedObjectHeader(object_id); |
| 1469 | 1469 |
| 1470 // Indicate this is an instance object. | 1470 // Indicate this is an instance object. |
| 1471 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | 1471 Write<int32_t>(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1472 | 1472 |
| 1473 // Write out the tags. | 1473 // Write out the tags. |
| 1474 WriteIntptrValue(tags); | 1474 Write<int32_t>(tags); |
| 1475 | 1475 |
| 1476 // Write out the class information for this object. | 1476 // Write out the class information for this object. |
| 1477 WriteObjectImpl(cls); | 1477 WriteObjectImpl(cls); |
| 1478 | 1478 |
| 1479 // Write out all the fields for the object. | 1479 // Write out all the fields for the object. |
| 1480 // Instance::NextFieldOffset() returns the offset of the first field in | 1480 // Instance::NextFieldOffset() returns the offset of the first field in |
| 1481 // a Dart object. | 1481 // a Dart object. |
| 1482 intptr_t offset = Instance::NextFieldOffset(); | 1482 intptr_t offset = Instance::NextFieldOffset(); |
| 1483 while (offset < next_field_offset) { | 1483 while (offset < next_field_offset) { |
| 1484 WriteObjectRef(*reinterpret_cast<RawObject**>( | 1484 WriteObjectRef(*reinterpret_cast<RawObject**>( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1496 // Object is being referenced, add it to the forward ref list and mark | 1496 // Object is being referenced, add it to the forward ref list and mark |
| 1497 // it so that future references to this object in the snapshot will use | 1497 // it so that future references to this object in the snapshot will use |
| 1498 // this object id. Mark it as not having been serialized yet so that we | 1498 // this object id. Mark it as not having been serialized yet so that we |
| 1499 // will serialize the object when we go through the forward list. | 1499 // will serialize the object when we go through the forward list. |
| 1500 intptr_t object_id = MarkObject(raw, kIsNotSerialized); | 1500 intptr_t object_id = MarkObject(raw, kIsNotSerialized); |
| 1501 | 1501 |
| 1502 // Write out the serialization header value for this object. | 1502 // Write out the serialization header value for this object. |
| 1503 WriteInlinedObjectHeader(object_id); | 1503 WriteInlinedObjectHeader(object_id); |
| 1504 | 1504 |
| 1505 // Indicate this is an instance object. | 1505 // Indicate this is an instance object. |
| 1506 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | 1506 Write<int32_t>(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1507 | 1507 |
| 1508 // Write out the class information for this object. | 1508 // Write out the class information for this object. |
| 1509 WriteObjectImpl(cls); | 1509 WriteObjectImpl(cls); |
| 1510 } | 1510 } |
| 1511 | 1511 |
| 1512 | 1512 |
| 1513 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, | 1513 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, |
| 1514 const char* msg) { | 1514 const char* msg) { |
| 1515 Isolate::Current()->object_store()->clear_sticky_error(); | 1515 Isolate::Current()->object_store()->clear_sticky_error(); |
| 1516 UnmarkAll(); | 1516 UnmarkAll(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 NoGCScope no_gc; | 1572 NoGCScope no_gc; |
| 1573 WriteObject(obj.raw()); | 1573 WriteObject(obj.raw()); |
| 1574 UnmarkAll(); | 1574 UnmarkAll(); |
| 1575 } else { | 1575 } else { |
| 1576 ThrowException(exception_type(), exception_msg()); | 1576 ThrowException(exception_type(), exception_msg()); |
| 1577 } | 1577 } |
| 1578 } | 1578 } |
| 1579 | 1579 |
| 1580 | 1580 |
| 1581 } // namespace dart | 1581 } // namespace dart |
| OLD | NEW |