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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 = ReadTags(); |
306 tags = RawObject::ClassIdTag::update(class_id, tags); | |
siva
2014/06/23 21:45:53
Is it necessary to or in the class_id here? I thin
zra
2014/06/23 22:17:50
The class id is taken from tags in TypedData::Read
| |
306 switch (class_id) { | 307 switch (class_id) { |
307 #define SNAPSHOT_READ(clazz) \ | 308 #define SNAPSHOT_READ(clazz) \ |
308 case clazz::kClassId: { \ | 309 case clazz::kClassId: { \ |
309 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ | 310 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ |
310 break; \ | 311 break; \ |
311 } | 312 } |
312 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) | 313 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) |
313 #undef SNAPSHOT_READ | 314 #undef SNAPSHOT_READ |
314 #define SNAPSHOT_READ(clazz) \ | 315 #define SNAPSHOT_READ(clazz) \ |
315 case kTypedData##clazz##Cid: \ | 316 case kTypedData##clazz##Cid: \ |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 } | 806 } |
806 } | 807 } |
807 Object* object = GetBackRef(object_id); | 808 Object* object = GetBackRef(object_id); |
808 return object->raw(); | 809 return object->raw(); |
809 } | 810 } |
810 | 811 |
811 | 812 |
812 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { | 813 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { |
813 // Read the class header information and lookup the class. | 814 // Read the class header information and lookup the class. |
814 intptr_t class_header = ReadIntptrValue(); | 815 intptr_t class_header = ReadIntptrValue(); |
815 intptr_t tags = ReadIntptrValue(); | 816 intptr_t tags = ReadTags(); |
816 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 817 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
817 // Object is regular dart instance. | 818 // Object is regular dart instance. |
818 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); | 819 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); |
819 intptr_t instance_size = 0; | 820 intptr_t instance_size = 0; |
820 if (result == NULL) { | 821 if (result == NULL) { |
821 result = &(Instance::ZoneHandle(isolate(), Instance::null())); | 822 result = &(Instance::ZoneHandle(isolate(), Instance::null())); |
822 AddBackRef(object_id, result, kIsDeserialized); | 823 AddBackRef(object_id, result, kIsDeserialized); |
823 cls_ ^= ReadObjectImpl(); | 824 cls_ ^= ReadObjectImpl(); |
824 ASSERT(!cls_.IsNull()); | 825 ASSERT(!cls_.IsNull()); |
825 instance_size = cls_.instance_size(); | 826 instance_size = cls_.instance_size(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 result->SetCreatedFromSnapshot(); | 874 result->SetCreatedFromSnapshot(); |
874 } else if (result->IsCanonical()) { | 875 } else if (result->IsCanonical()) { |
875 *result = result->CheckAndCanonicalize(NULL); | 876 *result = result->CheckAndCanonicalize(NULL); |
876 ASSERT(!result->IsNull()); | 877 ASSERT(!result->IsNull()); |
877 } | 878 } |
878 return result->raw(); | 879 return result->raw(); |
879 } | 880 } |
880 ASSERT((class_header & kSmiTagMask) != kSmiTag); | 881 ASSERT((class_header & kSmiTagMask) != kSmiTag); |
881 cls_ = LookupInternalClass(class_header); | 882 cls_ = LookupInternalClass(class_header); |
882 ASSERT(!cls_.IsNull()); | 883 ASSERT(!cls_.IsNull()); |
884 tags = RawObject::ClassIdTag::update(cls_.id(), tags); | |
siva
2014/06/23 21:45:53
Ditto comment about oring in the class_id
zra
2014/06/23 22:17:50
Same as above.
| |
883 switch (cls_.id()) { | 885 switch (cls_.id()) { |
884 #define SNAPSHOT_READ(clazz) \ | 886 #define SNAPSHOT_READ(clazz) \ |
885 case clazz::kClassId: { \ | 887 case clazz::kClassId: { \ |
886 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ | 888 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ |
887 break; \ | 889 break; \ |
888 } | 890 } |
889 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) | 891 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) |
890 #undef SNAPSHOT_READ | 892 #undef SNAPSHOT_READ |
891 #define SNAPSHOT_READ(clazz) \ | 893 #define SNAPSHOT_READ(clazz) \ |
892 case kTypedData##clazz##Cid: \ | 894 case kTypedData##clazz##Cid: \ |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 | 1383 |
1382 | 1384 |
1383 void SnapshotWriter::WriteClassId(RawClass* cls) { | 1385 void SnapshotWriter::WriteClassId(RawClass* cls) { |
1384 ASSERT(kind_ != Snapshot::kFull); | 1386 ASSERT(kind_ != Snapshot::kFull); |
1385 int class_id = cls->ptr()->id_; | 1387 int class_id = cls->ptr()->id_; |
1386 ASSERT(!IsSingletonClassId(class_id) && !IsObjectStoreClassId(class_id)); | 1388 ASSERT(!IsSingletonClassId(class_id) && !IsObjectStoreClassId(class_id)); |
1387 // TODO(5411462): Should restrict this to only core-lib classes in this | 1389 // TODO(5411462): Should restrict this to only core-lib classes in this |
1388 // case. | 1390 // case. |
1389 // Write out the class and tags information. | 1391 // Write out the class and tags information. |
1390 WriteVMIsolateObject(kClassCid); | 1392 WriteVMIsolateObject(kClassCid); |
1391 WriteIntptrValue(GetObjectTags(cls)); | 1393 WriteTags(GetObjectTags(cls)); |
1392 | 1394 |
1393 // Write out the library url and class name. | 1395 // Write out the library url and class name. |
1394 RawLibrary* library = cls->ptr()->library_; | 1396 RawLibrary* library = cls->ptr()->library_; |
1395 ASSERT(library != Library::null()); | 1397 ASSERT(library != Library::null()); |
1396 WriteObjectImpl(library->ptr()->url_); | 1398 WriteObjectImpl(library->ptr()->url_); |
1397 WriteObjectImpl(cls->ptr()->name_); | 1399 WriteObjectImpl(cls->ptr()->name_); |
1398 } | 1400 } |
1399 | 1401 |
1400 | 1402 |
1401 void SnapshotWriter::ArrayWriteTo(intptr_t object_id, | 1403 void SnapshotWriter::ArrayWriteTo(intptr_t object_id, |
1402 intptr_t array_kind, | 1404 intptr_t array_kind, |
1403 intptr_t tags, | 1405 intptr_t tags, |
1404 RawSmi* length, | 1406 RawSmi* length, |
1405 RawTypeArguments* type_arguments, | 1407 RawTypeArguments* type_arguments, |
1406 RawObject* data[]) { | 1408 RawObject* data[]) { |
1407 intptr_t len = Smi::Value(length); | 1409 intptr_t len = Smi::Value(length); |
1408 | 1410 |
1409 // Write out the serialization header value for this object. | 1411 // Write out the serialization header value for this object. |
1410 WriteInlinedObjectHeader(object_id); | 1412 WriteInlinedObjectHeader(object_id); |
1411 | 1413 |
1412 // Write out the class and tags information. | 1414 // Write out the class and tags information. |
1413 WriteIndexedObject(array_kind); | 1415 WriteIndexedObject(array_kind); |
1414 WriteIntptrValue(tags); | 1416 WriteTags(tags); |
1415 | 1417 |
1416 // Write out the length field. | 1418 // Write out the length field. |
1417 Write<RawObject*>(length); | 1419 Write<RawObject*>(length); |
1418 | 1420 |
1419 // Write out the type arguments. | 1421 // Write out the type arguments. |
1420 WriteObjectImpl(type_arguments); | 1422 WriteObjectImpl(type_arguments); |
1421 | 1423 |
1422 // Write out the individual object ids. | 1424 // Write out the individual object ids. |
1423 for (intptr_t i = 0; i < len; i++) { | 1425 for (intptr_t i = 0; i < len; i++) { |
1424 WriteObjectRef(data[i]); | 1426 WriteObjectRef(data[i]); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1464 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; | 1466 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; |
1465 ASSERT(next_field_offset > 0); | 1467 ASSERT(next_field_offset > 0); |
1466 | 1468 |
1467 // Write out the serialization header value for this object. | 1469 // Write out the serialization header value for this object. |
1468 WriteInlinedObjectHeader(object_id); | 1470 WriteInlinedObjectHeader(object_id); |
1469 | 1471 |
1470 // Indicate this is an instance object. | 1472 // Indicate this is an instance object. |
1471 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | 1473 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); |
1472 | 1474 |
1473 // Write out the tags. | 1475 // Write out the tags. |
1474 WriteIntptrValue(tags); | 1476 WriteTags(tags); |
1475 | 1477 |
1476 // Write out the class information for this object. | 1478 // Write out the class information for this object. |
1477 WriteObjectImpl(cls); | 1479 WriteObjectImpl(cls); |
1478 | 1480 |
1479 // Write out all the fields for the object. | 1481 // Write out all the fields for the object. |
1480 // Instance::NextFieldOffset() returns the offset of the first field in | 1482 // Instance::NextFieldOffset() returns the offset of the first field in |
1481 // a Dart object. | 1483 // a Dart object. |
1482 intptr_t offset = Instance::NextFieldOffset(); | 1484 intptr_t offset = Instance::NextFieldOffset(); |
1483 while (offset < next_field_offset) { | 1485 while (offset < next_field_offset) { |
1484 WriteObjectRef(*reinterpret_cast<RawObject**>( | 1486 WriteObjectRef(*reinterpret_cast<RawObject**>( |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1572 NoGCScope no_gc; | 1574 NoGCScope no_gc; |
1573 WriteObject(obj.raw()); | 1575 WriteObject(obj.raw()); |
1574 UnmarkAll(); | 1576 UnmarkAll(); |
1575 } else { | 1577 } else { |
1576 ThrowException(exception_type(), exception_msg()); | 1578 ThrowException(exception_type(), exception_msg()); |
1577 } | 1579 } |
1578 } | 1580 } |
1579 | 1581 |
1580 | 1582 |
1581 } // namespace dart | 1583 } // namespace dart |
OLD | NEW |