Chromium Code Reviews| 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() | |
|
Ivan Posva
2012/01/16 19:30:33
Parens around this expression to avoid being surpr
siva
2012/01/18 00:00:24
Done.
| |
| 15 | |
| 16 static RawSmi* AsSmi(intptr_t value) { | |
| 14 ASSERT((value & kSmiTagMask) == 0); | 17 ASSERT((value & kSmiTagMask) == 0); |
| 15 return reinterpret_cast<RawSmi*>(value); | 18 return reinterpret_cast<RawSmi*>(value); |
| 16 } | 19 } |
| 17 | 20 |
| 18 | 21 |
| 22 static intptr_t GetSmiValue(intptr_t value) { | |
| 23 return Smi::Value(AsSmi(value)); | |
| 24 } | |
| 25 | |
| 26 | |
| 19 static uword ZoneAllocator(intptr_t size) { | 27 static uword ZoneAllocator(intptr_t size) { |
| 20 Zone* zone = Isolate::Current()->current_zone(); | 28 Zone* zone = Isolate::Current()->current_zone(); |
| 21 return zone->Allocate(size); | 29 return zone->Allocate(size); |
| 22 } | 30 } |
| 23 | 31 |
| 24 | 32 |
| 25 RawClass* Class::ReadFrom(SnapshotReader* reader, | 33 RawClass* Class::ReadFrom(SnapshotReader* reader, |
| 26 intptr_t object_id, | 34 intptr_t object_id, |
| 27 intptr_t tags, | 35 intptr_t tags, |
| 28 Snapshot::Kind kind) { | 36 Snapshot::Kind kind) { |
| 29 ASSERT(reader != NULL); | 37 ASSERT(reader != NULL); |
| 30 | 38 |
| 31 Class& cls = Class::ZoneHandle(reader->isolate(), Class::null()); | 39 Class& cls = Class::ZoneHandle(reader->isolate(), Class::null()); |
| 32 if ((kind == Snapshot::kFull) || | 40 if ((kind == Snapshot::kFull) || |
| 33 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { | 41 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { |
| 34 // Read in the base information. | 42 // Read in the base information. |
| 35 ObjectKind kind = reader->Read<ObjectKind>(); | 43 ObjectKind object_kind = reader->Read<ObjectKind>(); |
| 36 | 44 |
| 37 // Allocate class object of specified kind. | 45 // Allocate class object of specified kind. |
| 38 cls = Class::GetClass(kind); | 46 if (kind == Snapshot::kFull) { |
| 47 reader->NewClass(&cls, object_kind); | |
| 48 } else { | |
| 49 cls = Class::GetClass(object_kind); | |
| 50 } | |
| 39 reader->AddBackwardReference(object_id, &cls); | 51 reader->AddBackwardReference(object_id, &cls); |
| 40 | 52 |
| 41 // Set the object tags. | 53 // Set the object tags. |
| 42 cls.set_tags(tags); | 54 cls.set_tags(tags); |
| 43 | 55 |
| 44 // Set all non object fields. | 56 // Set all non object fields. |
| 45 cls.set_instance_size(reader->ReadIntptrValue()); | 57 cls.set_instance_size(reader->ReadIntptrValue()); |
| 46 cls.set_type_arguments_instance_field_offset(reader->ReadIntptrValue()); | 58 cls.set_type_arguments_instance_field_offset(reader->ReadIntptrValue()); |
| 47 cls.set_next_field_offset(reader->ReadIntptrValue()); | 59 cls.set_next_field_offset(reader->ReadIntptrValue()); |
| 48 cls.set_num_native_fields(reader->ReadIntptrValue()); | 60 cls.set_num_native_fields(reader->ReadIntptrValue()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 } | 113 } |
| 102 | 114 |
| 103 | 115 |
| 104 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, | 116 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, |
| 105 intptr_t object_id, | 117 intptr_t object_id, |
| 106 intptr_t tags, | 118 intptr_t tags, |
| 107 Snapshot::Kind kind) { | 119 Snapshot::Kind kind) { |
| 108 ASSERT(reader != NULL); | 120 ASSERT(reader != NULL); |
| 109 | 121 |
| 110 // Allocate parameterized type object. | 122 // Allocate parameterized type object. |
| 111 UnresolvedClass& unresolved_class = | 123 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( |
| 112 UnresolvedClass::ZoneHandle(reader->isolate(), UnresolvedClass::New()); | 124 reader->isolate(), NEW_OBJECT(UnresolvedClass)); |
| 113 reader->AddBackwardReference(object_id, &unresolved_class); | 125 reader->AddBackwardReference(object_id, &unresolved_class); |
| 114 | 126 |
| 115 // Set the object tags. | 127 // Set the object tags. |
| 116 unresolved_class.set_tags(tags); | 128 unresolved_class.set_tags(tags); |
| 117 | 129 |
| 118 // Set all non object fields. | 130 // Set all non object fields. |
| 119 unresolved_class.set_token_index(reader->ReadIntptrValue()); | 131 unresolved_class.set_token_index(reader->ReadIntptrValue()); |
| 120 | 132 |
| 121 // Set all the object fields. | 133 // Set all the object fields. |
| 122 // TODO(5411462): Need to assert No GC can happen here, even though | 134 // 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 } | 178 } |
| 167 | 179 |
| 168 | 180 |
| 169 RawType* Type::ReadFrom(SnapshotReader* reader, | 181 RawType* Type::ReadFrom(SnapshotReader* reader, |
| 170 intptr_t object_id, | 182 intptr_t object_id, |
| 171 intptr_t tags, | 183 intptr_t tags, |
| 172 Snapshot::Kind kind) { | 184 Snapshot::Kind kind) { |
| 173 ASSERT(reader != NULL); | 185 ASSERT(reader != NULL); |
| 174 | 186 |
| 175 // Allocate parameterized type object. | 187 // Allocate parameterized type object. |
| 176 Type& parameterized_type = Type::ZoneHandle(reader->isolate(), Type::New()); | 188 Type& parameterized_type = Type::ZoneHandle( |
| 189 reader->isolate(), NEW_OBJECT(Type)); | |
| 177 reader->AddBackwardReference(object_id, ¶meterized_type); | 190 reader->AddBackwardReference(object_id, ¶meterized_type); |
| 178 | 191 |
| 179 // Set the object tags. | 192 // Set the object tags. |
| 180 parameterized_type.set_tags(tags); | 193 parameterized_type.set_tags(tags); |
| 181 | 194 |
| 182 // Set all non object fields. | 195 // Set all non object fields. |
| 183 parameterized_type.set_type_state(reader->Read<int8_t>()); | 196 parameterized_type.set_type_state(reader->Read<int8_t>()); |
| 184 | 197 |
| 185 // Set all the object fields. | 198 // Set all the object fields. |
| 186 // TODO(5411462): Need to assert No GC can happen here, even though | 199 // 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 } | 232 } |
| 220 | 233 |
| 221 | 234 |
| 222 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, | 235 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, |
| 223 intptr_t object_id, | 236 intptr_t object_id, |
| 224 intptr_t tags, | 237 intptr_t tags, |
| 225 Snapshot::Kind kind) { | 238 Snapshot::Kind kind) { |
| 226 ASSERT(reader != NULL); | 239 ASSERT(reader != NULL); |
| 227 | 240 |
| 228 // Allocate type parameter object. | 241 // Allocate type parameter object. |
| 229 TypeParameter& type_parameter = | 242 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
| 230 TypeParameter::ZoneHandle(reader->isolate(), TypeParameter::New()); | 243 reader->isolate(), NEW_OBJECT(TypeParameter)); |
| 231 reader->AddBackwardReference(object_id, &type_parameter); | 244 reader->AddBackwardReference(object_id, &type_parameter); |
| 232 | 245 |
| 233 // Set the object tags. | 246 // Set the object tags. |
| 234 type_parameter.set_tags(tags); | 247 type_parameter.set_tags(tags); |
| 235 | 248 |
| 236 // Set all non object fields. | 249 // Set all non object fields. |
| 237 type_parameter.set_index(reader->ReadIntptrValue()); | 250 type_parameter.set_index(reader->ReadIntptrValue()); |
| 238 type_parameter.set_type_state(reader->Read<int8_t>()); | 251 type_parameter.set_type_state(reader->Read<int8_t>()); |
| 239 | 252 |
| 240 // Set all the object fields. | 253 // Set all the object fields. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 } | 346 } |
| 334 | 347 |
| 335 | 348 |
| 336 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, | 349 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, |
| 337 intptr_t object_id, | 350 intptr_t object_id, |
| 338 intptr_t tags, | 351 intptr_t tags, |
| 339 Snapshot::Kind kind) { | 352 Snapshot::Kind kind) { |
| 340 ASSERT(reader != NULL); | 353 ASSERT(reader != NULL); |
| 341 | 354 |
| 342 // Read the length so that we can determine instance size to allocate. | 355 // Read the length so that we can determine instance size to allocate. |
| 343 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); | 356 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 344 intptr_t len = Smi::Value(smi_len); | |
| 345 | 357 |
| 346 TypeArguments& type_arguments = | 358 TypeArguments& type_arguments = TypeArguments::ZoneHandle( |
| 347 TypeArguments::ZoneHandle(reader->isolate(), TypeArguments::New(len)); | 359 reader->isolate(), TypeArguments::null()); |
| 360 if (kind == Snapshot::kFull) { | |
| 361 reader->NewTypeArguments(&type_arguments, len); | |
| 362 } else { | |
| 363 type_arguments = TypeArguments::New(len); | |
| 364 } | |
| 348 reader->AddBackwardReference(object_id, &type_arguments); | 365 reader->AddBackwardReference(object_id, &type_arguments); |
| 349 | 366 |
| 350 // Now set all the object fields. | 367 // Now set all the object fields. |
| 351 for (intptr_t i = 0; i < len; i++) { | 368 for (intptr_t i = 0; i < len; i++) { |
| 352 *reader->TypeHandle() ^= reader->ReadObject(); | 369 *reader->TypeHandle() ^= reader->ReadObject(); |
| 353 type_arguments.SetTypeAt(i, *reader->TypeHandle()); | 370 type_arguments.SetTypeAt(i, *reader->TypeHandle()); |
| 354 } | 371 } |
| 355 | 372 |
| 356 // Set the object tags (This is done after setting the object fields | 373 // 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 | 374 // 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 | 454 |
| 438 | 455 |
| 439 RawFunction* Function::ReadFrom(SnapshotReader* reader, | 456 RawFunction* Function::ReadFrom(SnapshotReader* reader, |
| 440 intptr_t object_id, | 457 intptr_t object_id, |
| 441 intptr_t tags, | 458 intptr_t tags, |
| 442 Snapshot::Kind kind) { | 459 Snapshot::Kind kind) { |
| 443 ASSERT(reader != NULL); | 460 ASSERT(reader != NULL); |
| 444 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 461 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 445 | 462 |
| 446 // Allocate function object. | 463 // Allocate function object. |
| 447 Function& func = Function::ZoneHandle(reader->isolate(), Function::New()); | 464 Function& func = Function::ZoneHandle( |
| 465 reader->isolate(), NEW_OBJECT(Function)); | |
| 448 reader->AddBackwardReference(object_id, &func); | 466 reader->AddBackwardReference(object_id, &func); |
| 449 | 467 |
| 450 // Set the object tags. | 468 // Set the object tags. |
| 451 func.set_tags(tags); | 469 func.set_tags(tags); |
| 452 | 470 |
| 453 // Set all the non object fields. | 471 // Set all the non object fields. |
| 454 func.set_token_index(reader->ReadIntptrValue()); | 472 func.set_token_index(reader->ReadIntptrValue()); |
| 455 func.set_num_fixed_parameters(reader->ReadIntptrValue()); | 473 func.set_num_fixed_parameters(reader->ReadIntptrValue()); |
| 456 func.set_num_optional_parameters(reader->ReadIntptrValue()); | 474 func.set_num_optional_parameters(reader->ReadIntptrValue()); |
| 457 func.set_invocation_counter(reader->ReadIntptrValue()); | 475 func.set_invocation_counter(reader->ReadIntptrValue()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 | 521 |
| 504 | 522 |
| 505 RawField* Field::ReadFrom(SnapshotReader* reader, | 523 RawField* Field::ReadFrom(SnapshotReader* reader, |
| 506 intptr_t object_id, | 524 intptr_t object_id, |
| 507 intptr_t tags, | 525 intptr_t tags, |
| 508 Snapshot::Kind kind) { | 526 Snapshot::Kind kind) { |
| 509 ASSERT(reader != NULL); | 527 ASSERT(reader != NULL); |
| 510 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 528 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 511 | 529 |
| 512 // Allocate field object. | 530 // Allocate field object. |
| 513 Field& field = Field::ZoneHandle(reader->isolate(), Field::New()); | 531 Field& field = Field::ZoneHandle(reader->isolate(), NEW_OBJECT(Field)); |
| 514 reader->AddBackwardReference(object_id, &field); | 532 reader->AddBackwardReference(object_id, &field); |
| 515 | 533 |
| 516 // Set the object tags. | 534 // Set the object tags. |
| 517 field.set_tags(tags); | 535 field.set_tags(tags); |
| 518 | 536 |
| 519 // Set all non object fields. | 537 // Set all non object fields. |
| 520 field.set_token_index(reader->ReadIntptrValue()); | 538 field.set_token_index(reader->ReadIntptrValue()); |
| 521 field.set_is_static(reader->Read<bool>()); | 539 field.set_is_static(reader->Read<bool>()); |
| 522 field.set_is_final(reader->Read<bool>()); | 540 field.set_is_final(reader->Read<bool>()); |
| 523 field.set_has_initializer(reader->Read<bool>()); | 541 field.set_has_initializer(reader->Read<bool>()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 | 577 |
| 560 | 578 |
| 561 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, | 579 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, |
| 562 intptr_t object_id, | 580 intptr_t object_id, |
| 563 intptr_t tags, | 581 intptr_t tags, |
| 564 Snapshot::Kind kind) { | 582 Snapshot::Kind kind) { |
| 565 ASSERT(reader != NULL); | 583 ASSERT(reader != NULL); |
| 566 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 584 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 567 | 585 |
| 568 // Read the length so that we can determine number of tokens to read. | 586 // Read the length so that we can determine number of tokens to read. |
| 569 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); | 587 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); |
| 570 intptr_t len = Smi::Value(smi_len); | |
| 571 | 588 |
| 572 // Create the token stream object. | 589 // Create the token stream object. |
| 573 TokenStream& token_stream = TokenStream::ZoneHandle(reader->isolate(), | 590 TokenStream& token_stream = TokenStream::ZoneHandle( |
| 574 TokenStream::New(len)); | 591 reader->isolate(), TokenStream::null()); |
| 592 if (kind == Snapshot::kFull) { | |
| 593 reader->NewTokenStream(&token_stream, len); | |
| 594 } else { | |
| 595 token_stream = TokenStream::New(len); | |
| 596 } | |
| 575 reader->AddBackwardReference(object_id, &token_stream); | 597 reader->AddBackwardReference(object_id, &token_stream); |
| 576 | 598 |
| 577 // Set the object tags. | 599 // Set the object tags. |
| 578 token_stream.set_tags(tags); | 600 token_stream.set_tags(tags); |
| 579 | 601 |
| 580 // Read the token stream into the TokenStream. | 602 // Read the token stream into the TokenStream. |
| 581 for (intptr_t i = 0; i < len; i++) { | 603 for (intptr_t i = 0; i < len; i++) { |
| 582 Token::Kind kind = static_cast<Token::Kind>( | 604 Token::Kind kind = static_cast<Token::Kind>( |
| 583 Smi::Value(GetSmi(reader->ReadIntptrValue()))); | 605 GetSmiValue(reader->ReadIntptrValue())); |
| 584 *reader->StringHandle() ^= reader->ReadObject(); | 606 *reader->StringHandle() ^= reader->ReadObject(); |
| 585 token_stream.SetTokenAt(i, kind, *reader->StringHandle()); | 607 token_stream.SetTokenAt(i, kind, *reader->StringHandle()); |
| 586 } | 608 } |
| 587 return token_stream.raw(); | 609 return token_stream.raw(); |
| 588 } | 610 } |
| 589 | 611 |
| 590 | 612 |
| 591 void RawTokenStream::WriteTo(SnapshotWriter* writer, | 613 void RawTokenStream::WriteTo(SnapshotWriter* writer, |
| 592 intptr_t object_id, | 614 intptr_t object_id, |
| 593 Snapshot::Kind kind) { | 615 Snapshot::Kind kind) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 612 | 634 |
| 613 | 635 |
| 614 RawScript* Script::ReadFrom(SnapshotReader* reader, | 636 RawScript* Script::ReadFrom(SnapshotReader* reader, |
| 615 intptr_t object_id, | 637 intptr_t object_id, |
| 616 intptr_t tags, | 638 intptr_t tags, |
| 617 Snapshot::Kind kind) { | 639 Snapshot::Kind kind) { |
| 618 ASSERT(reader != NULL); | 640 ASSERT(reader != NULL); |
| 619 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 641 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 620 | 642 |
| 621 // Allocate script object. | 643 // Allocate script object. |
| 622 Script& script = Script::ZoneHandle(reader->isolate(), Script::New()); | 644 Script& script = Script::ZoneHandle(reader->isolate(), NEW_OBJECT(Script)); |
| 623 reader->AddBackwardReference(object_id, &script); | 645 reader->AddBackwardReference(object_id, &script); |
| 624 | 646 |
| 625 // Set the object tags. | 647 // Set the object tags. |
| 626 script.set_tags(tags); | 648 script.set_tags(tags); |
| 627 | 649 |
| 628 // Set all the object fields. | 650 // Set all the object fields. |
| 629 // TODO(5411462): Need to assert No GC can happen here, even though | 651 // TODO(5411462): Need to assert No GC can happen here, even though |
| 630 // allocations may happen. | 652 // allocations may happen. |
| 631 intptr_t num_flds = (script.raw()->to() - script.raw()->from()); | 653 intptr_t num_flds = (script.raw()->to() - script.raw()->from()); |
| 632 for (intptr_t i = 0; i <= num_flds; i++) { | 654 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()); | 688 Library& library = Library::ZoneHandle(reader->isolate(), Library::null()); |
| 667 reader->AddBackwardReference(object_id, &library); | 689 reader->AddBackwardReference(object_id, &library); |
| 668 | 690 |
| 669 if (RawObject::IsCreatedFromSnapshot(tags)) { | 691 if (RawObject::IsCreatedFromSnapshot(tags)) { |
| 670 ASSERT(kind != Snapshot::kFull); | 692 ASSERT(kind != Snapshot::kFull); |
| 671 // Lookup the object as it should already exist in the heap. | 693 // Lookup the object as it should already exist in the heap. |
| 672 *reader->StringHandle() ^= reader->ReadObject(); | 694 *reader->StringHandle() ^= reader->ReadObject(); |
| 673 library = Library::LookupLibrary(*reader->StringHandle()); | 695 library = Library::LookupLibrary(*reader->StringHandle()); |
| 674 } else { | 696 } else { |
| 675 // Allocate library object. | 697 // Allocate library object. |
| 676 library = Library::New(); | 698 library = NEW_OBJECT(Library); |
| 677 | 699 |
| 678 // Set the object tags. | 700 // Set the object tags. |
| 679 library.set_tags(tags); | 701 library.set_tags(tags); |
| 680 | 702 |
| 681 // Set all non object fields. | 703 // Set all non object fields. |
| 682 library.raw_ptr()->num_imports_ = reader->ReadIntptrValue(); | 704 library.raw_ptr()->num_imports_ = reader->ReadIntptrValue(); |
| 683 library.raw_ptr()->num_imported_into_ = reader->ReadIntptrValue(); | 705 library.raw_ptr()->num_imported_into_ = reader->ReadIntptrValue(); |
| 684 library.raw_ptr()->num_anonymous_ = reader->ReadIntptrValue(); | 706 library.raw_ptr()->num_anonymous_ = reader->ReadIntptrValue(); |
| 685 library.raw_ptr()->corelib_imported_ = reader->Read<bool>(); | 707 library.raw_ptr()->corelib_imported_ = reader->Read<bool>(); |
| 686 library.raw_ptr()->load_state_ = reader->Read<int8_t>(); | 708 library.raw_ptr()->load_state_ = reader->Read<int8_t>(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 | 759 |
| 738 | 760 |
| 739 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, | 761 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, |
| 740 intptr_t object_id, | 762 intptr_t object_id, |
| 741 intptr_t tags, | 763 intptr_t tags, |
| 742 Snapshot::Kind kind) { | 764 Snapshot::Kind kind) { |
| 743 ASSERT(reader != NULL); | 765 ASSERT(reader != NULL); |
| 744 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); | 766 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); |
| 745 | 767 |
| 746 // Allocate library prefix object. | 768 // Allocate library prefix object. |
| 747 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(reader->isolate(), | 769 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle( |
| 748 LibraryPrefix::New()); | 770 reader->isolate(), NEW_OBJECT(LibraryPrefix)); |
| 749 reader->AddBackwardReference(object_id, &prefix); | 771 reader->AddBackwardReference(object_id, &prefix); |
| 750 | 772 |
| 751 // Set the object tags. | 773 // Set the object tags. |
| 752 prefix.set_tags(tags); | 774 prefix.set_tags(tags); |
| 753 | 775 |
| 754 // Set all the object fields. | 776 // Set all the object fields. |
| 755 // TODO(5411462): Need to assert No GC can happen here, even though | 777 // TODO(5411462): Need to assert No GC can happen here, even though |
| 756 // allocations may happen. | 778 // allocations may happen. |
| 757 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); | 779 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); |
| 758 for (intptr_t i = 0; i <= num_flds; i++) { | 780 for (intptr_t i = 0; i <= num_flds; i++) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 778 // Write out all the object pointer fields. | 800 // Write out all the object pointer fields. |
| 779 SnapshotWriterVisitor visitor(writer); | 801 SnapshotWriterVisitor visitor(writer); |
| 780 visitor.VisitPointers(from(), to()); | 802 visitor.VisitPointers(from(), to()); |
| 781 } | 803 } |
| 782 | 804 |
| 783 | 805 |
| 784 RawCode* Code::ReadFrom(SnapshotReader* reader, | 806 RawCode* Code::ReadFrom(SnapshotReader* reader, |
| 785 intptr_t object_id, | 807 intptr_t object_id, |
| 786 intptr_t tags, | 808 intptr_t tags, |
| 787 Snapshot::Kind kind) { | 809 Snapshot::Kind kind) { |
| 788 ASSERT(reader != NULL); | 810 UNREACHABLE(); |
| 789 ASSERT(kind != Snapshot::kMessage); | 811 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 } | 812 } |
| 796 | 813 |
| 797 | 814 |
| 798 void RawCode::WriteTo(SnapshotWriter* writer, | 815 void RawCode::WriteTo(SnapshotWriter* writer, |
| 799 intptr_t object_id, | 816 intptr_t object_id, |
| 800 Snapshot::Kind kind) { | 817 Snapshot::Kind kind) { |
| 801 // Currently we do not serialize any code and hence we write | 818 // Currently we do not serialize any code and hence we write |
| 802 // out a null object for it. | 819 // out a null object for it. |
| 803 ASSERT(writer != NULL); | 820 ASSERT(writer != NULL); |
| 804 ASSERT(kind != Snapshot::kMessage); | 821 ASSERT(kind != Snapshot::kMessage); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 | 889 |
| 873 | 890 |
| 874 RawContext* Context::ReadFrom(SnapshotReader* reader, | 891 RawContext* Context::ReadFrom(SnapshotReader* reader, |
| 875 intptr_t object_id, | 892 intptr_t object_id, |
| 876 intptr_t tags, | 893 intptr_t tags, |
| 877 Snapshot::Kind kind) { | 894 Snapshot::Kind kind) { |
| 878 ASSERT(reader != NULL); | 895 ASSERT(reader != NULL); |
| 879 | 896 |
| 880 // Allocate context object. | 897 // Allocate context object. |
| 881 intptr_t num_vars = reader->ReadIntptrValue(); | 898 intptr_t num_vars = reader->ReadIntptrValue(); |
| 882 Context& context = Context::ZoneHandle( | 899 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); |
| 883 reader->isolate(), | 900 if (kind == Snapshot::kFull) { |
| 884 Context::New(num_vars, | 901 reader->NewContext(&context, num_vars); |
| 885 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | 902 } else { |
| 903 context = Context::New(num_vars); | |
| 904 } | |
| 886 reader->AddBackwardReference(object_id, &context); | 905 reader->AddBackwardReference(object_id, &context); |
| 887 | 906 |
| 888 // Set the object tags. | 907 // Set the object tags. |
| 889 context.set_tags(tags); | 908 context.set_tags(tags); |
| 890 | 909 |
| 891 // Set the isolate implicitly. | 910 // Set the isolate implicitly. |
| 892 context.set_isolate(Isolate::Current()); | 911 context.set_isolate(Isolate::Current()); |
| 893 | 912 |
| 894 // Set all the object fields. | 913 // Set all the object fields. |
| 895 // TODO(5411462): Need to assert No GC can happen here, even though | 914 // 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, | 1093 intptr_t object_id, |
| 1075 intptr_t tags, | 1094 intptr_t tags, |
| 1076 Snapshot::Kind kind) { | 1095 Snapshot::Kind kind) { |
| 1077 ASSERT(reader != NULL); | 1096 ASSERT(reader != NULL); |
| 1078 | 1097 |
| 1079 // Read the 64 bit value for the object. | 1098 // Read the 64 bit value for the object. |
| 1080 int64_t value = reader->Read<int64_t>(); | 1099 int64_t value = reader->Read<int64_t>(); |
| 1081 | 1100 |
| 1082 // Create a Mint object or get canonical one if it is a canonical constant. | 1101 // Create a Mint object or get canonical one if it is a canonical constant. |
| 1083 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); | 1102 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); |
| 1084 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 1103 if (kind == Snapshot::kFull) { |
| 1085 mint = Mint::NewCanonical(value); | 1104 reader->NewMint(&mint, value); |
| 1086 } else { | 1105 } else { |
| 1087 mint = Mint::New(value, | 1106 if (RawObject::IsCanonical(tags)) { |
| 1088 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew); | 1107 mint = Mint::NewCanonical(value); |
| 1108 } else { | |
| 1109 mint = Mint::New(value, Heap::kNew); | |
| 1110 } | |
| 1089 } | 1111 } |
| 1090 reader->AddBackwardReference(object_id, &mint); | 1112 reader->AddBackwardReference(object_id, &mint); |
| 1091 | 1113 |
| 1092 // Set the object tags. | 1114 // Set the object tags. |
| 1093 mint.set_tags(tags); | 1115 mint.set_tags(tags); |
| 1094 | 1116 |
| 1095 return mint.raw(); | 1117 return mint.raw(); |
| 1096 } | 1118 } |
| 1097 | 1119 |
| 1098 | 1120 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 RawDouble* Double::ReadFrom(SnapshotReader* reader, | 1190 RawDouble* Double::ReadFrom(SnapshotReader* reader, |
| 1169 intptr_t object_id, | 1191 intptr_t object_id, |
| 1170 intptr_t tags, | 1192 intptr_t tags, |
| 1171 Snapshot::Kind kind) { | 1193 Snapshot::Kind kind) { |
| 1172 ASSERT(reader != NULL); | 1194 ASSERT(reader != NULL); |
| 1173 // Read the double value for the object. | 1195 // Read the double value for the object. |
| 1174 double value = reader->Read<double>(); | 1196 double value = reader->Read<double>(); |
| 1175 | 1197 |
| 1176 // Create a Double object or get canonical one if it is a canonical constant. | 1198 // Create a Double object or get canonical one if it is a canonical constant. |
| 1177 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); | 1199 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); |
| 1178 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 1200 if (kind == Snapshot::kFull) { |
| 1179 dbl = Double::NewCanonical(value); | 1201 reader->NewDouble(&dbl, value); |
| 1180 } else { | 1202 } else { |
| 1181 dbl = Double::New(value, | 1203 if (RawObject::IsCanonical(tags)) { |
| 1182 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew); | 1204 dbl = Double::NewCanonical(value); |
| 1205 } else { | |
| 1206 dbl = Double::New(value, Heap::kNew); | |
| 1207 } | |
| 1183 } | 1208 } |
| 1184 reader->AddBackwardReference(object_id, &dbl); | 1209 reader->AddBackwardReference(object_id, &dbl); |
| 1185 | 1210 |
| 1186 // Set the object tags. | 1211 // Set the object tags. |
| 1187 dbl.set_tags(tags); | 1212 dbl.set_tags(tags); |
| 1188 | 1213 |
| 1189 return dbl.raw(); | 1214 return dbl.raw(); |
| 1190 } | 1215 } |
| 1191 | 1216 |
| 1192 | 1217 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1216 | 1241 |
| 1217 | 1242 |
| 1218 void RawString::WriteTo(SnapshotWriter* writer, | 1243 void RawString::WriteTo(SnapshotWriter* writer, |
| 1219 intptr_t object_id, | 1244 intptr_t object_id, |
| 1220 Snapshot::Kind kind) { | 1245 Snapshot::Kind kind) { |
| 1221 UNREACHABLE(); // String is an abstract class. | 1246 UNREACHABLE(); // String is an abstract class. |
| 1222 } | 1247 } |
| 1223 | 1248 |
| 1224 | 1249 |
| 1225 template<typename HandleType, typename CharacterType> | 1250 template<typename HandleType, typename CharacterType> |
| 1226 RawString* String::ReadFromImpl(SnapshotReader* reader, | 1251 void String::ReadFromImpl(SnapshotReader* reader, |
| 1227 intptr_t object_id, | 1252 HandleType* str_obj, |
| 1228 intptr_t tags, | 1253 intptr_t len, |
| 1229 Snapshot::Kind kind) { | 1254 intptr_t hash, |
| 1255 intptr_t tags) { | |
| 1230 ASSERT(reader != NULL); | 1256 ASSERT(reader != NULL); |
| 1231 // Read the length so that we can determine instance size to allocate. | 1257 if (RawObject::IsCanonical(tags)) { |
| 1232 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); | 1258 // Set up canonical string object. |
| 1233 intptr_t len = Smi::Value(smi_len); | 1259 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)); | 1260 CharacterType* ptr = reinterpret_cast<CharacterType*>(ZoneAllocator(len)); |
| 1240 for (intptr_t i = 0; i < len; i++) { | 1261 for (intptr_t i = 0; i < len; i++) { |
| 1241 ptr[i] = reader->Read<CharacterType>(); | 1262 ptr[i] = reader->Read<CharacterType>(); |
| 1242 } | 1263 } |
| 1243 str_obj ^= String::NewSymbol(ptr, len); | 1264 *str_obj ^= String::NewSymbol(ptr, len); |
| 1244 } else { | 1265 } else { |
| 1245 // Set up the string object. | 1266 // Set up the string object. |
| 1246 str_obj = HandleType::New( | 1267 *str_obj = HandleType::New(len, Heap::kNew); |
| 1247 len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew); | 1268 str_obj->set_tags(tags); |
| 1269 str_obj->SetHash(hash); | |
|
Ivan Posva
2012/01/16 19:30:33
The hash should be calculated as the string is des
siva
2012/01/18 00:00:24
In this case I will set the hash value to 0 so tha
| |
| 1248 for (intptr_t i = 0; i < len; i++) { | 1270 for (intptr_t i = 0; i < len; i++) { |
| 1249 *str_obj.CharAddr(i) = reader->Read<CharacterType>(); | 1271 *str_obj->CharAddr(i) = reader->Read<CharacterType>(); |
| 1250 } | 1272 } |
| 1251 str_obj.set_tags(tags); | |
| 1252 str_obj.SetHash(Smi::Value(smi_hash)); | |
| 1253 } | 1273 } |
| 1254 reader->AddBackwardReference(object_id, &str_obj); | |
| 1255 | |
| 1256 return str_obj.raw(); | |
| 1257 } | 1274 } |
| 1258 | 1275 |
| 1259 | 1276 |
| 1260 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1277 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
| 1261 intptr_t object_id, | 1278 intptr_t object_id, |
| 1262 intptr_t tags, | 1279 intptr_t tags, |
| 1263 Snapshot::Kind kind) { | 1280 Snapshot::Kind kind) { |
| 1264 return static_cast<RawOneByteString*>( | 1281 // Read the length so that we can determine instance size to allocate. |
| 1265 ReadFromImpl<OneByteString, uint8_t>(reader, object_id, tags, kind)); | 1282 ASSERT(reader != NULL); |
| 1283 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); | |
| 1284 intptr_t hash = GetSmiValue(reader->ReadIntptrValue()); | |
| 1285 OneByteString& str_obj = OneByteString::ZoneHandle(reader->isolate(), | |
| 1286 OneByteString::null()); | |
| 1287 | |
| 1288 if (kind == Snapshot::kFull) { | |
| 1289 reader->NewOneByteString(&str_obj, len); | |
| 1290 str_obj.set_tags(tags); | |
| 1291 str_obj.SetHash(hash); | |
|
Ivan Posva
2012/01/16 19:30:33
ditto for hash calculation: Recalculate during the
siva
2012/01/18 00:00:24
In the full snapshot case I added an ASSERT to
ens
| |
| 1292 for (intptr_t i = 0; i < len; i++) { | |
|
Ivan Posva
2012/01/16 19:30:33
ASSERT(*str_obj.CharAddr(i) != NULL);
and avoid th
siva
2012/01/18 00:00:24
Done.
| |
| 1293 *str_obj.CharAddr(i) = reader->Read<uint8_t>(); | |
| 1294 } | |
| 1295 } else { | |
| 1296 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, hash, tags); | |
| 1297 } | |
| 1298 reader->AddBackwardReference(object_id, &str_obj); | |
| 1299 return str_obj.raw(); | |
| 1266 } | 1300 } |
| 1267 | 1301 |
| 1268 | 1302 |
| 1269 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1303 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1270 intptr_t object_id, | 1304 intptr_t object_id, |
| 1271 intptr_t tags, | 1305 intptr_t tags, |
| 1272 Snapshot::Kind kind) { | 1306 Snapshot::Kind kind) { |
| 1273 return static_cast<RawTwoByteString*>( | 1307 // Read the length so that we can determine instance size to allocate. |
| 1274 ReadFromImpl<TwoByteString, uint16_t>(reader, object_id, tags, kind)); | 1308 ASSERT(reader != NULL); |
| 1309 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); | |
| 1310 intptr_t hash = GetSmiValue(reader->ReadIntptrValue()); | |
| 1311 TwoByteString& str_obj = TwoByteString::ZoneHandle(reader->isolate(), | |
| 1312 TwoByteString::null()); | |
| 1313 | |
| 1314 if (kind == Snapshot::kFull) { | |
| 1315 reader->NewTwoByteString(&str_obj, len); | |
| 1316 str_obj.set_tags(tags); | |
| 1317 str_obj.SetHash(hash); | |
| 1318 for (intptr_t i = 0; i < len; i++) { | |
| 1319 *str_obj.CharAddr(i) = reader->Read<uint16_t>(); | |
| 1320 } | |
| 1321 } else { | |
| 1322 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, hash, tags); | |
| 1323 } | |
| 1324 reader->AddBackwardReference(object_id, &str_obj); | |
| 1325 return str_obj.raw(); | |
| 1275 } | 1326 } |
| 1276 | 1327 |
| 1277 | 1328 |
| 1278 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | 1329 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, |
| 1279 intptr_t object_id, | 1330 intptr_t object_id, |
| 1280 intptr_t tags, | 1331 intptr_t tags, |
| 1281 Snapshot::Kind kind) { | 1332 Snapshot::Kind kind) { |
| 1282 return static_cast<RawFourByteString*>( | 1333 // Read the length so that we can determine instance size to allocate. |
| 1283 ReadFromImpl<FourByteString, uint32_t>(reader, object_id, tags, kind)); | 1334 ASSERT(reader != NULL); |
| 1335 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); | |
| 1336 intptr_t hash = GetSmiValue(reader->ReadIntptrValue()); | |
| 1337 FourByteString& str_obj = FourByteString::ZoneHandle(reader->isolate(), | |
| 1338 FourByteString::null()); | |
| 1339 | |
| 1340 if (kind == Snapshot::kFull) { | |
| 1341 reader->NewFourByteString(&str_obj, len); | |
| 1342 str_obj.set_tags(tags); | |
| 1343 str_obj.SetHash(hash); | |
| 1344 for (intptr_t i = 0; i < len; i++) { | |
| 1345 *str_obj.CharAddr(i) = reader->Read<uint32_t>(); | |
| 1346 } | |
| 1347 } else { | |
| 1348 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, hash, tags); | |
| 1349 } | |
| 1350 reader->AddBackwardReference(object_id, &str_obj); | |
| 1351 return str_obj.raw(); | |
| 1284 } | 1352 } |
| 1285 | 1353 |
| 1286 | 1354 |
| 1287 template<typename T> | 1355 template<typename T> |
| 1288 static void StringWriteTo(SnapshotWriter* writer, | 1356 static void StringWriteTo(SnapshotWriter* writer, |
| 1289 intptr_t object_id, | 1357 intptr_t object_id, |
| 1290 Snapshot::Kind kind, | 1358 Snapshot::Kind kind, |
| 1291 intptr_t class_id, | 1359 intptr_t class_id, |
| 1292 intptr_t tags, | 1360 intptr_t tags, |
| 1293 RawSmi* length, | 1361 RawSmi* length, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1441 } | 1509 } |
| 1442 | 1510 |
| 1443 | 1511 |
| 1444 void RawBool::WriteTo(SnapshotWriter* writer, | 1512 void RawBool::WriteTo(SnapshotWriter* writer, |
| 1445 intptr_t object_id, | 1513 intptr_t object_id, |
| 1446 Snapshot::Kind kind) { | 1514 Snapshot::Kind kind) { |
| 1447 UNREACHABLE(); | 1515 UNREACHABLE(); |
| 1448 } | 1516 } |
| 1449 | 1517 |
| 1450 | 1518 |
| 1451 template <class T> | 1519 static void ArrayReadFrom(SnapshotReader* reader, |
| 1452 static RawObject* ArrayReadFrom(SnapshotReader* reader, | 1520 const Array& result, |
| 1453 intptr_t object_id, | 1521 intptr_t len, |
| 1454 intptr_t tags, | 1522 intptr_t tags) { |
| 1455 Snapshot::Kind kind) { | |
| 1456 ASSERT(reader != NULL); | 1523 ASSERT(reader != NULL); |
| 1457 | 1524 |
| 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. | 1525 // Set the object tags. |
| 1467 result.set_tags(tags); | 1526 result.set_tags(tags); |
| 1468 | 1527 |
| 1469 // Setup the object fields. | 1528 // Setup the object fields. |
| 1470 *reader->TypeArgumentsHandle() ^= reader->ReadObject(); | 1529 *reader->TypeArgumentsHandle() ^= reader->ReadObject(); |
| 1471 result.SetTypeArguments(*reader->TypeArgumentsHandle()); | 1530 result.SetTypeArguments(*reader->TypeArgumentsHandle()); |
| 1472 | 1531 |
| 1473 for (intptr_t i = 0; i < len; i++) { | 1532 for (intptr_t i = 0; i < len; i++) { |
| 1474 *reader->ObjectHandle() = reader->ReadObject(); | 1533 *reader->ObjectHandle() = reader->ReadObject(); |
| 1475 result.SetAt(i, *reader->ObjectHandle()); | 1534 result.SetAt(i, *reader->ObjectHandle()); |
| 1476 } | 1535 } |
| 1477 return result.raw(); | |
| 1478 } | 1536 } |
| 1479 | 1537 |
| 1480 | 1538 |
| 1481 RawArray* Array::ReadFrom(SnapshotReader* reader, | 1539 RawArray* Array::ReadFrom(SnapshotReader* reader, |
| 1482 intptr_t object_id, | 1540 intptr_t object_id, |
| 1483 intptr_t tags, | 1541 intptr_t tags, |
| 1484 Snapshot::Kind kind) { | 1542 Snapshot::Kind kind) { |
| 1485 return reinterpret_cast<RawArray*>( | 1543 ASSERT(reader != NULL); |
| 1486 ArrayReadFrom<Array>(reader, object_id, tags, kind)); | 1544 |
| 1545 // Read the length so that we can determine instance size to allocate. | |
| 1546 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); | |
| 1547 Array& array = Array::ZoneHandle(reader->isolate(), Array::null()); | |
| 1548 if (kind == Snapshot::kFull) { | |
| 1549 reader->NewArray(&array, len); | |
| 1550 } else { | |
| 1551 array = Array::New(len, Heap::kNew); | |
| 1552 } | |
| 1553 reader->AddBackwardReference(object_id, &array); | |
| 1554 ArrayReadFrom(reader, array, len, tags); | |
| 1555 return array.raw(); | |
| 1487 } | 1556 } |
| 1488 | 1557 |
| 1489 | 1558 |
| 1490 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, | 1559 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, |
| 1491 intptr_t object_id, | 1560 intptr_t object_id, |
| 1492 intptr_t tags, | 1561 intptr_t tags, |
| 1493 Snapshot::Kind kind) { | 1562 Snapshot::Kind kind) { |
| 1494 return reinterpret_cast<RawImmutableArray*>( | 1563 ASSERT(reader != NULL); |
| 1495 ArrayReadFrom<ImmutableArray>(reader, object_id, tags, kind)); | 1564 |
| 1565 // Read the length so that we can determine instance size to allocate. | |
| 1566 intptr_t len = GetSmiValue(reader->ReadIntptrValue()); | |
| 1567 ImmutableArray& array = ImmutableArray::ZoneHandle(reader->isolate(), | |
| 1568 ImmutableArray::null()); | |
| 1569 if (kind == Snapshot::kFull) { | |
| 1570 reader->NewImmutableArray(&array, len); | |
| 1571 } else { | |
| 1572 array = ImmutableArray::New(len, Heap::kNew); | |
| 1573 } | |
| 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 |