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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 static intptr_t ClassIdFromObjectId(intptr_t object_id) { | 48 static intptr_t ClassIdFromObjectId(intptr_t object_id) { |
49 ASSERT(object_id > kClassIdsOffset); | 49 ASSERT(object_id > kClassIdsOffset); |
50 intptr_t class_id = (object_id - kClassIdsOffset); | 50 intptr_t class_id = (object_id - kClassIdsOffset); |
51 return class_id; | 51 return class_id; |
52 } | 52 } |
53 | 53 |
54 | 54 |
55 static intptr_t ObjectIdFromClassId(intptr_t class_id) { | 55 static intptr_t ObjectIdFromClassId(intptr_t class_id) { |
56 ASSERT((class_id > kIllegalCid) && (class_id < kNumPredefinedCids)); | 56 ASSERT((class_id > kIllegalCid) && (class_id < kNumPredefinedCids)); |
| 57 ASSERT(!RawObject::IsTypedDataViewClassId(class_id)); |
57 return (class_id + kClassIdsOffset); | 58 return (class_id + kClassIdsOffset); |
58 } | 59 } |
59 | 60 |
60 | 61 |
61 static RawType* GetType(ObjectStore* object_store, int index) { | 62 static RawType* GetType(ObjectStore* object_store, int index) { |
62 switch (index) { | 63 switch (index) { |
63 case kObjectType: return object_store->object_type(); | 64 case kObjectType: return object_store->object_type(); |
64 case kNullType: return object_store->null_type(); | 65 case kNullType: return object_store->null_type(); |
65 case kDynamicType: return object_store->dynamic_type(); | 66 case kDynamicType: return object_store->dynamic_type(); |
66 case kVoidType: return object_store->void_type(); | 67 case kVoidType: return object_store->void_type(); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 intptr_t tags = ReadIntptrValue(); | 309 intptr_t tags = ReadIntptrValue(); |
309 switch (class_id) { | 310 switch (class_id) { |
310 #define SNAPSHOT_READ(clazz) \ | 311 #define SNAPSHOT_READ(clazz) \ |
311 case clazz::kClassId: { \ | 312 case clazz::kClassId: { \ |
312 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ | 313 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ |
313 break; \ | 314 break; \ |
314 } | 315 } |
315 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) | 316 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) |
316 #undef SNAPSHOT_READ | 317 #undef SNAPSHOT_READ |
317 #define SNAPSHOT_READ(clazz) \ | 318 #define SNAPSHOT_READ(clazz) \ |
318 case kTypedData##clazz##Cid: { \ | 319 case kTypedData##clazz##Cid: \ |
319 obj_ = TypedData::ReadFrom(this, object_id, tags, kind_); \ | 320 |
320 break; \ | 321 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) { |
321 } \ | 322 obj_ = TypedData::ReadFrom(this, object_id, tags, kind_); |
322 case kExternalTypedData##clazz##Cid: { \ | 323 break; |
323 obj_ = ExternalTypedData::ReadFrom(this, object_id, tags, kind_); \ | |
324 break; \ | |
325 } | 324 } |
326 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) | 325 #undef SNAPSHOT_READ |
| 326 #define SNAPSHOT_READ(clazz) \ |
| 327 case kExternalTypedData##clazz##Cid: \ |
| 328 |
| 329 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) { |
| 330 obj_ = ExternalTypedData::ReadFrom(this, object_id, tags, kind_); |
| 331 break; |
| 332 } |
327 #undef SNAPSHOT_READ | 333 #undef SNAPSHOT_READ |
328 default: UNREACHABLE(); break; | 334 default: UNREACHABLE(); break; |
329 } | 335 } |
330 if (kind_ == Snapshot::kFull) { | 336 if (kind_ == Snapshot::kFull) { |
331 obj_.SetCreatedFromSnapshot(); | 337 obj_.SetCreatedFromSnapshot(); |
332 } | 338 } |
333 return obj_.raw(); | 339 return obj_.raw(); |
334 } | 340 } |
335 | 341 |
336 | 342 |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 ASSERT(!cls_.IsNull()); | 802 ASSERT(!cls_.IsNull()); |
797 switch (cls_.id()) { | 803 switch (cls_.id()) { |
798 #define SNAPSHOT_READ(clazz) \ | 804 #define SNAPSHOT_READ(clazz) \ |
799 case clazz::kClassId: { \ | 805 case clazz::kClassId: { \ |
800 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ | 806 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ |
801 break; \ | 807 break; \ |
802 } | 808 } |
803 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) | 809 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) |
804 #undef SNAPSHOT_READ | 810 #undef SNAPSHOT_READ |
805 #define SNAPSHOT_READ(clazz) \ | 811 #define SNAPSHOT_READ(clazz) \ |
806 case kTypedData##clazz##Cid: { \ | 812 case kTypedData##clazz##Cid: \ |
807 obj_ = TypedData::ReadFrom(this, object_id, tags, kind_); \ | 813 |
808 break; \ | 814 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) { |
809 } \ | 815 obj_ = TypedData::ReadFrom(this, object_id, tags, kind_); |
810 case kExternalTypedData##clazz##Cid: { \ | 816 break; |
811 obj_ = ExternalTypedData::ReadFrom(this, object_id, tags, kind_); \ | |
812 break; \ | |
813 } | 817 } |
814 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) | 818 #undef SNAPSHOT_READ |
| 819 #define SNAPSHOT_READ(clazz) \ |
| 820 case kExternalTypedData##clazz##Cid: \ |
| 821 |
| 822 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) { |
| 823 obj_ = ExternalTypedData::ReadFrom(this, object_id, tags, kind_); |
| 824 break; |
| 825 } |
815 #undef SNAPSHOT_READ | 826 #undef SNAPSHOT_READ |
816 default: UNREACHABLE(); break; | 827 default: UNREACHABLE(); break; |
817 } | 828 } |
818 if (kind_ == Snapshot::kFull) { | 829 if (kind_ == Snapshot::kFull) { |
819 obj_.SetCreatedFromSnapshot(); | 830 obj_.SetCreatedFromSnapshot(); |
820 } | 831 } |
821 return obj_.raw(); | 832 return obj_.raw(); |
822 } | 833 } |
823 | 834 |
824 | 835 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 // First check if object can be written as a simple predefined type. | 930 // First check if object can be written as a simple predefined type. |
920 if (CheckAndWritePredefinedObject(raw)) { | 931 if (CheckAndWritePredefinedObject(raw)) { |
921 return; | 932 return; |
922 } | 933 } |
923 | 934 |
924 NoGCScope no_gc; | 935 NoGCScope no_gc; |
925 RawClass* cls = class_table_->At(raw->GetClassId()); | 936 RawClass* cls = class_table_->At(raw->GetClassId()); |
926 intptr_t class_id = cls->ptr()->id_; | 937 intptr_t class_id = cls->ptr()->id_; |
927 ASSERT(class_id == raw->GetClassId()); | 938 ASSERT(class_id == raw->GetClassId()); |
928 if (class_id >= kNumPredefinedCids) { | 939 if (class_id >= kNumPredefinedCids) { |
929 if (Class::IsSignatureClass(cls)) { | 940 WriteInstanceRef(raw, cls); |
930 // We do not allow closure objects in an isolate message. | |
931 set_exception_type(Exceptions::kArgument); | |
932 // TODO(6726): Allocate these constant strings once in the VM isolate. | |
933 set_exception_msg("Illegal argument in isolate message" | |
934 " : (object is a closure)"); | |
935 Isolate::Current()->long_jump_base()->Jump(1, *ErrorHandle()); | |
936 } | |
937 // Object is being referenced, add it to the forward ref list and mark | |
938 // it so that future references to this object in the snapshot will use | |
939 // this object id. Mark it as not having been serialized yet so that we | |
940 // will serialize the object when we go through the forward list. | |
941 intptr_t object_id = MarkObject(raw, kIsNotSerialized); | |
942 | |
943 // Write out the serialization header value for this object. | |
944 WriteInlinedObjectHeader(object_id); | |
945 | |
946 // Indicate this is an instance object. | |
947 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | |
948 | |
949 // Write out the class information for this object. | |
950 WriteObjectImpl(cls); | |
951 | |
952 return; | 941 return; |
953 } | 942 } |
954 if (class_id == kArrayCid) { | 943 if (class_id == kArrayCid) { |
955 // Object is being referenced, add it to the forward ref list and mark | 944 // Object is being referenced, add it to the forward ref list and mark |
956 // it so that future references to this object in the snapshot will use | 945 // it so that future references to this object in the snapshot will use |
957 // this object id. Mark it as not having been serialized yet so that we | 946 // this object id. Mark it as not having been serialized yet so that we |
958 // will serialize the object when we go through the forward list. | 947 // will serialize the object when we go through the forward list. |
959 intptr_t object_id = MarkObject(raw, kIsNotSerialized); | 948 intptr_t object_id = MarkObject(raw, kIsNotSerialized); |
960 | 949 |
961 RawArray* rawarray = reinterpret_cast<RawArray*>(raw); | 950 RawArray* rawarray = reinterpret_cast<RawArray*>(raw); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 #define SNAPSHOT_WRITE(clazz) \ | 989 #define SNAPSHOT_WRITE(clazz) \ |
1001 case clazz::kClassId: { \ | 990 case clazz::kClassId: { \ |
1002 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \ | 991 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \ |
1003 raw_obj->WriteTo(this, object_id, kind_); \ | 992 raw_obj->WriteTo(this, object_id, kind_); \ |
1004 return; \ | 993 return; \ |
1005 } \ | 994 } \ |
1006 | 995 |
1007 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) | 996 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) |
1008 #undef SNAPSHOT_WRITE | 997 #undef SNAPSHOT_WRITE |
1009 #define SNAPSHOT_WRITE(clazz) \ | 998 #define SNAPSHOT_WRITE(clazz) \ |
1010 case kTypedData##clazz##Cid: { \ | 999 case kTypedData##clazz##Cid: \ |
1011 RawTypedData* raw_obj = reinterpret_cast<RawTypedData*>(raw); \ | 1000 |
1012 raw_obj->WriteTo(this, object_id, kind_); \ | 1001 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE) { |
1013 return; \ | 1002 RawTypedData* raw_obj = reinterpret_cast<RawTypedData*>(raw); |
1014 } \ | 1003 raw_obj->WriteTo(this, object_id, kind_); |
1015 case kExternalTypedData##clazz##Cid: { \ | 1004 return; |
1016 RawExternalTypedData* raw_obj = \ | 1005 } |
1017 reinterpret_cast<RawExternalTypedData*>(raw); \ | 1006 #undef SNAPSHOT_WRITE |
1018 raw_obj->WriteTo(this, object_id, kind_); \ | 1007 #define SNAPSHOT_WRITE(clazz) \ |
1019 return; \ | 1008 case kExternalTypedData##clazz##Cid: \ |
1020 } \ | 1009 |
| 1010 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE) { |
| 1011 RawExternalTypedData* raw_obj = |
| 1012 reinterpret_cast<RawExternalTypedData*>(raw); |
| 1013 raw_obj->WriteTo(this, object_id, kind_); |
| 1014 return; |
| 1015 } |
| 1016 #undef SNAPSHOT_WRITE |
| 1017 #define SNAPSHOT_WRITE(clazz) \ |
| 1018 case kTypedData##clazz##ViewCid: \ |
1021 | 1019 |
1022 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE) | 1020 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE) |
| 1021 case kByteDataViewCid: { |
| 1022 WriteInstanceRef(raw, cls); |
| 1023 return; |
| 1024 } |
1023 #undef SNAPSHOT_WRITE | 1025 #undef SNAPSHOT_WRITE |
1024 default: break; | 1026 default: break; |
1025 } | 1027 } |
1026 UNREACHABLE(); | 1028 UNREACHABLE(); |
1027 } | 1029 } |
1028 | 1030 |
1029 | 1031 |
1030 void FullSnapshotWriter::WriteFullSnapshot() { | 1032 void FullSnapshotWriter::WriteFullSnapshot() { |
1031 Isolate* isolate = Isolate::Current(); | 1033 Isolate* isolate = Isolate::Current(); |
1032 ASSERT(isolate != NULL); | 1034 ASSERT(isolate != NULL); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 // ...... | 1193 // ...... |
1192 NoGCScope no_gc; | 1194 NoGCScope no_gc; |
1193 uword tags = raw->ptr()->tags_; | 1195 uword tags = raw->ptr()->tags_; |
1194 ASSERT(SerializedHeaderTag::decode(tags) == kObjectId); | 1196 ASSERT(SerializedHeaderTag::decode(tags) == kObjectId); |
1195 intptr_t object_id = SerializedHeaderData::decode(tags); | 1197 intptr_t object_id = SerializedHeaderData::decode(tags); |
1196 tags = forward_list_[object_id - kMaxPredefinedObjectIds]->tags(); | 1198 tags = forward_list_[object_id - kMaxPredefinedObjectIds]->tags(); |
1197 RawClass* cls = class_table_->At(RawObject::ClassIdTag::decode(tags)); | 1199 RawClass* cls = class_table_->At(RawObject::ClassIdTag::decode(tags)); |
1198 intptr_t class_id = cls->ptr()->id_; | 1200 intptr_t class_id = cls->ptr()->id_; |
1199 | 1201 |
1200 if (class_id >= kNumPredefinedCids) { | 1202 if (class_id >= kNumPredefinedCids) { |
1201 if (Class::IsSignatureClass(cls)) { | 1203 WriteInstance(object_id, raw, cls, tags); |
1202 // We do not allow closure objects in an isolate message. | |
1203 set_exception_type(Exceptions::kArgument); | |
1204 // TODO(6726): Allocate these constant strings once in the VM isolate. | |
1205 set_exception_msg("Illegal argument in isolate message" | |
1206 " : (object is a closure)"); | |
1207 Isolate::Current()->long_jump_base()->Jump(1, *ErrorHandle()); | |
1208 } | |
1209 if (cls->ptr()->num_native_fields_ != 0) { | |
1210 // We do not allow objects with native fields in an isolate message. | |
1211 set_exception_type(Exceptions::kArgument); | |
1212 // TODO(6726): Allocate these constant strings once in the VM isolate. | |
1213 set_exception_msg("Illegal argument in isolate message" | |
1214 " : (object extends NativeWrapper)"); | |
1215 | |
1216 Isolate::Current()->long_jump_base()->Jump(1, *ErrorHandle()); | |
1217 } | |
1218 // Object is regular dart instance. | |
1219 intptr_t instance_size = | |
1220 cls->ptr()->instance_size_in_words_ << kWordSizeLog2; | |
1221 ASSERT(instance_size != 0); | |
1222 | |
1223 // Write out the serialization header value for this object. | |
1224 WriteInlinedObjectHeader(object_id); | |
1225 | |
1226 // Indicate this is an instance object. | |
1227 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); | |
1228 | |
1229 // Write out the tags. | |
1230 WriteIntptrValue(tags); | |
1231 | |
1232 // Write out the class information for this object. | |
1233 WriteObjectImpl(cls); | |
1234 | |
1235 // Write out all the fields for the object. | |
1236 intptr_t offset = Object::InstanceSize(); | |
1237 while (offset < instance_size) { | |
1238 WriteObjectRef(*reinterpret_cast<RawObject**>( | |
1239 reinterpret_cast<uword>(raw->ptr()) + offset)); | |
1240 offset += kWordSize; | |
1241 } | |
1242 return; | 1204 return; |
1243 } | 1205 } |
1244 switch (class_id) { | 1206 switch (class_id) { |
1245 #define SNAPSHOT_WRITE(clazz) \ | 1207 #define SNAPSHOT_WRITE(clazz) \ |
1246 case clazz::kClassId: { \ | 1208 case clazz::kClassId: { \ |
1247 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \ | 1209 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \ |
1248 raw_obj->WriteTo(this, object_id, kind_); \ | 1210 raw_obj->WriteTo(this, object_id, kind_); \ |
1249 return; \ | 1211 return; \ |
1250 } \ | 1212 } \ |
1251 | 1213 |
1252 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) | 1214 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) |
1253 #undef SNAPSHOT_WRITE | 1215 #undef SNAPSHOT_WRITE |
1254 #define SNAPSHOT_WRITE(clazz) \ | 1216 #define SNAPSHOT_WRITE(clazz) \ |
1255 case kTypedData##clazz##Cid: { \ | 1217 case kTypedData##clazz##Cid: \ |
1256 RawTypedData* raw_obj = reinterpret_cast<RawTypedData*>(raw); \ | 1218 |
1257 raw_obj->WriteTo(this, object_id, kind_); \ | 1219 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE) { |
1258 return; \ | 1220 RawTypedData* raw_obj = reinterpret_cast<RawTypedData*>(raw); |
1259 } \ | 1221 raw_obj->WriteTo(this, object_id, kind_); |
1260 case kExternalTypedData##clazz##Cid: { \ | 1222 return; |
1261 RawExternalTypedData* raw_obj = \ | 1223 } |
1262 reinterpret_cast<RawExternalTypedData*>(raw); \ | 1224 #undef SNAPSHOT_WRITE |
1263 raw_obj->WriteTo(this, object_id, kind_); \ | 1225 #define SNAPSHOT_WRITE(clazz) \ |
1264 return; \ | 1226 case kExternalTypedData##clazz##Cid: \ |
1265 } \ | 1227 |
| 1228 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE) { |
| 1229 RawExternalTypedData* raw_obj = |
| 1230 reinterpret_cast<RawExternalTypedData*>(raw); |
| 1231 raw_obj->WriteTo(this, object_id, kind_); |
| 1232 return; |
| 1233 } |
| 1234 #undef SNAPSHOT_WRITE |
| 1235 #define SNAPSHOT_WRITE(clazz) \ |
| 1236 case kTypedData##clazz##ViewCid: \ |
1266 | 1237 |
1267 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE) | 1238 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE) |
| 1239 case kByteDataViewCid: { |
| 1240 WriteInstance(object_id, raw, cls, tags); |
| 1241 return; |
| 1242 } |
1268 #undef SNAPSHOT_WRITE | 1243 #undef SNAPSHOT_WRITE |
1269 default: break; | 1244 default: break; |
1270 } | 1245 } |
1271 UNREACHABLE(); | 1246 UNREACHABLE(); |
1272 } | 1247 } |
1273 | 1248 |
1274 | 1249 |
1275 void SnapshotWriter::WriteForwardedObjects() { | 1250 void SnapshotWriter::WriteForwardedObjects() { |
1276 // Write out all objects that were added to the forward list and have | 1251 // Write out all objects that were added to the forward list and have |
1277 // not been serialized yet. These would typically be fields of instance | 1252 // not been serialized yet. These would typically be fields of instance |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 // Write out the type arguments. | 1312 // Write out the type arguments. |
1338 WriteObjectImpl(type_arguments); | 1313 WriteObjectImpl(type_arguments); |
1339 | 1314 |
1340 // Write out the individual object ids. | 1315 // Write out the individual object ids. |
1341 for (intptr_t i = 0; i < len; i++) { | 1316 for (intptr_t i = 0; i < len; i++) { |
1342 WriteObjectRef(data[i]); | 1317 WriteObjectRef(data[i]); |
1343 } | 1318 } |
1344 } | 1319 } |
1345 | 1320 |
1346 | 1321 |
| 1322 void SnapshotWriter::CheckIfSerializable(RawClass* cls) { |
| 1323 if (Class::IsSignatureClass(cls)) { |
| 1324 // We do not allow closure objects in an isolate message. |
| 1325 set_exception_type(Exceptions::kArgument); |
| 1326 // TODO(6726): Allocate these constant strings once in the VM isolate. |
| 1327 set_exception_msg("Illegal argument in isolate message" |
| 1328 " : (object is a closure)"); |
| 1329 Isolate::Current()->long_jump_base()->Jump(1, *ErrorHandle()); |
| 1330 } |
| 1331 if (cls->ptr()->num_native_fields_ != 0) { |
| 1332 // We do not allow objects with native fields in an isolate message. |
| 1333 set_exception_type(Exceptions::kArgument); |
| 1334 // TODO(6726): Allocate these constant strings once in the VM isolate. |
| 1335 set_exception_msg("Illegal argument in isolate message" |
| 1336 " : (object extends NativeWrapper)"); |
| 1337 |
| 1338 Isolate::Current()->long_jump_base()->Jump(1, *ErrorHandle()); |
| 1339 } |
| 1340 } |
| 1341 |
| 1342 |
| 1343 void SnapshotWriter::WriteInstance(intptr_t object_id, |
| 1344 RawObject* raw, |
| 1345 RawClass* cls, |
| 1346 intptr_t tags) { |
| 1347 // First check if object is a closure or has native fields. |
| 1348 CheckIfSerializable(cls); |
| 1349 |
| 1350 // Object is regular dart instance. |
| 1351 intptr_t instance_size = |
| 1352 cls->ptr()->instance_size_in_words_ << kWordSizeLog2; |
| 1353 ASSERT(instance_size != 0); |
| 1354 |
| 1355 // Write out the serialization header value for this object. |
| 1356 WriteInlinedObjectHeader(object_id); |
| 1357 |
| 1358 // Indicate this is an instance object. |
| 1359 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1360 |
| 1361 // Write out the tags. |
| 1362 WriteIntptrValue(tags); |
| 1363 |
| 1364 // Write out the class information for this object. |
| 1365 WriteObjectImpl(cls); |
| 1366 |
| 1367 // Write out all the fields for the object. |
| 1368 intptr_t offset = Object::InstanceSize(); |
| 1369 while (offset < instance_size) { |
| 1370 WriteObjectRef(*reinterpret_cast<RawObject**>( |
| 1371 reinterpret_cast<uword>(raw->ptr()) + offset)); |
| 1372 offset += kWordSize; |
| 1373 } |
| 1374 return; |
| 1375 } |
| 1376 |
| 1377 |
| 1378 void SnapshotWriter::WriteInstanceRef(RawObject* raw, RawClass* cls) { |
| 1379 // First check if object is a closure or has native fields. |
| 1380 CheckIfSerializable(cls); |
| 1381 |
| 1382 // Object is being referenced, add it to the forward ref list and mark |
| 1383 // it so that future references to this object in the snapshot will use |
| 1384 // this object id. Mark it as not having been serialized yet so that we |
| 1385 // will serialize the object when we go through the forward list. |
| 1386 intptr_t object_id = MarkObject(raw, kIsNotSerialized); |
| 1387 |
| 1388 // Write out the serialization header value for this object. |
| 1389 WriteInlinedObjectHeader(object_id); |
| 1390 |
| 1391 // Indicate this is an instance object. |
| 1392 WriteIntptrValue(SerializedHeaderData::encode(kInstanceObjectId)); |
| 1393 |
| 1394 // Write out the class information for this object. |
| 1395 WriteObjectImpl(cls); |
| 1396 } |
| 1397 |
| 1398 |
1347 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, | 1399 void SnapshotWriter::ThrowException(Exceptions::ExceptionType type, |
1348 const char* msg) { | 1400 const char* msg) { |
1349 Isolate::Current()->object_store()->clear_sticky_error(); | 1401 Isolate::Current()->object_store()->clear_sticky_error(); |
1350 UnmarkAll(); | 1402 UnmarkAll(); |
1351 const String& msg_obj = String::Handle(String::New(msg)); | 1403 const String& msg_obj = String::Handle(String::New(msg)); |
1352 const Array& args = Array::Handle(Array::New(1)); | 1404 const Array& args = Array::Handle(Array::New(1)); |
1353 args.SetAt(0, msg_obj); | 1405 args.SetAt(0, msg_obj); |
1354 Exceptions::ThrowByType(type, args); | 1406 Exceptions::ThrowByType(type, args); |
1355 UNREACHABLE(); | 1407 UNREACHABLE(); |
1356 } | 1408 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 UnmarkAll(); | 1466 UnmarkAll(); |
1415 isolate->set_long_jump_base(base); | 1467 isolate->set_long_jump_base(base); |
1416 } else { | 1468 } else { |
1417 isolate->set_long_jump_base(base); | 1469 isolate->set_long_jump_base(base); |
1418 ThrowException(exception_type(), exception_msg()); | 1470 ThrowException(exception_type(), exception_msg()); |
1419 } | 1471 } |
1420 } | 1472 } |
1421 | 1473 |
1422 | 1474 |
1423 } // namespace dart | 1475 } // namespace dart |
OLD | NEW |