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

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

Issue 1134773003: Small cid (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | Annotate | Revision Log
« 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/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
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 int32_t class_id = reader->Read<int32_t>(); 35 cid_t class_id = reader->Read<cid_t>();
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 if ((kind == Snapshot::kFull) || 90 if ((kind == Snapshot::kFull) ||
91 (kind == Snapshot::kScript && 91 (kind == Snapshot::kScript &&
92 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this)))) { 92 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this)))) {
93 // Write out the class and tags information. 93 // Write out the class and tags information.
94 writer->WriteVMIsolateObject(kClassCid); 94 writer->WriteVMIsolateObject(kClassCid);
95 writer->WriteTags(writer->GetObjectTags(this)); 95 writer->WriteTags(writer->GetObjectTags(this));
96 96
97 // Write out all the non object pointer fields. 97 // Write out all the non object pointer fields.
98 // NOTE: cpp_vtable_ is not written. 98 // NOTE: cpp_vtable_ is not written.
99 int32_t class_id = ptr()->id_; 99 cid_t class_id = ptr()->id_;
100 writer->Write<int32_t>(class_id); 100 writer->Write<cid_t>(class_id);
101 if (!RawObject::IsInternalVMdefinedClassId(class_id)) { 101 if (!RawObject::IsInternalVMdefinedClassId(class_id)) {
102 // We don't write the instance size of VM defined classes as they 102 // We don't write the instance size of VM defined classes as they
103 // are already setup during initialization as part of pre populating 103 // are already setup during initialization as part of pre populating
104 // the class table. 104 // the class table.
105 writer->Write<int32_t>(ptr()->instance_size_in_words_); 105 writer->Write<int32_t>(ptr()->instance_size_in_words_);
106 writer->Write<int32_t>(ptr()->next_field_offset_in_words_); 106 writer->Write<int32_t>(ptr()->next_field_offset_in_words_);
107 } 107 }
108 writer->Write<int32_t>(ptr()->type_arguments_field_offset_in_words_); 108 writer->Write<int32_t>(ptr()->type_arguments_field_offset_in_words_);
109 writer->Write<int16_t>(ptr()->num_type_arguments_); 109 writer->Write<int16_t>(ptr()->num_type_arguments_);
110 writer->Write<int16_t>(ptr()->num_own_type_arguments_); 110 writer->Write<int16_t>(ptr()->num_own_type_arguments_);
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 // Set the object tags. 701 // Set the object tags.
702 func.set_tags(tags); 702 func.set_tags(tags);
703 703
704 // Set all the non object fields. 704 // Set all the non object fields.
705 func.set_token_pos(reader->Read<int32_t>()); 705 func.set_token_pos(reader->Read<int32_t>());
706 func.set_end_token_pos(reader->Read<int32_t>()); 706 func.set_end_token_pos(reader->Read<int32_t>());
707 func.set_usage_counter(reader->Read<int32_t>()); 707 func.set_usage_counter(reader->Read<int32_t>());
708 func.set_num_fixed_parameters(reader->Read<int16_t>()); 708 func.set_num_fixed_parameters(reader->Read<int16_t>());
709 func.set_num_optional_parameters(reader->Read<int16_t>()); 709 func.set_num_optional_parameters(reader->Read<int16_t>());
710 func.set_deoptimization_counter(reader->Read<int16_t>()); 710 func.set_deoptimization_counter(reader->Read<int16_t>());
711 func.set_regexp_cid(reader->Read<int16_t>()); 711 func.set_regexp_cid(reader->Read<cid_t>());
712 func.set_kind_tag(reader->Read<uint32_t>()); 712 func.set_kind_tag(reader->Read<uint32_t>());
713 func.set_optimized_instruction_count(reader->Read<uint16_t>()); 713 func.set_optimized_instruction_count(reader->Read<uint16_t>());
714 func.set_optimized_call_site_count(reader->Read<uint16_t>()); 714 func.set_optimized_call_site_count(reader->Read<uint16_t>());
715 715
716 // Set all the object fields. 716 // Set all the object fields.
717 // TODO(5411462): Need to assert No GC can happen here, even though 717 // TODO(5411462): Need to assert No GC can happen here, even though
718 // allocations may happen. 718 // allocations may happen.
719 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from()); 719 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from());
720 for (intptr_t i = 0; i <= num_flds; i++) { 720 for (intptr_t i = 0; i <= num_flds; i++) {
721 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); 721 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef();
(...skipping 23 matching lines...) Expand all
745 writer->WriteVMIsolateObject(kFunctionCid); 745 writer->WriteVMIsolateObject(kFunctionCid);
746 writer->WriteTags(writer->GetObjectTags(this)); 746 writer->WriteTags(writer->GetObjectTags(this));
747 747
748 // Write out all the non object fields. 748 // Write out all the non object fields.
749 writer->Write<int32_t>(ptr()->token_pos_); 749 writer->Write<int32_t>(ptr()->token_pos_);
750 writer->Write<int32_t>(ptr()->end_token_pos_); 750 writer->Write<int32_t>(ptr()->end_token_pos_);
751 writer->Write<int32_t>(ptr()->usage_counter_); 751 writer->Write<int32_t>(ptr()->usage_counter_);
752 writer->Write<int16_t>(ptr()->num_fixed_parameters_); 752 writer->Write<int16_t>(ptr()->num_fixed_parameters_);
753 writer->Write<int16_t>(ptr()->num_optional_parameters_); 753 writer->Write<int16_t>(ptr()->num_optional_parameters_);
754 writer->Write<int16_t>(ptr()->deoptimization_counter_); 754 writer->Write<int16_t>(ptr()->deoptimization_counter_);
755 writer->Write<int16_t>(ptr()->regexp_cid_); 755 writer->Write<cid_t>(ptr()->regexp_cid_);
756 writer->Write<uint32_t>(ptr()->kind_tag_); 756 writer->Write<uint32_t>(ptr()->kind_tag_);
757 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); 757 writer->Write<uint16_t>(ptr()->optimized_instruction_count_);
758 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); 758 writer->Write<uint16_t>(ptr()->optimized_call_site_count_);
759 759
760 // Write out all the object pointer fields. 760 // Write out all the object pointer fields.
761 SnapshotWriterVisitor visitor(writer); 761 SnapshotWriterVisitor visitor(writer);
762 visitor.VisitPointers(from(), to_snapshot()); 762 visitor.VisitPointers(from(), to_snapshot());
763 } 763 }
764 764
765 765
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 library = Library::LookupLibrary(*reader->StringHandle()); 1034 library = Library::LookupLibrary(*reader->StringHandle());
1035 } else { 1035 } else {
1036 // Allocate library object. 1036 // Allocate library object.
1037 library = NEW_OBJECT(Library); 1037 library = NEW_OBJECT(Library);
1038 1038
1039 // Set the object tags. 1039 // Set the object tags.
1040 library.set_tags(tags); 1040 library.set_tags(tags);
1041 1041
1042 // Set all non object fields. 1042 // Set all non object fields.
1043 library.StoreNonPointer(&library.raw_ptr()->index_, 1043 library.StoreNonPointer(&library.raw_ptr()->index_,
1044 reader->Read<int32_t>()); 1044 reader->Read<cid_t>());
1045 library.StoreNonPointer(&library.raw_ptr()->num_imports_, 1045 library.StoreNonPointer(&library.raw_ptr()->num_imports_,
1046 reader->Read<int32_t>()); 1046 reader->Read<cid_t>());
1047 library.StoreNonPointer(&library.raw_ptr()->num_anonymous_, 1047 library.StoreNonPointer(&library.raw_ptr()->num_anonymous_,
1048 reader->Read<int32_t>()); 1048 reader->Read<cid_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 library.StoreNonPointer(&library.raw_ptr()->load_state_, 1055 library.StoreNonPointer(&library.raw_ptr()->load_state_,
1056 reader->Read<int8_t>()); 1056 reader->Read<int8_t>());
1057 // The native resolver is not serialized. 1057 // The native resolver is not serialized.
1058 Dart_NativeEntryResolver resolver = 1058 Dart_NativeEntryResolver resolver =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 writer->WriteVMIsolateObject(kLibraryCid); 1097 writer->WriteVMIsolateObject(kLibraryCid);
1098 writer->WriteTags(writer->GetObjectTags(this)); 1098 writer->WriteTags(writer->GetObjectTags(this));
1099 1099
1100 if ((kind == Snapshot::kScript) && 1100 if ((kind == Snapshot::kScript) &&
1101 RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) { 1101 RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) {
1102 ASSERT(kind != Snapshot::kFull); 1102 ASSERT(kind != Snapshot::kFull);
1103 // Write out library URL so that it can be looked up when reading. 1103 // Write out library URL so that it can be looked up when reading.
1104 writer->WriteObjectImpl(ptr()->url_); 1104 writer->WriteObjectImpl(ptr()->url_);
1105 } else { 1105 } else {
1106 // Write out all non object fields. 1106 // Write out all non object fields.
1107 writer->Write<int32_t>(ptr()->index_); 1107 writer->Write<cid_t>(ptr()->index_);
1108 writer->Write<int32_t>(ptr()->num_imports_); 1108 writer->Write<cid_t>(ptr()->num_imports_);
1109 writer->Write<int32_t>(ptr()->num_anonymous_); 1109 writer->Write<cid_t>(ptr()->num_anonymous_);
1110 writer->Write<bool>(ptr()->corelib_imported_); 1110 writer->Write<bool>(ptr()->corelib_imported_);
1111 writer->Write<bool>(ptr()->is_dart_scheme_); 1111 writer->Write<bool>(ptr()->is_dart_scheme_);
1112 writer->Write<bool>(ptr()->debuggable_); 1112 writer->Write<bool>(ptr()->debuggable_);
1113 writer->Write<int8_t>(ptr()->load_state_); 1113 writer->Write<int8_t>(ptr()->load_state_);
1114 // We do not serialize the native resolver over, this needs to be explicitly 1114 // We do not serialize the native resolver over, this needs to be explicitly
1115 // set after deserialization. 1115 // set after deserialization.
1116 writer->Write<Dart_NativeEntryResolver>(NULL); 1116 writer->Write<Dart_NativeEntryResolver>(NULL);
1117 // We do not serialize the native entry symbol, this needs to be explicitly 1117 // We do not serialize the native entry symbol, this needs to be explicitly
1118 // set after deserialization. 1118 // set after deserialization.
1119 writer->Write<Dart_NativeEntrySymbol>(NULL); 1119 writer->Write<Dart_NativeEntrySymbol>(NULL);
(...skipping 20 matching lines...) Expand all
1140 // Allocate library prefix object. 1140 // Allocate library prefix object.
1141 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle( 1141 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(
1142 reader->zone(), NEW_OBJECT(LibraryPrefix)); 1142 reader->zone(), NEW_OBJECT(LibraryPrefix));
1143 reader->AddBackRef(object_id, &prefix, kIsDeserialized); 1143 reader->AddBackRef(object_id, &prefix, kIsDeserialized);
1144 1144
1145 // Set the object tags. 1145 // Set the object tags.
1146 prefix.set_tags(tags); 1146 prefix.set_tags(tags);
1147 1147
1148 // Set all non object fields. 1148 // Set all non object fields.
1149 prefix.StoreNonPointer(&prefix.raw_ptr()->num_imports_, 1149 prefix.StoreNonPointer(&prefix.raw_ptr()->num_imports_,
1150 reader->Read<int32_t>()); 1150 reader->Read<cid_t>());
1151 prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_, 1151 prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_,
1152 reader->Read<bool>()); 1152 reader->Read<bool>());
1153 prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, reader->Read<bool>()); 1153 prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, reader->Read<bool>());
1154 1154
1155 // Set all the object fields. 1155 // Set all the object fields.
1156 // TODO(5411462): Need to assert No GC can happen here, even though 1156 // TODO(5411462): Need to assert No GC can happen here, even though
1157 // allocations may happen. 1157 // allocations may happen.
1158 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); 1158 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from());
1159 for (intptr_t i = 0; i <= num_flds; i++) { 1159 for (intptr_t i = 0; i <= num_flds; i++) {
1160 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef(); 1160 (*reader->PassiveObjectHandle()) = reader->ReadObjectRef();
(...skipping 14 matching lines...) Expand all
1175 (kind == Snapshot::kFull)); 1175 (kind == Snapshot::kFull));
1176 1176
1177 // Write out the serialization header value for this object. 1177 // Write out the serialization header value for this object.
1178 writer->WriteInlinedObjectHeader(object_id); 1178 writer->WriteInlinedObjectHeader(object_id);
1179 1179
1180 // Write out the class and tags information. 1180 // Write out the class and tags information.
1181 writer->WriteIndexedObject(kLibraryPrefixCid); 1181 writer->WriteIndexedObject(kLibraryPrefixCid);
1182 writer->WriteTags(writer->GetObjectTags(this)); 1182 writer->WriteTags(writer->GetObjectTags(this));
1183 1183
1184 // Write out all non object fields. 1184 // Write out all non object fields.
1185 writer->Write<int32_t>(ptr()->num_imports_); 1185 writer->Write<cid_t>(ptr()->num_imports_);
1186 writer->Write<bool>(ptr()->is_deferred_load_); 1186 writer->Write<bool>(ptr()->is_deferred_load_);
1187 writer->Write<bool>(ptr()->is_loaded_); 1187 writer->Write<bool>(ptr()->is_loaded_);
1188 1188
1189 // Write out all the object pointer fields. 1189 // Write out all the object pointer fields.
1190 SnapshotWriterVisitor visitor(writer); 1190 SnapshotWriterVisitor visitor(writer);
1191 visitor.VisitPointers(from(), to()); 1191 visitor.VisitPointers(from(), to());
1192 } 1192 }
1193 1193
1194 1194
1195 RawNamespace* Namespace::ReadFrom(SnapshotReader* reader, 1195 RawNamespace* Namespace::ReadFrom(SnapshotReader* reader,
(...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after
2878 // We do not allow objects with native fields in an isolate message. 2878 // We do not allow objects with native fields in an isolate message.
2879 writer->SetWriteException(Exceptions::kArgument, 2879 writer->SetWriteException(Exceptions::kArgument,
2880 "Illegal argument in isolate message" 2880 "Illegal argument in isolate message"
2881 " : (object is a UserTag)"); 2881 " : (object is a UserTag)");
2882 } else { 2882 } else {
2883 UNREACHABLE(); 2883 UNREACHABLE();
2884 } 2884 }
2885 } 2885 }
2886 2886
2887 } // namespace dart 2887 } // 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