| 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/object.h" | 5 #include "vm/object.h" |
| 6 #include "vm/object_store.h" | 6 #include "vm/object_store.h" |
| 7 #include "vm/snapshot.h" | 7 #include "vm/snapshot.h" |
| 8 #include "vm/stub_code.h" | 8 #include "vm/stub_code.h" |
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
| 10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 #define NEW_OBJECT(type) \ | 14 #define NEW_OBJECT(type) \ |
| 15 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) | 15 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) |
| 16 | 16 |
| 17 #define NEW_OBJECT_WITH_LEN(type, len) \ | 17 #define NEW_OBJECT_WITH_LEN(type, len) \ |
| 18 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) | 18 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) |
| 19 | 19 |
| 20 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ | 20 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ |
| 21 ((kind == Snapshot::kFull) ? \ | 21 ((kind == Snapshot::kFull) ? \ |
| 22 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) | 22 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) |
| 23 | 23 |
| 24 #define OFFSET_OF_FROM(obj) \ |
| 25 obj.raw()->from() - reinterpret_cast<RawObject**>(obj.raw()->ptr()) |
| 24 | 26 |
| 25 RawClass* Class::ReadFrom(SnapshotReader* reader, | 27 RawClass* Class::ReadFrom(SnapshotReader* reader, |
| 26 intptr_t object_id, | 28 intptr_t object_id, |
| 27 intptr_t tags, | 29 intptr_t tags, |
| 28 Snapshot::Kind kind) { | 30 Snapshot::Kind kind) { |
| 29 ASSERT(reader != NULL); | 31 ASSERT(reader != NULL); |
| 30 | 32 |
| 31 Class& cls = Class::ZoneHandle(reader->zone(), Class::null()); | 33 Class& cls = Class::ZoneHandle(reader->zone(), Class::null()); |
| 32 if ((kind == Snapshot::kFull) || | 34 if ((kind == Snapshot::kFull) || |
| 33 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { | 35 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 60 cls.set_num_type_arguments(reader->Read<int16_t>()); | 62 cls.set_num_type_arguments(reader->Read<int16_t>()); |
| 61 cls.set_num_own_type_arguments(reader->Read<int16_t>()); | 63 cls.set_num_own_type_arguments(reader->Read<int16_t>()); |
| 62 cls.set_num_native_fields(reader->Read<uint16_t>()); | 64 cls.set_num_native_fields(reader->Read<uint16_t>()); |
| 63 cls.set_token_pos(reader->Read<int32_t>()); | 65 cls.set_token_pos(reader->Read<int32_t>()); |
| 64 cls.set_state_bits(reader->Read<uint16_t>()); | 66 cls.set_state_bits(reader->Read<uint16_t>()); |
| 65 | 67 |
| 66 // Set all the object fields. | 68 // Set all the object fields. |
| 67 // TODO(5411462): Need to assert No GC can happen here, even though | 69 // TODO(5411462): Need to assert No GC can happen here, even though |
| 68 // allocations may happen. | 70 // allocations may happen. |
| 69 intptr_t num_flds = (cls.raw()->to() - cls.raw()->from()); | 71 intptr_t num_flds = (cls.raw()->to() - cls.raw()->from()); |
| 72 intptr_t from_offset = OFFSET_OF_FROM(cls); |
| 70 for (intptr_t i = 0; i <= num_flds; i++) { | 73 for (intptr_t i = 0; i <= num_flds; i++) { |
| 71 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 74 (*reader->PassiveObjectHandle()) = |
| 72 cls.StorePointer((cls.raw()->from() + i), | 75 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); |
| 76 cls.StorePointer((cls.raw()->from() + i), |
| 73 reader->PassiveObjectHandle()->raw()); | 77 reader->PassiveObjectHandle()->raw()); |
| 74 } | 78 } |
| 75 } else { | 79 } else { |
| 76 cls ^= reader->ReadClassId(object_id); | 80 cls ^= reader->ReadClassId(object_id); |
| 77 } | 81 } |
| 78 return cls.raw(); | 82 return cls.raw(); |
| 79 } | 83 } |
| 80 | 84 |
| 81 | 85 |
| 82 void RawClass::WriteTo(SnapshotWriter* writer, | 86 void RawClass::WriteTo(SnapshotWriter* writer, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 202 |
| 199 | 203 |
| 200 RawType* Type::ReadFrom(SnapshotReader* reader, | 204 RawType* Type::ReadFrom(SnapshotReader* reader, |
| 201 intptr_t object_id, | 205 intptr_t object_id, |
| 202 intptr_t tags, | 206 intptr_t tags, |
| 203 Snapshot::Kind kind) { | 207 Snapshot::Kind kind) { |
| 204 ASSERT(reader != NULL); | 208 ASSERT(reader != NULL); |
| 205 | 209 |
| 206 // Allocate type object. | 210 // Allocate type object. |
| 207 Type& type = Type::ZoneHandle(reader->zone(), NEW_OBJECT(Type)); | 211 Type& type = Type::ZoneHandle(reader->zone(), NEW_OBJECT(Type)); |
| 208 reader->AddBackRef(object_id, &type, kIsDeserialized); | 212 bool is_canonical = RawObject::IsCanonical(tags); |
| 213 bool defer_canonicalization = is_canonical && (kind != Snapshot::kFull); |
| 214 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization); |
| 209 | 215 |
| 210 // Set all non object fields. | 216 // Set all non object fields. |
| 211 type.set_token_pos(reader->Read<int32_t>()); | 217 type.set_token_pos(reader->Read<int32_t>()); |
| 212 type.set_type_state(reader->Read<int8_t>()); | 218 type.set_type_state(reader->Read<int8_t>()); |
| 213 | 219 |
| 214 // Set all the object fields. | 220 // Set all the object fields. |
| 215 // TODO(5411462): Need to assert No GC can happen here, even though | 221 // TODO(5411462): Need to assert No GC can happen here, even though |
| 216 // allocations may happen. | 222 // allocations may happen. |
| 217 intptr_t num_flds = (type.raw()->to() - type.raw()->from()); | 223 intptr_t num_flds = (type.raw()->to() - type.raw()->from()); |
| 224 intptr_t from_offset = OFFSET_OF_FROM(type); |
| 218 for (intptr_t i = 0; i <= num_flds; i++) { | 225 for (intptr_t i = 0; i <= num_flds; i++) { |
| 219 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsInlinedObject); | 226 (*reader->PassiveObjectHandle()) = |
| 227 reader->ReadObjectImpl(kAsInlinedObject, object_id, (i + from_offset)); |
| 220 type.StorePointer((type.raw()->from() + i), | 228 type.StorePointer((type.raw()->from() + i), |
| 221 reader->PassiveObjectHandle()->raw()); | 229 reader->PassiveObjectHandle()->raw()); |
| 222 } | 230 } |
| 223 | 231 |
| 224 // If object needs to be a canonical object, Canonicalize it. | 232 // Set the object tags. |
| 225 // When reading a full snapshot we don't need to canonicalize the object | |
| 226 // as it would already be a canonical object. | |
| 227 // When reading a script snapshot we need to canonicalize only those object | |
| 228 // references that are objects from the core library (loaded from a | |
| 229 // full snapshot). Objects that are only in the script need not be | |
| 230 // canonicalized as they are already canonical. | |
| 231 // When reading a message snapshot we always have to canonicalize the object. | |
| 232 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags) && | |
| 233 (RawObject::IsCreatedFromSnapshot(tags) || | |
| 234 (kind == Snapshot::kMessage))) { | |
| 235 type ^= type.Canonicalize(); | |
| 236 } | |
| 237 | |
| 238 // Set the object tags (This is done after 'Canonicalize', which | |
| 239 // does not canonicalize a type already marked as canonical). | |
| 240 type.set_tags(tags); | 233 type.set_tags(tags); |
| 241 | 234 |
| 242 return type.raw(); | 235 return type.raw(); |
| 243 } | 236 } |
| 244 | 237 |
| 245 | 238 |
| 246 void RawType::WriteTo(SnapshotWriter* writer, | 239 void RawType::WriteTo(SnapshotWriter* writer, |
| 247 intptr_t object_id, | 240 intptr_t object_id, |
| 248 Snapshot::Kind kind) { | 241 Snapshot::Kind kind) { |
| 249 ASSERT(writer != NULL); | 242 ASSERT(writer != NULL); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 reader->zone(), NEW_OBJECT(TypeRef)); | 275 reader->zone(), NEW_OBJECT(TypeRef)); |
| 283 reader->AddBackRef(object_id, &type_ref, kIsDeserialized); | 276 reader->AddBackRef(object_id, &type_ref, kIsDeserialized); |
| 284 | 277 |
| 285 // Set the object tags. | 278 // Set the object tags. |
| 286 type_ref.set_tags(tags); | 279 type_ref.set_tags(tags); |
| 287 | 280 |
| 288 // Set all the object fields. | 281 // Set all the object fields. |
| 289 // TODO(5411462): Need to assert No GC can happen here, even though | 282 // TODO(5411462): Need to assert No GC can happen here, even though |
| 290 // allocations may happen. | 283 // allocations may happen. |
| 291 intptr_t num_flds = (type_ref.raw()->to() - type_ref.raw()->from()); | 284 intptr_t num_flds = (type_ref.raw()->to() - type_ref.raw()->from()); |
| 285 intptr_t from_offset = OFFSET_OF_FROM(type_ref); |
| 292 for (intptr_t i = 0; i <= num_flds; i++) { | 286 for (intptr_t i = 0; i <= num_flds; i++) { |
| 293 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 287 (*reader->PassiveObjectHandle()) = |
| 288 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); |
| 294 type_ref.StorePointer((type_ref.raw()->from() + i), | 289 type_ref.StorePointer((type_ref.raw()->from() + i), |
| 295 reader->PassiveObjectHandle()->raw()); | 290 reader->PassiveObjectHandle()->raw()); |
| 296 } | 291 } |
| 297 | 292 |
| 298 return type_ref.raw(); | 293 return type_ref.raw(); |
| 299 } | 294 } |
| 300 | 295 |
| 301 | 296 |
| 302 void RawTypeRef::WriteTo(SnapshotWriter* writer, | 297 void RawTypeRef::WriteTo(SnapshotWriter* writer, |
| 303 intptr_t object_id, | 298 intptr_t object_id, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 334 // Set all non object fields. | 329 // Set all non object fields. |
| 335 type_parameter.set_token_pos(reader->Read<int32_t>()); | 330 type_parameter.set_token_pos(reader->Read<int32_t>()); |
| 336 type_parameter.set_index(reader->Read<int16_t>()); | 331 type_parameter.set_index(reader->Read<int16_t>()); |
| 337 type_parameter.set_type_state(reader->Read<int8_t>()); | 332 type_parameter.set_type_state(reader->Read<int8_t>()); |
| 338 | 333 |
| 339 // Set all the object fields. | 334 // Set all the object fields. |
| 340 // TODO(5411462): Need to assert No GC can happen here, even though | 335 // TODO(5411462): Need to assert No GC can happen here, even though |
| 341 // allocations may happen. | 336 // allocations may happen. |
| 342 intptr_t num_flds = (type_parameter.raw()->to() - | 337 intptr_t num_flds = (type_parameter.raw()->to() - |
| 343 type_parameter.raw()->from()); | 338 type_parameter.raw()->from()); |
| 339 intptr_t from_offset = OFFSET_OF_FROM(type_parameter); |
| 344 for (intptr_t i = 0; i <= num_flds; i++) { | 340 for (intptr_t i = 0; i <= num_flds; i++) { |
| 345 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 341 (*reader->PassiveObjectHandle()) = |
| 342 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); |
| 346 type_parameter.StorePointer((type_parameter.raw()->from() + i), | 343 type_parameter.StorePointer((type_parameter.raw()->from() + i), |
| 347 reader->PassiveObjectHandle()->raw()); | 344 reader->PassiveObjectHandle()->raw()); |
| 348 } | 345 } |
| 349 | 346 |
| 350 return type_parameter.raw(); | 347 return type_parameter.raw(); |
| 351 } | 348 } |
| 352 | 349 |
| 353 | 350 |
| 354 void RawTypeParameter::WriteTo(SnapshotWriter* writer, | 351 void RawTypeParameter::WriteTo(SnapshotWriter* writer, |
| 355 intptr_t object_id, | 352 intptr_t object_id, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 reader->AddBackRef(object_id, &bounded_type, kIsDeserialized); | 386 reader->AddBackRef(object_id, &bounded_type, kIsDeserialized); |
| 390 | 387 |
| 391 // Set the object tags. | 388 // Set the object tags. |
| 392 bounded_type.set_tags(tags); | 389 bounded_type.set_tags(tags); |
| 393 | 390 |
| 394 // Set all the object fields. | 391 // Set all the object fields. |
| 395 // TODO(5411462): Need to assert No GC can happen here, even though | 392 // TODO(5411462): Need to assert No GC can happen here, even though |
| 396 // allocations may happen. | 393 // allocations may happen. |
| 397 intptr_t num_flds = (bounded_type.raw()->to() - | 394 intptr_t num_flds = (bounded_type.raw()->to() - |
| 398 bounded_type.raw()->from()); | 395 bounded_type.raw()->from()); |
| 396 intptr_t from_offset = OFFSET_OF_FROM(bounded_type); |
| 399 for (intptr_t i = 0; i <= num_flds; i++) { | 397 for (intptr_t i = 0; i <= num_flds; i++) { |
| 400 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 398 (*reader->PassiveObjectHandle()) = |
| 399 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); |
| 401 bounded_type.StorePointer((bounded_type.raw()->from() + i), | 400 bounded_type.StorePointer((bounded_type.raw()->from() + i), |
| 402 reader->PassiveObjectHandle()->raw()); | 401 reader->PassiveObjectHandle()->raw()); |
| 403 } | 402 } |
| 404 | 403 |
| 405 return bounded_type.raw(); | 404 return bounded_type.raw(); |
| 406 } | 405 } |
| 407 | 406 |
| 408 | 407 |
| 409 void RawBoundedType::WriteTo(SnapshotWriter* writer, | 408 void RawBoundedType::WriteTo(SnapshotWriter* writer, |
| 410 intptr_t object_id, | 409 intptr_t object_id, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 intptr_t object_id, | 443 intptr_t object_id, |
| 445 intptr_t tags, | 444 intptr_t tags, |
| 446 Snapshot::Kind kind) { | 445 Snapshot::Kind kind) { |
| 447 ASSERT(reader != NULL); | 446 ASSERT(reader != NULL); |
| 448 | 447 |
| 449 // Read the length so that we can determine instance size to allocate. | 448 // Read the length so that we can determine instance size to allocate. |
| 450 intptr_t len = reader->ReadSmiValue(); | 449 intptr_t len = reader->ReadSmiValue(); |
| 451 | 450 |
| 452 TypeArguments& type_arguments = TypeArguments::ZoneHandle( | 451 TypeArguments& type_arguments = TypeArguments::ZoneHandle( |
| 453 reader->zone(), NEW_OBJECT_WITH_LEN_SPACE(TypeArguments, len, kind)); | 452 reader->zone(), NEW_OBJECT_WITH_LEN_SPACE(TypeArguments, len, kind)); |
| 454 reader->AddBackRef(object_id, &type_arguments, kIsDeserialized); | 453 bool is_canonical = RawObject::IsCanonical(tags); |
| 454 bool defer_canonicalization = is_canonical && (kind != Snapshot::kFull); |
| 455 reader->AddBackRef(object_id, |
| 456 &type_arguments, |
| 457 kIsDeserialized, |
| 458 defer_canonicalization); |
| 455 | 459 |
| 456 // Set the instantiations field, which is only read from a full snapshot. | 460 // Set the instantiations field, which is only read from a full snapshot. |
| 457 if (kind == Snapshot::kFull) { | 461 if (kind == Snapshot::kFull) { |
| 458 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); | 462 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); |
| 459 type_arguments.set_instantiations(*(reader->ArrayHandle())); | 463 type_arguments.set_instantiations(*(reader->ArrayHandle())); |
| 460 } else { | 464 } else { |
| 461 type_arguments.set_instantiations(Object::zero_array()); | 465 type_arguments.set_instantiations(Object::zero_array()); |
| 462 } | 466 } |
| 463 | 467 |
| 464 // Now set all the type fields. | 468 // Now set all the type fields. |
| 469 intptr_t offset = type_arguments.TypeAddr(0) - |
| 470 reinterpret_cast<RawAbstractType**>(type_arguments.raw()->ptr()); |
| 465 for (intptr_t i = 0; i < len; i++) { | 471 for (intptr_t i = 0; i < len; i++) { |
| 466 *reader->TypeHandle() ^= reader->ReadObjectImpl(kAsInlinedObject); | 472 *reader->TypeHandle() ^= |
| 473 reader->ReadObjectImpl(kAsInlinedObject, object_id, (i + offset)); |
| 467 type_arguments.SetTypeAt(i, *reader->TypeHandle()); | 474 type_arguments.SetTypeAt(i, *reader->TypeHandle()); |
| 468 } | 475 } |
| 469 | 476 |
| 470 // If object needs to be a canonical object, Canonicalize it. | 477 // Set the object tags . |
| 471 // When reading a full snapshot we don't need to canonicalize the object | |
| 472 // as it would already be a canonical object. | |
| 473 // When reading a script snapshot we need to canonicalize only those object | |
| 474 // references that are objects from the core library (loaded from a | |
| 475 // full snapshot). Objects that are only in the script need not be | |
| 476 // canonicalized as they are already canonical. | |
| 477 // When reading a message snapshot we always have to canonicalize the object. | |
| 478 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags) && | |
| 479 (RawObject::IsCreatedFromSnapshot(tags) || | |
| 480 (kind == Snapshot::kMessage))) { | |
| 481 type_arguments ^= type_arguments.Canonicalize(); | |
| 482 } | |
| 483 | |
| 484 // Set the object tags (This is done after setting the object fields | |
| 485 // because 'SetTypeAt' has an assertion to check if the object is not | |
| 486 // already canonical. Also, this is done after 'Canonicalize', which | |
| 487 // does not canonicalize a type already marked as canonical). | |
| 488 type_arguments.set_tags(tags); | 478 type_arguments.set_tags(tags); |
| 489 | 479 |
| 490 return type_arguments.raw(); | 480 return type_arguments.raw(); |
| 491 } | 481 } |
| 492 | 482 |
| 493 | 483 |
| 494 void RawTypeArguments::WriteTo(SnapshotWriter* writer, | 484 void RawTypeArguments::WriteTo(SnapshotWriter* writer, |
| 495 intptr_t object_id, | 485 intptr_t object_id, |
| 496 Snapshot::Kind kind) { | 486 Snapshot::Kind kind) { |
| 497 ASSERT(writer != NULL); | 487 ASSERT(writer != NULL); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 reader->zone(), NEW_OBJECT(RedirectionData)); | 634 reader->zone(), NEW_OBJECT(RedirectionData)); |
| 645 reader->AddBackRef(object_id, &data, kIsDeserialized); | 635 reader->AddBackRef(object_id, &data, kIsDeserialized); |
| 646 | 636 |
| 647 // Set the object tags. | 637 // Set the object tags. |
| 648 data.set_tags(tags); | 638 data.set_tags(tags); |
| 649 | 639 |
| 650 // Set all the object fields. | 640 // Set all the object fields. |
| 651 // TODO(5411462): Need to assert No GC can happen here, even though | 641 // TODO(5411462): Need to assert No GC can happen here, even though |
| 652 // allocations may happen. | 642 // allocations may happen. |
| 653 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); | 643 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); |
| 644 intptr_t from_offset = OFFSET_OF_FROM(data); |
| 654 for (intptr_t i = 0; i <= num_flds; i++) { | 645 for (intptr_t i = 0; i <= num_flds; i++) { |
| 655 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 646 (*reader->PassiveObjectHandle()) = |
| 647 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); |
| 656 data.StorePointer((data.raw()->from() + i), | 648 data.StorePointer((data.raw()->from() + i), |
| 657 reader->PassiveObjectHandle()->raw()); | 649 reader->PassiveObjectHandle()->raw()); |
| 658 } | 650 } |
| 659 | 651 |
| 660 return data.raw(); | 652 return data.raw(); |
| 661 } | 653 } |
| 662 | 654 |
| 663 | 655 |
| 664 void RawRedirectionData::WriteTo(SnapshotWriter* writer, | 656 void RawRedirectionData::WriteTo(SnapshotWriter* writer, |
| 665 intptr_t object_id, | 657 intptr_t object_id, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 func.set_deoptimization_counter(reader->Read<int16_t>()); | 700 func.set_deoptimization_counter(reader->Read<int16_t>()); |
| 709 func.set_regexp_cid(reader->ReadClassIDValue()); | 701 func.set_regexp_cid(reader->ReadClassIDValue()); |
| 710 func.set_kind_tag(reader->Read<uint32_t>()); | 702 func.set_kind_tag(reader->Read<uint32_t>()); |
| 711 func.set_optimized_instruction_count(reader->Read<uint16_t>()); | 703 func.set_optimized_instruction_count(reader->Read<uint16_t>()); |
| 712 func.set_optimized_call_site_count(reader->Read<uint16_t>()); | 704 func.set_optimized_call_site_count(reader->Read<uint16_t>()); |
| 713 | 705 |
| 714 // Set all the object fields. | 706 // Set all the object fields. |
| 715 // TODO(5411462): Need to assert No GC can happen here, even though | 707 // TODO(5411462): Need to assert No GC can happen here, even though |
| 716 // allocations may happen. | 708 // allocations may happen. |
| 717 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from()); | 709 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from()); |
| 710 intptr_t from_offset = OFFSET_OF_FROM(func); |
| 718 for (intptr_t i = 0; i <= num_flds; i++) { | 711 for (intptr_t i = 0; i <= num_flds; i++) { |
| 719 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 712 (*reader->PassiveObjectHandle()) = |
| 713 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); |
| 720 func.StorePointer((func.raw()->from() + i), | 714 func.StorePointer((func.raw()->from() + i), |
| 721 reader->PassiveObjectHandle()->raw()); | 715 reader->PassiveObjectHandle()->raw()); |
| 722 } | 716 } |
| 723 | 717 |
| 724 // Initialize all fields that are not part of the snapshot. | 718 // Initialize all fields that are not part of the snapshot. |
| 725 func.ClearICDataArray(); | 719 func.ClearICDataArray(); |
| 726 func.ClearCode(); | 720 func.ClearCode(); |
| 727 return func.raw(); | 721 return func.raw(); |
| 728 } | 722 } |
| 729 | 723 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 // Set all non object fields. | 774 // Set all non object fields. |
| 781 field.set_token_pos(reader->Read<int32_t>()); | 775 field.set_token_pos(reader->Read<int32_t>()); |
| 782 field.set_guarded_cid(reader->Read<int32_t>()); | 776 field.set_guarded_cid(reader->Read<int32_t>()); |
| 783 field.set_is_nullable(reader->Read<int32_t>()); | 777 field.set_is_nullable(reader->Read<int32_t>()); |
| 784 field.set_kind_bits(reader->Read<uint8_t>()); | 778 field.set_kind_bits(reader->Read<uint8_t>()); |
| 785 | 779 |
| 786 // Set all the object fields. | 780 // Set all the object fields. |
| 787 // TODO(5411462): Need to assert No GC can happen here, even though | 781 // TODO(5411462): Need to assert No GC can happen here, even though |
| 788 // allocations may happen. | 782 // allocations may happen. |
| 789 intptr_t num_flds = (field.raw()->to() - field.raw()->from()); | 783 intptr_t num_flds = (field.raw()->to() - field.raw()->from()); |
| 784 intptr_t from_offset = OFFSET_OF_FROM(field); |
| 790 for (intptr_t i = 0; i <= num_flds; i++) { | 785 for (intptr_t i = 0; i <= num_flds; i++) { |
| 791 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 786 (*reader->PassiveObjectHandle()) = |
| 787 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); |
| 792 field.StorePointer((field.raw()->from() + i), | 788 field.StorePointer((field.raw()->from() + i), |
| 793 reader->PassiveObjectHandle()->raw()); | 789 reader->PassiveObjectHandle()->raw()); |
| 794 } | 790 } |
| 795 | 791 |
| 796 field.InitializeGuardedListLengthInObjectOffset(); | 792 field.InitializeGuardedListLengthInObjectOffset(); |
| 797 | 793 |
| 798 return field.raw(); | 794 return field.raw(); |
| 799 } | 795 } |
| 800 | 796 |
| 801 | 797 |
| (...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2257 // Read the length so that we can determine instance size to allocate. | 2253 // Read the length so that we can determine instance size to allocate. |
| 2258 intptr_t len = reader->ReadSmiValue(); | 2254 intptr_t len = reader->ReadSmiValue(); |
| 2259 Array* array = reinterpret_cast<Array*>( | 2255 Array* array = reinterpret_cast<Array*>( |
| 2260 reader->GetBackRef(object_id)); | 2256 reader->GetBackRef(object_id)); |
| 2261 if (array == NULL) { | 2257 if (array == NULL) { |
| 2262 array = &(Array::ZoneHandle(reader->zone(), | 2258 array = &(Array::ZoneHandle(reader->zone(), |
| 2263 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); | 2259 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); |
| 2264 reader->AddBackRef(object_id, array, kIsDeserialized); | 2260 reader->AddBackRef(object_id, array, kIsDeserialized); |
| 2265 } | 2261 } |
| 2266 ASSERT(!RawObject::IsCanonical(tags)); | 2262 ASSERT(!RawObject::IsCanonical(tags)); |
| 2267 reader->ArrayReadFrom(*array, len, tags); | 2263 reader->ArrayReadFrom(object_id, *array, len, tags); |
| 2268 return array->raw(); | 2264 return array->raw(); |
| 2269 } | 2265 } |
| 2270 | 2266 |
| 2271 | 2267 |
| 2272 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, | 2268 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, |
| 2273 intptr_t object_id, | 2269 intptr_t object_id, |
| 2274 intptr_t tags, | 2270 intptr_t tags, |
| 2275 Snapshot::Kind kind) { | 2271 Snapshot::Kind kind) { |
| 2276 ASSERT(reader != NULL); | 2272 ASSERT(reader != NULL); |
| 2277 | 2273 |
| 2278 // Read the length so that we can determine instance size to allocate. | 2274 // Read the length so that we can determine instance size to allocate. |
| 2279 intptr_t len = reader->ReadSmiValue(); | 2275 intptr_t len = reader->ReadSmiValue(); |
| 2280 Array* array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); | 2276 Array* array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); |
| 2281 if (array == NULL) { | 2277 if (array == NULL) { |
| 2282 array = &(Array::ZoneHandle( | 2278 array = &(Array::ZoneHandle( |
| 2283 reader->zone(), | 2279 reader->zone(), |
| 2284 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); | 2280 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); |
| 2285 reader->AddBackRef(object_id, array, kIsDeserialized); | 2281 reader->AddBackRef(object_id, array, kIsDeserialized); |
| 2286 } | 2282 } |
| 2287 reader->ArrayReadFrom(*array, len, tags); | 2283 reader->ArrayReadFrom(object_id, *array, len, tags); |
| 2288 if (RawObject::IsCanonical(tags)) { | 2284 if (RawObject::IsCanonical(tags)) { |
| 2289 *array ^= array->CheckAndCanonicalize(NULL); | 2285 *array ^= array->CheckAndCanonicalize(NULL); |
| 2290 } | 2286 } |
| 2291 return raw(*array); | 2287 return raw(*array); |
| 2292 } | 2288 } |
| 2293 | 2289 |
| 2294 | 2290 |
| 2295 void RawArray::WriteTo(SnapshotWriter* writer, | 2291 void RawArray::WriteTo(SnapshotWriter* writer, |
| 2296 intptr_t object_id, | 2292 intptr_t object_id, |
| 2297 Snapshot::Kind kind) { | 2293 Snapshot::Kind kind) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2376 UNREACHABLE(); | 2372 UNREACHABLE(); |
| 2377 } else { | 2373 } else { |
| 2378 // Since the map might contain itself as a key or value, allocate first. | 2374 // Since the map might contain itself as a key or value, allocate first. |
| 2379 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); | 2375 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); |
| 2380 } | 2376 } |
| 2381 reader->AddBackRef(object_id, &map, kIsDeserialized); | 2377 reader->AddBackRef(object_id, &map, kIsDeserialized); |
| 2382 // Set the object tags. | 2378 // Set the object tags. |
| 2383 map.set_tags(tags); | 2379 map.set_tags(tags); |
| 2384 | 2380 |
| 2385 // Read the type arguments. | 2381 // Read the type arguments. |
| 2386 *reader->TypeArgumentsHandle() ^= reader->ReadObjectImpl(kAsInlinedObject); | 2382 intptr_t typeargs_offset = |
| 2383 reinterpret_cast<RawObject**>(&map.raw()->ptr()->type_arguments_) - |
| 2384 reinterpret_cast<RawObject**>(map.raw()->ptr()); |
| 2385 *reader->TypeArgumentsHandle() ^= |
| 2386 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset); |
| 2387 map.SetTypeArguments(*reader->TypeArgumentsHandle()); | 2387 map.SetTypeArguments(*reader->TypeArgumentsHandle()); |
| 2388 | 2388 |
| 2389 // Read the number of key/value pairs. | 2389 // Read the number of key/value pairs. |
| 2390 intptr_t len = reader->ReadSmiValue(); | 2390 intptr_t len = reader->ReadSmiValue(); |
| 2391 intptr_t used_data = (len << 1); | 2391 intptr_t used_data = (len << 1); |
| 2392 map.SetUsedData(used_data); | 2392 map.SetUsedData(used_data); |
| 2393 | 2393 |
| 2394 // Allocate the data array. | 2394 // Allocate the data array. |
| 2395 intptr_t data_size = Utils::Maximum( | 2395 intptr_t data_size = Utils::Maximum( |
| 2396 Utils::RoundUpToPowerOfTwo(used_data), | 2396 Utils::RoundUpToPowerOfTwo(used_data), |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2670 | 2670 |
| 2671 | 2671 |
| 2672 RawExternalTypedData* ExternalTypedData::ReadFrom(SnapshotReader* reader, | 2672 RawExternalTypedData* ExternalTypedData::ReadFrom(SnapshotReader* reader, |
| 2673 intptr_t object_id, | 2673 intptr_t object_id, |
| 2674 intptr_t tags, | 2674 intptr_t tags, |
| 2675 Snapshot::Kind kind) { | 2675 Snapshot::Kind kind) { |
| 2676 ASSERT(kind != Snapshot::kFull); | 2676 ASSERT(kind != Snapshot::kFull); |
| 2677 intptr_t cid = RawObject::ClassIdTag::decode(tags); | 2677 intptr_t cid = RawObject::ClassIdTag::decode(tags); |
| 2678 intptr_t length = reader->ReadSmiValue(); | 2678 intptr_t length = reader->ReadSmiValue(); |
| 2679 uint8_t* data = reinterpret_cast<uint8_t*>(reader->ReadRawPointerValue()); | 2679 uint8_t* data = reinterpret_cast<uint8_t*>(reader->ReadRawPointerValue()); |
| 2680 const ExternalTypedData& obj = ExternalTypedData::Handle( | 2680 ExternalTypedData& obj = ExternalTypedData::Handle( |
| 2681 ExternalTypedData::New(cid, data, length)); | 2681 ExternalTypedData::New(cid, data, length)); |
| 2682 reader->AddBackRef(object_id, &obj, kIsDeserialized); |
| 2682 void* peer = reinterpret_cast<void*>(reader->ReadRawPointerValue()); | 2683 void* peer = reinterpret_cast<void*>(reader->ReadRawPointerValue()); |
| 2683 Dart_WeakPersistentHandleFinalizer callback = | 2684 Dart_WeakPersistentHandleFinalizer callback = |
| 2684 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( | 2685 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( |
| 2685 reader->ReadRawPointerValue()); | 2686 reader->ReadRawPointerValue()); |
| 2686 obj.AddFinalizer(peer, callback); | 2687 obj.AddFinalizer(peer, callback); |
| 2687 return obj.raw(); | 2688 return obj.raw(); |
| 2688 } | 2689 } |
| 2689 | 2690 |
| 2690 | 2691 |
| 2691 #define TYPED_DATA_WRITE(type) \ | 2692 #define TYPED_DATA_WRITE(type) \ |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3097 // We do not allow objects with native fields in an isolate message. | 3098 // We do not allow objects with native fields in an isolate message. |
| 3098 writer->SetWriteException(Exceptions::kArgument, | 3099 writer->SetWriteException(Exceptions::kArgument, |
| 3099 "Illegal argument in isolate message" | 3100 "Illegal argument in isolate message" |
| 3100 " : (object is a UserTag)"); | 3101 " : (object is a UserTag)"); |
| 3101 } else { | 3102 } else { |
| 3102 UNREACHABLE(); | 3103 UNREACHABLE(); |
| 3103 } | 3104 } |
| 3104 } | 3105 } |
| 3105 | 3106 |
| 3106 } // namespace dart | 3107 } // namespace dart |
| OLD | NEW |