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/object.h" | 5 #include "vm/object.h" |
6 #include "vm/object_store.h" | 6 #include "vm/object_store.h" |
7 #include "vm/snapshot.h" | 7 #include "vm/snapshot.h" |
8 #include "vm/stub_code.h" | 8 #include "vm/stub_code.h" |
9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 RawClass* Class::ReadFrom(SnapshotReader* reader, | 25 RawClass* Class::ReadFrom(SnapshotReader* reader, |
26 intptr_t object_id, | 26 intptr_t object_id, |
27 intptr_t tags, | 27 intptr_t tags, |
28 Snapshot::Kind kind) { | 28 Snapshot::Kind kind) { |
29 ASSERT(reader != NULL); | 29 ASSERT(reader != NULL); |
30 | 30 |
31 Class& cls = Class::ZoneHandle(reader->zone(), Class::null()); | 31 Class& cls = Class::ZoneHandle(reader->zone(), Class::null()); |
32 if ((kind == Snapshot::kFull) || | 32 if ((kind == Snapshot::kFull) || |
33 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { | 33 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { |
34 // Read in the base information. | 34 // Read in the base information. |
35 classid_t class_id = reader->Read<classid_t>(); | 35 classid_t class_id = reader->ReadClassIDValue(); |
36 | 36 |
37 // Allocate class object of specified kind. | 37 // Allocate class object of specified kind. |
38 if (kind == Snapshot::kFull) { | 38 if (kind == Snapshot::kFull) { |
39 cls = reader->NewClass(class_id); | 39 cls = reader->NewClass(class_id); |
40 } else { | 40 } else { |
41 if (class_id < kNumPredefinedCids) { | 41 if (class_id < kNumPredefinedCids) { |
42 ASSERT((class_id >= kInstanceCid) && (class_id <= kMirrorReferenceCid)); | 42 ASSERT((class_id >= kInstanceCid) && (class_id <= kMirrorReferenceCid)); |
43 cls = reader->isolate()->class_table()->At(class_id); | 43 cls = reader->isolate()->class_table()->At(class_id); |
44 } else { | 44 } else { |
45 cls = New<Instance>(kIllegalCid); | 45 cls = New<Instance>(kIllegalCid); |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 // Set the object tags. | 699 // Set the object tags. |
700 func.set_tags(tags); | 700 func.set_tags(tags); |
701 | 701 |
702 // Set all the non object fields. | 702 // Set all the non object fields. |
703 func.set_token_pos(reader->Read<int32_t>()); | 703 func.set_token_pos(reader->Read<int32_t>()); |
704 func.set_end_token_pos(reader->Read<int32_t>()); | 704 func.set_end_token_pos(reader->Read<int32_t>()); |
705 func.set_usage_counter(reader->Read<int32_t>()); | 705 func.set_usage_counter(reader->Read<int32_t>()); |
706 func.set_num_fixed_parameters(reader->Read<int16_t>()); | 706 func.set_num_fixed_parameters(reader->Read<int16_t>()); |
707 func.set_num_optional_parameters(reader->Read<int16_t>()); | 707 func.set_num_optional_parameters(reader->Read<int16_t>()); |
708 func.set_deoptimization_counter(reader->Read<int16_t>()); | 708 func.set_deoptimization_counter(reader->Read<int16_t>()); |
709 func.set_regexp_cid(reader->Read<classid_t>()); | 709 func.set_regexp_cid(reader->ReadClassIDValue()); |
710 func.set_kind_tag(reader->Read<uint32_t>()); | 710 func.set_kind_tag(reader->Read<uint32_t>()); |
711 func.set_optimized_instruction_count(reader->Read<uint16_t>()); | 711 func.set_optimized_instruction_count(reader->Read<uint16_t>()); |
712 func.set_optimized_call_site_count(reader->Read<uint16_t>()); | 712 func.set_optimized_call_site_count(reader->Read<uint16_t>()); |
713 | 713 |
714 // Set all the object fields. | 714 // Set all the object fields. |
715 // TODO(5411462): Need to assert No GC can happen here, even though | 715 // TODO(5411462): Need to assert No GC can happen here, even though |
716 // allocations may happen. | 716 // allocations may happen. |
717 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from()); | 717 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from()); |
718 for (intptr_t i = 0; i <= num_flds; i++) { | 718 for (intptr_t i = 0; i <= num_flds; i++) { |
719 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); | 719 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); |
(...skipping 23 matching lines...) Expand all Loading... |
743 writer->WriteVMIsolateObject(kFunctionCid); | 743 writer->WriteVMIsolateObject(kFunctionCid); |
744 writer->WriteTags(writer->GetObjectTags(this)); | 744 writer->WriteTags(writer->GetObjectTags(this)); |
745 | 745 |
746 // Write out all the non object fields. | 746 // Write out all the non object fields. |
747 writer->Write<int32_t>(ptr()->token_pos_); | 747 writer->Write<int32_t>(ptr()->token_pos_); |
748 writer->Write<int32_t>(ptr()->end_token_pos_); | 748 writer->Write<int32_t>(ptr()->end_token_pos_); |
749 writer->Write<int32_t>(ptr()->usage_counter_); | 749 writer->Write<int32_t>(ptr()->usage_counter_); |
750 writer->Write<int16_t>(ptr()->num_fixed_parameters_); | 750 writer->Write<int16_t>(ptr()->num_fixed_parameters_); |
751 writer->Write<int16_t>(ptr()->num_optional_parameters_); | 751 writer->Write<int16_t>(ptr()->num_optional_parameters_); |
752 writer->Write<int16_t>(ptr()->deoptimization_counter_); | 752 writer->Write<int16_t>(ptr()->deoptimization_counter_); |
753 writer->Write<classid_t>(ptr()->regexp_cid_); | 753 writer->WriteClassIDValue(ptr()->regexp_cid_); |
754 writer->Write<uint32_t>(ptr()->kind_tag_); | 754 writer->Write<uint32_t>(ptr()->kind_tag_); |
755 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); | 755 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); |
756 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); | 756 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); |
757 | 757 |
758 // Write out all the object pointer fields. | 758 // Write out all the object pointer fields. |
759 SnapshotWriterVisitor visitor(writer); | 759 SnapshotWriterVisitor visitor(writer); |
760 visitor.VisitPointers(from(), to_snapshot()); | 760 visitor.VisitPointers(from(), to_snapshot()); |
761 } | 761 } |
762 | 762 |
763 | 763 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 library = Library::LookupLibrary(*reader->StringHandle()); | 1032 library = Library::LookupLibrary(*reader->StringHandle()); |
1033 } else { | 1033 } else { |
1034 // Allocate library object. | 1034 // Allocate library object. |
1035 library = NEW_OBJECT(Library); | 1035 library = NEW_OBJECT(Library); |
1036 | 1036 |
1037 // Set the object tags. | 1037 // Set the object tags. |
1038 library.set_tags(tags); | 1038 library.set_tags(tags); |
1039 | 1039 |
1040 // Set all non object fields. | 1040 // Set all non object fields. |
1041 library.StoreNonPointer(&library.raw_ptr()->index_, | 1041 library.StoreNonPointer(&library.raw_ptr()->index_, |
1042 reader->Read<classid_t>()); | 1042 reader->ReadClassIDValue()); |
1043 library.StoreNonPointer(&library.raw_ptr()->num_anonymous_, | 1043 library.StoreNonPointer(&library.raw_ptr()->num_anonymous_, |
1044 reader->Read<classid_t>()); | 1044 reader->ReadClassIDValue()); |
1045 library.StoreNonPointer(&library.raw_ptr()->num_imports_, | 1045 library.StoreNonPointer(&library.raw_ptr()->num_imports_, |
1046 reader->Read<uint16_t>()); | 1046 reader->Read<uint16_t>()); |
1047 library.StoreNonPointer(&library.raw_ptr()->load_state_, | 1047 library.StoreNonPointer(&library.raw_ptr()->load_state_, |
1048 reader->Read<int8_t>()); | 1048 reader->Read<int8_t>()); |
1049 library.StoreNonPointer(&library.raw_ptr()->corelib_imported_, | 1049 library.StoreNonPointer(&library.raw_ptr()->corelib_imported_, |
1050 reader->Read<bool>()); | 1050 reader->Read<bool>()); |
1051 library.StoreNonPointer(&library.raw_ptr()->is_dart_scheme_, | 1051 library.StoreNonPointer(&library.raw_ptr()->is_dart_scheme_, |
1052 reader->Read<bool>()); | 1052 reader->Read<bool>()); |
1053 library.StoreNonPointer(&library.raw_ptr()->debuggable_, | 1053 library.StoreNonPointer(&library.raw_ptr()->debuggable_, |
1054 reader->Read<bool>()); | 1054 reader->Read<bool>()); |
1055 // The native resolver is not serialized. | 1055 // The native resolver and symbolizer are not serialized. |
1056 Dart_NativeEntryResolver resolver = | 1056 library.set_native_entry_resolver(NULL); |
1057 reader->Read<Dart_NativeEntryResolver>(); | 1057 library.set_native_entry_symbol_resolver(NULL); |
1058 ASSERT(resolver == NULL); | |
1059 library.set_native_entry_resolver(resolver); | |
1060 // The symbol resolver is not serialized. | |
1061 Dart_NativeEntrySymbol symbol_resolver = | |
1062 reader->Read<Dart_NativeEntrySymbol>(); | |
1063 ASSERT(symbol_resolver == NULL); | |
1064 library.set_native_entry_symbol_resolver(symbol_resolver); | |
1065 // The cache of loaded scripts is not serialized. | 1058 // The cache of loaded scripts is not serialized. |
1066 library.StorePointer(&library.raw_ptr()->loaded_scripts_, Array::null()); | 1059 library.StorePointer(&library.raw_ptr()->loaded_scripts_, Array::null()); |
1067 | 1060 |
1068 // Set all the object fields. | 1061 // Set all the object fields. |
1069 // TODO(5411462): Need to assert No GC can happen here, even though | 1062 // TODO(5411462): Need to assert No GC can happen here, even though |
1070 // allocations may happen. | 1063 // allocations may happen. |
1071 intptr_t num_flds = (library.raw()->to() - library.raw()->from()); | 1064 intptr_t num_flds = (library.raw()->to() - library.raw()->from()); |
1072 for (intptr_t i = 0; i <= num_flds; i++) { | 1065 for (intptr_t i = 0; i <= num_flds; i++) { |
1073 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); | 1066 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); |
1074 library.StorePointer((library.raw()->from() + i), | 1067 library.StorePointer((library.raw()->from() + i), |
(...skipping 20 matching lines...) Expand all Loading... |
1095 writer->WriteVMIsolateObject(kLibraryCid); | 1088 writer->WriteVMIsolateObject(kLibraryCid); |
1096 writer->WriteTags(writer->GetObjectTags(this)); | 1089 writer->WriteTags(writer->GetObjectTags(this)); |
1097 | 1090 |
1098 if ((kind == Snapshot::kScript) && | 1091 if ((kind == Snapshot::kScript) && |
1099 RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) { | 1092 RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) { |
1100 ASSERT(kind != Snapshot::kFull); | 1093 ASSERT(kind != Snapshot::kFull); |
1101 // Write out library URL so that it can be looked up when reading. | 1094 // Write out library URL so that it can be looked up when reading. |
1102 writer->WriteObjectImpl(ptr()->url_); | 1095 writer->WriteObjectImpl(ptr()->url_); |
1103 } else { | 1096 } else { |
1104 // Write out all non object fields. | 1097 // Write out all non object fields. |
1105 writer->Write<classid_t>(ptr()->index_); | 1098 writer->WriteClassIDValue(ptr()->index_); |
1106 writer->Write<classid_t>(ptr()->num_anonymous_); | 1099 writer->WriteClassIDValue(ptr()->num_anonymous_); |
1107 writer->Write<uint16_t>(ptr()->num_imports_); | 1100 writer->Write<uint16_t>(ptr()->num_imports_); |
1108 writer->Write<int8_t>(ptr()->load_state_); | 1101 writer->Write<int8_t>(ptr()->load_state_); |
1109 writer->Write<bool>(ptr()->corelib_imported_); | 1102 writer->Write<bool>(ptr()->corelib_imported_); |
1110 writer->Write<bool>(ptr()->is_dart_scheme_); | 1103 writer->Write<bool>(ptr()->is_dart_scheme_); |
1111 writer->Write<bool>(ptr()->debuggable_); | 1104 writer->Write<bool>(ptr()->debuggable_); |
1112 // We do not serialize the native resolver over, this needs to be explicitly | 1105 // We do not serialize the native resolver or symbolizer. These need to be |
1113 // set after deserialization. | 1106 // explicitly set after deserialization. |
1114 writer->Write<Dart_NativeEntryResolver>(NULL); | |
1115 // We do not serialize the native entry symbol, this needs to be explicitly | |
1116 // set after deserialization. | |
1117 writer->Write<Dart_NativeEntrySymbol>(NULL); | |
1118 // We do not write the loaded_scripts_ cache to the snapshot. It gets | 1107 // We do not write the loaded_scripts_ cache to the snapshot. It gets |
1119 // set to NULL when reading the library from the snapshot, and will | 1108 // set to NULL when reading the library from the snapshot, and will |
1120 // be rebuilt lazily. | 1109 // be rebuilt lazily. |
1121 | 1110 |
1122 // Write out all the object pointer fields. | 1111 // Write out all the object pointer fields. |
1123 SnapshotWriterVisitor visitor(writer); | 1112 SnapshotWriterVisitor visitor(writer); |
1124 visitor.VisitPointers(from(), to()); | 1113 visitor.VisitPointers(from(), to()); |
1125 } | 1114 } |
1126 } | 1115 } |
1127 | 1116 |
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2963 // We do not allow objects with native fields in an isolate message. | 2952 // We do not allow objects with native fields in an isolate message. |
2964 writer->SetWriteException(Exceptions::kArgument, | 2953 writer->SetWriteException(Exceptions::kArgument, |
2965 "Illegal argument in isolate message" | 2954 "Illegal argument in isolate message" |
2966 " : (object is a UserTag)"); | 2955 " : (object is a UserTag)"); |
2967 } else { | 2956 } else { |
2968 UNREACHABLE(); | 2957 UNREACHABLE(); |
2969 } | 2958 } |
2970 } | 2959 } |
2971 | 2960 |
2972 } // namespace dart | 2961 } // namespace dart |
OLD | NEW |