Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/visitor.h" | 9 #include "vm/visitor.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 static RawSmi* GetSmi(intptr_t value) { | 13 static RawSmi* GetSmi(intptr_t value) { |
| 14 ASSERT((value & kSmiTagMask) == 0); | 14 ASSERT((value & kSmiTagMask) == 0); |
| 15 return reinterpret_cast<RawSmi*>(value); | 15 return reinterpret_cast<RawSmi*>(value); |
| 16 } | 16 } |
| 17 | 17 |
| 18 | 18 |
| 19 static uword ZoneAllocator(intptr_t size) { | 19 static uword ZoneAllocator(intptr_t size) { |
| 20 Zone* zone = Isolate::Current()->current_zone(); | 20 Zone* zone = Isolate::Current()->current_zone(); |
| 21 return zone->Allocate(size); | 21 return zone->Allocate(size); |
| 22 } | 22 } |
| 23 | 23 |
| 24 | 24 |
| 25 RawClass* Class::ReadFrom(SnapshotReader* reader, | 25 RawClass* Class::ReadFrom(SnapshotReader* reader, |
| 26 intptr_t object_id, | 26 intptr_t object_id, |
| 27 bool classes_serialized) { | 27 Snapshot::Kind kind) { |
| 28 ASSERT(reader != NULL); | 28 ASSERT(reader != NULL); |
| 29 | 29 |
| 30 Class& cls = Class::ZoneHandle(); | 30 Class& cls = Class::ZoneHandle(); |
| 31 if (classes_serialized) { | 31 if (kind == Snapshot::kFull) { |
| 32 // Read in the base information. | 32 // Read in the base information. |
| 33 ObjectKind kind = reader->Read<ObjectKind>(); | 33 ObjectKind kind = reader->Read<ObjectKind>(); |
| 34 | 34 |
| 35 // Allocate class object of specified kind. | 35 // Allocate class object of specified kind. |
| 36 cls = Class::GetClass(kind); | 36 cls = Class::GetClass(kind); |
| 37 reader->AddBackwardReference(object_id, &cls); | 37 reader->AddBackwardReference(object_id, &cls); |
| 38 | 38 |
| 39 // Set all non object fields. | 39 // Set all non object fields. |
| 40 cls.set_instance_size(reader->Read<intptr_t>()); | 40 cls.set_instance_size(reader->Read<intptr_t>()); |
| 41 cls.set_type_arguments_instance_field_offset(reader->Read<intptr_t>()); | 41 cls.set_type_arguments_instance_field_offset(reader->Read<intptr_t>()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 58 } | 58 } |
| 59 } else { | 59 } else { |
| 60 cls ^= reader->ReadClassId(object_id); | 60 cls ^= reader->ReadClassId(object_id); |
| 61 } | 61 } |
| 62 return cls.raw(); | 62 return cls.raw(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 | 65 |
| 66 void RawClass::WriteTo(SnapshotWriter* writer, | 66 void RawClass::WriteTo(SnapshotWriter* writer, |
| 67 intptr_t object_id, | 67 intptr_t object_id, |
| 68 bool serialize_classes) { | 68 Snapshot::Kind kind) { |
| 69 ASSERT(writer != NULL); | 69 ASSERT(writer != NULL); |
| 70 SnapshotWriterVisitor visitor(writer); | 70 SnapshotWriterVisitor visitor(writer); |
| 71 | 71 |
| 72 // Write out the serialization header value for this object. | 72 // Write out the serialization header value for this object. |
| 73 writer->WriteObjectHeader(kInlined, object_id); | 73 writer->WriteObjectHeader(kInlined, object_id); |
| 74 | 74 |
| 75 if (serialize_classes) { | 75 if (kind == Snapshot::kFull) { |
| 76 // Write out the class information. | 76 // Write out the class information. |
| 77 writer->WriteObjectHeader(kObjectId, Object::kClassClass); | 77 writer->WriteObjectHeader(kObjectId, Object::kClassClass); |
| 78 | 78 |
| 79 // Write out all the non object pointer fields. | 79 // Write out all the non object pointer fields. |
| 80 // NOTE: cpp_vtable_ is not written. | 80 // NOTE: cpp_vtable_ is not written. |
| 81 writer->Write<ObjectKind>(ptr()->instance_kind_); | 81 writer->Write<ObjectKind>(ptr()->instance_kind_); |
| 82 writer->Write<intptr_t>(ptr()->instance_size_); | 82 writer->Write<intptr_t>(ptr()->instance_size_); |
| 83 writer->Write<intptr_t>(ptr()->type_arguments_instance_field_offset_); | 83 writer->Write<intptr_t>(ptr()->type_arguments_instance_field_offset_); |
| 84 writer->Write<intptr_t>(ptr()->next_field_offset_); | 84 writer->Write<intptr_t>(ptr()->next_field_offset_); |
| 85 writer->Write<intptr_t>(ptr()->num_native_fields_); | 85 writer->Write<intptr_t>(ptr()->num_native_fields_); |
| 86 writer->Write<int8_t>(ptr()->class_state_); | 86 writer->Write<int8_t>(ptr()->class_state_); |
| 87 writer->Write<bool>(ptr()->is_const_); | 87 writer->Write<bool>(ptr()->is_const_); |
| 88 writer->Write<bool>(ptr()->is_interface_); | 88 writer->Write<bool>(ptr()->is_interface_); |
| 89 | 89 |
| 90 // Write out all the object pointer fields. | 90 // Write out all the object pointer fields. |
| 91 visitor.VisitPointers(from(), to()); | 91 visitor.VisitPointers(from(), to()); |
| 92 } else { | 92 } else { |
| 93 writer->WriteClassId(this); | 93 writer->WriteClassId(this); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 | 97 |
| 98 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, | 98 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, |
| 99 intptr_t object_id, | 99 intptr_t object_id, |
| 100 bool classes_serialized) { | 100 Snapshot::Kind kind) { |
| 101 ASSERT(reader != NULL); | 101 ASSERT(reader != NULL); |
| 102 | 102 |
| 103 // Allocate parameterized type object. | 103 // Allocate parameterized type object. |
| 104 UnresolvedClass& unresolved_class = | 104 UnresolvedClass& unresolved_class = |
| 105 UnresolvedClass::ZoneHandle(UnresolvedClass::New()); | 105 UnresolvedClass::ZoneHandle(UnresolvedClass::New()); |
| 106 reader->AddBackwardReference(object_id, &unresolved_class); | 106 reader->AddBackwardReference(object_id, &unresolved_class); |
| 107 | 107 |
| 108 // Set all non object fields. | 108 // Set all non object fields. |
| 109 unresolved_class.set_token_index(reader->Read<intptr_t>()); | 109 unresolved_class.set_token_index(reader->Read<intptr_t>()); |
| 110 | 110 |
| 111 // Set all the object fields. | 111 // Set all the object fields. |
| 112 // TODO(5411462): Need to assert No GC can happen here, even though | 112 // TODO(5411462): Need to assert No GC can happen here, even though |
| 113 // allocations may happen. | 113 // allocations may happen. |
| 114 intptr_t num_flds = (unresolved_class.raw()->to() - | 114 intptr_t num_flds = (unresolved_class.raw()->to() - |
| 115 unresolved_class.raw()->from()); | 115 unresolved_class.raw()->from()); |
| 116 for (intptr_t i = 0; i <= num_flds; i++) { | 116 for (intptr_t i = 0; i <= num_flds; i++) { |
| 117 *(unresolved_class.raw()->from() + i) = reader->ReadObject(); | 117 *(unresolved_class.raw()->from() + i) = reader->ReadObject(); |
| 118 } | 118 } |
| 119 return unresolved_class.raw(); | 119 return unresolved_class.raw(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 | 122 |
| 123 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, | 123 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, |
| 124 intptr_t object_id, | 124 intptr_t object_id, |
| 125 bool serialize_classes) { | 125 Snapshot::Kind kind) { |
| 126 ASSERT(writer != NULL); | 126 ASSERT(writer != NULL); |
| 127 SnapshotWriterVisitor visitor(writer); | 127 SnapshotWriterVisitor visitor(writer); |
| 128 | 128 |
| 129 // Write out the serialization header value for this object. | 129 // Write out the serialization header value for this object. |
| 130 writer->WriteObjectHeader(kInlined, object_id); | 130 writer->WriteObjectHeader(kInlined, object_id); |
| 131 | 131 |
| 132 // Write out the class information. | 132 // Write out the class information. |
| 133 writer->WriteObjectHeader(kObjectId, Object::kUnresolvedClassClass); | 133 writer->WriteObjectHeader(kObjectId, Object::kUnresolvedClassClass); |
| 134 | 134 |
| 135 // Write out all the non object pointer fields. | 135 // Write out all the non object pointer fields. |
| 136 writer->Write<intptr_t>(ptr()->token_index_); | 136 writer->Write<intptr_t>(ptr()->token_index_); |
| 137 | 137 |
| 138 // Write out all the object pointer fields. | 138 // Write out all the object pointer fields. |
| 139 visitor.VisitPointers(from(), to()); | 139 visitor.VisitPointers(from(), to()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 | 142 |
| 143 RawAbstractType* AbstractType::ReadFrom(SnapshotReader* reader, | 143 RawAbstractType* AbstractType::ReadFrom(SnapshotReader* reader, |
| 144 intptr_t object_id, | 144 intptr_t object_id, |
| 145 bool classes_serialized) { | 145 Snapshot::Kind kind) { |
| 146 UNREACHABLE(); // AbstractType is an abstract class. | 146 UNREACHABLE(); // AbstractType is an abstract class. |
| 147 return NULL; | 147 return NULL; |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 void RawAbstractType::WriteTo(SnapshotWriter* writer, | 151 void RawAbstractType::WriteTo(SnapshotWriter* writer, |
| 152 intptr_t object_id, | 152 intptr_t object_id, |
| 153 bool serialize_classes) { | 153 Snapshot::Kind kind) { |
| 154 UNREACHABLE(); // AbstractType is an abstract class. | 154 UNREACHABLE(); // AbstractType is an abstract class. |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 RawType* Type::ReadFrom(SnapshotReader* reader, | 158 RawType* Type::ReadFrom(SnapshotReader* reader, |
| 159 intptr_t object_id, | 159 intptr_t object_id, |
| 160 bool classes_serialized) { | 160 Snapshot::Kind kind) { |
| 161 ASSERT(reader != NULL); | 161 ASSERT(reader != NULL); |
| 162 | 162 |
| 163 // Allocate parameterized type object. | 163 // Allocate parameterized type object. |
| 164 Type& parameterized_type = Type::ZoneHandle(Type::New()); | 164 Type& parameterized_type = Type::ZoneHandle(Type::New()); |
| 165 reader->AddBackwardReference(object_id, ¶meterized_type); | 165 reader->AddBackwardReference(object_id, ¶meterized_type); |
| 166 | 166 |
| 167 // Set all non object fields. | 167 // Set all non object fields. |
| 168 parameterized_type.set_type_state(reader->Read<int8_t>()); | 168 parameterized_type.set_type_state(reader->Read<int8_t>()); |
| 169 | 169 |
| 170 // Set all the object fields. | 170 // Set all the object fields. |
| 171 // TODO(5411462): Need to assert No GC can happen here, even though | 171 // TODO(5411462): Need to assert No GC can happen here, even though |
| 172 // allocations may happen. | 172 // allocations may happen. |
| 173 intptr_t num_flds = (parameterized_type.raw()->to() - | 173 intptr_t num_flds = (parameterized_type.raw()->to() - |
| 174 parameterized_type.raw()->from()); | 174 parameterized_type.raw()->from()); |
| 175 for (intptr_t i = 0; i <= num_flds; i++) { | 175 for (intptr_t i = 0; i <= num_flds; i++) { |
| 176 *(parameterized_type.raw()->from() + i) = reader->ReadObject(); | 176 *(parameterized_type.raw()->from() + i) = reader->ReadObject(); |
| 177 } | 177 } |
| 178 return parameterized_type.raw(); | 178 return parameterized_type.raw(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 | 181 |
| 182 void RawType::WriteTo(SnapshotWriter* writer, | 182 void RawType::WriteTo(SnapshotWriter* writer, |
| 183 intptr_t object_id, | 183 intptr_t object_id, |
| 184 bool serialize_classes) { | 184 Snapshot::Kind kind) { |
| 185 ASSERT(writer != NULL); | 185 ASSERT(writer != NULL); |
| 186 SnapshotWriterVisitor visitor(writer); | 186 SnapshotWriterVisitor visitor(writer); |
| 187 | 187 |
| 188 // Write out the serialization header value for this object. | 188 // Write out the serialization header value for this object. |
| 189 writer->WriteObjectHeader(kInlined, object_id); | 189 writer->WriteObjectHeader(kInlined, object_id); |
| 190 | 190 |
| 191 // Write out the class information. | 191 // Write out the class information. |
| 192 writer->WriteObjectHeader(kObjectId, Object::kTypeClass); | 192 writer->WriteObjectHeader(kObjectId, Object::kTypeClass); |
| 193 | 193 |
| 194 // Write out all the non object pointer fields. | 194 // Write out all the non object pointer fields. |
| 195 writer->Write<int8_t>(ptr()->type_state_); | 195 writer->Write<int8_t>(ptr()->type_state_); |
| 196 | 196 |
| 197 // Write out all the object pointer fields. | 197 // Write out all the object pointer fields. |
| 198 visitor.VisitPointers(from(), to()); | 198 visitor.VisitPointers(from(), to()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 | 201 |
| 202 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, | 202 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, |
| 203 intptr_t object_id, | 203 intptr_t object_id, |
| 204 bool classes_serialized) { | 204 Snapshot::Kind kind) { |
| 205 ASSERT(reader != NULL); | 205 ASSERT(reader != NULL); |
| 206 | 206 |
| 207 // Allocate type parameter object. | 207 // Allocate type parameter object. |
| 208 TypeParameter& type_parameter = | 208 TypeParameter& type_parameter = |
| 209 TypeParameter::ZoneHandle(TypeParameter::New()); | 209 TypeParameter::ZoneHandle(TypeParameter::New()); |
| 210 reader->AddBackwardReference(object_id, &type_parameter); | 210 reader->AddBackwardReference(object_id, &type_parameter); |
| 211 | 211 |
| 212 // Set all non object fields. | 212 // Set all non object fields. |
| 213 type_parameter.set_index(reader->Read<intptr_t>()); | 213 type_parameter.set_index(reader->Read<intptr_t>()); |
| 214 | 214 |
| 215 // Set all the object fields. | 215 // Set all the object fields. |
| 216 // TODO(5411462): Need to assert No GC can happen here, even though | 216 // TODO(5411462): Need to assert No GC can happen here, even though |
| 217 // allocations may happen. | 217 // allocations may happen. |
| 218 intptr_t num_flds = (type_parameter.raw()->to() - | 218 intptr_t num_flds = (type_parameter.raw()->to() - |
| 219 type_parameter.raw()->from()); | 219 type_parameter.raw()->from()); |
| 220 for (intptr_t i = 0; i <= num_flds; i++) { | 220 for (intptr_t i = 0; i <= num_flds; i++) { |
| 221 *(type_parameter.raw()->from() + i) = reader->ReadObject(); | 221 *(type_parameter.raw()->from() + i) = reader->ReadObject(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 return type_parameter.raw(); | 224 return type_parameter.raw(); |
| 225 } | 225 } |
| 226 | 226 |
| 227 | 227 |
| 228 void RawTypeParameter::WriteTo(SnapshotWriter* writer, | 228 void RawTypeParameter::WriteTo(SnapshotWriter* writer, |
| 229 intptr_t object_id, | 229 intptr_t object_id, |
| 230 bool serialize_classes) { | 230 Snapshot::Kind kind) { |
| 231 ASSERT(writer != NULL); | 231 ASSERT(writer != NULL); |
| 232 SnapshotWriterVisitor visitor(writer); | 232 SnapshotWriterVisitor visitor(writer); |
| 233 | 233 |
| 234 // Write out the serialization header value for this object. | 234 // Write out the serialization header value for this object. |
| 235 writer->WriteObjectHeader(kInlined, object_id); | 235 writer->WriteObjectHeader(kInlined, object_id); |
| 236 | 236 |
| 237 // Write out the class information. | 237 // Write out the class information. |
| 238 writer->WriteObjectHeader(kObjectId, Object::kTypeParameterClass); | 238 writer->WriteObjectHeader(kObjectId, Object::kTypeParameterClass); |
| 239 | 239 |
| 240 writer->Write<intptr_t>(ptr()->index_); | 240 writer->Write<intptr_t>(ptr()->index_); |
| 241 | 241 |
| 242 // Write out all the object pointer fields. | 242 // Write out all the object pointer fields. |
| 243 visitor.VisitPointers(from(), to()); | 243 visitor.VisitPointers(from(), to()); |
| 244 } | 244 } |
| 245 | 245 |
| 246 | 246 |
| 247 RawInstantiatedType* InstantiatedType::ReadFrom(SnapshotReader* reader, | 247 RawInstantiatedType* InstantiatedType::ReadFrom(SnapshotReader* reader, |
| 248 intptr_t object_id, | 248 intptr_t object_id, |
| 249 bool classes_serialized) { | 249 Snapshot::Kind kind) { |
| 250 ASSERT(reader != NULL); | 250 ASSERT(reader != NULL); |
| 251 | 251 |
| 252 // Allocate instantiated type object. | 252 // Allocate instantiated type object. |
| 253 InstantiatedType& instantiated_type = | 253 InstantiatedType& instantiated_type = |
| 254 InstantiatedType::ZoneHandle(InstantiatedType::New()); | 254 InstantiatedType::ZoneHandle(InstantiatedType::New()); |
| 255 reader->AddBackwardReference(object_id, &instantiated_type); | 255 reader->AddBackwardReference(object_id, &instantiated_type); |
| 256 | 256 |
| 257 // Now set all the object fields. | 257 // Now set all the object fields. |
| 258 // TODO(5411462): Need to assert No GC can happen here, even though | 258 // TODO(5411462): Need to assert No GC can happen here, even though |
| 259 // allocations may happen. | 259 // allocations may happen. |
| 260 intptr_t num_flds = (instantiated_type.raw()->to() - | 260 intptr_t num_flds = (instantiated_type.raw()->to() - |
| 261 instantiated_type.raw()->from()); | 261 instantiated_type.raw()->from()); |
| 262 for (intptr_t i = 0; i <= num_flds; i++) { | 262 for (intptr_t i = 0; i <= num_flds; i++) { |
| 263 *(instantiated_type.raw()->from() + i) = reader->ReadObject(); | 263 *(instantiated_type.raw()->from() + i) = reader->ReadObject(); |
| 264 } | 264 } |
| 265 return instantiated_type.raw(); | 265 return instantiated_type.raw(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 | 268 |
| 269 void RawInstantiatedType::WriteTo(SnapshotWriter* writer, | 269 void RawInstantiatedType::WriteTo(SnapshotWriter* writer, |
| 270 intptr_t object_id, | 270 intptr_t object_id, |
| 271 bool serialize_classes) { | 271 Snapshot::Kind kind) { |
| 272 ASSERT(writer != NULL); | 272 ASSERT(writer != NULL); |
| 273 SnapshotWriterVisitor visitor(writer); | 273 SnapshotWriterVisitor visitor(writer); |
| 274 | 274 |
| 275 // Write out the serialization header value for this object. | 275 // Write out the serialization header value for this object. |
| 276 writer->WriteObjectHeader(kInlined, object_id); | 276 writer->WriteObjectHeader(kInlined, object_id); |
| 277 | 277 |
| 278 // Write out the class information. | 278 // Write out the class information. |
| 279 writer->WriteObjectHeader(kObjectId, Object::kInstantiatedTypeClass); | 279 writer->WriteObjectHeader(kObjectId, Object::kInstantiatedTypeClass); |
| 280 | 280 |
| 281 // Write out all the object pointer fields. | 281 // Write out all the object pointer fields. |
| 282 visitor.VisitPointers(from(), to()); | 282 visitor.VisitPointers(from(), to()); |
| 283 } | 283 } |
| 284 | 284 |
| 285 | 285 |
| 286 RawAbstractTypeArguments* AbstractTypeArguments::ReadFrom( | 286 RawAbstractTypeArguments* AbstractTypeArguments::ReadFrom( |
| 287 SnapshotReader* reader, | 287 SnapshotReader* reader, |
| 288 intptr_t object_id, | 288 intptr_t object_id, |
| 289 bool classes_serialized) { | 289 Snapshot::Kind kind) { |
| 290 UNREACHABLE(); // AbstractTypeArguments is an abstract class. | 290 UNREACHABLE(); // AbstractTypeArguments is an abstract class. |
| 291 return TypeArguments::null(); | 291 return TypeArguments::null(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 | 294 |
| 295 void RawAbstractTypeArguments::WriteTo(SnapshotWriter* writer, | 295 void RawAbstractTypeArguments::WriteTo(SnapshotWriter* writer, |
| 296 intptr_t object_id, | 296 intptr_t object_id, |
| 297 bool serialize_classes) { | 297 Snapshot::Kind kind) { |
| 298 UNREACHABLE(); // AbstractTypeArguments is an abstract class. | 298 UNREACHABLE(); // AbstractTypeArguments is an abstract class. |
| 299 } | 299 } |
| 300 | 300 |
| 301 | 301 |
| 302 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, | 302 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, |
| 303 intptr_t object_id, | 303 intptr_t object_id, |
| 304 bool classes_serialized) { | 304 Snapshot::Kind kind) { |
| 305 ASSERT(reader != NULL); | 305 ASSERT(reader != NULL); |
| 306 | 306 |
| 307 // Read the length so that we can determine instance size to allocate. | 307 // Read the length so that we can determine instance size to allocate. |
| 308 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 308 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 309 intptr_t len = Smi::Value(smi_len); | 309 intptr_t len = Smi::Value(smi_len); |
| 310 | 310 |
| 311 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(len)); | 311 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(len)); |
| 312 reader->AddBackwardReference(object_id, &type_array); | 312 reader->AddBackwardReference(object_id, &type_array); |
| 313 AbstractType& type = AbstractType::Handle(); | 313 AbstractType& type = AbstractType::Handle(); |
| 314 for (intptr_t i = 0; i < len; i++) { | 314 for (intptr_t i = 0; i < len; i++) { |
| 315 type ^= reader->ReadObject(); | 315 type ^= reader->ReadObject(); |
| 316 type_array.SetTypeAt(i, type); | 316 type_array.SetTypeAt(i, type); |
| 317 } | 317 } |
| 318 return type_array.raw(); | 318 return type_array.raw(); |
| 319 } | 319 } |
| 320 | 320 |
| 321 | 321 |
| 322 void RawTypeArguments::WriteTo(SnapshotWriter* writer, | 322 void RawTypeArguments::WriteTo(SnapshotWriter* writer, |
| 323 intptr_t object_id, | 323 intptr_t object_id, |
| 324 bool serialize_classes) { | 324 Snapshot::Kind kind) { |
| 325 ASSERT(writer != NULL); | 325 ASSERT(writer != NULL); |
| 326 | 326 |
| 327 // Write out the serialization header value for this object. | 327 // Write out the serialization header value for this object. |
| 328 writer->WriteObjectHeader(kInlined, object_id); | 328 writer->WriteObjectHeader(kInlined, object_id); |
| 329 | 329 |
| 330 // Write out the class information. | 330 // Write out the class information. |
| 331 writer->WriteObjectHeader(kObjectId, Object::kTypeArgumentsClass); | 331 writer->WriteObjectHeader(kObjectId, Object::kTypeArgumentsClass); |
| 332 | 332 |
| 333 // Write out the length field. | 333 // Write out the length field. |
| 334 writer->Write<RawObject*>(ptr()->length_); | 334 writer->Write<RawObject*>(ptr()->length_); |
| 335 | 335 |
| 336 // Write out the individual types. | 336 // Write out the individual types. |
| 337 intptr_t len = Smi::Value(ptr()->length_); | 337 intptr_t len = Smi::Value(ptr()->length_); |
| 338 for (intptr_t i = 0; i < len; i++) { | 338 for (intptr_t i = 0; i < len; i++) { |
| 339 writer->WriteObject(ptr()->types_[i]); | 339 writer->WriteObject(ptr()->types_[i]); |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 | 342 |
| 343 | 343 |
| 344 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( | 344 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( |
| 345 SnapshotReader* reader, | 345 SnapshotReader* reader, |
| 346 intptr_t object_id, | 346 intptr_t object_id, |
| 347 bool classes_serialized) { | 347 Snapshot::Kind kind) { |
| 348 ASSERT(reader != NULL); | 348 ASSERT(reader != NULL); |
| 349 | 349 |
| 350 // Allocate instantiated types object. | 350 // Allocate instantiated types object. |
| 351 InstantiatedTypeArguments& instantiated_type_arguments = | 351 InstantiatedTypeArguments& instantiated_type_arguments = |
| 352 InstantiatedTypeArguments::ZoneHandle(InstantiatedTypeArguments::New()); | 352 InstantiatedTypeArguments::ZoneHandle(InstantiatedTypeArguments::New()); |
| 353 reader->AddBackwardReference(object_id, &instantiated_type_arguments); | 353 reader->AddBackwardReference(object_id, &instantiated_type_arguments); |
| 354 | 354 |
| 355 // Set all the object fields. | 355 // Set all the object fields. |
| 356 // TODO(5411462): Need to assert No GC can happen here, even though | 356 // TODO(5411462): Need to assert No GC can happen here, even though |
| 357 // allocations may happen. | 357 // allocations may happen. |
| 358 intptr_t num_flds = (instantiated_type_arguments.raw()->to() - | 358 intptr_t num_flds = (instantiated_type_arguments.raw()->to() - |
| 359 instantiated_type_arguments.raw()->from()); | 359 instantiated_type_arguments.raw()->from()); |
| 360 for (intptr_t i = 0; i <= num_flds; i++) { | 360 for (intptr_t i = 0; i <= num_flds; i++) { |
| 361 *(instantiated_type_arguments.raw()->from() + i) = reader->ReadObject(); | 361 *(instantiated_type_arguments.raw()->from() + i) = reader->ReadObject(); |
| 362 } | 362 } |
| 363 return instantiated_type_arguments.raw(); | 363 return instantiated_type_arguments.raw(); |
| 364 } | 364 } |
| 365 | 365 |
| 366 | 366 |
| 367 void RawInstantiatedTypeArguments::WriteTo(SnapshotWriter* writer, | 367 void RawInstantiatedTypeArguments::WriteTo(SnapshotWriter* writer, |
| 368 intptr_t object_id, | 368 intptr_t object_id, |
| 369 bool serialize_classes) { | 369 Snapshot::Kind kind) { |
| 370 ASSERT(writer != NULL); | 370 ASSERT(writer != NULL); |
| 371 SnapshotWriterVisitor visitor(writer); | 371 SnapshotWriterVisitor visitor(writer); |
| 372 | 372 |
| 373 // Write out the serialization header value for this object. | 373 // Write out the serialization header value for this object. |
| 374 writer->WriteObjectHeader(kInlined, object_id); | 374 writer->WriteObjectHeader(kInlined, object_id); |
| 375 | 375 |
| 376 // Write out the class information. | 376 // Write out the class information. |
| 377 writer->WriteObjectHeader(kObjectId, Object::kInstantiatedTypeArgumentsClass); | 377 writer->WriteObjectHeader(kObjectId, Object::kInstantiatedTypeArgumentsClass); |
| 378 | 378 |
| 379 // Write out all the object pointer fields. | 379 // Write out all the object pointer fields. |
| 380 visitor.VisitPointers(from(), to()); | 380 visitor.VisitPointers(from(), to()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 | 383 |
| 384 RawFunction* Function::ReadFrom(SnapshotReader* reader, | 384 RawFunction* Function::ReadFrom(SnapshotReader* reader, |
| 385 intptr_t object_id, | 385 intptr_t object_id, |
| 386 bool classes_serialized) { | 386 Snapshot::Kind kind) { |
| 387 ASSERT(reader != NULL); | 387 ASSERT(reader != NULL); |
| 388 | 388 |
| 389 // Allocate function object. | 389 // Allocate function object. |
| 390 Function& func = Function::ZoneHandle(Function::New()); | 390 Function& func = Function::ZoneHandle(Function::New()); |
| 391 reader->AddBackwardReference(object_id, &func); | 391 reader->AddBackwardReference(object_id, &func); |
| 392 | 392 |
| 393 // Set all the non object fields. | 393 // Set all the non object fields. |
| 394 func.set_token_index(reader->Read<intptr_t>()); | 394 func.set_token_index(reader->Read<intptr_t>()); |
| 395 func.set_num_fixed_parameters(reader->Read<intptr_t>()); | 395 func.set_num_fixed_parameters(reader->Read<intptr_t>()); |
| 396 func.set_num_optional_parameters(reader->Read<intptr_t>()); | 396 func.set_num_optional_parameters(reader->Read<intptr_t>()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 408 for (intptr_t i = 0; i <= num_flds; i++) { | 408 for (intptr_t i = 0; i <= num_flds; i++) { |
| 409 *(func.raw()->from() + i) = reader->ReadObject(); | 409 *(func.raw()->from() + i) = reader->ReadObject(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 return func.raw(); | 412 return func.raw(); |
| 413 } | 413 } |
| 414 | 414 |
| 415 | 415 |
| 416 void RawFunction::WriteTo(SnapshotWriter* writer, | 416 void RawFunction::WriteTo(SnapshotWriter* writer, |
| 417 intptr_t object_id, | 417 intptr_t object_id, |
| 418 bool serialize_classes) { | 418 Snapshot::Kind kind) { |
| 419 ASSERT(writer != NULL); | 419 ASSERT(writer != NULL); |
| 420 SnapshotWriterVisitor visitor(writer); | 420 SnapshotWriterVisitor visitor(writer); |
| 421 | 421 |
| 422 // Write out the serialization header value for this object. | 422 // Write out the serialization header value for this object. |
| 423 writer->WriteObjectHeader(kInlined, object_id); | 423 writer->WriteObjectHeader(kInlined, object_id); |
| 424 | 424 |
| 425 // Write out the class information. | 425 // Write out the class information. |
| 426 writer->WriteObjectHeader(kObjectId, Object::kFunctionClass); | 426 writer->WriteObjectHeader(kObjectId, Object::kFunctionClass); |
| 427 | 427 |
| 428 // Write out all the non object fields. | 428 // Write out all the non object fields. |
| 429 writer->Write<intptr_t>(ptr()->token_index_); | 429 writer->Write<intptr_t>(ptr()->token_index_); |
| 430 writer->Write<intptr_t>(ptr()->num_fixed_parameters_); | 430 writer->Write<intptr_t>(ptr()->num_fixed_parameters_); |
| 431 writer->Write<intptr_t>(ptr()->num_optional_parameters_); | 431 writer->Write<intptr_t>(ptr()->num_optional_parameters_); |
| 432 writer->Write<intptr_t>(ptr()->invocation_counter_); | 432 writer->Write<intptr_t>(ptr()->invocation_counter_); |
| 433 writer->Write<intptr_t>(ptr()->deoptimization_counter_); | 433 writer->Write<intptr_t>(ptr()->deoptimization_counter_); |
| 434 writer->Write<intptr_t>(ptr()->kind_); | 434 writer->Write<intptr_t>(ptr()->kind_); |
| 435 writer->Write<bool>(ptr()->is_static_); | 435 writer->Write<bool>(ptr()->is_static_); |
| 436 writer->Write<bool>(ptr()->is_const_); | 436 writer->Write<bool>(ptr()->is_const_); |
| 437 writer->Write<bool>(ptr()->is_optimizable_); | 437 writer->Write<bool>(ptr()->is_optimizable_); |
| 438 | 438 |
| 439 // Write out all the object pointer fields. | 439 // Write out all the object pointer fields. |
| 440 visitor.VisitPointers(from(), to()); | 440 visitor.VisitPointers(from(), to()); |
| 441 } | 441 } |
| 442 | 442 |
| 443 | 443 |
| 444 RawField* Field::ReadFrom(SnapshotReader* reader, | 444 RawField* Field::ReadFrom(SnapshotReader* reader, |
| 445 intptr_t object_id, | 445 intptr_t object_id, |
| 446 bool classes_serialized) { | 446 Snapshot::Kind kind) { |
| 447 ASSERT(reader != NULL); | 447 ASSERT(reader != NULL); |
| 448 | 448 |
| 449 // Allocate field object. | 449 // Allocate field object. |
| 450 Field& field = Field::ZoneHandle(Field::New()); | 450 Field& field = Field::ZoneHandle(Field::New()); |
| 451 reader->AddBackwardReference(object_id, &field); | 451 reader->AddBackwardReference(object_id, &field); |
| 452 | 452 |
| 453 // Set all non object fields. | 453 // Set all non object fields. |
| 454 field.set_token_index(reader->Read<intptr_t>()); | 454 field.set_token_index(reader->Read<intptr_t>()); |
| 455 field.set_is_static(reader->Read<bool>()); | 455 field.set_is_static(reader->Read<bool>()); |
| 456 field.set_is_final(reader->Read<bool>()); | 456 field.set_is_final(reader->Read<bool>()); |
| 457 field.set_has_initializer(reader->Read<bool>()); | 457 field.set_has_initializer(reader->Read<bool>()); |
| 458 | 458 |
| 459 // Set all the object fields. | 459 // Set all the object fields. |
| 460 // TODO(5411462): Need to assert No GC can happen here, even though | 460 // TODO(5411462): Need to assert No GC can happen here, even though |
| 461 // allocations may happen. | 461 // allocations may happen. |
| 462 intptr_t num_flds = (field.raw()->to() - field.raw()->from()); | 462 intptr_t num_flds = (field.raw()->to() - field.raw()->from()); |
| 463 for (intptr_t i = 0; i <= num_flds; i++) { | 463 for (intptr_t i = 0; i <= num_flds; i++) { |
| 464 *(field.raw()->from() + i) = reader->ReadObject(); | 464 *(field.raw()->from() + i) = reader->ReadObject(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 return field.raw(); | 467 return field.raw(); |
| 468 } | 468 } |
| 469 | 469 |
| 470 | 470 |
| 471 void RawField::WriteTo(SnapshotWriter* writer, | 471 void RawField::WriteTo(SnapshotWriter* writer, |
| 472 intptr_t object_id, | 472 intptr_t object_id, |
| 473 bool serialize_classes) { | 473 Snapshot::Kind kind) { |
| 474 ASSERT(writer != NULL); | 474 ASSERT(writer != NULL); |
| 475 SnapshotWriterVisitor visitor(writer); | 475 SnapshotWriterVisitor visitor(writer); |
| 476 | 476 |
| 477 // Write out the serialization header value for this object. | 477 // Write out the serialization header value for this object. |
| 478 writer->WriteObjectHeader(kInlined, object_id); | 478 writer->WriteObjectHeader(kInlined, object_id); |
| 479 | 479 |
| 480 // Write out the class information. | 480 // Write out the class information. |
| 481 writer->WriteObjectHeader(kObjectId, Object::kFieldClass); | 481 writer->WriteObjectHeader(kObjectId, Object::kFieldClass); |
| 482 | 482 |
| 483 writer->Write<intptr_t>(ptr()->token_index_); | 483 writer->Write<intptr_t>(ptr()->token_index_); |
| 484 writer->Write<bool>(ptr()->is_static_); | 484 writer->Write<bool>(ptr()->is_static_); |
| 485 writer->Write<bool>(ptr()->is_final_); | 485 writer->Write<bool>(ptr()->is_final_); |
| 486 writer->Write<bool>(ptr()->has_initializer_); | 486 writer->Write<bool>(ptr()->has_initializer_); |
| 487 | 487 |
| 488 // Write out all the object pointer fields. | 488 // Write out all the object pointer fields. |
| 489 visitor.VisitPointers(from(), to()); | 489 visitor.VisitPointers(from(), to()); |
| 490 } | 490 } |
| 491 | 491 |
| 492 | 492 |
| 493 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, | 493 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, |
| 494 intptr_t object_id, | 494 intptr_t object_id, |
| 495 bool classes_serialized) { | 495 Snapshot::Kind kind) { |
| 496 ASSERT(reader != NULL); | 496 ASSERT(reader != NULL); |
| 497 | 497 |
| 498 // Read the length so that we can determine number of tokens to read. | 498 // Read the length so that we can determine number of tokens to read. |
| 499 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 499 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 500 intptr_t len = Smi::Value(smi_len); | 500 intptr_t len = Smi::Value(smi_len); |
| 501 | 501 |
| 502 // Create the token stream object. | 502 // Create the token stream object. |
| 503 TokenStream& token_stream = TokenStream::ZoneHandle(TokenStream::New(len)); | 503 TokenStream& token_stream = TokenStream::ZoneHandle(TokenStream::New(len)); |
| 504 reader->AddBackwardReference(object_id, &token_stream); | 504 reader->AddBackwardReference(object_id, &token_stream); |
| 505 | 505 |
| 506 // Read the token stream into the TokenStream. | 506 // Read the token stream into the TokenStream. |
| 507 String& literal = String::Handle(); | 507 String& literal = String::Handle(); |
| 508 for (intptr_t i = 0; i < len; i++) { | 508 for (intptr_t i = 0; i < len; i++) { |
| 509 Token::Kind kind = static_cast<Token::Kind>( | 509 Token::Kind kind = static_cast<Token::Kind>( |
| 510 Smi::Value(GetSmi(reader->Read<intptr_t>()))); | 510 Smi::Value(GetSmi(reader->Read<intptr_t>()))); |
| 511 literal ^= reader->ReadObject(); | 511 literal ^= reader->ReadObject(); |
| 512 token_stream.SetTokenAt(i, kind, literal); | 512 token_stream.SetTokenAt(i, kind, literal); |
| 513 } | 513 } |
| 514 return token_stream.raw(); | 514 return token_stream.raw(); |
| 515 } | 515 } |
| 516 | 516 |
| 517 | 517 |
| 518 void RawTokenStream::WriteTo(SnapshotWriter* writer, | 518 void RawTokenStream::WriteTo(SnapshotWriter* writer, |
| 519 intptr_t object_id, | 519 intptr_t object_id, |
| 520 bool serialize_classes) { | 520 Snapshot::Kind kind) { |
| 521 ASSERT(writer != NULL); | 521 ASSERT(writer != NULL); |
| 522 | 522 |
| 523 // Write out the serialization header value for this object. | 523 // Write out the serialization header value for this object. |
| 524 writer->WriteObjectHeader(kInlined, object_id); | 524 writer->WriteObjectHeader(kInlined, object_id); |
| 525 | 525 |
| 526 // Write out the class information. | 526 // Write out the class information. |
| 527 writer->WriteObjectHeader(kObjectId, Object::kTokenStreamClass); | 527 writer->WriteObjectHeader(kObjectId, Object::kTokenStreamClass); |
| 528 | 528 |
| 529 // Write out the length field. | 529 // Write out the length field. |
| 530 writer->Write<RawObject*>(ptr()->length_); | 530 writer->Write<RawObject*>(ptr()->length_); |
| 531 | 531 |
| 532 // Write out the token stream (token kind and literal). | 532 // Write out the token stream (token kind and literal). |
| 533 intptr_t len = Smi::Value(ptr()->length_); | 533 intptr_t len = Smi::Value(ptr()->length_); |
| 534 for (intptr_t i = 0; i < TokenStream::StreamLength(len); i++) { | 534 for (intptr_t i = 0; i < TokenStream::StreamLength(len); i++) { |
| 535 writer->WriteObject(ptr()->data_[i]); | 535 writer->WriteObject(ptr()->data_[i]); |
| 536 } | 536 } |
| 537 } | 537 } |
| 538 | 538 |
| 539 | 539 |
| 540 RawScript* Script::ReadFrom(SnapshotReader* reader, | 540 RawScript* Script::ReadFrom(SnapshotReader* reader, |
| 541 intptr_t object_id, | 541 intptr_t object_id, |
| 542 bool classes_serialized) { | 542 Snapshot::Kind kind) { |
| 543 ASSERT(reader != NULL); | 543 ASSERT(reader != NULL); |
| 544 | 544 |
| 545 // Allocate script object. | 545 // Allocate script object. |
| 546 Script& script = Script::ZoneHandle(Script::New()); | 546 Script& script = Script::ZoneHandle(Script::New()); |
| 547 reader->AddBackwardReference(object_id, &script); | 547 reader->AddBackwardReference(object_id, &script); |
| 548 | 548 |
| 549 // Set all the object fields. | 549 // Set all the object fields. |
| 550 // TODO(5411462): Need to assert No GC can happen here, even though | 550 // TODO(5411462): Need to assert No GC can happen here, even though |
| 551 // allocations may happen. | 551 // allocations may happen. |
| 552 intptr_t num_flds = (script.raw()->to() - script.raw()->from()); | 552 intptr_t num_flds = (script.raw()->to() - script.raw()->from()); |
| 553 for (intptr_t i = 0; i <= num_flds; i++) { | 553 for (intptr_t i = 0; i <= num_flds; i++) { |
| 554 *(script.raw()->from() + i) = reader->ReadObject(); | 554 *(script.raw()->from() + i) = reader->ReadObject(); |
| 555 } | 555 } |
| 556 | 556 |
| 557 return script.raw(); | 557 return script.raw(); |
| 558 } | 558 } |
| 559 | 559 |
| 560 | 560 |
| 561 void RawScript::WriteTo(SnapshotWriter* writer, | 561 void RawScript::WriteTo(SnapshotWriter* writer, |
| 562 intptr_t object_id, | 562 intptr_t object_id, |
| 563 bool serialize_classes) { | 563 Snapshot::Kind kind) { |
| 564 ASSERT(writer != NULL); | 564 ASSERT(writer != NULL); |
| 565 ASSERT(tokens_ != TokenStream::null()); | 565 ASSERT(tokens_ != TokenStream::null()); |
| 566 SnapshotWriterVisitor visitor(writer); | 566 SnapshotWriterVisitor visitor(writer); |
| 567 | 567 |
| 568 // Write out the serialization header value for this object. | 568 // Write out the serialization header value for this object. |
| 569 writer->WriteObjectHeader(kInlined, object_id); | 569 writer->WriteObjectHeader(kInlined, object_id); |
| 570 | 570 |
| 571 // Write out the class information. | 571 // Write out the class information. |
| 572 writer->WriteObjectHeader(kObjectId, Object::kScriptClass); | 572 writer->WriteObjectHeader(kObjectId, Object::kScriptClass); |
| 573 | 573 |
| 574 // Write out all the object pointer fields. | 574 // Write out all the object pointer fields. |
| 575 visitor.VisitPointers(from(), to()); | 575 visitor.VisitPointers(from(), to()); |
| 576 } | 576 } |
| 577 | 577 |
| 578 | 578 |
| 579 RawLibrary* Library::ReadFrom(SnapshotReader* reader, | 579 RawLibrary* Library::ReadFrom(SnapshotReader* reader, |
| 580 intptr_t object_id, | 580 intptr_t object_id, |
| 581 bool classes_serialized) { | 581 Snapshot::Kind kind) { |
| 582 ASSERT(reader != NULL); | 582 ASSERT(reader != NULL); |
| 583 | 583 |
| 584 // Allocate library object. | 584 // Allocate library object. |
| 585 Library& library = Library::ZoneHandle(Library::New()); | 585 Library& library = Library::ZoneHandle(Library::New()); |
| 586 reader->AddBackwardReference(object_id, &library); | 586 reader->AddBackwardReference(object_id, &library); |
| 587 | 587 |
| 588 // Set all non object fields. | 588 // Set all non object fields. |
| 589 library.raw_ptr()->num_imports_ = reader->Read<intptr_t>(); | 589 library.raw_ptr()->num_imports_ = reader->Read<intptr_t>(); |
| 590 library.raw_ptr()->num_imported_into_ = reader->Read<intptr_t>(); | 590 library.raw_ptr()->num_imported_into_ = reader->Read<intptr_t>(); |
| 591 library.raw_ptr()->num_anonymous_ = reader->Read<intptr_t>(); | 591 library.raw_ptr()->num_anonymous_ = reader->Read<intptr_t>(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 603 for (intptr_t i = 0; i <= num_flds; i++) { | 603 for (intptr_t i = 0; i <= num_flds; i++) { |
| 604 *(library.raw()->from() + i) = reader->ReadObject(); | 604 *(library.raw()->from() + i) = reader->ReadObject(); |
| 605 } | 605 } |
| 606 | 606 |
| 607 return library.raw(); | 607 return library.raw(); |
| 608 } | 608 } |
| 609 | 609 |
| 610 | 610 |
| 611 void RawLibrary::WriteTo(SnapshotWriter* writer, | 611 void RawLibrary::WriteTo(SnapshotWriter* writer, |
| 612 intptr_t object_id, | 612 intptr_t object_id, |
| 613 bool serialize_classes) { | 613 Snapshot::Kind kind) { |
| 614 ASSERT(writer != NULL); | 614 ASSERT(writer != NULL); |
| 615 SnapshotWriterVisitor visitor(writer); | 615 SnapshotWriterVisitor visitor(writer); |
| 616 | 616 |
| 617 // Write out the serialization header value for this object. | 617 // Write out the serialization header value for this object. |
| 618 writer->WriteObjectHeader(kInlined, object_id); | 618 writer->WriteObjectHeader(kInlined, object_id); |
| 619 | 619 |
| 620 // Write out the class information. | 620 // Write out the class information. |
| 621 writer->WriteObjectHeader(kObjectId, Object::kLibraryClass); | 621 writer->WriteObjectHeader(kObjectId, Object::kLibraryClass); |
| 622 | 622 |
| 623 writer->Write<intptr_t>(ptr()->num_imports_); | 623 writer->Write<intptr_t>(ptr()->num_imports_); |
| 624 writer->Write<intptr_t>(ptr()->num_imported_into_); | 624 writer->Write<intptr_t>(ptr()->num_imported_into_); |
| 625 writer->Write<intptr_t>(ptr()->num_anonymous_); | 625 writer->Write<intptr_t>(ptr()->num_anonymous_); |
| 626 writer->Write<bool>(ptr()->corelib_imported_); | 626 writer->Write<bool>(ptr()->corelib_imported_); |
| 627 writer->Write<int8_t>(ptr()->load_state_); | 627 writer->Write<int8_t>(ptr()->load_state_); |
| 628 // We do not serialize the native resolver over, this needs to be explicitly | 628 // We do not serialize the native resolver over, this needs to be explicitly |
| 629 // set after deserialization. | 629 // set after deserialization. |
| 630 writer->Write<Dart_NativeEntryResolver>(NULL); | 630 writer->Write<Dart_NativeEntryResolver>(NULL); |
| 631 | 631 |
| 632 // Write out all the object pointer fields. | 632 // Write out all the object pointer fields. |
| 633 visitor.VisitPointers(from(), to()); | 633 visitor.VisitPointers(from(), to()); |
| 634 } | 634 } |
| 635 | 635 |
| 636 | 636 |
| 637 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, | 637 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, |
| 638 intptr_t object_id, | 638 intptr_t object_id, |
| 639 bool classes_serialized) { | 639 Snapshot::Kind kind) { |
| 640 ASSERT(reader != NULL); | 640 ASSERT(reader != NULL); |
| 641 | 641 |
| 642 // Allocate library prefix object. | 642 // Allocate library prefix object. |
| 643 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(LibraryPrefix::New()); | 643 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(LibraryPrefix::New()); |
| 644 reader->AddBackwardReference(object_id, &prefix); | 644 reader->AddBackwardReference(object_id, &prefix); |
| 645 | 645 |
| 646 // Set all the object fields. | 646 // Set all the object fields. |
| 647 // TODO(5411462): Need to assert No GC can happen here, even though | 647 // TODO(5411462): Need to assert No GC can happen here, even though |
| 648 // allocations may happen. | 648 // allocations may happen. |
| 649 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); | 649 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); |
| 650 for (intptr_t i = 0; i <= num_flds; i++) { | 650 for (intptr_t i = 0; i <= num_flds; i++) { |
| 651 *(prefix.raw()->from() + i) = reader->ReadObject(); | 651 *(prefix.raw()->from() + i) = reader->ReadObject(); |
| 652 } | 652 } |
| 653 | 653 |
| 654 return prefix.raw(); | 654 return prefix.raw(); |
| 655 } | 655 } |
| 656 | 656 |
| 657 | 657 |
| 658 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, | 658 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, |
| 659 intptr_t object_id, | 659 intptr_t object_id, |
| 660 bool serialize_classes) { | 660 Snapshot::Kind kind) { |
| 661 ASSERT(writer != NULL); | 661 ASSERT(writer != NULL); |
| 662 SnapshotWriterVisitor visitor(writer); | 662 SnapshotWriterVisitor visitor(writer); |
| 663 | 663 |
| 664 // Write out the serialization header value for this object. | 664 // Write out the serialization header value for this object. |
| 665 writer->WriteObjectHeader(kInlined, object_id); | 665 writer->WriteObjectHeader(kInlined, object_id); |
| 666 | 666 |
| 667 // Write out the class information. | 667 // Write out the class information. |
| 668 writer->WriteObjectHeader(kObjectId, Object::kLibraryPrefixClass); | 668 writer->WriteObjectHeader(kObjectId, Object::kLibraryPrefixClass); |
| 669 | 669 |
| 670 // Write out all the object pointer fields. | 670 // Write out all the object pointer fields. |
| 671 visitor.VisitPointers(from(), to()); | 671 visitor.VisitPointers(from(), to()); |
| 672 } | 672 } |
| 673 | 673 |
| 674 | 674 |
| 675 RawCode* Code::ReadFrom(SnapshotReader* reader, | 675 RawCode* Code::ReadFrom(SnapshotReader* reader, |
| 676 intptr_t object_id, | 676 intptr_t object_id, |
| 677 bool classes_serialized) { | 677 Snapshot::Kind kind) { |
| 678 ASSERT(reader != NULL); | 678 ASSERT(reader != NULL); |
| 679 | 679 |
| 680 // Create Code object. | 680 // Create Code object. |
| 681 Code& code = Code::ZoneHandle(Code::New(0)); | 681 Code& code = Code::ZoneHandle(Code::New(0)); |
| 682 reader->AddBackwardReference(object_id, &code); | 682 reader->AddBackwardReference(object_id, &code); |
| 683 return code.raw(); | 683 return code.raw(); |
| 684 } | 684 } |
| 685 | 685 |
| 686 | 686 |
| 687 void RawCode::WriteTo(SnapshotWriter* writer, | 687 void RawCode::WriteTo(SnapshotWriter* writer, |
| 688 intptr_t object_id, | 688 intptr_t object_id, |
| 689 bool serialize_classes) { | 689 Snapshot::Kind kind) { |
| 690 // Currently we do not serialize any code and hence we write | 690 // Currently we do not serialize any code and hence we write |
| 691 // out a null object for it. | 691 // out a null object for it. |
| 692 ASSERT(writer != NULL); | 692 ASSERT(writer != NULL); |
| 693 | 693 |
| 694 writer->WriteObjectHeader(kObjectId, Object::kNullObject); | 694 writer->WriteObjectHeader(kObjectId, Object::kNullObject); |
| 695 } | 695 } |
| 696 | 696 |
| 697 | 697 |
| 698 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, | 698 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, |
| 699 intptr_t object_id, | 699 intptr_t object_id, |
| 700 bool classes_serialized) { | 700 Snapshot::Kind kind) { |
| 701 UNREACHABLE(); | 701 UNREACHABLE(); |
| 702 return Instructions::null(); | 702 return Instructions::null(); |
| 703 } | 703 } |
| 704 | 704 |
| 705 | 705 |
| 706 void RawInstructions::WriteTo(SnapshotWriter* writer, | 706 void RawInstructions::WriteTo(SnapshotWriter* writer, |
| 707 intptr_t object_id, | 707 intptr_t object_id, |
| 708 bool serialize_classes) { | 708 Snapshot::Kind kind) { |
| 709 UNREACHABLE(); | 709 UNREACHABLE(); |
| 710 } | 710 } |
| 711 | 711 |
| 712 | 712 |
| 713 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader, | 713 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader, |
| 714 intptr_t object_id, | 714 intptr_t object_id, |
| 715 bool classes_serialized) { | 715 Snapshot::Kind kind) { |
| 716 UNREACHABLE(); | 716 UNREACHABLE(); |
| 717 return PcDescriptors::null(); | 717 return PcDescriptors::null(); |
| 718 } | 718 } |
| 719 | 719 |
| 720 | 720 |
| 721 void RawPcDescriptors::WriteTo(SnapshotWriter* writer, | 721 void RawPcDescriptors::WriteTo(SnapshotWriter* writer, |
| 722 intptr_t object_id, | 722 intptr_t object_id, |
| 723 bool serialize_classes) { | 723 Snapshot::Kind kind) { |
| 724 UNREACHABLE(); | 724 UNREACHABLE(); |
| 725 } | 725 } |
| 726 | 726 |
| 727 | 727 |
| 728 RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader, | 728 RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader, |
| 729 intptr_t object_id, | 729 intptr_t object_id, |
| 730 bool classes_serialized) { | 730 Snapshot::Kind kind) { |
| 731 UNREACHABLE(); | 731 UNREACHABLE(); |
| 732 return ExceptionHandlers::null(); | 732 return ExceptionHandlers::null(); |
| 733 } | 733 } |
| 734 | 734 |
| 735 | 735 |
| 736 void RawExceptionHandlers::WriteTo(SnapshotWriter* writer, | 736 void RawExceptionHandlers::WriteTo(SnapshotWriter* writer, |
| 737 intptr_t object_id, | 737 intptr_t object_id, |
| 738 bool serialize_classes) { | 738 Snapshot::Kind kind) { |
| 739 UNREACHABLE(); | 739 UNREACHABLE(); |
| 740 } | 740 } |
| 741 | 741 |
| 742 | 742 |
| 743 RawContext* Context::ReadFrom(SnapshotReader* reader, | 743 RawContext* Context::ReadFrom(SnapshotReader* reader, |
| 744 intptr_t object_id, | 744 intptr_t object_id, |
| 745 bool classes_serialized) { | 745 Snapshot::Kind kind) { |
| 746 ASSERT(reader != NULL); | 746 ASSERT(reader != NULL); |
| 747 | 747 |
| 748 // Allocate context object. | 748 // Allocate context object. |
| 749 intptr_t num_vars = reader->Read<intptr_t>(); | 749 intptr_t num_vars = reader->Read<intptr_t>(); |
| 750 Context& context = Context::ZoneHandle( | 750 Context& context = Context::ZoneHandle( |
| 751 Context::New(num_vars, classes_serialized ? Heap::kOld : Heap::kNew)); | 751 Context::New(num_vars, |
| 752 (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | |
| 752 reader->AddBackwardReference(object_id, &context); | 753 reader->AddBackwardReference(object_id, &context); |
| 753 | 754 |
| 754 // Set the isolate implicitly. | 755 // Set the isolate implicitly. |
| 755 context.set_isolate(Isolate::Current()); | 756 context.set_isolate(Isolate::Current()); |
| 756 | 757 |
| 757 // Set all the object fields. | 758 // Set all the object fields. |
| 758 // TODO(5411462): Need to assert No GC can happen here, even though | 759 // TODO(5411462): Need to assert No GC can happen here, even though |
| 759 // allocations may happen. | 760 // allocations may happen. |
| 760 intptr_t num_flds = (context.raw()->to(num_vars) - context.raw()->from()); | 761 intptr_t num_flds = (context.raw()->to(num_vars) - context.raw()->from()); |
| 761 for (intptr_t i = 0; i <= num_flds; i++) { | 762 for (intptr_t i = 0; i <= num_flds; i++) { |
| 762 *(context.raw()->from() + i) = reader->ReadObject(); | 763 *(context.raw()->from() + i) = reader->ReadObject(); |
| 763 } | 764 } |
| 764 | 765 |
| 765 return context.raw(); | 766 return context.raw(); |
| 766 } | 767 } |
| 767 | 768 |
| 768 | 769 |
| 769 void RawContext::WriteTo(SnapshotWriter* writer, | 770 void RawContext::WriteTo(SnapshotWriter* writer, |
| 770 intptr_t object_id, | 771 intptr_t object_id, |
| 771 bool serialize_classes) { | 772 Snapshot::Kind kind) { |
| 772 ASSERT(writer != NULL); | 773 ASSERT(writer != NULL); |
| 773 SnapshotWriterVisitor visitor(writer); | 774 SnapshotWriterVisitor visitor(writer); |
| 774 | 775 |
| 775 // Write out the serialization header value for this object. | 776 // Write out the serialization header value for this object. |
| 776 writer->WriteObjectHeader(kInlined, object_id); | 777 writer->WriteObjectHeader(kInlined, object_id); |
| 777 | 778 |
| 778 // Write out the class information. | 779 // Write out the class information. |
| 779 writer->WriteObjectHeader(kObjectId, Object::kContextClass); | 780 writer->WriteObjectHeader(kObjectId, Object::kContextClass); |
| 780 | 781 |
| 781 // Write out num of variables in the context. | 782 // Write out num of variables in the context. |
| 782 writer->Write<intptr_t>(ptr()->num_variables_); | 783 writer->Write<intptr_t>(ptr()->num_variables_); |
| 783 | 784 |
| 784 // Can't serialize the isolate pointer, we set it implicitly on read. | 785 // Can't serialize the isolate pointer, we set it implicitly on read. |
| 785 | 786 |
| 786 // Write out all the object pointer fields. | 787 // Write out all the object pointer fields. |
| 787 visitor.VisitPointers(from(), to(ptr()->num_variables_)); | 788 visitor.VisitPointers(from(), to(ptr()->num_variables_)); |
| 788 } | 789 } |
| 789 | 790 |
| 790 | 791 |
| 791 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, | 792 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, |
| 792 intptr_t object_id, | 793 intptr_t object_id, |
| 793 bool classes_serialized) { | 794 Snapshot::Kind kind) { |
| 794 ASSERT(reader != NULL); | 795 ASSERT(reader != NULL); |
| 795 | 796 |
| 796 // Allocate context scope object. | 797 // Allocate context scope object. |
| 797 intptr_t num_vars = reader->Read<intptr_t>(); | 798 intptr_t num_vars = reader->Read<intptr_t>(); |
| 798 ContextScope& scope = ContextScope::ZoneHandle(ContextScope::New(num_vars)); | 799 ContextScope& scope = ContextScope::ZoneHandle(ContextScope::New(num_vars)); |
| 799 reader->AddBackwardReference(object_id, &scope); | 800 reader->AddBackwardReference(object_id, &scope); |
| 800 | 801 |
| 801 // Set all the object fields. | 802 // Set all the object fields. |
| 802 // TODO(5411462): Need to assert No GC can happen here, even though | 803 // TODO(5411462): Need to assert No GC can happen here, even though |
| 803 // allocations may happen. | 804 // allocations may happen. |
| 804 intptr_t num_flds = (scope.raw()->to(num_vars) - scope.raw()->from()); | 805 intptr_t num_flds = (scope.raw()->to(num_vars) - scope.raw()->from()); |
| 805 for (intptr_t i = 0; i <= num_flds; i++) { | 806 for (intptr_t i = 0; i <= num_flds; i++) { |
| 806 *(scope.raw()->from() + i) = reader->ReadObject(); | 807 *(scope.raw()->from() + i) = reader->ReadObject(); |
| 807 } | 808 } |
| 808 | 809 |
| 809 return scope.raw(); | 810 return scope.raw(); |
| 810 } | 811 } |
| 811 | 812 |
| 812 | 813 |
| 813 void RawContextScope::WriteTo(SnapshotWriter* writer, | 814 void RawContextScope::WriteTo(SnapshotWriter* writer, |
| 814 intptr_t object_id, | 815 intptr_t object_id, |
| 815 bool serialize_classes) { | 816 Snapshot::Kind kind) { |
| 816 ASSERT(writer != NULL); | 817 ASSERT(writer != NULL); |
| 817 SnapshotWriterVisitor visitor(writer); | 818 SnapshotWriterVisitor visitor(writer); |
| 818 | 819 |
| 819 // Write out the serialization header value for this object. | 820 // Write out the serialization header value for this object. |
| 820 writer->WriteObjectHeader(kInlined, object_id); | 821 writer->WriteObjectHeader(kInlined, object_id); |
| 821 | 822 |
| 822 // Write out the class information. | 823 // Write out the class information. |
| 823 writer->WriteObjectHeader(kObjectId, Object::kContextScopeClass); | 824 writer->WriteObjectHeader(kObjectId, Object::kContextScopeClass); |
| 824 | 825 |
| 825 // Serialize number of variables. | 826 // Serialize number of variables. |
| 826 writer->Write<intptr_t>(ptr()->num_variables_); | 827 writer->Write<intptr_t>(ptr()->num_variables_); |
| 827 | 828 |
| 828 // Write out all the object pointer fields. | 829 // Write out all the object pointer fields. |
| 829 visitor.VisitPointers(from(), to(ptr()->num_variables_)); | 830 visitor.VisitPointers(from(), to(ptr()->num_variables_)); |
| 830 } | 831 } |
| 831 | 832 |
| 832 | 833 |
| 833 RawUnhandledException* UnhandledException::ReadFrom(SnapshotReader* reader, | 834 RawUnhandledException* UnhandledException::ReadFrom(SnapshotReader* reader, |
| 834 intptr_t object_id, | 835 intptr_t object_id, |
| 835 bool classes_serialized) { | 836 Snapshot::Kind kind) { |
| 836 UNIMPLEMENTED(); | 837 UNIMPLEMENTED(); |
| 837 return UnhandledException::null(); | 838 return UnhandledException::null(); |
| 838 } | 839 } |
| 839 | 840 |
| 840 | 841 |
| 841 void RawUnhandledException::WriteTo(SnapshotWriter* writer, | 842 void RawUnhandledException::WriteTo(SnapshotWriter* writer, |
| 842 intptr_t object_id, | 843 intptr_t object_id, |
| 843 bool serialize_classes) { | 844 Snapshot::Kind kind) { |
| 844 UNIMPLEMENTED(); | 845 UNIMPLEMENTED(); |
| 845 } | 846 } |
| 846 | 847 |
| 847 | 848 |
| 848 RawApiError* ApiError::ReadFrom(SnapshotReader* reader, | 849 RawApiError* ApiError::ReadFrom(SnapshotReader* reader, |
| 849 intptr_t object_id, | 850 intptr_t object_id, |
| 850 bool classes_serialized) { | 851 Snapshot::Kind kind) { |
| 851 UNIMPLEMENTED(); | 852 UNIMPLEMENTED(); |
| 852 return ApiError::null(); | 853 return ApiError::null(); |
| 853 } | 854 } |
| 854 | 855 |
| 855 | 856 |
| 856 void RawApiError::WriteTo(SnapshotWriter* writer, | 857 void RawApiError::WriteTo(SnapshotWriter* writer, |
| 857 intptr_t object_id, | 858 intptr_t object_id, |
| 858 bool serialize_classes) { | 859 Snapshot::Kind kind) { |
| 859 UNIMPLEMENTED(); | 860 UNIMPLEMENTED(); |
| 860 } | 861 } |
| 861 | 862 |
| 862 | 863 |
| 863 RawInstance* Instance::ReadFrom(SnapshotReader* reader, | 864 RawInstance* Instance::ReadFrom(SnapshotReader* reader, |
| 864 intptr_t object_id, | 865 intptr_t object_id, |
| 865 bool classes_serialized) { | 866 Snapshot::Kind kind) { |
| 866 UNREACHABLE(); | 867 UNREACHABLE(); |
| 867 return Instance::null(); | 868 return Instance::null(); |
| 868 } | 869 } |
| 869 | 870 |
| 870 | 871 |
| 871 void RawInstance::WriteTo(SnapshotWriter* writer, | 872 void RawInstance::WriteTo(SnapshotWriter* writer, |
| 872 intptr_t object_id, | 873 intptr_t object_id, |
| 873 bool serialize_classes) { | 874 Snapshot::Kind kind) { |
| 874 UNREACHABLE(); | 875 UNREACHABLE(); |
| 875 } | 876 } |
| 876 | 877 |
| 877 | 878 |
| 878 RawMint* Mint::ReadFrom(SnapshotReader* reader, | 879 RawMint* Mint::ReadFrom(SnapshotReader* reader, |
| 879 intptr_t object_id, | 880 intptr_t object_id, |
| 880 bool classes_serialized) { | 881 Snapshot::Kind kind) { |
| 881 ASSERT(reader != NULL); | 882 ASSERT(reader != NULL); |
| 882 | 883 |
| 883 // Read the 64 bit value for the object. | 884 // Read the 64 bit value for the object. |
| 884 int64_t value = reader->Read<int64_t>(); | 885 int64_t value = reader->Read<int64_t>(); |
| 885 | 886 |
| 886 // Create a Mint object. | 887 // Create a Mint object. |
| 887 Mint& mint = Mint::ZoneHandle( | 888 Mint& mint = Mint::ZoneHandle( |
| 888 Mint::New(value, classes_serialized ? Heap::kOld : Heap::kNew)); | 889 Mint::New(value, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); |
| 889 reader->AddBackwardReference(object_id, &mint); | 890 reader->AddBackwardReference(object_id, &mint); |
| 890 return mint.raw(); | 891 return mint.raw(); |
| 891 } | 892 } |
| 892 | 893 |
| 893 | 894 |
| 894 void RawMint::WriteTo(SnapshotWriter* writer, | 895 void RawMint::WriteTo(SnapshotWriter* writer, |
| 895 intptr_t object_id, | 896 intptr_t object_id, |
| 896 bool serialize_classes) { | 897 Snapshot::Kind kind) { |
| 897 ASSERT(writer != NULL); | 898 ASSERT(writer != NULL); |
| 898 | 899 |
| 899 // Write out the serialization header value for this object. | 900 // Write out the serialization header value for this object. |
| 900 writer->WriteObjectHeader(kInlined, object_id); | 901 writer->WriteObjectHeader(kInlined, object_id); |
| 901 | 902 |
| 902 // Write out the class information. | 903 // Write out the class information. |
| 903 writer->WriteObjectHeader(kObjectId, ObjectStore::kMintClass); | 904 writer->WriteObjectHeader(kObjectId, ObjectStore::kMintClass); |
| 904 | 905 |
| 905 // Write out the 64 bit value. | 906 // Write out the 64 bit value. |
| 906 writer->Write<int64_t>(ptr()->value_); | 907 writer->Write<int64_t>(ptr()->value_); |
| 907 } | 908 } |
| 908 | 909 |
| 909 | 910 |
| 910 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, | 911 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, |
| 911 intptr_t object_id, | 912 intptr_t object_id, |
| 912 bool classes_serialized) { | 913 Snapshot::Kind kind) { |
| 913 ASSERT(reader != NULL); | 914 ASSERT(reader != NULL); |
| 914 // Read in the HexCString representation of the bigint. | 915 // Read in the HexCString representation of the bigint. |
| 915 intptr_t len = reader->Read<intptr_t>(); | 916 intptr_t len = reader->Read<intptr_t>(); |
| 916 char* str = reinterpret_cast<char*>(ZoneAllocator(len + 1)); | 917 char* str = reinterpret_cast<char*>(ZoneAllocator(len + 1)); |
| 917 str[len] = '\0'; | 918 str[len] = '\0'; |
| 918 for (intptr_t i = 0; i < len; i++) { | 919 for (intptr_t i = 0; i < len; i++) { |
| 919 str[i] = reader->Read<uint8_t>(); | 920 str[i] = reader->Read<uint8_t>(); |
| 920 } | 921 } |
| 921 // Create a Bigint object from HexCString. | 922 // Create a Bigint object from HexCString. |
| 922 Bigint& obj = Bigint::ZoneHandle(BigintOperations::FromHexCString(str)); | 923 Bigint& obj = Bigint::ZoneHandle(BigintOperations::FromHexCString(str)); |
| 923 reader->AddBackwardReference(object_id, &obj); | 924 reader->AddBackwardReference(object_id, &obj); |
| 924 return obj.raw(); | 925 return obj.raw(); |
| 925 } | 926 } |
| 926 | 927 |
| 927 | 928 |
| 928 void RawBigint::WriteTo(SnapshotWriter* writer, | 929 void RawBigint::WriteTo(SnapshotWriter* writer, |
| 929 intptr_t object_id, | 930 intptr_t object_id, |
| 930 bool serialize_classes) { | 931 Snapshot::Kind kind) { |
| 931 ASSERT(writer != NULL); | 932 ASSERT(writer != NULL); |
| 932 | 933 |
| 933 // Write out the serialization header value for this object. | 934 // Write out the serialization header value for this object. |
| 934 writer->WriteObjectHeader(kInlined, object_id); | 935 writer->WriteObjectHeader(kInlined, object_id); |
| 935 | 936 |
| 936 // Write out the class information. | 937 // Write out the class information. |
| 937 writer->WriteObjectHeader(kObjectId, ObjectStore::kBigintClass); | 938 writer->WriteObjectHeader(kObjectId, ObjectStore::kBigintClass); |
| 938 | 939 |
| 939 // Write out the bigint value as a HEXCstring. | 940 // Write out the bigint value as a HEXCstring. |
| 940 ptr()->bn_.d = ptr()->data_; | 941 ptr()->bn_.d = ptr()->data_; |
| 941 const char* str = BigintOperations::ToHexCString(&ptr()->bn_, &ZoneAllocator); | 942 const char* str = BigintOperations::ToHexCString(&ptr()->bn_, &ZoneAllocator); |
| 942 intptr_t len = strlen(str); | 943 intptr_t len = strlen(str); |
| 943 writer->Write<intptr_t>(len-2); | 944 writer->Write<intptr_t>(len-2); |
| 944 for (intptr_t i = 2; i < len; i++) { | 945 for (intptr_t i = 2; i < len; i++) { |
| 945 writer->Write<uint8_t>(str[i]); | 946 writer->Write<uint8_t>(str[i]); |
| 946 } | 947 } |
| 947 } | 948 } |
| 948 | 949 |
| 949 | 950 |
| 950 RawDouble* Double::ReadFrom(SnapshotReader* reader, | 951 RawDouble* Double::ReadFrom(SnapshotReader* reader, |
| 951 intptr_t object_id, | 952 intptr_t object_id, |
| 952 bool classes_serialized) { | 953 Snapshot::Kind kind) { |
| 953 ASSERT(reader != NULL); | 954 ASSERT(reader != NULL); |
| 954 // Read the double value for the object. | 955 // Read the double value for the object. |
| 955 double value = reader->Read<double>(); | 956 double value = reader->Read<double>(); |
| 956 // Create a double object. | 957 // Create a double object. |
| 957 Double& dbl = Double::ZoneHandle( | 958 Double& dbl = Double::ZoneHandle( |
| 958 Double::New(value, classes_serialized ? Heap::kOld : Heap::kNew)); | 959 Double::New(value, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); |
| 959 reader->AddBackwardReference(object_id, &dbl); | 960 reader->AddBackwardReference(object_id, &dbl); |
| 960 return dbl.raw(); | 961 return dbl.raw(); |
| 961 } | 962 } |
| 962 | 963 |
| 963 | 964 |
| 964 void RawDouble::WriteTo(SnapshotWriter* writer, | 965 void RawDouble::WriteTo(SnapshotWriter* writer, |
| 965 intptr_t object_id, | 966 intptr_t object_id, |
| 966 bool serialize_classes) { | 967 Snapshot::Kind kind) { |
| 967 ASSERT(writer != NULL); | 968 ASSERT(writer != NULL); |
| 968 | 969 |
| 969 // Write out the serialization header value for this object. | 970 // Write out the serialization header value for this object. |
| 970 writer->WriteObjectHeader(kInlined, object_id); | 971 writer->WriteObjectHeader(kInlined, object_id); |
| 971 | 972 |
| 972 // Write out the class information. | 973 // Write out the class information. |
| 973 writer->WriteObjectHeader(kObjectId, ObjectStore::kDoubleClass); | 974 writer->WriteObjectHeader(kObjectId, ObjectStore::kDoubleClass); |
| 974 | 975 |
| 975 // Write out the double value. | 976 // Write out the double value. |
| 976 writer->Write<double>(ptr()->value_); | 977 writer->Write<double>(ptr()->value_); |
| 977 } | 978 } |
| 978 | 979 |
| 979 | 980 |
| 980 RawString* String::ReadFrom(SnapshotReader* reader, | 981 RawString* String::ReadFrom(SnapshotReader* reader, |
| 981 intptr_t object_id, | 982 intptr_t object_id, |
| 982 bool classes_serialized) { | 983 Snapshot::Kind kind) { |
| 983 UNREACHABLE(); // String is an abstract class. | 984 UNREACHABLE(); // String is an abstract class. |
| 984 return String::null(); | 985 return String::null(); |
| 985 } | 986 } |
| 986 | 987 |
| 987 | 988 |
| 988 void RawString::WriteTo(SnapshotWriter* writer, | 989 void RawString::WriteTo(SnapshotWriter* writer, |
| 989 intptr_t object_id, | 990 intptr_t object_id, |
| 990 bool serialize_classes) { | 991 Snapshot::Kind kind) { |
| 991 UNREACHABLE(); // String is an abstract class. | 992 UNREACHABLE(); // String is an abstract class. |
| 992 } | 993 } |
| 993 | 994 |
| 994 | 995 |
| 995 template<typename HandleType, typename CharacterType> | 996 template<typename HandleType, typename CharacterType> |
| 996 RawString* String::ReadFromImpl(SnapshotReader* reader, | 997 RawString* String::ReadFromImpl(SnapshotReader* reader, |
| 997 intptr_t object_id, | 998 intptr_t object_id, |
| 998 bool classes_serialized) { | 999 Snapshot::Kind kind) { |
| 999 ASSERT(reader != NULL); | 1000 ASSERT(reader != NULL); |
| 1000 // Read the length so that we can determine instance size to allocate. | 1001 // Read the length so that we can determine instance size to allocate. |
| 1001 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 1002 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 1002 intptr_t len = Smi::Value(smi_len); | 1003 intptr_t len = Smi::Value(smi_len); |
| 1003 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | 1004 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); |
| 1004 | 1005 |
| 1005 // Set up the string object. | 1006 // Set up the string object. |
| 1006 HandleType& str_obj = HandleType::ZoneHandle( | 1007 HandleType& str_obj = HandleType::ZoneHandle(HandleType::New( |
| 1007 HandleType::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | 1008 len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); |
| 1008 for (intptr_t i = 0; i < len; i++) { | 1009 for (intptr_t i = 0; i < len; i++) { |
| 1009 *str_obj.CharAddr(i) = reader->Read<CharacterType>(); | 1010 *str_obj.CharAddr(i) = reader->Read<CharacterType>(); |
| 1010 } | 1011 } |
| 1011 reader->AddBackwardReference(object_id, &str_obj); | 1012 reader->AddBackwardReference(object_id, &str_obj); |
| 1012 str_obj.SetHash(Smi::Value(smi_hash)); | 1013 str_obj.SetHash(Smi::Value(smi_hash)); |
| 1013 return str_obj.raw(); | 1014 return str_obj.raw(); |
| 1014 } | 1015 } |
| 1015 | 1016 |
| 1016 | 1017 |
| 1017 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1018 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
| 1018 intptr_t object_id, | 1019 intptr_t object_id, |
| 1019 bool classes_serialized) { | 1020 Snapshot::Kind kind) { |
| 1020 return static_cast<RawOneByteString*>( | 1021 return static_cast<RawOneByteString*>( |
| 1021 ReadFromImpl<OneByteString, uint8_t>(reader, | 1022 ReadFromImpl<OneByteString, uint8_t>(reader, object_id, kind)); |
| 1022 object_id, | |
| 1023 classes_serialized)); | |
| 1024 } | 1023 } |
| 1025 | 1024 |
| 1026 | 1025 |
| 1027 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1026 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1028 intptr_t object_id, | 1027 intptr_t object_id, |
| 1029 bool classes_serialized) { | 1028 Snapshot::Kind kind) { |
| 1030 return static_cast<RawTwoByteString*>( | 1029 return static_cast<RawTwoByteString*>( |
| 1031 ReadFromImpl<TwoByteString, uint16_t>(reader, | 1030 ReadFromImpl<TwoByteString, uint16_t>(reader, |
| 1032 object_id, | 1031 object_id, |
| 1033 classes_serialized)); | 1032 kind)); |
|
turnidge
2011/12/05 18:49:00
Fit above on one line?
siva
2011/12/05 21:35:37
Done.
| |
| 1034 } | 1033 } |
| 1035 | 1034 |
| 1036 | 1035 |
| 1037 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | 1036 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, |
| 1038 intptr_t object_id, | 1037 intptr_t object_id, |
| 1039 bool classes_serialized) { | 1038 Snapshot::Kind kind) { |
| 1040 return static_cast<RawFourByteString*>( | 1039 return static_cast<RawFourByteString*>( |
| 1041 ReadFromImpl<FourByteString, uint32_t>(reader, | 1040 ReadFromImpl<FourByteString, uint32_t>(reader, object_id, kind)); |
| 1042 object_id, | |
| 1043 classes_serialized)); | |
| 1044 } | 1041 } |
| 1045 | 1042 |
| 1046 | 1043 |
| 1047 template<typename T> | 1044 template<typename T> |
| 1048 static void StringWriteTo(SnapshotWriter* writer, | 1045 static void StringWriteTo(SnapshotWriter* writer, |
| 1049 intptr_t object_id, | 1046 intptr_t object_id, |
| 1050 intptr_t class_id, | 1047 intptr_t class_id, |
| 1051 bool serialize_classes, | 1048 Snapshot::Kind kind, |
| 1052 RawSmi* length, | 1049 RawSmi* length, |
| 1053 RawSmi* hash, | 1050 RawSmi* hash, |
| 1054 T* data) { | 1051 T* data) { |
| 1055 ASSERT(writer != NULL); | 1052 ASSERT(writer != NULL); |
| 1056 intptr_t len = Smi::Value(length); | 1053 intptr_t len = Smi::Value(length); |
| 1057 | 1054 |
| 1058 // Write out the serialization header value for this object. | 1055 // Write out the serialization header value for this object. |
| 1059 writer->WriteObjectHeader(kInlined, object_id); | 1056 writer->WriteObjectHeader(kInlined, object_id); |
| 1060 | 1057 |
| 1061 // Write out the class information. | 1058 // Write out the class information. |
| 1062 writer->WriteObjectHeader(kObjectId, class_id); | 1059 writer->WriteObjectHeader(kObjectId, class_id); |
| 1063 | 1060 |
| 1064 // Write out the length field. | 1061 // Write out the length field. |
| 1065 writer->Write<RawObject*>(length); | 1062 writer->Write<RawObject*>(length); |
| 1066 | 1063 |
| 1067 // Write out the hash field. | 1064 // Write out the hash field. |
| 1068 writer->Write<RawObject*>(hash); | 1065 writer->Write<RawObject*>(hash); |
| 1069 | 1066 |
| 1070 // Write out the string. | 1067 // Write out the string. |
| 1071 for (intptr_t i = 0; i < len; i++) { | 1068 for (intptr_t i = 0; i < len; i++) { |
| 1072 writer->Write(data[i]); | 1069 writer->Write(data[i]); |
| 1073 } | 1070 } |
| 1074 } | 1071 } |
| 1075 | 1072 |
| 1076 | 1073 |
| 1077 void RawOneByteString::WriteTo(SnapshotWriter* writer, | 1074 void RawOneByteString::WriteTo(SnapshotWriter* writer, |
| 1078 intptr_t object_id, | 1075 intptr_t object_id, |
| 1079 bool serialize_classes) { | 1076 Snapshot::Kind kind) { |
| 1080 StringWriteTo(writer, | 1077 StringWriteTo(writer, |
| 1081 object_id, | 1078 object_id, |
| 1082 ObjectStore::kOneByteStringClass, | 1079 ObjectStore::kOneByteStringClass, |
| 1083 serialize_classes, | 1080 kind, |
| 1084 ptr()->length_, | 1081 ptr()->length_, |
| 1085 ptr()->hash_, | 1082 ptr()->hash_, |
| 1086 ptr()->data_); | 1083 ptr()->data_); |
| 1087 } | 1084 } |
| 1088 | 1085 |
| 1089 | 1086 |
| 1090 void RawTwoByteString::WriteTo(SnapshotWriter* writer, | 1087 void RawTwoByteString::WriteTo(SnapshotWriter* writer, |
| 1091 intptr_t object_id, | 1088 intptr_t object_id, |
| 1092 bool serialize_classes) { | 1089 Snapshot::Kind kind) { |
| 1093 StringWriteTo(writer, | 1090 StringWriteTo(writer, |
| 1094 object_id, | 1091 object_id, |
| 1095 ObjectStore::kTwoByteStringClass, | 1092 ObjectStore::kTwoByteStringClass, |
| 1096 serialize_classes, | 1093 kind, |
| 1097 ptr()->length_, | 1094 ptr()->length_, |
| 1098 ptr()->hash_, | 1095 ptr()->hash_, |
| 1099 ptr()->data_); | 1096 ptr()->data_); |
| 1100 } | 1097 } |
| 1101 | 1098 |
| 1102 | 1099 |
| 1103 void RawFourByteString::WriteTo(SnapshotWriter* writer, | 1100 void RawFourByteString::WriteTo(SnapshotWriter* writer, |
| 1104 intptr_t object_id, | 1101 intptr_t object_id, |
| 1105 bool serialize_classes) { | 1102 Snapshot::Kind kind) { |
| 1106 StringWriteTo(writer, | 1103 StringWriteTo(writer, |
| 1107 object_id, | 1104 object_id, |
| 1108 ObjectStore::kFourByteStringClass, | 1105 ObjectStore::kFourByteStringClass, |
| 1109 serialize_classes, | 1106 kind, |
| 1110 ptr()->length_, | 1107 ptr()->length_, |
| 1111 ptr()->hash_, | 1108 ptr()->hash_, |
| 1112 ptr()->data_); | 1109 ptr()->data_); |
| 1113 } | 1110 } |
| 1114 | 1111 |
| 1115 | 1112 |
| 1116 RawExternalOneByteString* ExternalOneByteString::ReadFrom( | 1113 RawExternalOneByteString* ExternalOneByteString::ReadFrom( |
| 1117 SnapshotReader* reader, | 1114 SnapshotReader* reader, |
| 1118 intptr_t object_id, | 1115 intptr_t object_id, |
| 1119 bool classes_serialized) { | 1116 Snapshot::Kind kind) { |
| 1120 UNREACHABLE(); | 1117 UNREACHABLE(); |
| 1121 return ExternalOneByteString::null(); | 1118 return ExternalOneByteString::null(); |
| 1122 } | 1119 } |
| 1123 | 1120 |
| 1124 | 1121 |
| 1125 RawExternalTwoByteString* ExternalTwoByteString::ReadFrom( | 1122 RawExternalTwoByteString* ExternalTwoByteString::ReadFrom( |
| 1126 SnapshotReader* reader, | 1123 SnapshotReader* reader, |
| 1127 intptr_t object_id, | 1124 intptr_t object_id, |
| 1128 bool classes_serialized) { | 1125 Snapshot::Kind kind) { |
| 1129 UNREACHABLE(); | 1126 UNREACHABLE(); |
| 1130 return ExternalTwoByteString::null(); | 1127 return ExternalTwoByteString::null(); |
| 1131 } | 1128 } |
| 1132 | 1129 |
| 1133 | 1130 |
| 1134 RawExternalFourByteString* ExternalFourByteString::ReadFrom( | 1131 RawExternalFourByteString* ExternalFourByteString::ReadFrom( |
| 1135 SnapshotReader* reader, | 1132 SnapshotReader* reader, |
| 1136 intptr_t object_id, | 1133 intptr_t object_id, |
| 1137 bool classes_serialized) { | 1134 Snapshot::Kind kind) { |
| 1138 UNREACHABLE(); | 1135 UNREACHABLE(); |
| 1139 return ExternalFourByteString::null(); | 1136 return ExternalFourByteString::null(); |
| 1140 } | 1137 } |
| 1141 | 1138 |
| 1142 | 1139 |
| 1143 void RawExternalOneByteString::WriteTo(SnapshotWriter* writer, | 1140 void RawExternalOneByteString::WriteTo(SnapshotWriter* writer, |
| 1144 intptr_t object_id, | 1141 intptr_t object_id, |
| 1145 bool serialize_classes) { | 1142 Snapshot::Kind kind) { |
| 1146 // Serialize as a non-external one byte string. | 1143 // Serialize as a non-external one byte string. |
| 1147 StringWriteTo(writer, | 1144 StringWriteTo(writer, |
| 1148 object_id, | 1145 object_id, |
| 1149 ObjectStore::kOneByteStringClass, | 1146 ObjectStore::kOneByteStringClass, |
| 1150 serialize_classes, | 1147 kind, |
| 1151 ptr()->length_, | 1148 ptr()->length_, |
| 1152 ptr()->hash_, | 1149 ptr()->hash_, |
| 1153 ptr()->external_data_->data_); | 1150 ptr()->external_data_->data_); |
| 1154 } | 1151 } |
| 1155 | 1152 |
| 1156 | 1153 |
| 1157 void RawExternalTwoByteString::WriteTo(SnapshotWriter* writer, | 1154 void RawExternalTwoByteString::WriteTo(SnapshotWriter* writer, |
| 1158 intptr_t object_id, | 1155 intptr_t object_id, |
| 1159 bool serialize_classes) { | 1156 Snapshot::Kind kind) { |
| 1160 // Serialize as a non-external two byte string. | 1157 // Serialize as a non-external two byte string. |
| 1161 StringWriteTo(writer, | 1158 StringWriteTo(writer, |
| 1162 object_id, | 1159 object_id, |
| 1163 ObjectStore::kTwoByteStringClass, | 1160 ObjectStore::kTwoByteStringClass, |
| 1164 serialize_classes, | 1161 kind, |
| 1165 ptr()->length_, | 1162 ptr()->length_, |
| 1166 ptr()->hash_, | 1163 ptr()->hash_, |
| 1167 ptr()->external_data_->data_); | 1164 ptr()->external_data_->data_); |
| 1168 } | 1165 } |
| 1169 | 1166 |
| 1170 | 1167 |
| 1171 void RawExternalFourByteString::WriteTo(SnapshotWriter* writer, | 1168 void RawExternalFourByteString::WriteTo(SnapshotWriter* writer, |
| 1172 intptr_t object_id, | 1169 intptr_t object_id, |
| 1173 bool serialize_classes) { | 1170 Snapshot::Kind kind) { |
| 1174 // Serialize as a non-external four byte string. | 1171 // Serialize as a non-external four byte string. |
| 1175 StringWriteTo(writer, | 1172 StringWriteTo(writer, |
| 1176 object_id, | 1173 object_id, |
| 1177 ObjectStore::kFourByteStringClass, | 1174 ObjectStore::kFourByteStringClass, |
| 1178 serialize_classes, | 1175 kind, |
| 1179 ptr()->length_, | 1176 ptr()->length_, |
| 1180 ptr()->hash_, | 1177 ptr()->hash_, |
| 1181 ptr()->external_data_->data_); | 1178 ptr()->external_data_->data_); |
| 1182 } | 1179 } |
| 1183 | 1180 |
| 1184 | 1181 |
| 1185 RawBool* Bool::ReadFrom(SnapshotReader* reader, | 1182 RawBool* Bool::ReadFrom(SnapshotReader* reader, |
| 1186 intptr_t object_id, | 1183 intptr_t object_id, |
| 1187 bool classes_serialized) { | 1184 Snapshot::Kind kind) { |
| 1188 UNREACHABLE(); | 1185 UNREACHABLE(); |
| 1189 return Bool::null(); | 1186 return Bool::null(); |
| 1190 } | 1187 } |
| 1191 | 1188 |
| 1192 | 1189 |
| 1193 void RawBool::WriteTo(SnapshotWriter* writer, | 1190 void RawBool::WriteTo(SnapshotWriter* writer, |
| 1194 intptr_t object_id, | 1191 intptr_t object_id, |
| 1195 bool serialize_classes) { | 1192 Snapshot::Kind kind) { |
| 1196 UNREACHABLE(); | 1193 UNREACHABLE(); |
| 1197 } | 1194 } |
| 1198 | 1195 |
| 1199 | 1196 |
| 1200 template <class T> | 1197 template <class T> |
| 1201 static RawObject* ArrayReadFrom(SnapshotReader* reader, | 1198 static RawObject* ArrayReadFrom(SnapshotReader* reader, |
| 1202 intptr_t object_id, | 1199 intptr_t object_id, |
| 1203 bool classes_serialized) { | 1200 Snapshot::Kind kind) { |
| 1204 ASSERT(reader != NULL); | 1201 ASSERT(reader != NULL); |
| 1205 | 1202 |
| 1206 // Read the length so that we can determine instance size to allocate. | 1203 // Read the length so that we can determine instance size to allocate. |
| 1207 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 1204 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 1208 intptr_t len = Smi::Value(smi_len); | 1205 intptr_t len = Smi::Value(smi_len); |
| 1209 T& result = T::Handle(T::New(len, | 1206 T& result = T::Handle( |
| 1210 classes_serialized ? Heap::kOld : Heap::kNew)); | 1207 T::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); |
| 1211 reader->AddBackwardReference(object_id, &result); | 1208 reader->AddBackwardReference(object_id, &result); |
| 1212 | 1209 |
| 1213 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 1210 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 1214 type_arguments ^= reader->ReadObject(); | 1211 type_arguments ^= reader->ReadObject(); |
| 1215 result.SetTypeArguments(type_arguments); | 1212 result.SetTypeArguments(type_arguments); |
| 1216 | 1213 |
| 1217 Object& obj = Object::Handle(); | 1214 Object& obj = Object::Handle(); |
| 1218 for (intptr_t i = 0; i < len; i++) { | 1215 for (intptr_t i = 0; i < len; i++) { |
| 1219 obj = reader->ReadObject(); | 1216 obj = reader->ReadObject(); |
| 1220 result.SetAt(i, obj); | 1217 result.SetAt(i, obj); |
| 1221 } | 1218 } |
| 1222 return result.raw(); | 1219 return result.raw(); |
| 1223 } | 1220 } |
| 1224 | 1221 |
| 1225 | 1222 |
| 1226 RawArray* Array::ReadFrom(SnapshotReader* reader, | 1223 RawArray* Array::ReadFrom(SnapshotReader* reader, |
| 1227 intptr_t object_id, | 1224 intptr_t object_id, |
| 1228 bool classes_serialized) { | 1225 Snapshot::Kind kind) { |
| 1229 return reinterpret_cast<RawArray*>(ArrayReadFrom<Array>(reader, | 1226 return reinterpret_cast<RawArray*>(ArrayReadFrom<Array>(reader, |
| 1230 object_id, | 1227 object_id, |
| 1231 classes_serialized)); | 1228 kind)); |
| 1232 } | 1229 } |
| 1233 | 1230 |
| 1234 | 1231 |
| 1235 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, | 1232 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, |
| 1236 intptr_t object_id, | 1233 intptr_t object_id, |
| 1237 bool classes_serialized) { | 1234 Snapshot::Kind kind) { |
| 1238 return reinterpret_cast<RawImmutableArray*>( | 1235 return reinterpret_cast<RawImmutableArray*>( |
| 1239 ArrayReadFrom<ImmutableArray>(reader, object_id, classes_serialized)); | 1236 ArrayReadFrom<ImmutableArray>(reader, object_id, kind)); |
| 1240 } | 1237 } |
| 1241 | 1238 |
| 1242 | 1239 |
| 1243 static void ArrayWriteTo(SnapshotWriter* writer, | 1240 static void ArrayWriteTo(SnapshotWriter* writer, |
| 1244 intptr_t object_id, | 1241 intptr_t object_id, |
| 1245 bool serialize_classes, | 1242 Snapshot::Kind kind, |
| 1246 intptr_t kind, | 1243 intptr_t array_kind, |
| 1247 RawSmi* length, | 1244 RawSmi* length, |
| 1248 RawAbstractTypeArguments* type_arguments, | 1245 RawAbstractTypeArguments* type_arguments, |
| 1249 RawObject* data[]) { | 1246 RawObject* data[]) { |
| 1250 ASSERT(writer != NULL); | 1247 ASSERT(writer != NULL); |
| 1251 intptr_t len = Smi::Value(length); | 1248 intptr_t len = Smi::Value(length); |
| 1252 | 1249 |
| 1253 // Write out the serialization header value for this object. | 1250 // Write out the serialization header value for this object. |
| 1254 writer->WriteObjectHeader(kInlined, object_id); | 1251 writer->WriteObjectHeader(kInlined, object_id); |
| 1255 | 1252 |
| 1256 // Write out the class information. | 1253 // Write out the class information. |
| 1257 writer->WriteObjectHeader(kObjectId, kind); | 1254 writer->WriteObjectHeader(kObjectId, array_kind); |
| 1258 | 1255 |
| 1259 // Write out the length field. | 1256 // Write out the length field. |
| 1260 writer->Write<RawObject*>(length); | 1257 writer->Write<RawObject*>(length); |
| 1261 | 1258 |
| 1262 // Write out the type arguments. | 1259 // Write out the type arguments. |
| 1263 writer->WriteObject(type_arguments); | 1260 writer->WriteObject(type_arguments); |
| 1264 | 1261 |
| 1265 // Write out the individual objects. | 1262 // Write out the individual objects. |
| 1266 for (intptr_t i = 0; i < len; i++) { | 1263 for (intptr_t i = 0; i < len; i++) { |
| 1267 writer->WriteObject(data[i]); | 1264 writer->WriteObject(data[i]); |
| 1268 } | 1265 } |
| 1269 } | 1266 } |
| 1270 | 1267 |
| 1271 | 1268 |
| 1272 void RawArray::WriteTo(SnapshotWriter* writer, | 1269 void RawArray::WriteTo(SnapshotWriter* writer, |
| 1273 intptr_t object_id, | 1270 intptr_t object_id, |
| 1274 bool serialize_classes) { | 1271 Snapshot::Kind kind) { |
| 1275 ArrayWriteTo(writer, | 1272 ArrayWriteTo(writer, |
| 1276 object_id, | 1273 object_id, |
| 1277 serialize_classes, | 1274 kind, |
| 1278 ObjectStore::kArrayClass, | 1275 ObjectStore::kArrayClass, |
| 1279 ptr()->length_, | 1276 ptr()->length_, |
| 1280 ptr()->type_arguments_, | 1277 ptr()->type_arguments_, |
| 1281 ptr()->data()); | 1278 ptr()->data()); |
| 1282 } | 1279 } |
| 1283 | 1280 |
| 1284 | 1281 |
| 1285 void RawImmutableArray::WriteTo(SnapshotWriter* writer, | 1282 void RawImmutableArray::WriteTo(SnapshotWriter* writer, |
| 1286 intptr_t object_id, | 1283 intptr_t object_id, |
| 1287 bool serialize_classes) { | 1284 Snapshot::Kind kind) { |
| 1288 ArrayWriteTo(writer, | 1285 ArrayWriteTo(writer, |
| 1289 object_id, | 1286 object_id, |
| 1290 serialize_classes, | 1287 kind, |
| 1291 ObjectStore::kImmutableArrayClass, | 1288 ObjectStore::kImmutableArrayClass, |
| 1292 ptr()->length_, | 1289 ptr()->length_, |
| 1293 ptr()->type_arguments_, | 1290 ptr()->type_arguments_, |
| 1294 ptr()->data()); | 1291 ptr()->data()); |
| 1295 } | 1292 } |
| 1296 | 1293 |
| 1297 | 1294 |
| 1298 RawByteBuffer* ByteBuffer::ReadFrom(SnapshotReader* reader, | 1295 RawByteBuffer* ByteBuffer::ReadFrom(SnapshotReader* reader, |
| 1299 intptr_t object_id, | 1296 intptr_t object_id, |
| 1300 bool classes_serialized) { | 1297 Snapshot::Kind kind) { |
| 1301 UNIMPLEMENTED(); | 1298 UNIMPLEMENTED(); |
| 1302 return ByteBuffer::null(); | 1299 return ByteBuffer::null(); |
| 1303 } | 1300 } |
| 1304 | 1301 |
| 1305 | 1302 |
| 1306 void RawByteBuffer::WriteTo(SnapshotWriter* writer, | 1303 void RawByteBuffer::WriteTo(SnapshotWriter* writer, |
| 1307 intptr_t object_id, | 1304 intptr_t object_id, |
| 1308 bool serialize_classes) { | 1305 Snapshot::Kind kind) { |
| 1309 UNIMPLEMENTED(); | 1306 UNIMPLEMENTED(); |
| 1310 } | 1307 } |
| 1311 | 1308 |
| 1312 | 1309 |
| 1313 RawClosure* Closure::ReadFrom(SnapshotReader* reader, | 1310 RawClosure* Closure::ReadFrom(SnapshotReader* reader, |
| 1314 intptr_t object_id, | 1311 intptr_t object_id, |
| 1315 bool classes_serialized) { | 1312 Snapshot::Kind kind) { |
| 1316 UNIMPLEMENTED(); | 1313 UNIMPLEMENTED(); |
| 1317 return Closure::null(); | 1314 return Closure::null(); |
| 1318 } | 1315 } |
| 1319 | 1316 |
| 1320 | 1317 |
| 1321 void RawClosure::WriteTo(SnapshotWriter* writer, | 1318 void RawClosure::WriteTo(SnapshotWriter* writer, |
| 1322 intptr_t object_id, | 1319 intptr_t object_id, |
| 1323 bool serialize_classes) { | 1320 Snapshot::Kind kind) { |
| 1324 UNIMPLEMENTED(); | 1321 UNIMPLEMENTED(); |
| 1325 } | 1322 } |
| 1326 | 1323 |
| 1327 | 1324 |
| 1328 RawStacktrace* Stacktrace::ReadFrom(SnapshotReader* reader, | 1325 RawStacktrace* Stacktrace::ReadFrom(SnapshotReader* reader, |
| 1329 intptr_t object_id, | 1326 intptr_t object_id, |
| 1330 bool classes_serialized) { | 1327 Snapshot::Kind kind) { |
| 1331 UNIMPLEMENTED(); | 1328 UNIMPLEMENTED(); |
| 1332 return Stacktrace::null(); | 1329 return Stacktrace::null(); |
| 1333 } | 1330 } |
| 1334 | 1331 |
| 1335 | 1332 |
| 1336 void RawStacktrace::WriteTo(SnapshotWriter* writer, | 1333 void RawStacktrace::WriteTo(SnapshotWriter* writer, |
| 1337 intptr_t object_id, | 1334 intptr_t object_id, |
| 1338 bool serialize_classes) { | 1335 Snapshot::Kind kind) { |
| 1339 UNIMPLEMENTED(); | 1336 UNIMPLEMENTED(); |
| 1340 } | 1337 } |
| 1341 | 1338 |
| 1342 | 1339 |
| 1343 RawJSRegExp* JSRegExp::ReadFrom(SnapshotReader* reader, | 1340 RawJSRegExp* JSRegExp::ReadFrom(SnapshotReader* reader, |
| 1344 intptr_t object_id, | 1341 intptr_t object_id, |
| 1345 bool classes_serialized) { | 1342 Snapshot::Kind kind) { |
| 1346 ASSERT(reader != NULL); | 1343 ASSERT(reader != NULL); |
| 1347 | 1344 |
| 1348 // Read the length so that we can determine instance size to allocate. | 1345 // Read the length so that we can determine instance size to allocate. |
| 1349 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 1346 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 1350 intptr_t len = Smi::Value(smi_len); | 1347 intptr_t len = Smi::Value(smi_len); |
| 1351 | 1348 |
| 1352 // Allocate JSRegExp object. | 1349 // Allocate JSRegExp object. |
| 1353 JSRegExp& regex = JSRegExp::ZoneHandle( | 1350 JSRegExp& regex = JSRegExp::ZoneHandle( |
| 1354 JSRegExp::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | 1351 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); |
| 1355 reader->AddBackwardReference(object_id, ®ex); | 1352 reader->AddBackwardReference(object_id, ®ex); |
| 1356 | 1353 |
| 1357 // Read and Set all the other fields. | 1354 // Read and Set all the other fields. |
| 1358 regex.raw_ptr()->num_bracket_expressions_ = GetSmi(reader->Read<intptr_t>()); | 1355 regex.raw_ptr()->num_bracket_expressions_ = GetSmi(reader->Read<intptr_t>()); |
| 1359 String& pattern = String::Handle(); | 1356 String& pattern = String::Handle(); |
| 1360 pattern ^= reader->ReadObject(); | 1357 pattern ^= reader->ReadObject(); |
| 1361 regex.raw_ptr()->pattern_ = pattern.raw(); | 1358 regex.raw_ptr()->pattern_ = pattern.raw(); |
| 1362 regex.raw_ptr()->type_ = reader->Read<intptr_t>(); | 1359 regex.raw_ptr()->type_ = reader->Read<intptr_t>(); |
| 1363 regex.raw_ptr()->flags_ = reader->Read<intptr_t>(); | 1360 regex.raw_ptr()->flags_ = reader->Read<intptr_t>(); |
| 1364 | 1361 |
| 1365 // TODO(5411462): Need to implement a way of recompiling the regex. | 1362 // TODO(5411462): Need to implement a way of recompiling the regex. |
| 1366 | 1363 |
| 1367 return regex.raw(); | 1364 return regex.raw(); |
| 1368 } | 1365 } |
| 1369 | 1366 |
| 1370 | 1367 |
| 1371 void RawJSRegExp::WriteTo(SnapshotWriter* writer, | 1368 void RawJSRegExp::WriteTo(SnapshotWriter* writer, |
| 1372 intptr_t object_id, | 1369 intptr_t object_id, |
| 1373 bool serialize_classes) { | 1370 Snapshot::Kind kind) { |
| 1374 ASSERT(writer != NULL); | 1371 ASSERT(writer != NULL); |
| 1375 | 1372 |
| 1376 // Write out the serialization header value for this object. | 1373 // Write out the serialization header value for this object. |
| 1377 writer->WriteObjectHeader(kInlined, object_id); | 1374 writer->WriteObjectHeader(kInlined, object_id); |
| 1378 | 1375 |
| 1379 // Write out the class information. | 1376 // Write out the class information. |
| 1380 writer->WriteObjectHeader(kObjectId, ObjectStore::kJSRegExpClass); | 1377 writer->WriteObjectHeader(kObjectId, ObjectStore::kJSRegExpClass); |
| 1381 | 1378 |
| 1382 // Write out the data length field. | 1379 // Write out the data length field. |
| 1383 writer->Write<RawObject*>(ptr()->data_length_); | 1380 writer->Write<RawObject*>(ptr()->data_length_); |
| 1384 | 1381 |
| 1385 // Write out all the other fields. | 1382 // Write out all the other fields. |
| 1386 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 1383 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); |
| 1387 writer->WriteObject(ptr()->pattern_); | 1384 writer->WriteObject(ptr()->pattern_); |
| 1388 writer->Write<intptr_t>(ptr()->type_); | 1385 writer->Write<intptr_t>(ptr()->type_); |
| 1389 writer->Write<intptr_t>(ptr()->flags_); | 1386 writer->Write<intptr_t>(ptr()->flags_); |
| 1390 | 1387 |
| 1391 // Do not write out the data part which is native. | 1388 // Do not write out the data part which is native. |
| 1392 } | 1389 } |
| 1393 | 1390 |
| 1394 } // namespace dart | 1391 } // namespace dart |
| OLD | NEW |