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

Side by Side Diff: runtime/vm/raw_object_snapshot.cc

Issue 2993613002: [kernel] Make snapshotting work. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/raw_object.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/native_entry.h" 5 #include "vm/native_entry.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/stub_code.h" 9 #include "vm/stub_code.h"
10 #include "vm/symbols.h" 10 #include "vm/symbols.h"
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 bool is_in_fullsnapshot = reader->Read<bool>(); 712 bool is_in_fullsnapshot = reader->Read<bool>();
713 if (!is_in_fullsnapshot) { 713 if (!is_in_fullsnapshot) {
714 // Allocate function object. 714 // Allocate function object.
715 Function& func = Function::ZoneHandle(reader->zone(), Function::New()); 715 Function& func = Function::ZoneHandle(reader->zone(), Function::New());
716 reader->AddBackRef(object_id, &func, kIsDeserialized); 716 reader->AddBackRef(object_id, &func, kIsDeserialized);
717 717
718 // Set all the non object fields. Read the token positions now but 718 // Set all the non object fields. Read the token positions now but
719 // don't set them until after setting the kind. 719 // don't set them until after setting the kind.
720 const int32_t token_pos = reader->Read<int32_t>(); 720 const int32_t token_pos = reader->Read<int32_t>();
721 const int32_t end_token_pos = reader->Read<uint32_t>(); 721 const int32_t end_token_pos = reader->Read<uint32_t>();
722 int32_t kernel_offset = 0;
723 #if !defined(DART_PRECOMPILED_RUNTIME)
724 kernel_offset = reader->Read<int32_t>();
725 #endif
722 func.set_num_fixed_parameters(reader->Read<int16_t>()); 726 func.set_num_fixed_parameters(reader->Read<int16_t>());
723 func.set_num_optional_parameters(reader->Read<int16_t>()); 727 func.set_num_optional_parameters(reader->Read<int16_t>());
724 func.set_kind_tag(reader->Read<uint32_t>()); 728 func.set_kind_tag(reader->Read<uint32_t>());
725 func.set_token_pos(TokenPosition::SnapshotDecode(token_pos)); 729 func.set_token_pos(TokenPosition::SnapshotDecode(token_pos));
726 func.set_end_token_pos(TokenPosition::SnapshotDecode(end_token_pos)); 730 func.set_end_token_pos(TokenPosition::SnapshotDecode(end_token_pos));
731 func.set_kernel_offset(kernel_offset);
727 func.set_usage_counter(reader->Read<int32_t>()); 732 func.set_usage_counter(reader->Read<int32_t>());
728 func.set_deoptimization_counter(reader->Read<int8_t>()); 733 func.set_deoptimization_counter(reader->Read<int8_t>());
729 func.set_optimized_instruction_count(reader->Read<uint16_t>()); 734 func.set_optimized_instruction_count(reader->Read<uint16_t>());
730 func.set_optimized_call_site_count(reader->Read<uint16_t>()); 735 func.set_optimized_call_site_count(reader->Read<uint16_t>());
731 func.set_kernel_offset(0);
732 func.set_was_compiled(false); 736 func.set_was_compiled(false);
733 737
734 // Set all the object fields. 738 // Set all the object fields.
735 READ_OBJECT_FIELDS(func, func.raw()->from(), func.raw()->to_snapshot(), 739 READ_OBJECT_FIELDS(func, func.raw()->from(), func.raw()->to_snapshot(),
736 kAsReference); 740 kAsReference);
737 // Initialize all fields that are not part of the snapshot. 741 // Initialize all fields that are not part of the snapshot.
738 bool is_optimized = func.usage_counter() != 0; 742 bool is_optimized = func.usage_counter() != 0;
739 if (is_optimized) { 743 if (is_optimized) {
740 // Read the ic data array as the function is an optimized one. 744 // Read the ic data array as the function is an optimized one.
741 (*reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsReference); 745 (*reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsReference);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 // to be interpreted. 785 // to be interpreted.
782 writer->Write<bool>(is_in_fullsnapshot); 786 writer->Write<bool>(is_in_fullsnapshot);
783 787
784 if (!is_in_fullsnapshot) { 788 if (!is_in_fullsnapshot) {
785 bool is_optimized = Code::IsOptimized(ptr()->code_); 789 bool is_optimized = Code::IsOptimized(ptr()->code_);
786 790
787 // Write out all the non object fields. 791 // Write out all the non object fields.
788 #if !defined(DART_PRECOMPILED_RUNTIME) 792 #if !defined(DART_PRECOMPILED_RUNTIME)
789 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); 793 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode());
790 writer->Write<int32_t>(ptr()->end_token_pos_.SnapshotEncode()); 794 writer->Write<int32_t>(ptr()->end_token_pos_.SnapshotEncode());
795 writer->Write<int32_t>(ptr()->kernel_offset_);
791 #endif 796 #endif
792 writer->Write<int16_t>(ptr()->num_fixed_parameters_); 797 writer->Write<int16_t>(ptr()->num_fixed_parameters_);
793 writer->Write<int16_t>(ptr()->num_optional_parameters_); 798 writer->Write<int16_t>(ptr()->num_optional_parameters_);
794 writer->Write<uint32_t>(ptr()->kind_tag_); 799 writer->Write<uint32_t>(ptr()->kind_tag_);
795 #if !defined(DART_PRECOMPILED_RUNTIME) 800 #if !defined(DART_PRECOMPILED_RUNTIME)
796 if (is_optimized) { 801 if (is_optimized) {
797 writer->Write<int32_t>(FLAG_optimization_counter_threshold); 802 writer->Write<int32_t>(FLAG_optimization_counter_threshold);
798 } else { 803 } else {
799 writer->Write<int32_t>(0); 804 writer->Write<int32_t>(0);
800 } 805 }
(...skipping 23 matching lines...) Expand all
824 ASSERT(kind == Snapshot::kScript); 829 ASSERT(kind == Snapshot::kScript);
825 830
826 // Allocate field object. 831 // Allocate field object.
827 Field& field = Field::ZoneHandle(reader->zone(), Field::New()); 832 Field& field = Field::ZoneHandle(reader->zone(), Field::New());
828 reader->AddBackRef(object_id, &field, kIsDeserialized); 833 reader->AddBackRef(object_id, &field, kIsDeserialized);
829 834
830 // Set all non object fields. 835 // Set all non object fields.
831 field.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>())); 836 field.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>()));
832 field.set_guarded_cid(reader->Read<int32_t>()); 837 field.set_guarded_cid(reader->Read<int32_t>());
833 field.set_is_nullable(reader->Read<int32_t>()); 838 field.set_is_nullable(reader->Read<int32_t>());
839 #if !defined(DART_PRECOMPILED_RUNTIME)
840 field.set_kernel_offset(reader->Read<int32_t>());
841 #endif
834 field.set_kind_bits(reader->Read<uint8_t>()); 842 field.set_kind_bits(reader->Read<uint8_t>());
835 field.set_kernel_offset(0);
836 843
837 // Set all the object fields. 844 // Set all the object fields.
838 READ_OBJECT_FIELDS(field, field.raw()->from(), field.raw()->to_snapshot(kind), 845 READ_OBJECT_FIELDS(field, field.raw()->from(), field.raw()->to_snapshot(kind),
839 kAsReference); 846 kAsReference);
840 field.StorePointer(&field.raw_ptr()->dependent_code_, Array::null()); 847 field.StorePointer(&field.raw_ptr()->dependent_code_, Array::null());
841 848
842 if (!reader->isolate()->use_field_guards()) { 849 if (!reader->isolate()->use_field_guards()) {
843 field.set_guarded_cid(kDynamicCid); 850 field.set_guarded_cid(kDynamicCid);
844 field.set_is_nullable(true); 851 field.set_is_nullable(true);
845 field.set_guarded_list_length(Field::kNoFixedLength); 852 field.set_guarded_list_length(Field::kNoFixedLength);
(...skipping 16 matching lines...) Expand all
862 writer->WriteInlinedObjectHeader(object_id); 869 writer->WriteInlinedObjectHeader(object_id);
863 870
864 // Write out the class and tags information. 871 // Write out the class and tags information.
865 writer->WriteVMIsolateObject(kFieldCid); 872 writer->WriteVMIsolateObject(kFieldCid);
866 writer->WriteTags(writer->GetObjectTags(this)); 873 writer->WriteTags(writer->GetObjectTags(this));
867 874
868 // Write out all the non object fields. 875 // Write out all the non object fields.
869 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); 876 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode());
870 writer->Write<int32_t>(ptr()->guarded_cid_); 877 writer->Write<int32_t>(ptr()->guarded_cid_);
871 writer->Write<int32_t>(ptr()->is_nullable_); 878 writer->Write<int32_t>(ptr()->is_nullable_);
879 #if !defined(DART_PRECOMPILED_RUNTIME)
880 writer->Write<int32_t>(ptr()->kernel_offset_);
881 #endif
872 writer->Write<uint8_t>(ptr()->kind_bits_); 882 writer->Write<uint8_t>(ptr()->kind_bits_);
873 883
874 // Write out the name. 884 // Write out the name.
875 writer->WriteObjectImpl(ptr()->name_, kAsReference); 885 writer->WriteObjectImpl(ptr()->name_, kAsReference);
876 // Write out the owner. 886 // Write out the owner.
877 writer->WriteObjectImpl(ptr()->owner_, kAsReference); 887 writer->WriteObjectImpl(ptr()->owner_, kAsReference);
878 // Write out the type. 888 // Write out the type.
879 writer->WriteObjectImpl(ptr()->type_, kAsReference); 889 writer->WriteObjectImpl(ptr()->type_, kAsReference);
880 // Write out the kernel_body. 890 // Write out the kernel_body.
881 writer->WriteObjectImpl(ptr()->kernel_body_, kAsReference); 891 writer->WriteObjectImpl(ptr()->kernel_body_, kAsReference);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 1023
1014 // Allocate script object. 1024 // Allocate script object.
1015 Script& script = Script::ZoneHandle(reader->zone(), Script::New()); 1025 Script& script = Script::ZoneHandle(reader->zone(), Script::New());
1016 reader->AddBackRef(object_id, &script, kIsDeserialized); 1026 reader->AddBackRef(object_id, &script, kIsDeserialized);
1017 1027
1018 script.StoreNonPointer(&script.raw_ptr()->line_offset_, 1028 script.StoreNonPointer(&script.raw_ptr()->line_offset_,
1019 reader->Read<int32_t>()); 1029 reader->Read<int32_t>());
1020 script.StoreNonPointer(&script.raw_ptr()->col_offset_, 1030 script.StoreNonPointer(&script.raw_ptr()->col_offset_,
1021 reader->Read<int32_t>()); 1031 reader->Read<int32_t>());
1022 script.StoreNonPointer(&script.raw_ptr()->kind_, reader->Read<int8_t>()); 1032 script.StoreNonPointer(&script.raw_ptr()->kind_, reader->Read<int8_t>());
1033 script.StoreNonPointer(&script.raw_ptr()->kernel_script_index_,
1034 reader->Read<int32_t>());
1023 1035
1024 *reader->StringHandle() ^= String::null(); 1036 *reader->StringHandle() ^= String::null();
1025 script.set_source(*reader->StringHandle()); 1037 script.set_source(*reader->StringHandle());
1026 *reader->StreamHandle() ^= TokenStream::null(); 1038 *reader->StreamHandle() ^= TokenStream::null();
1027 script.set_tokens(*reader->StreamHandle()); 1039 script.set_tokens(*reader->StreamHandle());
1028 1040
1029 // Set all the object fields. 1041 // Set all the object fields.
1030 // TODO(5411462): Need to assert No GC can happen here, even though 1042 // TODO(5411462): Need to assert No GC can happen here, even though
1031 // allocations may happen. 1043 // allocations may happen.
1032 intptr_t num_flds = (script.raw()->to_snapshot(kind) - script.raw()->from()); 1044 intptr_t num_flds = (script.raw()->to_snapshot(kind) - script.raw()->from());
(...skipping 21 matching lines...) Expand all
1054 writer->WriteInlinedObjectHeader(object_id); 1066 writer->WriteInlinedObjectHeader(object_id);
1055 1067
1056 // Write out the class and tags information. 1068 // Write out the class and tags information.
1057 writer->WriteVMIsolateObject(kScriptCid); 1069 writer->WriteVMIsolateObject(kScriptCid);
1058 writer->WriteTags(writer->GetObjectTags(this)); 1070 writer->WriteTags(writer->GetObjectTags(this));
1059 1071
1060 // Write out all the non object fields. 1072 // Write out all the non object fields.
1061 writer->Write<int32_t>(ptr()->line_offset_); 1073 writer->Write<int32_t>(ptr()->line_offset_);
1062 writer->Write<int32_t>(ptr()->col_offset_); 1074 writer->Write<int32_t>(ptr()->col_offset_);
1063 writer->Write<int8_t>(ptr()->kind_); 1075 writer->Write<int8_t>(ptr()->kind_);
1076 writer->Write<int32_t>(ptr()->kernel_script_index_);
1064 1077
1065 // Write out all the object pointer fields. 1078 // Write out all the object pointer fields.
1066 SnapshotWriterVisitor visitor(writer, kAsReference); 1079 SnapshotWriterVisitor visitor(writer, kAsReference);
1067 visitor.VisitPointers(from(), to_snapshot(kind)); 1080 visitor.VisitPointers(from(), to_snapshot(kind));
1068 } 1081 }
1069 1082
1070 RawLibrary* Library::ReadFrom(SnapshotReader* reader, 1083 RawLibrary* Library::ReadFrom(SnapshotReader* reader,
1071 intptr_t object_id, 1084 intptr_t object_id,
1072 intptr_t tags, 1085 intptr_t tags,
1073 Snapshot::Kind kind, 1086 Snapshot::Kind kind,
(...skipping 1847 matching lines...) Expand 10 before | Expand all | Expand 10 after
2921 // We do not allow objects with native fields in an isolate message. 2934 // We do not allow objects with native fields in an isolate message.
2922 writer->SetWriteException(Exceptions::kArgument, 2935 writer->SetWriteException(Exceptions::kArgument,
2923 "Illegal argument in isolate message" 2936 "Illegal argument in isolate message"
2924 " : (object is a UserTag)"); 2937 " : (object is a UserTag)");
2925 } else { 2938 } else {
2926 UNREACHABLE(); 2939 UNREACHABLE();
2927 } 2940 }
2928 } 2941 }
2929 2942
2930 } // namespace dart 2943 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698