| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/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/symbols.h" | 9 #include "vm/symbols.h" |
| 10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 SnapshotWriterVisitor visitor(writer); | 566 SnapshotWriterVisitor visitor(writer); |
| 567 visitor.VisitPointers(from(), to()); | 567 visitor.VisitPointers(from(), to()); |
| 568 } | 568 } |
| 569 | 569 |
| 570 | 570 |
| 571 RawPatchClass* PatchClass::ReadFrom(SnapshotReader* reader, | 571 RawPatchClass* PatchClass::ReadFrom(SnapshotReader* reader, |
| 572 intptr_t object_id, | 572 intptr_t object_id, |
| 573 intptr_t tags, | 573 intptr_t tags, |
| 574 Snapshot::Kind kind) { | 574 Snapshot::Kind kind) { |
| 575 ASSERT(reader != NULL); | 575 ASSERT(reader != NULL); |
| 576 ASSERT((kind != Snapshot::kMessage) && | 576 ASSERT(((kind == Snapshot::kScript) && |
| 577 !RawObject::IsCreatedFromSnapshot(tags)); | 577 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 578 (kind == Snapshot::kFull)); |
| 578 | 579 |
| 579 // Allocate function object. | 580 // Allocate function object. |
| 580 PatchClass& cls = PatchClass::ZoneHandle(reader->isolate(), | 581 PatchClass& cls = PatchClass::ZoneHandle(reader->isolate(), |
| 581 NEW_OBJECT(PatchClass)); | 582 NEW_OBJECT(PatchClass)); |
| 582 reader->AddBackRef(object_id, &cls, kIsDeserialized); | 583 reader->AddBackRef(object_id, &cls, kIsDeserialized); |
| 583 | 584 |
| 584 // Set the object tags. | 585 // Set the object tags. |
| 585 cls.set_tags(tags); | 586 cls.set_tags(tags); |
| 586 | 587 |
| 587 // Set all the object fields. | 588 // Set all the object fields. |
| 588 // TODO(5411462): Need to assert No GC can happen here, even though | 589 // TODO(5411462): Need to assert No GC can happen here, even though |
| 589 // allocations may happen. | 590 // allocations may happen. |
| 590 intptr_t num_flds = (cls.raw()->to() - cls.raw()->from()); | 591 intptr_t num_flds = (cls.raw()->to() - cls.raw()->from()); |
| 591 for (intptr_t i = 0; i <= num_flds; i++) { | 592 for (intptr_t i = 0; i <= num_flds; i++) { |
| 592 *(cls.raw()->from() + i) = reader->ReadObjectRef(); | 593 *(cls.raw()->from() + i) = reader->ReadObjectRef(); |
| 593 } | 594 } |
| 594 | 595 |
| 595 return cls.raw(); | 596 return cls.raw(); |
| 596 } | 597 } |
| 597 | 598 |
| 598 | 599 |
| 599 void RawPatchClass::WriteTo(SnapshotWriter* writer, | 600 void RawPatchClass::WriteTo(SnapshotWriter* writer, |
| 600 intptr_t object_id, | 601 intptr_t object_id, |
| 601 Snapshot::Kind kind) { | 602 Snapshot::Kind kind) { |
| 602 ASSERT(writer != NULL); | 603 ASSERT(writer != NULL); |
| 603 ASSERT((kind != Snapshot::kMessage) && | 604 ASSERT(((kind == Snapshot::kScript) && |
| 604 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 605 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 606 (kind == Snapshot::kFull)); |
| 605 | 607 |
| 606 // Write out the serialization header value for this object. | 608 // Write out the serialization header value for this object. |
| 607 writer->WriteInlinedObjectHeader(object_id); | 609 writer->WriteInlinedObjectHeader(object_id); |
| 608 | 610 |
| 609 // Write out the class and tags information. | 611 // Write out the class and tags information. |
| 610 writer->WriteVMIsolateObject(kPatchClassCid); | 612 writer->WriteVMIsolateObject(kPatchClassCid); |
| 611 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 613 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 612 // Write out all the object pointer fields. | 614 // Write out all the object pointer fields. |
| 613 SnapshotWriterVisitor visitor(writer); | 615 SnapshotWriterVisitor visitor(writer); |
| 614 visitor.VisitPointers(from(), to()); | 616 visitor.VisitPointers(from(), to()); |
| 615 } | 617 } |
| 616 | 618 |
| 617 | 619 |
| 618 RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader, | 620 RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader, |
| 619 intptr_t object_id, | 621 intptr_t object_id, |
| 620 intptr_t tags, | 622 intptr_t tags, |
| 621 Snapshot::Kind kind) { | 623 Snapshot::Kind kind) { |
| 622 ASSERT(reader != NULL); | 624 ASSERT(reader != NULL); |
| 623 ASSERT((kind != Snapshot::kMessage) && | 625 ASSERT(((kind == Snapshot::kScript) && |
| 624 !RawObject::IsCreatedFromSnapshot(tags)); | 626 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 627 (kind == Snapshot::kFull)); |
| 625 | 628 |
| 626 // Allocate closure data object. | 629 // Allocate closure data object. |
| 627 ClosureData& data = ClosureData::ZoneHandle( | 630 ClosureData& data = ClosureData::ZoneHandle( |
| 628 reader->isolate(), NEW_OBJECT(ClosureData)); | 631 reader->isolate(), NEW_OBJECT(ClosureData)); |
| 629 reader->AddBackRef(object_id, &data, kIsDeserialized); | 632 reader->AddBackRef(object_id, &data, kIsDeserialized); |
| 630 | 633 |
| 631 // Set the object tags. | 634 // Set the object tags. |
| 632 data.set_tags(tags); | 635 data.set_tags(tags); |
| 633 | 636 |
| 634 // Set all the object fields. | 637 // Set all the object fields. |
| 635 // TODO(5411462): Need to assert No GC can happen here, even though | 638 // TODO(5411462): Need to assert No GC can happen here, even though |
| 636 // allocations may happen. | 639 // allocations may happen. |
| 637 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); | 640 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); |
| 638 for (intptr_t i = 0; i <= num_flds; i++) { | 641 for (intptr_t i = 0; i <= num_flds; i++) { |
| 639 *(data.raw()->from() + i) = reader->ReadObjectRef(); | 642 *(data.raw()->from() + i) = reader->ReadObjectRef(); |
| 640 } | 643 } |
| 641 | 644 |
| 642 return data.raw(); | 645 return data.raw(); |
| 643 } | 646 } |
| 644 | 647 |
| 645 | 648 |
| 646 void RawClosureData::WriteTo(SnapshotWriter* writer, | 649 void RawClosureData::WriteTo(SnapshotWriter* writer, |
| 647 intptr_t object_id, | 650 intptr_t object_id, |
| 648 Snapshot::Kind kind) { | 651 Snapshot::Kind kind) { |
| 649 ASSERT(writer != NULL); | 652 ASSERT(writer != NULL); |
| 650 ASSERT((kind != Snapshot::kMessage) && | 653 ASSERT(((kind == Snapshot::kScript) && |
| 651 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 654 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 655 (kind == Snapshot::kFull)); |
| 652 | 656 |
| 653 // Write out the serialization header value for this object. | 657 // Write out the serialization header value for this object. |
| 654 writer->WriteInlinedObjectHeader(object_id); | 658 writer->WriteInlinedObjectHeader(object_id); |
| 655 | 659 |
| 656 // Write out the class and tags information. | 660 // Write out the class and tags information. |
| 657 writer->WriteVMIsolateObject(kClosureDataCid); | 661 writer->WriteVMIsolateObject(kClosureDataCid); |
| 658 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 662 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 659 | 663 |
| 660 // Context scope. | 664 // Context scope. |
| 661 // We don't write the context scope in the snapshot. | 665 // We don't write the context scope in the snapshot. |
| 662 writer->WriteObjectImpl(Object::null()); | 666 writer->WriteObjectImpl(Object::null()); |
| 663 | 667 |
| 664 // Parent function. | 668 // Parent function. |
| 665 writer->WriteObjectImpl(ptr()->parent_function_); | 669 writer->WriteObjectImpl(ptr()->parent_function_); |
| 666 | 670 |
| 667 // Signature class. | 671 // Signature class. |
| 668 writer->WriteObjectImpl(ptr()->signature_class_); | 672 writer->WriteObjectImpl(ptr()->signature_class_); |
| 669 | 673 |
| 670 // Static closure/Closure allocation stub. | 674 // Static closure/Closure allocation stub. |
| 671 // We don't write the closure or allocation stub in the snapshot. | 675 // We don't write the closure or allocation stub in the snapshot. |
| 672 writer->WriteObjectImpl(Object::null()); | 676 writer->WriteObjectImpl(Object::null()); |
| 673 } | 677 } |
| 674 | 678 |
| 675 | 679 |
| 676 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, | 680 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, |
| 677 intptr_t object_id, | 681 intptr_t object_id, |
| 678 intptr_t tags, | 682 intptr_t tags, |
| 679 Snapshot::Kind kind) { | 683 Snapshot::Kind kind) { |
| 680 ASSERT(reader != NULL); | 684 ASSERT(reader != NULL); |
| 681 ASSERT((kind != Snapshot::kMessage) && | 685 ASSERT(((kind == Snapshot::kScript) && |
| 682 !RawObject::IsCreatedFromSnapshot(tags)); | 686 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 687 (kind == Snapshot::kFull)); |
| 683 | 688 |
| 684 // Allocate redirection data object. | 689 // Allocate redirection data object. |
| 685 RedirectionData& data = RedirectionData::ZoneHandle( | 690 RedirectionData& data = RedirectionData::ZoneHandle( |
| 686 reader->isolate(), NEW_OBJECT(RedirectionData)); | 691 reader->isolate(), NEW_OBJECT(RedirectionData)); |
| 687 reader->AddBackRef(object_id, &data, kIsDeserialized); | 692 reader->AddBackRef(object_id, &data, kIsDeserialized); |
| 688 | 693 |
| 689 // Set the object tags. | 694 // Set the object tags. |
| 690 data.set_tags(tags); | 695 data.set_tags(tags); |
| 691 | 696 |
| 692 // Set all the object fields. | 697 // Set all the object fields. |
| 693 // TODO(5411462): Need to assert No GC can happen here, even though | 698 // TODO(5411462): Need to assert No GC can happen here, even though |
| 694 // allocations may happen. | 699 // allocations may happen. |
| 695 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); | 700 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); |
| 696 for (intptr_t i = 0; i <= num_flds; i++) { | 701 for (intptr_t i = 0; i <= num_flds; i++) { |
| 697 *(data.raw()->from() + i) = reader->ReadObjectRef(); | 702 *(data.raw()->from() + i) = reader->ReadObjectRef(); |
| 698 } | 703 } |
| 699 | 704 |
| 700 return data.raw(); | 705 return data.raw(); |
| 701 } | 706 } |
| 702 | 707 |
| 703 | 708 |
| 704 void RawRedirectionData::WriteTo(SnapshotWriter* writer, | 709 void RawRedirectionData::WriteTo(SnapshotWriter* writer, |
| 705 intptr_t object_id, | 710 intptr_t object_id, |
| 706 Snapshot::Kind kind) { | 711 Snapshot::Kind kind) { |
| 707 ASSERT(writer != NULL); | 712 ASSERT(writer != NULL); |
| 708 ASSERT((kind != Snapshot::kMessage) && | 713 ASSERT(((kind == Snapshot::kScript) && |
| 709 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 714 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 715 (kind == Snapshot::kFull)); |
| 710 | 716 |
| 711 // Write out the serialization header value for this object. | 717 // Write out the serialization header value for this object. |
| 712 writer->WriteInlinedObjectHeader(object_id); | 718 writer->WriteInlinedObjectHeader(object_id); |
| 713 | 719 |
| 714 // Write out the class and tags information. | 720 // Write out the class and tags information. |
| 715 writer->WriteVMIsolateObject(kRedirectionDataCid); | 721 writer->WriteVMIsolateObject(kRedirectionDataCid); |
| 716 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 722 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 717 | 723 |
| 718 // Write out all the object pointer fields. | 724 // Write out all the object pointer fields. |
| 719 SnapshotWriterVisitor visitor(writer); | 725 SnapshotWriterVisitor visitor(writer); |
| 720 visitor.VisitPointers(from(), to()); | 726 visitor.VisitPointers(from(), to()); |
| 721 } | 727 } |
| 722 | 728 |
| 723 | 729 |
| 724 RawFunction* Function::ReadFrom(SnapshotReader* reader, | 730 RawFunction* Function::ReadFrom(SnapshotReader* reader, |
| 725 intptr_t object_id, | 731 intptr_t object_id, |
| 726 intptr_t tags, | 732 intptr_t tags, |
| 727 Snapshot::Kind kind) { | 733 Snapshot::Kind kind) { |
| 728 ASSERT(reader != NULL); | 734 ASSERT(reader != NULL); |
| 729 ASSERT((kind != Snapshot::kMessage) && | 735 ASSERT(((kind == Snapshot::kScript) && |
| 730 !RawObject::IsCreatedFromSnapshot(tags)); | 736 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 737 (kind == Snapshot::kFull)); |
| 731 | 738 |
| 732 // Allocate function object. | 739 // Allocate function object. |
| 733 Function& func = Function::ZoneHandle( | 740 Function& func = Function::ZoneHandle( |
| 734 reader->isolate(), NEW_OBJECT(Function)); | 741 reader->isolate(), NEW_OBJECT(Function)); |
| 735 reader->AddBackRef(object_id, &func, kIsDeserialized); | 742 reader->AddBackRef(object_id, &func, kIsDeserialized); |
| 736 | 743 |
| 737 // Set the object tags. | 744 // Set the object tags. |
| 738 func.set_tags(tags); | 745 func.set_tags(tags); |
| 739 | 746 |
| 740 // Set all the non object fields. | 747 // Set all the non object fields. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 757 } | 764 } |
| 758 | 765 |
| 759 return func.raw(); | 766 return func.raw(); |
| 760 } | 767 } |
| 761 | 768 |
| 762 | 769 |
| 763 void RawFunction::WriteTo(SnapshotWriter* writer, | 770 void RawFunction::WriteTo(SnapshotWriter* writer, |
| 764 intptr_t object_id, | 771 intptr_t object_id, |
| 765 Snapshot::Kind kind) { | 772 Snapshot::Kind kind) { |
| 766 ASSERT(writer != NULL); | 773 ASSERT(writer != NULL); |
| 767 ASSERT((kind != Snapshot::kMessage) && | 774 ASSERT(((kind == Snapshot::kScript) && |
| 768 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 775 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 776 (kind == Snapshot::kFull)); |
| 769 | 777 |
| 770 // Write out the serialization header value for this object. | 778 // Write out the serialization header value for this object. |
| 771 writer->WriteInlinedObjectHeader(object_id); | 779 writer->WriteInlinedObjectHeader(object_id); |
| 772 | 780 |
| 773 // Write out the class and tags information. | 781 // Write out the class and tags information. |
| 774 writer->WriteVMIsolateObject(kFunctionCid); | 782 writer->WriteVMIsolateObject(kFunctionCid); |
| 775 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 783 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 776 | 784 |
| 777 // Write out all the non object fields. | 785 // Write out all the non object fields. |
| 778 writer->WriteIntptrValue(ptr()->token_pos_); | 786 writer->WriteIntptrValue(ptr()->token_pos_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 789 SnapshotWriterVisitor visitor(writer); | 797 SnapshotWriterVisitor visitor(writer); |
| 790 visitor.VisitPointers(from(), to()); | 798 visitor.VisitPointers(from(), to()); |
| 791 } | 799 } |
| 792 | 800 |
| 793 | 801 |
| 794 RawField* Field::ReadFrom(SnapshotReader* reader, | 802 RawField* Field::ReadFrom(SnapshotReader* reader, |
| 795 intptr_t object_id, | 803 intptr_t object_id, |
| 796 intptr_t tags, | 804 intptr_t tags, |
| 797 Snapshot::Kind kind) { | 805 Snapshot::Kind kind) { |
| 798 ASSERT(reader != NULL); | 806 ASSERT(reader != NULL); |
| 799 ASSERT((kind != Snapshot::kMessage) && | 807 ASSERT(((kind == Snapshot::kScript) && |
| 800 !RawObject::IsCreatedFromSnapshot(tags)); | 808 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 809 (kind == Snapshot::kFull)); |
| 801 | 810 |
| 802 // Allocate field object. | 811 // Allocate field object. |
| 803 Field& field = Field::ZoneHandle(reader->isolate(), NEW_OBJECT(Field)); | 812 Field& field = Field::ZoneHandle(reader->isolate(), NEW_OBJECT(Field)); |
| 804 reader->AddBackRef(object_id, &field, kIsDeserialized); | 813 reader->AddBackRef(object_id, &field, kIsDeserialized); |
| 805 | 814 |
| 806 // Set the object tags. | 815 // Set the object tags. |
| 807 field.set_tags(tags); | 816 field.set_tags(tags); |
| 808 | 817 |
| 809 // Set all non object fields. | 818 // Set all non object fields. |
| 810 field.set_token_pos(reader->ReadIntptrValue()); | 819 field.set_token_pos(reader->ReadIntptrValue()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 821 } | 830 } |
| 822 | 831 |
| 823 return field.raw(); | 832 return field.raw(); |
| 824 } | 833 } |
| 825 | 834 |
| 826 | 835 |
| 827 void RawField::WriteTo(SnapshotWriter* writer, | 836 void RawField::WriteTo(SnapshotWriter* writer, |
| 828 intptr_t object_id, | 837 intptr_t object_id, |
| 829 Snapshot::Kind kind) { | 838 Snapshot::Kind kind) { |
| 830 ASSERT(writer != NULL); | 839 ASSERT(writer != NULL); |
| 831 ASSERT((kind != Snapshot::kMessage) && | 840 ASSERT(((kind == Snapshot::kScript) && |
| 832 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 841 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 842 (kind == Snapshot::kFull)); |
| 833 | 843 |
| 834 // Write out the serialization header value for this object. | 844 // Write out the serialization header value for this object. |
| 835 writer->WriteInlinedObjectHeader(object_id); | 845 writer->WriteInlinedObjectHeader(object_id); |
| 836 | 846 |
| 837 // Write out the class and tags information. | 847 // Write out the class and tags information. |
| 838 writer->WriteVMIsolateObject(kFieldCid); | 848 writer->WriteVMIsolateObject(kFieldCid); |
| 839 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 849 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 840 | 850 |
| 841 // Write out all the non object fields. | 851 // Write out all the non object fields. |
| 842 writer->WriteIntptrValue(ptr()->token_pos_); | 852 writer->WriteIntptrValue(ptr()->token_pos_); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 writer->WriteObjectImpl(ptr()->literal_); | 907 writer->WriteObjectImpl(ptr()->literal_); |
| 898 writer->WriteObjectImpl(ptr()->value_); | 908 writer->WriteObjectImpl(ptr()->value_); |
| 899 } | 909 } |
| 900 | 910 |
| 901 | 911 |
| 902 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, | 912 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, |
| 903 intptr_t object_id, | 913 intptr_t object_id, |
| 904 intptr_t tags, | 914 intptr_t tags, |
| 905 Snapshot::Kind kind) { | 915 Snapshot::Kind kind) { |
| 906 ASSERT(reader != NULL); | 916 ASSERT(reader != NULL); |
| 907 ASSERT((kind != Snapshot::kMessage) | 917 ASSERT(((kind == Snapshot::kScript) && |
| 908 && !RawObject::IsCreatedFromSnapshot(tags)); | 918 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 919 (kind == Snapshot::kFull)); |
| 909 | 920 |
| 910 // Read the length so that we can determine number of tokens to read. | 921 // Read the length so that we can determine number of tokens to read. |
| 911 intptr_t len = reader->ReadSmiValue(); | 922 intptr_t len = reader->ReadSmiValue(); |
| 912 | 923 |
| 913 // Create the token stream object. | 924 // Create the token stream object. |
| 914 TokenStream& token_stream = TokenStream::ZoneHandle( | 925 TokenStream& token_stream = TokenStream::ZoneHandle( |
| 915 reader->isolate(), NEW_OBJECT_WITH_LEN(TokenStream, len)); | 926 reader->isolate(), NEW_OBJECT_WITH_LEN(TokenStream, len)); |
| 916 reader->AddBackRef(object_id, &token_stream, kIsDeserialized); | 927 reader->AddBackRef(object_id, &token_stream, kIsDeserialized); |
| 917 | 928 |
| 918 // Set the object tags. | 929 // Set the object tags. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 934 token_stream.SetPrivateKey(*(reader->StringHandle())); | 945 token_stream.SetPrivateKey(*(reader->StringHandle())); |
| 935 | 946 |
| 936 return token_stream.raw(); | 947 return token_stream.raw(); |
| 937 } | 948 } |
| 938 | 949 |
| 939 | 950 |
| 940 void RawTokenStream::WriteTo(SnapshotWriter* writer, | 951 void RawTokenStream::WriteTo(SnapshotWriter* writer, |
| 941 intptr_t object_id, | 952 intptr_t object_id, |
| 942 Snapshot::Kind kind) { | 953 Snapshot::Kind kind) { |
| 943 ASSERT(writer != NULL); | 954 ASSERT(writer != NULL); |
| 944 ASSERT((kind != Snapshot::kMessage) && | 955 ASSERT(((kind == Snapshot::kScript) && |
| 945 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 956 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 957 (kind == Snapshot::kFull)); |
| 946 | 958 |
| 947 // Write out the serialization header value for this object. | 959 // Write out the serialization header value for this object. |
| 948 writer->WriteInlinedObjectHeader(object_id); | 960 writer->WriteInlinedObjectHeader(object_id); |
| 949 | 961 |
| 950 // Write out the class and tags information. | 962 // Write out the class and tags information. |
| 951 writer->WriteVMIsolateObject(kTokenStreamCid); | 963 writer->WriteVMIsolateObject(kTokenStreamCid); |
| 952 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 964 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 953 | 965 |
| 954 // Write out the length field and the token stream. | 966 // Write out the length field and the token stream. |
| 955 RawExternalTypedData* stream = ptr()->stream_; | 967 RawExternalTypedData* stream = ptr()->stream_; |
| 956 intptr_t len = Smi::Value(stream->ptr()->length_); | 968 intptr_t len = Smi::Value(stream->ptr()->length_); |
| 957 writer->Write<RawObject*>(stream->ptr()->length_); | 969 writer->Write<RawObject*>(stream->ptr()->length_); |
| 958 writer->WriteBytes(stream->ptr()->data_, len); | 970 writer->WriteBytes(stream->ptr()->data_, len); |
| 959 | 971 |
| 960 // Write out the literal/identifier token array. | 972 // Write out the literal/identifier token array. |
| 961 writer->WriteObjectImpl(ptr()->token_objects_); | 973 writer->WriteObjectImpl(ptr()->token_objects_); |
| 962 // Write out the private key in use by the token stream. | 974 // Write out the private key in use by the token stream. |
| 963 writer->WriteObjectImpl(ptr()->private_key_); | 975 writer->WriteObjectImpl(ptr()->private_key_); |
| 964 } | 976 } |
| 965 | 977 |
| 966 | 978 |
| 967 RawScript* Script::ReadFrom(SnapshotReader* reader, | 979 RawScript* Script::ReadFrom(SnapshotReader* reader, |
| 968 intptr_t object_id, | 980 intptr_t object_id, |
| 969 intptr_t tags, | 981 intptr_t tags, |
| 970 Snapshot::Kind kind) { | 982 Snapshot::Kind kind) { |
| 971 ASSERT(reader != NULL); | 983 ASSERT(reader != NULL); |
| 972 ASSERT((kind != Snapshot::kMessage) && | 984 ASSERT(((kind == Snapshot::kScript) && |
| 973 !RawObject::IsCreatedFromSnapshot(tags)); | 985 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 986 (kind == Snapshot::kFull)); |
| 974 | 987 |
| 975 // Allocate script object. | 988 // Allocate script object. |
| 976 Script& script = Script::ZoneHandle(reader->isolate(), NEW_OBJECT(Script)); | 989 Script& script = Script::ZoneHandle(reader->isolate(), NEW_OBJECT(Script)); |
| 977 reader->AddBackRef(object_id, &script, kIsDeserialized); | 990 reader->AddBackRef(object_id, &script, kIsDeserialized); |
| 978 | 991 |
| 979 // Set the object tags. | 992 // Set the object tags. |
| 980 script.set_tags(tags); | 993 script.set_tags(tags); |
| 981 | 994 |
| 982 // Set all the object fields. | 995 // Set all the object fields. |
| 983 // TODO(5411462): Need to assert No GC can happen here, even though | 996 // TODO(5411462): Need to assert No GC can happen here, even though |
| (...skipping 12 matching lines...) Expand all Loading... |
| 996 | 1009 |
| 997 return script.raw(); | 1010 return script.raw(); |
| 998 } | 1011 } |
| 999 | 1012 |
| 1000 | 1013 |
| 1001 void RawScript::WriteTo(SnapshotWriter* writer, | 1014 void RawScript::WriteTo(SnapshotWriter* writer, |
| 1002 intptr_t object_id, | 1015 intptr_t object_id, |
| 1003 Snapshot::Kind kind) { | 1016 Snapshot::Kind kind) { |
| 1004 ASSERT(writer != NULL); | 1017 ASSERT(writer != NULL); |
| 1005 ASSERT(tokens_ != TokenStream::null()); | 1018 ASSERT(tokens_ != TokenStream::null()); |
| 1006 ASSERT((kind != Snapshot::kMessage) && | 1019 ASSERT(((kind == Snapshot::kScript) && |
| 1007 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 1020 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 1021 (kind == Snapshot::kFull)); |
| 1008 | 1022 |
| 1009 // Write out the serialization header value for this object. | 1023 // Write out the serialization header value for this object. |
| 1010 writer->WriteInlinedObjectHeader(object_id); | 1024 writer->WriteInlinedObjectHeader(object_id); |
| 1011 | 1025 |
| 1012 // Write out the class and tags information. | 1026 // Write out the class and tags information. |
| 1013 writer->WriteVMIsolateObject(kScriptCid); | 1027 writer->WriteVMIsolateObject(kScriptCid); |
| 1014 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 1028 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 1015 | 1029 |
| 1016 // Write out all the object pointer fields. | 1030 // Write out all the object pointer fields. |
| 1017 writer->WriteObjectImpl(ptr()->url_); | 1031 writer->WriteObjectImpl(ptr()->url_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 ASSERT(writer != NULL); | 1095 ASSERT(writer != NULL); |
| 1082 ASSERT(kind != Snapshot::kMessage); | 1096 ASSERT(kind != Snapshot::kMessage); |
| 1083 | 1097 |
| 1084 // Write out the serialization header value for this object. | 1098 // Write out the serialization header value for this object. |
| 1085 writer->WriteInlinedObjectHeader(object_id); | 1099 writer->WriteInlinedObjectHeader(object_id); |
| 1086 | 1100 |
| 1087 // Write out the class and tags information. | 1101 // Write out the class and tags information. |
| 1088 writer->WriteVMIsolateObject(kLibraryCid); | 1102 writer->WriteVMIsolateObject(kLibraryCid); |
| 1089 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 1103 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 1090 | 1104 |
| 1091 if (RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) { | 1105 if ((kind == Snapshot::kScript) && |
| 1106 RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) { |
| 1092 ASSERT(kind != Snapshot::kFull); | 1107 ASSERT(kind != Snapshot::kFull); |
| 1093 // Write out library URL so that it can be looked up when reading. | 1108 // Write out library URL so that it can be looked up when reading. |
| 1094 writer->WriteObjectImpl(ptr()->url_); | 1109 writer->WriteObjectImpl(ptr()->url_); |
| 1095 } else { | 1110 } else { |
| 1096 // Write out all non object fields. | 1111 // Write out all non object fields. |
| 1097 writer->WriteIntptrValue(ptr()->index_); | 1112 writer->WriteIntptrValue(ptr()->index_); |
| 1098 writer->WriteIntptrValue(ptr()->num_imports_); | 1113 writer->WriteIntptrValue(ptr()->num_imports_); |
| 1099 writer->WriteIntptrValue(ptr()->num_anonymous_); | 1114 writer->WriteIntptrValue(ptr()->num_anonymous_); |
| 1100 writer->Write<bool>(ptr()->corelib_imported_); | 1115 writer->Write<bool>(ptr()->corelib_imported_); |
| 1101 writer->Write<bool>(ptr()->debuggable_); | 1116 writer->Write<bool>(ptr()->debuggable_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1112 visitor.VisitPointers(from(), to()); | 1127 visitor.VisitPointers(from(), to()); |
| 1113 } | 1128 } |
| 1114 } | 1129 } |
| 1115 | 1130 |
| 1116 | 1131 |
| 1117 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, | 1132 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, |
| 1118 intptr_t object_id, | 1133 intptr_t object_id, |
| 1119 intptr_t tags, | 1134 intptr_t tags, |
| 1120 Snapshot::Kind kind) { | 1135 Snapshot::Kind kind) { |
| 1121 ASSERT(reader != NULL); | 1136 ASSERT(reader != NULL); |
| 1122 ASSERT((kind != Snapshot::kMessage) && | 1137 ASSERT(((kind == Snapshot::kScript) && |
| 1123 !RawObject::IsCreatedFromSnapshot(tags)); | 1138 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 1139 (kind == Snapshot::kFull)); |
| 1124 | 1140 |
| 1125 // Allocate library prefix object. | 1141 // Allocate library prefix object. |
| 1126 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle( | 1142 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle( |
| 1127 reader->isolate(), NEW_OBJECT(LibraryPrefix)); | 1143 reader->isolate(), NEW_OBJECT(LibraryPrefix)); |
| 1128 reader->AddBackRef(object_id, &prefix, kIsDeserialized); | 1144 reader->AddBackRef(object_id, &prefix, kIsDeserialized); |
| 1129 | 1145 |
| 1130 // Set the object tags. | 1146 // Set the object tags. |
| 1131 prefix.set_tags(tags); | 1147 prefix.set_tags(tags); |
| 1132 | 1148 |
| 1133 // Set all non object fields. | 1149 // Set all non object fields. |
| 1134 prefix.raw_ptr()->num_imports_ = reader->ReadIntptrValue(); | 1150 prefix.raw_ptr()->num_imports_ = reader->ReadIntptrValue(); |
| 1135 | 1151 |
| 1136 // Set all the object fields. | 1152 // Set all the object fields. |
| 1137 // TODO(5411462): Need to assert No GC can happen here, even though | 1153 // TODO(5411462): Need to assert No GC can happen here, even though |
| 1138 // allocations may happen. | 1154 // allocations may happen. |
| 1139 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); | 1155 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); |
| 1140 for (intptr_t i = 0; i <= num_flds; i++) { | 1156 for (intptr_t i = 0; i <= num_flds; i++) { |
| 1141 *(prefix.raw()->from() + i) = reader->ReadObjectRef(); | 1157 *(prefix.raw()->from() + i) = reader->ReadObjectRef(); |
| 1142 } | 1158 } |
| 1143 | 1159 |
| 1144 return prefix.raw(); | 1160 return prefix.raw(); |
| 1145 } | 1161 } |
| 1146 | 1162 |
| 1147 | 1163 |
| 1148 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, | 1164 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, |
| 1149 intptr_t object_id, | 1165 intptr_t object_id, |
| 1150 Snapshot::Kind kind) { | 1166 Snapshot::Kind kind) { |
| 1151 ASSERT(writer != NULL); | 1167 ASSERT(writer != NULL); |
| 1152 ASSERT((kind != Snapshot::kMessage) && | 1168 ASSERT(((kind == Snapshot::kScript) && |
| 1153 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 1169 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 1170 (kind == Snapshot::kFull)); |
| 1154 | 1171 |
| 1155 // Write out the serialization header value for this object. | 1172 // Write out the serialization header value for this object. |
| 1156 writer->WriteInlinedObjectHeader(object_id); | 1173 writer->WriteInlinedObjectHeader(object_id); |
| 1157 | 1174 |
| 1158 // Write out the class and tags information. | 1175 // Write out the class and tags information. |
| 1159 writer->WriteVMIsolateObject(kLibraryPrefixCid); | 1176 writer->WriteVMIsolateObject(kLibraryPrefixCid); |
| 1160 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 1177 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 1161 | 1178 |
| 1162 // Write out all non object fields. | 1179 // Write out all non object fields. |
| 1163 writer->WriteIntptrValue(ptr()->num_imports_); | 1180 writer->WriteIntptrValue(ptr()->num_imports_); |
| 1164 | 1181 |
| 1165 // Write out all the object pointer fields. | 1182 // Write out all the object pointer fields. |
| 1166 SnapshotWriterVisitor visitor(writer); | 1183 SnapshotWriterVisitor visitor(writer); |
| 1167 visitor.VisitPointers(from(), to()); | 1184 visitor.VisitPointers(from(), to()); |
| 1168 } | 1185 } |
| 1169 | 1186 |
| 1170 | 1187 |
| 1171 RawNamespace* Namespace::ReadFrom(SnapshotReader* reader, | 1188 RawNamespace* Namespace::ReadFrom(SnapshotReader* reader, |
| 1172 intptr_t object_id, | 1189 intptr_t object_id, |
| 1173 intptr_t tags, | 1190 intptr_t tags, |
| 1174 Snapshot::Kind kind) { | 1191 Snapshot::Kind kind) { |
| 1175 ASSERT(reader != NULL); | 1192 ASSERT(reader != NULL); |
| 1176 ASSERT((kind != Snapshot::kMessage) && | 1193 ASSERT(((kind == Snapshot::kScript) && |
| 1177 !RawObject::IsCreatedFromSnapshot(tags)); | 1194 !RawObject::IsCreatedFromSnapshot(tags)) || |
| 1195 (kind == Snapshot::kFull)); |
| 1178 | 1196 |
| 1179 // Allocate Namespace object. | 1197 // Allocate Namespace object. |
| 1180 Namespace& ns = Namespace::ZoneHandle( | 1198 Namespace& ns = Namespace::ZoneHandle( |
| 1181 reader->isolate(), NEW_OBJECT(Namespace)); | 1199 reader->isolate(), NEW_OBJECT(Namespace)); |
| 1182 reader->AddBackRef(object_id, &ns, kIsDeserialized); | 1200 reader->AddBackRef(object_id, &ns, kIsDeserialized); |
| 1183 | 1201 |
| 1184 // Set the object tags. | 1202 // Set the object tags. |
| 1185 ns.set_tags(tags); | 1203 ns.set_tags(tags); |
| 1186 | 1204 |
| 1187 // Set all the object fields. | 1205 // Set all the object fields. |
| 1188 // TODO(5411462): Need to assert No GC can happen here, even though | 1206 // TODO(5411462): Need to assert No GC can happen here, even though |
| 1189 // allocations may happen. | 1207 // allocations may happen. |
| 1190 intptr_t num_flds = (ns.raw()->to() - ns.raw()->from()); | 1208 intptr_t num_flds = (ns.raw()->to() - ns.raw()->from()); |
| 1191 for (intptr_t i = 0; i <= num_flds; i++) { | 1209 for (intptr_t i = 0; i <= num_flds; i++) { |
| 1192 *(ns.raw()->from() + i) = reader->ReadObjectRef(); | 1210 *(ns.raw()->from() + i) = reader->ReadObjectRef(); |
| 1193 } | 1211 } |
| 1194 | 1212 |
| 1195 return ns.raw(); | 1213 return ns.raw(); |
| 1196 } | 1214 } |
| 1197 | 1215 |
| 1198 | 1216 |
| 1199 void RawNamespace::WriteTo(SnapshotWriter* writer, | 1217 void RawNamespace::WriteTo(SnapshotWriter* writer, |
| 1200 intptr_t object_id, | 1218 intptr_t object_id, |
| 1201 Snapshot::Kind kind) { | 1219 Snapshot::Kind kind) { |
| 1202 ASSERT(writer != NULL); | 1220 ASSERT(writer != NULL); |
| 1203 ASSERT((kind != Snapshot::kMessage) && | 1221 ASSERT(((kind == Snapshot::kScript) && |
| 1204 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); | 1222 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) || |
| 1223 (kind == Snapshot::kFull)); |
| 1205 | 1224 |
| 1206 // Write out the serialization header value for this object. | 1225 // Write out the serialization header value for this object. |
| 1207 writer->WriteInlinedObjectHeader(object_id); | 1226 writer->WriteInlinedObjectHeader(object_id); |
| 1208 | 1227 |
| 1209 // Write out the class and tags information. | 1228 // Write out the class and tags information. |
| 1210 writer->WriteVMIsolateObject(kNamespaceCid); | 1229 writer->WriteVMIsolateObject(kNamespaceCid); |
| 1211 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 1230 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 1212 | 1231 |
| 1213 // Write out all the object pointer fields. | 1232 // Write out all the object pointer fields. |
| 1214 SnapshotWriterVisitor visitor(writer); | 1233 SnapshotWriterVisitor visitor(writer); |
| (...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2621 // Write out the class and tags information. | 2640 // Write out the class and tags information. |
| 2622 writer->WriteIndexedObject(kWeakPropertyCid); | 2641 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2623 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2642 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2624 | 2643 |
| 2625 // Write out all the other fields. | 2644 // Write out all the other fields. |
| 2626 writer->Write<RawObject*>(ptr()->key_); | 2645 writer->Write<RawObject*>(ptr()->key_); |
| 2627 writer->Write<RawObject*>(ptr()->value_); | 2646 writer->Write<RawObject*>(ptr()->value_); |
| 2628 } | 2647 } |
| 2629 | 2648 |
| 2630 } // namespace dart | 2649 } // namespace dart |
| OLD | NEW |