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