Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: runtime/vm/raw_object_snapshot.cc

Issue 1255003004: Implement patch records to patch canonical objects. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merged-to-tot Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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->ReadObjectRef(); 74 (*reader->PassiveObjectHandle()) =
72 cls.StorePointer((cls.raw()->from() + i), 75 reader->ReadObjectRef(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
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(); 226 (*reader->PassiveObjectHandle()) =
227 reader->ReadObjectImpl(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
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->ReadObjectRef(); 287 (*reader->PassiveObjectHandle()) =
288 reader->ReadObjectRef(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
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->ReadObjectRef(); 341 (*reader->PassiveObjectHandle()) =
342 reader->ReadObjectRef(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
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->ReadObjectRef(); 398 (*reader->PassiveObjectHandle()) =
399 reader->ReadObjectRef(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
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(); 462 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl();
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(); 472 *reader->TypeHandle() ^= reader->ReadObjectImpl(object_id, (i + offset));
467 type_arguments.SetTypeAt(i, *reader->TypeHandle()); 473 type_arguments.SetTypeAt(i, *reader->TypeHandle());
468 } 474 }
469 475
470 // If object needs to be a canonical object, Canonicalize it. 476 // 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); 477 type_arguments.set_tags(tags);
489 478
490 return type_arguments.raw(); 479 return type_arguments.raw();
491 } 480 }
492 481
493 482
494 void RawTypeArguments::WriteTo(SnapshotWriter* writer, 483 void RawTypeArguments::WriteTo(SnapshotWriter* writer,
495 intptr_t object_id, 484 intptr_t object_id,
496 Snapshot::Kind kind) { 485 Snapshot::Kind kind) {
497 ASSERT(writer != NULL); 486 ASSERT(writer != NULL);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 reader->zone(), NEW_OBJECT(RedirectionData)); 633 reader->zone(), NEW_OBJECT(RedirectionData));
645 reader->AddBackRef(object_id, &data, kIsDeserialized); 634 reader->AddBackRef(object_id, &data, kIsDeserialized);
646 635
647 // Set the object tags. 636 // Set the object tags.
648 data.set_tags(tags); 637 data.set_tags(tags);
649 638
650 // Set all the object fields. 639 // Set all the object fields.
651 // TODO(5411462): Need to assert No GC can happen here, even though 640 // TODO(5411462): Need to assert No GC can happen here, even though
652 // allocations may happen. 641 // allocations may happen.
653 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); 642 intptr_t num_flds = (data.raw()->to() - data.raw()->from());
643 intptr_t from_offset = OFFSET_OF_FROM(data);
654 for (intptr_t i = 0; i <= num_flds; i++) { 644 for (intptr_t i = 0; i <= num_flds; i++) {
655 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); 645 (*reader->PassiveObjectHandle()) =
646 reader->ReadObjectRef(object_id, (i + from_offset));
656 data.StorePointer((data.raw()->from() + i), 647 data.StorePointer((data.raw()->from() + i),
657 reader->PassiveObjectHandle()->raw()); 648 reader->PassiveObjectHandle()->raw());
658 } 649 }
659 650
660 return data.raw(); 651 return data.raw();
661 } 652 }
662 653
663 654
664 void RawRedirectionData::WriteTo(SnapshotWriter* writer, 655 void RawRedirectionData::WriteTo(SnapshotWriter* writer,
665 intptr_t object_id, 656 intptr_t object_id,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 func.set_deoptimization_counter(reader->Read<int16_t>()); 699 func.set_deoptimization_counter(reader->Read<int16_t>());
709 func.set_regexp_cid(reader->ReadClassIDValue()); 700 func.set_regexp_cid(reader->ReadClassIDValue());
710 func.set_kind_tag(reader->Read<uint32_t>()); 701 func.set_kind_tag(reader->Read<uint32_t>());
711 func.set_optimized_instruction_count(reader->Read<uint16_t>()); 702 func.set_optimized_instruction_count(reader->Read<uint16_t>());
712 func.set_optimized_call_site_count(reader->Read<uint16_t>()); 703 func.set_optimized_call_site_count(reader->Read<uint16_t>());
713 704
714 // Set all the object fields. 705 // Set all the object fields.
715 // TODO(5411462): Need to assert No GC can happen here, even though 706 // TODO(5411462): Need to assert No GC can happen here, even though
716 // allocations may happen. 707 // allocations may happen.
717 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from()); 708 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from());
709 intptr_t from_offset = OFFSET_OF_FROM(func);
718 for (intptr_t i = 0; i <= num_flds; i++) { 710 for (intptr_t i = 0; i <= num_flds; i++) {
719 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); 711 (*reader->PassiveObjectHandle()) =
712 reader->ReadObjectRef(object_id, (i + from_offset));
720 func.StorePointer((func.raw()->from() + i), 713 func.StorePointer((func.raw()->from() + i),
721 reader->PassiveObjectHandle()->raw()); 714 reader->PassiveObjectHandle()->raw());
722 } 715 }
723 716
724 // Initialize all fields that are not part of the snapshot. 717 // Initialize all fields that are not part of the snapshot.
725 func.ClearICDataArray(); 718 func.ClearICDataArray();
726 func.ClearCode(); 719 func.ClearCode();
727 return func.raw(); 720 return func.raw();
728 } 721 }
729 722
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 // Set all non object fields. 773 // Set all non object fields.
781 field.set_token_pos(reader->Read<int32_t>()); 774 field.set_token_pos(reader->Read<int32_t>());
782 field.set_guarded_cid(reader->Read<int32_t>()); 775 field.set_guarded_cid(reader->Read<int32_t>());
783 field.set_is_nullable(reader->Read<int32_t>()); 776 field.set_is_nullable(reader->Read<int32_t>());
784 field.set_kind_bits(reader->Read<uint8_t>()); 777 field.set_kind_bits(reader->Read<uint8_t>());
785 778
786 // Set all the object fields. 779 // Set all the object fields.
787 // TODO(5411462): Need to assert No GC can happen here, even though 780 // TODO(5411462): Need to assert No GC can happen here, even though
788 // allocations may happen. 781 // allocations may happen.
789 intptr_t num_flds = (field.raw()->to() - field.raw()->from()); 782 intptr_t num_flds = (field.raw()->to() - field.raw()->from());
783 intptr_t from_offset = OFFSET_OF_FROM(field);
790 for (intptr_t i = 0; i <= num_flds; i++) { 784 for (intptr_t i = 0; i <= num_flds; i++) {
791 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); 785 (*reader->PassiveObjectHandle()) =
786 reader->ReadObjectRef(object_id, (i + from_offset));
792 field.StorePointer((field.raw()->from() + i), 787 field.StorePointer((field.raw()->from() + i),
793 reader->PassiveObjectHandle()->raw()); 788 reader->PassiveObjectHandle()->raw());
794 } 789 }
795 790
796 field.InitializeGuardedListLengthInObjectOffset(); 791 field.InitializeGuardedListLengthInObjectOffset();
797 792
798 return field.raw(); 793 return field.raw();
799 } 794 }
800 795
801 796
(...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 // Read the length so that we can determine instance size to allocate. 2248 // Read the length so that we can determine instance size to allocate.
2254 intptr_t len = reader->ReadSmiValue(); 2249 intptr_t len = reader->ReadSmiValue();
2255 Array* array = reinterpret_cast<Array*>( 2250 Array* array = reinterpret_cast<Array*>(
2256 reader->GetBackRef(object_id)); 2251 reader->GetBackRef(object_id));
2257 if (array == NULL) { 2252 if (array == NULL) {
2258 array = &(Array::ZoneHandle(reader->zone(), 2253 array = &(Array::ZoneHandle(reader->zone(),
2259 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); 2254 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind)));
2260 reader->AddBackRef(object_id, array, kIsDeserialized); 2255 reader->AddBackRef(object_id, array, kIsDeserialized);
2261 } 2256 }
2262 ASSERT(!RawObject::IsCanonical(tags)); 2257 ASSERT(!RawObject::IsCanonical(tags));
2263 reader->ArrayReadFrom(*array, len, tags); 2258 reader->ArrayReadFrom(object_id, *array, len, tags);
2264 return array->raw(); 2259 return array->raw();
2265 } 2260 }
2266 2261
2267 2262
2268 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, 2263 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader,
2269 intptr_t object_id, 2264 intptr_t object_id,
2270 intptr_t tags, 2265 intptr_t tags,
2271 Snapshot::Kind kind) { 2266 Snapshot::Kind kind) {
2272 ASSERT(reader != NULL); 2267 ASSERT(reader != NULL);
2273 2268
2274 // Read the length so that we can determine instance size to allocate. 2269 // Read the length so that we can determine instance size to allocate.
2275 intptr_t len = reader->ReadSmiValue(); 2270 intptr_t len = reader->ReadSmiValue();
2276 Array* array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); 2271 Array* array = reinterpret_cast<Array*>(reader->GetBackRef(object_id));
2277 if (array == NULL) { 2272 if (array == NULL) {
2278 array = &(Array::ZoneHandle( 2273 array = &(Array::ZoneHandle(
2279 reader->zone(), 2274 reader->zone(),
2280 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); 2275 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind)));
2281 reader->AddBackRef(object_id, array, kIsDeserialized); 2276 reader->AddBackRef(object_id, array, kIsDeserialized);
2282 } 2277 }
2283 reader->ArrayReadFrom(*array, len, tags); 2278 reader->ArrayReadFrom(object_id, *array, len, tags);
2284 if (RawObject::IsCanonical(tags)) { 2279 if (RawObject::IsCanonical(tags)) {
2285 *array ^= array->CheckAndCanonicalize(NULL); 2280 *array ^= array->CheckAndCanonicalize(NULL);
2286 } 2281 }
2287 return raw(*array); 2282 return raw(*array);
2288 } 2283 }
2289 2284
2290 2285
2291 void RawArray::WriteTo(SnapshotWriter* writer, 2286 void RawArray::WriteTo(SnapshotWriter* writer,
2292 intptr_t object_id, 2287 intptr_t object_id,
2293 Snapshot::Kind kind) { 2288 Snapshot::Kind kind) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 UNREACHABLE(); 2367 UNREACHABLE();
2373 } else { 2368 } else {
2374 // Since the map might contain itself as a key or value, allocate first. 2369 // Since the map might contain itself as a key or value, allocate first.
2375 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); 2370 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind));
2376 } 2371 }
2377 reader->AddBackRef(object_id, &map, kIsDeserialized); 2372 reader->AddBackRef(object_id, &map, kIsDeserialized);
2378 // Set the object tags. 2373 // Set the object tags.
2379 map.set_tags(tags); 2374 map.set_tags(tags);
2380 2375
2381 // Read the type arguments. 2376 // Read the type arguments.
2382 *reader->TypeArgumentsHandle() ^= reader->ReadObjectImpl(); 2377 intptr_t typeargs_offset =
2378 reinterpret_cast<RawObject**>(&map.raw()->ptr()->type_arguments_) -
2379 reinterpret_cast<RawObject**>(map.raw()->ptr());
2380 *reader->TypeArgumentsHandle() ^=
2381 reader->ReadObjectImpl(object_id, typeargs_offset);
2383 map.SetTypeArguments(*reader->TypeArgumentsHandle()); 2382 map.SetTypeArguments(*reader->TypeArgumentsHandle());
2384 2383
2385 // Read the number of key/value pairs. 2384 // Read the number of key/value pairs.
2386 intptr_t len = reader->ReadSmiValue(); 2385 intptr_t len = reader->ReadSmiValue();
2387 intptr_t used_data = (len << 1); 2386 intptr_t used_data = (len << 1);
2388 map.SetUsedData(used_data); 2387 map.SetUsedData(used_data);
2389 2388
2390 // Allocate the data array. 2389 // Allocate the data array.
2391 intptr_t data_size = Utils::Maximum( 2390 intptr_t data_size = Utils::Maximum(
2392 Utils::RoundUpToPowerOfTwo(used_data), 2391 Utils::RoundUpToPowerOfTwo(used_data),
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
2672 2671
2673 2672
2674 RawExternalTypedData* ExternalTypedData::ReadFrom(SnapshotReader* reader, 2673 RawExternalTypedData* ExternalTypedData::ReadFrom(SnapshotReader* reader,
2675 intptr_t object_id, 2674 intptr_t object_id,
2676 intptr_t tags, 2675 intptr_t tags,
2677 Snapshot::Kind kind) { 2676 Snapshot::Kind kind) {
2678 ASSERT(kind != Snapshot::kFull); 2677 ASSERT(kind != Snapshot::kFull);
2679 intptr_t cid = RawObject::ClassIdTag::decode(tags); 2678 intptr_t cid = RawObject::ClassIdTag::decode(tags);
2680 intptr_t length = reader->ReadSmiValue(); 2679 intptr_t length = reader->ReadSmiValue();
2681 uint8_t* data = reinterpret_cast<uint8_t*>(reader->ReadRawPointerValue()); 2680 uint8_t* data = reinterpret_cast<uint8_t*>(reader->ReadRawPointerValue());
2682 const ExternalTypedData& obj = ExternalTypedData::Handle( 2681 ExternalTypedData& obj = ExternalTypedData::Handle(
2683 ExternalTypedData::New(cid, data, length)); 2682 ExternalTypedData::New(cid, data, length));
2683 reader->AddBackRef(object_id, &obj, kIsDeserialized);
2684 void* peer = reinterpret_cast<void*>(reader->ReadRawPointerValue()); 2684 void* peer = reinterpret_cast<void*>(reader->ReadRawPointerValue());
2685 Dart_WeakPersistentHandleFinalizer callback = 2685 Dart_WeakPersistentHandleFinalizer callback =
2686 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( 2686 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>(
2687 reader->ReadRawPointerValue()); 2687 reader->ReadRawPointerValue());
2688 obj.AddFinalizer(peer, callback); 2688 obj.AddFinalizer(peer, callback);
2689 return obj.raw(); 2689 return obj.raw();
2690 } 2690 }
2691 2691
2692 2692
2693 #define TYPED_DATA_WRITE(type) \ 2693 #define TYPED_DATA_WRITE(type) \
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3099 // We do not allow objects with native fields in an isolate message. 3099 // We do not allow objects with native fields in an isolate message.
3100 writer->SetWriteException(Exceptions::kArgument, 3100 writer->SetWriteException(Exceptions::kArgument,
3101 "Illegal argument in isolate message" 3101 "Illegal argument in isolate message"
3102 " : (object is a UserTag)"); 3102 " : (object is a UserTag)");
3103 } else { 3103 } else {
3104 UNREACHABLE(); 3104 UNREACHABLE();
3105 } 3105 }
3106 } 3106 }
3107 3107
3108 } // namespace dart 3108 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.h » ('j') | runtime/vm/snapshot.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698