| OLD | NEW |
| 1 // Copyright (c) 2011, 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/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 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 static RawSmi* GetSmi(intptr_t value) { | 13 #define NEW_OBJECT(type) \ |
| 14 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) |
| 15 |
| 16 #define NEW_OBJECT_WITH_LEN(type, len) \ |
| 17 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) |
| 18 |
| 19 |
| 20 static RawSmi* AsSmi(intptr_t value) { |
| 14 ASSERT((value & kSmiTagMask) == 0); | 21 ASSERT((value & kSmiTagMask) == 0); |
| 15 return reinterpret_cast<RawSmi*>(value); | 22 return reinterpret_cast<RawSmi*>(value); |
| 16 } | 23 } |
| 17 | 24 |
| 18 | 25 |
| 26 static intptr_t GetSmiValue(intptr_t value) { |
| 27 return Smi::Value(AsSmi(value)); |
| 28 } |
| 29 |
| 30 |
| 19 static uword ZoneAllocator(intptr_t size) { | 31 static uword ZoneAllocator(intptr_t size) { |
| 20 Zone* zone = Isolate::Current()->current_zone(); | 32 Zone* zone = Isolate::Current()->current_zone(); |
| 21 return zone->Allocate(size); | 33 return zone->Allocate(size); |
| 22 } | 34 } |
| 23 | 35 |
| 24 | 36 |
| 25 RawClass* Class::ReadFrom(SnapshotReader* reader, | 37 RawClass* Class::ReadFrom(SnapshotReader* reader, |
| 26 intptr_t object_id, | 38 intptr_t object_id, |
| 27 intptr_t tags, | 39 intptr_t tags, |
| 28 Snapshot::Kind kind) { | 40 Snapshot::Kind kind) { |
| 29 ASSERT(reader != NULL); | 41 ASSERT(reader != NULL); |
| 30 | 42 |
| 31 Class& cls = Class::ZoneHandle(reader->isolate(), Class::null()); | 43 Class& cls = Class::ZoneHandle(reader->isolate(), Class::null()); |
| 32 if ((kind == Snapshot::kFull) || | 44 if ((kind == Snapshot::kFull) || |
| 33 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { | 45 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { |
| 34 // Read in the base information. | 46 // Read in the base information. |
| 35 ObjectKind kind = reader->Read<ObjectKind>(); | 47 ObjectKind object_kind = reader->Read<ObjectKind>(); |
| 36 | 48 |
| 37 // Allocate class object of specified kind. | 49 // Allocate class object of specified kind. |
| 38 cls = Class::GetClass(kind); | 50 if (kind == Snapshot::kFull) { |
| 51 cls = reader->NewClass(object_kind); |
| 52 } else { |
| 53 cls = Class::GetClass(object_kind); |
| 54 } |
| 39 reader->AddBackwardReference(object_id, &cls); | 55 reader->AddBackwardReference(object_id, &cls); |
| 40 | 56 |
| 41 // Set the object tags. | 57 // Set the object tags. |
| 42 cls.set_tags(tags); | 58 cls.set_tags(tags); |
| 43 | 59 |
| 44 // Set all non object fields. | 60 // Set all non object fields. |
| 45 cls.set_instance_size(reader->ReadIntptrValue()); | 61 cls.set_instance_size(reader->ReadIntptrValue()); |
| 46 cls.set_type_arguments_instance_field_offset(reader->ReadIntptrValue()); | 62 cls.set_type_arguments_instance_field_offset(reader->ReadIntptrValue()); |
| 47 cls.set_next_field_offset(reader->ReadIntptrValue()); | 63 cls.set_next_field_offset(reader->ReadIntptrValue()); |
| 48 cls.set_num_native_fields(reader->ReadIntptrValue()); | 64 cls.set_num_native_fields(reader->ReadIntptrValue()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 117 } |
| 102 | 118 |
| 103 | 119 |
| 104 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, | 120 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, |
| 105 intptr_t object_id, | 121 intptr_t object_id, |
| 106 intptr_t tags, | 122 intptr_t tags, |
| 107 Snapshot::Kind kind) { | 123 Snapshot::Kind kind) { |
| 108 ASSERT(reader != NULL); | 124 ASSERT(reader != NULL); |
| 109 | 125 |
| 110 // Allocate parameterized type object. | 126 // Allocate parameterized type object. |
| 111 UnresolvedClass& unresolved_class = | 127 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( |
| 112 UnresolvedClass::ZoneHandle(reader->isolate(), UnresolvedClass::New()); | 128 reader->isolate(), NEW_OBJECT(UnresolvedClass)); |
| 113 reader->AddBackwardReference(object_id, &unresolved_class); | 129 reader->AddBackwardReference(object_id, &unresolved_class); |
| 114 | 130 |
| 115 // Set the object tags. | 131 // Set the object tags. |
| 116 unresolved_class.set_tags(tags); | 132 unresolved_class.set_tags(tags); |
| 117 | 133 |
| 118 // Set all non object fields. | 134 // Set all non object fields. |
| 119 unresolved_class.set_token_index(reader->ReadIntptrValue()); | 135 unresolved_class.set_token_index(reader->ReadIntptrValue()); |
| 120 | 136 |
| 121 // Set all the object fields. | 137 // Set all the object fields. |
| 122 // TODO(5411462): Need to assert No GC can happen here, even though | 138 // TODO(5411462): Need to assert No GC can happen here, even though |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 182 } |
| 167 | 183 |
| 168 | 184 |
| 169 RawType* Type::ReadFrom(SnapshotReader* reader, | 185 RawType* Type::ReadFrom(SnapshotReader* reader, |
| 170 intptr_t object_id, | 186 intptr_t object_id, |
| 171 intptr_t tags, | 187 intptr_t tags, |
| 172 Snapshot::Kind kind) { | 188 Snapshot::Kind kind) { |
| 173 ASSERT(reader != NULL); | 189 ASSERT(reader != NULL); |
| 174 | 190 |
| 175 // Allocate parameterized type object. | 191 // Allocate parameterized type object. |
| 176 Type& parameterized_type = Type::ZoneHandle(reader->isolate(), Type::New()); | 192 Type& parameterized_type = Type::ZoneHandle( |
| 193 reader->isolate(), NEW_OBJECT(Type)); |
| 177 reader->AddBackwardReference(object_id, ¶meterized_type); | 194 reader->AddBackwardReference(object_id, ¶meterized_type); |
| 178 | 195 |
| 179 // Set the object tags. | 196 // Set the object tags. |
| 180 parameterized_type.set_tags(tags); | 197 parameterized_type.set_tags(tags); |
| 181 | 198 |
| 182 // Set all non object fields. | 199 // Set all non object fields. |
| 183 parameterized_type.set_type_state(reader->Read<int8_t>()); | 200 parameterized_type.set_type_state(reader->Read<int8_t>()); |
| 184 | 201 |
| 185 // Set all the object fields. | 202 // Set all the object fields. |
| 186 // TODO(5411462): Need to assert No GC can happen here, even though | 203 // TODO(5411462): Need to assert No GC can happen here, even though |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 236 } |
| 220 | 237 |
| 221 | 238 |
| 222 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, | 239 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, |
| 223 intptr_t object_id, | 240 intptr_t object_id, |
| 224 intptr_t tags, | 241 intptr_t tags, |
| 225 Snapshot::Kind kind) { | 242 Snapshot::Kind kind) { |
| 226 ASSERT(reader != NULL); | 243 ASSERT(reader != NULL); |
| 227 | 244 |
| 228 // Allocate type parameter object. | 245 // Allocate type parameter object. |
| 229 TypeParameter& type_parameter = | 246 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
| 230 TypeParameter::ZoneHandle(reader->isolate(), TypeParameter::New()); | 247 reader->isolate(), NEW_OBJECT(TypeParameter)); |
| 231 reader->AddBackwardReference(object_id, &type_parameter); | 248 reader->AddBackwardReference(object_id, &type_parameter); |
| 232 | 249 |
| 233 // Set the object tags. | 250 // Set the object tags. |
| 234 type_parameter.set_tags(tags); | 251 type_parameter.set_tags(tags); |
| 235 | 252 |
| 236 // Set all non object fields. | 253 // Set all non object fields. |
| 237 type_parameter.set_index(reader->ReadIntptrValue()); | 254 type_parameter.set_index(reader->ReadIntptrValue()); |
| 238 type_parameter.set_type_state(reader->Read<int8_t>()); | 255 type_parameter.set_type_state(reader->Read<int8_t>()); |
| 239 | 256 |
| 240 // Set all the object fields. | 257 // Set all the object fields. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 } | 350 } |
| 334 | 351 |
| 335 | 352 |
| 336 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, | 353 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, |
| 337 intptr_t object_id, | 354 intptr_t object_id, |
| 338 intptr_t tags, | 355 intptr_t tags, |
| 339 Snapshot::Kind kind) { | 356 Snapshot::Kind kind) { |
| 340 ASSERT(reader != NULL); | 357 ASSERT(reader != NULL); |
| 341 | 358 |
| 342 // Read the length so that we can determine instance size to allocate. | 359 // Read the length so that we can determine instance size to allocate. |
| 343 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); | 360 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 344 intptr_t len = Smi::Value(smi_len); | |
| 345 | 361 |
| 346 TypeArguments& type_arguments = | 362 TypeArguments& type_arguments = TypeArguments::ZoneHandle( |
| 347 TypeArguments::ZoneHandle(reader->isolate(), TypeArguments::New(len)); | 363 reader->isolate(), NEW_OBJECT_WITH_LEN(TypeArguments, len)); |
| 348 reader->AddBackwardReference(object_id, &type_arguments); | 364 reader->AddBackwardReference(object_id, &type_arguments); |
| 349 | 365 |
| 350 // Now set all the object fields. | 366 // Now set all the object fields. |
| 351 for (intptr_t i = 0; i < len; i++) { | 367 for (intptr_t i = 0; i < len; i++) { |
| 352 *reader->TypeHandle() ^= reader->ReadObject(); | 368 *reader->TypeHandle() ^= reader->ReadObject(); |
| 353 type_arguments.SetTypeAt(i, *reader->TypeHandle()); | 369 type_arguments.SetTypeAt(i, *reader->TypeHandle()); |
| 354 } | 370 } |
| 355 | 371 |
| 356 // Set the object tags (This is done after setting the object fields | 372 // Set the object tags (This is done after setting the object fields |
| 357 // because 'SetTypeAt' has an assertion to check if the object is not | 373 // because 'SetTypeAt' has an assertion to check if the object is not |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 453 |
| 438 | 454 |
| 439 RawFunction* Function::ReadFrom(SnapshotReader* reader, | 455 RawFunction* Function::ReadFrom(SnapshotReader* reader, |
| 440 intptr_t object_id, | 456 intptr_t object_id, |
| 441 intptr_t tags, | 457 intptr_t tags, |
| 442 Snapshot::Kind kind) { | 458 Snapshot::Kind kind) { |
| 443 ASSERT(reader != NULL); | 459 ASSERT(reader != NULL); |
| 444 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 460 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 445 | 461 |
| 446 // Allocate function object. | 462 // Allocate function object. |
| 447 Function& func = Function::ZoneHandle(reader->isolate(), Function::New()); | 463 Function& func = Function::ZoneHandle( |
| 464 reader->isolate(), NEW_OBJECT(Function)); |
| 448 reader->AddBackwardReference(object_id, &func); | 465 reader->AddBackwardReference(object_id, &func); |
| 449 | 466 |
| 450 // Set the object tags. | 467 // Set the object tags. |
| 451 func.set_tags(tags); | 468 func.set_tags(tags); |
| 452 | 469 |
| 453 // Set all the non object fields. | 470 // Set all the non object fields. |
| 454 func.set_token_index(reader->ReadIntptrValue()); | 471 func.set_token_index(reader->ReadIntptrValue()); |
| 455 func.set_num_fixed_parameters(reader->ReadIntptrValue()); | 472 func.set_num_fixed_parameters(reader->ReadIntptrValue()); |
| 456 func.set_num_optional_parameters(reader->ReadIntptrValue()); | 473 func.set_num_optional_parameters(reader->ReadIntptrValue()); |
| 457 func.set_invocation_counter(reader->ReadIntptrValue()); | 474 func.set_invocation_counter(reader->ReadIntptrValue()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 520 |
| 504 | 521 |
| 505 RawField* Field::ReadFrom(SnapshotReader* reader, | 522 RawField* Field::ReadFrom(SnapshotReader* reader, |
| 506 intptr_t object_id, | 523 intptr_t object_id, |
| 507 intptr_t tags, | 524 intptr_t tags, |
| 508 Snapshot::Kind kind) { | 525 Snapshot::Kind kind) { |
| 509 ASSERT(reader != NULL); | 526 ASSERT(reader != NULL); |
| 510 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 527 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 511 | 528 |
| 512 // Allocate field object. | 529 // Allocate field object. |
| 513 Field& field = Field::ZoneHandle(reader->isolate(), Field::New()); | 530 Field& field = Field::ZoneHandle(reader->isolate(), NEW_OBJECT(Field)); |
| 514 reader->AddBackwardReference(object_id, &field); | 531 reader->AddBackwardReference(object_id, &field); |
| 515 | 532 |
| 516 // Set the object tags. | 533 // Set the object tags. |
| 517 field.set_tags(tags); | 534 field.set_tags(tags); |
| 518 | 535 |
| 519 // Set all non object fields. | 536 // Set all non object fields. |
| 520 field.set_token_index(reader->ReadIntptrValue()); | 537 field.set_token_index(reader->ReadIntptrValue()); |
| 521 field.set_is_static(reader->Read<bool>()); | 538 field.set_is_static(reader->Read<bool>()); |
| 522 field.set_is_final(reader->Read<bool>()); | 539 field.set_is_final(reader->Read<bool>()); |
| 523 field.set_has_initializer(reader->Read<bool>()); | 540 field.set_has_initializer(reader->Read<bool>()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 576 |
| 560 | 577 |
| 561 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, | 578 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, |
| 562 intptr_t object_id, | 579 intptr_t object_id, |
| 563 intptr_t tags, | 580 intptr_t tags, |
| 564 Snapshot::Kind kind) { | 581 Snapshot::Kind kind) { |
| 565 ASSERT(reader != NULL); | 582 ASSERT(reader != NULL); |
| 566 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 583 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 567 | 584 |
| 568 // Read the length so that we can determine number of tokens to read. | 585 // Read the length so that we can determine number of tokens to read. |
| 569 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); | 586 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 570 intptr_t len = Smi::Value(smi_len); | |
| 571 | 587 |
| 572 // Create the token stream object. | 588 // Create the token stream object. |
| 573 TokenStream& token_stream = TokenStream::ZoneHandle(reader->isolate(), | 589 TokenStream& token_stream = TokenStream::ZoneHandle( |
| 574 TokenStream::New(len)); | 590 reader->isolate(), NEW_OBJECT_WITH_LEN(TokenStream, len)); |
| 575 reader->AddBackwardReference(object_id, &token_stream); | 591 reader->AddBackwardReference(object_id, &token_stream); |
| 576 | 592 |
| 577 // Set the object tags. | 593 // Set the object tags. |
| 578 token_stream.set_tags(tags); | 594 token_stream.set_tags(tags); |
| 579 | 595 |
| 580 // Read the token stream into the TokenStream. | 596 // Read the token stream into the TokenStream. |
| 581 for (intptr_t i = 0; i < len; i++) { | 597 for (intptr_t i = 0; i < len; i++) { |
| 582 Token::Kind kind = static_cast<Token::Kind>( | 598 Token::Kind kind = static_cast<Token::Kind>( |
| 583 Smi::Value(GetSmi(reader->ReadIntptrValue()))); | 599 GetSmiValue(reader->ReadIntptrValue())); |
| 584 *reader->StringHandle() ^= reader->ReadObject(); | 600 *reader->StringHandle() ^= reader->ReadObject(); |
| 585 token_stream.SetTokenAt(i, kind, *reader->StringHandle()); | 601 token_stream.SetTokenAt(i, kind, *reader->StringHandle()); |
| 586 } | 602 } |
| 587 return token_stream.raw(); | 603 return token_stream.raw(); |
| 588 } | 604 } |
| 589 | 605 |
| 590 | 606 |
| 591 void RawTokenStream::WriteTo(SnapshotWriter* writer, | 607 void RawTokenStream::WriteTo(SnapshotWriter* writer, |
| 592 intptr_t object_id, | 608 intptr_t object_id, |
| 593 Snapshot::Kind kind) { | 609 Snapshot::Kind kind) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 612 | 628 |
| 613 | 629 |
| 614 RawScript* Script::ReadFrom(SnapshotReader* reader, | 630 RawScript* Script::ReadFrom(SnapshotReader* reader, |
| 615 intptr_t object_id, | 631 intptr_t object_id, |
| 616 intptr_t tags, | 632 intptr_t tags, |
| 617 Snapshot::Kind kind) { | 633 Snapshot::Kind kind) { |
| 618 ASSERT(reader != NULL); | 634 ASSERT(reader != NULL); |
| 619 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 635 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 620 | 636 |
| 621 // Allocate script object. | 637 // Allocate script object. |
| 622 Script& script = Script::ZoneHandle(reader->isolate(), Script::New()); | 638 Script& script = Script::ZoneHandle(reader->isolate(), NEW_OBJECT(Script)); |
| 623 reader->AddBackwardReference(object_id, &script); | 639 reader->AddBackwardReference(object_id, &script); |
| 624 | 640 |
| 625 // Set the object tags. | 641 // Set the object tags. |
| 626 script.set_tags(tags); | 642 script.set_tags(tags); |
| 627 | 643 |
| 628 // Set all the object fields. | 644 // Set all the object fields. |
| 629 // TODO(5411462): Need to assert No GC can happen here, even though | 645 // TODO(5411462): Need to assert No GC can happen here, even though |
| 630 // allocations may happen. | 646 // allocations may happen. |
| 631 intptr_t num_flds = (script.raw()->to() - script.raw()->from()); | 647 intptr_t num_flds = (script.raw()->to() - script.raw()->from()); |
| 632 for (intptr_t i = 0; i <= num_flds; i++) { | 648 for (intptr_t i = 0; i <= num_flds; i++) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 Library& library = Library::ZoneHandle(reader->isolate(), Library::null()); | 682 Library& library = Library::ZoneHandle(reader->isolate(), Library::null()); |
| 667 reader->AddBackwardReference(object_id, &library); | 683 reader->AddBackwardReference(object_id, &library); |
| 668 | 684 |
| 669 if (RawObject::IsCreatedFromSnapshot(tags)) { | 685 if (RawObject::IsCreatedFromSnapshot(tags)) { |
| 670 ASSERT(kind != Snapshot::kFull); | 686 ASSERT(kind != Snapshot::kFull); |
| 671 // Lookup the object as it should already exist in the heap. | 687 // Lookup the object as it should already exist in the heap. |
| 672 *reader->StringHandle() ^= reader->ReadObject(); | 688 *reader->StringHandle() ^= reader->ReadObject(); |
| 673 library = Library::LookupLibrary(*reader->StringHandle()); | 689 library = Library::LookupLibrary(*reader->StringHandle()); |
| 674 } else { | 690 } else { |
| 675 // Allocate library object. | 691 // Allocate library object. |
| 676 library = Library::New(); | 692 library = NEW_OBJECT(Library); |
| 677 | 693 |
| 678 // Set the object tags. | 694 // Set the object tags. |
| 679 library.set_tags(tags); | 695 library.set_tags(tags); |
| 680 | 696 |
| 681 // Set all non object fields. | 697 // Set all non object fields. |
| 682 library.raw_ptr()->num_imports_ = reader->ReadIntptrValue(); | 698 library.raw_ptr()->num_imports_ = reader->ReadIntptrValue(); |
| 683 library.raw_ptr()->num_imported_into_ = reader->ReadIntptrValue(); | 699 library.raw_ptr()->num_imported_into_ = reader->ReadIntptrValue(); |
| 684 library.raw_ptr()->num_anonymous_ = reader->ReadIntptrValue(); | 700 library.raw_ptr()->num_anonymous_ = reader->ReadIntptrValue(); |
| 685 library.raw_ptr()->corelib_imported_ = reader->Read<bool>(); | 701 library.raw_ptr()->corelib_imported_ = reader->Read<bool>(); |
| 686 library.raw_ptr()->load_state_ = reader->Read<int8_t>(); | 702 library.raw_ptr()->load_state_ = reader->Read<int8_t>(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 753 |
| 738 | 754 |
| 739 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, | 755 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, |
| 740 intptr_t object_id, | 756 intptr_t object_id, |
| 741 intptr_t tags, | 757 intptr_t tags, |
| 742 Snapshot::Kind kind) { | 758 Snapshot::Kind kind) { |
| 743 ASSERT(reader != NULL); | 759 ASSERT(reader != NULL); |
| 744 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 760 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 745 | 761 |
| 746 // Allocate library prefix object. | 762 // Allocate library prefix object. |
| 747 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(reader->isolate(), | 763 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle( |
| 748 LibraryPrefix::New()); | 764 reader->isolate(), NEW_OBJECT(LibraryPrefix)); |
| 749 reader->AddBackwardReference(object_id, &prefix); | 765 reader->AddBackwardReference(object_id, &prefix); |
| 750 | 766 |
| 751 // Set the object tags. | 767 // Set the object tags. |
| 752 prefix.set_tags(tags); | 768 prefix.set_tags(tags); |
| 753 | 769 |
| 754 // Set all the object fields. | 770 // Set all the object fields. |
| 755 // TODO(5411462): Need to assert No GC can happen here, even though | 771 // TODO(5411462): Need to assert No GC can happen here, even though |
| 756 // allocations may happen. | 772 // allocations may happen. |
| 757 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); | 773 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); |
| 758 for (intptr_t i = 0; i <= num_flds; i++) { | 774 for (intptr_t i = 0; i <= num_flds; i++) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 778 // Write out all the object pointer fields. | 794 // Write out all the object pointer fields. |
| 779 SnapshotWriterVisitor visitor(writer); | 795 SnapshotWriterVisitor visitor(writer); |
| 780 visitor.VisitPointers(from(), to()); | 796 visitor.VisitPointers(from(), to()); |
| 781 } | 797 } |
| 782 | 798 |
| 783 | 799 |
| 784 RawCode* Code::ReadFrom(SnapshotReader* reader, | 800 RawCode* Code::ReadFrom(SnapshotReader* reader, |
| 785 intptr_t object_id, | 801 intptr_t object_id, |
| 786 intptr_t tags, | 802 intptr_t tags, |
| 787 Snapshot::Kind kind) { | 803 Snapshot::Kind kind) { |
| 788 ASSERT(reader != NULL); | 804 UNREACHABLE(); |
| 789 ASSERT(kind != Snapshot::kMessage); | 805 return Code::null(); |
| 790 | |
| 791 // Create Code object. | |
| 792 Code& code = Code::ZoneHandle(reader->isolate(), Code::New(0)); | |
| 793 reader->AddBackwardReference(object_id, &code); | |
| 794 return code.raw(); | |
| 795 } | 806 } |
| 796 | 807 |
| 797 | 808 |
| 798 void RawCode::WriteTo(SnapshotWriter* writer, | 809 void RawCode::WriteTo(SnapshotWriter* writer, |
| 799 intptr_t object_id, | 810 intptr_t object_id, |
| 800 Snapshot::Kind kind) { | 811 Snapshot::Kind kind) { |
| 801 // Currently we do not serialize any code and hence we write | 812 // Currently we do not serialize any code and hence we write |
| 802 // out a null object for it. | 813 // out a null object for it. |
| 803 ASSERT(writer != NULL); | 814 ASSERT(writer != NULL); |
| 804 ASSERT(kind != Snapshot::kMessage); | 815 ASSERT(kind != Snapshot::kMessage); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 | 883 |
| 873 | 884 |
| 874 RawContext* Context::ReadFrom(SnapshotReader* reader, | 885 RawContext* Context::ReadFrom(SnapshotReader* reader, |
| 875 intptr_t object_id, | 886 intptr_t object_id, |
| 876 intptr_t tags, | 887 intptr_t tags, |
| 877 Snapshot::Kind kind) { | 888 Snapshot::Kind kind) { |
| 878 ASSERT(reader != NULL); | 889 ASSERT(reader != NULL); |
| 879 | 890 |
| 880 // Allocate context object. | 891 // Allocate context object. |
| 881 intptr_t num_vars = reader->ReadIntptrValue(); | 892 intptr_t num_vars = reader->ReadIntptrValue(); |
| 882 Context& context = Context::ZoneHandle( | 893 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); |
| 883 reader->isolate(), | 894 if (kind == Snapshot::kFull) { |
| 884 Context::New(num_vars, | 895 context = reader->NewContext(num_vars); |
| 885 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | 896 } else { |
| 897 context = Context::New(num_vars); |
| 898 } |
| 886 reader->AddBackwardReference(object_id, &context); | 899 reader->AddBackwardReference(object_id, &context); |
| 887 | 900 |
| 888 // Set the object tags. | 901 // Set the object tags. |
| 889 context.set_tags(tags); | 902 context.set_tags(tags); |
| 890 | 903 |
| 891 // Set the isolate implicitly. | 904 // Set the isolate implicitly. |
| 892 context.set_isolate(Isolate::Current()); | 905 context.set_isolate(Isolate::Current()); |
| 893 | 906 |
| 894 // Set all the object fields. | 907 // Set all the object fields. |
| 895 // TODO(5411462): Need to assert No GC can happen here, even though | 908 // TODO(5411462): Need to assert No GC can happen here, even though |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 intptr_t object_id, | 1087 intptr_t object_id, |
| 1075 intptr_t tags, | 1088 intptr_t tags, |
| 1076 Snapshot::Kind kind) { | 1089 Snapshot::Kind kind) { |
| 1077 ASSERT(reader != NULL); | 1090 ASSERT(reader != NULL); |
| 1078 | 1091 |
| 1079 // Read the 64 bit value for the object. | 1092 // Read the 64 bit value for the object. |
| 1080 int64_t value = reader->Read<int64_t>(); | 1093 int64_t value = reader->Read<int64_t>(); |
| 1081 | 1094 |
| 1082 // Create a Mint object or get canonical one if it is a canonical constant. | 1095 // Create a Mint object or get canonical one if it is a canonical constant. |
| 1083 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); | 1096 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); |
| 1084 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 1097 if (kind == Snapshot::kFull) { |
| 1085 mint = Mint::NewCanonical(value); | 1098 mint = reader->NewMint(value); |
| 1086 } else { | 1099 } else { |
| 1087 mint = Mint::New(value, | 1100 if (RawObject::IsCanonical(tags)) { |
| 1088 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew); | 1101 mint = Mint::NewCanonical(value); |
| 1102 } else { |
| 1103 mint = Mint::New(value, Heap::kNew); |
| 1104 } |
| 1089 } | 1105 } |
| 1090 reader->AddBackwardReference(object_id, &mint); | 1106 reader->AddBackwardReference(object_id, &mint); |
| 1091 | 1107 |
| 1092 // Set the object tags. | 1108 // Set the object tags. |
| 1093 mint.set_tags(tags); | 1109 mint.set_tags(tags); |
| 1094 | 1110 |
| 1095 return mint.raw(); | 1111 return mint.raw(); |
| 1096 } | 1112 } |
| 1097 | 1113 |
| 1098 | 1114 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 RawDouble* Double::ReadFrom(SnapshotReader* reader, | 1184 RawDouble* Double::ReadFrom(SnapshotReader* reader, |
| 1169 intptr_t object_id, | 1185 intptr_t object_id, |
| 1170 intptr_t tags, | 1186 intptr_t tags, |
| 1171 Snapshot::Kind kind) { | 1187 Snapshot::Kind kind) { |
| 1172 ASSERT(reader != NULL); | 1188 ASSERT(reader != NULL); |
| 1173 // Read the double value for the object. | 1189 // Read the double value for the object. |
| 1174 double value = reader->Read<double>(); | 1190 double value = reader->Read<double>(); |
| 1175 | 1191 |
| 1176 // Create a Double object or get canonical one if it is a canonical constant. | 1192 // Create a Double object or get canonical one if it is a canonical constant. |
| 1177 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); | 1193 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); |
| 1178 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 1194 if (kind == Snapshot::kFull) { |
| 1179 dbl = Double::NewCanonical(value); | 1195 dbl = reader->NewDouble(value); |
| 1180 } else { | 1196 } else { |
| 1181 dbl = Double::New(value, | 1197 if (RawObject::IsCanonical(tags)) { |
| 1182 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew); | 1198 dbl = Double::NewCanonical(value); |
| 1199 } else { |
| 1200 dbl = Double::New(value, Heap::kNew); |
| 1201 } |
| 1183 } | 1202 } |
| 1184 reader->AddBackwardReference(object_id, &dbl); | 1203 reader->AddBackwardReference(object_id, &dbl); |
| 1185 | 1204 |
| 1186 // Set the object tags. | 1205 // Set the object tags. |
| 1187 dbl.set_tags(tags); | 1206 dbl.set_tags(tags); |
| 1188 | 1207 |
| 1189 return dbl.raw(); | 1208 return dbl.raw(); |
| 1190 } | 1209 } |
| 1191 | 1210 |
| 1192 | 1211 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1216 | 1235 |
| 1217 | 1236 |
| 1218 void RawString::WriteTo(SnapshotWriter* writer, | 1237 void RawString::WriteTo(SnapshotWriter* writer, |
| 1219 intptr_t object_id, | 1238 intptr_t object_id, |
| 1220 Snapshot::Kind kind) { | 1239 Snapshot::Kind kind) { |
| 1221 UNREACHABLE(); // String is an abstract class. | 1240 UNREACHABLE(); // String is an abstract class. |
| 1222 } | 1241 } |
| 1223 | 1242 |
| 1224 | 1243 |
| 1225 template<typename HandleType, typename CharacterType> | 1244 template<typename HandleType, typename CharacterType> |
| 1226 RawString* String::ReadFromImpl(SnapshotReader* reader, | 1245 void String::ReadFromImpl(SnapshotReader* reader, |
| 1227 intptr_t object_id, | 1246 HandleType* str_obj, |
| 1228 intptr_t tags, | 1247 intptr_t len, |
| 1229 Snapshot::Kind kind) { | 1248 intptr_t tags) { |
| 1230 ASSERT(reader != NULL); | 1249 ASSERT(reader != NULL); |
| 1231 // Read the length so that we can determine instance size to allocate. | 1250 if (RawObject::IsCanonical(tags)) { |
| 1232 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); | 1251 // Set up canonical string object. |
| 1233 intptr_t len = Smi::Value(smi_len); | 1252 ASSERT(reader != NULL); |
| 1234 RawSmi* smi_hash = GetSmi(reader->ReadIntptrValue()); | |
| 1235 | |
| 1236 HandleType& str_obj = HandleType::ZoneHandle(reader->isolate(), | |
| 1237 HandleType::null()); | |
| 1238 if (kind != Snapshot::kFull && RawObject::IsCanonical(tags)) { | |
| 1239 CharacterType* ptr = reinterpret_cast<CharacterType*>(ZoneAllocator(len)); | 1253 CharacterType* ptr = reinterpret_cast<CharacterType*>(ZoneAllocator(len)); |
| 1240 for (intptr_t i = 0; i < len; i++) { | 1254 for (intptr_t i = 0; i < len; i++) { |
| 1241 ptr[i] = reader->Read<CharacterType>(); | 1255 ptr[i] = reader->Read<CharacterType>(); |
| 1242 } | 1256 } |
| 1243 str_obj ^= String::NewSymbol(ptr, len); | 1257 *str_obj ^= String::NewSymbol(ptr, len); |
| 1244 } else { | 1258 } else { |
| 1245 // Set up the string object. | 1259 // Set up the string object. |
| 1246 str_obj = HandleType::New( | 1260 *str_obj = HandleType::New(len, Heap::kNew); |
| 1247 len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew); | 1261 str_obj->set_tags(tags); |
| 1262 str_obj->SetHash(0); // Will get computed when needed. |
| 1248 for (intptr_t i = 0; i < len; i++) { | 1263 for (intptr_t i = 0; i < len; i++) { |
| 1249 *str_obj.CharAddr(i) = reader->Read<CharacterType>(); | 1264 *str_obj->CharAddr(i) = reader->Read<CharacterType>(); |
| 1250 } | 1265 } |
| 1251 str_obj.set_tags(tags); | |
| 1252 str_obj.SetHash(Smi::Value(smi_hash)); | |
| 1253 } | 1266 } |
| 1254 reader->AddBackwardReference(object_id, &str_obj); | |
| 1255 | |
| 1256 return str_obj.raw(); | |
| 1257 } | 1267 } |
| 1258 | 1268 |
| 1259 | 1269 |
| 1260 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1270 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
| 1261 intptr_t object_id, | 1271 intptr_t object_id, |
| 1262 intptr_t tags, | 1272 intptr_t tags, |
| 1263 Snapshot::Kind kind) { | 1273 Snapshot::Kind kind) { |
| 1264 return static_cast<RawOneByteString*>( | 1274 // Read the length so that we can determine instance size to allocate. |
| 1265 ReadFromImpl<OneByteString, uint8_t>(reader, object_id, tags, kind)); | 1275 ASSERT(reader != NULL); |
| 1276 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 1277 intptr_t hash = GetSmiValue(reader->ReadIntptrValue()); |
| 1278 OneByteString& str_obj = OneByteString::ZoneHandle(reader->isolate(), |
| 1279 OneByteString::null()); |
| 1280 |
| 1281 if (kind == Snapshot::kFull) { |
| 1282 ASSERT(reader->isolate()->no_gc_scope_depth() != 0); |
| 1283 RawOneByteString* obj = reader->NewOneByteString(len); |
| 1284 str_obj = obj; |
| 1285 str_obj.set_tags(tags); |
| 1286 obj->ptr()->hash_ = Smi::New(hash); |
| 1287 uint8_t* raw_ptr = (len > 0) ? str_obj.CharAddr(0) : NULL; |
| 1288 for (intptr_t i = 0; i < len; i++) { |
| 1289 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. |
| 1290 *raw_ptr = reader->Read<uint8_t>(); |
| 1291 raw_ptr += 1; |
| 1292 } |
| 1293 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); |
| 1294 } else { |
| 1295 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags); |
| 1296 } |
| 1297 reader->AddBackwardReference(object_id, &str_obj); |
| 1298 return str_obj.raw(); |
| 1266 } | 1299 } |
| 1267 | 1300 |
| 1268 | 1301 |
| 1269 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1302 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1270 intptr_t object_id, | 1303 intptr_t object_id, |
| 1271 intptr_t tags, | 1304 intptr_t tags, |
| 1272 Snapshot::Kind kind) { | 1305 Snapshot::Kind kind) { |
| 1273 return static_cast<RawTwoByteString*>( | 1306 // Read the length so that we can determine instance size to allocate. |
| 1274 ReadFromImpl<TwoByteString, uint16_t>(reader, object_id, tags, kind)); | 1307 ASSERT(reader != NULL); |
| 1308 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 1309 intptr_t hash = GetSmiValue(reader->ReadIntptrValue()); |
| 1310 TwoByteString& str_obj = TwoByteString::ZoneHandle(reader->isolate(), |
| 1311 TwoByteString::null()); |
| 1312 |
| 1313 if (kind == Snapshot::kFull) { |
| 1314 RawTwoByteString* obj = reader->NewTwoByteString(len); |
| 1315 str_obj = obj; |
| 1316 str_obj.set_tags(tags); |
| 1317 obj->ptr()->hash_ = Smi::New(hash); |
| 1318 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; |
| 1319 for (intptr_t i = 0; i < len; i++) { |
| 1320 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. |
| 1321 *raw_ptr = reader->Read<uint16_t>(); |
| 1322 raw_ptr += 1; |
| 1323 } |
| 1324 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
| 1325 } else { |
| 1326 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags); |
| 1327 } |
| 1328 reader->AddBackwardReference(object_id, &str_obj); |
| 1329 return str_obj.raw(); |
| 1275 } | 1330 } |
| 1276 | 1331 |
| 1277 | 1332 |
| 1278 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | 1333 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, |
| 1279 intptr_t object_id, | 1334 intptr_t object_id, |
| 1280 intptr_t tags, | 1335 intptr_t tags, |
| 1281 Snapshot::Kind kind) { | 1336 Snapshot::Kind kind) { |
| 1282 return static_cast<RawFourByteString*>( | 1337 // Read the length so that we can determine instance size to allocate. |
| 1283 ReadFromImpl<FourByteString, uint32_t>(reader, object_id, tags, kind)); | 1338 ASSERT(reader != NULL); |
| 1339 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 1340 intptr_t hash = GetSmiValue(reader->ReadIntptrValue()); |
| 1341 FourByteString& str_obj = FourByteString::ZoneHandle(reader->isolate(), |
| 1342 FourByteString::null()); |
| 1343 |
| 1344 if (kind == Snapshot::kFull) { |
| 1345 RawFourByteString* obj = reader->NewFourByteString(len); |
| 1346 str_obj = obj; |
| 1347 str_obj.set_tags(tags); |
| 1348 obj->ptr()->hash_ = Smi::New(hash); |
| 1349 uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; |
| 1350 for (intptr_t i = 0; i < len; i++) { |
| 1351 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. |
| 1352 *raw_ptr = reader->Read<uint32_t>(); |
| 1353 raw_ptr += 1; |
| 1354 } |
| 1355 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
| 1356 } else { |
| 1357 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags); |
| 1358 } |
| 1359 reader->AddBackwardReference(object_id, &str_obj); |
| 1360 return str_obj.raw(); |
| 1284 } | 1361 } |
| 1285 | 1362 |
| 1286 | 1363 |
| 1287 template<typename T> | 1364 template<typename T> |
| 1288 static void StringWriteTo(SnapshotWriter* writer, | 1365 static void StringWriteTo(SnapshotWriter* writer, |
| 1289 intptr_t object_id, | 1366 intptr_t object_id, |
| 1290 Snapshot::Kind kind, | 1367 Snapshot::Kind kind, |
| 1291 intptr_t class_id, | 1368 intptr_t class_id, |
| 1292 intptr_t tags, | 1369 intptr_t tags, |
| 1293 RawSmi* length, | 1370 RawSmi* length, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 } | 1518 } |
| 1442 | 1519 |
| 1443 | 1520 |
| 1444 void RawBool::WriteTo(SnapshotWriter* writer, | 1521 void RawBool::WriteTo(SnapshotWriter* writer, |
| 1445 intptr_t object_id, | 1522 intptr_t object_id, |
| 1446 Snapshot::Kind kind) { | 1523 Snapshot::Kind kind) { |
| 1447 UNREACHABLE(); | 1524 UNREACHABLE(); |
| 1448 } | 1525 } |
| 1449 | 1526 |
| 1450 | 1527 |
| 1451 template <class T> | 1528 static void ArrayReadFrom(SnapshotReader* reader, |
| 1452 static RawObject* ArrayReadFrom(SnapshotReader* reader, | 1529 const Array& result, |
| 1453 intptr_t object_id, | 1530 intptr_t len, |
| 1454 intptr_t tags, | 1531 intptr_t tags) { |
| 1455 Snapshot::Kind kind) { | |
| 1456 ASSERT(reader != NULL); | 1532 ASSERT(reader != NULL); |
| 1457 | 1533 |
| 1458 // Read the length so that we can determine instance size to allocate. | |
| 1459 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); | |
| 1460 intptr_t len = Smi::Value(smi_len); | |
| 1461 T& result = T::ZoneHandle( | |
| 1462 reader->isolate(), | |
| 1463 T::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | |
| 1464 reader->AddBackwardReference(object_id, &result); | |
| 1465 | |
| 1466 // Set the object tags. | 1534 // Set the object tags. |
| 1467 result.set_tags(tags); | 1535 result.set_tags(tags); |
| 1468 | 1536 |
| 1469 // Setup the object fields. | 1537 // Setup the object fields. |
| 1470 *reader->TypeArgumentsHandle() ^= reader->ReadObject(); | 1538 *reader->TypeArgumentsHandle() ^= reader->ReadObject(); |
| 1471 result.SetTypeArguments(*reader->TypeArgumentsHandle()); | 1539 result.SetTypeArguments(*reader->TypeArgumentsHandle()); |
| 1472 | 1540 |
| 1473 for (intptr_t i = 0; i < len; i++) { | 1541 for (intptr_t i = 0; i < len; i++) { |
| 1474 *reader->ObjectHandle() = reader->ReadObject(); | 1542 *reader->ObjectHandle() = reader->ReadObject(); |
| 1475 result.SetAt(i, *reader->ObjectHandle()); | 1543 result.SetAt(i, *reader->ObjectHandle()); |
| 1476 } | 1544 } |
| 1477 return result.raw(); | |
| 1478 } | 1545 } |
| 1479 | 1546 |
| 1480 | 1547 |
| 1481 RawArray* Array::ReadFrom(SnapshotReader* reader, | 1548 RawArray* Array::ReadFrom(SnapshotReader* reader, |
| 1482 intptr_t object_id, | 1549 intptr_t object_id, |
| 1483 intptr_t tags, | 1550 intptr_t tags, |
| 1484 Snapshot::Kind kind) { | 1551 Snapshot::Kind kind) { |
| 1485 return reinterpret_cast<RawArray*>( | 1552 ASSERT(reader != NULL); |
| 1486 ArrayReadFrom<Array>(reader, object_id, tags, kind)); | 1553 |
| 1554 // Read the length so that we can determine instance size to allocate. |
| 1555 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 1556 Array& array = Array::ZoneHandle(reader->isolate(), |
| 1557 NEW_OBJECT_WITH_LEN(Array, len)); |
| 1558 reader->AddBackwardReference(object_id, &array); |
| 1559 ArrayReadFrom(reader, array, len, tags); |
| 1560 return array.raw(); |
| 1487 } | 1561 } |
| 1488 | 1562 |
| 1489 | 1563 |
| 1490 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, | 1564 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, |
| 1491 intptr_t object_id, | 1565 intptr_t object_id, |
| 1492 intptr_t tags, | 1566 intptr_t tags, |
| 1493 Snapshot::Kind kind) { | 1567 Snapshot::Kind kind) { |
| 1494 return reinterpret_cast<RawImmutableArray*>( | 1568 ASSERT(reader != NULL); |
| 1495 ArrayReadFrom<ImmutableArray>(reader, object_id, tags, kind)); | 1569 |
| 1570 // Read the length so that we can determine instance size to allocate. |
| 1571 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 1572 ImmutableArray& array = ImmutableArray::ZoneHandle( |
| 1573 reader->isolate(), NEW_OBJECT_WITH_LEN(ImmutableArray, len)); |
| 1574 reader->AddBackwardReference(object_id, &array); |
| 1575 ArrayReadFrom(reader, array, len, tags); |
| 1576 return array.raw(); |
| 1496 } | 1577 } |
| 1497 | 1578 |
| 1498 | 1579 |
| 1499 static void ArrayWriteTo(SnapshotWriter* writer, | 1580 static void ArrayWriteTo(SnapshotWriter* writer, |
| 1500 intptr_t object_id, | 1581 intptr_t object_id, |
| 1501 Snapshot::Kind kind, | 1582 Snapshot::Kind kind, |
| 1502 intptr_t array_kind, | 1583 intptr_t array_kind, |
| 1503 intptr_t tags, | 1584 intptr_t tags, |
| 1504 RawSmi* length, | 1585 RawSmi* length, |
| 1505 RawAbstractTypeArguments* type_arguments, | 1586 RawAbstractTypeArguments* type_arguments, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 | 1684 |
| 1604 | 1685 |
| 1605 RawJSRegExp* JSRegExp::ReadFrom(SnapshotReader* reader, | 1686 RawJSRegExp* JSRegExp::ReadFrom(SnapshotReader* reader, |
| 1606 intptr_t object_id, | 1687 intptr_t object_id, |
| 1607 intptr_t tags, | 1688 intptr_t tags, |
| 1608 Snapshot::Kind kind) { | 1689 Snapshot::Kind kind) { |
| 1609 ASSERT(reader != NULL); | 1690 ASSERT(reader != NULL); |
| 1610 ASSERT(kind == Snapshot::kMessage); | 1691 ASSERT(kind == Snapshot::kMessage); |
| 1611 | 1692 |
| 1612 // Read the length so that we can determine instance size to allocate. | 1693 // Read the length so that we can determine instance size to allocate. |
| 1613 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); | 1694 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 1614 intptr_t len = Smi::Value(smi_len); | |
| 1615 | 1695 |
| 1616 // Allocate JSRegExp object. | 1696 // Allocate JSRegExp object. |
| 1617 JSRegExp& regex = JSRegExp::ZoneHandle( | 1697 JSRegExp& regex = JSRegExp::ZoneHandle( |
| 1618 reader->isolate(), | 1698 reader->isolate(), |
| 1619 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | 1699 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); |
| 1620 reader->AddBackwardReference(object_id, ®ex); | 1700 reader->AddBackwardReference(object_id, ®ex); |
| 1621 | 1701 |
| 1622 // Set the object tags. | 1702 // Set the object tags. |
| 1623 regex.set_tags(tags); | 1703 regex.set_tags(tags); |
| 1624 | 1704 |
| 1625 // Read and Set all the other fields. | 1705 // Read and Set all the other fields. |
| 1626 regex.raw_ptr()->num_bracket_expressions_ = GetSmi(reader->ReadIntptrValue()); | 1706 regex.raw_ptr()->num_bracket_expressions_ = AsSmi(reader->ReadIntptrValue()); |
| 1627 *reader->StringHandle() ^= reader->ReadObject(); | 1707 *reader->StringHandle() ^= reader->ReadObject(); |
| 1628 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw(); | 1708 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw(); |
| 1629 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); | 1709 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); |
| 1630 regex.raw_ptr()->flags_ = reader->ReadIntptrValue(); | 1710 regex.raw_ptr()->flags_ = reader->ReadIntptrValue(); |
| 1631 | 1711 |
| 1632 // TODO(5411462): Need to implement a way of recompiling the regex. | 1712 // TODO(5411462): Need to implement a way of recompiling the regex. |
| 1633 | 1713 |
| 1634 return regex.raw(); | 1714 return regex.raw(); |
| 1635 } | 1715 } |
| 1636 | 1716 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1653 // Write out all the other fields. | 1733 // Write out all the other fields. |
| 1654 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 1734 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); |
| 1655 writer->WriteObject(ptr()->pattern_); | 1735 writer->WriteObject(ptr()->pattern_); |
| 1656 writer->WriteIntptrValue(ptr()->type_); | 1736 writer->WriteIntptrValue(ptr()->type_); |
| 1657 writer->WriteIntptrValue(ptr()->flags_); | 1737 writer->WriteIntptrValue(ptr()->flags_); |
| 1658 | 1738 |
| 1659 // Do not write out the data part which is native. | 1739 // Do not write out the data part which is native. |
| 1660 } | 1740 } |
| 1661 | 1741 |
| 1662 } // namespace dart | 1742 } // namespace dart |
| OLD | NEW |