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

Side by Side Diff: vm/raw_object_snapshot.cc

Issue 8970004: Changes to create an application snapshot which can be layered on top (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/bigint_operations.h" 5 #include "vm/bigint_operations.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/visitor.h" 9 #include "vm/visitor.h"
10 10
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 24
25 RawClass* Class::ReadFrom(SnapshotReader* reader, 25 RawClass* Class::ReadFrom(SnapshotReader* reader,
26 intptr_t object_id, 26 intptr_t object_id,
27 intptr_t tags, 27 intptr_t tags,
28 Snapshot::Kind kind) { 28 Snapshot::Kind kind) {
29 ASSERT(reader != NULL); 29 ASSERT(reader != NULL);
30 30
31 Class& cls = Class::ZoneHandle(); 31 Class& cls = Class::ZoneHandle();
32 if (kind == Snapshot::kFull) { 32 if ((kind == Snapshot::kFull) ||
33 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) {
Ivan Posva 2011/12/19 21:32:42 I am wondering if there is a way to simplify the l
siva 2011/12/19 23:50:00 I would have to think about how this can be done b
33 // Read in the base information. 34 // Read in the base information.
34 ObjectKind kind = reader->Read<ObjectKind>(); 35 ObjectKind kind = reader->Read<ObjectKind>();
35 36
36 // Allocate class object of specified kind. 37 // Allocate class object of specified kind.
37 cls = Class::GetClass(kind); 38 cls = Class::GetClass(kind);
38 reader->AddBackwardReference(object_id, &cls); 39 reader->AddBackwardReference(object_id, &cls);
39 40
40 // Set the object tags. 41 // Set the object tags.
41 cls.set_tags(tags); 42 cls.set_tags(tags);
42 43
(...skipping 21 matching lines...) Expand all
64 cls ^= reader->ReadClassId(object_id); 65 cls ^= reader->ReadClassId(object_id);
65 } 66 }
66 return cls.raw(); 67 return cls.raw();
67 } 68 }
68 69
69 70
70 void RawClass::WriteTo(SnapshotWriter* writer, 71 void RawClass::WriteTo(SnapshotWriter* writer,
71 intptr_t object_id, 72 intptr_t object_id,
72 Snapshot::Kind kind) { 73 Snapshot::Kind kind) {
73 ASSERT(writer != NULL); 74 ASSERT(writer != NULL);
74 SnapshotWriterVisitor visitor(writer);
75 75
76 // Write out the serialization header value for this object. 76 // Write out the serialization header value for this object.
77 writer->WriteSerializationMarker(kInlined, object_id); 77 writer->WriteSerializationMarker(kInlined, object_id);
78 78
79 if (kind == Snapshot::kFull) { 79 if ((kind == Snapshot::kFull) ||
80 (kind == Snapshot::kScript && !IsCreatedFromSnapshot())) {
80 // Write out the class and tags information. 81 // Write out the class and tags information.
81 writer->WriteObjectHeader(Object::kClassClass, ptr()->tags_); 82 writer->WriteObjectHeader(Object::kClassClass, ptr()->tags_);
82 83
83 // Write out all the non object pointer fields. 84 // Write out all the non object pointer fields.
84 // NOTE: cpp_vtable_ is not written. 85 // NOTE: cpp_vtable_ is not written.
85 writer->Write<ObjectKind>(ptr()->instance_kind_); 86 writer->Write<ObjectKind>(ptr()->instance_kind_);
86 writer->Write<intptr_t>(ptr()->instance_size_); 87 writer->Write<intptr_t>(ptr()->instance_size_);
87 writer->Write<intptr_t>(ptr()->type_arguments_instance_field_offset_); 88 writer->Write<intptr_t>(ptr()->type_arguments_instance_field_offset_);
88 writer->Write<intptr_t>(ptr()->next_field_offset_); 89 writer->Write<intptr_t>(ptr()->next_field_offset_);
89 writer->Write<intptr_t>(ptr()->num_native_fields_); 90 writer->Write<intptr_t>(ptr()->num_native_fields_);
90 writer->Write<int8_t>(ptr()->class_state_); 91 writer->Write<int8_t>(ptr()->class_state_);
91 writer->Write<bool>(ptr()->is_const_); 92 writer->Write<bool>(ptr()->is_const_);
92 writer->Write<bool>(ptr()->is_interface_); 93 writer->Write<bool>(ptr()->is_interface_);
93 94
94 // Write out all the object pointer fields. 95 // Write out all the object pointer fields.
96 SnapshotWriterVisitor visitor(writer);
95 visitor.VisitPointers(from(), to()); 97 visitor.VisitPointers(from(), to());
96 } else { 98 } else {
97 writer->WriteClassId(this); 99 writer->WriteClassId(this);
98 } 100 }
99 } 101 }
100 102
101 103
102 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, 104 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader,
103 intptr_t object_id, 105 intptr_t object_id,
104 intptr_t tags, 106 intptr_t tags,
(...skipping 20 matching lines...) Expand all
125 *(unresolved_class.raw()->from() + i) = reader->ReadObject(); 127 *(unresolved_class.raw()->from() + i) = reader->ReadObject();
126 } 128 }
127 return unresolved_class.raw(); 129 return unresolved_class.raw();
128 } 130 }
129 131
130 132
131 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, 133 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer,
132 intptr_t object_id, 134 intptr_t object_id,
133 Snapshot::Kind kind) { 135 Snapshot::Kind kind) {
134 ASSERT(writer != NULL); 136 ASSERT(writer != NULL);
135 SnapshotWriterVisitor visitor(writer);
136 137
137 // Write out the serialization header value for this object. 138 // Write out the serialization header value for this object.
138 writer->WriteSerializationMarker(kInlined, object_id); 139 writer->WriteSerializationMarker(kInlined, object_id);
139 140
140 // Write out the class and tags information. 141 // Write out the class and tags information.
141 writer->WriteObjectHeader(Object::kUnresolvedClassClass, ptr()->tags_); 142 writer->WriteObjectHeader(Object::kUnresolvedClassClass, ptr()->tags_);
142 143
143 // Write out all the non object pointer fields. 144 // Write out all the non object pointer fields.
144 writer->Write<intptr_t>(ptr()->token_index_); 145 writer->Write<intptr_t>(ptr()->token_index_);
145 146
146 // Write out all the object pointer fields. 147 // Write out all the object pointer fields.
148 SnapshotWriterVisitor visitor(writer);
147 visitor.VisitPointers(from(), to()); 149 visitor.VisitPointers(from(), to());
148 } 150 }
149 151
150 152
151 RawAbstractType* AbstractType::ReadFrom(SnapshotReader* reader, 153 RawAbstractType* AbstractType::ReadFrom(SnapshotReader* reader,
152 intptr_t object_id, 154 intptr_t object_id,
153 intptr_t tags, 155 intptr_t tags,
154 Snapshot::Kind kind) { 156 Snapshot::Kind kind) {
155 UNREACHABLE(); // AbstractType is an abstract class. 157 UNREACHABLE(); // AbstractType is an abstract class.
156 return NULL; 158 return NULL;
(...skipping 24 matching lines...) Expand all
181 parameterized_type.set_type_state(reader->Read<int8_t>()); 183 parameterized_type.set_type_state(reader->Read<int8_t>());
182 184
183 // Set all the object fields. 185 // Set all the object fields.
184 // TODO(5411462): Need to assert No GC can happen here, even though 186 // TODO(5411462): Need to assert No GC can happen here, even though
185 // allocations may happen. 187 // allocations may happen.
186 intptr_t num_flds = (parameterized_type.raw()->to() - 188 intptr_t num_flds = (parameterized_type.raw()->to() -
187 parameterized_type.raw()->from()); 189 parameterized_type.raw()->from());
188 for (intptr_t i = 0; i <= num_flds; i++) { 190 for (intptr_t i = 0; i <= num_flds; i++) {
189 *(parameterized_type.raw()->from() + i) = reader->ReadObject(); 191 *(parameterized_type.raw()->from() + i) = reader->ReadObject();
190 } 192 }
193
194 // If object needs to be a canonical object, Canonicalize it.
195 if ((kind != Snapshot::kFull) && parameterized_type.IsCanonical()) {
196 parameterized_type ^= parameterized_type.Canonicalize();
197 }
191 return parameterized_type.raw(); 198 return parameterized_type.raw();
192 } 199 }
193 200
194 201
195 void RawType::WriteTo(SnapshotWriter* writer, 202 void RawType::WriteTo(SnapshotWriter* writer,
196 intptr_t object_id, 203 intptr_t object_id,
197 Snapshot::Kind kind) { 204 Snapshot::Kind kind) {
198 ASSERT(writer != NULL); 205 ASSERT(writer != NULL);
199 SnapshotWriterVisitor visitor(writer);
200 206
201 // Write out the serialization header value for this object. 207 // Write out the serialization header value for this object.
202 writer->WriteSerializationMarker(kInlined, object_id); 208 writer->WriteSerializationMarker(kInlined, object_id);
203 209
204 // Write out the class and tags information. 210 // Write out the class and tags information.
205 writer->WriteObjectHeader(Object::kTypeClass, ptr()->tags_); 211 writer->WriteObjectHeader(Object::kTypeClass, ptr()->tags_);
206 212
207 // Write out all the non object pointer fields. 213 // Write out all the non object pointer fields.
208 writer->Write<int8_t>(ptr()->type_state_); 214 writer->Write<int8_t>(ptr()->type_state_);
209 215
210 // Write out all the object pointer fields. 216 // Write out all the object pointer fields.
217 SnapshotWriterVisitor visitor(writer);
211 visitor.VisitPointers(from(), to()); 218 visitor.VisitPointers(from(), to());
212 } 219 }
213 220
214 221
215 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, 222 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader,
216 intptr_t object_id, 223 intptr_t object_id,
217 intptr_t tags, 224 intptr_t tags,
218 Snapshot::Kind kind) { 225 Snapshot::Kind kind) {
219 ASSERT(reader != NULL); 226 ASSERT(reader != NULL);
220 227
(...skipping 19 matching lines...) Expand all
240 } 247 }
241 248
242 return type_parameter.raw(); 249 return type_parameter.raw();
243 } 250 }
244 251
245 252
246 void RawTypeParameter::WriteTo(SnapshotWriter* writer, 253 void RawTypeParameter::WriteTo(SnapshotWriter* writer,
247 intptr_t object_id, 254 intptr_t object_id,
248 Snapshot::Kind kind) { 255 Snapshot::Kind kind) {
249 ASSERT(writer != NULL); 256 ASSERT(writer != NULL);
250 SnapshotWriterVisitor visitor(writer);
251 257
252 // Write out the serialization header value for this object. 258 // Write out the serialization header value for this object.
253 writer->WriteSerializationMarker(kInlined, object_id); 259 writer->WriteSerializationMarker(kInlined, object_id);
254 260
255 // Write out the class and tags information. 261 // Write out the class and tags information.
256 writer->WriteObjectHeader(Object::kTypeParameterClass, ptr()->tags_); 262 writer->WriteObjectHeader(Object::kTypeParameterClass, ptr()->tags_);
257 263
258 // Write out all the non object pointer fields. 264 // Write out all the non object pointer fields.
259 writer->Write<intptr_t>(ptr()->index_); 265 writer->Write<intptr_t>(ptr()->index_);
260 writer->Write<int8_t>(ptr()->type_state_); 266 writer->Write<int8_t>(ptr()->type_state_);
261 267
262 // Write out all the object pointer fields. 268 // Write out all the object pointer fields.
269 SnapshotWriterVisitor visitor(writer);
263 visitor.VisitPointers(from(), to()); 270 visitor.VisitPointers(from(), to());
264 } 271 }
265 272
266 273
267 RawInstantiatedType* InstantiatedType::ReadFrom(SnapshotReader* reader, 274 RawInstantiatedType* InstantiatedType::ReadFrom(SnapshotReader* reader,
268 intptr_t object_id, 275 intptr_t object_id,
269 intptr_t tags, 276 intptr_t tags,
270 Snapshot::Kind kind) { 277 Snapshot::Kind kind) {
271 ASSERT(reader != NULL); 278 ASSERT(reader != NULL);
272 ASSERT(kind == Snapshot::kMessage); 279 ASSERT(kind == Snapshot::kMessage);
(...skipping 16 matching lines...) Expand all
289 } 296 }
290 return instantiated_type.raw(); 297 return instantiated_type.raw();
291 } 298 }
292 299
293 300
294 void RawInstantiatedType::WriteTo(SnapshotWriter* writer, 301 void RawInstantiatedType::WriteTo(SnapshotWriter* writer,
295 intptr_t object_id, 302 intptr_t object_id,
296 Snapshot::Kind kind) { 303 Snapshot::Kind kind) {
297 ASSERT(writer != NULL); 304 ASSERT(writer != NULL);
298 ASSERT(kind == Snapshot::kMessage); 305 ASSERT(kind == Snapshot::kMessage);
299 SnapshotWriterVisitor visitor(writer);
300 306
301 // Write out the serialization header value for this object. 307 // Write out the serialization header value for this object.
302 writer->WriteSerializationMarker(kInlined, object_id); 308 writer->WriteSerializationMarker(kInlined, object_id);
303 309
304 // Write out the class and tags information. 310 // Write out the class and tags information.
305 writer->WriteObjectHeader(Object::kInstantiatedTypeClass, ptr()->tags_); 311 writer->WriteObjectHeader(Object::kInstantiatedTypeClass, ptr()->tags_);
306 312
307 // Write out all the object pointer fields. 313 // Write out all the object pointer fields.
314 SnapshotWriterVisitor visitor(writer);
308 visitor.VisitPointers(from(), to()); 315 visitor.VisitPointers(from(), to());
309 } 316 }
310 317
311 318
312 RawAbstractTypeArguments* AbstractTypeArguments::ReadFrom( 319 RawAbstractTypeArguments* AbstractTypeArguments::ReadFrom(
313 SnapshotReader* reader, 320 SnapshotReader* reader,
314 intptr_t object_id, 321 intptr_t object_id,
315 intptr_t tags, 322 intptr_t tags,
316 Snapshot::Kind kind) { 323 Snapshot::Kind kind) {
317 UNREACHABLE(); // AbstractTypeArguments is an abstract class. 324 UNREACHABLE(); // AbstractTypeArguments is an abstract class.
(...skipping 22 matching lines...) Expand all
340 TypeArguments::Handle(TypeArguments::New(len)); 347 TypeArguments::Handle(TypeArguments::New(len));
341 reader->AddBackwardReference(object_id, &type_arguments); 348 reader->AddBackwardReference(object_id, &type_arguments);
342 349
343 // Now set all the object fields. 350 // Now set all the object fields.
344 AbstractType& type = AbstractType::Handle(); 351 AbstractType& type = AbstractType::Handle();
345 for (intptr_t i = 0; i < len; i++) { 352 for (intptr_t i = 0; i < len; i++) {
346 type ^= reader->ReadObject(); 353 type ^= reader->ReadObject();
347 type_arguments.SetTypeAt(i, type); 354 type_arguments.SetTypeAt(i, type);
348 } 355 }
349 356
350 // Set the object tags. 357 // Set the object tags (This is done after setting the object fields
358 // because 'SetTypeAt' has an assertion to check if the object is not
359 // already canonical).
351 type_arguments.set_tags(tags); 360 type_arguments.set_tags(tags);
352 361
362 // If object needs to be a canonical object, Canonicalize it.
363 if ((kind != Snapshot::kFull) && type_arguments.IsCanonical()) {
364 type_arguments ^= type_arguments.Canonicalize();
365 }
353 return type_arguments.raw(); 366 return type_arguments.raw();
354 } 367 }
355 368
356 369
357 void RawTypeArguments::WriteTo(SnapshotWriter* writer, 370 void RawTypeArguments::WriteTo(SnapshotWriter* writer,
358 intptr_t object_id, 371 intptr_t object_id,
359 Snapshot::Kind kind) { 372 Snapshot::Kind kind) {
360 ASSERT(writer != NULL); 373 ASSERT(writer != NULL);
361 374
362 // Write out the serialization header value for this object. 375 // Write out the serialization header value for this object.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 415 }
403 return instantiated_type_arguments.raw(); 416 return instantiated_type_arguments.raw();
404 } 417 }
405 418
406 419
407 void RawInstantiatedTypeArguments::WriteTo(SnapshotWriter* writer, 420 void RawInstantiatedTypeArguments::WriteTo(SnapshotWriter* writer,
408 intptr_t object_id, 421 intptr_t object_id,
409 Snapshot::Kind kind) { 422 Snapshot::Kind kind) {
410 ASSERT(writer != NULL); 423 ASSERT(writer != NULL);
411 ASSERT(kind == Snapshot::kMessage); 424 ASSERT(kind == Snapshot::kMessage);
412 SnapshotWriterVisitor visitor(writer);
413 425
414 // Write out the serialization header value for this object. 426 // Write out the serialization header value for this object.
415 writer->WriteSerializationMarker(kInlined, object_id); 427 writer->WriteSerializationMarker(kInlined, object_id);
416 428
417 // Write out the class and tags information. 429 // Write out the class and tags information.
418 writer->WriteObjectHeader(Object::kInstantiatedTypeArgumentsClass, 430 writer->WriteObjectHeader(Object::kInstantiatedTypeArgumentsClass,
419 ptr()->tags_); 431 ptr()->tags_);
420 432
421 // Write out all the object pointer fields. 433 // Write out all the object pointer fields.
434 SnapshotWriterVisitor visitor(writer);
422 visitor.VisitPointers(from(), to()); 435 visitor.VisitPointers(from(), to());
423 } 436 }
424 437
425 438
426 RawFunction* Function::ReadFrom(SnapshotReader* reader, 439 RawFunction* Function::ReadFrom(SnapshotReader* reader,
427 intptr_t object_id, 440 intptr_t object_id,
428 intptr_t tags, 441 intptr_t tags,
429 Snapshot::Kind kind) { 442 Snapshot::Kind kind) {
430 ASSERT(reader != NULL); 443 ASSERT(reader != NULL);
444 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
431 445
432 // Allocate function object. 446 // Allocate function object.
433 Function& func = Function::ZoneHandle(Function::New()); 447 Function& func = Function::ZoneHandle(Function::New());
434 reader->AddBackwardReference(object_id, &func); 448 reader->AddBackwardReference(object_id, &func);
435 449
436 // Set the object tags. 450 // Set the object tags.
437 func.set_tags(tags); 451 func.set_tags(tags);
438 452
439 // Set all the non object fields. 453 // Set all the non object fields.
440 func.set_token_index(reader->Read<intptr_t>()); 454 func.set_token_index(reader->Read<intptr_t>());
(...skipping 15 matching lines...) Expand all
456 } 470 }
457 471
458 return func.raw(); 472 return func.raw();
459 } 473 }
460 474
461 475
462 void RawFunction::WriteTo(SnapshotWriter* writer, 476 void RawFunction::WriteTo(SnapshotWriter* writer,
463 intptr_t object_id, 477 intptr_t object_id,
464 Snapshot::Kind kind) { 478 Snapshot::Kind kind) {
465 ASSERT(writer != NULL); 479 ASSERT(writer != NULL);
466 SnapshotWriterVisitor visitor(writer); 480 ASSERT(kind != Snapshot::kMessage && !IsCreatedFromSnapshot());
467 481
468 // Write out the serialization header value for this object. 482 // Write out the serialization header value for this object.
469 writer->WriteSerializationMarker(kInlined, object_id); 483 writer->WriteSerializationMarker(kInlined, object_id);
470 484
471 // Write out the class and tags information. 485 // Write out the class and tags information.
472 writer->WriteObjectHeader(Object::kFunctionClass, ptr()->tags_); 486 writer->WriteObjectHeader(Object::kFunctionClass, ptr()->tags_);
473 487
474 // Write out all the non object fields. 488 // Write out all the non object fields.
475 writer->Write<intptr_t>(ptr()->token_index_); 489 writer->Write<intptr_t>(ptr()->token_index_);
476 writer->Write<intptr_t>(ptr()->num_fixed_parameters_); 490 writer->Write<intptr_t>(ptr()->num_fixed_parameters_);
477 writer->Write<intptr_t>(ptr()->num_optional_parameters_); 491 writer->Write<intptr_t>(ptr()->num_optional_parameters_);
478 writer->Write<intptr_t>(ptr()->invocation_counter_); 492 writer->Write<intptr_t>(ptr()->invocation_counter_);
479 writer->Write<intptr_t>(ptr()->deoptimization_counter_); 493 writer->Write<intptr_t>(ptr()->deoptimization_counter_);
480 writer->Write<intptr_t>(ptr()->kind_); 494 writer->Write<intptr_t>(ptr()->kind_);
481 writer->Write<bool>(ptr()->is_static_); 495 writer->Write<bool>(ptr()->is_static_);
482 writer->Write<bool>(ptr()->is_const_); 496 writer->Write<bool>(ptr()->is_const_);
483 writer->Write<bool>(ptr()->is_optimizable_); 497 writer->Write<bool>(ptr()->is_optimizable_);
484 498
485 // Write out all the object pointer fields. 499 // Write out all the object pointer fields.
500 SnapshotWriterVisitor visitor(writer);
486 visitor.VisitPointers(from(), to()); 501 visitor.VisitPointers(from(), to());
487 } 502 }
488 503
489 504
490 RawField* Field::ReadFrom(SnapshotReader* reader, 505 RawField* Field::ReadFrom(SnapshotReader* reader,
491 intptr_t object_id, 506 intptr_t object_id,
492 intptr_t tags, 507 intptr_t tags,
493 Snapshot::Kind kind) { 508 Snapshot::Kind kind) {
494 ASSERT(reader != NULL); 509 ASSERT(reader != NULL);
510 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
495 511
496 // Allocate field object. 512 // Allocate field object.
497 Field& field = Field::ZoneHandle(Field::New()); 513 Field& field = Field::ZoneHandle(Field::New());
498 reader->AddBackwardReference(object_id, &field); 514 reader->AddBackwardReference(object_id, &field);
499 515
500 // Set the object tags. 516 // Set the object tags.
501 field.set_tags(tags); 517 field.set_tags(tags);
502 518
503 // Set all non object fields. 519 // Set all non object fields.
504 field.set_token_index(reader->Read<intptr_t>()); 520 field.set_token_index(reader->Read<intptr_t>());
(...skipping 10 matching lines...) Expand all
515 } 531 }
516 532
517 return field.raw(); 533 return field.raw();
518 } 534 }
519 535
520 536
521 void RawField::WriteTo(SnapshotWriter* writer, 537 void RawField::WriteTo(SnapshotWriter* writer,
522 intptr_t object_id, 538 intptr_t object_id,
523 Snapshot::Kind kind) { 539 Snapshot::Kind kind) {
524 ASSERT(writer != NULL); 540 ASSERT(writer != NULL);
525 SnapshotWriterVisitor visitor(writer); 541 ASSERT(kind != Snapshot::kMessage && !IsCreatedFromSnapshot());
526 542
527 // Write out the serialization header value for this object. 543 // Write out the serialization header value for this object.
528 writer->WriteSerializationMarker(kInlined, object_id); 544 writer->WriteSerializationMarker(kInlined, object_id);
529 545
530 // Write out the class and tags information. 546 // Write out the class and tags information.
531 writer->WriteObjectHeader(Object::kFieldClass, ptr()->tags_); 547 writer->WriteObjectHeader(Object::kFieldClass, ptr()->tags_);
532 548
549 // Write out all the non object fields.
533 writer->Write<intptr_t>(ptr()->token_index_); 550 writer->Write<intptr_t>(ptr()->token_index_);
534 writer->Write<bool>(ptr()->is_static_); 551 writer->Write<bool>(ptr()->is_static_);
535 writer->Write<bool>(ptr()->is_final_); 552 writer->Write<bool>(ptr()->is_final_);
536 writer->Write<bool>(ptr()->has_initializer_); 553 writer->Write<bool>(ptr()->has_initializer_);
537 554
538 // Write out all the object pointer fields. 555 // Write out all the object pointer fields.
556 SnapshotWriterVisitor visitor(writer);
539 visitor.VisitPointers(from(), to()); 557 visitor.VisitPointers(from(), to());
540 } 558 }
541 559
542 560
543 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, 561 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader,
544 intptr_t object_id, 562 intptr_t object_id,
545 intptr_t tags, 563 intptr_t tags,
546 Snapshot::Kind kind) { 564 Snapshot::Kind kind) {
547 ASSERT(reader != NULL); 565 ASSERT(reader != NULL);
566 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
548 567
549 // Read the length so that we can determine number of tokens to read. 568 // Read the length so that we can determine number of tokens to read.
550 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); 569 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>());
551 intptr_t len = Smi::Value(smi_len); 570 intptr_t len = Smi::Value(smi_len);
552 571
553 // Create the token stream object. 572 // Create the token stream object.
554 TokenStream& token_stream = TokenStream::ZoneHandle(TokenStream::New(len)); 573 TokenStream& token_stream = TokenStream::ZoneHandle(TokenStream::New(len));
555 reader->AddBackwardReference(object_id, &token_stream); 574 reader->AddBackwardReference(object_id, &token_stream);
556 575
557 // Set the object tags. 576 // Set the object tags.
558 token_stream.set_tags(tags); 577 token_stream.set_tags(tags);
559 578
560 // Read the token stream into the TokenStream. 579 // Read the token stream into the TokenStream.
561 String& literal = String::Handle(); 580 String& literal = String::Handle();
562 for (intptr_t i = 0; i < len; i++) { 581 for (intptr_t i = 0; i < len; i++) {
563 Token::Kind kind = static_cast<Token::Kind>( 582 Token::Kind kind = static_cast<Token::Kind>(
564 Smi::Value(GetSmi(reader->Read<intptr_t>()))); 583 Smi::Value(GetSmi(reader->Read<intptr_t>())));
565 literal ^= reader->ReadObject(); 584 literal ^= reader->ReadObject();
566 token_stream.SetTokenAt(i, kind, literal); 585 token_stream.SetTokenAt(i, kind, literal);
567 } 586 }
568 return token_stream.raw(); 587 return token_stream.raw();
569 } 588 }
570 589
571 590
572 void RawTokenStream::WriteTo(SnapshotWriter* writer, 591 void RawTokenStream::WriteTo(SnapshotWriter* writer,
573 intptr_t object_id, 592 intptr_t object_id,
574 Snapshot::Kind kind) { 593 Snapshot::Kind kind) {
575 ASSERT(writer != NULL); 594 ASSERT(writer != NULL);
595 ASSERT(kind != Snapshot::kMessage && !IsCreatedFromSnapshot());
576 596
577 // Write out the serialization header value for this object. 597 // Write out the serialization header value for this object.
578 writer->WriteSerializationMarker(kInlined, object_id); 598 writer->WriteSerializationMarker(kInlined, object_id);
579 599
580 // Write out the class and tags information. 600 // Write out the class and tags information.
581 writer->WriteObjectHeader(Object::kTokenStreamClass, ptr()->tags_); 601 writer->WriteObjectHeader(Object::kTokenStreamClass, ptr()->tags_);
582 602
583 // Write out the length field. 603 // Write out the length field.
584 writer->Write<RawObject*>(ptr()->length_); 604 writer->Write<RawObject*>(ptr()->length_);
585 605
586 // Write out the token stream (token kind and literal). 606 // Write out the token stream (token kind and literal).
587 intptr_t len = Smi::Value(ptr()->length_); 607 intptr_t len = Smi::Value(ptr()->length_);
588 for (intptr_t i = 0; i < TokenStream::StreamLength(len); i++) { 608 for (intptr_t i = 0; i < TokenStream::StreamLength(len); i++) {
589 writer->WriteObject(ptr()->data_[i]); 609 writer->WriteObject(ptr()->data_[i]);
590 } 610 }
591 } 611 }
592 612
593 613
594 RawScript* Script::ReadFrom(SnapshotReader* reader, 614 RawScript* Script::ReadFrom(SnapshotReader* reader,
595 intptr_t object_id, 615 intptr_t object_id,
596 intptr_t tags, 616 intptr_t tags,
597 Snapshot::Kind kind) { 617 Snapshot::Kind kind) {
598 ASSERT(reader != NULL); 618 ASSERT(reader != NULL);
619 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
599 620
600 // Allocate script object. 621 // Allocate script object.
601 Script& script = Script::ZoneHandle(Script::New()); 622 Script& script = Script::ZoneHandle(Script::New());
602 reader->AddBackwardReference(object_id, &script); 623 reader->AddBackwardReference(object_id, &script);
603 624
604 // Set the object tags. 625 // Set the object tags.
605 script.set_tags(tags); 626 script.set_tags(tags);
606 627
607 // Set all the object fields. 628 // Set all the object fields.
608 // TODO(5411462): Need to assert No GC can happen here, even though 629 // TODO(5411462): Need to assert No GC can happen here, even though
609 // allocations may happen. 630 // allocations may happen.
610 intptr_t num_flds = (script.raw()->to() - script.raw()->from()); 631 intptr_t num_flds = (script.raw()->to() - script.raw()->from());
611 for (intptr_t i = 0; i <= num_flds; i++) { 632 for (intptr_t i = 0; i <= num_flds; i++) {
612 *(script.raw()->from() + i) = reader->ReadObject(); 633 *(script.raw()->from() + i) = reader->ReadObject();
613 } 634 }
614 635
615 return script.raw(); 636 return script.raw();
616 } 637 }
617 638
618 639
619 void RawScript::WriteTo(SnapshotWriter* writer, 640 void RawScript::WriteTo(SnapshotWriter* writer,
620 intptr_t object_id, 641 intptr_t object_id,
621 Snapshot::Kind kind) { 642 Snapshot::Kind kind) {
622 ASSERT(writer != NULL); 643 ASSERT(writer != NULL);
623 ASSERT(tokens_ != TokenStream::null()); 644 ASSERT(tokens_ != TokenStream::null());
624 SnapshotWriterVisitor visitor(writer); 645 ASSERT(kind != Snapshot::kMessage && !IsCreatedFromSnapshot());
625 646
626 // Write out the serialization header value for this object. 647 // Write out the serialization header value for this object.
627 writer->WriteSerializationMarker(kInlined, object_id); 648 writer->WriteSerializationMarker(kInlined, object_id);
628 649
629 // Write out the class and tags information. 650 // Write out the class and tags information.
630 writer->WriteObjectHeader(Object::kScriptClass, ptr()->tags_); 651 writer->WriteObjectHeader(Object::kScriptClass, ptr()->tags_);
631 652
632 // Write out all the object pointer fields. 653 // Write out all the object pointer fields.
654 SnapshotWriterVisitor visitor(writer);
633 visitor.VisitPointers(from(), to()); 655 visitor.VisitPointers(from(), to());
634 } 656 }
635 657
636 658
637 RawLibrary* Library::ReadFrom(SnapshotReader* reader, 659 RawLibrary* Library::ReadFrom(SnapshotReader* reader,
638 intptr_t object_id, 660 intptr_t object_id,
639 intptr_t tags, 661 intptr_t tags,
640 Snapshot::Kind kind) { 662 Snapshot::Kind kind) {
641 ASSERT(reader != NULL); 663 ASSERT(reader != NULL);
664 ASSERT(kind != Snapshot::kMessage);
642 665
643 // Allocate library object. 666 Library& library = Library::ZoneHandle();
644 Library& library = Library::ZoneHandle(Library::New());
645 reader->AddBackwardReference(object_id, &library); 667 reader->AddBackwardReference(object_id, &library);
646 668
647 // Set the object tags. 669 if (RawObject::IsCreatedFromSnapshot(tags)) {
648 library.set_tags(tags); 670 ASSERT(kind != Snapshot::kFull);
671 // Lookup the object as it should already exist in the heap.
672 String& library_url = String::Handle();
673 library_url ^= reader->ReadObject();
674 library = Library::LookupLibrary(library_url);
675 } else {
676 // Allocate library object.
677 library = Library::New();
649 678
650 // Set all non object fields. 679 // Set the object tags.
651 library.raw_ptr()->num_imports_ = reader->Read<intptr_t>(); 680 library.set_tags(tags);
652 library.raw_ptr()->num_imported_into_ = reader->Read<intptr_t>();
653 library.raw_ptr()->num_anonymous_ = reader->Read<intptr_t>();
654 library.raw_ptr()->corelib_imported_ = reader->Read<bool>();
655 library.raw_ptr()->load_state_ = reader->Read<int8_t>();
656 // The native resolver is not serialized.
657 Dart_NativeEntryResolver resolver = reader->Read<Dart_NativeEntryResolver>();
658 ASSERT(resolver == NULL);
659 library.set_native_entry_resolver(resolver);
660 681
661 // Set all the object fields. 682 // Set all non object fields.
662 // TODO(5411462): Need to assert No GC can happen here, even though 683 library.raw_ptr()->num_imports_ = reader->Read<intptr_t>();
663 // allocations may happen. 684 library.raw_ptr()->num_imported_into_ = reader->Read<intptr_t>();
664 intptr_t num_flds = (library.raw()->to() - library.raw()->from()); 685 library.raw_ptr()->num_anonymous_ = reader->Read<intptr_t>();
665 for (intptr_t i = 0; i <= num_flds; i++) { 686 library.raw_ptr()->corelib_imported_ = reader->Read<bool>();
666 *(library.raw()->from() + i) = reader->ReadObject(); 687 library.raw_ptr()->load_state_ = reader->Read<int8_t>();
688 // The native resolver is not serialized.
689 Dart_NativeEntryResolver resolver =
690 reader->Read<Dart_NativeEntryResolver>();
691 ASSERT(resolver == NULL);
692 library.set_native_entry_resolver(resolver);
693
694 // Set all the object fields.
695 // TODO(5411462): Need to assert No GC can happen here, even though
696 // allocations may happen.
697 intptr_t num_flds = (library.raw()->to() - library.raw()->from());
698 for (intptr_t i = 0; i <= num_flds; i++) {
699 *(library.raw()->from() + i) = reader->ReadObject();
700 }
667 } 701 }
668
669 return library.raw(); 702 return library.raw();
670 } 703 }
671 704
672 705
673 void RawLibrary::WriteTo(SnapshotWriter* writer, 706 void RawLibrary::WriteTo(SnapshotWriter* writer,
674 intptr_t object_id, 707 intptr_t object_id,
675 Snapshot::Kind kind) { 708 Snapshot::Kind kind) {
676 ASSERT(writer != NULL); 709 ASSERT(writer != NULL);
677 SnapshotWriterVisitor visitor(writer); 710 ASSERT(kind != Snapshot::kMessage);
678 711
679 // Write out the serialization header value for this object. 712 // Write out the serialization header value for this object.
680 writer->WriteSerializationMarker(kInlined, object_id); 713 writer->WriteSerializationMarker(kInlined, object_id);
681 714
682 // Write out the class and tags information. 715 // Write out the class and tags information.
683 writer->WriteObjectHeader(Object::kLibraryClass, ptr()->tags_); 716 writer->WriteObjectHeader(Object::kLibraryClass, ptr()->tags_);
684 717
685 writer->Write<intptr_t>(ptr()->num_imports_); 718 if (IsCreatedFromSnapshot()) {
686 writer->Write<intptr_t>(ptr()->num_imported_into_); 719 ASSERT(kind != Snapshot::kFull);
687 writer->Write<intptr_t>(ptr()->num_anonymous_); 720 // Write out library URL so that it can be looked up when reading.
688 writer->Write<bool>(ptr()->corelib_imported_); 721 writer->WriteObject(ptr()->url_);
689 writer->Write<int8_t>(ptr()->load_state_); 722 } else {
690 // We do not serialize the native resolver over, this needs to be explicitly 723 // Write out all non object fields.
691 // set after deserialization. 724 writer->Write<intptr_t>(ptr()->num_imports_);
692 writer->Write<Dart_NativeEntryResolver>(NULL); 725 writer->Write<intptr_t>(ptr()->num_imported_into_);
726 writer->Write<intptr_t>(ptr()->num_anonymous_);
727 writer->Write<bool>(ptr()->corelib_imported_);
728 writer->Write<int8_t>(ptr()->load_state_);
729 // We do not serialize the native resolver over, this needs to be explicitly
730 // set after deserialization.
731 writer->Write<Dart_NativeEntryResolver>(NULL);
693 732
694 // Write out all the object pointer fields. 733 // Write out all the object pointer fields.
695 visitor.VisitPointers(from(), to()); 734 SnapshotWriterVisitor visitor(writer);
735 visitor.VisitPointers(from(), to());
736 }
696 } 737 }
697 738
698 739
699 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, 740 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader,
700 intptr_t object_id, 741 intptr_t object_id,
701 intptr_t tags, 742 intptr_t tags,
702 Snapshot::Kind kind) { 743 Snapshot::Kind kind) {
703 ASSERT(reader != NULL); 744 ASSERT(reader != NULL);
745 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
704 746
705 // Allocate library prefix object. 747 // Allocate library prefix object.
706 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(LibraryPrefix::New()); 748 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(LibraryPrefix::New());
707 reader->AddBackwardReference(object_id, &prefix); 749 reader->AddBackwardReference(object_id, &prefix);
708 750
709 // Set the object tags. 751 // Set the object tags.
710 prefix.set_tags(tags); 752 prefix.set_tags(tags);
711 753
712 // Set all the object fields. 754 // Set all the object fields.
713 // TODO(5411462): Need to assert No GC can happen here, even though 755 // TODO(5411462): Need to assert No GC can happen here, even though
714 // allocations may happen. 756 // allocations may happen.
715 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); 757 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from());
716 for (intptr_t i = 0; i <= num_flds; i++) { 758 for (intptr_t i = 0; i <= num_flds; i++) {
717 *(prefix.raw()->from() + i) = reader->ReadObject(); 759 *(prefix.raw()->from() + i) = reader->ReadObject();
718 } 760 }
719 761
720 return prefix.raw(); 762 return prefix.raw();
721 } 763 }
722 764
723 765
724 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, 766 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer,
725 intptr_t object_id, 767 intptr_t object_id,
726 Snapshot::Kind kind) { 768 Snapshot::Kind kind) {
727 ASSERT(writer != NULL); 769 ASSERT(writer != NULL);
728 SnapshotWriterVisitor visitor(writer); 770 ASSERT(kind != Snapshot::kMessage && !IsCreatedFromSnapshot());
729 771
730 // Write out the serialization header value for this object. 772 // Write out the serialization header value for this object.
731 writer->WriteSerializationMarker(kInlined, object_id); 773 writer->WriteSerializationMarker(kInlined, object_id);
732 774
733 // Write out the class and tags information. 775 // Write out the class and tags information.
734 writer->WriteObjectHeader(Object::kLibraryPrefixClass, ptr()->tags_); 776 writer->WriteObjectHeader(Object::kLibraryPrefixClass, ptr()->tags_);
735 777
736 // Write out all the object pointer fields. 778 // Write out all the object pointer fields.
779 SnapshotWriterVisitor visitor(writer);
737 visitor.VisitPointers(from(), to()); 780 visitor.VisitPointers(from(), to());
738 } 781 }
739 782
740 783
741 RawCode* Code::ReadFrom(SnapshotReader* reader, 784 RawCode* Code::ReadFrom(SnapshotReader* reader,
742 intptr_t object_id, 785 intptr_t object_id,
743 intptr_t tags, 786 intptr_t tags,
744 Snapshot::Kind kind) { 787 Snapshot::Kind kind) {
745 ASSERT(reader != NULL); 788 ASSERT(reader != NULL);
789 ASSERT(kind != Snapshot::kMessage);
746 790
747 // Create Code object. 791 // Create Code object.
748 Code& code = Code::ZoneHandle(Code::New(0)); 792 Code& code = Code::ZoneHandle(Code::New(0));
749 reader->AddBackwardReference(object_id, &code); 793 reader->AddBackwardReference(object_id, &code);
750 return code.raw(); 794 return code.raw();
751 } 795 }
752 796
753 797
754 void RawCode::WriteTo(SnapshotWriter* writer, 798 void RawCode::WriteTo(SnapshotWriter* writer,
755 intptr_t object_id, 799 intptr_t object_id,
756 Snapshot::Kind kind) { 800 Snapshot::Kind kind) {
757 // Currently we do not serialize any code and hence we write 801 // Currently we do not serialize any code and hence we write
758 // out a null object for it. 802 // out a null object for it.
759 ASSERT(writer != NULL); 803 ASSERT(writer != NULL);
804 ASSERT(kind != Snapshot::kMessage);
760 805
761 writer->WriteIndexedObject(Object::kNullObject); 806 writer->WriteIndexedObject(Object::kNullObject);
762 } 807 }
763 808
764 809
765 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, 810 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader,
766 intptr_t object_id, 811 intptr_t object_id,
767 intptr_t tags, 812 intptr_t tags,
768 Snapshot::Kind kind) { 813 Snapshot::Kind kind) {
769 UNREACHABLE(); 814 UNREACHABLE();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 } 883 }
839 884
840 return context.raw(); 885 return context.raw();
841 } 886 }
842 887
843 888
844 void RawContext::WriteTo(SnapshotWriter* writer, 889 void RawContext::WriteTo(SnapshotWriter* writer,
845 intptr_t object_id, 890 intptr_t object_id,
846 Snapshot::Kind kind) { 891 Snapshot::Kind kind) {
847 ASSERT(writer != NULL); 892 ASSERT(writer != NULL);
848 SnapshotWriterVisitor visitor(writer);
849 893
850 // Write out the serialization header value for this object. 894 // Write out the serialization header value for this object.
851 writer->WriteSerializationMarker(kInlined, object_id); 895 writer->WriteSerializationMarker(kInlined, object_id);
852 896
853 // Write out the class and tags information. 897 // Write out the class and tags information.
854 writer->WriteObjectHeader(Object::kContextClass, ptr()->tags_); 898 writer->WriteObjectHeader(Object::kContextClass, ptr()->tags_);
855 899
856 // Write out num of variables in the context. 900 // Write out num of variables in the context.
857 writer->Write<intptr_t>(ptr()->num_variables_); 901 writer->Write<intptr_t>(ptr()->num_variables_);
858 902
859 // Can't serialize the isolate pointer, we set it implicitly on read. 903 // Can't serialize the isolate pointer, we set it implicitly on read.
860 904
861 // Write out all the object pointer fields. 905 // Write out all the object pointer fields.
906 SnapshotWriterVisitor visitor(writer);
862 visitor.VisitPointers(from(), to(ptr()->num_variables_)); 907 visitor.VisitPointers(from(), to(ptr()->num_variables_));
863 } 908 }
864 909
865 910
866 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, 911 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader,
867 intptr_t object_id, 912 intptr_t object_id,
868 intptr_t tags, 913 intptr_t tags,
869 Snapshot::Kind kind) { 914 Snapshot::Kind kind) {
870 ASSERT(reader != NULL); 915 ASSERT(reader != NULL);
871 ASSERT(kind == Snapshot::kMessage); 916 ASSERT(kind == Snapshot::kMessage);
(...skipping 16 matching lines...) Expand all
888 933
889 return scope.raw(); 934 return scope.raw();
890 } 935 }
891 936
892 937
893 void RawContextScope::WriteTo(SnapshotWriter* writer, 938 void RawContextScope::WriteTo(SnapshotWriter* writer,
894 intptr_t object_id, 939 intptr_t object_id,
895 Snapshot::Kind kind) { 940 Snapshot::Kind kind) {
896 ASSERT(writer != NULL); 941 ASSERT(writer != NULL);
897 ASSERT(kind == Snapshot::kMessage); 942 ASSERT(kind == Snapshot::kMessage);
898 SnapshotWriterVisitor visitor(writer);
899 943
900 // Write out the serialization header value for this object. 944 // Write out the serialization header value for this object.
901 writer->WriteSerializationMarker(kInlined, object_id); 945 writer->WriteSerializationMarker(kInlined, object_id);
902 946
903 // Write out the class and tags information. 947 // Write out the class and tags information.
904 writer->WriteObjectHeader(Object::kContextScopeClass, ptr()->tags_); 948 writer->WriteObjectHeader(Object::kContextScopeClass, ptr()->tags_);
905 949
906 // Serialize number of variables. 950 // Serialize number of variables.
907 writer->Write<intptr_t>(ptr()->num_variables_); 951 writer->Write<intptr_t>(ptr()->num_variables_);
908 952
909 // Write out all the object pointer fields. 953 // Write out all the object pointer fields.
954 SnapshotWriterVisitor visitor(writer);
910 visitor.VisitPointers(from(), to(ptr()->num_variables_)); 955 visitor.VisitPointers(from(), to(ptr()->num_variables_));
911 } 956 }
912 957
913 958
914 RawUnhandledException* UnhandledException::ReadFrom(SnapshotReader* reader, 959 RawUnhandledException* UnhandledException::ReadFrom(SnapshotReader* reader,
915 intptr_t object_id, 960 intptr_t object_id,
916 intptr_t tags, 961 intptr_t tags,
917 Snapshot::Kind kind) { 962 Snapshot::Kind kind) {
918 UNIMPLEMENTED(); 963 UNIMPLEMENTED();
919 return UnhandledException::null(); 964 return UnhandledException::null();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 1006
962 RawMint* Mint::ReadFrom(SnapshotReader* reader, 1007 RawMint* Mint::ReadFrom(SnapshotReader* reader,
963 intptr_t object_id, 1008 intptr_t object_id,
964 intptr_t tags, 1009 intptr_t tags,
965 Snapshot::Kind kind) { 1010 Snapshot::Kind kind) {
966 ASSERT(reader != NULL); 1011 ASSERT(reader != NULL);
967 1012
968 // Read the 64 bit value for the object. 1013 // Read the 64 bit value for the object.
969 int64_t value = reader->Read<int64_t>(); 1014 int64_t value = reader->Read<int64_t>();
970 1015
971 // Create a Mint object. 1016 // Create a Mint object or get canonical one if it is a canonical constant.
972 Mint& mint = Mint::ZoneHandle( 1017 Mint& mint = Mint::ZoneHandle();
973 Mint::New(value, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); 1018 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) {
1019 mint = Mint::NewCanonical(value);
1020 } else {
1021 mint = Mint::New(value,
1022 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew);
1023 }
974 reader->AddBackwardReference(object_id, &mint); 1024 reader->AddBackwardReference(object_id, &mint);
975 1025
976 // Set the object tags. 1026 // Set the object tags.
977 mint.set_tags(tags); 1027 mint.set_tags(tags);
978 1028
979 return mint.raw(); 1029 return mint.raw();
980 } 1030 }
981 1031
982 1032
983 void RawMint::WriteTo(SnapshotWriter* writer, 1033 void RawMint::WriteTo(SnapshotWriter* writer,
(...skipping 10 matching lines...) Expand all
994 // Write out the 64 bit value. 1044 // Write out the 64 bit value.
995 writer->Write<int64_t>(ptr()->value_); 1045 writer->Write<int64_t>(ptr()->value_);
996 } 1046 }
997 1047
998 1048
999 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, 1049 RawBigint* Bigint::ReadFrom(SnapshotReader* reader,
1000 intptr_t object_id, 1050 intptr_t object_id,
1001 intptr_t tags, 1051 intptr_t tags,
1002 Snapshot::Kind kind) { 1052 Snapshot::Kind kind) {
1003 ASSERT(reader != NULL); 1053 ASSERT(reader != NULL);
1054
1004 // Read in the HexCString representation of the bigint. 1055 // Read in the HexCString representation of the bigint.
1005 intptr_t len = reader->Read<intptr_t>(); 1056 intptr_t len = reader->Read<intptr_t>();
1006 char* str = reinterpret_cast<char*>(ZoneAllocator(len + 1)); 1057 char* str = reinterpret_cast<char*>(ZoneAllocator(len + 1));
1007 str[len] = '\0'; 1058 str[len] = '\0';
1008 for (intptr_t i = 0; i < len; i++) { 1059 for (intptr_t i = 0; i < len; i++) {
1009 str[i] = reader->Read<uint8_t>(); 1060 str[i] = reader->Read<uint8_t>();
1010 } 1061 }
1062
1011 // Create a Bigint object from HexCString. 1063 // Create a Bigint object from HexCString.
1012 Bigint& obj = Bigint::ZoneHandle(BigintOperations::FromHexCString(str)); 1064 Bigint& obj = Bigint::ZoneHandle(BigintOperations::FromHexCString(str));
1065
1066 // If it is a canonical constant make it one.
1067 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) {
1068 obj ^= obj.Canonicalize();
1069 }
1013 reader->AddBackwardReference(object_id, &obj); 1070 reader->AddBackwardReference(object_id, &obj);
1014 1071
1015 // Set the object tags. 1072 // Set the object tags.
1016 obj.set_tags(tags); 1073 obj.set_tags(tags);
1017 1074
1018 return obj.raw(); 1075 return obj.raw();
1019 } 1076 }
1020 1077
1021 1078
1022 void RawBigint::WriteTo(SnapshotWriter* writer, 1079 void RawBigint::WriteTo(SnapshotWriter* writer,
(...skipping 18 matching lines...) Expand all
1041 } 1098 }
1042 1099
1043 1100
1044 RawDouble* Double::ReadFrom(SnapshotReader* reader, 1101 RawDouble* Double::ReadFrom(SnapshotReader* reader,
1045 intptr_t object_id, 1102 intptr_t object_id,
1046 intptr_t tags, 1103 intptr_t tags,
1047 Snapshot::Kind kind) { 1104 Snapshot::Kind kind) {
1048 ASSERT(reader != NULL); 1105 ASSERT(reader != NULL);
1049 // Read the double value for the object. 1106 // Read the double value for the object.
1050 double value = reader->Read<double>(); 1107 double value = reader->Read<double>();
1051 // Create a double object. 1108
1052 Double& dbl = Double::ZoneHandle( 1109 // Create a Double object or get canonical one if it is a canonical constant.
1053 Double::New(value, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); 1110 Double& dbl = Double::ZoneHandle();
1111 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) {
1112 dbl = Double::NewCanonical(value);
1113 } else {
1114 dbl = Double::New(value,
1115 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew);
1116 }
1054 reader->AddBackwardReference(object_id, &dbl); 1117 reader->AddBackwardReference(object_id, &dbl);
1055 1118
1056 // Set the object tags. 1119 // Set the object tags.
1057 dbl.set_tags(tags); 1120 dbl.set_tags(tags);
1058 1121
1059 return dbl.raw(); 1122 return dbl.raw();
1060 } 1123 }
1061 1124
1062 1125
1063 void RawDouble::WriteTo(SnapshotWriter* writer, 1126 void RawDouble::WriteTo(SnapshotWriter* writer,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 RawString* String::ReadFromImpl(SnapshotReader* reader, 1159 RawString* String::ReadFromImpl(SnapshotReader* reader,
1097 intptr_t object_id, 1160 intptr_t object_id,
1098 intptr_t tags, 1161 intptr_t tags,
1099 Snapshot::Kind kind) { 1162 Snapshot::Kind kind) {
1100 ASSERT(reader != NULL); 1163 ASSERT(reader != NULL);
1101 // Read the length so that we can determine instance size to allocate. 1164 // Read the length so that we can determine instance size to allocate.
1102 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); 1165 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>());
1103 intptr_t len = Smi::Value(smi_len); 1166 intptr_t len = Smi::Value(smi_len);
1104 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); 1167 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>());
1105 1168
1106 // Set up the string object. 1169 HandleType& str_obj = HandleType::ZoneHandle();
1107 HandleType& str_obj = HandleType::ZoneHandle(HandleType::New( 1170 if (kind != Snapshot::kFull && RawObject::IsCanonical(tags)) {
1108 len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); 1171 CharacterType* ptr = reinterpret_cast<CharacterType*>(ZoneAllocator(len));
1109 for (intptr_t i = 0; i < len; i++) { 1172 for (intptr_t i = 0; i < len; i++) {
1110 *str_obj.CharAddr(i) = reader->Read<CharacterType>(); 1173 ptr[i] = reader->Read<CharacterType>();
1174 }
1175 str_obj ^= String::NewSymbol(ptr, len);
1176 } else {
1177 // Set up the string object.
1178 str_obj = HandleType::New(
1179 len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew);
1180 for (intptr_t i = 0; i < len; i++) {
1181 *str_obj.CharAddr(i) = reader->Read<CharacterType>();
1182 }
1183 str_obj.set_tags(tags);
1184 str_obj.SetHash(Smi::Value(smi_hash));
1111 } 1185 }
1112 reader->AddBackwardReference(object_id, &str_obj); 1186 reader->AddBackwardReference(object_id, &str_obj);
1113 1187
1114 // Set the object tags.
1115 str_obj.set_tags(tags);
1116
1117 // Set up the hash value.
1118 str_obj.SetHash(Smi::Value(smi_hash));
1119
1120 return str_obj.raw(); 1188 return str_obj.raw();
1121 } 1189 }
1122 1190
1123 1191
1124 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, 1192 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader,
1125 intptr_t object_id, 1193 intptr_t object_id,
1126 intptr_t tags, 1194 intptr_t tags,
1127 Snapshot::Kind kind) { 1195 Snapshot::Kind kind) {
1128 return static_cast<RawOneByteString*>( 1196 return static_cast<RawOneByteString*>(
1129 ReadFromImpl<OneByteString, uint8_t>(reader, object_id, tags, kind)); 1197 ReadFromImpl<OneByteString, uint8_t>(reader, object_id, tags, kind));
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 // Write out all the other fields. 1586 // Write out all the other fields.
1519 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); 1587 writer->Write<RawObject*>(ptr()->num_bracket_expressions_);
1520 writer->WriteObject(ptr()->pattern_); 1588 writer->WriteObject(ptr()->pattern_);
1521 writer->Write<intptr_t>(ptr()->type_); 1589 writer->Write<intptr_t>(ptr()->type_);
1522 writer->Write<intptr_t>(ptr()->flags_); 1590 writer->Write<intptr_t>(ptr()->flags_);
1523 1591
1524 // Do not write out the data part which is native. 1592 // Do not write out the data part which is native.
1525 } 1593 }
1526 1594
1527 } // namespace dart 1595 } // namespace dart
OLDNEW
« vm/dart_api_impl.cc ('K') | « vm/dart_api_impl.cc ('k') | vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698