| 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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 } else { | 783 } else { |
| 784 *result ^= Object::Allocate(cls_.id(), | 784 *result ^= Object::Allocate(cls_.id(), |
| 785 instance_size, | 785 instance_size, |
| 786 HEAP_SPACE(kind_)); | 786 HEAP_SPACE(kind_)); |
| 787 } | 787 } |
| 788 } else { | 788 } else { |
| 789 cls_ ^= ReadObjectImpl(); | 789 cls_ ^= ReadObjectImpl(); |
| 790 ASSERT(!cls_.IsNull()); | 790 ASSERT(!cls_.IsNull()); |
| 791 instance_size = cls_.instance_size(); | 791 instance_size = cls_.instance_size(); |
| 792 } | 792 } |
| 793 intptr_t offset = Object::InstanceSize(); | 793 intptr_t next_field_offset = cls_.next_field_offset(); |
| 794 intptr_t type_argument_field_offset = cls_.type_arguments_field_offset(); |
| 795 ASSERT(next_field_offset > 0); |
| 796 intptr_t offset = Instance::NextFieldOffset(); |
| 794 intptr_t result_cid = result->GetClassId(); | 797 intptr_t result_cid = result->GetClassId(); |
| 795 while (offset < instance_size) { | 798 while (offset < next_field_offset) { |
| 796 obj_ = ReadObjectRef(); | 799 obj_ = ReadObjectRef(); |
| 797 result->SetFieldAtOffset(offset, obj_); | 800 result->SetFieldAtOffset(offset, obj_); |
| 798 if (kind_ == Snapshot::kMessage) { | 801 if ((offset != type_argument_field_offset) && |
| 802 (kind_ == Snapshot::kMessage)) { |
| 799 // TODO(fschneider): Consider hoisting these lookups out of the loop. | 803 // TODO(fschneider): Consider hoisting these lookups out of the loop. |
| 800 // This would involve creating a handle, since cls_ can't be reused | 804 // This would involve creating a handle, since cls_ can't be reused |
| 801 // across the call to ReadObjectRef. | 805 // across the call to ReadObjectRef. |
| 802 cls_ = isolate()->class_table()->At(result_cid); | 806 cls_ = isolate()->class_table()->At(result_cid); |
| 803 array_ = cls_.OffsetToFieldMap(); | 807 array_ = cls_.OffsetToFieldMap(); |
| 804 field_ ^= array_.At(offset >> kWordSizeLog2); | 808 field_ ^= array_.At(offset >> kWordSizeLog2); |
| 805 // Entries can be null because offset can be outside of instance fields | 809 ASSERT(!field_.IsNull()); |
| 806 // due to rounded allocation size. | 810 ASSERT(field_.Offset() == offset); |
| 807 if (!field_.IsNull()) { | 811 field_.UpdateGuardedCidAndLength(obj_); |
| 808 ASSERT(field_.Offset() == offset); | |
| 809 field_.UpdateGuardedCidAndLength(obj_); | |
| 810 } | |
| 811 } | 812 } |
| 812 // TODO(fschneider): Verify the guarded cid and length for other kinds of | 813 // TODO(fschneider): Verify the guarded cid and length for other kinds of |
| 813 // snapshot (kFull, kScript) with asserts. | 814 // snapshot (kFull, kScript) with asserts. |
| 814 offset += kWordSize; | 815 offset += kWordSize; |
| 815 } | 816 } |
| 816 if (kind_ == Snapshot::kFull) { | 817 if (kind_ == Snapshot::kFull) { |
| 818 // We create an uninitialized object in the case of full snapshots, so |
| 819 // we need to initialize any remaining padding area with the Null object. |
| 820 while (offset < instance_size) { |
| 821 result->SetFieldAtOffset(offset, Object::null_object()); |
| 822 offset += kWordSize; |
| 823 } |
| 817 result->SetCreatedFromSnapshot(); | 824 result->SetCreatedFromSnapshot(); |
| 818 } else if (result->IsCanonical()) { | 825 } else if (result->IsCanonical()) { |
| 819 *result = result->CheckAndCanonicalize(NULL); | 826 *result = result->CheckAndCanonicalize(NULL); |
| 820 ASSERT(!result->IsNull()); | 827 ASSERT(!result->IsNull()); |
| 821 } | 828 } |
| 822 return result->raw(); | 829 return result->raw(); |
| 823 } | 830 } |
| 824 ASSERT((class_header & kSmiTagMask) != kSmiTag); | 831 ASSERT((class_header & kSmiTagMask) != kSmiTag); |
| 825 cls_ = LookupInternalClass(class_header); | 832 cls_ = LookupInternalClass(class_header); |
| 826 ASSERT(!cls_.IsNull()); | 833 ASSERT(!cls_.IsNull()); |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 | 1387 |
| 1381 | 1388 |
| 1382 void SnapshotWriter::WriteInstance(intptr_t object_id, | 1389 void SnapshotWriter::WriteInstance(intptr_t object_id, |
| 1383 RawObject* raw, | 1390 RawObject* raw, |
| 1384 RawClass* cls, | 1391 RawClass* cls, |
| 1385 intptr_t tags) { | 1392 intptr_t tags) { |
| 1386 // First check if object is a closure or has native fields. | 1393 // First check if object is a closure or has native fields. |
| 1387 CheckIfSerializable(cls); | 1394 CheckIfSerializable(cls); |
| 1388 | 1395 |
| 1389 // Object is regular dart instance. | 1396 // Object is regular dart instance. |
| 1390 intptr_t instance_size = | 1397 intptr_t next_field_offset = |
| 1391 cls->ptr()->instance_size_in_words_ << kWordSizeLog2; | 1398 cls->ptr()->next_field_offset_in_words_ << kWordSizeLog2; |
| 1392 ASSERT(instance_size != 0); | 1399 ASSERT(next_field_offset > 0); |
| 1393 | 1400 |
| 1394 // Write out the serialization header value for this object. | 1401 // Write out the serialization header value for this object. |
| 1395 WriteInlinedObjectHeader(object_id); | 1402 WriteInlinedObjectHeader(object_id); |
| 1396 | 1403 |
| 1397 // Indicate this is an instance object. | 1404 // Indicate this is an instance object. |
| 1398 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | 1405 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1399 | 1406 |
| 1400 // Write out the tags. | 1407 // Write out the tags. |
| 1401 WriteIntptrValue(tags); | 1408 WriteIntptrValue(tags); |
| 1402 | 1409 |
| 1403 // Write out the class information for this object. | 1410 // Write out the class information for this object. |
| 1404 WriteObjectImpl(cls); | 1411 WriteObjectImpl(cls); |
| 1405 | 1412 |
| 1406 // Write out all the fields for the object. | 1413 // Write out all the fields for the object. |
| 1407 intptr_t offset = Object::InstanceSize(); | 1414 intptr_t offset = Instance::NextFieldOffset(); |
| 1408 while (offset < instance_size) { | 1415 while (offset < next_field_offset) { |
| 1409 WriteObjectRef(*reinterpret_cast<RawObject**>( | 1416 WriteObjectRef(*reinterpret_cast<RawObject**>( |
| 1410 reinterpret_cast<uword>(raw->ptr()) + offset)); | 1417 reinterpret_cast<uword>(raw->ptr()) + offset)); |
| 1411 offset += kWordSize; | 1418 offset += kWordSize; |
| 1412 } | 1419 } |
| 1413 return; | 1420 return; |
| 1414 } | 1421 } |
| 1415 | 1422 |
| 1416 | 1423 |
| 1417 void SnapshotWriter::WriteInstanceRef(RawObject* raw, RawClass* cls) { | 1424 void SnapshotWriter::WriteInstanceRef(RawObject* raw, RawClass* cls) { |
| 1418 // First check if object is a closure or has native fields. | 1425 // First check if object is a closure or has native fields. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1505 UnmarkAll(); | 1512 UnmarkAll(); |
| 1506 isolate->set_long_jump_base(base); | 1513 isolate->set_long_jump_base(base); |
| 1507 } else { | 1514 } else { |
| 1508 isolate->set_long_jump_base(base); | 1515 isolate->set_long_jump_base(base); |
| 1509 ThrowException(exception_type(), exception_msg()); | 1516 ThrowException(exception_type(), exception_msg()); |
| 1510 } | 1517 } |
| 1511 } | 1518 } |
| 1512 | 1519 |
| 1513 | 1520 |
| 1514 } // namespace dart | 1521 } // namespace dart |
| OLD | NEW |