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

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

Issue 2161853002: Remove dead full snapshot support from the recursive descent serializer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: . Created 4 years, 5 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
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/native_entry.h" 5 #include "vm/native_entry.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/snapshot.h" 8 #include "vm/snapshot.h"
9 #include "vm/stub_code.h" 9 #include "vm/stub_code.h"
10 #include "vm/symbols.h" 10 #include "vm/symbols.h"
11 #include "vm/visitor.h" 11 #include "vm/visitor.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 DECLARE_FLAG(bool, remove_script_timestamps_for_test); 15 DECLARE_FLAG(bool, remove_script_timestamps_for_test);
16 16
17 #define NEW_OBJECT(type) \
18 ((Snapshot::IsFull(kind)) ? reader->New##type() : type::New())
19
20 #define NEW_OBJECT_WITH_LEN(type, len) \
21 ((Snapshot::IsFull(kind)) ? reader->New##type(len) : type::New(len))
22
23 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \
24 ((Snapshot::IsFull(kind)) ? \
25 reader->New##type(len) : type::New(len, HEAP_SPACE(kind)))
26
27 #define OFFSET_OF_FROM(obj) \ 17 #define OFFSET_OF_FROM(obj) \
28 obj.raw()->from() - reinterpret_cast<RawObject**>(obj.raw()->ptr()) 18 obj.raw()->from() - reinterpret_cast<RawObject**>(obj.raw()->ptr())
29 19
30 // TODO(18854): Need to assert No GC can happen here, even though 20 // TODO(18854): Need to assert No GC can happen here, even though
31 // allocations may happen. 21 // allocations may happen.
32 #define READ_OBJECT_FIELDS(object, from, to, as_reference) \ 22 #define READ_OBJECT_FIELDS(object, from, to, as_reference) \
33 intptr_t num_flds = (to) - (from); \ 23 intptr_t num_flds = (to) - (from); \
34 intptr_t from_offset = OFFSET_OF_FROM(object); \ 24 intptr_t from_offset = OFFSET_OF_FROM(object); \
35 for (intptr_t i = 0; i <= num_flds; i++) { \ 25 for (intptr_t i = 0; i <= num_flds; i++) { \
36 (*reader->PassiveObjectHandle()) = \ 26 (*reader->PassiveObjectHandle()) = \
37 reader->ReadObjectImpl(as_reference, object_id, (i + from_offset)); \ 27 reader->ReadObjectImpl(as_reference, object_id, (i + from_offset)); \
38 object.StorePointer(((from) + i), \ 28 object.StorePointer(((from) + i), \
39 reader->PassiveObjectHandle()->raw()); \ 29 reader->PassiveObjectHandle()->raw()); \
40 } 30 }
41 31
42 RawClass* Class::ReadFrom(SnapshotReader* reader, 32 RawClass* Class::ReadFrom(SnapshotReader* reader,
43 intptr_t object_id, 33 intptr_t object_id,
44 intptr_t tags, 34 intptr_t tags,
45 Snapshot::Kind kind, 35 Snapshot::Kind kind,
46 bool as_reference) { 36 bool as_reference) {
47 ASSERT(reader != NULL); 37 ASSERT(reader != NULL);
48 38
49 Class& cls = Class::ZoneHandle(reader->zone(), Class::null()); 39 Class& cls = Class::ZoneHandle(reader->zone(), Class::null());
50 bool is_in_fullsnapshot = reader->Read<bool>(); 40 bool is_in_fullsnapshot = reader->Read<bool>();
51 if (Snapshot::IsFull(kind) || 41 if ((kind == Snapshot::kScript) && !is_in_fullsnapshot) {
52 (kind == Snapshot::kScript && !is_in_fullsnapshot)) {
53 // Read in the base information. 42 // Read in the base information.
54 classid_t class_id = reader->ReadClassIDValue(); 43 classid_t class_id = reader->ReadClassIDValue();
55 44
56 // Allocate class object of specified kind. 45 // Allocate class object of specified kind.
57 if (Snapshot::IsFull(kind)) { 46 if (class_id < kNumPredefinedCids) {
58 cls = reader->NewClass(class_id); 47 ASSERT((class_id >= kInstanceCid) && (class_id <= kMirrorReferenceCid));
48 cls = reader->isolate()->class_table()->At(class_id);
59 } else { 49 } else {
60 if (class_id < kNumPredefinedCids) { 50 cls = Class::NewInstanceClass();
61 ASSERT((class_id >= kInstanceCid) && (class_id <= kMirrorReferenceCid));
62 cls = reader->isolate()->class_table()->At(class_id);
63 } else {
64 cls = Class::NewInstanceClass();
65 }
66 } 51 }
67 reader->AddBackRef(object_id, &cls, kIsDeserialized); 52 reader->AddBackRef(object_id, &cls, kIsDeserialized);
68 53
69 // Set all non object fields. 54 // Set all non object fields.
70 if (!RawObject::IsInternalVMdefinedClassId(class_id)) { 55 if (!RawObject::IsInternalVMdefinedClassId(class_id)) {
71 // Instance size of a VM defined class is already set up. 56 // Instance size of a VM defined class is already set up.
72 cls.set_instance_size_in_words(reader->Read<int32_t>()); 57 cls.set_instance_size_in_words(reader->Read<int32_t>());
73 cls.set_next_field_offset_in_words(reader->Read<int32_t>()); 58 cls.set_next_field_offset_in_words(reader->Read<int32_t>());
74 } 59 }
75 cls.set_type_arguments_field_offset_in_words(reader->Read<int32_t>()); 60 cls.set_type_arguments_field_offset_in_words(reader->Read<int32_t>());
76 cls.set_num_type_arguments(reader->Read<int16_t>()); 61 cls.set_num_type_arguments(reader->Read<int16_t>());
77 cls.set_num_own_type_arguments(reader->Read<int16_t>()); 62 cls.set_num_own_type_arguments(reader->Read<int16_t>());
78 cls.set_num_native_fields(reader->Read<uint16_t>()); 63 cls.set_num_native_fields(reader->Read<uint16_t>());
79 cls.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 64 cls.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
80 cls.set_state_bits(reader->Read<uint16_t>()); 65 cls.set_state_bits(reader->Read<uint16_t>());
81 66
82 // Set all the object fields. 67 // Set all the object fields.
83 READ_OBJECT_FIELDS(cls, 68 READ_OBJECT_FIELDS(cls,
84 cls.raw()->from(), 69 cls.raw()->from(),
85 cls.raw()->to_snapshot(kind), 70 cls.raw()->to_snapshot(kind),
86 kAsReference); 71 kAsReference);
87 cls.StorePointer(&cls.raw_ptr()->dependent_code_, Array::null()); 72 cls.StorePointer(&cls.raw_ptr()->dependent_code_, Array::null());
88 ASSERT(!cls.IsInFullSnapshot() || (Snapshot::IsFull(kind))); 73 ASSERT(!cls.IsInFullSnapshot());
89 } else { 74 } else {
90 cls ^= reader->ReadClassId(object_id); 75 cls ^= reader->ReadClassId(object_id);
91 ASSERT((kind == Snapshot::kMessage) || cls.IsInFullSnapshot()); 76 ASSERT((kind == Snapshot::kMessage) || cls.IsInFullSnapshot());
92 } 77 }
93 return cls.raw(); 78 return cls.raw();
94 } 79 }
95 80
96 81
97 void RawClass::WriteTo(SnapshotWriter* writer, 82 void RawClass::WriteTo(SnapshotWriter* writer,
98 intptr_t object_id, 83 intptr_t object_id,
99 Snapshot::Kind kind, 84 Snapshot::Kind kind,
100 bool as_reference) { 85 bool as_reference) {
101 ASSERT(writer != NULL); 86 ASSERT(writer != NULL);
102 bool is_in_fullsnapshot = Class::IsInFullSnapshot(this); 87 bool is_in_fullsnapshot = Class::IsInFullSnapshot(this);
103 88
104 // Write out the serialization header value for this object. 89 // Write out the serialization header value for this object.
105 writer->WriteInlinedObjectHeader(object_id); 90 writer->WriteInlinedObjectHeader(object_id);
106 91
107 // Write out the class and tags information. 92 // Write out the class and tags information.
108 writer->WriteVMIsolateObject(kClassCid); 93 writer->WriteVMIsolateObject(kClassCid);
109 writer->WriteTags(writer->GetObjectTags(this)); 94 writer->WriteTags(writer->GetObjectTags(this));
110 95
111 // Write out the boolean is_in_fullsnapshot first as this will 96 // Write out the boolean is_in_fullsnapshot first as this will
112 // help the reader decide how the rest of the information needs 97 // help the reader decide how the rest of the information needs
113 // to be interpreted. 98 // to be interpreted.
114 writer->Write<bool>(is_in_fullsnapshot); 99 writer->Write<bool>(is_in_fullsnapshot);
115 100
116 if (Snapshot::IsFull(kind) || 101 if ((kind == Snapshot::kScript) && !is_in_fullsnapshot) {
117 (kind == Snapshot::kScript && !is_in_fullsnapshot)) {
118 // Write out all the non object pointer fields. 102 // Write out all the non object pointer fields.
119 // NOTE: cpp_vtable_ is not written. 103 // NOTE: cpp_vtable_ is not written.
120 classid_t class_id = ptr()->id_; 104 classid_t class_id = ptr()->id_;
121 ASSERT(class_id != kIllegalCid); 105 ASSERT(class_id != kIllegalCid);
122 writer->Write<classid_t>(class_id); 106 writer->Write<classid_t>(class_id);
123 if (!RawObject::IsInternalVMdefinedClassId(class_id)) { 107 if (!RawObject::IsInternalVMdefinedClassId(class_id)) {
124 // We don't write the instance size of VM defined classes as they 108 // We don't write the instance size of VM defined classes as they
125 // are already setup during initialization as part of pre populating 109 // are already setup during initialization as part of pre populating
126 // the class table. 110 // the class table.
127 writer->Write<int32_t>(ptr()->instance_size_in_words_); 111 writer->Write<int32_t>(ptr()->instance_size_in_words_);
(...skipping 25 matching lines...) Expand all
153 137
154 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, 138 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader,
155 intptr_t object_id, 139 intptr_t object_id,
156 intptr_t tags, 140 intptr_t tags,
157 Snapshot::Kind kind, 141 Snapshot::Kind kind,
158 bool as_reference) { 142 bool as_reference) {
159 ASSERT(reader != NULL); 143 ASSERT(reader != NULL);
160 144
161 // Allocate unresolved class object. 145 // Allocate unresolved class object.
162 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( 146 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle(
163 reader->zone(), NEW_OBJECT(UnresolvedClass)); 147 reader->zone(), UnresolvedClass::New());
164 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized); 148 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized);
165 149
166 // Set all non object fields. 150 // Set all non object fields.
167 unresolved_class.set_token_pos( 151 unresolved_class.set_token_pos(
168 TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 152 TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
169 153
170 // Set all the object fields. 154 // Set all the object fields.
171 READ_OBJECT_FIELDS(unresolved_class, 155 READ_OBJECT_FIELDS(unresolved_class,
172 unresolved_class.raw()->from(), 156 unresolved_class.raw()->from(),
173 unresolved_class.raw()->to(), 157 unresolved_class.raw()->to(),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 intptr_t object_id, 205 intptr_t object_id,
222 intptr_t tags, 206 intptr_t tags,
223 Snapshot::Kind kind, 207 Snapshot::Kind kind,
224 bool as_reference) { 208 bool as_reference) {
225 ASSERT(reader != NULL); 209 ASSERT(reader != NULL);
226 210
227 // Determine if the type class of this type is in the full snapshot. 211 // Determine if the type class of this type is in the full snapshot.
228 bool typeclass_is_in_fullsnapshot = reader->Read<bool>(); 212 bool typeclass_is_in_fullsnapshot = reader->Read<bool>();
229 213
230 // Allocate type object. 214 // Allocate type object.
231 Type& type = Type::ZoneHandle(reader->zone(), NEW_OBJECT(Type)); 215 Type& type = Type::ZoneHandle(reader->zone(), Type::New());
232 bool is_canonical = RawObject::IsCanonical(tags); 216 bool is_canonical = RawObject::IsCanonical(tags);
233 bool defer_canonicalization = is_canonical && 217 bool defer_canonicalization = is_canonical &&
234 (!Snapshot::IsFull(kind) && typeclass_is_in_fullsnapshot); 218 (!Snapshot::IsFull(kind) && typeclass_is_in_fullsnapshot);
235 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization); 219 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization);
236 220
237 // Set all non object fields. 221 // Set all non object fields.
238 type.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 222 type.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
239 type.set_type_state(reader->Read<int8_t>()); 223 type.set_type_state(reader->Read<int8_t>());
240 224
241 // Set all the object fields. 225 // Set all the object fields.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 286
303 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader, 287 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader,
304 intptr_t object_id, 288 intptr_t object_id,
305 intptr_t tags, 289 intptr_t tags,
306 Snapshot::Kind kind, 290 Snapshot::Kind kind,
307 bool as_reference) { 291 bool as_reference) {
308 ASSERT(reader != NULL); 292 ASSERT(reader != NULL);
309 293
310 // Allocate type ref object. 294 // Allocate type ref object.
311 TypeRef& type_ref = TypeRef::ZoneHandle( 295 TypeRef& type_ref = TypeRef::ZoneHandle(
312 reader->zone(), NEW_OBJECT(TypeRef)); 296 reader->zone(), TypeRef::New());
313 reader->AddBackRef(object_id, &type_ref, kIsDeserialized); 297 reader->AddBackRef(object_id, &type_ref, kIsDeserialized);
314 298
315 // Set all the object fields. 299 // Set all the object fields.
316 READ_OBJECT_FIELDS(type_ref, 300 READ_OBJECT_FIELDS(type_ref,
317 type_ref.raw()->from(), type_ref.raw()->to(), 301 type_ref.raw()->from(), type_ref.raw()->to(),
318 kAsReference); 302 kAsReference);
319 303
320 return type_ref.raw(); 304 return type_ref.raw();
321 } 305 }
322 306
(...skipping 19 matching lines...) Expand all
342 326
343 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, 327 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader,
344 intptr_t object_id, 328 intptr_t object_id,
345 intptr_t tags, 329 intptr_t tags,
346 Snapshot::Kind kind, 330 Snapshot::Kind kind,
347 bool as_reference) { 331 bool as_reference) {
348 ASSERT(reader != NULL); 332 ASSERT(reader != NULL);
349 333
350 // Allocate type parameter object. 334 // Allocate type parameter object.
351 TypeParameter& type_parameter = TypeParameter::ZoneHandle( 335 TypeParameter& type_parameter = TypeParameter::ZoneHandle(
352 reader->zone(), NEW_OBJECT(TypeParameter)); 336 reader->zone(), TypeParameter::New());
353 reader->AddBackRef(object_id, &type_parameter, kIsDeserialized); 337 reader->AddBackRef(object_id, &type_parameter, kIsDeserialized);
354 338
355 // Set all non object fields. 339 // Set all non object fields.
356 type_parameter.set_token_pos( 340 type_parameter.set_token_pos(
357 TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 341 TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
358 type_parameter.set_index(reader->Read<int16_t>()); 342 type_parameter.set_index(reader->Read<int16_t>());
359 type_parameter.set_type_state(reader->Read<int8_t>()); 343 type_parameter.set_type_state(reader->Read<int8_t>());
360 344
361 // Set all the object fields. 345 // Set all the object fields.
362 READ_OBJECT_FIELDS(type_parameter, 346 READ_OBJECT_FIELDS(type_parameter,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 390
407 RawBoundedType* BoundedType::ReadFrom(SnapshotReader* reader, 391 RawBoundedType* BoundedType::ReadFrom(SnapshotReader* reader,
408 intptr_t object_id, 392 intptr_t object_id,
409 intptr_t tags, 393 intptr_t tags,
410 Snapshot::Kind kind, 394 Snapshot::Kind kind,
411 bool as_reference) { 395 bool as_reference) {
412 ASSERT(reader != NULL); 396 ASSERT(reader != NULL);
413 397
414 // Allocate bounded type object. 398 // Allocate bounded type object.
415 BoundedType& bounded_type = BoundedType::ZoneHandle( 399 BoundedType& bounded_type = BoundedType::ZoneHandle(
416 reader->zone(), NEW_OBJECT(BoundedType)); 400 reader->zone(), BoundedType::New());
417 reader->AddBackRef(object_id, &bounded_type, kIsDeserialized); 401 reader->AddBackRef(object_id, &bounded_type, kIsDeserialized);
418 402
419 // Set all the object fields. 403 // Set all the object fields.
420 READ_OBJECT_FIELDS(bounded_type, 404 READ_OBJECT_FIELDS(bounded_type,
421 bounded_type.raw()->from(), bounded_type.raw()->to(), 405 bounded_type.raw()->from(), bounded_type.raw()->to(),
422 kAsReference); 406 kAsReference);
423 407
424 return bounded_type.raw(); 408 return bounded_type.raw();
425 } 409 }
426 410
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 intptr_t object_id, 450 intptr_t object_id,
467 intptr_t tags, 451 intptr_t tags,
468 Snapshot::Kind kind, 452 Snapshot::Kind kind,
469 bool as_reference) { 453 bool as_reference) {
470 ASSERT(reader != NULL); 454 ASSERT(reader != NULL);
471 455
472 // Read the length so that we can determine instance size to allocate. 456 // Read the length so that we can determine instance size to allocate.
473 intptr_t len = reader->ReadSmiValue(); 457 intptr_t len = reader->ReadSmiValue();
474 458
475 TypeArguments& type_arguments = TypeArguments::ZoneHandle( 459 TypeArguments& type_arguments = TypeArguments::ZoneHandle(
476 reader->zone(), NEW_OBJECT_WITH_LEN_SPACE(TypeArguments, len, kind)); 460 reader->zone(), TypeArguments::New(len, HEAP_SPACE(kind)));
477 bool is_canonical = RawObject::IsCanonical(tags); 461 bool is_canonical = RawObject::IsCanonical(tags);
478 bool defer_canonicalization = is_canonical && (!Snapshot::IsFull(kind)); 462 bool defer_canonicalization = is_canonical && (!Snapshot::IsFull(kind));
479 reader->AddBackRef(object_id, 463 reader->AddBackRef(object_id,
480 &type_arguments, 464 &type_arguments,
481 kIsDeserialized, 465 kIsDeserialized,
482 defer_canonicalization); 466 defer_canonicalization);
483 467
484 // Set the instantiations field, which is only read from a full snapshot. 468 // Set the instantiations field, which is only read from a full snapshot.
485 if (Snapshot::IsFull(kind)) { 469 type_arguments.set_instantiations(Object::zero_array());
486 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
487 type_arguments.set_instantiations(*(reader->ArrayHandle()));
488 } else {
489 type_arguments.set_instantiations(Object::zero_array());
490 }
491 470
492 // Now set all the type fields. 471 // Now set all the type fields.
493 intptr_t offset = type_arguments.TypeAddr(0) - 472 intptr_t offset = type_arguments.TypeAddr(0) -
494 reinterpret_cast<RawAbstractType**>(type_arguments.raw()->ptr()); 473 reinterpret_cast<RawAbstractType**>(type_arguments.raw()->ptr());
495 for (intptr_t i = 0; i < len; i++) { 474 for (intptr_t i = 0; i < len; i++) {
496 *reader->TypeHandle() ^= 475 *reader->TypeHandle() ^=
497 reader->ReadObjectImpl(kAsReference, object_id, (i + offset)); 476 reader->ReadObjectImpl(kAsReference, object_id, (i + offset));
498 type_arguments.SetTypeAt(i, *reader->TypeHandle()); 477 type_arguments.SetTypeAt(i, *reader->TypeHandle());
499 } 478 }
500 479
(...skipping 15 matching lines...) Expand all
516 // Write out the serialization header value for this object. 495 // Write out the serialization header value for this object.
517 writer->WriteInlinedObjectHeader(object_id); 496 writer->WriteInlinedObjectHeader(object_id);
518 497
519 // Write out the class and tags information. 498 // Write out the class and tags information.
520 writer->WriteVMIsolateObject(kTypeArgumentsCid); 499 writer->WriteVMIsolateObject(kTypeArgumentsCid);
521 writer->WriteTags(writer->GetObjectTags(this)); 500 writer->WriteTags(writer->GetObjectTags(this));
522 501
523 // Write out the length field. 502 // Write out the length field.
524 writer->Write<RawObject*>(ptr()->length_); 503 writer->Write<RawObject*>(ptr()->length_);
525 504
526 // Write out the instantiations field, but only in a full snapshot.
527 if (Snapshot::IsFull(kind)) {
528 writer->WriteObjectImpl(ptr()->instantiations_, kAsInlinedObject);
529 }
530
531 // Write out the individual types. 505 // Write out the individual types.
532 intptr_t len = Smi::Value(ptr()->length_); 506 intptr_t len = Smi::Value(ptr()->length_);
533 for (intptr_t i = 0; i < len; i++) { 507 for (intptr_t i = 0; i < len; i++) {
534 writer->WriteObjectImpl(ptr()->types()[i], kAsReference); 508 writer->WriteObjectImpl(ptr()->types()[i], kAsReference);
535 } 509 }
536 } 510 }
537 511
538 512
539 RawPatchClass* PatchClass::ReadFrom(SnapshotReader* reader, 513 RawPatchClass* PatchClass::ReadFrom(SnapshotReader* reader,
540 intptr_t object_id, 514 intptr_t object_id,
541 intptr_t tags, 515 intptr_t tags,
542 Snapshot::Kind kind, 516 Snapshot::Kind kind,
543 bool as_reference) { 517 bool as_reference) {
544 ASSERT(reader != NULL); 518 ASSERT(reader != NULL);
519 ASSERT(kind == Snapshot::kScript);
545 520
546 // Allocate function object. 521 // Allocate function object.
547 PatchClass& cls = PatchClass::ZoneHandle(reader->zone(), 522 PatchClass& cls = PatchClass::ZoneHandle(reader->zone(),
548 NEW_OBJECT(PatchClass)); 523 PatchClass::New());
549 reader->AddBackRef(object_id, &cls, kIsDeserialized); 524 reader->AddBackRef(object_id, &cls, kIsDeserialized);
550 525
551 // Set all the object fields. 526 // Set all the object fields.
552 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); 527 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference);
553 528
554 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind)));
555 return cls.raw(); 529 return cls.raw();
556 } 530 }
557 531
558 532
559 void RawPatchClass::WriteTo(SnapshotWriter* writer, 533 void RawPatchClass::WriteTo(SnapshotWriter* writer,
560 intptr_t object_id, 534 intptr_t object_id,
561 Snapshot::Kind kind, 535 Snapshot::Kind kind,
562 bool as_reference) { 536 bool as_reference) {
563 ASSERT(writer != NULL); 537 ASSERT(writer != NULL);
564 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 538 ASSERT(kind == Snapshot::kScript);
565 539
566 // Write out the serialization header value for this object. 540 // Write out the serialization header value for this object.
567 writer->WriteInlinedObjectHeader(object_id); 541 writer->WriteInlinedObjectHeader(object_id);
568 542
569 // Write out the class and tags information. 543 // Write out the class and tags information.
570 writer->WriteVMIsolateObject(kPatchClassCid); 544 writer->WriteVMIsolateObject(kPatchClassCid);
571 writer->WriteTags(writer->GetObjectTags(this)); 545 writer->WriteTags(writer->GetObjectTags(this));
572 // Write out all the object pointer fields. 546 // Write out all the object pointer fields.
573 SnapshotWriterVisitor visitor(writer, kAsReference); 547 SnapshotWriterVisitor visitor(writer, kAsReference);
574 visitor.VisitPointers(from(), to()); 548 visitor.VisitPointers(from(), to());
575 } 549 }
576 550
577 551
578 RawClosure* Closure::ReadFrom(SnapshotReader* reader, 552 RawClosure* Closure::ReadFrom(SnapshotReader* reader,
579 intptr_t object_id, 553 intptr_t object_id,
580 intptr_t tags, 554 intptr_t tags,
581 Snapshot::Kind kind, 555 Snapshot::Kind kind,
582 bool as_reference) { 556 bool as_reference) {
583 ASSERT(reader != NULL); 557 UNREACHABLE();
584 ASSERT(Snapshot::IsFull(kind)); 558 return Closure::null();
585
586 // Allocate closure object.
587 Closure& closure = Closure::ZoneHandle(
588 reader->zone(), NEW_OBJECT(Closure));
589 reader->AddBackRef(object_id, &closure, kIsDeserialized);
590
591 // Set all the object fields.
592 READ_OBJECT_FIELDS(closure,
593 closure.raw()->from(), closure.raw()->to(),
594 kAsReference);
595
596 // Set the canonical bit.
597 if (RawObject::IsCanonical(tags)) {
598 closure.SetCanonical();
599 }
600 return closure.raw();
601 } 559 }
602 560
603 561
604 void RawClosure::WriteTo(SnapshotWriter* writer, 562 void RawClosure::WriteTo(SnapshotWriter* writer,
605 intptr_t object_id, 563 intptr_t object_id,
606 Snapshot::Kind kind, 564 Snapshot::Kind kind,
607 bool as_reference) { 565 bool as_reference) {
608 ASSERT(writer != NULL); 566 ASSERT(writer != NULL);
609 if ((kind == Snapshot::kMessage) || (kind == Snapshot::kScript)) { 567 ASSERT((kind == Snapshot::kMessage) || (kind == Snapshot::kScript));
610 // Check if closure is serializable, throw an exception otherwise. 568
611 RawFunction* func = writer->IsSerializableClosure(this); 569 // Check if closure is serializable, throw an exception otherwise.
612 if (func != Function::null()) { 570 RawFunction* func = writer->IsSerializableClosure(this);
613 writer->WriteStaticImplicitClosure(object_id, 571 if (func != Function::null()) {
614 func, 572 writer->WriteStaticImplicitClosure(object_id,
615 writer->GetObjectTags(this)); 573 func,
616 return; 574 writer->GetObjectTags(this));
617 } 575 return;
618 } 576 }
619 577
620 // Write out the serialization header value for this object. 578 UNREACHABLE();
621 writer->WriteInlinedObjectHeader(object_id);
622
623 // Write out the class and tags information.
624 writer->WriteIndexedObject(kClosureCid);
625 writer->WriteTags(writer->GetObjectTags(this));
626
627 // Write out all the object pointer fields.
628 SnapshotWriterVisitor visitor(writer, kAsReference);
629 visitor.VisitPointers(from(), to());
630 } 579 }
631 580
632 581
633 RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader, 582 RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader,
634 intptr_t object_id, 583 intptr_t object_id,
635 intptr_t tags, 584 intptr_t tags,
636 Snapshot::Kind kind, 585 Snapshot::Kind kind,
637 bool as_reference) { 586 bool as_reference) {
638 ASSERT(reader != NULL); 587 ASSERT(reader != NULL);
639 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 588 ASSERT(kind == Snapshot::kScript);
640 589
641 // Allocate closure data object. 590 // Allocate closure data object.
642 ClosureData& data = ClosureData::ZoneHandle( 591 ClosureData& data = ClosureData::ZoneHandle(reader->zone(),
643 reader->zone(), NEW_OBJECT(ClosureData)); 592 ClosureData::New());
644 reader->AddBackRef(object_id, &data, kIsDeserialized); 593 reader->AddBackRef(object_id, &data, kIsDeserialized);
645 594
646 // Set all the object fields. 595 // Set all the object fields.
647 READ_OBJECT_FIELDS(data, 596 READ_OBJECT_FIELDS(data,
648 data.raw()->from(), data.raw()->to(), 597 data.raw()->from(), data.raw()->to(),
649 kAsInlinedObject); 598 kAsInlinedObject);
650 599
651 return data.raw(); 600 return data.raw();
652 } 601 }
653 602
654 603
655 void RawClosureData::WriteTo(SnapshotWriter* writer, 604 void RawClosureData::WriteTo(SnapshotWriter* writer,
656 intptr_t object_id, 605 intptr_t object_id,
657 Snapshot::Kind kind, 606 Snapshot::Kind kind,
658 bool as_reference) { 607 bool as_reference) {
659 ASSERT(writer != NULL); 608 ASSERT(writer != NULL);
660 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 609 ASSERT(kind == Snapshot::kScript);
661 610
662 // Write out the serialization header value for this object. 611 // Write out the serialization header value for this object.
663 writer->WriteInlinedObjectHeader(object_id); 612 writer->WriteInlinedObjectHeader(object_id);
664 613
665 // Write out the class and tags information. 614 // Write out the class and tags information.
666 writer->WriteVMIsolateObject(kClosureDataCid); 615 writer->WriteVMIsolateObject(kClosureDataCid);
667 writer->WriteTags(writer->GetObjectTags(this)); 616 writer->WriteTags(writer->GetObjectTags(this));
668 617
669 // Context scope. 618 // Context scope.
670 if (ptr()->context_scope_ == Object::empty_context_scope().raw()) { 619 if (ptr()->context_scope_ == Object::empty_context_scope().raw()) {
671 writer->WriteVMIsolateObject(kEmptyContextScopeObject); 620 writer->WriteVMIsolateObject(kEmptyContextScopeObject);
672 } else if (ptr()->context_scope_->ptr()->is_implicit_ || 621 } else if (ptr()->context_scope_->ptr()->is_implicit_) {
673 (kind == Snapshot::kAppWithJIT)) {
674 writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject); 622 writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject);
675 } else { 623 } else {
676 // We don't write non implicit context scopes in the snapshot. 624 // We don't write non implicit context scopes in the snapshot.
677 writer->WriteVMIsolateObject(kNullObject); 625 writer->WriteVMIsolateObject(kNullObject);
678 } 626 }
679 627
680 // Parent function. 628 // Parent function.
681 writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject); 629 writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject);
682 630
683 // Signature type. 631 // Signature type.
684 writer->WriteObjectImpl(ptr()->signature_type_, kAsInlinedObject); 632 writer->WriteObjectImpl(ptr()->signature_type_, kAsInlinedObject);
685 633
686 // Canonical static closure. 634 // Canonical static closure.
687 writer->WriteObjectImpl(ptr()->closure_, kAsInlinedObject); 635 writer->WriteObjectImpl(ptr()->closure_, kAsInlinedObject);
688 } 636 }
689 637
690 638
691 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, 639 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader,
692 intptr_t object_id, 640 intptr_t object_id,
693 intptr_t tags, 641 intptr_t tags,
694 Snapshot::Kind kind, 642 Snapshot::Kind kind,
695 bool as_reference) { 643 bool as_reference) {
696 ASSERT(reader != NULL); 644 ASSERT(reader != NULL);
697 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 645 ASSERT(kind == Snapshot::kScript);
698 646
699 // Allocate redirection data object. 647 // Allocate redirection data object.
700 RedirectionData& data = RedirectionData::ZoneHandle( 648 RedirectionData& data = RedirectionData::ZoneHandle(reader->zone(),
701 reader->zone(), NEW_OBJECT(RedirectionData)); 649 RedirectionData::New());
702 reader->AddBackRef(object_id, &data, kIsDeserialized); 650 reader->AddBackRef(object_id, &data, kIsDeserialized);
703 651
704 // Set all the object fields. 652 // Set all the object fields.
705 READ_OBJECT_FIELDS(data, 653 READ_OBJECT_FIELDS(data,
706 data.raw()->from(), data.raw()->to(), 654 data.raw()->from(), data.raw()->to(),
707 kAsReference); 655 kAsReference);
708 656
709 return data.raw(); 657 return data.raw();
710 } 658 }
711 659
712 660
713 void RawRedirectionData::WriteTo(SnapshotWriter* writer, 661 void RawRedirectionData::WriteTo(SnapshotWriter* writer,
714 intptr_t object_id, 662 intptr_t object_id,
715 Snapshot::Kind kind, 663 Snapshot::Kind kind,
716 bool as_reference) { 664 bool as_reference) {
717 ASSERT(writer != NULL); 665 ASSERT(writer != NULL);
718 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 666 ASSERT(kind == Snapshot::kScript);
719 667
720 // Write out the serialization header value for this object. 668 // Write out the serialization header value for this object.
721 writer->WriteInlinedObjectHeader(object_id); 669 writer->WriteInlinedObjectHeader(object_id);
722 670
723 // Write out the class and tags information. 671 // Write out the class and tags information.
724 writer->WriteVMIsolateObject(kRedirectionDataCid); 672 writer->WriteVMIsolateObject(kRedirectionDataCid);
725 writer->WriteTags(writer->GetObjectTags(this)); 673 writer->WriteTags(writer->GetObjectTags(this));
726 674
727 // Write out all the object pointer fields. 675 // Write out all the object pointer fields.
728 SnapshotWriterVisitor visitor(writer, kAsReference); 676 SnapshotWriterVisitor visitor(writer, kAsReference);
729 visitor.VisitPointers(from(), to()); 677 visitor.VisitPointers(from(), to());
730 } 678 }
731 679
732 680
733 RawFunction* Function::ReadFrom(SnapshotReader* reader, 681 RawFunction* Function::ReadFrom(SnapshotReader* reader,
734 intptr_t object_id, 682 intptr_t object_id,
735 intptr_t tags, 683 intptr_t tags,
736 Snapshot::Kind kind, 684 Snapshot::Kind kind,
737 bool as_reference) { 685 bool as_reference) {
738 ASSERT(reader != NULL); 686 ASSERT(reader != NULL);
739 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 687 ASSERT(kind == Snapshot::kScript);
740 688
741 bool is_in_fullsnapshot = reader->Read<bool>(); 689 bool is_in_fullsnapshot = reader->Read<bool>();
742 if ((Snapshot::IsFull(kind)) || !is_in_fullsnapshot) { 690 if (!is_in_fullsnapshot) {
743 // Allocate function object. 691 // Allocate function object.
744 Function& func = Function::ZoneHandle( 692 Function& func = Function::ZoneHandle(reader->zone(),
745 reader->zone(), NEW_OBJECT(Function)); 693 Function::New());
746 reader->AddBackRef(object_id, &func, kIsDeserialized); 694 reader->AddBackRef(object_id, &func, kIsDeserialized);
747 695
748 // Set all the non object fields. Read the token positions now but 696 // Set all the non object fields. Read the token positions now but
749 // don't set them until after setting the kind. 697 // don't set them until after setting the kind.
750 const int32_t token_pos = reader->Read<int32_t>(); 698 const int32_t token_pos = reader->Read<int32_t>();
751 const int32_t end_token_pos = reader->Read<uint32_t>(); 699 const int32_t end_token_pos = reader->Read<uint32_t>();
752 func.set_num_fixed_parameters(reader->Read<int16_t>()); 700 func.set_num_fixed_parameters(reader->Read<int16_t>());
753 func.set_num_optional_parameters(reader->Read<int16_t>()); 701 func.set_num_optional_parameters(reader->Read<int16_t>());
754 func.set_kind_tag(reader->Read<uint32_t>()); 702 func.set_kind_tag(reader->Read<uint32_t>());
755 func.set_token_pos(TokenPosition::SnapshotDecode(token_pos)); 703 func.set_token_pos(TokenPosition::SnapshotDecode(token_pos));
756 func.set_end_token_pos(TokenPosition::SnapshotDecode(end_token_pos)); 704 func.set_end_token_pos(TokenPosition::SnapshotDecode(end_token_pos));
757 if (kind == Snapshot::kAppNoJIT) { 705 func.set_usage_counter(reader->Read<int32_t>());
758 func.set_usage_counter(0); 706 func.set_deoptimization_counter(reader->Read<int8_t>());
759 func.set_deoptimization_counter(0); 707 func.set_optimized_instruction_count(reader->Read<uint16_t>());
760 func.set_optimized_instruction_count(0); 708 func.set_optimized_call_site_count(reader->Read<uint16_t>());
761 func.set_optimized_call_site_count(0);
762 } else {
763 func.set_usage_counter(reader->Read<int32_t>());
764 func.set_deoptimization_counter(reader->Read<int8_t>());
765 func.set_optimized_instruction_count(reader->Read<uint16_t>());
766 func.set_optimized_call_site_count(reader->Read<uint16_t>());
767 }
768 func.set_was_compiled(false); 709 func.set_was_compiled(false);
769 710
770 // Set all the object fields. 711 // Set all the object fields.
771 READ_OBJECT_FIELDS(func, 712 READ_OBJECT_FIELDS(func,
772 func.raw()->from(), func.raw()->to_snapshot(), 713 func.raw()->from(), func.raw()->to_snapshot(),
773 kAsReference); 714 kAsReference);
774 // Initialize all fields that are not part of the snapshot. 715 // Initialize all fields that are not part of the snapshot.
775 if (kind == Snapshot::kAppNoJIT) { 716 bool is_optimized = func.usage_counter() != 0;
776 // Read the code object and fixup entry point. 717 if (is_optimized) {
777 func.ClearICDataArray(); 718 // Read the ic data array as the function is an optimized one.
778 func.ClearCode();
779 (*reader->CodeHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
780 func.SetInstructions(*reader->CodeHandle());
781 } else if (kind == Snapshot::kAppWithJIT) {
782 (*reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsReference); 719 (*reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsReference);
783 func.set_ic_data_array(*reader->ArrayHandle()); 720 func.set_ic_data_array(*reader->ArrayHandle());
784 (*reader->CodeHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
785 func.set_unoptimized_code(*reader->CodeHandle());
786 if (!reader->CodeHandle()->IsNull()) {
787 func.SetInstructions(*reader->CodeHandle());
788 func.set_was_compiled(true);
789 } else {
790 func.ClearCode();
791 }
792 } else { 721 } else {
793 bool is_optimized = func.usage_counter() != 0; 722 func.ClearICDataArray();
794 if (is_optimized) {
795 // Read the ic data array as the function is an optimized one.
796 (*reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsReference);
797 func.set_ic_data_array(*reader->ArrayHandle());
798 } else {
799 func.ClearICDataArray();
800 }
801 func.ClearCode();
802 } 723 }
724 func.ClearCode();
803 return func.raw(); 725 return func.raw();
804 } else { 726 } else {
805 return reader->ReadFunctionId(object_id); 727 return reader->ReadFunctionId(object_id);
806 } 728 }
807 } 729 }
808 730
809 731
810 void RawFunction::WriteTo(SnapshotWriter* writer, 732 void RawFunction::WriteTo(SnapshotWriter* writer,
811 intptr_t object_id, 733 intptr_t object_id,
812 Snapshot::Kind kind, 734 Snapshot::Kind kind,
813 bool as_reference) { 735 bool as_reference) {
814 ASSERT(writer != NULL); 736 ASSERT(writer != NULL);
815 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 737 ASSERT(kind == Snapshot::kScript);
816 bool is_in_fullsnapshot = false; 738 bool is_in_fullsnapshot = false;
817 bool owner_is_class = false; 739 bool owner_is_class = false;
818 if ((kind == Snapshot::kScript) && !Function::IsSignatureFunction(this)) { 740 if ((kind == Snapshot::kScript) && !Function::IsSignatureFunction(this)) {
819 intptr_t tags = writer->GetObjectTags(ptr()->owner_); 741 intptr_t tags = writer->GetObjectTags(ptr()->owner_);
820 intptr_t cid = ClassIdTag::decode(tags); 742 intptr_t cid = ClassIdTag::decode(tags);
821 owner_is_class = (cid == kClassCid); 743 owner_is_class = (cid == kClassCid);
822 is_in_fullsnapshot = owner_is_class ? 744 is_in_fullsnapshot = owner_is_class ?
823 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) : 745 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) :
824 PatchClass::IsInFullSnapshot( 746 PatchClass::IsInFullSnapshot(
825 reinterpret_cast<RawPatchClass*>(ptr()->owner_)); 747 reinterpret_cast<RawPatchClass*>(ptr()->owner_));
826 } 748 }
827 749
828 // Write out the serialization header value for this object. 750 // Write out the serialization header value for this object.
829 writer->WriteInlinedObjectHeader(object_id); 751 writer->WriteInlinedObjectHeader(object_id);
830 752
831 // Write out the class and tags information. 753 // Write out the class and tags information.
832 writer->WriteVMIsolateObject(kFunctionCid); 754 writer->WriteVMIsolateObject(kFunctionCid);
833 writer->WriteTags(writer->GetObjectTags(this)); 755 writer->WriteTags(writer->GetObjectTags(this));
834 756
835 // Write out the boolean is_in_fullsnapshot first as this will 757 // Write out the boolean is_in_fullsnapshot first as this will
836 // help the reader decide how the rest of the information needs 758 // help the reader decide how the rest of the information needs
837 // to be interpreted. 759 // to be interpreted.
838 writer->Write<bool>(is_in_fullsnapshot); 760 writer->Write<bool>(is_in_fullsnapshot);
839 761
840 if (Snapshot::IsFull(kind) || !is_in_fullsnapshot) { 762 if (!is_in_fullsnapshot) {
841 bool is_optimized = Code::IsOptimized(ptr()->code_); 763 bool is_optimized = Code::IsOptimized(ptr()->code_);
842 764
843 // Write out all the non object fields. 765 // Write out all the non object fields.
844 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); 766 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode());
845 writer->Write<int32_t>(ptr()->end_token_pos_.SnapshotEncode()); 767 writer->Write<int32_t>(ptr()->end_token_pos_.SnapshotEncode());
846 writer->Write<int16_t>(ptr()->num_fixed_parameters_); 768 writer->Write<int16_t>(ptr()->num_fixed_parameters_);
847 writer->Write<int16_t>(ptr()->num_optional_parameters_); 769 writer->Write<int16_t>(ptr()->num_optional_parameters_);
848 writer->Write<uint32_t>(ptr()->kind_tag_); 770 writer->Write<uint32_t>(ptr()->kind_tag_);
849 if (kind == Snapshot::kAppNoJIT) { 771 if (is_optimized) {
850 // Omit fields used to support de/reoptimization. 772 writer->Write<int32_t>(FLAG_optimization_counter_threshold);
851 } else { 773 } else {
852 if (is_optimized) { 774 writer->Write<int32_t>(0);
853 writer->Write<int32_t>(FLAG_optimization_counter_threshold);
854 } else {
855 writer->Write<int32_t>(0);
856 }
857 writer->Write<int8_t>(ptr()->deoptimization_counter_);
858 writer->Write<uint16_t>(ptr()->optimized_instruction_count_);
859 writer->Write<uint16_t>(ptr()->optimized_call_site_count_);
860 } 775 }
776 writer->Write<int8_t>(ptr()->deoptimization_counter_);
777 writer->Write<uint16_t>(ptr()->optimized_instruction_count_);
778 writer->Write<uint16_t>(ptr()->optimized_call_site_count_);
861 779
862 // Write out all the object pointer fields. 780 // Write out all the object pointer fields.
863 SnapshotWriterVisitor visitor(writer, kAsReference); 781 SnapshotWriterVisitor visitor(writer, kAsReference);
864 visitor.VisitPointers(from(), to_snapshot()); 782 visitor.VisitPointers(from(), to_snapshot());
865 if (kind == Snapshot::kAppNoJIT) { 783 if (is_optimized) {
866 ASSERT(ptr()->ic_data_array_ == Array::null());
867 ASSERT((ptr()->code_ == ptr()->unoptimized_code_) ||
868 (ptr()->unoptimized_code_ == Code::null()));
869 writer->WriteObjectImpl(ptr()->code_, kAsInlinedObject);
870 } else if (kind == Snapshot::kAppWithJIT) {
871 writer->WriteObjectImpl(ptr()->ic_data_array_, kAsReference);
872 writer->WriteObjectImpl(ptr()->unoptimized_code_, kAsInlinedObject);
873 } else if (is_optimized) {
874 // Write out the ic data array as the function is optimized. 784 // Write out the ic data array as the function is optimized.
875 writer->WriteObjectImpl(ptr()->ic_data_array_, kAsReference); 785 writer->WriteObjectImpl(ptr()->ic_data_array_, kAsReference);
876 } 786 }
877 } else { 787 } else {
878 writer->WriteFunctionId(this, owner_is_class); 788 writer->WriteFunctionId(this, owner_is_class);
879 } 789 }
880 } 790 }
881 791
882 792
883 RawField* Field::ReadFrom(SnapshotReader* reader, 793 RawField* Field::ReadFrom(SnapshotReader* reader,
884 intptr_t object_id, 794 intptr_t object_id,
885 intptr_t tags, 795 intptr_t tags,
886 Snapshot::Kind kind, 796 Snapshot::Kind kind,
887 bool as_reference) { 797 bool as_reference) {
888 ASSERT(reader != NULL); 798 ASSERT(reader != NULL);
889 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 799 ASSERT(kind == Snapshot::kScript);
890 800
891 // Allocate field object. 801 // Allocate field object.
892 Field& field = Field::ZoneHandle(reader->zone(), NEW_OBJECT(Field)); 802 Field& field = Field::ZoneHandle(reader->zone(), Field::New());
893 reader->AddBackRef(object_id, &field, kIsDeserialized); 803 reader->AddBackRef(object_id, &field, kIsDeserialized);
894 804
895 // Set all non object fields. 805 // Set all non object fields.
896 if (kind == Snapshot::kAppNoJIT) { 806 field.set_token_pos(
897 field.set_token_pos(TokenPosition::kNoSource); 807 TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
898 ASSERT(!FLAG_use_field_guards); 808 field.set_guarded_cid(reader->Read<int32_t>());
899 } else { 809 field.set_is_nullable(reader->Read<int32_t>());
900 field.set_token_pos(
901 TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
902 field.set_guarded_cid(reader->Read<int32_t>());
903 field.set_is_nullable(reader->Read<int32_t>());
904 }
905 field.set_kind_bits(reader->Read<uint8_t>()); 810 field.set_kind_bits(reader->Read<uint8_t>());
906 811
907 // Set all the object fields. 812 // Set all the object fields.
908 READ_OBJECT_FIELDS(field, 813 READ_OBJECT_FIELDS(field,
909 field.raw()->from(), 814 field.raw()->from(),
910 field.raw()->to_snapshot(kind), 815 field.raw()->to_snapshot(kind),
911 kAsReference); 816 kAsReference);
912 field.StorePointer(&field.raw_ptr()->dependent_code_, Array::null()); 817 field.StorePointer(&field.raw_ptr()->dependent_code_, Array::null());
913 818
914 if (!FLAG_use_field_guards) { 819 if (!FLAG_use_field_guards) {
915 field.set_guarded_cid(kDynamicCid); 820 field.set_guarded_cid(kDynamicCid);
916 field.set_is_nullable(true); 821 field.set_is_nullable(true);
917 field.set_guarded_list_length(Field::kNoFixedLength); 822 field.set_guarded_list_length(Field::kNoFixedLength);
918 field.set_guarded_list_length_in_object_offset(Field::kUnknownLengthOffset); 823 field.set_guarded_list_length_in_object_offset(Field::kUnknownLengthOffset);
919 } else { 824 } else {
920 field.InitializeGuardedListLengthInObjectOffset(); 825 field.InitializeGuardedListLengthInObjectOffset();
921 } 826 }
922 827
923 return field.raw(); 828 return field.raw();
924 } 829 }
925 830
926 831
927 void RawField::WriteTo(SnapshotWriter* writer, 832 void RawField::WriteTo(SnapshotWriter* writer,
928 intptr_t object_id, 833 intptr_t object_id,
929 Snapshot::Kind kind, 834 Snapshot::Kind kind,
930 bool as_reference) { 835 bool as_reference) {
931 ASSERT(writer != NULL); 836 ASSERT(writer != NULL);
932 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 837 ASSERT(kind == Snapshot::kScript);
933 838
934 // Write out the serialization header value for this object. 839 // Write out the serialization header value for this object.
935 writer->WriteInlinedObjectHeader(object_id); 840 writer->WriteInlinedObjectHeader(object_id);
936 841
937 // Write out the class and tags information. 842 // Write out the class and tags information.
938 writer->WriteVMIsolateObject(kFieldCid); 843 writer->WriteVMIsolateObject(kFieldCid);
939 writer->WriteTags(writer->GetObjectTags(this)); 844 writer->WriteTags(writer->GetObjectTags(this));
940 845
941 // Write out all the non object fields. 846 // Write out all the non object fields.
942 if (kind != Snapshot::kAppNoJIT) { 847 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode());
943 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); 848 writer->Write<int32_t>(ptr()->guarded_cid_);
944 writer->Write<int32_t>(ptr()->guarded_cid_); 849 writer->Write<int32_t>(ptr()->is_nullable_);
945 writer->Write<int32_t>(ptr()->is_nullable_);
946 }
947 writer->Write<uint8_t>(ptr()->kind_bits_); 850 writer->Write<uint8_t>(ptr()->kind_bits_);
948 851
949 // Write out the name. 852 // Write out the name.
950 writer->WriteObjectImpl(ptr()->name_, kAsReference); 853 writer->WriteObjectImpl(ptr()->name_, kAsReference);
951 // Write out the owner. 854 // Write out the owner.
952 writer->WriteObjectImpl(ptr()->owner_, kAsReference); 855 writer->WriteObjectImpl(ptr()->owner_, kAsReference);
953 // Write out the type. 856 // Write out the type.
954 writer->WriteObjectImpl(ptr()->type_, kAsReference); 857 writer->WriteObjectImpl(ptr()->type_, kAsReference);
955 // Write out the initial static value or field offset. 858 // Write out the initial static value or field offset.
956 if (Field::StaticBit::decode(ptr()->kind_bits_)) { 859 if (Field::StaticBit::decode(ptr()->kind_bits_)) {
957 if (kind == Snapshot::kAppNoJIT) { 860 if (Field::ConstBit::decode(ptr()->kind_bits_)) {
958 // For precompiled static fields, the value was already reset and
959 // initializer_ now contains a Function.
960 writer->WriteObjectImpl(ptr()->value_.static_value_, kAsReference);
961 } else if (Field::ConstBit::decode(ptr()->kind_bits_)) {
962 // Do not reset const fields. 861 // Do not reset const fields.
963 writer->WriteObjectImpl(ptr()->value_.static_value_, kAsReference); 862 writer->WriteObjectImpl(ptr()->value_.static_value_, kAsReference);
964 } else { 863 } else {
965 // Otherwise, for static fields we write out the initial static value. 864 // Otherwise, for static fields we write out the initial static value.
966 writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference); 865 writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference);
967 } 866 }
968 } else { 867 } else {
969 writer->WriteObjectImpl(ptr()->value_.offset_, kAsReference); 868 writer->WriteObjectImpl(ptr()->value_.offset_, kAsReference);
970 } 869 }
971 // Write out the initializer function or saved initial value. 870 // Write out the initializer function or saved initial value.
972 if (kind == Snapshot::kAppNoJIT) { 871 writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference);
973 writer->WriteObjectImpl(ptr()->initializer_.precompiled_, kAsReference); 872 // Write out the guarded list length.
974 } else { 873 writer->WriteObjectImpl(ptr()->guarded_list_length_, kAsReference);
975 writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference);
976 }
977 if (kind != Snapshot::kAppNoJIT) {
978 // Write out the guarded list length.
979 writer->WriteObjectImpl(ptr()->guarded_list_length_, kAsReference);
980 }
981 } 874 }
982 875
983 876
984 RawLiteralToken* LiteralToken::ReadFrom(SnapshotReader* reader, 877 RawLiteralToken* LiteralToken::ReadFrom(SnapshotReader* reader,
985 intptr_t object_id, 878 intptr_t object_id,
986 intptr_t tags, 879 intptr_t tags,
987 Snapshot::Kind kind, 880 Snapshot::Kind kind,
988 bool as_reference) { 881 bool as_reference) {
989 ASSERT(reader != NULL); 882 ASSERT(reader != NULL);
990 ASSERT(kind != Snapshot::kMessage); 883 ASSERT(kind != Snapshot::kMessage);
991 884
992 // Create the literal token object. 885 // Create the literal token object.
993 LiteralToken& literal_token = LiteralToken::ZoneHandle( 886 LiteralToken& literal_token = LiteralToken::ZoneHandle(reader->zone(),
994 reader->zone(), NEW_OBJECT(LiteralToken)); 887 LiteralToken::New());
995 reader->AddBackRef(object_id, &literal_token, kIsDeserialized); 888 reader->AddBackRef(object_id, &literal_token, kIsDeserialized);
996 889
997 // Read the token attributes. 890 // Read the token attributes.
998 Token::Kind token_kind = static_cast<Token::Kind>(reader->Read<int32_t>()); 891 Token::Kind token_kind = static_cast<Token::Kind>(reader->Read<int32_t>());
999 literal_token.set_kind(token_kind); 892 literal_token.set_kind(token_kind);
1000 893
1001 // Set all the object fields. 894 // Set all the object fields.
1002 READ_OBJECT_FIELDS(literal_token, 895 READ_OBJECT_FIELDS(literal_token,
1003 literal_token.raw()->from(), literal_token.raw()->to(), 896 literal_token.raw()->from(), literal_token.raw()->to(),
1004 kAsReference); 897 kAsReference);
(...skipping 24 matching lines...) Expand all
1029 visitor.VisitPointers(from(), to()); 922 visitor.VisitPointers(from(), to());
1030 } 923 }
1031 924
1032 925
1033 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, 926 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader,
1034 intptr_t object_id, 927 intptr_t object_id,
1035 intptr_t tags, 928 intptr_t tags,
1036 Snapshot::Kind kind, 929 Snapshot::Kind kind,
1037 bool as_reference) { 930 bool as_reference) {
1038 ASSERT(reader != NULL); 931 ASSERT(reader != NULL);
1039 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 932 ASSERT(kind == Snapshot::kScript);
1040 933
1041 // Read the length so that we can determine number of tokens to read. 934 // Read the length so that we can determine number of tokens to read.
1042 intptr_t len = reader->ReadSmiValue(); 935 intptr_t len = reader->ReadSmiValue();
1043 936
1044 // Create the token stream object. 937 // Create the token stream object.
1045 TokenStream& token_stream = TokenStream::ZoneHandle( 938 TokenStream& token_stream = TokenStream::ZoneHandle(reader->zone(),
1046 reader->zone(), NEW_OBJECT_WITH_LEN(TokenStream, len)); 939 TokenStream::New(len));
1047 reader->AddBackRef(object_id, &token_stream, kIsDeserialized); 940 reader->AddBackRef(object_id, &token_stream, kIsDeserialized);
1048 941
1049 // Read the stream of tokens into the TokenStream object for script 942 // Read the stream of tokens into the TokenStream object for script
1050 // snapshots as we made a copy of token stream. 943 // snapshots as we made a copy of token stream.
1051 if (kind == Snapshot::kScript) { 944 if (kind == Snapshot::kScript) {
1052 NoSafepointScope no_safepoint; 945 NoSafepointScope no_safepoint;
1053 RawExternalTypedData* stream = token_stream.GetStream(); 946 RawExternalTypedData* stream = token_stream.GetStream();
1054 reader->ReadBytes(stream->ptr()->data_, len); 947 reader->ReadBytes(stream->ptr()->data_, len);
1055 } 948 }
1056 949
1057 // Read in the literal/identifier token array. 950 // Read in the literal/identifier token array.
1058 *(reader->TokensHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); 951 *(reader->TokensHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
1059 token_stream.SetTokenObjects(*(reader->TokensHandle())); 952 token_stream.SetTokenObjects(*(reader->TokensHandle()));
1060 // Read in the private key in use by the token stream. 953 // Read in the private key in use by the token stream.
1061 *(reader->StringHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); 954 *(reader->StringHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
1062 token_stream.SetPrivateKey(*(reader->StringHandle())); 955 token_stream.SetPrivateKey(*(reader->StringHandle()));
1063 956
1064 return token_stream.raw(); 957 return token_stream.raw();
1065 } 958 }
1066 959
1067 960
1068 void RawTokenStream::WriteTo(SnapshotWriter* writer, 961 void RawTokenStream::WriteTo(SnapshotWriter* writer,
1069 intptr_t object_id, 962 intptr_t object_id,
1070 Snapshot::Kind kind, 963 Snapshot::Kind kind,
1071 bool as_reference) { 964 bool as_reference) {
1072 ASSERT(writer != NULL); 965 ASSERT(writer != NULL);
1073 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 966 ASSERT(kind == Snapshot::kScript);
1074 967
1075 // Write out the serialization header value for this object. 968 // Write out the serialization header value for this object.
1076 writer->WriteInlinedObjectHeader(object_id); 969 writer->WriteInlinedObjectHeader(object_id);
1077 970
1078 // Write out the class and tags information. 971 // Write out the class and tags information.
1079 writer->WriteVMIsolateObject(kTokenStreamCid); 972 writer->WriteVMIsolateObject(kTokenStreamCid);
1080 writer->WriteTags(writer->GetObjectTags(this)); 973 writer->WriteTags(writer->GetObjectTags(this));
1081 974
1082 // Write out the length field and the token stream. 975 // Write out the length field and the token stream.
1083 RawExternalTypedData* stream = ptr()->stream_; 976 RawExternalTypedData* stream = ptr()->stream_;
1084 intptr_t len = Smi::Value(stream->ptr()->length_); 977 intptr_t len = Smi::Value(stream->ptr()->length_);
1085 writer->Write<RawObject*>(stream->ptr()->length_); 978 writer->Write<RawObject*>(stream->ptr()->length_);
1086 writer->WriteBytes(stream->ptr()->data_, len); 979 writer->WriteBytes(stream->ptr()->data_, len);
1087 980
1088 // Write out the literal/identifier token array. 981 // Write out the literal/identifier token array.
1089 writer->WriteObjectImpl(ptr()->token_objects_, kAsInlinedObject); 982 writer->WriteObjectImpl(ptr()->token_objects_, kAsInlinedObject);
1090 // Write out the private key in use by the token stream. 983 // Write out the private key in use by the token stream.
1091 writer->WriteObjectImpl(ptr()->private_key_, kAsInlinedObject); 984 writer->WriteObjectImpl(ptr()->private_key_, kAsInlinedObject);
1092 } 985 }
1093 986
1094 987
1095 RawScript* Script::ReadFrom(SnapshotReader* reader, 988 RawScript* Script::ReadFrom(SnapshotReader* reader,
1096 intptr_t object_id, 989 intptr_t object_id,
1097 intptr_t tags, 990 intptr_t tags,
1098 Snapshot::Kind kind, 991 Snapshot::Kind kind,
1099 bool as_reference) { 992 bool as_reference) {
1100 ASSERT(reader != NULL); 993 ASSERT(reader != NULL);
1101 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 994 ASSERT(kind == Snapshot::kScript);
1102 995
1103 // Allocate script object. 996 // Allocate script object.
1104 Script& script = Script::ZoneHandle(reader->zone(), NEW_OBJECT(Script)); 997 Script& script = Script::ZoneHandle(reader->zone(), Script::New());
1105 reader->AddBackRef(object_id, &script, kIsDeserialized); 998 reader->AddBackRef(object_id, &script, kIsDeserialized);
1106 999
1107 script.StoreNonPointer(&script.raw_ptr()->line_offset_, 1000 script.StoreNonPointer(&script.raw_ptr()->line_offset_,
1108 reader->Read<int32_t>()); 1001 reader->Read<int32_t>());
1109 script.StoreNonPointer(&script.raw_ptr()->col_offset_, 1002 script.StoreNonPointer(&script.raw_ptr()->col_offset_,
1110 reader->Read<int32_t>()); 1003 reader->Read<int32_t>());
1111 script.StoreNonPointer(&script.raw_ptr()->kind_, 1004 script.StoreNonPointer(&script.raw_ptr()->kind_,
1112 reader->Read<int8_t>()); 1005 reader->Read<int8_t>());
1113 1006
1114 *reader->StringHandle() ^= String::null(); 1007 *reader->StringHandle() ^= String::null();
(...skipping 17 matching lines...) Expand all
1132 return script.raw(); 1025 return script.raw();
1133 } 1026 }
1134 1027
1135 1028
1136 void RawScript::WriteTo(SnapshotWriter* writer, 1029 void RawScript::WriteTo(SnapshotWriter* writer,
1137 intptr_t object_id, 1030 intptr_t object_id,
1138 Snapshot::Kind kind, 1031 Snapshot::Kind kind,
1139 bool as_reference) { 1032 bool as_reference) {
1140 ASSERT(writer != NULL); 1033 ASSERT(writer != NULL);
1141 ASSERT(tokens_ != TokenStream::null()); 1034 ASSERT(tokens_ != TokenStream::null());
1142 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 1035 ASSERT(kind == Snapshot::kScript);
1143 1036
1144 // Write out the serialization header value for this object. 1037 // Write out the serialization header value for this object.
1145 writer->WriteInlinedObjectHeader(object_id); 1038 writer->WriteInlinedObjectHeader(object_id);
1146 1039
1147 // Write out the class and tags information. 1040 // Write out the class and tags information.
1148 writer->WriteVMIsolateObject(kScriptCid); 1041 writer->WriteVMIsolateObject(kScriptCid);
1149 writer->WriteTags(writer->GetObjectTags(this)); 1042 writer->WriteTags(writer->GetObjectTags(this));
1150 1043
1151 // Write out all the non object fields. 1044 // Write out all the non object fields.
1152 writer->Write<int32_t>(ptr()->line_offset_); 1045 writer->Write<int32_t>(ptr()->line_offset_);
(...skipping 18 matching lines...) Expand all
1171 reader->AddBackRef(object_id, &library, kIsDeserialized); 1064 reader->AddBackRef(object_id, &library, kIsDeserialized);
1172 1065
1173 bool is_in_fullsnapshot = reader->Read<bool>(); 1066 bool is_in_fullsnapshot = reader->Read<bool>();
1174 if ((kind == Snapshot::kScript) && is_in_fullsnapshot) { 1067 if ((kind == Snapshot::kScript) && is_in_fullsnapshot) {
1175 // Lookup the object as it should already exist in the heap. 1068 // Lookup the object as it should already exist in the heap.
1176 *reader->StringHandle() ^= reader->ReadObjectImpl(kAsInlinedObject); 1069 *reader->StringHandle() ^= reader->ReadObjectImpl(kAsInlinedObject);
1177 library = Library::LookupLibrary(reader->thread(), *reader->StringHandle()); 1070 library = Library::LookupLibrary(reader->thread(), *reader->StringHandle());
1178 ASSERT(library.is_in_fullsnapshot()); 1071 ASSERT(library.is_in_fullsnapshot());
1179 } else { 1072 } else {
1180 // Allocate library object. 1073 // Allocate library object.
1181 library = NEW_OBJECT(Library); 1074 library = Library::New();
1182 1075
1183 // Set all non object fields. 1076 // Set all non object fields.
1184 library.StoreNonPointer(&library.raw_ptr()->index_, 1077 library.StoreNonPointer(&library.raw_ptr()->index_,
1185 reader->ReadClassIDValue()); 1078 reader->ReadClassIDValue());
1186 library.StoreNonPointer(&library.raw_ptr()->num_imports_, 1079 library.StoreNonPointer(&library.raw_ptr()->num_imports_,
1187 reader->Read<uint16_t>()); 1080 reader->Read<uint16_t>());
1188 library.StoreNonPointer(&library.raw_ptr()->load_state_, 1081 library.StoreNonPointer(&library.raw_ptr()->load_state_,
1189 reader->Read<int8_t>()); 1082 reader->Read<int8_t>());
1190 library.StoreNonPointer(&library.raw_ptr()->corelib_imported_, 1083 library.StoreNonPointer(&library.raw_ptr()->corelib_imported_,
1191 reader->Read<bool>()); 1084 reader->Read<bool>());
1192 library.StoreNonPointer(&library.raw_ptr()->is_dart_scheme_, 1085 library.StoreNonPointer(&library.raw_ptr()->is_dart_scheme_,
1193 reader->Read<bool>()); 1086 reader->Read<bool>());
1194 library.StoreNonPointer(&library.raw_ptr()->debuggable_, 1087 library.StoreNonPointer(&library.raw_ptr()->debuggable_,
1195 reader->Read<bool>()); 1088 reader->Read<bool>());
1196 if (Snapshot::IsFull(kind)) {
1197 is_in_fullsnapshot = true;
1198 }
1199 library.StoreNonPointer(&library.raw_ptr()->is_in_fullsnapshot_, 1089 library.StoreNonPointer(&library.raw_ptr()->is_in_fullsnapshot_,
1200 is_in_fullsnapshot); 1090 is_in_fullsnapshot);
1201 // The native resolver and symbolizer are not serialized. 1091 // The native resolver and symbolizer are not serialized.
1202 library.set_native_entry_resolver(NULL); 1092 library.set_native_entry_resolver(NULL);
1203 library.set_native_entry_symbol_resolver(NULL); 1093 library.set_native_entry_symbol_resolver(NULL);
1204 1094
1205 // Set all the object fields. 1095 // Set all the object fields.
1206 // TODO(5411462): Need to assert No GC can happen here, even though 1096 // TODO(5411462): Need to assert No GC can happen here, even though
1207 // allocations may happen. 1097 // allocations may happen.
1208 intptr_t num_flds = (library.raw()->to_snapshot() - library.raw()->from()); 1098 intptr_t num_flds = (library.raw()->to_snapshot() - library.raw()->from());
1209 for (intptr_t i = 0; i <= num_flds; i++) { 1099 for (intptr_t i = 0; i <= num_flds; i++) {
1210 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); 1100 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1211 library.StorePointer((library.raw()->from() + i), 1101 library.StorePointer((library.raw()->from() + i),
1212 reader->PassiveObjectHandle()->raw()); 1102 reader->PassiveObjectHandle()->raw());
1213 } 1103 }
1214 // Initialize cache of resolved names. 1104 // Initialize cache of resolved names.
1215 const intptr_t kInitialNameCacheSize = 64; 1105 const intptr_t kInitialNameCacheSize = 64;
1216 if (!Snapshot::IsFull(kind)) { 1106 // The cache of resolved names in library scope is not serialized.
1217 // The cache of resolved names in library scope is not serialized. 1107 library.InitResolvedNamesCache(kInitialNameCacheSize);
1218 library.InitResolvedNamesCache(kInitialNameCacheSize); 1108 library.Register(reader->thread());
1219 library.Register(reader->thread());
1220 } else {
1221 library.InitResolvedNamesCache(kInitialNameCacheSize, reader);
1222 }
1223 library.StorePointer(&library.raw_ptr()->exported_names_, Array::null()); 1109 library.StorePointer(&library.raw_ptr()->exported_names_, Array::null());
1224 // Initialize cache of loaded scripts. 1110 // Initialize cache of loaded scripts.
1225 library.StorePointer(&library.raw_ptr()->loaded_scripts_, Array::null()); 1111 library.StorePointer(&library.raw_ptr()->loaded_scripts_, Array::null());
1226 } 1112 }
1227 return library.raw(); 1113 return library.raw();
1228 } 1114 }
1229 1115
1230 1116
1231 void RawLibrary::WriteTo(SnapshotWriter* writer, 1117 void RawLibrary::WriteTo(SnapshotWriter* writer,
1232 intptr_t object_id, 1118 intptr_t object_id,
(...skipping 11 matching lines...) Expand all
1244 1130
1245 // Write out the boolean is_in_fullsnapshot_ first as this will 1131 // Write out the boolean is_in_fullsnapshot_ first as this will
1246 // help the reader decide how the rest of the information needs 1132 // help the reader decide how the rest of the information needs
1247 // to be interpreted. 1133 // to be interpreted.
1248 writer->Write<bool>(ptr()->is_in_fullsnapshot_); 1134 writer->Write<bool>(ptr()->is_in_fullsnapshot_);
1249 1135
1250 if ((kind == Snapshot::kScript) && ptr()->is_in_fullsnapshot_) { 1136 if ((kind == Snapshot::kScript) && ptr()->is_in_fullsnapshot_) {
1251 // Write out library URL so that it can be looked up when reading. 1137 // Write out library URL so that it can be looked up when reading.
1252 writer->WriteObjectImpl(ptr()->url_, kAsInlinedObject); 1138 writer->WriteObjectImpl(ptr()->url_, kAsInlinedObject);
1253 } else { 1139 } else {
1254 ASSERT((Snapshot::IsFull(kind)) || !ptr()->is_in_fullsnapshot_); 1140 ASSERT(!ptr()->is_in_fullsnapshot_);
1255 // Write out all non object fields. 1141 // Write out all non object fields.
1256 ASSERT(ptr()->index_ != static_cast<classid_t>(-1)); 1142 ASSERT(ptr()->index_ != static_cast<classid_t>(-1));
1257 writer->WriteClassIDValue(ptr()->index_); 1143 writer->WriteClassIDValue(ptr()->index_);
1258 writer->Write<uint16_t>(ptr()->num_imports_); 1144 writer->Write<uint16_t>(ptr()->num_imports_);
1259 writer->Write<int8_t>(ptr()->load_state_); 1145 writer->Write<int8_t>(ptr()->load_state_);
1260 writer->Write<bool>(ptr()->corelib_imported_); 1146 writer->Write<bool>(ptr()->corelib_imported_);
1261 writer->Write<bool>(ptr()->is_dart_scheme_); 1147 writer->Write<bool>(ptr()->is_dart_scheme_);
1262 writer->Write<bool>(ptr()->debuggable_); 1148 writer->Write<bool>(ptr()->debuggable_);
1263 // We do not serialize the native resolver or symbolizer. These need to be 1149 // We do not serialize the native resolver or symbolizer. These need to be
1264 // explicitly set after deserialization. 1150 // explicitly set after deserialization.
1265 1151
1266 // We do not write the loaded_scripts_ and resolved_names_ caches to the 1152 // We do not write the loaded_scripts_ and resolved_names_ caches to the
1267 // snapshot. They get initialized when reading the library from the 1153 // snapshot. They get initialized when reading the library from the
1268 // snapshot and will be rebuilt lazily. 1154 // snapshot and will be rebuilt lazily.
1269 // Write out all the object pointer fields. 1155 // Write out all the object pointer fields.
1270 SnapshotWriterVisitor visitor(writer, kAsReference); 1156 SnapshotWriterVisitor visitor(writer, kAsReference);
1271 visitor.VisitPointers(from(), to_snapshot()); 1157 visitor.VisitPointers(from(), to_snapshot());
1272 } 1158 }
1273 } 1159 }
1274 1160
1275 1161
1276 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, 1162 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader,
1277 intptr_t object_id, 1163 intptr_t object_id,
1278 intptr_t tags, 1164 intptr_t tags,
1279 Snapshot::Kind kind, 1165 Snapshot::Kind kind,
1280 bool as_reference) { 1166 bool as_reference) {
1281 ASSERT(reader != NULL); 1167 ASSERT(reader != NULL);
1282 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 1168 ASSERT(kind == Snapshot::kScript);
1283 1169
1284 // Allocate library prefix object. 1170 // Allocate library prefix object.
1285 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle( 1171 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(reader->zone(),
1286 reader->zone(), NEW_OBJECT(LibraryPrefix)); 1172 LibraryPrefix::New());
1287 reader->AddBackRef(object_id, &prefix, kIsDeserialized); 1173 reader->AddBackRef(object_id, &prefix, kIsDeserialized);
1288 1174
1289 // Set all non object fields. 1175 // Set all non object fields.
1290 prefix.StoreNonPointer(&prefix.raw_ptr()->num_imports_, 1176 prefix.StoreNonPointer(&prefix.raw_ptr()->num_imports_,
1291 reader->Read<int16_t>()); 1177 reader->Read<int16_t>());
1292 prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_, 1178 prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_,
1293 reader->Read<bool>()); 1179 reader->Read<bool>());
1294 prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, reader->Read<bool>()); 1180 prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, reader->Read<bool>());
1295 1181
1296 // Set all the object fields. 1182 // Set all the object fields.
1297 READ_OBJECT_FIELDS(prefix, 1183 READ_OBJECT_FIELDS(prefix,
1298 prefix.raw()->from(), 1184 prefix.raw()->from(),
1299 prefix.raw()->to_snapshot(kind), 1185 prefix.raw()->to_snapshot(kind),
1300 kAsReference); 1186 kAsReference);
1301 if (kind == Snapshot::kAppNoJIT) {
1302 prefix.StorePointer(&prefix.raw_ptr()->imports_,
1303 Object::empty_array().raw());
1304 }
1305 prefix.StorePointer(&prefix.raw_ptr()->dependent_code_, 1187 prefix.StorePointer(&prefix.raw_ptr()->dependent_code_,
1306 Array::null()); 1188 Array::null());
1307 1189
1308 return prefix.raw(); 1190 return prefix.raw();
1309 } 1191 }
1310 1192
1311 1193
1312 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, 1194 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer,
1313 intptr_t object_id, 1195 intptr_t object_id,
1314 Snapshot::Kind kind, 1196 Snapshot::Kind kind,
1315 bool as_reference) { 1197 bool as_reference) {
1316 ASSERT(writer != NULL); 1198 ASSERT(writer != NULL);
1317 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 1199 ASSERT(kind == Snapshot::kScript);
1318 1200
1319 // Write out the serialization header value for this object. 1201 // Write out the serialization header value for this object.
1320 writer->WriteInlinedObjectHeader(object_id); 1202 writer->WriteInlinedObjectHeader(object_id);
1321 1203
1322 // Write out the class and tags information. 1204 // Write out the class and tags information.
1323 writer->WriteIndexedObject(kLibraryPrefixCid); 1205 writer->WriteIndexedObject(kLibraryPrefixCid);
1324 writer->WriteTags(writer->GetObjectTags(this)); 1206 writer->WriteTags(writer->GetObjectTags(this));
1325 1207
1326 // Write out all non object fields. 1208 // Write out all non object fields.
1327 writer->Write<int16_t>(ptr()->num_imports_); 1209 writer->Write<int16_t>(ptr()->num_imports_);
1328 writer->Write<bool>(ptr()->is_deferred_load_); 1210 writer->Write<bool>(ptr()->is_deferred_load_);
1329 writer->Write<bool>(ptr()->is_loaded_); 1211 writer->Write<bool>(ptr()->is_loaded_);
1330 1212
1331 // Write out all the object pointer fields. 1213 // Write out all the object pointer fields.
1332 SnapshotWriterVisitor visitor(writer, kAsReference); 1214 SnapshotWriterVisitor visitor(writer, kAsReference);
1333 visitor.VisitPointers(from(), to_snapshot(kind)); 1215 visitor.VisitPointers(from(), to_snapshot(kind));
1334 } 1216 }
1335 1217
1336 1218
1337 RawNamespace* Namespace::ReadFrom(SnapshotReader* reader, 1219 RawNamespace* Namespace::ReadFrom(SnapshotReader* reader,
1338 intptr_t object_id, 1220 intptr_t object_id,
1339 intptr_t tags, 1221 intptr_t tags,
1340 Snapshot::Kind kind, 1222 Snapshot::Kind kind,
1341 bool as_reference) { 1223 bool as_reference) {
1342 ASSERT(reader != NULL); 1224 ASSERT(reader != NULL);
1343 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 1225 ASSERT(kind == Snapshot::kScript);
1344 1226
1345 // Allocate Namespace object. 1227 // Allocate Namespace object.
1346 Namespace& ns = Namespace::ZoneHandle( 1228 Namespace& ns = Namespace::ZoneHandle(reader->zone(), Namespace::New());
1347 reader->zone(), NEW_OBJECT(Namespace));
1348 reader->AddBackRef(object_id, &ns, kIsDeserialized); 1229 reader->AddBackRef(object_id, &ns, kIsDeserialized);
1349 1230
1350 // Set all the object fields. 1231 // Set all the object fields.
1351 READ_OBJECT_FIELDS(ns, ns.raw()->from(), ns.raw()->to(), kAsReference); 1232 READ_OBJECT_FIELDS(ns, ns.raw()->from(), ns.raw()->to(), kAsReference);
1352 1233
1353 return ns.raw(); 1234 return ns.raw();
1354 } 1235 }
1355 1236
1356 1237
1357 void RawNamespace::WriteTo(SnapshotWriter* writer, 1238 void RawNamespace::WriteTo(SnapshotWriter* writer,
1358 intptr_t object_id, 1239 intptr_t object_id,
1359 Snapshot::Kind kind, 1240 Snapshot::Kind kind,
1360 bool as_reference) { 1241 bool as_reference) {
1361 ASSERT(writer != NULL); 1242 ASSERT(writer != NULL);
1362 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 1243 ASSERT(kind == Snapshot::kScript);
1363 1244
1364 // Write out the serialization header value for this object. 1245 // Write out the serialization header value for this object.
1365 writer->WriteInlinedObjectHeader(object_id); 1246 writer->WriteInlinedObjectHeader(object_id);
1366 1247
1367 // Write out the class and tags information. 1248 // Write out the class and tags information.
1368 writer->WriteVMIsolateObject(kNamespaceCid); 1249 writer->WriteVMIsolateObject(kNamespaceCid);
1369 writer->WriteTags(writer->GetObjectTags(this)); 1250 writer->WriteTags(writer->GetObjectTags(this));
1370 1251
1371 // Write out all the object pointer fields. 1252 // Write out all the object pointer fields.
1372 SnapshotWriterVisitor visitor(writer, kAsReference); 1253 SnapshotWriterVisitor visitor(writer, kAsReference);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 bool as_reference) { 1406 bool as_reference) {
1526 ASSERT(reader != NULL); 1407 ASSERT(reader != NULL);
1527 1408
1528 // Allocate context object. 1409 // Allocate context object.
1529 int32_t num_vars = reader->Read<int32_t>(); 1410 int32_t num_vars = reader->Read<int32_t>();
1530 Context& context = Context::ZoneHandle(reader->zone()); 1411 Context& context = Context::ZoneHandle(reader->zone());
1531 reader->AddBackRef(object_id, &context, kIsDeserialized); 1412 reader->AddBackRef(object_id, &context, kIsDeserialized);
1532 if (num_vars == 0) { 1413 if (num_vars == 0) {
1533 context ^= reader->object_store()->empty_context(); 1414 context ^= reader->object_store()->empty_context();
1534 } else { 1415 } else {
1535 context ^= NEW_OBJECT_WITH_LEN(Context, num_vars); 1416 context ^= Context::New(num_vars);
1536 1417
1537 // Set all the object fields. 1418 // Set all the object fields.
1538 // TODO(5411462): Need to assert No GC can happen here, even though 1419 // TODO(5411462): Need to assert No GC can happen here, even though
1539 // allocations may happen. 1420 // allocations may happen.
1540 intptr_t num_flds = (context.raw()->to(num_vars) - context.raw()->from()); 1421 intptr_t num_flds = (context.raw()->to(num_vars) - context.raw()->from());
1541 for (intptr_t i = 0; i <= num_flds; i++) { 1422 for (intptr_t i = 0; i <= num_flds; i++) {
1542 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); 1423 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1543 context.StorePointer((context.raw()->from() + i), 1424 context.StorePointer((context.raw()->from() + i),
1544 reader->PassiveObjectHandle()->raw()); 1425 reader->PassiveObjectHandle()->raw());
1545 } 1426 }
(...skipping 30 matching lines...) Expand all
1576 intptr_t object_id, 1457 intptr_t object_id,
1577 intptr_t tags, 1458 intptr_t tags,
1578 Snapshot::Kind kind, 1459 Snapshot::Kind kind,
1579 bool as_reference) { 1460 bool as_reference) {
1580 ASSERT(reader != NULL); 1461 ASSERT(reader != NULL);
1581 1462
1582 // Allocate context object. 1463 // Allocate context object.
1583 bool is_implicit = reader->Read<bool>(); 1464 bool is_implicit = reader->Read<bool>();
1584 if (is_implicit) { 1465 if (is_implicit) {
1585 ContextScope& context_scope = ContextScope::ZoneHandle(reader->zone()); 1466 ContextScope& context_scope = ContextScope::ZoneHandle(reader->zone());
1586 if (Snapshot::IsFull(kind)) { 1467 context_scope = ContextScope::New(1, true);
1587 context_scope = reader->NewContextScope(1);
1588 context_scope.set_is_implicit(true);
1589 } else {
1590 context_scope = ContextScope::New(1, true);
1591 }
1592 reader->AddBackRef(object_id, &context_scope, kIsDeserialized); 1468 reader->AddBackRef(object_id, &context_scope, kIsDeserialized);
1593 1469
1594 *reader->TypeHandle() ^= reader->ReadObjectImpl(kAsInlinedObject); 1470 *reader->TypeHandle() ^= reader->ReadObjectImpl(kAsInlinedObject);
1595 1471
1596 // Create a descriptor for 'this' variable. 1472 // Create a descriptor for 'this' variable.
1597 context_scope.SetTokenIndexAt(0, TokenPosition::kMinSource); 1473 context_scope.SetTokenIndexAt(0, TokenPosition::kMinSource);
1598 context_scope.SetNameAt(0, Symbols::This()); 1474 context_scope.SetNameAt(0, Symbols::This());
1599 context_scope.SetIsFinalAt(0, true); 1475 context_scope.SetIsFinalAt(0, true);
1600 context_scope.SetIsConstAt(0, false); 1476 context_scope.SetIsConstAt(0, false);
1601 context_scope.SetTypeAt(0, *reader->TypeHandle()); 1477 context_scope.SetTypeAt(0, *reader->TypeHandle());
1602 context_scope.SetContextIndexAt(0, 0); 1478 context_scope.SetContextIndexAt(0, 0);
1603 context_scope.SetContextLevelAt(0, 0); 1479 context_scope.SetContextLevelAt(0, 0);
1604 return context_scope.raw(); 1480 return context_scope.raw();
1605 } else if (kind == Snapshot::kAppWithJIT) {
1606 int32_t num_vars = reader->Read<int32_t>();
1607
1608 ContextScope& context_scope = ContextScope::ZoneHandle(reader->zone());
1609 context_scope = reader->NewContextScope(num_vars);
1610 context_scope.set_is_implicit(false);
1611 reader->AddBackRef(object_id, &context_scope, kIsDeserialized);
1612
1613 READ_OBJECT_FIELDS(context_scope,
1614 context_scope.raw()->from(),
1615 context_scope.raw()->to(num_vars),
1616 kAsInlinedObject);
1617 return context_scope.raw();
1618 } 1481 }
1619 UNREACHABLE(); 1482 UNREACHABLE();
1620 return NULL; 1483 return NULL;
1621 } 1484 }
1622 1485
1623 1486
1624 void RawContextScope::WriteTo(SnapshotWriter* writer, 1487 void RawContextScope::WriteTo(SnapshotWriter* writer,
1625 intptr_t object_id, 1488 intptr_t object_id,
1626 Snapshot::Kind kind, 1489 Snapshot::Kind kind,
1627 bool as_reference) { 1490 bool as_reference) {
(...skipping 10 matching lines...) Expand all
1638 writer->WriteVMIsolateObject(kContextScopeCid); 1501 writer->WriteVMIsolateObject(kContextScopeCid);
1639 writer->WriteTags(writer->GetObjectTags(this)); 1502 writer->WriteTags(writer->GetObjectTags(this));
1640 1503
1641 // Write out is_implicit flag for the context scope. 1504 // Write out is_implicit flag for the context scope.
1642 writer->Write<bool>(true); 1505 writer->Write<bool>(true);
1643 1506
1644 // Write out the type of 'this' the variable. 1507 // Write out the type of 'this' the variable.
1645 writer->WriteObjectImpl(var->type, kAsInlinedObject); 1508 writer->WriteObjectImpl(var->type, kAsInlinedObject);
1646 1509
1647 return; 1510 return;
1648 } else if (kind == Snapshot::kAppWithJIT) {
1649 // Write out the serialization header value for this object.
1650 writer->WriteInlinedObjectHeader(object_id);
1651
1652 // Write out the class and tags information.
1653 writer->WriteVMIsolateObject(kContextScopeCid);
1654 writer->WriteTags(writer->GetObjectTags(this));
1655
1656 // Write out is_implicit flag for the context scope.
1657 writer->Write<bool>(false);
1658 int32_t num_vars = ptr()->num_variables_;
1659 writer->Write<int32_t>(num_vars);
1660
1661 SnapshotWriterVisitor visitor(writer, kAsInlinedObject);
1662 visitor.VisitPointers(from(), to(num_vars));
1663
1664 return;
1665 } 1511 }
1666 UNREACHABLE(); 1512 UNREACHABLE();
1667 } 1513 }
1668 1514
1669 1515
1670 RawICData* ICData::ReadFrom(SnapshotReader* reader, 1516 RawICData* ICData::ReadFrom(SnapshotReader* reader,
1671 intptr_t object_id, 1517 intptr_t object_id,
1672 intptr_t tags, 1518 intptr_t tags,
1673 Snapshot::Kind kind, 1519 Snapshot::Kind kind,
1674 bool as_reference) { 1520 bool as_reference) {
1675 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 1521 ASSERT(kind == Snapshot::kScript);
1676 1522
1677 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); 1523 ICData& result = ICData::ZoneHandle(reader->zone(), ICData::New());
1678 reader->AddBackRef(object_id, &result, kIsDeserialized); 1524 reader->AddBackRef(object_id, &result, kIsDeserialized);
1679 1525
1680 result.set_deopt_id(reader->Read<int32_t>()); 1526 result.set_deopt_id(reader->Read<int32_t>());
1681 result.set_state_bits(reader->Read<uint32_t>()); 1527 result.set_state_bits(reader->Read<uint32_t>());
1682 #if defined(TAG_IC_DATA) 1528 #if defined(TAG_IC_DATA)
1683 result.set_tag(reader->Read<int16_t>()); 1529 result.set_tag(reader->Read<int16_t>());
1684 #endif 1530 #endif
1685 1531
1686 // Set all the object fields. 1532 // Set all the object fields.
1687 READ_OBJECT_FIELDS(result, 1533 READ_OBJECT_FIELDS(result,
1688 result.raw()->from(), 1534 result.raw()->from(),
1689 result.raw()->to_snapshot(kind), 1535 result.raw()->to_snapshot(kind),
1690 kAsReference); 1536 kAsReference);
1691 if (kind == Snapshot::kAppNoJIT) {
1692 result.set_owner(Function::Handle(reader->zone()));
1693 }
1694 1537
1695 return result.raw(); 1538 return result.raw();
1696 } 1539 }
1697 1540
1698 1541
1699 void RawICData::WriteTo(SnapshotWriter* writer, 1542 void RawICData::WriteTo(SnapshotWriter* writer,
1700 intptr_t object_id, 1543 intptr_t object_id,
1701 Snapshot::Kind kind, 1544 Snapshot::Kind kind,
1702 bool as_reference) { 1545 bool as_reference) {
1703 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); 1546 ASSERT(kind == Snapshot::kScript);
1704 1547
1705 // Write out the serialization header value for this object. 1548 // Write out the serialization header value for this object.
1706 writer->WriteInlinedObjectHeader(object_id); 1549 writer->WriteInlinedObjectHeader(object_id);
1707 1550
1708 // Write out the class and tags information. 1551 // Write out the class and tags information.
1709 writer->WriteVMIsolateObject(kICDataCid); 1552 writer->WriteVMIsolateObject(kICDataCid);
1710 writer->WriteTags(writer->GetObjectTags(this)); 1553 writer->WriteTags(writer->GetObjectTags(this));
1711 1554
1712 // Write out all the non object fields. 1555 // Write out all the non object fields.
1713 writer->Write<int32_t>(ptr()->deopt_id_); 1556 writer->Write<int32_t>(ptr()->deopt_id_);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 1623
1781 RawApiError* ApiError::ReadFrom(SnapshotReader* reader, 1624 RawApiError* ApiError::ReadFrom(SnapshotReader* reader,
1782 intptr_t object_id, 1625 intptr_t object_id,
1783 intptr_t tags, 1626 intptr_t tags,
1784 Snapshot::Kind kind, 1627 Snapshot::Kind kind,
1785 bool as_reference) { 1628 bool as_reference) {
1786 ASSERT(reader != NULL); 1629 ASSERT(reader != NULL);
1787 1630
1788 // Allocate ApiError object. 1631 // Allocate ApiError object.
1789 ApiError& api_error = 1632 ApiError& api_error =
1790 ApiError::ZoneHandle(reader->zone(), NEW_OBJECT(ApiError)); 1633 ApiError::ZoneHandle(reader->zone(), ApiError::New());
1791 reader->AddBackRef(object_id, &api_error, kIsDeserialized); 1634 reader->AddBackRef(object_id, &api_error, kIsDeserialized);
1792 1635
1793 // Set all the object fields. 1636 // Set all the object fields.
1794 READ_OBJECT_FIELDS(api_error, 1637 READ_OBJECT_FIELDS(api_error,
1795 api_error.raw()->from(), api_error.raw()->to(), 1638 api_error.raw()->from(), api_error.raw()->to(),
1796 kAsReference); 1639 kAsReference);
1797 1640
1798 return api_error.raw(); 1641 return api_error.raw();
1799 } 1642 }
1800 1643
(...skipping 19 matching lines...) Expand all
1820 1663
1821 RawLanguageError* LanguageError::ReadFrom(SnapshotReader* reader, 1664 RawLanguageError* LanguageError::ReadFrom(SnapshotReader* reader,
1822 intptr_t object_id, 1665 intptr_t object_id,
1823 intptr_t tags, 1666 intptr_t tags,
1824 Snapshot::Kind kind, 1667 Snapshot::Kind kind,
1825 bool as_reference) { 1668 bool as_reference) {
1826 ASSERT(reader != NULL); 1669 ASSERT(reader != NULL);
1827 1670
1828 // Allocate LanguageError object. 1671 // Allocate LanguageError object.
1829 LanguageError& language_error = 1672 LanguageError& language_error =
1830 LanguageError::ZoneHandle(reader->zone(), NEW_OBJECT(LanguageError)); 1673 LanguageError::ZoneHandle(reader->zone(), LanguageError::New());
1831 reader->AddBackRef(object_id, &language_error, kIsDeserialized); 1674 reader->AddBackRef(object_id, &language_error, kIsDeserialized);
1832 1675
1833 // Set all non object fields. 1676 // Set all non object fields.
1834 language_error.set_token_pos( 1677 language_error.set_token_pos(
1835 TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 1678 TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
1836 language_error.set_report_after_token(reader->Read<bool>()); 1679 language_error.set_report_after_token(reader->Read<bool>());
1837 language_error.set_kind(reader->Read<uint8_t>()); 1680 language_error.set_kind(reader->Read<uint8_t>());
1838 1681
1839 // Set all the object fields. 1682 // Set all the object fields.
1840 READ_OBJECT_FIELDS(language_error, 1683 READ_OBJECT_FIELDS(language_error,
(...skipping 27 matching lines...) Expand all
1868 visitor.VisitPointers(from(), to()); 1711 visitor.VisitPointers(from(), to());
1869 } 1712 }
1870 1713
1871 1714
1872 RawUnhandledException* UnhandledException::ReadFrom(SnapshotReader* reader, 1715 RawUnhandledException* UnhandledException::ReadFrom(SnapshotReader* reader,
1873 intptr_t object_id, 1716 intptr_t object_id,
1874 intptr_t tags, 1717 intptr_t tags,
1875 Snapshot::Kind kind, 1718 Snapshot::Kind kind,
1876 bool as_reference) { 1719 bool as_reference) {
1877 UnhandledException& result = UnhandledException::ZoneHandle( 1720 UnhandledException& result = UnhandledException::ZoneHandle(
1878 reader->zone(), NEW_OBJECT(UnhandledException)); 1721 reader->zone(), UnhandledException::New());
1879 reader->AddBackRef(object_id, &result, kIsDeserialized); 1722 reader->AddBackRef(object_id, &result, kIsDeserialized);
1880 1723
1881 // Set all the object fields. 1724 // Set all the object fields.
1882 READ_OBJECT_FIELDS(result, 1725 READ_OBJECT_FIELDS(result,
1883 result.raw()->from(), result.raw()->to(), 1726 result.raw()->from(), result.raw()->to(),
1884 kAsReference); 1727 kAsReference);
1885 1728
1886 return result.raw(); 1729 return result.raw();
1887 } 1730 }
1888 1731
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 RawInstance* Instance::ReadFrom(SnapshotReader* reader, 1767 RawInstance* Instance::ReadFrom(SnapshotReader* reader,
1925 intptr_t object_id, 1768 intptr_t object_id,
1926 intptr_t tags, 1769 intptr_t tags,
1927 Snapshot::Kind kind, 1770 Snapshot::Kind kind,
1928 bool as_reference) { 1771 bool as_reference) {
1929 ASSERT(reader != NULL); 1772 ASSERT(reader != NULL);
1930 1773
1931 // Create an Instance object or get canonical one if it is a canonical 1774 // Create an Instance object or get canonical one if it is a canonical
1932 // constant. 1775 // constant.
1933 Instance& obj = Instance::ZoneHandle(reader->zone(), Instance::null()); 1776 Instance& obj = Instance::ZoneHandle(reader->zone(), Instance::null());
1934 if (Snapshot::IsFull(kind)) { 1777 obj ^= Object::Allocate(kInstanceCid,
1935 obj = reader->NewInstance(); 1778 Instance::InstanceSize(),
1936 // Set the canonical bit. 1779 HEAP_SPACE(kind));
1937 if (RawObject::IsCanonical(tags)) { 1780 if (RawObject::IsCanonical(tags)) {
1938 obj.SetCanonical(); 1781 obj = obj.CheckAndCanonicalize(reader->thread(), NULL);
1939 }
1940 } else {
1941 obj ^= Object::Allocate(kInstanceCid,
1942 Instance::InstanceSize(),
1943 HEAP_SPACE(kind));
1944 if (RawObject::IsCanonical(tags)) {
1945 obj = obj.CheckAndCanonicalize(reader->thread(), NULL);
1946 }
1947 } 1782 }
1948 reader->AddBackRef(object_id, &obj, kIsDeserialized); 1783 reader->AddBackRef(object_id, &obj, kIsDeserialized);
1949 1784
1950 return obj.raw(); 1785 return obj.raw();
1951 } 1786 }
1952 1787
1953 1788
1954 void RawInstance::WriteTo(SnapshotWriter* writer, 1789 void RawInstance::WriteTo(SnapshotWriter* writer,
1955 intptr_t object_id, 1790 intptr_t object_id,
1956 Snapshot::Kind kind, 1791 Snapshot::Kind kind,
(...skipping 23 matching lines...) Expand all
1980 // architecture, if so return the object as a Smi. 1815 // architecture, if so return the object as a Smi.
1981 if (Smi::IsValid(value)) { 1816 if (Smi::IsValid(value)) {
1982 Smi& smi = Smi::ZoneHandle(reader->zone(), 1817 Smi& smi = Smi::ZoneHandle(reader->zone(),
1983 Smi::New(static_cast<intptr_t>(value))); 1818 Smi::New(static_cast<intptr_t>(value)));
1984 reader->AddBackRef(object_id, &smi, kIsDeserialized); 1819 reader->AddBackRef(object_id, &smi, kIsDeserialized);
1985 return smi.raw(); 1820 return smi.raw();
1986 } 1821 }
1987 1822
1988 // Create a Mint object or get canonical one if it is a canonical constant. 1823 // Create a Mint object or get canonical one if it is a canonical constant.
1989 Mint& mint = Mint::ZoneHandle(reader->zone(), Mint::null()); 1824 Mint& mint = Mint::ZoneHandle(reader->zone(), Mint::null());
1990 if (Snapshot::IsFull(kind)) { 1825 // When reading a script snapshot we need to canonicalize only those object
1991 mint = reader->NewMint(value); 1826 // references that are objects from the core library (loaded from a
1992 // Set the canonical bit. 1827 // full snapshot). Objects that are only in the script need not be
1993 if (RawObject::IsCanonical(tags)) { 1828 // canonicalized as they are already canonical.
1994 mint.SetCanonical(); 1829 // When reading a message snapshot we always have to canonicalize.
1995 } 1830 if (RawObject::IsCanonical(tags)) {
1831 mint = Mint::NewCanonical(value);
1832 ASSERT(mint.IsCanonical());
1996 } else { 1833 } else {
1997 // When reading a script snapshot we need to canonicalize only those object 1834 mint = Mint::New(value, HEAP_SPACE(kind));
1998 // references that are objects from the core library (loaded from a
1999 // full snapshot). Objects that are only in the script need not be
2000 // canonicalized as they are already canonical.
2001 // When reading a message snapshot we always have to canonicalize.
2002 if (RawObject::IsCanonical(tags)) {
2003 mint = Mint::NewCanonical(value);
2004 ASSERT(mint.IsCanonical());
2005 } else {
2006 mint = Mint::New(value, HEAP_SPACE(kind));
2007 }
2008 } 1835 }
2009 reader->AddBackRef(object_id, &mint, kIsDeserialized); 1836 reader->AddBackRef(object_id, &mint, kIsDeserialized);
2010 return mint.raw(); 1837 return mint.raw();
2011 } 1838 }
2012 1839
2013 1840
2014 void RawMint::WriteTo(SnapshotWriter* writer, 1841 void RawMint::WriteTo(SnapshotWriter* writer,
2015 intptr_t object_id, 1842 intptr_t object_id,
2016 Snapshot::Kind kind, 1843 Snapshot::Kind kind,
2017 bool as_reference) { 1844 bool as_reference) {
(...skipping 12 matching lines...) Expand all
2030 1857
2031 1858
2032 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, 1859 RawBigint* Bigint::ReadFrom(SnapshotReader* reader,
2033 intptr_t object_id, 1860 intptr_t object_id,
2034 intptr_t tags, 1861 intptr_t tags,
2035 Snapshot::Kind kind, 1862 Snapshot::Kind kind,
2036 bool as_reference) { 1863 bool as_reference) {
2037 ASSERT(reader != NULL); 1864 ASSERT(reader != NULL);
2038 1865
2039 // Allocate bigint object. 1866 // Allocate bigint object.
2040 Bigint& obj = Bigint::ZoneHandle(reader->zone(), NEW_OBJECT(Bigint)); 1867 Bigint& obj = Bigint::ZoneHandle(reader->zone(), Bigint::New());
2041 reader->AddBackRef(object_id, &obj, kIsDeserialized); 1868 reader->AddBackRef(object_id, &obj, kIsDeserialized);
2042 1869
2043 // Set all the object fields. 1870 // Set all the object fields.
2044 READ_OBJECT_FIELDS(obj, obj.raw()->from(), obj.raw()->to(), kAsInlinedObject); 1871 READ_OBJECT_FIELDS(obj, obj.raw()->from(), obj.raw()->to(), kAsInlinedObject);
2045 1872
2046 // If it is a canonical constant make it one. 1873 // If it is a canonical constant make it one.
2047 // When reading a full snapshot we don't need to canonicalize the object 1874 // When reading a full snapshot we don't need to canonicalize the object
2048 // as it would already be a canonical object. 1875 // as it would already be a canonical object.
2049 // When reading a script snapshot or a message snapshot we always have 1876 // When reading a script snapshot or a message snapshot we always have
2050 // to canonicalize the object. 1877 // to canonicalize the object.
2051 if (RawObject::IsCanonical(tags)) { 1878 if (RawObject::IsCanonical(tags)) {
2052 if (Snapshot::IsFull(kind)) { 1879 obj ^= obj.CheckAndCanonicalize(reader->thread(), NULL);
2053 // Set the canonical bit. 1880 ASSERT(!obj.IsNull());
2054 obj.SetCanonical(); 1881 ASSERT(obj.IsCanonical());
2055 } else {
2056 obj ^= obj.CheckAndCanonicalize(reader->thread(), NULL);
2057 ASSERT(!obj.IsNull());
2058 ASSERT(obj.IsCanonical());
2059 }
2060 } 1882 }
2061 return obj.raw(); 1883 return obj.raw();
2062 } 1884 }
2063 1885
2064 1886
2065 void RawBigint::WriteTo(SnapshotWriter* writer, 1887 void RawBigint::WriteTo(SnapshotWriter* writer,
2066 intptr_t object_id, 1888 intptr_t object_id,
2067 Snapshot::Kind kind, 1889 Snapshot::Kind kind,
2068 bool as_reference) { 1890 bool as_reference) {
2069 ASSERT(writer != NULL); 1891 ASSERT(writer != NULL);
(...skipping 16 matching lines...) Expand all
2086 intptr_t tags, 1908 intptr_t tags,
2087 Snapshot::Kind kind, 1909 Snapshot::Kind kind,
2088 bool as_reference) { 1910 bool as_reference) {
2089 ASSERT(reader != NULL); 1911 ASSERT(reader != NULL);
2090 ASSERT(kind != Snapshot::kMessage); 1912 ASSERT(kind != Snapshot::kMessage);
2091 // Read the double value for the object. 1913 // Read the double value for the object.
2092 double value = reader->ReadDouble(); 1914 double value = reader->ReadDouble();
2093 1915
2094 // Create a Double object or get canonical one if it is a canonical constant. 1916 // Create a Double object or get canonical one if it is a canonical constant.
2095 Double& dbl = Double::ZoneHandle(reader->zone(), Double::null()); 1917 Double& dbl = Double::ZoneHandle(reader->zone(), Double::null());
2096 if (Snapshot::IsFull(kind)) { 1918 // When reading a script snapshot we need to canonicalize only those object
2097 dbl = reader->NewDouble(value); 1919 // references that are objects from the core library (loaded from a
2098 // Set the canonical bit. 1920 // full snapshot). Objects that are only in the script need not be
2099 if (RawObject::IsCanonical(tags)) { 1921 // canonicalized as they are already canonical.
2100 dbl.SetCanonical(); 1922 if (RawObject::IsCanonical(tags)) {
2101 } 1923 dbl = Double::NewCanonical(value);
1924 ASSERT(dbl.IsCanonical());
2102 } else { 1925 } else {
2103 // When reading a script snapshot we need to canonicalize only those object 1926 dbl = Double::New(value, HEAP_SPACE(kind));
2104 // references that are objects from the core library (loaded from a
2105 // full snapshot). Objects that are only in the script need not be
2106 // canonicalized as they are already canonical.
2107 if (RawObject::IsCanonical(tags)) {
2108 dbl = Double::NewCanonical(value);
2109 ASSERT(dbl.IsCanonical());
2110 } else {
2111 dbl = Double::New(value, HEAP_SPACE(kind));
2112 }
2113 } 1927 }
2114 reader->AddBackRef(object_id, &dbl, kIsDeserialized); 1928 reader->AddBackRef(object_id, &dbl, kIsDeserialized);
2115 return dbl.raw(); 1929 return dbl.raw();
2116 } 1930 }
2117 1931
2118 1932
2119 void RawDouble::WriteTo(SnapshotWriter* writer, 1933 void RawDouble::WriteTo(SnapshotWriter* writer,
2120 intptr_t object_id, 1934 intptr_t object_id,
2121 Snapshot::Kind kind, 1935 Snapshot::Kind kind,
2122 bool as_reference) { 1936 bool as_reference) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2186 2000
2187 2001
2188 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, 2002 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader,
2189 intptr_t object_id, 2003 intptr_t object_id,
2190 intptr_t tags, 2004 intptr_t tags,
2191 Snapshot::Kind kind, 2005 Snapshot::Kind kind,
2192 bool as_reference) { 2006 bool as_reference) {
2193 // Read the length so that we can determine instance size to allocate. 2007 // Read the length so that we can determine instance size to allocate.
2194 ASSERT(reader != NULL); 2008 ASSERT(reader != NULL);
2195 intptr_t len = reader->ReadSmiValue(); 2009 intptr_t len = reader->ReadSmiValue();
2196 intptr_t hash = reader->ReadSmiValue();
2197 String& str_obj = String::ZoneHandle(reader->zone(), String::null()); 2010 String& str_obj = String::ZoneHandle(reader->zone(), String::null());
2198 2011
2199 if (Snapshot::IsFull(kind)) { 2012 String::ReadFromImpl<OneByteString, uint8_t>(
2200 // We currently only expect the Dart mutator to read snapshots. 2013 reader, &str_obj, len, tags, Symbols::FromLatin1, kind);
2201 reader->isolate()->AssertCurrentThreadIsMutator();
2202 ASSERT(Thread::Current()->no_safepoint_scope_depth() != 0);
2203 RawOneByteString* obj = reader->NewOneByteString(len);
2204 str_obj = obj;
2205 if (RawObject::IsCanonical(tags)) {
2206 str_obj.SetCanonical();
2207 }
2208 str_obj.SetHash(hash);
2209 if (len > 0) {
2210 uint8_t* raw_ptr = CharAddr(str_obj, 0);
2211 reader->ReadBytes(raw_ptr, len);
2212 }
2213 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash));
2214 } else {
2215 String::ReadFromImpl<OneByteString, uint8_t>(
2216 reader, &str_obj, len, tags, Symbols::FromLatin1, kind);
2217 }
2218 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); 2014 reader->AddBackRef(object_id, &str_obj, kIsDeserialized);
2219 return raw(str_obj); 2015 return raw(str_obj);
2220 } 2016 }
2221 2017
2222 2018
2223 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, 2019 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader,
2224 intptr_t object_id, 2020 intptr_t object_id,
2225 intptr_t tags, 2021 intptr_t tags,
2226 Snapshot::Kind kind, 2022 Snapshot::Kind kind,
2227 bool as_reference) { 2023 bool as_reference) {
2228 // Read the length so that we can determine instance size to allocate. 2024 // Read the length so that we can determine instance size to allocate.
2229 ASSERT(reader != NULL); 2025 ASSERT(reader != NULL);
2230 intptr_t len = reader->ReadSmiValue(); 2026 intptr_t len = reader->ReadSmiValue();
2231 intptr_t hash = reader->ReadSmiValue();
2232 String& str_obj = String::ZoneHandle(reader->zone(), String::null()); 2027 String& str_obj = String::ZoneHandle(reader->zone(), String::null());
2233 2028
2234 if (Snapshot::IsFull(kind)) { 2029 String::ReadFromImpl<TwoByteString, uint16_t>(
2235 RawTwoByteString* obj = reader->NewTwoByteString(len); 2030 reader, &str_obj, len, tags, Symbols::FromUTF16, kind);
2236 str_obj = obj;
2237 if (RawObject::IsCanonical(tags)) {
2238 str_obj.SetCanonical();
2239 }
2240 str_obj.SetHash(hash);
2241 NoSafepointScope no_safepoint;
2242 uint16_t* raw_ptr = (len > 0)? CharAddr(str_obj, 0) : NULL;
2243 for (intptr_t i = 0; i < len; i++) {
2244 ASSERT(CharAddr(str_obj, i) == raw_ptr); // Will trigger assertions.
2245 *raw_ptr = reader->Read<uint16_t>();
2246 raw_ptr += 1;
2247 }
2248 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash);
2249 } else {
2250 String::ReadFromImpl<TwoByteString, uint16_t>(
2251 reader, &str_obj, len, tags, Symbols::FromUTF16, kind);
2252 }
2253 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); 2031 reader->AddBackRef(object_id, &str_obj, kIsDeserialized);
2254 return raw(str_obj); 2032 return raw(str_obj);
2255 } 2033 }
2256 2034
2257 2035
2258 template<typename T> 2036 template<typename T>
2259 static void StringWriteTo(SnapshotWriter* writer, 2037 static void StringWriteTo(SnapshotWriter* writer,
2260 intptr_t object_id, 2038 intptr_t object_id,
2261 Snapshot::Kind kind, 2039 Snapshot::Kind kind,
2262 intptr_t class_id, 2040 intptr_t class_id,
2263 intptr_t tags, 2041 intptr_t tags,
2264 RawSmi* length, 2042 RawSmi* length,
2265 RawSmi* hash,
2266 T* data) { 2043 T* data) {
2267 ASSERT(writer != NULL); 2044 ASSERT(writer != NULL);
2268 intptr_t len = Smi::Value(length); 2045 intptr_t len = Smi::Value(length);
2269 2046
2270 // Write out the serialization header value for this object. 2047 // Write out the serialization header value for this object.
2271 writer->WriteInlinedObjectHeader(object_id); 2048 writer->WriteInlinedObjectHeader(object_id);
2272 2049
2273 // Write out the class and tags information. 2050 // Write out the class and tags information.
2274 writer->WriteIndexedObject(class_id); 2051 writer->WriteIndexedObject(class_id);
2275 writer->WriteTags(tags); 2052 writer->WriteTags(tags);
2276 2053
2277 // Write out the length field. 2054 // Write out the length field.
2278 writer->Write<RawObject*>(length); 2055 writer->Write<RawObject*>(length);
2279 2056
2280 // Write out the hash field.
2281 writer->Write<RawObject*>(hash);
2282
2283 // Write out the string. 2057 // Write out the string.
2284 if (len > 0) { 2058 if (len > 0) {
2285 if (class_id == kOneByteStringCid) { 2059 if (class_id == kOneByteStringCid) {
2286 writer->WriteBytes(reinterpret_cast<const uint8_t*>(data), len); 2060 writer->WriteBytes(reinterpret_cast<const uint8_t*>(data), len);
2287 } else { 2061 } else {
2288 for (intptr_t i = 0; i < len; i++) { 2062 for (intptr_t i = 0; i < len; i++) {
2289 writer->Write(data[i]); 2063 writer->Write(data[i]);
2290 } 2064 }
2291 } 2065 }
2292 } 2066 }
2293 } 2067 }
2294 2068
2295 2069
2296 void RawOneByteString::WriteTo(SnapshotWriter* writer, 2070 void RawOneByteString::WriteTo(SnapshotWriter* writer,
2297 intptr_t object_id, 2071 intptr_t object_id,
2298 Snapshot::Kind kind, 2072 Snapshot::Kind kind,
2299 bool as_reference) { 2073 bool as_reference) {
2300 StringWriteTo(writer, 2074 StringWriteTo(writer,
2301 object_id, 2075 object_id,
2302 kind, 2076 kind,
2303 kOneByteStringCid, 2077 kOneByteStringCid,
2304 writer->GetObjectTags(this), 2078 writer->GetObjectTags(this),
2305 ptr()->length_, 2079 ptr()->length_,
2306 ptr()->hash_,
2307 ptr()->data()); 2080 ptr()->data());
2308 } 2081 }
2309 2082
2310 2083
2311 void RawTwoByteString::WriteTo(SnapshotWriter* writer, 2084 void RawTwoByteString::WriteTo(SnapshotWriter* writer,
2312 intptr_t object_id, 2085 intptr_t object_id,
2313 Snapshot::Kind kind, 2086 Snapshot::Kind kind,
2314 bool as_reference) { 2087 bool as_reference) {
2315 StringWriteTo(writer, 2088 StringWriteTo(writer,
2316 object_id, 2089 object_id,
2317 kind, 2090 kind,
2318 kTwoByteStringCid, 2091 kTwoByteStringCid,
2319 writer->GetObjectTags(this), 2092 writer->GetObjectTags(this),
2320 ptr()->length_, 2093 ptr()->length_,
2321 ptr()->hash_,
2322 ptr()->data()); 2094 ptr()->data());
2323 } 2095 }
2324 2096
2325 2097
2326 RawExternalOneByteString* ExternalOneByteString::ReadFrom( 2098 RawExternalOneByteString* ExternalOneByteString::ReadFrom(
2327 SnapshotReader* reader, 2099 SnapshotReader* reader,
2328 intptr_t object_id, 2100 intptr_t object_id,
2329 intptr_t tags, 2101 intptr_t tags,
2330 Snapshot::Kind kind, 2102 Snapshot::Kind kind,
2331 bool as_reference) { 2103 bool as_reference) {
(...skipping 17 matching lines...) Expand all
2349 intptr_t object_id, 2121 intptr_t object_id,
2350 Snapshot::Kind kind, 2122 Snapshot::Kind kind,
2351 bool as_reference) { 2123 bool as_reference) {
2352 // Serialize as a non-external one byte string. 2124 // Serialize as a non-external one byte string.
2353 StringWriteTo(writer, 2125 StringWriteTo(writer,
2354 object_id, 2126 object_id,
2355 kind, 2127 kind,
2356 kOneByteStringCid, 2128 kOneByteStringCid,
2357 writer->GetObjectTags(this), 2129 writer->GetObjectTags(this),
2358 ptr()->length_, 2130 ptr()->length_,
2359 ptr()->hash_,
2360 ptr()->external_data_->data()); 2131 ptr()->external_data_->data());
2361 } 2132 }
2362 2133
2363 2134
2364 void RawExternalTwoByteString::WriteTo(SnapshotWriter* writer, 2135 void RawExternalTwoByteString::WriteTo(SnapshotWriter* writer,
2365 intptr_t object_id, 2136 intptr_t object_id,
2366 Snapshot::Kind kind, 2137 Snapshot::Kind kind,
2367 bool as_reference) { 2138 bool as_reference) {
2368 // Serialize as a non-external two byte string. 2139 // Serialize as a non-external two byte string.
2369 StringWriteTo(writer, 2140 StringWriteTo(writer,
2370 object_id, 2141 object_id,
2371 kind, 2142 kind,
2372 kTwoByteStringCid, 2143 kTwoByteStringCid,
2373 writer->GetObjectTags(this), 2144 writer->GetObjectTags(this),
2374 ptr()->length_, 2145 ptr()->length_,
2375 ptr()->hash_,
2376 ptr()->external_data_->data()); 2146 ptr()->external_data_->data());
2377 } 2147 }
2378 2148
2379 2149
2380 RawBool* Bool::ReadFrom(SnapshotReader* reader, 2150 RawBool* Bool::ReadFrom(SnapshotReader* reader,
2381 intptr_t object_id, 2151 intptr_t object_id,
2382 intptr_t tags, 2152 intptr_t tags,
2383 Snapshot::Kind kind, 2153 Snapshot::Kind kind,
2384 bool as_reference) { 2154 bool as_reference) {
2385 UNREACHABLE(); 2155 UNREACHABLE();
(...skipping 21 matching lines...) Expand all
2407 Array* array = NULL; 2177 Array* array = NULL;
2408 DeserializeState state; 2178 DeserializeState state;
2409 if (!as_reference) { 2179 if (!as_reference) {
2410 array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); 2180 array = reinterpret_cast<Array*>(reader->GetBackRef(object_id));
2411 state = kIsDeserialized; 2181 state = kIsDeserialized;
2412 } else { 2182 } else {
2413 state = kIsNotDeserialized; 2183 state = kIsNotDeserialized;
2414 } 2184 }
2415 if (array == NULL) { 2185 if (array == NULL) {
2416 array = &(Array::ZoneHandle(reader->zone(), 2186 array = &(Array::ZoneHandle(reader->zone(),
2417 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); 2187 Array::New(len, HEAP_SPACE(kind))));
2418 reader->AddBackRef(object_id, array, state); 2188 reader->AddBackRef(object_id, array, state);
2419 } 2189 }
2420 if (!as_reference) { 2190 if (!as_reference) {
2421 // Read all the individual elements for inlined objects. 2191 // Read all the individual elements for inlined objects.
2422 ASSERT(!RawObject::IsCanonical(tags)); 2192 ASSERT(!RawObject::IsCanonical(tags));
2423 reader->ArrayReadFrom(object_id, *array, len, tags); 2193 reader->ArrayReadFrom(object_id, *array, len, tags);
2424 } 2194 }
2425 return array->raw(); 2195 return array->raw();
2426 } 2196 }
2427 2197
(...skipping 11 matching lines...) Expand all
2439 DeserializeState state; 2209 DeserializeState state;
2440 if (!as_reference) { 2210 if (!as_reference) {
2441 array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); 2211 array = reinterpret_cast<Array*>(reader->GetBackRef(object_id));
2442 state = kIsDeserialized; 2212 state = kIsDeserialized;
2443 } else { 2213 } else {
2444 state = kIsNotDeserialized; 2214 state = kIsNotDeserialized;
2445 } 2215 }
2446 if (array == NULL) { 2216 if (array == NULL) {
2447 array = &(Array::ZoneHandle( 2217 array = &(Array::ZoneHandle(
2448 reader->zone(), 2218 reader->zone(),
2449 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); 2219 ImmutableArray::New(len, HEAP_SPACE(kind))));
2450 reader->AddBackRef(object_id, array, state); 2220 reader->AddBackRef(object_id, array, state);
2451 } 2221 }
2452 if (!as_reference) { 2222 if (!as_reference) {
2453 // Read all the individual elements for inlined objects. 2223 // Read all the individual elements for inlined objects.
2454 reader->ArrayReadFrom(object_id, *array, len, tags); 2224 reader->ArrayReadFrom(object_id, *array, len, tags);
2455 if (RawObject::IsCanonical(tags)) { 2225 if (RawObject::IsCanonical(tags)) {
2456 if (Snapshot::IsFull(kind)) { 2226 *array ^= array->CheckAndCanonicalize(reader->thread(), NULL);
2457 array->SetCanonical();
2458 } else {
2459 *array ^= array->CheckAndCanonicalize(reader->thread(), NULL);
2460 }
2461 } 2227 }
2462 } 2228 }
2463 return raw(*array); 2229 return raw(*array);
2464 } 2230 }
2465 2231
2466 2232
2467 void RawArray::WriteTo(SnapshotWriter* writer, 2233 void RawArray::WriteTo(SnapshotWriter* writer,
2468 intptr_t object_id, 2234 intptr_t object_id,
2469 Snapshot::Kind kind, 2235 Snapshot::Kind kind,
2470 bool as_reference) { 2236 bool as_reference) {
(...skipping 25 matching lines...) Expand all
2496 RawGrowableObjectArray* GrowableObjectArray::ReadFrom(SnapshotReader* reader, 2262 RawGrowableObjectArray* GrowableObjectArray::ReadFrom(SnapshotReader* reader,
2497 intptr_t object_id, 2263 intptr_t object_id,
2498 intptr_t tags, 2264 intptr_t tags,
2499 Snapshot::Kind kind, 2265 Snapshot::Kind kind,
2500 bool as_reference) { 2266 bool as_reference) {
2501 ASSERT(reader != NULL); 2267 ASSERT(reader != NULL);
2502 2268
2503 // 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.
2504 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( 2270 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle(
2505 reader->zone(), GrowableObjectArray::null()); 2271 reader->zone(), GrowableObjectArray::null());
2506 if (Snapshot::IsFull(kind)) { 2272 array = GrowableObjectArray::New(0, HEAP_SPACE(kind));
2507 array = reader->NewGrowableObjectArray();
2508 } else {
2509 array = GrowableObjectArray::New(0, HEAP_SPACE(kind));
2510 }
2511 reader->AddBackRef(object_id, &array, kIsDeserialized); 2273 reader->AddBackRef(object_id, &array, kIsDeserialized);
2512 2274
2513 // Read type arguments of growable array object. 2275 // Read type arguments of growable array object.
2514 const intptr_t typeargs_offset = 2276 const intptr_t typeargs_offset =
2515 GrowableObjectArray::type_arguments_offset() / kWordSize; 2277 GrowableObjectArray::type_arguments_offset() / kWordSize;
2516 *reader->TypeArgumentsHandle() ^= 2278 *reader->TypeArgumentsHandle() ^=
2517 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset); 2279 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset);
2518 array.StorePointer(&array.raw_ptr()->type_arguments_, 2280 array.StorePointer(&array.raw_ptr()->type_arguments_,
2519 reader->TypeArgumentsHandle()->raw()); 2281 reader->TypeArgumentsHandle()->raw());
2520 2282
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2555 2317
2556 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader, 2318 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader,
2557 intptr_t object_id, 2319 intptr_t object_id,
2558 intptr_t tags, 2320 intptr_t tags,
2559 Snapshot::Kind kind, 2321 Snapshot::Kind kind,
2560 bool as_reference) { 2322 bool as_reference) {
2561 ASSERT(reader != NULL); 2323 ASSERT(reader != NULL);
2562 2324
2563 LinkedHashMap& map = LinkedHashMap::ZoneHandle( 2325 LinkedHashMap& map = LinkedHashMap::ZoneHandle(
2564 reader->zone(), LinkedHashMap::null()); 2326 reader->zone(), LinkedHashMap::null());
2565 if (Snapshot::IsFull(kind) || kind == Snapshot::kScript) { 2327 if (kind == Snapshot::kScript) {
2566 // The immutable maps that seed map literals are not yet VM-internal, so 2328 // The immutable maps that seed map literals are not yet VM-internal, so
2567 // we don't reach this. 2329 // we don't reach this.
2568 UNREACHABLE(); 2330 UNREACHABLE();
2569 } else { 2331 } else {
2570 // Since the map might contain itself as a key or value, allocate first. 2332 // Since the map might contain itself as a key or value, allocate first.
2571 if (Snapshot::IsFull(kind)) { 2333 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind));
2572 map = reader->NewLinkedHashMap();
2573 } else {
2574 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind));
2575 }
2576 } 2334 }
2577 reader->AddBackRef(object_id, &map, kIsDeserialized); 2335 reader->AddBackRef(object_id, &map, kIsDeserialized);
2578 2336
2579 // Read the type arguments. 2337 // Read the type arguments.
2580 const intptr_t typeargs_offset = 2338 const intptr_t typeargs_offset =
2581 GrowableObjectArray::type_arguments_offset() / kWordSize; 2339 GrowableObjectArray::type_arguments_offset() / kWordSize;
2582 *reader->TypeArgumentsHandle() ^= 2340 *reader->TypeArgumentsHandle() ^=
2583 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset); 2341 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset);
2584 map.SetTypeArguments(*reader->TypeArgumentsHandle()); 2342 map.SetTypeArguments(*reader->TypeArgumentsHandle());
2585 2343
2586 // Read the number of key/value pairs. 2344 // Read the number of key/value pairs.
2587 intptr_t len = reader->ReadSmiValue(); 2345 intptr_t len = reader->ReadSmiValue();
2588 intptr_t used_data = (len << 1); 2346 intptr_t used_data = (len << 1);
2589 map.SetUsedData(used_data); 2347 map.SetUsedData(used_data);
2590 2348
2591 // Allocate the data array. 2349 // Allocate the data array.
2592 intptr_t data_size = Utils::Maximum( 2350 intptr_t data_size = Utils::Maximum(
2593 Utils::RoundUpToPowerOfTwo(used_data), 2351 Utils::RoundUpToPowerOfTwo(used_data),
2594 static_cast<uintptr_t>(LinkedHashMap::kInitialIndexSize)); 2352 static_cast<uintptr_t>(LinkedHashMap::kInitialIndexSize));
2595 Array& data = Array::ZoneHandle(reader->zone(), 2353 Array& data = Array::ZoneHandle(reader->zone(),
2596 NEW_OBJECT_WITH_LEN_SPACE(Array, 2354 Array::New(data_size, HEAP_SPACE(kind)));
2597 data_size,
2598 kind));
2599 map.SetData(data); 2355 map.SetData(data);
2600 map.SetDeletedKeys(0); 2356 map.SetDeletedKeys(0);
2601 2357
2602 // The index and hashMask is regenerated by the maps themselves on demand. 2358 // The index and hashMask is regenerated by the maps themselves on demand.
2603 // Thus, the index will probably be allocated in new space (unless it's huge). 2359 // Thus, the index will probably be allocated in new space (unless it's huge).
2604 // TODO(koda): Eagerly rehash here when no keys have user-defined '==', and 2360 // TODO(koda): Eagerly rehash here when no keys have user-defined '==', and
2605 // in particular, if/when (const) maps are needed in the VM isolate snapshot. 2361 // in particular, if/when (const) maps are needed in the VM isolate snapshot.
2606 ASSERT(reader->isolate() != Dart::vm_isolate()); 2362 ASSERT(reader->isolate() != Dart::vm_isolate());
2607 map.SetHashMask(0); // Prefer sentinel 0 over null for better type feedback. 2363 map.SetHashMask(0); // Prefer sentinel 0 over null for better type feedback.
2608 2364
2609 // Read the keys and values. 2365 // Read the keys and values.
2610 bool read_as_reference = RawObject::IsCanonical(tags) ? false : true; 2366 bool read_as_reference = RawObject::IsCanonical(tags) ? false : true;
2611 for (intptr_t i = 0; i < used_data; i++) { 2367 for (intptr_t i = 0; i < used_data; i++) {
2612 *reader->PassiveObjectHandle() = reader->ReadObjectImpl(read_as_reference); 2368 *reader->PassiveObjectHandle() = reader->ReadObjectImpl(read_as_reference);
2613 data.SetAt(i, *reader->PassiveObjectHandle()); 2369 data.SetAt(i, *reader->PassiveObjectHandle());
2614 } 2370 }
2615 return map.raw(); 2371 return map.raw();
2616 } 2372 }
2617 2373
2618 2374
2619 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer, 2375 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer,
2620 intptr_t object_id, 2376 intptr_t object_id,
2621 Snapshot::Kind kind, 2377 Snapshot::Kind kind,
2622 bool as_reference) { 2378 bool as_reference) {
2623 if (Snapshot::IsFull(kind) || kind == Snapshot::kScript) { 2379 if (kind == Snapshot::kScript) {
2624 // The immutable maps that seed map literals are not yet VM-internal, so 2380 // The immutable maps that seed map literals are not yet VM-internal, so
2625 // we don't reach this. 2381 // we don't reach this.
2626 } 2382 }
2627 ASSERT(writer != NULL); 2383 ASSERT(writer != NULL);
2628 2384
2629 // Write out the serialization header value for this object. 2385 // Write out the serialization header value for this object.
2630 writer->WriteInlinedObjectHeader(object_id); 2386 writer->WriteInlinedObjectHeader(object_id);
2631 2387
2632 // Write out the class and tags information. 2388 // Write out the class and tags information.
2633 writer->WriteIndexedObject(kLinkedHashMapCid); 2389 writer->WriteIndexedObject(kLinkedHashMapCid);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 ASSERT(reader != NULL); 2431 ASSERT(reader != NULL);
2676 // Read the values. 2432 // Read the values.
2677 float value0 = reader->Read<float>(); 2433 float value0 = reader->Read<float>();
2678 float value1 = reader->Read<float>(); 2434 float value1 = reader->Read<float>();
2679 float value2 = reader->Read<float>(); 2435 float value2 = reader->Read<float>();
2680 float value3 = reader->Read<float>(); 2436 float value3 = reader->Read<float>();
2681 2437
2682 // Create a Float32x4 object. 2438 // Create a Float32x4 object.
2683 Float32x4& simd = Float32x4::ZoneHandle(reader->zone(), 2439 Float32x4& simd = Float32x4::ZoneHandle(reader->zone(),
2684 Float32x4::null()); 2440 Float32x4::null());
2685 if (Snapshot::IsFull(kind)) { 2441 simd = Float32x4::New(value0, value1, value2, value3, HEAP_SPACE(kind));
2686 simd = reader->NewFloat32x4(value0, value1, value2, value3);
2687 } else {
2688 simd = Float32x4::New(value0, value1, value2, value3, HEAP_SPACE(kind));
2689 }
2690 reader->AddBackRef(object_id, &simd, kIsDeserialized); 2442 reader->AddBackRef(object_id, &simd, kIsDeserialized);
2691 return simd.raw(); 2443 return simd.raw();
2692 } 2444 }
2693 2445
2694 2446
2695 void RawFloat32x4::WriteTo(SnapshotWriter* writer, 2447 void RawFloat32x4::WriteTo(SnapshotWriter* writer,
2696 intptr_t object_id, 2448 intptr_t object_id,
2697 Snapshot::Kind kind, 2449 Snapshot::Kind kind,
2698 bool as_reference) { 2450 bool as_reference) {
2699 ASSERT(writer != NULL); 2451 ASSERT(writer != NULL);
(...skipping 20 matching lines...) Expand all
2720 bool as_reference) { 2472 bool as_reference) {
2721 ASSERT(reader != NULL); 2473 ASSERT(reader != NULL);
2722 // Read the values. 2474 // Read the values.
2723 uint32_t value0 = reader->Read<uint32_t>(); 2475 uint32_t value0 = reader->Read<uint32_t>();
2724 uint32_t value1 = reader->Read<uint32_t>(); 2476 uint32_t value1 = reader->Read<uint32_t>();
2725 uint32_t value2 = reader->Read<uint32_t>(); 2477 uint32_t value2 = reader->Read<uint32_t>();
2726 uint32_t value3 = reader->Read<uint32_t>(); 2478 uint32_t value3 = reader->Read<uint32_t>();
2727 2479
2728 // Create a Float32x4 object. 2480 // Create a Float32x4 object.
2729 Int32x4& simd = Int32x4::ZoneHandle(reader->zone(), Int32x4::null()); 2481 Int32x4& simd = Int32x4::ZoneHandle(reader->zone(), Int32x4::null());
2730 2482 simd = Int32x4::New(value0, value1, value2, value3, HEAP_SPACE(kind));
2731 if (Snapshot::IsFull(kind)) {
2732 simd = reader->NewInt32x4(value0, value1, value2, value3);
2733 } else {
2734 simd = Int32x4::New(value0, value1, value2, value3, HEAP_SPACE(kind));
2735 }
2736 reader->AddBackRef(object_id, &simd, kIsDeserialized); 2483 reader->AddBackRef(object_id, &simd, kIsDeserialized);
2737 return simd.raw(); 2484 return simd.raw();
2738 } 2485 }
2739 2486
2740 2487
2741 void RawInt32x4::WriteTo(SnapshotWriter* writer, 2488 void RawInt32x4::WriteTo(SnapshotWriter* writer,
2742 intptr_t object_id, 2489 intptr_t object_id,
2743 Snapshot::Kind kind, 2490 Snapshot::Kind kind,
2744 bool as_reference) { 2491 bool as_reference) {
2745 ASSERT(writer != NULL); 2492 ASSERT(writer != NULL);
(...skipping 19 matching lines...) Expand all
2765 Snapshot::Kind kind, 2512 Snapshot::Kind kind,
2766 bool as_reference) { 2513 bool as_reference) {
2767 ASSERT(reader != NULL); 2514 ASSERT(reader != NULL);
2768 // Read the values. 2515 // Read the values.
2769 double value0 = reader->Read<double>(); 2516 double value0 = reader->Read<double>();
2770 double value1 = reader->Read<double>(); 2517 double value1 = reader->Read<double>();
2771 2518
2772 // Create a Float64x2 object. 2519 // Create a Float64x2 object.
2773 Float64x2& simd = Float64x2::ZoneHandle(reader->zone(), 2520 Float64x2& simd = Float64x2::ZoneHandle(reader->zone(),
2774 Float64x2::null()); 2521 Float64x2::null());
2775 if (Snapshot::IsFull(kind)) { 2522 simd = Float64x2::New(value0, value1, HEAP_SPACE(kind));
2776 simd = reader->NewFloat64x2(value0, value1);
2777 } else {
2778 simd = Float64x2::New(value0, value1, HEAP_SPACE(kind));
2779 }
2780 reader->AddBackRef(object_id, &simd, kIsDeserialized); 2523 reader->AddBackRef(object_id, &simd, kIsDeserialized);
2781 return simd.raw(); 2524 return simd.raw();
2782 } 2525 }
2783 2526
2784 2527
2785 void RawFloat64x2::WriteTo(SnapshotWriter* writer, 2528 void RawFloat64x2::WriteTo(SnapshotWriter* writer,
2786 intptr_t object_id, 2529 intptr_t object_id,
2787 Snapshot::Kind kind, 2530 Snapshot::Kind kind,
2788 bool as_reference) { 2531 bool as_reference) {
2789 ASSERT(writer != NULL); 2532 ASSERT(writer != NULL);
(...skipping 19 matching lines...) Expand all
2809 2552
2810 RawTypedData* TypedData::ReadFrom(SnapshotReader* reader, 2553 RawTypedData* TypedData::ReadFrom(SnapshotReader* reader,
2811 intptr_t object_id, 2554 intptr_t object_id,
2812 intptr_t tags, 2555 intptr_t tags,
2813 Snapshot::Kind kind, 2556 Snapshot::Kind kind,
2814 bool as_reference) { 2557 bool as_reference) {
2815 ASSERT(reader != NULL); 2558 ASSERT(reader != NULL);
2816 2559
2817 intptr_t cid = RawObject::ClassIdTag::decode(tags); 2560 intptr_t cid = RawObject::ClassIdTag::decode(tags);
2818 intptr_t len = reader->ReadSmiValue(); 2561 intptr_t len = reader->ReadSmiValue();
2819 TypedData& result = TypedData::ZoneHandle(reader->zone(), 2562 TypedData& result = TypedData::ZoneHandle(
2820 (Snapshot::IsFull(kind)) ? reader->NewTypedData(cid, len) 2563 reader->zone(), TypedData::New(cid, len, HEAP_SPACE(kind)));
2821 : TypedData::New(cid, len, HEAP_SPACE(kind)));
2822 reader->AddBackRef(object_id, &result, kIsDeserialized); 2564 reader->AddBackRef(object_id, &result, kIsDeserialized);
2823 2565
2824 // Setup the array elements. 2566 // Setup the array elements.
2825 intptr_t element_size = ElementSizeInBytes(cid); 2567 intptr_t element_size = ElementSizeInBytes(cid);
2826 intptr_t length_in_bytes = len * element_size; 2568 intptr_t length_in_bytes = len * element_size;
2827 switch (cid) { 2569 switch (cid) {
2828 case kTypedDataInt8ArrayCid: 2570 case kTypedDataInt8ArrayCid:
2829 case kTypedDataUint8ArrayCid: 2571 case kTypedDataUint8ArrayCid:
2830 case kTypedDataUint8ClampedArrayCid: { 2572 case kTypedDataUint8ClampedArrayCid: {
2831 NoSafepointScope no_safepoint; 2573 NoSafepointScope no_safepoint;
(...skipping 27 matching lines...) Expand all
2859 break; 2601 break;
2860 default: 2602 default:
2861 UNREACHABLE(); 2603 UNREACHABLE();
2862 } 2604 }
2863 // If it is a canonical constant make it one. 2605 // If it is a canonical constant make it one.
2864 // When reading a full snapshot we don't need to canonicalize the object 2606 // When reading a full snapshot we don't need to canonicalize the object
2865 // as it would already be a canonical object. 2607 // as it would already be a canonical object.
2866 // When reading a script snapshot or a message snapshot we always have 2608 // When reading a script snapshot or a message snapshot we always have
2867 // to canonicalize the object. 2609 // to canonicalize the object.
2868 if (RawObject::IsCanonical(tags)) { 2610 if (RawObject::IsCanonical(tags)) {
2869 if (Snapshot::IsFull(kind)) { 2611 result ^= result.CheckAndCanonicalize(reader->thread(), NULL);
2870 // Set the canonical bit. 2612 ASSERT(!result.IsNull());
2871 result.SetCanonical(); 2613 ASSERT(result.IsCanonical());
2872 } else {
2873 result ^= result.CheckAndCanonicalize(reader->thread(), NULL);
2874 ASSERT(!result.IsNull());
2875 ASSERT(result.IsCanonical());
2876 }
2877 } 2614 }
2878 return result.raw(); 2615 return result.raw();
2879 } 2616 }
2880 #undef TYPED_DATA_READ 2617 #undef TYPED_DATA_READ
2881 2618
2882 2619
2883 RawExternalTypedData* ExternalTypedData::ReadFrom(SnapshotReader* reader, 2620 RawExternalTypedData* ExternalTypedData::ReadFrom(SnapshotReader* reader,
2884 intptr_t object_id, 2621 intptr_t object_id,
2885 intptr_t tags, 2622 intptr_t tags,
2886 Snapshot::Kind kind, 2623 Snapshot::Kind kind,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
3122 writer->Write<uint64_t>(ptr()->id_); 2859 writer->Write<uint64_t>(ptr()->id_);
3123 writer->Write<uint64_t>(ptr()->origin_id_); 2860 writer->Write<uint64_t>(ptr()->origin_id_);
3124 } 2861 }
3125 2862
3126 2863
3127 RawStacktrace* Stacktrace::ReadFrom(SnapshotReader* reader, 2864 RawStacktrace* Stacktrace::ReadFrom(SnapshotReader* reader,
3128 intptr_t object_id, 2865 intptr_t object_id,
3129 intptr_t tags, 2866 intptr_t tags,
3130 Snapshot::Kind kind, 2867 Snapshot::Kind kind,
3131 bool as_reference) { 2868 bool as_reference) {
3132 if (Snapshot::IsFull(kind)) {
3133 Stacktrace& result = Stacktrace::ZoneHandle(reader->zone(),
3134 reader->NewStacktrace());
3135 reader->AddBackRef(object_id, &result, kIsDeserialized);
3136
3137 bool expand_inlined = reader->Read<bool>();
3138 result.set_expand_inlined(expand_inlined);
3139
3140 // Set all the object fields.
3141 READ_OBJECT_FIELDS(result,
3142 result.raw()->from(), result.raw()->to(),
3143 kAsReference);
3144
3145 return result.raw();
3146 }
3147 UNREACHABLE(); // Stacktraces are not sent in a snapshot. 2869 UNREACHABLE(); // Stacktraces are not sent in a snapshot.
3148 return Stacktrace::null(); 2870 return Stacktrace::null();
3149 } 2871 }
3150 2872
3151 2873
3152 void RawStacktrace::WriteTo(SnapshotWriter* writer, 2874 void RawStacktrace::WriteTo(SnapshotWriter* writer,
3153 intptr_t object_id, 2875 intptr_t object_id,
3154 Snapshot::Kind kind, 2876 Snapshot::Kind kind,
3155 bool as_reference) { 2877 bool as_reference) {
3156 if (Snapshot::IsFull(kind)) { 2878 ASSERT(kind == Snapshot::kMessage);
3157 ASSERT(writer != NULL); 2879 writer->SetWriteException(Exceptions::kArgument,
3158 ASSERT(this == Isolate::Current()->object_store()-> 2880 "Illegal argument in isolate message"
3159 preallocated_stack_trace()); 2881 " : (object is a stacktrace)");
3160
3161 // Write out the serialization header value for this object.
3162 writer->WriteInlinedObjectHeader(object_id);
3163
3164 // Write out the class and tags information.
3165 writer->WriteIndexedObject(kStacktraceCid);
3166 writer->WriteTags(writer->GetObjectTags(this));
3167
3168 writer->Write(ptr()->expand_inlined_);
3169
3170 // Write out all the object pointer fields.
3171 SnapshotWriterVisitor visitor(writer, kAsReference);
3172 visitor.VisitPointers(from(), to());
3173 } else {
3174 // Stacktraces are not allowed in other snapshot forms.
3175 writer->SetWriteException(Exceptions::kArgument,
3176 "Illegal argument in isolate message"
3177 " : (object is a stacktrace)");
3178 }
3179 } 2882 }
3180 2883
3181 2884
3182 RawRegExp* RegExp::ReadFrom(SnapshotReader* reader, 2885 RawRegExp* RegExp::ReadFrom(SnapshotReader* reader,
3183 intptr_t object_id, 2886 intptr_t object_id,
3184 intptr_t tags, 2887 intptr_t tags,
3185 Snapshot::Kind kind, 2888 Snapshot::Kind kind,
3186 bool as_reference) { 2889 bool as_reference) {
3187 ASSERT(reader != NULL); 2890 ASSERT(reader != NULL);
3188 2891
3189 // Allocate RegExp object. 2892 // Allocate RegExp object.
3190 RegExp& regex = RegExp::ZoneHandle(reader->zone(), NEW_OBJECT(RegExp)); 2893 RegExp& regex = RegExp::ZoneHandle(reader->zone(), RegExp::New());
3191 reader->AddBackRef(object_id, &regex, kIsDeserialized); 2894 reader->AddBackRef(object_id, &regex, kIsDeserialized);
3192 2895
3193 // Read and Set all the other fields. 2896 // Read and Set all the other fields.
3194 regex.StoreSmi(&regex.raw_ptr()->num_bracket_expressions_, 2897 regex.StoreSmi(&regex.raw_ptr()->num_bracket_expressions_,
3195 reader->ReadAsSmi()); 2898 reader->ReadAsSmi());
3196 *reader->StringHandle() ^= reader->ReadObjectImpl(kAsInlinedObject); 2899 *reader->StringHandle() ^= reader->ReadObjectImpl(kAsInlinedObject);
3197 regex.set_pattern(*reader->StringHandle()); 2900 regex.set_pattern(*reader->StringHandle());
3198 regex.StoreNonPointer(&regex.raw_ptr()->num_registers_, 2901 regex.StoreNonPointer(&regex.raw_ptr()->num_registers_,
3199 reader->Read<int32_t>()); 2902 reader->Read<int32_t>());
3200 regex.StoreNonPointer(&regex.raw_ptr()->type_flags_, 2903 regex.StoreNonPointer(&regex.raw_ptr()->type_flags_,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3237 2940
3238 2941
3239 RawWeakProperty* WeakProperty::ReadFrom(SnapshotReader* reader, 2942 RawWeakProperty* WeakProperty::ReadFrom(SnapshotReader* reader,
3240 intptr_t object_id, 2943 intptr_t object_id,
3241 intptr_t tags, 2944 intptr_t tags,
3242 Snapshot::Kind kind, 2945 Snapshot::Kind kind,
3243 bool as_reference) { 2946 bool as_reference) {
3244 ASSERT(reader != NULL); 2947 ASSERT(reader != NULL);
3245 2948
3246 // Allocate the weak property object. 2949 // Allocate the weak property object.
3247 WeakProperty& weak_property = WeakProperty::ZoneHandle( 2950 WeakProperty& weak_property = WeakProperty::ZoneHandle(reader->zone(),
3248 reader->zone(), NEW_OBJECT(WeakProperty)); 2951 WeakProperty::New());
3249 reader->AddBackRef(object_id, &weak_property, kIsDeserialized); 2952 reader->AddBackRef(object_id, &weak_property, kIsDeserialized);
3250 2953
3251 // Set all the object fields. 2954 // Set all the object fields.
3252 READ_OBJECT_FIELDS(weak_property, 2955 READ_OBJECT_FIELDS(weak_property,
3253 weak_property.raw()->from(), weak_property.raw()->to(), 2956 weak_property.raw()->from(), weak_property.raw()->to(),
3254 kAsReference); 2957 kAsReference);
3255 2958
3256 return weak_property.raw(); 2959 return weak_property.raw();
3257 } 2960 }
3258 2961
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3319 // We do not allow objects with native fields in an isolate message. 3022 // We do not allow objects with native fields in an isolate message.
3320 writer->SetWriteException(Exceptions::kArgument, 3023 writer->SetWriteException(Exceptions::kArgument,
3321 "Illegal argument in isolate message" 3024 "Illegal argument in isolate message"
3322 " : (object is a UserTag)"); 3025 " : (object is a UserTag)");
3323 } else { 3026 } else {
3324 UNREACHABLE(); 3027 UNREACHABLE();
3325 } 3028 }
3326 } 3029 }
3327 3030
3328 } // namespace dart 3031 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698