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

Side by Side Diff: vm/raw_object_snapshot.cc

Issue 10535066: 1. Remove recursion during snapshot writing and reading (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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 | « vm/dart_api_message.cc ('k') | vm/snapshot.h » ('j') | 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/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
(...skipping 23 matching lines...) Expand all
34 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { 34 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) {
35 // Read in the base information. 35 // Read in the base information.
36 ObjectKind object_kind = reader->Read<ObjectKind>(); 36 ObjectKind object_kind = reader->Read<ObjectKind>();
37 37
38 // Allocate class object of specified kind. 38 // Allocate class object of specified kind.
39 if (kind == Snapshot::kFull) { 39 if (kind == Snapshot::kFull) {
40 cls = reader->NewClass(object_kind); 40 cls = reader->NewClass(object_kind);
41 } else { 41 } else {
42 cls = Class::GetClass(object_kind); 42 cls = Class::GetClass(object_kind);
43 } 43 }
44 reader->AddBackwardReference(object_id, &cls); 44 reader->AddBackRef(object_id, &cls, kIsDeserialized);
45 45
46 // Set the object tags. 46 // Set the object tags.
47 cls.set_tags(tags); 47 cls.set_tags(tags);
48 48
49 // Set all non object fields. 49 // Set all non object fields.
50 cls.set_instance_size(reader->ReadIntptrValue()); 50 cls.set_instance_size(reader->ReadIntptrValue());
51 cls.set_type_arguments_instance_field_offset(reader->ReadIntptrValue()); 51 cls.set_type_arguments_instance_field_offset(reader->ReadIntptrValue());
52 cls.set_next_field_offset(reader->ReadIntptrValue()); 52 cls.set_next_field_offset(reader->ReadIntptrValue());
53 cls.set_num_native_fields(reader->ReadIntptrValue()); 53 cls.set_num_native_fields(reader->ReadIntptrValue());
54 cls.set_token_index(reader->ReadIntptrValue()); 54 cls.set_token_index(reader->ReadIntptrValue());
55 cls.set_class_state(reader->Read<int8_t>()); 55 cls.set_class_state(reader->Read<int8_t>());
56 if (reader->Read<bool>()) { 56 if (reader->Read<bool>()) {
57 cls.set_is_const(); 57 cls.set_is_const();
58 } 58 }
59 if (reader->Read<bool>()) { 59 if (reader->Read<bool>()) {
60 cls.set_is_interface(); 60 cls.set_is_interface();
61 } 61 }
62 62
63 // Set all the object fields. 63 // Set all the object fields.
64 // TODO(5411462): Need to assert No GC can happen here, even though 64 // TODO(5411462): Need to assert No GC can happen here, even though
65 // allocations may happen. 65 // allocations may happen.
66 intptr_t num_flds = (cls.raw()->to() - cls.raw()->from()); 66 intptr_t num_flds = (cls.raw()->to() - cls.raw()->from());
67 for (intptr_t i = 0; i <= num_flds; i++) { 67 for (intptr_t i = 0; i <= num_flds; i++) {
68 *(cls.raw()->from() + i) = reader->ReadObject(); 68 *(cls.raw()->from() + i) = reader->ReadObjectRef();
69 } 69 }
70 } else { 70 } else {
71 cls ^= reader->ReadClassId(object_id); 71 cls ^= reader->ReadClassId(object_id);
72 } 72 }
73 return cls.raw(); 73 return cls.raw();
74 } 74 }
75 75
76 76
77 void RawClass::WriteTo(SnapshotWriter* writer, 77 void RawClass::WriteTo(SnapshotWriter* writer,
78 intptr_t object_id, 78 intptr_t object_id,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, 112 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader,
113 intptr_t object_id, 113 intptr_t object_id,
114 intptr_t tags, 114 intptr_t tags,
115 Snapshot::Kind kind) { 115 Snapshot::Kind kind) {
116 ASSERT(reader != NULL); 116 ASSERT(reader != NULL);
117 117
118 // Allocate parameterized type object. 118 // Allocate parameterized type object.
119 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( 119 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle(
120 reader->isolate(), NEW_OBJECT(UnresolvedClass)); 120 reader->isolate(), NEW_OBJECT(UnresolvedClass));
121 reader->AddBackwardReference(object_id, &unresolved_class); 121 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized);
122 122
123 // Set the object tags. 123 // Set the object tags.
124 unresolved_class.set_tags(tags); 124 unresolved_class.set_tags(tags);
125 125
126 // Set all non object fields. 126 // Set all non object fields.
127 unresolved_class.set_token_index(reader->ReadIntptrValue()); 127 unresolved_class.set_token_index(reader->ReadIntptrValue());
128 128
129 // Set all the object fields. 129 // Set all the object fields.
130 // TODO(5411462): Need to assert No GC can happen here, even though 130 // TODO(5411462): Need to assert No GC can happen here, even though
131 // allocations may happen. 131 // allocations may happen.
132 intptr_t num_flds = (unresolved_class.raw()->to() - 132 intptr_t num_flds = (unresolved_class.raw()->to() -
133 unresolved_class.raw()->from()); 133 unresolved_class.raw()->from());
134 for (intptr_t i = 0; i <= num_flds; i++) { 134 for (intptr_t i = 0; i <= num_flds; i++) {
135 *(unresolved_class.raw()->from() + i) = reader->ReadObject(); 135 *(unresolved_class.raw()->from() + i) = reader->ReadObjectRef();
136 } 136 }
137 return unresolved_class.raw(); 137 return unresolved_class.raw();
138 } 138 }
139 139
140 140
141 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, 141 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer,
142 intptr_t object_id, 142 intptr_t object_id,
143 Snapshot::Kind kind) { 143 Snapshot::Kind kind) {
144 ASSERT(writer != NULL); 144 ASSERT(writer != NULL);
145 145
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 RawType* Type::ReadFrom(SnapshotReader* reader, 178 RawType* Type::ReadFrom(SnapshotReader* reader,
179 intptr_t object_id, 179 intptr_t object_id,
180 intptr_t tags, 180 intptr_t tags,
181 Snapshot::Kind kind) { 181 Snapshot::Kind kind) {
182 ASSERT(reader != NULL); 182 ASSERT(reader != NULL);
183 183
184 // Allocate parameterized type object. 184 // Allocate parameterized type object.
185 Type& parameterized_type = Type::ZoneHandle( 185 Type& parameterized_type = Type::ZoneHandle(
186 reader->isolate(), NEW_OBJECT(Type)); 186 reader->isolate(), NEW_OBJECT(Type));
187 reader->AddBackwardReference(object_id, &parameterized_type); 187 reader->AddBackRef(object_id, &parameterized_type, kIsDeserialized);
188 188
189 // Set the object tags. 189 // Set the object tags.
190 parameterized_type.set_tags(tags); 190 parameterized_type.set_tags(tags);
191 191
192 // Set all non object fields. 192 // Set all non object fields.
193 parameterized_type.set_token_index(reader->ReadIntptrValue()); 193 parameterized_type.set_token_index(reader->ReadIntptrValue());
194 parameterized_type.set_type_state(reader->Read<int8_t>()); 194 parameterized_type.set_type_state(reader->Read<int8_t>());
195 195
196 // Set all the object fields. 196 // Set all the object fields.
197 // TODO(5411462): Need to assert No GC can happen here, even though 197 // TODO(5411462): Need to assert No GC can happen here, even though
198 // allocations may happen. 198 // allocations may happen.
199 intptr_t num_flds = (parameterized_type.raw()->to() - 199 intptr_t num_flds = (parameterized_type.raw()->to() -
200 parameterized_type.raw()->from()); 200 parameterized_type.raw()->from());
201 for (intptr_t i = 0; i <= num_flds; i++) { 201 for (intptr_t i = 0; i <= num_flds; i++) {
202 *(parameterized_type.raw()->from() + i) = reader->ReadObject(); 202 *(parameterized_type.raw()->from() + i) = reader->ReadObjectImpl();
203 } 203 }
204 204
205 // If object needs to be a canonical object, Canonicalize it. 205 // If object needs to be a canonical object, Canonicalize it.
206 if ((kind != Snapshot::kFull) && parameterized_type.IsCanonical()) { 206 if ((kind != Snapshot::kFull) && parameterized_type.IsCanonical()) {
207 parameterized_type ^= parameterized_type.Canonicalize(); 207 parameterized_type ^= parameterized_type.Canonicalize();
208 } 208 }
209 return parameterized_type.raw(); 209 return parameterized_type.raw();
210 } 210 }
211 211
212 212
213 void RawType::WriteTo(SnapshotWriter* writer, 213 void RawType::WriteTo(SnapshotWriter* writer,
214 intptr_t object_id, 214 intptr_t object_id,
215 Snapshot::Kind kind) { 215 Snapshot::Kind kind) {
216 ASSERT(writer != NULL); 216 ASSERT(writer != NULL);
217 217
218 // Write out the serialization header value for this object. 218 // Write out the serialization header value for this object.
219 writer->WriteSerializationMarker(kInlined, object_id); 219 writer->WriteSerializationMarker(kInlined, object_id);
220 220
221 // Write out the class and tags information. 221 // Write out the class and tags information.
222 writer->WriteObjectHeader(Object::kTypeClass, writer->GetObjectTags(this)); 222 writer->WriteObjectHeader(Object::kTypeClass, writer->GetObjectTags(this));
223 223
224 // Write out all the non object pointer fields. 224 // Write out all the non object pointer fields.
225 writer->WriteIntptrValue(ptr()->token_index_); 225 writer->WriteIntptrValue(ptr()->token_index_);
226 writer->Write<int8_t>(ptr()->type_state_); 226 writer->Write<int8_t>(ptr()->type_state_);
227 227
228 // Write out all the object pointer fields. 228 // Write out all the object pointer fields.
229 SnapshotWriterVisitor visitor(writer); 229 SnapshotWriterVisitor visitor(writer, false);
230 visitor.VisitPointers(from(), to()); 230 visitor.VisitPointers(from(), to());
231 } 231 }
232 232
233 233
234 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, 234 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader,
235 intptr_t object_id, 235 intptr_t object_id,
236 intptr_t tags, 236 intptr_t tags,
237 Snapshot::Kind kind) { 237 Snapshot::Kind kind) {
238 ASSERT(reader != NULL); 238 ASSERT(reader != NULL);
239 239
240 // Allocate type parameter object. 240 // Allocate type parameter object.
241 TypeParameter& type_parameter = TypeParameter::ZoneHandle( 241 TypeParameter& type_parameter = TypeParameter::ZoneHandle(
242 reader->isolate(), NEW_OBJECT(TypeParameter)); 242 reader->isolate(), NEW_OBJECT(TypeParameter));
243 reader->AddBackwardReference(object_id, &type_parameter); 243 reader->AddBackRef(object_id, &type_parameter, kIsDeserialized);
244 244
245 // Set the object tags. 245 // Set the object tags.
246 type_parameter.set_tags(tags); 246 type_parameter.set_tags(tags);
247 247
248 // Set all non object fields. 248 // Set all non object fields.
249 type_parameter.set_index(reader->ReadIntptrValue()); 249 type_parameter.set_index(reader->ReadIntptrValue());
250 type_parameter.set_token_index(reader->ReadIntptrValue()); 250 type_parameter.set_token_index(reader->ReadIntptrValue());
251 type_parameter.set_type_state(reader->Read<int8_t>()); 251 type_parameter.set_type_state(reader->Read<int8_t>());
252 252
253 // Set all the object fields. 253 // Set all the object fields.
254 // TODO(5411462): Need to assert No GC can happen here, even though 254 // TODO(5411462): Need to assert No GC can happen here, even though
255 // allocations may happen. 255 // allocations may happen.
256 intptr_t num_flds = (type_parameter.raw()->to() - 256 intptr_t num_flds = (type_parameter.raw()->to() -
257 type_parameter.raw()->from()); 257 type_parameter.raw()->from());
258 for (intptr_t i = 0; i <= num_flds; i++) { 258 for (intptr_t i = 0; i <= num_flds; i++) {
259 *(type_parameter.raw()->from() + i) = reader->ReadObject(); 259 *(type_parameter.raw()->from() + i) = reader->ReadObjectImpl();
260 } 260 }
261 261
262 return type_parameter.raw(); 262 return type_parameter.raw();
263 } 263 }
264 264
265 265
266 void RawTypeParameter::WriteTo(SnapshotWriter* writer, 266 void RawTypeParameter::WriteTo(SnapshotWriter* writer,
267 intptr_t object_id, 267 intptr_t object_id,
268 Snapshot::Kind kind) { 268 Snapshot::Kind kind) {
269 ASSERT(writer != NULL); 269 ASSERT(writer != NULL);
270 270
271 // Write out the serialization header value for this object. 271 // Write out the serialization header value for this object.
272 writer->WriteSerializationMarker(kInlined, object_id); 272 writer->WriteSerializationMarker(kInlined, object_id);
273 273
274 // Write out the class and tags information. 274 // Write out the class and tags information.
275 writer->WriteObjectHeader(Object::kTypeParameterClass, 275 writer->WriteObjectHeader(Object::kTypeParameterClass,
276 writer->GetObjectTags(this)); 276 writer->GetObjectTags(this));
277 277
278 // Write out all the non object pointer fields. 278 // Write out all the non object pointer fields.
279 writer->WriteIntptrValue(ptr()->index_); 279 writer->WriteIntptrValue(ptr()->index_);
280 writer->WriteIntptrValue(ptr()->token_index_); 280 writer->WriteIntptrValue(ptr()->token_index_);
281 writer->Write<int8_t>(ptr()->type_state_); 281 writer->Write<int8_t>(ptr()->type_state_);
282 282
283 // Write out all the object pointer fields. 283 // Write out all the object pointer fields.
284 SnapshotWriterVisitor visitor(writer); 284 SnapshotWriterVisitor visitor(writer, false);
285 visitor.VisitPointers(from(), to()); 285 visitor.VisitPointers(from(), to());
286 } 286 }
287 287
288 288
289 RawAbstractTypeArguments* AbstractTypeArguments::ReadFrom( 289 RawAbstractTypeArguments* AbstractTypeArguments::ReadFrom(
290 SnapshotReader* reader, 290 SnapshotReader* reader,
291 intptr_t object_id, 291 intptr_t object_id,
292 intptr_t tags, 292 intptr_t tags,
293 Snapshot::Kind kind) { 293 Snapshot::Kind kind) {
294 UNREACHABLE(); // AbstractTypeArguments is an abstract class. 294 UNREACHABLE(); // AbstractTypeArguments is an abstract class.
(...skipping 12 matching lines...) Expand all
307 intptr_t object_id, 307 intptr_t object_id,
308 intptr_t tags, 308 intptr_t tags,
309 Snapshot::Kind kind) { 309 Snapshot::Kind kind) {
310 ASSERT(reader != NULL); 310 ASSERT(reader != NULL);
311 311
312 // Read the length so that we can determine instance size to allocate. 312 // Read the length so that we can determine instance size to allocate.
313 intptr_t len = reader->ReadSmiValue(); 313 intptr_t len = reader->ReadSmiValue();
314 314
315 TypeArguments& type_arguments = TypeArguments::ZoneHandle( 315 TypeArguments& type_arguments = TypeArguments::ZoneHandle(
316 reader->isolate(), NEW_OBJECT_WITH_LEN(TypeArguments, len)); 316 reader->isolate(), NEW_OBJECT_WITH_LEN(TypeArguments, len));
317 reader->AddBackwardReference(object_id, &type_arguments); 317 reader->AddBackRef(object_id, &type_arguments, kIsDeserialized);
318 318
319 // Now set all the object fields. 319 // Now set all the object fields.
320 for (intptr_t i = 0; i < len; i++) { 320 for (intptr_t i = 0; i < len; i++) {
321 *reader->TypeHandle() ^= reader->ReadObject(); 321 *reader->TypeHandle() ^= reader->ReadObjectImpl();
322 type_arguments.SetTypeAt(i, *reader->TypeHandle()); 322 type_arguments.SetTypeAt(i, *reader->TypeHandle());
323 } 323 }
324 324
325 // Set the object tags (This is done after setting the object fields 325 // Set the object tags (This is done after setting the object fields
326 // because 'SetTypeAt' has an assertion to check if the object is not 326 // because 'SetTypeAt' has an assertion to check if the object is not
327 // already canonical). 327 // already canonical).
328 type_arguments.set_tags(tags); 328 type_arguments.set_tags(tags);
329 329
330 // If object needs to be a canonical object, Canonicalize it. 330 // If object needs to be a canonical object, Canonicalize it.
331 if ((kind != Snapshot::kFull) && type_arguments.IsCanonical()) { 331 if ((kind != Snapshot::kFull) && type_arguments.IsCanonical()) {
(...skipping 14 matching lines...) Expand all
346 // Write out the class and tags information. 346 // Write out the class and tags information.
347 writer->WriteObjectHeader(Object::kTypeArgumentsClass, 347 writer->WriteObjectHeader(Object::kTypeArgumentsClass,
348 writer->GetObjectTags(this)); 348 writer->GetObjectTags(this));
349 349
350 // Write out the length field. 350 // Write out the length field.
351 writer->Write<RawObject*>(ptr()->length_); 351 writer->Write<RawObject*>(ptr()->length_);
352 352
353 // Write out the individual types. 353 // Write out the individual types.
354 intptr_t len = Smi::Value(ptr()->length_); 354 intptr_t len = Smi::Value(ptr()->length_);
355 for (intptr_t i = 0; i < len; i++) { 355 for (intptr_t i = 0; i < len; i++) {
356 writer->WriteObject(ptr()->types_[i]); 356 writer->WriteObjectImpl(ptr()->types_[i]);
357 } 357 }
358 } 358 }
359 359
360 360
361 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( 361 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom(
362 SnapshotReader* reader, 362 SnapshotReader* reader,
363 intptr_t object_id, 363 intptr_t object_id,
364 intptr_t tags, 364 intptr_t tags,
365 Snapshot::Kind kind) { 365 Snapshot::Kind kind) {
366 ASSERT(reader != NULL); 366 ASSERT(reader != NULL);
367 ASSERT(kind == Snapshot::kMessage); 367 ASSERT(kind == Snapshot::kMessage);
368 368
369 // Allocate instantiated types object. 369 // Allocate instantiated types object.
370 InstantiatedTypeArguments& instantiated_type_arguments = 370 InstantiatedTypeArguments& instantiated_type_arguments =
371 InstantiatedTypeArguments::ZoneHandle(reader->isolate(), 371 InstantiatedTypeArguments::ZoneHandle(reader->isolate(),
372 InstantiatedTypeArguments::New()); 372 InstantiatedTypeArguments::New());
373 reader->AddBackwardReference(object_id, &instantiated_type_arguments); 373 reader->AddBackRef(object_id, &instantiated_type_arguments, kIsDeserialized);
374 374
375 // Set the object tags. 375 // Set the object tags.
376 instantiated_type_arguments.set_tags(tags); 376 instantiated_type_arguments.set_tags(tags);
377 377
378 // Set all the object fields. 378 // Set all the object fields.
379 // TODO(5411462): Need to assert No GC can happen here, even though 379 // TODO(5411462): Need to assert No GC can happen here, even though
380 // allocations may happen. 380 // allocations may happen.
381 intptr_t num_flds = (instantiated_type_arguments.raw()->to() - 381 intptr_t num_flds = (instantiated_type_arguments.raw()->to() -
382 instantiated_type_arguments.raw()->from()); 382 instantiated_type_arguments.raw()->from());
383 for (intptr_t i = 0; i <= num_flds; i++) { 383 for (intptr_t i = 0; i <= num_flds; i++) {
384 *(instantiated_type_arguments.raw()->from() + i) = reader->ReadObject(); 384 *(instantiated_type_arguments.raw()->from() + i) = reader->ReadObjectImpl();
385 } 385 }
386 return instantiated_type_arguments.raw(); 386 return instantiated_type_arguments.raw();
387 } 387 }
388 388
389 389
390 void RawInstantiatedTypeArguments::WriteTo(SnapshotWriter* writer, 390 void RawInstantiatedTypeArguments::WriteTo(SnapshotWriter* writer,
391 intptr_t object_id, 391 intptr_t object_id,
392 Snapshot::Kind kind) { 392 Snapshot::Kind kind) {
393 ASSERT(writer != NULL); 393 ASSERT(writer != NULL);
394 ASSERT(kind == Snapshot::kMessage); 394 ASSERT(kind == Snapshot::kMessage);
395 395
396 // Write out the serialization header value for this object. 396 // Write out the serialization header value for this object.
397 writer->WriteSerializationMarker(kInlined, object_id); 397 writer->WriteSerializationMarker(kInlined, object_id);
398 398
399 // Write out the class and tags information. 399 // Write out the class and tags information.
400 writer->WriteObjectHeader(Object::kInstantiatedTypeArgumentsClass, 400 writer->WriteObjectHeader(Object::kInstantiatedTypeArgumentsClass,
401 writer->GetObjectTags(this)); 401 writer->GetObjectTags(this));
402 402
403 // Write out all the object pointer fields. 403 // Write out all the object pointer fields.
404 SnapshotWriterVisitor visitor(writer); 404 SnapshotWriterVisitor visitor(writer, false);
405 visitor.VisitPointers(from(), to()); 405 visitor.VisitPointers(from(), to());
406 } 406 }
407 407
408 408
409 RawFunction* Function::ReadFrom(SnapshotReader* reader, 409 RawFunction* Function::ReadFrom(SnapshotReader* reader,
410 intptr_t object_id, 410 intptr_t object_id,
411 intptr_t tags, 411 intptr_t tags,
412 Snapshot::Kind kind) { 412 Snapshot::Kind kind) {
413 ASSERT(reader != NULL); 413 ASSERT(reader != NULL);
414 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); 414 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
415 415
416 // Allocate function object. 416 // Allocate function object.
417 Function& func = Function::ZoneHandle( 417 Function& func = Function::ZoneHandle(
418 reader->isolate(), NEW_OBJECT(Function)); 418 reader->isolate(), NEW_OBJECT(Function));
419 reader->AddBackwardReference(object_id, &func); 419 reader->AddBackRef(object_id, &func, kIsDeserialized);
420 420
421 // Set the object tags. 421 // Set the object tags.
422 func.set_tags(tags); 422 func.set_tags(tags);
423 423
424 // Set all the non object fields. 424 // Set all the non object fields.
425 func.set_token_index(reader->ReadIntptrValue()); 425 func.set_token_index(reader->ReadIntptrValue());
426 func.set_end_token_index(reader->ReadIntptrValue()); 426 func.set_end_token_index(reader->ReadIntptrValue());
427 func.set_num_fixed_parameters(reader->ReadIntptrValue()); 427 func.set_num_fixed_parameters(reader->ReadIntptrValue());
428 func.set_num_optional_parameters(reader->ReadIntptrValue()); 428 func.set_num_optional_parameters(reader->ReadIntptrValue());
429 func.set_usage_counter(reader->ReadIntptrValue()); 429 func.set_usage_counter(reader->ReadIntptrValue());
430 func.set_deoptimization_counter(reader->ReadIntptrValue()); 430 func.set_deoptimization_counter(reader->ReadIntptrValue());
431 func.set_kind(static_cast<RawFunction::Kind >(reader->ReadIntptrValue())); 431 func.set_kind(static_cast<RawFunction::Kind >(reader->ReadIntptrValue()));
432 func.set_is_static(reader->Read<bool>()); 432 func.set_is_static(reader->Read<bool>());
433 func.set_is_const(reader->Read<bool>()); 433 func.set_is_const(reader->Read<bool>());
434 func.set_is_optimizable(reader->Read<bool>()); 434 func.set_is_optimizable(reader->Read<bool>());
435 435
436 // Set all the object fields. 436 // Set all the object fields.
437 // TODO(5411462): Need to assert No GC can happen here, even though 437 // TODO(5411462): Need to assert No GC can happen here, even though
438 // allocations may happen. 438 // allocations may happen.
439 intptr_t num_flds = (func.raw()->to() - func.raw()->from()); 439 intptr_t num_flds = (func.raw()->to() - func.raw()->from());
440 for (intptr_t i = 0; i <= num_flds; i++) { 440 for (intptr_t i = 0; i <= num_flds; i++) {
441 *(func.raw()->from() + i) = reader->ReadObject(); 441 *(func.raw()->from() + i) = reader->ReadObjectRef();
442 } 442 }
443 443
444 return func.raw(); 444 return func.raw();
445 } 445 }
446 446
447 447
448 void RawFunction::WriteTo(SnapshotWriter* writer, 448 void RawFunction::WriteTo(SnapshotWriter* writer,
449 intptr_t object_id, 449 intptr_t object_id,
450 Snapshot::Kind kind) { 450 Snapshot::Kind kind) {
451 ASSERT(writer != NULL); 451 ASSERT(writer != NULL);
(...skipping 27 matching lines...) Expand all
479 479
480 RawField* Field::ReadFrom(SnapshotReader* reader, 480 RawField* Field::ReadFrom(SnapshotReader* reader,
481 intptr_t object_id, 481 intptr_t object_id,
482 intptr_t tags, 482 intptr_t tags,
483 Snapshot::Kind kind) { 483 Snapshot::Kind kind) {
484 ASSERT(reader != NULL); 484 ASSERT(reader != NULL);
485 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); 485 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
486 486
487 // Allocate field object. 487 // Allocate field object.
488 Field& field = Field::ZoneHandle(reader->isolate(), NEW_OBJECT(Field)); 488 Field& field = Field::ZoneHandle(reader->isolate(), NEW_OBJECT(Field));
489 reader->AddBackwardReference(object_id, &field); 489 reader->AddBackRef(object_id, &field, kIsDeserialized);
490 490
491 // Set the object tags. 491 // Set the object tags.
492 field.set_tags(tags); 492 field.set_tags(tags);
493 493
494 // Set all non object fields. 494 // Set all non object fields.
495 field.set_token_index(reader->ReadIntptrValue()); 495 field.set_token_index(reader->ReadIntptrValue());
496 field.set_is_static(reader->Read<bool>()); 496 field.set_is_static(reader->Read<bool>());
497 field.set_is_final(reader->Read<bool>()); 497 field.set_is_final(reader->Read<bool>());
498 field.set_has_initializer(reader->Read<bool>()); 498 field.set_has_initializer(reader->Read<bool>());
499 499
500 // Set all the object fields. 500 // Set all the object fields.
501 // TODO(5411462): Need to assert No GC can happen here, even though 501 // TODO(5411462): Need to assert No GC can happen here, even though
502 // allocations may happen. 502 // allocations may happen.
503 intptr_t num_flds = (field.raw()->to() - field.raw()->from()); 503 intptr_t num_flds = (field.raw()->to() - field.raw()->from());
504 for (intptr_t i = 0; i <= num_flds; i++) { 504 for (intptr_t i = 0; i <= num_flds; i++) {
505 *(field.raw()->from() + i) = reader->ReadObject(); 505 *(field.raw()->from() + i) = reader->ReadObjectRef();
506 } 506 }
507 507
508 return field.raw(); 508 return field.raw();
509 } 509 }
510 510
511 511
512 void RawField::WriteTo(SnapshotWriter* writer, 512 void RawField::WriteTo(SnapshotWriter* writer,
513 intptr_t object_id, 513 intptr_t object_id,
514 Snapshot::Kind kind) { 514 Snapshot::Kind kind) {
515 ASSERT(writer != NULL); 515 ASSERT(writer != NULL);
(...skipping 21 matching lines...) Expand all
537 RawLiteralToken* LiteralToken::ReadFrom(SnapshotReader* reader, 537 RawLiteralToken* LiteralToken::ReadFrom(SnapshotReader* reader,
538 intptr_t object_id, 538 intptr_t object_id,
539 intptr_t tags, 539 intptr_t tags,
540 Snapshot::Kind kind) { 540 Snapshot::Kind kind) {
541 ASSERT(reader != NULL); 541 ASSERT(reader != NULL);
542 ASSERT(kind != Snapshot::kMessage); 542 ASSERT(kind != Snapshot::kMessage);
543 543
544 // Create the literal token object. 544 // Create the literal token object.
545 LiteralToken& literal_token = LiteralToken::ZoneHandle( 545 LiteralToken& literal_token = LiteralToken::ZoneHandle(
546 reader->isolate(), NEW_OBJECT(LiteralToken)); 546 reader->isolate(), NEW_OBJECT(LiteralToken));
547 reader->AddBackwardReference(object_id, &literal_token); 547 reader->AddBackRef(object_id, &literal_token, kIsDeserialized);
548 548
549 // Set the object tags. 549 // Set the object tags.
550 literal_token.set_tags(tags); 550 literal_token.set_tags(tags);
551 551
552 // Read the token attributes. 552 // Read the token attributes.
553 Token::Kind token_kind = static_cast<Token::Kind>(reader->ReadIntptrValue()); 553 Token::Kind token_kind = static_cast<Token::Kind>(reader->ReadIntptrValue());
554 literal_token.set_kind(token_kind); 554 literal_token.set_kind(token_kind);
555 *reader->StringHandle() ^= reader->ReadObject(); 555 *reader->StringHandle() ^= reader->ReadObjectImpl();
556 literal_token.set_literal(*reader->StringHandle()); 556 literal_token.set_literal(*reader->StringHandle());
557 *reader->ObjectHandle() = reader->ReadObject(); 557 *reader->ObjectHandle() = reader->ReadObjectImpl();
558 literal_token.set_value(*reader->ObjectHandle()); 558 literal_token.set_value(*reader->ObjectHandle());
559 559
560 return literal_token.raw(); 560 return literal_token.raw();
561 } 561 }
562 562
563 563
564 void RawLiteralToken::WriteTo(SnapshotWriter* writer, 564 void RawLiteralToken::WriteTo(SnapshotWriter* writer,
565 intptr_t object_id, 565 intptr_t object_id,
566 Snapshot::Kind kind) { 566 Snapshot::Kind kind) {
567 ASSERT(writer != NULL); 567 ASSERT(writer != NULL);
568 ASSERT(kind != Snapshot::kMessage); 568 ASSERT(kind != Snapshot::kMessage);
569 569
570 // Write out the serialization header value for this object. 570 // Write out the serialization header value for this object.
571 writer->WriteSerializationMarker(kInlined, object_id); 571 writer->WriteSerializationMarker(kInlined, object_id);
572 572
573 // Write out the class and tags information. 573 // Write out the class and tags information.
574 writer->WriteObjectHeader(Object::kLiteralTokenClass, 574 writer->WriteObjectHeader(Object::kLiteralTokenClass,
575 writer->GetObjectTags(this)); 575 writer->GetObjectTags(this));
576 576
577 // Write out the kind field. 577 // Write out the kind field.
578 writer->Write<intptr_t>(ptr()->kind_); 578 writer->Write<intptr_t>(ptr()->kind_);
579 579
580 // Write out literal and value fields. 580 // Write out literal and value fields.
581 writer->WriteObject(ptr()->literal_); 581 writer->WriteObjectImpl(ptr()->literal_);
582 writer->WriteObject(ptr()->value_); 582 writer->WriteObjectImpl(ptr()->value_);
583 } 583 }
584 584
585 585
586 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, 586 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader,
587 intptr_t object_id, 587 intptr_t object_id,
588 intptr_t tags, 588 intptr_t tags,
589 Snapshot::Kind kind) { 589 Snapshot::Kind kind) {
590 ASSERT(reader != NULL); 590 ASSERT(reader != NULL);
591 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); 591 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
592 592
593 // Read the length so that we can determine number of tokens to read. 593 // Read the length so that we can determine number of tokens to read.
594 intptr_t len = reader->ReadSmiValue(); 594 intptr_t len = reader->ReadSmiValue();
595 595
596 // Create the token stream object. 596 // Create the token stream object.
597 TokenStream& token_stream = TokenStream::ZoneHandle( 597 TokenStream& token_stream = TokenStream::ZoneHandle(
598 reader->isolate(), NEW_OBJECT_WITH_LEN(TokenStream, len)); 598 reader->isolate(), NEW_OBJECT_WITH_LEN(TokenStream, len));
599 reader->AddBackwardReference(object_id, &token_stream); 599 reader->AddBackRef(object_id, &token_stream, kIsDeserialized);
600 600
601 // Set the object tags. 601 // Set the object tags.
602 token_stream.set_tags(tags); 602 token_stream.set_tags(tags);
603 603
604 // Read the token stream into the TokenStream. 604 // Read the token stream into the TokenStream.
605 for (intptr_t i = 0; i < len; i++) { 605 for (intptr_t i = 0; i < len; i++) {
606 *reader->ObjectHandle() = reader->ReadObject(); 606 *reader->ObjectHandle() = reader->ReadObjectImpl();
607 token_stream.SetTokenAt(i, *reader->ObjectHandle()); 607 token_stream.SetTokenAt(i, *reader->ObjectHandle());
608 } 608 }
609 return token_stream.raw(); 609 return token_stream.raw();
610 } 610 }
611 611
612 612
613 void RawTokenStream::WriteTo(SnapshotWriter* writer, 613 void RawTokenStream::WriteTo(SnapshotWriter* writer,
614 intptr_t object_id, 614 intptr_t object_id,
615 Snapshot::Kind kind) { 615 Snapshot::Kind kind) {
616 ASSERT(writer != NULL); 616 ASSERT(writer != NULL);
617 ASSERT(kind != Snapshot::kMessage && 617 ASSERT(kind != Snapshot::kMessage &&
618 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); 618 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this)));
619 619
620 // Write out the serialization header value for this object. 620 // Write out the serialization header value for this object.
621 writer->WriteSerializationMarker(kInlined, object_id); 621 writer->WriteSerializationMarker(kInlined, object_id);
622 622
623 // Write out the class and tags information. 623 // Write out the class and tags information.
624 writer->WriteObjectHeader(Object::kTokenStreamClass, 624 writer->WriteObjectHeader(Object::kTokenStreamClass,
625 writer->GetObjectTags(this)); 625 writer->GetObjectTags(this));
626 626
627 // Write out the length field. 627 // Write out the length field.
628 writer->Write<RawObject*>(ptr()->length_); 628 writer->Write<RawObject*>(ptr()->length_);
629 629
630 // Write out the token stream (token kind and literal). 630 // Write out the token stream (token kind and literal).
631 intptr_t len = Smi::Value(ptr()->length_); 631 intptr_t len = Smi::Value(ptr()->length_);
632 for (intptr_t i = 0; i < TokenStream::StreamLength(len); i++) { 632 for (intptr_t i = 0; i < TokenStream::StreamLength(len); i++) {
633 writer->WriteObject(ptr()->data_[i]); 633 writer->WriteObjectImpl(ptr()->data_[i]);
634 } 634 }
635 } 635 }
636 636
637 637
638 RawScript* Script::ReadFrom(SnapshotReader* reader, 638 RawScript* Script::ReadFrom(SnapshotReader* reader,
639 intptr_t object_id, 639 intptr_t object_id,
640 intptr_t tags, 640 intptr_t tags,
641 Snapshot::Kind kind) { 641 Snapshot::Kind kind) {
642 ASSERT(reader != NULL); 642 ASSERT(reader != NULL);
643 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); 643 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
644 644
645 // Allocate script object. 645 // Allocate script object.
646 Script& script = Script::ZoneHandle(reader->isolate(), NEW_OBJECT(Script)); 646 Script& script = Script::ZoneHandle(reader->isolate(), NEW_OBJECT(Script));
647 reader->AddBackwardReference(object_id, &script); 647 reader->AddBackRef(object_id, &script, kIsDeserialized);
648 648
649 // Set the object tags. 649 // Set the object tags.
650 script.set_tags(tags); 650 script.set_tags(tags);
651 651
652 // Set all the object fields. 652 // Set all the object fields.
653 // TODO(5411462): Need to assert No GC can happen here, even though 653 // TODO(5411462): Need to assert No GC can happen here, even though
654 // allocations may happen. 654 // allocations may happen.
655 *reader->StringHandle() ^= reader->ReadObject(); 655 *reader->StringHandle() ^= reader->ReadObjectImpl();
656 script.set_url(*reader->StringHandle()); 656 script.set_url(*reader->StringHandle());
657 *reader->StringHandle() ^= String::null(); 657 *reader->StringHandle() ^= String::null();
658 script.set_source(*reader->StringHandle()); 658 script.set_source(*reader->StringHandle());
659 TokenStream& stream = TokenStream::Handle(); 659 TokenStream& stream = TokenStream::Handle();
660 stream ^= reader->ReadObject(); 660 stream ^= reader->ReadObjectImpl();
661 script.set_tokens(stream); 661 script.set_tokens(stream);
662 662
663 return script.raw(); 663 return script.raw();
664 } 664 }
665 665
666 666
667 void RawScript::WriteTo(SnapshotWriter* writer, 667 void RawScript::WriteTo(SnapshotWriter* writer,
668 intptr_t object_id, 668 intptr_t object_id,
669 Snapshot::Kind kind) { 669 Snapshot::Kind kind) {
670 ASSERT(writer != NULL); 670 ASSERT(writer != NULL);
671 ASSERT(tokens_ != TokenStream::null()); 671 ASSERT(tokens_ != TokenStream::null());
672 ASSERT(kind != Snapshot::kMessage && 672 ASSERT(kind != Snapshot::kMessage &&
673 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))); 673 !RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this)));
674 674
675 // Write out the serialization header value for this object. 675 // Write out the serialization header value for this object.
676 writer->WriteSerializationMarker(kInlined, object_id); 676 writer->WriteSerializationMarker(kInlined, object_id);
677 677
678 // Write out the class and tags information. 678 // Write out the class and tags information.
679 writer->WriteObjectHeader(Object::kScriptClass, writer->GetObjectTags(this)); 679 writer->WriteObjectHeader(Object::kScriptClass, writer->GetObjectTags(this));
680 680
681 // Write out all the object pointer fields. 681 // Write out all the object pointer fields.
682 writer->WriteObject(ptr()->url_); 682 writer->WriteObjectImpl(ptr()->url_);
683 writer->WriteObject(ptr()->tokens_); 683 writer->WriteObjectImpl(ptr()->tokens_);
684 } 684 }
685 685
686 686
687 RawLibrary* Library::ReadFrom(SnapshotReader* reader, 687 RawLibrary* Library::ReadFrom(SnapshotReader* reader,
688 intptr_t object_id, 688 intptr_t object_id,
689 intptr_t tags, 689 intptr_t tags,
690 Snapshot::Kind kind) { 690 Snapshot::Kind kind) {
691 ASSERT(reader != NULL); 691 ASSERT(reader != NULL);
692 ASSERT(kind != Snapshot::kMessage); 692 ASSERT(kind != Snapshot::kMessage);
693 693
694 Library& library = Library::ZoneHandle(reader->isolate(), Library::null()); 694 Library& library = Library::ZoneHandle(reader->isolate(), Library::null());
695 reader->AddBackwardReference(object_id, &library); 695 reader->AddBackRef(object_id, &library, kIsDeserialized);
696 696
697 if (RawObject::IsCreatedFromSnapshot(tags)) { 697 if (RawObject::IsCreatedFromSnapshot(tags)) {
698 ASSERT(kind != Snapshot::kFull); 698 ASSERT(kind != Snapshot::kFull);
699 // Lookup the object as it should already exist in the heap. 699 // Lookup the object as it should already exist in the heap.
700 *reader->StringHandle() ^= reader->ReadObject(); 700 *reader->StringHandle() ^= reader->ReadObjectImpl();
701 library = Library::LookupLibrary(*reader->StringHandle()); 701 library = Library::LookupLibrary(*reader->StringHandle());
702 } else { 702 } else {
703 // Allocate library object. 703 // Allocate library object.
704 library = NEW_OBJECT(Library); 704 library = NEW_OBJECT(Library);
705 705
706 // Set the object tags. 706 // Set the object tags.
707 library.set_tags(tags); 707 library.set_tags(tags);
708 708
709 // Set all non object fields. 709 // Set all non object fields.
710 library.raw_ptr()->index_ = reader->ReadIntptrValue(); 710 library.raw_ptr()->index_ = reader->ReadIntptrValue();
711 library.raw_ptr()->num_imports_ = reader->ReadIntptrValue(); 711 library.raw_ptr()->num_imports_ = reader->ReadIntptrValue();
712 library.raw_ptr()->num_imported_into_ = reader->ReadIntptrValue(); 712 library.raw_ptr()->num_imported_into_ = reader->ReadIntptrValue();
713 library.raw_ptr()->num_anonymous_ = reader->ReadIntptrValue(); 713 library.raw_ptr()->num_anonymous_ = reader->ReadIntptrValue();
714 library.raw_ptr()->corelib_imported_ = reader->Read<bool>(); 714 library.raw_ptr()->corelib_imported_ = reader->Read<bool>();
715 library.raw_ptr()->debuggable_ = reader->Read<bool>(); 715 library.raw_ptr()->debuggable_ = reader->Read<bool>();
716 library.raw_ptr()->load_state_ = reader->Read<int8_t>(); 716 library.raw_ptr()->load_state_ = reader->Read<int8_t>();
717 // The native resolver is not serialized. 717 // The native resolver is not serialized.
718 Dart_NativeEntryResolver resolver = 718 Dart_NativeEntryResolver resolver =
719 reader->Read<Dart_NativeEntryResolver>(); 719 reader->Read<Dart_NativeEntryResolver>();
720 ASSERT(resolver == NULL); 720 ASSERT(resolver == NULL);
721 library.set_native_entry_resolver(resolver); 721 library.set_native_entry_resolver(resolver);
722 // The cache of loaded scripts is not serialized. 722 // The cache of loaded scripts is not serialized.
723 library.raw_ptr()->loaded_scripts_ = Array::null(); 723 library.raw_ptr()->loaded_scripts_ = Array::null();
724 724
725 // Set all the object fields. 725 // Set all the object fields.
726 // TODO(5411462): Need to assert No GC can happen here, even though 726 // TODO(5411462): Need to assert No GC can happen here, even though
727 // allocations may happen. 727 // allocations may happen.
728 intptr_t num_flds = (library.raw()->to() - library.raw()->from()); 728 intptr_t num_flds = (library.raw()->to() - library.raw()->from());
729 for (intptr_t i = 0; i <= num_flds; i++) { 729 for (intptr_t i = 0; i <= num_flds; i++) {
730 *(library.raw()->from() + i) = reader->ReadObject(); 730 *(library.raw()->from() + i) = reader->ReadObjectRef();
731 } 731 }
732 if (kind != Snapshot::kFull) { 732 if (kind != Snapshot::kFull) {
733 library.Register(); 733 library.Register();
734 } 734 }
735 } 735 }
736 return library.raw(); 736 return library.raw();
737 } 737 }
738 738
739 739
740 void RawLibrary::WriteTo(SnapshotWriter* writer, 740 void RawLibrary::WriteTo(SnapshotWriter* writer,
741 intptr_t object_id, 741 intptr_t object_id,
742 Snapshot::Kind kind) { 742 Snapshot::Kind kind) {
743 ASSERT(writer != NULL); 743 ASSERT(writer != NULL);
744 ASSERT(kind != Snapshot::kMessage); 744 ASSERT(kind != Snapshot::kMessage);
745 745
746 // Write out the serialization header value for this object. 746 // Write out the serialization header value for this object.
747 writer->WriteSerializationMarker(kInlined, object_id); 747 writer->WriteSerializationMarker(kInlined, object_id);
748 748
749 // Write out the class and tags information. 749 // Write out the class and tags information.
750 writer->WriteObjectHeader(Object::kLibraryClass, writer->GetObjectTags(this)); 750 writer->WriteObjectHeader(Object::kLibraryClass, writer->GetObjectTags(this));
751 751
752 if (RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) { 752 if (RawObject::IsCreatedFromSnapshot(writer->GetObjectTags(this))) {
753 ASSERT(kind != Snapshot::kFull); 753 ASSERT(kind != Snapshot::kFull);
754 // Write out library URL so that it can be looked up when reading. 754 // Write out library URL so that it can be looked up when reading.
755 writer->WriteObject(ptr()->url_); 755 writer->WriteObjectImpl(ptr()->url_);
756 } else { 756 } else {
757 // Write out all non object fields. 757 // Write out all non object fields.
758 writer->WriteIntptrValue(ptr()->index_); 758 writer->WriteIntptrValue(ptr()->index_);
759 writer->WriteIntptrValue(ptr()->num_imports_); 759 writer->WriteIntptrValue(ptr()->num_imports_);
760 writer->WriteIntptrValue(ptr()->num_imported_into_); 760 writer->WriteIntptrValue(ptr()->num_imported_into_);
761 writer->WriteIntptrValue(ptr()->num_anonymous_); 761 writer->WriteIntptrValue(ptr()->num_anonymous_);
762 writer->Write<bool>(ptr()->corelib_imported_); 762 writer->Write<bool>(ptr()->corelib_imported_);
763 writer->Write<bool>(ptr()->debuggable_); 763 writer->Write<bool>(ptr()->debuggable_);
764 writer->Write<int8_t>(ptr()->load_state_); 764 writer->Write<int8_t>(ptr()->load_state_);
765 // We do not serialize the native resolver over, this needs to be explicitly 765 // We do not serialize the native resolver over, this needs to be explicitly
(...skipping 13 matching lines...) Expand all
779 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, 779 RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader,
780 intptr_t object_id, 780 intptr_t object_id,
781 intptr_t tags, 781 intptr_t tags,
782 Snapshot::Kind kind) { 782 Snapshot::Kind kind) {
783 ASSERT(reader != NULL); 783 ASSERT(reader != NULL);
784 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags)); 784 ASSERT(kind != Snapshot::kMessage && !RawObject::IsCreatedFromSnapshot(tags));
785 785
786 // Allocate library prefix object. 786 // Allocate library prefix object.
787 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle( 787 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(
788 reader->isolate(), NEW_OBJECT(LibraryPrefix)); 788 reader->isolate(), NEW_OBJECT(LibraryPrefix));
789 reader->AddBackwardReference(object_id, &prefix); 789 reader->AddBackRef(object_id, &prefix, kIsDeserialized);
790 790
791 // Set the object tags. 791 // Set the object tags.
792 prefix.set_tags(tags); 792 prefix.set_tags(tags);
793 793
794 // Set all non object fields. 794 // Set all non object fields.
795 prefix.raw_ptr()->num_libs_ = reader->ReadIntptrValue(); 795 prefix.raw_ptr()->num_libs_ = reader->ReadIntptrValue();
796 796
797 // Set all the object fields. 797 // Set all the object fields.
798 // TODO(5411462): Need to assert No GC can happen here, even though 798 // TODO(5411462): Need to assert No GC can happen here, even though
799 // allocations may happen. 799 // allocations may happen.
800 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); 800 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from());
801 for (intptr_t i = 0; i <= num_flds; i++) { 801 for (intptr_t i = 0; i <= num_flds; i++) {
802 *(prefix.raw()->from() + i) = reader->ReadObject(); 802 *(prefix.raw()->from() + i) = reader->ReadObjectRef();
803 } 803 }
804 804
805 return prefix.raw(); 805 return prefix.raw();
806 } 806 }
807 807
808 808
809 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, 809 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer,
810 intptr_t object_id, 810 intptr_t object_id,
811 Snapshot::Kind kind) { 811 Snapshot::Kind kind) {
812 ASSERT(writer != NULL); 812 ASSERT(writer != NULL);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 ASSERT(reader != NULL); 934 ASSERT(reader != NULL);
935 935
936 // Allocate context object. 936 // Allocate context object.
937 intptr_t num_vars = reader->ReadIntptrValue(); 937 intptr_t num_vars = reader->ReadIntptrValue();
938 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); 938 Context& context = Context::ZoneHandle(reader->isolate(), Context::null());
939 if (kind == Snapshot::kFull) { 939 if (kind == Snapshot::kFull) {
940 context = reader->NewContext(num_vars); 940 context = reader->NewContext(num_vars);
941 } else { 941 } else {
942 context = Context::New(num_vars); 942 context = Context::New(num_vars);
943 } 943 }
944 reader->AddBackwardReference(object_id, &context); 944 reader->AddBackRef(object_id, &context, kIsDeserialized);
945 945
946 // Set the object tags. 946 // Set the object tags.
947 context.set_tags(tags); 947 context.set_tags(tags);
948 948
949 // Set the isolate implicitly. 949 // Set the isolate implicitly.
950 context.set_isolate(Isolate::Current()); 950 context.set_isolate(Isolate::Current());
951 951
952 // Set all the object fields. 952 // Set all the object fields.
953 // TODO(5411462): Need to assert No GC can happen here, even though 953 // TODO(5411462): Need to assert No GC can happen here, even though
954 // allocations may happen. 954 // allocations may happen.
955 intptr_t num_flds = (context.raw()->to(num_vars) - context.raw()->from()); 955 intptr_t num_flds = (context.raw()->to(num_vars) - context.raw()->from());
956 for (intptr_t i = 0; i <= num_flds; i++) { 956 for (intptr_t i = 0; i <= num_flds; i++) {
957 *(context.raw()->from() + i) = reader->ReadObject(); 957 *(context.raw()->from() + i) = reader->ReadObjectRef();
958 } 958 }
959 959
960 return context.raw(); 960 return context.raw();
961 } 961 }
962 962
963 963
964 void RawContext::WriteTo(SnapshotWriter* writer, 964 void RawContext::WriteTo(SnapshotWriter* writer,
965 intptr_t object_id, 965 intptr_t object_id,
966 Snapshot::Kind kind) { 966 Snapshot::Kind kind) {
967 ASSERT(writer != NULL); 967 ASSERT(writer != NULL);
(...skipping 19 matching lines...) Expand all
987 intptr_t object_id, 987 intptr_t object_id,
988 intptr_t tags, 988 intptr_t tags,
989 Snapshot::Kind kind) { 989 Snapshot::Kind kind) {
990 ASSERT(reader != NULL); 990 ASSERT(reader != NULL);
991 ASSERT(kind == Snapshot::kMessage); 991 ASSERT(kind == Snapshot::kMessage);
992 992
993 // Allocate context scope object. 993 // Allocate context scope object.
994 intptr_t num_vars = reader->ReadIntptrValue(); 994 intptr_t num_vars = reader->ReadIntptrValue();
995 ContextScope& scope = ContextScope::ZoneHandle(reader->isolate(), 995 ContextScope& scope = ContextScope::ZoneHandle(reader->isolate(),
996 ContextScope::New(num_vars)); 996 ContextScope::New(num_vars));
997 reader->AddBackwardReference(object_id, &scope); 997 reader->AddBackRef(object_id, &scope, kIsDeserialized);
998 998
999 // Set the object tags. 999 // Set the object tags.
1000 scope.set_tags(tags); 1000 scope.set_tags(tags);
1001 1001
1002 // Set all the object fields. 1002 // Set all the object fields.
1003 // TODO(5411462): Need to assert No GC can happen here, even though 1003 // TODO(5411462): Need to assert No GC can happen here, even though
1004 // allocations may happen. 1004 // allocations may happen.
1005 intptr_t num_flds = (scope.raw()->to(num_vars) - scope.raw()->from()); 1005 intptr_t num_flds = (scope.raw()->to(num_vars) - scope.raw()->from());
1006 for (intptr_t i = 0; i <= num_flds; i++) { 1006 for (intptr_t i = 0; i <= num_flds; i++) {
1007 *(scope.raw()->from() + i) = reader->ReadObject(); 1007 *(scope.raw()->from() + i) = reader->ReadObjectRef();
1008 } 1008 }
1009 1009
1010 return scope.raw(); 1010 return scope.raw();
1011 } 1011 }
1012 1012
1013 1013
1014 void RawContextScope::WriteTo(SnapshotWriter* writer, 1014 void RawContextScope::WriteTo(SnapshotWriter* writer,
1015 intptr_t object_id, 1015 intptr_t object_id,
1016 Snapshot::Kind kind) { 1016 Snapshot::Kind kind) {
1017 ASSERT(writer != NULL); 1017 ASSERT(writer != NULL);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); 1174 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null());
1175 if (kind == Snapshot::kFull) { 1175 if (kind == Snapshot::kFull) {
1176 mint = reader->NewMint(value); 1176 mint = reader->NewMint(value);
1177 } else { 1177 } else {
1178 if (RawObject::IsCanonical(tags)) { 1178 if (RawObject::IsCanonical(tags)) {
1179 mint = Mint::NewCanonical(value); 1179 mint = Mint::NewCanonical(value);
1180 } else { 1180 } else {
1181 mint = Mint::New(value, Heap::kNew); 1181 mint = Mint::New(value, Heap::kNew);
1182 } 1182 }
1183 } 1183 }
1184 reader->AddBackwardReference(object_id, &mint); 1184 reader->AddBackRef(object_id, &mint, kIsDeserialized);
1185 1185
1186 // Set the object tags. 1186 // Set the object tags.
1187 mint.set_tags(tags); 1187 mint.set_tags(tags);
1188 1188
1189 return mint.raw(); 1189 return mint.raw();
1190 } 1190 }
1191 1191
1192 1192
1193 void RawMint::WriteTo(SnapshotWriter* writer, 1193 void RawMint::WriteTo(SnapshotWriter* writer,
1194 intptr_t object_id, 1194 intptr_t object_id,
(...skipping 27 matching lines...) Expand all
1222 // Create a Bigint object from HexCString. 1222 // Create a Bigint object from HexCString.
1223 Bigint& obj = Bigint::ZoneHandle( 1223 Bigint& obj = Bigint::ZoneHandle(
1224 reader->isolate(), 1224 reader->isolate(),
1225 (kind == Snapshot::kFull) ? reader->NewBigint(str) : 1225 (kind == Snapshot::kFull) ? reader->NewBigint(str) :
1226 BigintOperations::FromHexCString(str)); 1226 BigintOperations::FromHexCString(str));
1227 1227
1228 // If it is a canonical constant make it one. 1228 // If it is a canonical constant make it one.
1229 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { 1229 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) {
1230 obj ^= obj.Canonicalize(); 1230 obj ^= obj.Canonicalize();
1231 } 1231 }
1232 reader->AddBackwardReference(object_id, &obj); 1232 reader->AddBackRef(object_id, &obj, kIsDeserialized);
1233 1233
1234 // Set the object tags. 1234 // Set the object tags.
1235 obj.set_tags(tags); 1235 obj.set_tags(tags);
1236 1236
1237 return obj.raw(); 1237 return obj.raw();
1238 } 1238 }
1239 1239
1240 1240
1241 void RawBigint::WriteTo(SnapshotWriter* writer, 1241 void RawBigint::WriteTo(SnapshotWriter* writer,
1242 intptr_t object_id, 1242 intptr_t object_id,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); 1294 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null());
1295 if (kind == Snapshot::kFull) { 1295 if (kind == Snapshot::kFull) {
1296 dbl = reader->NewDouble(value); 1296 dbl = reader->NewDouble(value);
1297 } else { 1297 } else {
1298 if (RawObject::IsCanonical(tags)) { 1298 if (RawObject::IsCanonical(tags)) {
1299 dbl = Double::NewCanonical(value); 1299 dbl = Double::NewCanonical(value);
1300 } else { 1300 } else {
1301 dbl = Double::New(value, Heap::kNew); 1301 dbl = Double::New(value, Heap::kNew);
1302 } 1302 }
1303 } 1303 }
1304 reader->AddBackwardReference(object_id, &dbl); 1304 reader->AddBackRef(object_id, &dbl, kIsDeserialized);
1305 1305
1306 // Set the object tags. 1306 // Set the object tags.
1307 dbl.set_tags(tags); 1307 dbl.set_tags(tags);
1308 1308
1309 return dbl.raw(); 1309 return dbl.raw();
1310 } 1310 }
1311 1311
1312 1312
1313 void RawDouble::WriteTo(SnapshotWriter* writer, 1313 void RawDouble::WriteTo(SnapshotWriter* writer,
1314 intptr_t object_id, 1314 intptr_t object_id,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 str_obj.set_tags(tags); 1387 str_obj.set_tags(tags);
1388 obj->ptr()->hash_ = Smi::New(hash); 1388 obj->ptr()->hash_ = Smi::New(hash);
1389 if (len > 0) { 1389 if (len > 0) {
1390 uint8_t* raw_ptr = str_obj.CharAddr(0); 1390 uint8_t* raw_ptr = str_obj.CharAddr(0);
1391 reader->ReadBytes(raw_ptr, len); 1391 reader->ReadBytes(raw_ptr, len);
1392 } 1392 }
1393 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); 1393 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash));
1394 } else { 1394 } else {
1395 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags); 1395 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags);
1396 } 1396 }
1397 reader->AddBackwardReference(object_id, &str_obj); 1397 reader->AddBackRef(object_id, &str_obj, kIsDeserialized);
1398 return str_obj.raw(); 1398 return str_obj.raw();
1399 } 1399 }
1400 1400
1401 1401
1402 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, 1402 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader,
1403 intptr_t object_id, 1403 intptr_t object_id,
1404 intptr_t tags, 1404 intptr_t tags,
1405 Snapshot::Kind kind) { 1405 Snapshot::Kind kind) {
1406 // Read the length so that we can determine instance size to allocate. 1406 // Read the length so that we can determine instance size to allocate.
1407 ASSERT(reader != NULL); 1407 ASSERT(reader != NULL);
(...skipping 10 matching lines...) Expand all
1418 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; 1418 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL;
1419 for (intptr_t i = 0; i < len; i++) { 1419 for (intptr_t i = 0; i < len; i++) {
1420 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. 1420 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions.
1421 *raw_ptr = reader->Read<uint16_t>(); 1421 *raw_ptr = reader->Read<uint16_t>();
1422 raw_ptr += 1; 1422 raw_ptr += 1;
1423 } 1423 }
1424 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); 1424 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash);
1425 } else { 1425 } else {
1426 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags); 1426 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags);
1427 } 1427 }
1428 reader->AddBackwardReference(object_id, &str_obj); 1428 reader->AddBackRef(object_id, &str_obj, kIsDeserialized);
1429 return str_obj.raw(); 1429 return str_obj.raw();
1430 } 1430 }
1431 1431
1432 1432
1433 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, 1433 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader,
1434 intptr_t object_id, 1434 intptr_t object_id,
1435 intptr_t tags, 1435 intptr_t tags,
1436 Snapshot::Kind kind) { 1436 Snapshot::Kind kind) {
1437 // Read the length so that we can determine instance size to allocate. 1437 // Read the length so that we can determine instance size to allocate.
1438 ASSERT(reader != NULL); 1438 ASSERT(reader != NULL);
(...skipping 10 matching lines...) Expand all
1449 uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; 1449 uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL;
1450 for (intptr_t i = 0; i < len; i++) { 1450 for (intptr_t i = 0; i < len; i++) {
1451 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. 1451 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions.
1452 *raw_ptr = reader->Read<uint32_t>(); 1452 *raw_ptr = reader->Read<uint32_t>();
1453 raw_ptr += 1; 1453 raw_ptr += 1;
1454 } 1454 }
1455 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); 1455 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash);
1456 } else { 1456 } else {
1457 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags); 1457 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags);
1458 } 1458 }
1459 reader->AddBackwardReference(object_id, &str_obj); 1459 reader->AddBackRef(object_id, &str_obj, kIsDeserialized);
1460 return str_obj.raw(); 1460 return str_obj.raw();
1461 } 1461 }
1462 1462
1463 1463
1464 template<typename T> 1464 template<typename T>
1465 static void StringWriteTo(SnapshotWriter* writer, 1465 static void StringWriteTo(SnapshotWriter* writer,
1466 intptr_t object_id, 1466 intptr_t object_id,
1467 Snapshot::Kind kind, 1467 Snapshot::Kind kind,
1468 intptr_t class_id, 1468 intptr_t class_id,
1469 intptr_t tags, 1469 intptr_t tags,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 } 1618 }
1619 1619
1620 1620
1621 void RawBool::WriteTo(SnapshotWriter* writer, 1621 void RawBool::WriteTo(SnapshotWriter* writer,
1622 intptr_t object_id, 1622 intptr_t object_id,
1623 Snapshot::Kind kind) { 1623 Snapshot::Kind kind) {
1624 UNREACHABLE(); 1624 UNREACHABLE();
1625 } 1625 }
1626 1626
1627 1627
1628 static void ArrayReadFrom(SnapshotReader* reader,
1629 const Array& result,
1630 intptr_t len,
1631 intptr_t tags) {
1632 ASSERT(reader != NULL);
1633
1634 // Set the object tags.
1635 result.set_tags(tags);
1636
1637 // Setup the object fields.
1638 *reader->TypeArgumentsHandle() ^= reader->ReadObject();
1639 result.SetTypeArguments(*reader->TypeArgumentsHandle());
1640
1641 for (intptr_t i = 0; i < len; i++) {
1642 *reader->ObjectHandle() = reader->ReadObject();
1643 result.SetAt(i, *reader->ObjectHandle());
1644 }
1645 }
1646
1647
1648 RawArray* Array::ReadFrom(SnapshotReader* reader, 1628 RawArray* Array::ReadFrom(SnapshotReader* reader,
1649 intptr_t object_id, 1629 intptr_t object_id,
1650 intptr_t tags, 1630 intptr_t tags,
1651 Snapshot::Kind kind) { 1631 Snapshot::Kind kind) {
1652 ASSERT(reader != NULL); 1632 ASSERT(reader != NULL);
1653 1633
1654 // Read the length so that we can determine instance size to allocate. 1634 // Read the length so that we can determine instance size to allocate.
1655 intptr_t len = reader->ReadSmiValue(); 1635 intptr_t len = reader->ReadSmiValue();
1656 Array& array = Array::ZoneHandle(reader->isolate(), 1636 Array* array = reinterpret_cast<Array*>(
1657 NEW_OBJECT_WITH_LEN(Array, len)); 1637 reader->GetBackRef(object_id));
1658 reader->AddBackwardReference(object_id, &array); 1638 if (array == NULL) {
1659 ArrayReadFrom(reader, array, len, tags); 1639 array = &(Array::ZoneHandle(reader->isolate(),
1660 return array.raw(); 1640 NEW_OBJECT_WITH_LEN(Array, len)));
1641 reader->AddBackRef(object_id, array, kIsDeserialized);
1642 }
1643 reader->ArrayReadFrom(*array, len, tags);
1644 return array->raw();
1661 } 1645 }
1662 1646
1663 1647
1664 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, 1648 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader,
1665 intptr_t object_id, 1649 intptr_t object_id,
1666 intptr_t tags, 1650 intptr_t tags,
1667 Snapshot::Kind kind) { 1651 Snapshot::Kind kind) {
1668 ASSERT(reader != NULL); 1652 ASSERT(reader != NULL);
1669 1653
1670 // Read the length so that we can determine instance size to allocate. 1654 // Read the length so that we can determine instance size to allocate.
1671 intptr_t len = reader->ReadSmiValue(); 1655 intptr_t len = reader->ReadSmiValue();
1672 ImmutableArray& array = ImmutableArray::ZoneHandle( 1656 ImmutableArray* array = reinterpret_cast<ImmutableArray*>(
1673 reader->isolate(), NEW_OBJECT_WITH_LEN(ImmutableArray, len)); 1657 reader->GetBackRef(object_id));
1674 reader->AddBackwardReference(object_id, &array); 1658 if (array == NULL) {
1675 ArrayReadFrom(reader, array, len, tags); 1659 array = &(ImmutableArray::ZoneHandle(
1676 return array.raw(); 1660 reader->isolate(), NEW_OBJECT_WITH_LEN(ImmutableArray, len)));
1677 } 1661 reader->AddBackRef(object_id, array, kIsDeserialized);
1678
1679
1680 static void ArrayWriteTo(SnapshotWriter* writer,
1681 intptr_t object_id,
1682 Snapshot::Kind kind,
1683 intptr_t array_kind,
1684 intptr_t tags,
1685 RawSmi* length,
1686 RawAbstractTypeArguments* type_arguments,
1687 RawObject* data[]) {
1688 ASSERT(writer != NULL);
1689 intptr_t len = Smi::Value(length);
1690
1691 // Write out the serialization header value for this object.
1692 writer->WriteSerializationMarker(kInlined, object_id);
1693
1694 // Write out the class and tags information.
1695 writer->WriteObjectHeader(array_kind, tags);
1696
1697 // Write out the length field.
1698 writer->Write<RawObject*>(length);
1699
1700 // Write out the type arguments.
1701 writer->WriteObject(type_arguments);
1702
1703 // Write out the individual objects.
1704 for (intptr_t i = 0; i < len; i++) {
1705 writer->WriteObject(data[i]);
1706 } 1662 }
1663 reader->ArrayReadFrom(*array, len, tags);
1664 return array->raw();
1707 } 1665 }
1708 1666
1709 1667
1710 void RawArray::WriteTo(SnapshotWriter* writer, 1668 void RawArray::WriteTo(SnapshotWriter* writer,
1711 intptr_t object_id, 1669 intptr_t object_id,
1712 Snapshot::Kind kind) { 1670 Snapshot::Kind kind) {
1713 ArrayWriteTo(writer, 1671 writer->ArrayWriteTo(object_id,
1714 object_id, 1672 ObjectStore::kArrayClass,
1715 kind, 1673 writer->GetObjectTags(this),
1716 ObjectStore::kArrayClass, 1674 ptr()->length_,
1717 writer->GetObjectTags(this), 1675 ptr()->type_arguments_,
1718 ptr()->length_, 1676 ptr()->data());
1719 ptr()->type_arguments_,
1720 ptr()->data());
1721 } 1677 }
1722 1678
1723 1679
1724 void RawImmutableArray::WriteTo(SnapshotWriter* writer, 1680 void RawImmutableArray::WriteTo(SnapshotWriter* writer,
1725 intptr_t object_id, 1681 intptr_t object_id,
1726 Snapshot::Kind kind) { 1682 Snapshot::Kind kind) {
1727 ArrayWriteTo(writer, 1683 writer->ArrayWriteTo(object_id,
1728 object_id, 1684 ObjectStore::kImmutableArrayClass,
1729 kind, 1685 writer->GetObjectTags(this),
1730 ObjectStore::kImmutableArrayClass, 1686 ptr()->length_,
1731 writer->GetObjectTags(this), 1687 ptr()->type_arguments_,
1732 ptr()->length_, 1688 ptr()->data());
1733 ptr()->type_arguments_,
1734 ptr()->data());
1735 } 1689 }
1736 1690
1737 1691
1738 RawGrowableObjectArray* GrowableObjectArray::ReadFrom(SnapshotReader* reader, 1692 RawGrowableObjectArray* GrowableObjectArray::ReadFrom(SnapshotReader* reader,
1739 intptr_t object_id, 1693 intptr_t object_id,
1740 intptr_t tags, 1694 intptr_t tags,
1741 Snapshot::Kind kind) { 1695 Snapshot::Kind kind) {
1742 ASSERT(reader != NULL); 1696 ASSERT(reader != NULL);
1743 1697
1744 // Read the length so that we can determine instance size to allocate. 1698 // Read the length so that we can determine instance size to allocate.
1745 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( 1699 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle(
1746 reader->isolate(), GrowableObjectArray::null()); 1700 reader->isolate(), GrowableObjectArray::null());
1747 if (kind == Snapshot::kFull) { 1701 if (kind == Snapshot::kFull) {
1748 array = reader->NewGrowableObjectArray(); 1702 array = reader->NewGrowableObjectArray();
1749 } else { 1703 } else {
1750 array = GrowableObjectArray::New(0); 1704 array = GrowableObjectArray::New(0);
1751 } 1705 }
1752 reader->AddBackwardReference(object_id, &array); 1706 reader->AddBackRef(object_id, &array, kIsDeserialized);
1753 intptr_t length = reader->ReadSmiValue(); 1707 intptr_t length = reader->ReadSmiValue();
1754 array.SetLength(length); 1708 array.SetLength(length);
1755 Array& contents = Array::Handle(); 1709 Array& contents = Array::Handle();
1756 contents ^= reader->ReadObject(); 1710 contents ^= reader->ReadObjectImpl();
1757 array.SetData(contents); 1711 array.SetData(contents);
1758 const AbstractTypeArguments& type_arguments = 1712 const AbstractTypeArguments& type_arguments =
1759 AbstractTypeArguments::Handle(contents.GetTypeArguments()); 1713 AbstractTypeArguments::Handle(contents.GetTypeArguments());
1760 array.SetTypeArguments(type_arguments); 1714 array.SetTypeArguments(type_arguments);
1761 return array.raw(); 1715 return array.raw();
1762 } 1716 }
1763 1717
1764 1718
1765 void RawGrowableObjectArray::WriteTo(SnapshotWriter* writer, 1719 void RawGrowableObjectArray::WriteTo(SnapshotWriter* writer,
1766 intptr_t object_id, 1720 intptr_t object_id,
1767 Snapshot::Kind kind) { 1721 Snapshot::Kind kind) {
1768 ASSERT(writer != NULL); 1722 ASSERT(writer != NULL);
1769 1723
1770 // Write out the serialization header value for this object. 1724 // Write out the serialization header value for this object.
1771 writer->WriteSerializationMarker(kInlined, object_id); 1725 writer->WriteSerializationMarker(kInlined, object_id);
1772 1726
1773 // Write out the class and tags information. 1727 // Write out the class and tags information.
1774 writer->WriteObjectHeader(ObjectStore::kGrowableObjectArrayClass, 1728 writer->WriteObjectHeader(ObjectStore::kGrowableObjectArrayClass,
1775 writer->GetObjectTags(this)); 1729 writer->GetObjectTags(this));
1776 1730
1777 // Write out the used length field. 1731 // Write out the used length field.
1778 writer->Write<RawObject*>(ptr()->length_); 1732 writer->Write<RawObject*>(ptr()->length_);
1779 1733
1780 // Write out the Array object. 1734 // Write out the Array object.
1781 writer->WriteObject(ptr()->data_); 1735 writer->WriteObjectImpl(ptr()->data_);
1782 } 1736 }
1783 1737
1784 1738
1785 RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader, 1739 RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader,
1786 intptr_t object_id, 1740 intptr_t object_id,
1787 intptr_t tags, 1741 intptr_t tags,
1788 Snapshot::Kind kind) { 1742 Snapshot::Kind kind) {
1789 UNREACHABLE(); // ByteArray is an abstract class. 1743 UNREACHABLE(); // ByteArray is an abstract class.
1790 return ByteArray::null(); 1744 return ByteArray::null();
1791 } 1745 }
1792 1746
1793 1747
1794 template<typename HandleT, typename RawT, typename ElementT> 1748 template<typename HandleT, typename RawT, typename ElementT>
1795 RawT* ByteArray::ReadFromImpl(SnapshotReader* reader, 1749 RawT* ByteArray::ReadFromImpl(SnapshotReader* reader,
1796 intptr_t object_id, 1750 intptr_t object_id,
1797 intptr_t tags, 1751 intptr_t tags,
1798 Snapshot::Kind kind) { 1752 Snapshot::Kind kind) {
1799 ASSERT(reader != NULL); 1753 ASSERT(reader != NULL);
1800 1754
1801 intptr_t len = reader->ReadSmiValue(); 1755 intptr_t len = reader->ReadSmiValue();
1802 Heap::Space space = (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew; 1756 Heap::Space space = (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew;
1803 HandleT& result = 1757 HandleT& result =
1804 HandleT::ZoneHandle(reader->isolate(), HandleT::New(len, space)); 1758 HandleT::ZoneHandle(reader->isolate(), HandleT::New(len, space));
1805 reader->AddBackwardReference(object_id, &result); 1759 reader->AddBackRef(object_id, &result, kIsDeserialized);
1806 1760
1807 // Set the object tags. 1761 // Set the object tags.
1808 result.set_tags(tags); 1762 result.set_tags(tags);
1809 1763
1810 // Setup the array elements. 1764 // Setup the array elements.
1811 for (intptr_t i = 0; i < len; ++i) { 1765 for (intptr_t i = 0; i < len; ++i) {
1812 result.SetAt(i, reader->Read<ElementT>()); 1766 result.SetAt(i, reader->Read<ElementT>());
1813 } 1767 }
1814 return result.raw(); 1768 return result.raw();
1815 } 1769 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 ASSERT(reader != NULL); 1922 ASSERT(reader != NULL);
1969 ASSERT(kind == Snapshot::kMessage); 1923 ASSERT(kind == Snapshot::kMessage);
1970 1924
1971 // Read the length so that we can determine instance size to allocate. 1925 // Read the length so that we can determine instance size to allocate.
1972 intptr_t len = reader->ReadSmiValue(); 1926 intptr_t len = reader->ReadSmiValue();
1973 1927
1974 // Allocate JSRegExp object. 1928 // Allocate JSRegExp object.
1975 JSRegExp& regex = JSRegExp::ZoneHandle( 1929 JSRegExp& regex = JSRegExp::ZoneHandle(
1976 reader->isolate(), 1930 reader->isolate(),
1977 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); 1931 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew));
1978 reader->AddBackwardReference(object_id, &regex); 1932 reader->AddBackRef(object_id, &regex, kIsDeserialized);
1979 1933
1980 // Set the object tags. 1934 // Set the object tags.
1981 regex.set_tags(tags); 1935 regex.set_tags(tags);
1982 1936
1983 // Read and Set all the other fields. 1937 // Read and Set all the other fields.
1984 regex.raw_ptr()->num_bracket_expressions_ = reader->ReadAsSmi(); 1938 regex.raw_ptr()->num_bracket_expressions_ = reader->ReadAsSmi();
1985 *reader->StringHandle() ^= reader->ReadObject(); 1939 *reader->StringHandle() ^= reader->ReadObjectImpl();
1986 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw(); 1940 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw();
1987 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); 1941 regex.raw_ptr()->type_ = reader->ReadIntptrValue();
1988 regex.raw_ptr()->flags_ = reader->ReadIntptrValue(); 1942 regex.raw_ptr()->flags_ = reader->ReadIntptrValue();
1989 1943
1990 // TODO(5411462): Need to implement a way of recompiling the regex. 1944 // TODO(5411462): Need to implement a way of recompiling the regex.
1991 1945
1992 return regex.raw(); 1946 return regex.raw();
1993 } 1947 }
1994 1948
1995 1949
1996 void RawJSRegExp::WriteTo(SnapshotWriter* writer, 1950 void RawJSRegExp::WriteTo(SnapshotWriter* writer,
1997 intptr_t object_id, 1951 intptr_t object_id,
1998 Snapshot::Kind kind) { 1952 Snapshot::Kind kind) {
1999 ASSERT(writer != NULL); 1953 ASSERT(writer != NULL);
2000 ASSERT(kind == Snapshot::kMessage); 1954 ASSERT(kind == Snapshot::kMessage);
2001 1955
2002 // Write out the serialization header value for this object. 1956 // Write out the serialization header value for this object.
2003 writer->WriteSerializationMarker(kInlined, object_id); 1957 writer->WriteSerializationMarker(kInlined, object_id);
2004 1958
2005 // Write out the class and tags information. 1959 // Write out the class and tags information.
2006 writer->WriteObjectHeader(ObjectStore::kJSRegExpClass, 1960 writer->WriteObjectHeader(ObjectStore::kJSRegExpClass,
2007 writer->GetObjectTags(this)); 1961 writer->GetObjectTags(this));
2008 1962
2009 // Write out the data length field. 1963 // Write out the data length field.
2010 writer->Write<RawObject*>(ptr()->data_length_); 1964 writer->Write<RawObject*>(ptr()->data_length_);
2011 1965
2012 // Write out all the other fields. 1966 // Write out all the other fields.
2013 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); 1967 writer->Write<RawObject*>(ptr()->num_bracket_expressions_);
2014 writer->WriteObject(ptr()->pattern_); 1968 writer->WriteObjectImpl(ptr()->pattern_);
2015 writer->WriteIntptrValue(ptr()->type_); 1969 writer->WriteIntptrValue(ptr()->type_);
2016 writer->WriteIntptrValue(ptr()->flags_); 1970 writer->WriteIntptrValue(ptr()->flags_);
2017 1971
2018 // Do not write out the data part which is native. 1972 // Do not write out the data part which is native.
2019 } 1973 }
2020 1974
2021 1975
2022 } // namespace dart 1976 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_message.cc ('k') | vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698