| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 #include "vm/object_store.h" | 6 #include "vm/object_store.h" |
| 7 #include "vm/snapshot.h" | 7 #include "vm/snapshot.h" |
| 8 #include "vm/stub_code.h" | 8 #include "vm/stub_code.h" |
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
| 10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 DECLARE_FLAG(int, optimization_counter_threshold); | 14 DECLARE_FLAG(int, optimization_counter_threshold); |
| 15 | 15 |
| 16 #define NEW_OBJECT(type) \ | 16 #define NEW_OBJECT(type) \ |
| 17 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) | 17 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) |
| 18 | 18 |
| 19 #define NEW_OBJECT_WITH_LEN(type, len) \ | 19 #define NEW_OBJECT_WITH_LEN(type, len) \ |
| 20 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) | 20 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) |
| 21 | 21 |
| 22 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ | 22 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ |
| 23 ((kind == Snapshot::kFull) ? \ | 23 ((kind == Snapshot::kFull) ? \ |
| 24 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) | 24 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) |
| 25 | 25 |
| 26 #define OFFSET_OF_FROM(obj) \ | 26 #define OFFSET_OF_FROM(obj) \ |
| 27 obj.raw()->from() - reinterpret_cast<RawObject**>(obj.raw()->ptr()) | 27 obj.raw()->from() - reinterpret_cast<RawObject**>(obj.raw()->ptr()) |
| 28 | 28 |
| 29 // TODO(18854): Need to assert No GC can happen here, even though |
| 30 // allocations may happen. |
| 31 #define READ_OBJECT_FIELDS(object, from, to, as_reference) \ |
| 32 intptr_t num_flds = (to) - (from); \ |
| 33 intptr_t from_offset = OFFSET_OF_FROM(object); \ |
| 34 for (intptr_t i = 0; i <= num_flds; i++) { \ |
| 35 (*reader->PassiveObjectHandle()) = \ |
| 36 reader->ReadObjectImpl(as_reference, object_id, (i + from_offset)); \ |
| 37 object.StorePointer(((from) + i), \ |
| 38 reader->PassiveObjectHandle()->raw()); \ |
| 39 } |
| 40 |
| 29 RawClass* Class::ReadFrom(SnapshotReader* reader, | 41 RawClass* Class::ReadFrom(SnapshotReader* reader, |
| 30 intptr_t object_id, | 42 intptr_t object_id, |
| 31 intptr_t tags, | 43 intptr_t tags, |
| 32 Snapshot::Kind kind) { | 44 Snapshot::Kind kind) { |
| 33 ASSERT(reader != NULL); | 45 ASSERT(reader != NULL); |
| 34 | 46 |
| 35 Class& cls = Class::ZoneHandle(reader->zone(), Class::null()); | 47 Class& cls = Class::ZoneHandle(reader->zone(), Class::null()); |
| 36 bool is_in_fullsnapshot = reader->Read<bool>(); | 48 bool is_in_fullsnapshot = reader->Read<bool>(); |
| 37 if ((kind == Snapshot::kFull) || | 49 if ((kind == Snapshot::kFull) || |
| 38 (kind == Snapshot::kScript && !is_in_fullsnapshot)) { | 50 (kind == Snapshot::kScript && !is_in_fullsnapshot)) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 59 cls.set_next_field_offset_in_words(reader->Read<int32_t>()); | 71 cls.set_next_field_offset_in_words(reader->Read<int32_t>()); |
| 60 } | 72 } |
| 61 cls.set_type_arguments_field_offset_in_words(reader->Read<int32_t>()); | 73 cls.set_type_arguments_field_offset_in_words(reader->Read<int32_t>()); |
| 62 cls.set_num_type_arguments(reader->Read<int16_t>()); | 74 cls.set_num_type_arguments(reader->Read<int16_t>()); |
| 63 cls.set_num_own_type_arguments(reader->Read<int16_t>()); | 75 cls.set_num_own_type_arguments(reader->Read<int16_t>()); |
| 64 cls.set_num_native_fields(reader->Read<uint16_t>()); | 76 cls.set_num_native_fields(reader->Read<uint16_t>()); |
| 65 cls.set_token_pos(reader->Read<int32_t>()); | 77 cls.set_token_pos(reader->Read<int32_t>()); |
| 66 cls.set_state_bits(reader->Read<uint16_t>()); | 78 cls.set_state_bits(reader->Read<uint16_t>()); |
| 67 | 79 |
| 68 // Set all the object fields. | 80 // Set all the object fields. |
| 69 // TODO(5411462): Need to assert No GC can happen here, even though | 81 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); |
| 70 // allocations may happen. | 82 |
| 71 intptr_t num_flds = (cls.raw()->to() - cls.raw()->from()); | |
| 72 intptr_t from_offset = OFFSET_OF_FROM(cls); | |
| 73 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 74 (*reader->PassiveObjectHandle()) = | |
| 75 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); | |
| 76 cls.StorePointer((cls.raw()->from() + i), | |
| 77 reader->PassiveObjectHandle()->raw()); | |
| 78 } | |
| 79 ASSERT(!cls.IsInFullSnapshot() || (kind == Snapshot::kFull)); | 83 ASSERT(!cls.IsInFullSnapshot() || (kind == Snapshot::kFull)); |
| 80 } else { | 84 } else { |
| 81 cls ^= reader->ReadClassId(object_id); | 85 cls ^= reader->ReadClassId(object_id); |
| 82 ASSERT((kind == Snapshot::kMessage) || cls.IsInFullSnapshot()); | 86 ASSERT((kind == Snapshot::kMessage) || cls.IsInFullSnapshot()); |
| 83 } | 87 } |
| 84 return cls.raw(); | 88 return cls.raw(); |
| 85 } | 89 } |
| 86 | 90 |
| 87 | 91 |
| 88 void RawClass::WriteTo(SnapshotWriter* writer, | 92 void RawClass::WriteTo(SnapshotWriter* writer, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 152 |
| 149 // Allocate unresolved class object. | 153 // Allocate unresolved class object. |
| 150 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( | 154 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( |
| 151 reader->zone(), NEW_OBJECT(UnresolvedClass)); | 155 reader->zone(), NEW_OBJECT(UnresolvedClass)); |
| 152 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized); | 156 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized); |
| 153 | 157 |
| 154 // Set all non object fields. | 158 // Set all non object fields. |
| 155 unresolved_class.set_token_pos(reader->Read<int32_t>()); | 159 unresolved_class.set_token_pos(reader->Read<int32_t>()); |
| 156 | 160 |
| 157 // Set all the object fields. | 161 // Set all the object fields. |
| 158 // TODO(5411462): Need to assert No GC can happen here, even though | 162 READ_OBJECT_FIELDS(unresolved_class, |
| 159 // allocations may happen. | 163 unresolved_class.raw()->from(), |
| 160 intptr_t num_flds = (unresolved_class.raw()->to() - | 164 unresolved_class.raw()->to(), |
| 161 unresolved_class.raw()->from()); | 165 kAsReference); |
| 162 for (intptr_t i = 0; i <= num_flds; i++) { | 166 |
| 163 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 164 unresolved_class.StorePointer((unresolved_class.raw()->from() + i), | |
| 165 reader->PassiveObjectHandle()->raw()); | |
| 166 } | |
| 167 return unresolved_class.raw(); | 167 return unresolved_class.raw(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 | 170 |
| 171 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, | 171 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, |
| 172 intptr_t object_id, | 172 intptr_t object_id, |
| 173 Snapshot::Kind kind) { | 173 Snapshot::Kind kind) { |
| 174 ASSERT(writer != NULL); | 174 ASSERT(writer != NULL); |
| 175 | 175 |
| 176 // Write out the serialization header value for this object. | 176 // Write out the serialization header value for this object. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 bool is_canonical = RawObject::IsCanonical(tags); | 219 bool is_canonical = RawObject::IsCanonical(tags); |
| 220 bool defer_canonicalization = is_canonical && | 220 bool defer_canonicalization = is_canonical && |
| 221 (kind != Snapshot::kFull && typeclass_is_in_fullsnapshot); | 221 (kind != Snapshot::kFull && typeclass_is_in_fullsnapshot); |
| 222 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization); | 222 reader->AddBackRef(object_id, &type, kIsDeserialized, defer_canonicalization); |
| 223 | 223 |
| 224 // Set all non object fields. | 224 // Set all non object fields. |
| 225 type.set_token_pos(reader->Read<int32_t>()); | 225 type.set_token_pos(reader->Read<int32_t>()); |
| 226 type.set_type_state(reader->Read<int8_t>()); | 226 type.set_type_state(reader->Read<int8_t>()); |
| 227 | 227 |
| 228 // Set all the object fields. | 228 // Set all the object fields. |
| 229 // TODO(5411462): Need to assert No GC can happen here, even though | 229 READ_OBJECT_FIELDS(type, type.raw()->from(), type.raw()->to(), kAsReference); |
| 230 // allocations may happen. | |
| 231 intptr_t num_flds = (type.raw()->to() - type.raw()->from()); | |
| 232 intptr_t from_offset = OFFSET_OF_FROM(type); | |
| 233 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 234 (*reader->PassiveObjectHandle()) = | |
| 235 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); | |
| 236 type.StorePointer((type.raw()->from() + i), | |
| 237 reader->PassiveObjectHandle()->raw()); | |
| 238 } | |
| 239 | 230 |
| 240 // Set the canonical bit. | 231 // Set the canonical bit. |
| 241 if (!defer_canonicalization && RawObject::IsCanonical(tags)) { | 232 if (!defer_canonicalization && RawObject::IsCanonical(tags)) { |
| 242 type.SetCanonical(); | 233 type.SetCanonical(); |
| 243 } | 234 } |
| 244 | 235 |
| 245 return type.raw(); | 236 return type.raw(); |
| 246 } | 237 } |
| 247 | 238 |
| 248 | 239 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 intptr_t tags, | 280 intptr_t tags, |
| 290 Snapshot::Kind kind) { | 281 Snapshot::Kind kind) { |
| 291 ASSERT(reader != NULL); | 282 ASSERT(reader != NULL); |
| 292 | 283 |
| 293 // Allocate type ref object. | 284 // Allocate type ref object. |
| 294 TypeRef& type_ref = TypeRef::ZoneHandle( | 285 TypeRef& type_ref = TypeRef::ZoneHandle( |
| 295 reader->zone(), NEW_OBJECT(TypeRef)); | 286 reader->zone(), NEW_OBJECT(TypeRef)); |
| 296 reader->AddBackRef(object_id, &type_ref, kIsDeserialized); | 287 reader->AddBackRef(object_id, &type_ref, kIsDeserialized); |
| 297 | 288 |
| 298 // Set all the object fields. | 289 // Set all the object fields. |
| 299 // TODO(5411462): Need to assert No GC can happen here, even though | 290 READ_OBJECT_FIELDS(type_ref, |
| 300 // allocations may happen. | 291 type_ref.raw()->from(), type_ref.raw()->to(), |
| 301 intptr_t num_flds = (type_ref.raw()->to() - type_ref.raw()->from()); | 292 kAsReference); |
| 302 intptr_t from_offset = OFFSET_OF_FROM(type_ref); | |
| 303 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 304 (*reader->PassiveObjectHandle()) = | |
| 305 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); | |
| 306 type_ref.StorePointer((type_ref.raw()->from() + i), | |
| 307 reader->PassiveObjectHandle()->raw()); | |
| 308 } | |
| 309 | 293 |
| 310 return type_ref.raw(); | 294 return type_ref.raw(); |
| 311 } | 295 } |
| 312 | 296 |
| 313 | 297 |
| 314 void RawTypeRef::WriteTo(SnapshotWriter* writer, | 298 void RawTypeRef::WriteTo(SnapshotWriter* writer, |
| 315 intptr_t object_id, | 299 intptr_t object_id, |
| 316 Snapshot::Kind kind) { | 300 Snapshot::Kind kind) { |
| 317 ASSERT(writer != NULL); | 301 ASSERT(writer != NULL); |
| 318 | 302 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 339 TypeParameter& type_parameter = TypeParameter::ZoneHandle( | 323 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
| 340 reader->zone(), NEW_OBJECT(TypeParameter)); | 324 reader->zone(), NEW_OBJECT(TypeParameter)); |
| 341 reader->AddBackRef(object_id, &type_parameter, kIsDeserialized); | 325 reader->AddBackRef(object_id, &type_parameter, kIsDeserialized); |
| 342 | 326 |
| 343 // Set all non object fields. | 327 // Set all non object fields. |
| 344 type_parameter.set_token_pos(reader->Read<int32_t>()); | 328 type_parameter.set_token_pos(reader->Read<int32_t>()); |
| 345 type_parameter.set_index(reader->Read<int16_t>()); | 329 type_parameter.set_index(reader->Read<int16_t>()); |
| 346 type_parameter.set_type_state(reader->Read<int8_t>()); | 330 type_parameter.set_type_state(reader->Read<int8_t>()); |
| 347 | 331 |
| 348 // Set all the object fields. | 332 // Set all the object fields. |
| 349 // TODO(5411462): Need to assert No GC can happen here, even though | 333 READ_OBJECT_FIELDS(type_parameter, |
| 350 // allocations may happen. | 334 type_parameter.raw()->from(), type_parameter.raw()->to(), |
| 351 intptr_t num_flds = (type_parameter.raw()->to() - | 335 kAsReference); |
| 352 type_parameter.raw()->from()); | |
| 353 intptr_t from_offset = OFFSET_OF_FROM(type_parameter); | |
| 354 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 355 (*reader->PassiveObjectHandle()) = | |
| 356 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); | |
| 357 type_parameter.StorePointer((type_parameter.raw()->from() + i), | |
| 358 reader->PassiveObjectHandle()->raw()); | |
| 359 } | |
| 360 | 336 |
| 361 return type_parameter.raw(); | 337 return type_parameter.raw(); |
| 362 } | 338 } |
| 363 | 339 |
| 364 | 340 |
| 365 void RawTypeParameter::WriteTo(SnapshotWriter* writer, | 341 void RawTypeParameter::WriteTo(SnapshotWriter* writer, |
| 366 intptr_t object_id, | 342 intptr_t object_id, |
| 367 Snapshot::Kind kind) { | 343 Snapshot::Kind kind) { |
| 368 ASSERT(writer != NULL); | 344 ASSERT(writer != NULL); |
| 369 | 345 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 393 intptr_t tags, | 369 intptr_t tags, |
| 394 Snapshot::Kind kind) { | 370 Snapshot::Kind kind) { |
| 395 ASSERT(reader != NULL); | 371 ASSERT(reader != NULL); |
| 396 | 372 |
| 397 // Allocate bounded type object. | 373 // Allocate bounded type object. |
| 398 BoundedType& bounded_type = BoundedType::ZoneHandle( | 374 BoundedType& bounded_type = BoundedType::ZoneHandle( |
| 399 reader->zone(), NEW_OBJECT(BoundedType)); | 375 reader->zone(), NEW_OBJECT(BoundedType)); |
| 400 reader->AddBackRef(object_id, &bounded_type, kIsDeserialized); | 376 reader->AddBackRef(object_id, &bounded_type, kIsDeserialized); |
| 401 | 377 |
| 402 // Set all the object fields. | 378 // Set all the object fields. |
| 403 // TODO(5411462): Need to assert No GC can happen here, even though | 379 READ_OBJECT_FIELDS(bounded_type, |
| 404 // allocations may happen. | 380 bounded_type.raw()->from(), bounded_type.raw()->to(), |
| 405 intptr_t num_flds = (bounded_type.raw()->to() - | 381 kAsReference); |
| 406 bounded_type.raw()->from()); | |
| 407 intptr_t from_offset = OFFSET_OF_FROM(bounded_type); | |
| 408 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 409 (*reader->PassiveObjectHandle()) = | |
| 410 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); | |
| 411 bounded_type.StorePointer((bounded_type.raw()->from() + i), | |
| 412 reader->PassiveObjectHandle()->raw()); | |
| 413 } | |
| 414 | 382 |
| 415 return bounded_type.raw(); | 383 return bounded_type.raw(); |
| 416 } | 384 } |
| 417 | 385 |
| 418 | 386 |
| 419 void RawBoundedType::WriteTo(SnapshotWriter* writer, | 387 void RawBoundedType::WriteTo(SnapshotWriter* writer, |
| 420 intptr_t object_id, | 388 intptr_t object_id, |
| 421 Snapshot::Kind kind) { | 389 Snapshot::Kind kind) { |
| 422 ASSERT(writer != NULL); | 390 ASSERT(writer != NULL); |
| 423 | 391 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 intptr_t tags, | 495 intptr_t tags, |
| 528 Snapshot::Kind kind) { | 496 Snapshot::Kind kind) { |
| 529 ASSERT(reader != NULL); | 497 ASSERT(reader != NULL); |
| 530 | 498 |
| 531 // Allocate function object. | 499 // Allocate function object. |
| 532 PatchClass& cls = PatchClass::ZoneHandle(reader->zone(), | 500 PatchClass& cls = PatchClass::ZoneHandle(reader->zone(), |
| 533 NEW_OBJECT(PatchClass)); | 501 NEW_OBJECT(PatchClass)); |
| 534 reader->AddBackRef(object_id, &cls, kIsDeserialized); | 502 reader->AddBackRef(object_id, &cls, kIsDeserialized); |
| 535 | 503 |
| 536 // Set all the object fields. | 504 // Set all the object fields. |
| 537 // TODO(5411462): Need to assert No GC can happen here, even though | 505 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); |
| 538 // allocations may happen. | 506 |
| 539 intptr_t num_flds = (cls.raw()->to() - cls.raw()->from()); | |
| 540 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 541 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 542 cls.StorePointer((cls.raw()->from() + i), | |
| 543 reader->PassiveObjectHandle()->raw()); | |
| 544 } | |
| 545 ASSERT(((kind == Snapshot::kScript) && | 507 ASSERT(((kind == Snapshot::kScript) && |
| 546 !Class::IsInFullSnapshot(cls.source_class())) || | 508 !Class::IsInFullSnapshot(cls.source_class())) || |
| 547 (kind == Snapshot::kFull)); | 509 (kind == Snapshot::kFull)); |
| 548 | 510 |
| 549 return cls.raw(); | 511 return cls.raw(); |
| 550 } | 512 } |
| 551 | 513 |
| 552 | 514 |
| 553 void RawPatchClass::WriteTo(SnapshotWriter* writer, | 515 void RawPatchClass::WriteTo(SnapshotWriter* writer, |
| 554 intptr_t object_id, | 516 intptr_t object_id, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 574 Snapshot::Kind kind) { | 536 Snapshot::Kind kind) { |
| 575 ASSERT(reader != NULL); | 537 ASSERT(reader != NULL); |
| 576 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 538 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 577 | 539 |
| 578 // Allocate closure data object. | 540 // Allocate closure data object. |
| 579 ClosureData& data = ClosureData::ZoneHandle( | 541 ClosureData& data = ClosureData::ZoneHandle( |
| 580 reader->zone(), NEW_OBJECT(ClosureData)); | 542 reader->zone(), NEW_OBJECT(ClosureData)); |
| 581 reader->AddBackRef(object_id, &data, kIsDeserialized); | 543 reader->AddBackRef(object_id, &data, kIsDeserialized); |
| 582 | 544 |
| 583 // Set all the object fields. | 545 // Set all the object fields. |
| 584 // TODO(5411462): Need to assert No GC can happen here, even though | 546 READ_OBJECT_FIELDS(data, data.raw()->from(), data.raw()->to(), kAsReference); |
| 585 // allocations may happen. | |
| 586 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); | |
| 587 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 588 *(data.raw()->from() + i) = reader->ReadObjectImpl(kAsReference); | |
| 589 } | |
| 590 | 547 |
| 591 return data.raw(); | 548 return data.raw(); |
| 592 } | 549 } |
| 593 | 550 |
| 594 | 551 |
| 595 void RawClosureData::WriteTo(SnapshotWriter* writer, | 552 void RawClosureData::WriteTo(SnapshotWriter* writer, |
| 596 intptr_t object_id, | 553 intptr_t object_id, |
| 597 Snapshot::Kind kind) { | 554 Snapshot::Kind kind) { |
| 598 ASSERT(writer != NULL); | 555 ASSERT(writer != NULL); |
| 599 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 556 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 610 writer->WriteVMIsolateObject(kEmptyContextScopeObject); | 567 writer->WriteVMIsolateObject(kEmptyContextScopeObject); |
| 611 } else { | 568 } else { |
| 612 if (ptr()->context_scope_->ptr()->is_implicit_) { | 569 if (ptr()->context_scope_->ptr()->is_implicit_) { |
| 613 writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject); | 570 writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject); |
| 614 } else { | 571 } else { |
| 615 // We don't write non implicit context scopes in the snapshot. | 572 // We don't write non implicit context scopes in the snapshot. |
| 616 writer->WriteVMIsolateObject(kNullObject); | 573 writer->WriteVMIsolateObject(kNullObject); |
| 617 } | 574 } |
| 618 } | 575 } |
| 619 | 576 |
| 620 writer->WriteObjectImpl(Object::null(), kAsInlinedObject); | |
| 621 | |
| 622 // Parent function. | 577 // Parent function. |
| 623 writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject); | 578 writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject); |
| 624 | 579 |
| 625 // Signature class. | 580 // Signature class. |
| 626 writer->WriteObjectImpl(ptr()->signature_class_, kAsInlinedObject); | 581 writer->WriteObjectImpl(ptr()->signature_class_, kAsInlinedObject); |
| 627 | 582 |
| 628 // Static closure/Closure allocation stub. | 583 // Static closure/Closure allocation stub. |
| 629 // We don't write the closure or allocation stub in the snapshot. | 584 // We don't write the closure or allocation stub in the snapshot. |
| 630 writer->WriteVMIsolateObject(kNullObject); | 585 writer->WriteVMIsolateObject(kNullObject); |
| 631 } | 586 } |
| 632 | 587 |
| 633 | 588 |
| 634 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, | 589 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, |
| 635 intptr_t object_id, | 590 intptr_t object_id, |
| 636 intptr_t tags, | 591 intptr_t tags, |
| 637 Snapshot::Kind kind) { | 592 Snapshot::Kind kind) { |
| 638 ASSERT(reader != NULL); | 593 ASSERT(reader != NULL); |
| 639 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 594 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 640 | 595 |
| 641 // Allocate redirection data object. | 596 // Allocate redirection data object. |
| 642 RedirectionData& data = RedirectionData::ZoneHandle( | 597 RedirectionData& data = RedirectionData::ZoneHandle( |
| 643 reader->zone(), NEW_OBJECT(RedirectionData)); | 598 reader->zone(), NEW_OBJECT(RedirectionData)); |
| 644 reader->AddBackRef(object_id, &data, kIsDeserialized); | 599 reader->AddBackRef(object_id, &data, kIsDeserialized); |
| 645 | 600 |
| 646 // Set all the object fields. | 601 // Set all the object fields. |
| 647 // TODO(5411462): Need to assert No GC can happen here, even though | 602 READ_OBJECT_FIELDS(data, data.raw()->from(), data.raw()->to(), kAsReference); |
| 648 // allocations may happen. | |
| 649 intptr_t num_flds = (data.raw()->to() - data.raw()->from()); | |
| 650 intptr_t from_offset = OFFSET_OF_FROM(data); | |
| 651 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 652 (*reader->PassiveObjectHandle()) = | |
| 653 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); | |
| 654 data.StorePointer((data.raw()->from() + i), | |
| 655 reader->PassiveObjectHandle()->raw()); | |
| 656 } | |
| 657 | 603 |
| 658 return data.raw(); | 604 return data.raw(); |
| 659 } | 605 } |
| 660 | 606 |
| 661 | 607 |
| 662 void RawRedirectionData::WriteTo(SnapshotWriter* writer, | 608 void RawRedirectionData::WriteTo(SnapshotWriter* writer, |
| 663 intptr_t object_id, | 609 intptr_t object_id, |
| 664 Snapshot::Kind kind) { | 610 Snapshot::Kind kind) { |
| 665 ASSERT(writer != NULL); | 611 ASSERT(writer != NULL); |
| 666 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 612 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 695 func.set_end_token_pos(reader->Read<int32_t>()); | 641 func.set_end_token_pos(reader->Read<int32_t>()); |
| 696 func.set_usage_counter(reader->Read<int32_t>()); | 642 func.set_usage_counter(reader->Read<int32_t>()); |
| 697 func.set_num_fixed_parameters(reader->Read<int16_t>()); | 643 func.set_num_fixed_parameters(reader->Read<int16_t>()); |
| 698 func.set_num_optional_parameters(reader->Read<int16_t>()); | 644 func.set_num_optional_parameters(reader->Read<int16_t>()); |
| 699 func.set_deoptimization_counter(reader->Read<int16_t>()); | 645 func.set_deoptimization_counter(reader->Read<int16_t>()); |
| 700 func.set_kind_tag(reader->Read<uint32_t>()); | 646 func.set_kind_tag(reader->Read<uint32_t>()); |
| 701 func.set_optimized_instruction_count(reader->Read<uint16_t>()); | 647 func.set_optimized_instruction_count(reader->Read<uint16_t>()); |
| 702 func.set_optimized_call_site_count(reader->Read<uint16_t>()); | 648 func.set_optimized_call_site_count(reader->Read<uint16_t>()); |
| 703 | 649 |
| 704 // Set all the object fields. | 650 // Set all the object fields. |
| 705 // TODO(5411462): Need to assert No GC can happen here, even though | 651 READ_OBJECT_FIELDS(func, |
| 706 // allocations may happen. | 652 func.raw()->from(), |
| 707 RawObject** toaddr = reader->snapshot_code() ? func.raw()->to() | 653 reader->snapshot_code() ? func.raw()->to() |
| 708 : func.raw()->to_snapshot(); | 654 : func.raw()->to_snapshot(), |
| 709 intptr_t num_flds = toaddr - func.raw()->from(); | 655 kAsReference); |
| 710 intptr_t from_offset = OFFSET_OF_FROM(func); | |
| 711 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 712 (*reader->PassiveObjectHandle()) = | |
| 713 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); | |
| 714 func.StorePointer((func.raw()->from() + i), | |
| 715 reader->PassiveObjectHandle()->raw()); | |
| 716 } | |
| 717 | 656 |
| 718 if (!reader->snapshot_code()) { | 657 if (!reader->snapshot_code()) { |
| 719 // Initialize all fields that are not part of the snapshot. | 658 // Initialize all fields that are not part of the snapshot. |
| 720 func.ClearICDataArray(); | 659 func.ClearICDataArray(); |
| 721 func.ClearCode(); | 660 func.ClearCode(); |
| 661 } else { |
| 662 // TODO(rmacnak): Fix entry_point_. |
| 722 } | 663 } |
| 723 return func.raw(); | 664 return func.raw(); |
| 724 } | 665 } |
| 725 | 666 |
| 726 | 667 |
| 727 void RawFunction::WriteTo(SnapshotWriter* writer, | 668 void RawFunction::WriteTo(SnapshotWriter* writer, |
| 728 intptr_t object_id, | 669 intptr_t object_id, |
| 729 Snapshot::Kind kind) { | 670 Snapshot::Kind kind) { |
| 730 ASSERT(writer != NULL); | 671 ASSERT(writer != NULL); |
| 731 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 672 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 Field& field = Field::ZoneHandle(reader->zone(), NEW_OBJECT(Field)); | 711 Field& field = Field::ZoneHandle(reader->zone(), NEW_OBJECT(Field)); |
| 771 reader->AddBackRef(object_id, &field, kIsDeserialized); | 712 reader->AddBackRef(object_id, &field, kIsDeserialized); |
| 772 | 713 |
| 773 // Set all non object fields. | 714 // Set all non object fields. |
| 774 field.set_token_pos(reader->Read<int32_t>()); | 715 field.set_token_pos(reader->Read<int32_t>()); |
| 775 field.set_guarded_cid(reader->Read<int32_t>()); | 716 field.set_guarded_cid(reader->Read<int32_t>()); |
| 776 field.set_is_nullable(reader->Read<int32_t>()); | 717 field.set_is_nullable(reader->Read<int32_t>()); |
| 777 field.set_kind_bits(reader->Read<uint8_t>()); | 718 field.set_kind_bits(reader->Read<uint8_t>()); |
| 778 | 719 |
| 779 // Set all the object fields. | 720 // Set all the object fields. |
| 780 // TODO(5411462): Need to assert No GC can happen here, even though | 721 READ_OBJECT_FIELDS(field, |
| 781 // allocations may happen. | 722 field.raw()->from(), field.raw()->to(), |
| 782 intptr_t num_flds = (field.raw()->to() - field.raw()->from()); | 723 kAsReference); |
| 783 intptr_t from_offset = OFFSET_OF_FROM(field); | |
| 784 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 785 (*reader->PassiveObjectHandle()) = | |
| 786 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); | |
| 787 field.StorePointer((field.raw()->from() + i), | |
| 788 reader->PassiveObjectHandle()->raw()); | |
| 789 } | |
| 790 | 724 |
| 791 field.InitializeGuardedListLengthInObjectOffset(); | 725 field.InitializeGuardedListLengthInObjectOffset(); |
| 792 | 726 |
| 793 return field.raw(); | 727 return field.raw(); |
| 794 } | 728 } |
| 795 | 729 |
| 796 | 730 |
| 797 void RawField::WriteTo(SnapshotWriter* writer, | 731 void RawField::WriteTo(SnapshotWriter* writer, |
| 798 intptr_t object_id, | 732 intptr_t object_id, |
| 799 Snapshot::Kind kind) { | 733 Snapshot::Kind kind) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 829 // Create the literal token object. | 763 // Create the literal token object. |
| 830 LiteralToken& literal_token = LiteralToken::ZoneHandle( | 764 LiteralToken& literal_token = LiteralToken::ZoneHandle( |
| 831 reader->zone(), NEW_OBJECT(LiteralToken)); | 765 reader->zone(), NEW_OBJECT(LiteralToken)); |
| 832 reader->AddBackRef(object_id, &literal_token, kIsDeserialized); | 766 reader->AddBackRef(object_id, &literal_token, kIsDeserialized); |
| 833 | 767 |
| 834 // Read the token attributes. | 768 // Read the token attributes. |
| 835 Token::Kind token_kind = static_cast<Token::Kind>(reader->Read<int32_t>()); | 769 Token::Kind token_kind = static_cast<Token::Kind>(reader->Read<int32_t>()); |
| 836 literal_token.set_kind(token_kind); | 770 literal_token.set_kind(token_kind); |
| 837 | 771 |
| 838 // Set all the object fields. | 772 // Set all the object fields. |
| 839 // TODO(5411462): Need to assert No GC can happen here, even though | 773 READ_OBJECT_FIELDS(literal_token, |
| 840 // allocations may happen. | 774 literal_token.raw()->from(), literal_token.raw()->to(), |
| 841 intptr_t num_flds = (literal_token.raw()->to() - literal_token.raw()->from()); | 775 kAsReference); |
| 842 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 843 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 844 literal_token.StorePointer((literal_token.raw()->from() + i), | |
| 845 reader->PassiveObjectHandle()->raw()); | |
| 846 } | |
| 847 | 776 |
| 848 return literal_token.raw(); | 777 return literal_token.raw(); |
| 849 } | 778 } |
| 850 | 779 |
| 851 | 780 |
| 852 void RawLiteralToken::WriteTo(SnapshotWriter* writer, | 781 void RawLiteralToken::WriteTo(SnapshotWriter* writer, |
| 853 intptr_t object_id, | 782 intptr_t object_id, |
| 854 Snapshot::Kind kind) { | 783 Snapshot::Kind kind) { |
| 855 ASSERT(writer != NULL); | 784 ASSERT(writer != NULL); |
| 856 ASSERT(kind != Snapshot::kMessage); | 785 ASSERT(kind != Snapshot::kMessage); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 reader->AddBackRef(object_id, &prefix, kIsDeserialized); | 1046 reader->AddBackRef(object_id, &prefix, kIsDeserialized); |
| 1118 | 1047 |
| 1119 // Set all non object fields. | 1048 // Set all non object fields. |
| 1120 prefix.StoreNonPointer(&prefix.raw_ptr()->num_imports_, | 1049 prefix.StoreNonPointer(&prefix.raw_ptr()->num_imports_, |
| 1121 reader->Read<int16_t>()); | 1050 reader->Read<int16_t>()); |
| 1122 prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_, | 1051 prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_, |
| 1123 reader->Read<bool>()); | 1052 reader->Read<bool>()); |
| 1124 prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, reader->Read<bool>()); | 1053 prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, reader->Read<bool>()); |
| 1125 | 1054 |
| 1126 // Set all the object fields. | 1055 // Set all the object fields. |
| 1127 // TODO(5411462): Need to assert No GC can happen here, even though | 1056 READ_OBJECT_FIELDS(prefix, |
| 1128 // allocations may happen. | 1057 prefix.raw()->from(), prefix.raw()->to(), |
| 1129 intptr_t num_flds = (prefix.raw()->to() - prefix.raw()->from()); | 1058 kAsReference); |
| 1130 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 1131 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 1132 prefix.StorePointer((prefix.raw()->from() + i), | |
| 1133 reader->PassiveObjectHandle()->raw()); | |
| 1134 } | |
| 1135 | 1059 |
| 1136 return prefix.raw(); | 1060 return prefix.raw(); |
| 1137 } | 1061 } |
| 1138 | 1062 |
| 1139 | 1063 |
| 1140 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, | 1064 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, |
| 1141 intptr_t object_id, | 1065 intptr_t object_id, |
| 1142 Snapshot::Kind kind) { | 1066 Snapshot::Kind kind) { |
| 1143 ASSERT(writer != NULL); | 1067 ASSERT(writer != NULL); |
| 1144 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 1068 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1167 Snapshot::Kind kind) { | 1091 Snapshot::Kind kind) { |
| 1168 ASSERT(reader != NULL); | 1092 ASSERT(reader != NULL); |
| 1169 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 1093 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 1170 | 1094 |
| 1171 // Allocate Namespace object. | 1095 // Allocate Namespace object. |
| 1172 Namespace& ns = Namespace::ZoneHandle( | 1096 Namespace& ns = Namespace::ZoneHandle( |
| 1173 reader->zone(), NEW_OBJECT(Namespace)); | 1097 reader->zone(), NEW_OBJECT(Namespace)); |
| 1174 reader->AddBackRef(object_id, &ns, kIsDeserialized); | 1098 reader->AddBackRef(object_id, &ns, kIsDeserialized); |
| 1175 | 1099 |
| 1176 // Set all the object fields. | 1100 // Set all the object fields. |
| 1177 // TODO(5411462): Need to assert No GC can happen here, even though | 1101 READ_OBJECT_FIELDS(ns, ns.raw()->from(), ns.raw()->to(), kAsReference); |
| 1178 // allocations may happen. | |
| 1179 intptr_t num_flds = (ns.raw()->to() - ns.raw()->from()); | |
| 1180 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 1181 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 1182 ns.StorePointer((ns.raw()->from() + i), | |
| 1183 reader->PassiveObjectHandle()->raw()); | |
| 1184 } | |
| 1185 | 1102 |
| 1186 return ns.raw(); | 1103 return ns.raw(); |
| 1187 } | 1104 } |
| 1188 | 1105 |
| 1189 | 1106 |
| 1190 void RawNamespace::WriteTo(SnapshotWriter* writer, | 1107 void RawNamespace::WriteTo(SnapshotWriter* writer, |
| 1191 intptr_t object_id, | 1108 intptr_t object_id, |
| 1192 Snapshot::Kind kind) { | 1109 Snapshot::Kind kind) { |
| 1193 ASSERT(writer != NULL); | 1110 ASSERT(writer != NULL); |
| 1194 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 1111 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 1195 | 1112 |
| 1196 // Write out the serialization header value for this object. | 1113 // Write out the serialization header value for this object. |
| 1197 writer->WriteInlinedObjectHeader(object_id); | 1114 writer->WriteInlinedObjectHeader(object_id); |
| 1198 | 1115 |
| 1199 // Write out the class and tags information. | 1116 // Write out the class and tags information. |
| 1200 writer->WriteVMIsolateObject(kNamespaceCid); | 1117 writer->WriteVMIsolateObject(kNamespaceCid); |
| 1201 writer->WriteTags(writer->GetObjectTags(this)); | 1118 writer->WriteTags(writer->GetObjectTags(this)); |
| 1202 | 1119 |
| 1203 // Write out all the object pointer fields. | 1120 // Write out all the object pointer fields. |
| 1204 SnapshotWriterVisitor visitor(writer); | 1121 SnapshotWriterVisitor visitor(writer); |
| 1205 visitor.VisitPointers(from(), to()); | 1122 visitor.VisitPointers(from(), to()); |
| 1206 } | 1123 } |
| 1207 | 1124 |
| 1208 | 1125 |
| 1209 RawCode* Code::ReadFrom(SnapshotReader* reader, | 1126 RawCode* Code::ReadFrom(SnapshotReader* reader, |
| 1210 intptr_t object_id, | 1127 intptr_t object_id, |
| 1211 intptr_t tags, | 1128 intptr_t tags, |
| 1212 Snapshot::Kind kind) { | 1129 Snapshot::Kind kind) { |
| 1213 UNREACHABLE(); // Untested. | |
| 1214 ASSERT(reader->snapshot_code()); | 1130 ASSERT(reader->snapshot_code()); |
| 1215 ASSERT(kind == Snapshot::kFull); | 1131 ASSERT(kind == Snapshot::kFull); |
| 1216 | 1132 |
| 1217 Code& result = Code::ZoneHandle(reader->zone(), NEW_OBJECT_WITH_LEN(Code, 0)); | 1133 Code& result = Code::ZoneHandle(reader->zone(), NEW_OBJECT_WITH_LEN(Code, 0)); |
| 1218 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1134 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1219 | 1135 |
| 1220 result.set_compile_timestamp(reader->Read<int64_t>()); | 1136 result.set_compile_timestamp(reader->Read<int64_t>()); |
| 1221 result.set_state_bits(reader->Read<int32_t>()); | 1137 result.set_state_bits(reader->Read<int32_t>()); |
| 1222 result.set_entry_patch_pc_offset(reader->Read<int32_t>()); | 1138 result.set_entry_patch_pc_offset(reader->Read<int32_t>()); |
| 1223 result.set_patch_code_pc_offset(reader->Read<int32_t>()); | 1139 result.set_patch_code_pc_offset(reader->Read<int32_t>()); |
| 1224 result.set_lazy_deopt_pc_offset(reader->Read<int32_t>()); | 1140 result.set_lazy_deopt_pc_offset(reader->Read<int32_t>()); |
| 1225 | 1141 |
| 1226 // Set all the object fields. | 1142 // Set all the object fields. |
| 1227 // TODO(5411462): Need to assert No GC can happen here, even though | 1143 READ_OBJECT_FIELDS(result, |
| 1228 // allocations may happen. | 1144 result.raw()->from(), result.raw()->to(), |
| 1229 intptr_t num_flds = (result.raw()->to() - result.raw()->from()); | 1145 kAsReference); |
| 1230 for (intptr_t i = 0; i <= num_flds; i++) { | 1146 |
| 1231 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 1147 // TODO(rmacnak): Fix entry_point_. |
| 1232 result.StorePointer((result.raw()->from() + i), | |
| 1233 reader->PassiveObjectHandle()->raw()); | |
| 1234 } | |
| 1235 | 1148 |
| 1236 return result.raw(); | 1149 return result.raw(); |
| 1237 } | 1150 } |
| 1238 | 1151 |
| 1239 | 1152 |
| 1240 void RawCode::WriteTo(SnapshotWriter* writer, | 1153 void RawCode::WriteTo(SnapshotWriter* writer, |
| 1241 intptr_t object_id, | 1154 intptr_t object_id, |
| 1242 Snapshot::Kind kind) { | 1155 Snapshot::Kind kind) { |
| 1243 ASSERT(writer->snapshot_code()); | 1156 ASSERT(writer->snapshot_code()); |
| 1244 ASSERT(kind == Snapshot::kFull); | 1157 ASSERT(kind == Snapshot::kFull); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1267 // Write out all the object pointer fields. | 1180 // Write out all the object pointer fields. |
| 1268 SnapshotWriterVisitor visitor(writer); | 1181 SnapshotWriterVisitor visitor(writer); |
| 1269 visitor.VisitPointers(from(), to()); | 1182 visitor.VisitPointers(from(), to()); |
| 1270 } | 1183 } |
| 1271 | 1184 |
| 1272 | 1185 |
| 1273 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, | 1186 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, |
| 1274 intptr_t object_id, | 1187 intptr_t object_id, |
| 1275 intptr_t tags, | 1188 intptr_t tags, |
| 1276 Snapshot::Kind kind) { | 1189 Snapshot::Kind kind) { |
| 1277 UNREACHABLE(); // Untested. | |
| 1278 ASSERT(reader->snapshot_code()); | 1190 ASSERT(reader->snapshot_code()); |
| 1279 ASSERT(kind == Snapshot::kFull); | 1191 ASSERT(kind == Snapshot::kFull); |
| 1280 | 1192 |
| 1281 intptr_t id = reader->Read<int32_t>(); | 1193 intptr_t full_tags = static_cast<uword>(reader->Read<intptr_t>()); |
| 1194 intptr_t offset = reader->Read<int32_t>(); |
| 1282 Instructions& result = | 1195 Instructions& result = |
| 1283 Instructions::ZoneHandle(reader->zone(), | 1196 Instructions::ZoneHandle(reader->zone(), |
| 1284 reader->GetInstructionsById(id)); | 1197 reader->GetInstructionsAt(offset, full_tags)); |
| 1285 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1198 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1199 |
| 1200 { |
| 1201 // TODO(rmacnak): Drop after calling convention change. |
| 1202 Code::CheckedHandle(reader->ReadObjectImpl(kAsReference)); |
| 1203 ObjectPool::CheckedHandle(reader->ReadObjectImpl(kAsReference)); |
| 1204 } |
| 1205 |
| 1286 return result.raw(); | 1206 return result.raw(); |
| 1287 } | 1207 } |
| 1288 | 1208 |
| 1289 | 1209 |
| 1290 void RawInstructions::WriteTo(SnapshotWriter* writer, | 1210 void RawInstructions::WriteTo(SnapshotWriter* writer, |
| 1291 intptr_t object_id, | 1211 intptr_t object_id, |
| 1292 Snapshot::Kind kind) { | 1212 Snapshot::Kind kind) { |
| 1293 ASSERT(writer->snapshot_code()); | 1213 ASSERT(writer->snapshot_code()); |
| 1294 ASSERT(kind == Snapshot::kFull); | 1214 ASSERT(kind == Snapshot::kFull); |
| 1295 | 1215 |
| 1296 { | 1216 { |
| 1297 // TODO(rmacnak): Drop after calling convention change. | 1217 // TODO(rmacnak): Drop after calling convention change. |
| 1298 writer->WriteInlinedObjectHeader(object_id); | 1218 writer->WriteInlinedObjectHeader(object_id); |
| 1299 writer->WriteVMIsolateObject(kInstructionsCid); | 1219 writer->WriteVMIsolateObject(kInstructionsCid); |
| 1300 writer->WriteTags(writer->GetObjectTags(this)); | 1220 writer->WriteTags(writer->GetObjectTags(this)); |
| 1221 } |
| 1222 |
| 1223 writer->Write<intptr_t>(writer->GetObjectTags(this)); // For sanity check. |
| 1224 |
| 1225 // Temporarily restore the object header for writing to the text section. |
| 1226 // TODO(asiva): Don't mutate object headers during serialization. |
| 1227 uword object_tags = writer->GetObjectTags(this); |
| 1228 uword snapshot_tags = ptr()->tags_; |
| 1229 ptr()->tags_ = object_tags; |
| 1230 writer->Write<int32_t>(writer->GetInstructionsId(this)); |
| 1231 ptr()->tags_ = snapshot_tags; |
| 1232 |
| 1233 { |
| 1234 // TODO(rmacnak): Drop after calling convention change. |
| 1301 writer->WriteObjectImpl(ptr()->code_, kAsReference); | 1235 writer->WriteObjectImpl(ptr()->code_, kAsReference); |
| 1302 writer->WriteObjectImpl(ptr()->object_pool_, kAsReference); | 1236 writer->WriteObjectImpl(ptr()->object_pool_, kAsReference); |
| 1303 } | 1237 } |
| 1304 | |
| 1305 writer->Write<int32_t>(writer->GetInstructionsId(this)); | |
| 1306 } | 1238 } |
| 1307 | 1239 |
| 1308 | 1240 |
| 1309 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, | 1241 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, |
| 1310 intptr_t object_id, | 1242 intptr_t object_id, |
| 1311 intptr_t tags, | 1243 intptr_t tags, |
| 1312 Snapshot::Kind kind) { | 1244 Snapshot::Kind kind) { |
| 1313 UNREACHABLE(); // Untested. | |
| 1314 ASSERT(reader->snapshot_code()); | 1245 ASSERT(reader->snapshot_code()); |
| 1315 ASSERT(kind == Snapshot::kFull); | 1246 ASSERT(kind == Snapshot::kFull); |
| 1316 | 1247 |
| 1317 intptr_t length = reader->Read<intptr_t>(); | 1248 intptr_t length = reader->Read<intptr_t>(); |
| 1318 | 1249 |
| 1319 ObjectPool& result = | 1250 ObjectPool& result = |
| 1320 ObjectPool::ZoneHandle(reader->zone(), | 1251 ObjectPool::ZoneHandle(reader->zone(), |
| 1321 NEW_OBJECT_WITH_LEN(ObjectPool, length)); | 1252 NEW_OBJECT_WITH_LEN(ObjectPool, length)); |
| 1322 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1253 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1323 | 1254 |
| 1324 RawTypedData* info_array = result.raw_ptr()->info_array_->ptr(); | 1255 const TypedData& info_array = |
| 1256 TypedData::Handle(reader->NewTypedData(kTypedDataInt8ArrayCid, length)); |
| 1257 result.set_info_array(info_array); |
| 1325 | 1258 |
| 1326 // Set all the object fields. | 1259 NoSafepointScope no_safepoint; |
| 1327 // TODO(5411462): Need to assert No GC can happen here, even though | |
| 1328 // allocations may happen. | |
| 1329 for (intptr_t i = 0; i < length; i++) { | 1260 for (intptr_t i = 0; i < length; i++) { |
| 1330 ObjectPool::EntryType entry_type = | 1261 ObjectPool::EntryType entry_type = |
| 1331 static_cast<ObjectPool::EntryType>(reader->Read<uint8_t>()); | 1262 static_cast<ObjectPool::EntryType>(reader->Read<int8_t>()); |
| 1332 info_array->data()[i] = entry_type; | 1263 *reinterpret_cast<int8_t*>(info_array.DataAddr(i)) = entry_type; |
| 1333 switch (entry_type) { | 1264 switch (entry_type) { |
| 1334 case ObjectPool::kTaggedObject: { | 1265 case ObjectPool::kTaggedObject: { |
| 1335 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | 1266 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); |
| 1336 result.SetObjectAt(i, *(reader->PassiveObjectHandle())); | 1267 result.SetObjectAt(i, *(reader->PassiveObjectHandle())); |
| 1337 break; | 1268 break; |
| 1338 } | 1269 } |
| 1339 case ObjectPool::kImmediate: { | 1270 case ObjectPool::kImmediate: { |
| 1340 intptr_t raw_value = reader->Read<intptr_t>(); | 1271 intptr_t raw_value = reader->Read<intptr_t>(); |
| 1341 result.SetRawValueAt(i, raw_value); | 1272 result.SetRawValueAt(i, raw_value); |
| 1342 break; | 1273 break; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1370 writer->WriteTags(writer->GetObjectTags(this)); | 1301 writer->WriteTags(writer->GetObjectTags(this)); |
| 1371 | 1302 |
| 1372 intptr_t length = ptr()->length_; | 1303 intptr_t length = ptr()->length_; |
| 1373 RawTypedData* info_array = ptr()->info_array_->ptr(); | 1304 RawTypedData* info_array = ptr()->info_array_->ptr(); |
| 1374 ASSERT(info_array != TypedData::null()); | 1305 ASSERT(info_array != TypedData::null()); |
| 1375 | 1306 |
| 1376 writer->Write<intptr_t>(length); | 1307 writer->Write<intptr_t>(length); |
| 1377 for (intptr_t i = 0; i < length; i++) { | 1308 for (intptr_t i = 0; i < length; i++) { |
| 1378 ObjectPool::EntryType entry_type = | 1309 ObjectPool::EntryType entry_type = |
| 1379 static_cast<ObjectPool::EntryType>(info_array->data()[i]); | 1310 static_cast<ObjectPool::EntryType>(info_array->data()[i]); |
| 1380 writer->Write<uint8_t>(entry_type); | 1311 writer->Write<int8_t>(entry_type); |
| 1381 Entry& entry = ptr()->data()[i]; | 1312 Entry& entry = ptr()->data()[i]; |
| 1382 switch (entry_type) { | 1313 switch (entry_type) { |
| 1383 case ObjectPool::kTaggedObject: | 1314 case ObjectPool::kTaggedObject: |
| 1384 writer->WriteObjectImpl(entry.raw_obj_, kAsReference); | 1315 writer->WriteObjectImpl(entry.raw_obj_, kAsReference); |
| 1385 break; | 1316 break; |
| 1386 case ObjectPool::kImmediate: | 1317 case ObjectPool::kImmediate: |
| 1387 writer->Write<intptr_t>(entry.raw_value_); | 1318 writer->Write<intptr_t>(entry.raw_value_); |
| 1388 break; | 1319 break; |
| 1389 case ObjectPool::kExternalLabel: | 1320 case ObjectPool::kExternalLabel: |
| 1390 // TODO(rmacnak): Write symbolically. | 1321 // TODO(rmacnak): Write symbolically. |
| 1391 writer->Write<intptr_t>(entry.raw_value_); | 1322 writer->Write<intptr_t>(entry.raw_value_); |
| 1392 break; | 1323 break; |
| 1393 default: | 1324 default: |
| 1394 UNREACHABLE(); | 1325 UNREACHABLE(); |
| 1395 } | 1326 } |
| 1396 } | 1327 } |
| 1397 } | 1328 } |
| 1398 | 1329 |
| 1399 | 1330 |
| 1400 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader, | 1331 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader, |
| 1401 intptr_t object_id, | 1332 intptr_t object_id, |
| 1402 intptr_t tags, | 1333 intptr_t tags, |
| 1403 Snapshot::Kind kind) { | 1334 Snapshot::Kind kind) { |
| 1404 UNREACHABLE(); // Untested. | |
| 1405 ASSERT(reader->snapshot_code()); | 1335 ASSERT(reader->snapshot_code()); |
| 1336 ASSERT(kind == Snapshot::kFull); |
| 1406 | 1337 |
| 1407 const int32_t length = reader->Read<int32_t>(); | 1338 const int32_t length = reader->Read<int32_t>(); |
| 1408 PcDescriptors& result = PcDescriptors::ZoneHandle(reader->zone(), | 1339 PcDescriptors& result = |
| 1409 PcDescriptors::New(length)); | 1340 PcDescriptors::ZoneHandle(reader->zone(), |
| 1341 NEW_OBJECT_WITH_LEN(PcDescriptors, length)); |
| 1410 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1342 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1411 | 1343 |
| 1412 if (result.Length() > 0) { | 1344 if (result.Length() > 0) { |
| 1413 NoSafepointScope no_safepoint; | 1345 NoSafepointScope no_safepoint; |
| 1414 intptr_t len = result.Length(); | 1346 intptr_t len = result.Length(); |
| 1415 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); | 1347 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); |
| 1416 reader->ReadBytes(data, len); | 1348 reader->ReadBytes(data, len); |
| 1417 } | 1349 } |
| 1418 | 1350 |
| 1419 return result.raw(); | 1351 return result.raw(); |
| 1420 } | 1352 } |
| 1421 | 1353 |
| 1422 | 1354 |
| 1423 void RawPcDescriptors::WriteTo(SnapshotWriter* writer, | 1355 void RawPcDescriptors::WriteTo(SnapshotWriter* writer, |
| 1424 intptr_t object_id, | 1356 intptr_t object_id, |
| 1425 Snapshot::Kind kind) { | 1357 Snapshot::Kind kind) { |
| 1426 ASSERT(writer->snapshot_code()); | 1358 ASSERT(writer->snapshot_code()); |
| 1359 ASSERT(kind == Snapshot::kFull); |
| 1427 | 1360 |
| 1428 // Write out the serialization header value for this object. | 1361 // Write out the serialization header value for this object. |
| 1429 writer->WriteInlinedObjectHeader(object_id); | 1362 writer->WriteInlinedObjectHeader(object_id); |
| 1430 writer->WriteIndexedObject(kPcDescriptorsCid); | 1363 writer->WriteIndexedObject(kPcDescriptorsCid); |
| 1431 writer->WriteTags(writer->GetObjectTags(this)); | 1364 writer->WriteTags(writer->GetObjectTags(this)); |
| 1432 writer->Write<int32_t>(ptr()->length_); | 1365 writer->Write<int32_t>(ptr()->length_); |
| 1433 if (ptr()->length_ > 0) { | 1366 if (ptr()->length_ > 0) { |
| 1434 intptr_t len = ptr()->length_; | 1367 intptr_t len = ptr()->length_; |
| 1435 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); | 1368 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); |
| 1436 writer->WriteBytes(data, len); | 1369 writer->WriteBytes(data, len); |
| 1437 } | 1370 } |
| 1438 } | 1371 } |
| 1439 | 1372 |
| 1440 | 1373 |
| 1441 RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader, | 1374 RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader, |
| 1442 intptr_t object_id, | 1375 intptr_t object_id, |
| 1443 intptr_t tags, | 1376 intptr_t tags, |
| 1444 Snapshot::Kind kind) { | 1377 Snapshot::Kind kind) { |
| 1445 UNREACHABLE(); // Untested. | |
| 1446 ASSERT(reader->snapshot_code()); | 1378 ASSERT(reader->snapshot_code()); |
| 1379 ASSERT(kind == Snapshot::kFull); |
| 1447 | 1380 |
| 1448 const int32_t length = reader->Read<int32_t>(); | 1381 const int32_t length = reader->Read<int32_t>(); |
| 1449 const int32_t register_bit_count = reader->Read<int32_t>(); | |
| 1450 const uword pc_offset = reader->Read<uint32_t>(); | |
| 1451 | |
| 1452 Stackmap& result = | 1382 Stackmap& result = |
| 1453 Stackmap::ZoneHandle(reader->zone(), | 1383 Stackmap::ZoneHandle(reader->zone(), |
| 1454 Stackmap::New(length, register_bit_count, pc_offset)); | 1384 reader->NewStackmap(length)); |
| 1455 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1385 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1456 | 1386 |
| 1457 if (result.Length() > 0) { | 1387 result.SetRegisterBitCount(reader->Read<int32_t>()); |
| 1388 result.SetPcOffset(reader->Read<uint32_t>()); |
| 1389 |
| 1390 if (length > 0) { |
| 1458 NoSafepointScope no_safepoint; | 1391 NoSafepointScope no_safepoint; |
| 1459 intptr_t len = (result.Length() + 7) / 8; | 1392 intptr_t len = (result.Length() + 7) / 8; |
| 1460 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); | 1393 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); |
| 1461 reader->ReadBytes(data, len); | 1394 reader->ReadBytes(data, len); |
| 1462 } | 1395 } |
| 1463 | 1396 |
| 1464 return result.raw(); | 1397 return result.raw(); |
| 1465 } | 1398 } |
| 1466 | 1399 |
| 1467 | 1400 |
| 1468 void RawStackmap::WriteTo(SnapshotWriter* writer, | 1401 void RawStackmap::WriteTo(SnapshotWriter* writer, |
| 1469 intptr_t object_id, | 1402 intptr_t object_id, |
| 1470 Snapshot::Kind kind) { | 1403 Snapshot::Kind kind) { |
| 1471 ASSERT(writer->snapshot_code()); | 1404 ASSERT(writer->snapshot_code()); |
| 1405 ASSERT(kind == Snapshot::kFull); |
| 1472 | 1406 |
| 1473 // Write out the serialization header value for this object. | 1407 // Write out the serialization header value for this object. |
| 1474 writer->WriteInlinedObjectHeader(object_id); | 1408 writer->WriteInlinedObjectHeader(object_id); |
| 1475 writer->WriteIndexedObject(kStackmapCid); | 1409 writer->WriteIndexedObject(kStackmapCid); |
| 1476 writer->WriteTags(writer->GetObjectTags(this)); | 1410 writer->WriteTags(writer->GetObjectTags(this)); |
| 1411 |
| 1477 writer->Write<int32_t>(ptr()->length_); | 1412 writer->Write<int32_t>(ptr()->length_); |
| 1478 writer->Write<int32_t>(ptr()->register_bit_count_); | 1413 writer->Write<int32_t>(ptr()->register_bit_count_); |
| 1479 writer->Write<uint32_t>(ptr()->pc_offset_); | 1414 writer->Write<uint32_t>(ptr()->pc_offset_); |
| 1480 if (ptr()->length_ > 0) { | 1415 if (ptr()->length_ > 0) { |
| 1481 intptr_t len = (ptr()->length_ + 7) / 8; | 1416 intptr_t len = (ptr()->length_ + 7) / 8; |
| 1482 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); | 1417 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); |
| 1483 writer->WriteBytes(data, len); | 1418 writer->WriteBytes(data, len); |
| 1484 } | 1419 } |
| 1485 } | 1420 } |
| 1486 | 1421 |
| 1487 | 1422 |
| 1488 RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader, | 1423 RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader, |
| 1489 intptr_t object_id, | 1424 intptr_t object_id, |
| 1490 intptr_t tags, | 1425 intptr_t tags, |
| 1491 Snapshot::Kind kind) { | 1426 Snapshot::Kind kind) { |
| 1492 UNREACHABLE(); // Untested. | |
| 1493 ASSERT(reader->snapshot_code()); | 1427 ASSERT(reader->snapshot_code()); |
| 1428 ASSERT(kind == Snapshot::kFull); |
| 1494 | 1429 |
| 1495 const int32_t num_entries = reader->Read<int32_t>(); | 1430 const int32_t num_entries = reader->Read<int32_t>(); |
| 1496 | 1431 |
| 1497 LocalVarDescriptors& result = | 1432 LocalVarDescriptors& result = |
| 1498 LocalVarDescriptors::ZoneHandle(reader->zone(), | 1433 LocalVarDescriptors::ZoneHandle(reader->zone(), |
| 1499 LocalVarDescriptors::New(num_entries)); | 1434 NEW_OBJECT_WITH_LEN(LocalVarDescriptors, |
| 1435 num_entries)); |
| 1500 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1436 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1501 | 1437 |
| 1502 for (intptr_t i = 0; i < num_entries; i++) { | 1438 for (intptr_t i = 0; i < num_entries; i++) { |
| 1503 (*reader->StringHandle()) ^= reader->ReadObjectImpl(kAsReference); | 1439 (*reader->StringHandle()) ^= reader->ReadObjectImpl(kAsReference); |
| 1504 result.StorePointer(result.raw()->nameAddrAt(i), | 1440 result.StorePointer(result.raw()->nameAddrAt(i), |
| 1505 reader->StringHandle()->raw()); | 1441 reader->StringHandle()->raw()); |
| 1506 } | 1442 } |
| 1507 | 1443 |
| 1508 if (num_entries > 0) { | 1444 if (num_entries > 0) { |
| 1509 NoSafepointScope no_safepoint; | 1445 NoSafepointScope no_safepoint; |
| 1510 intptr_t len = num_entries * sizeof(RawLocalVarDescriptors::VarInfo); | 1446 intptr_t len = num_entries * sizeof(RawLocalVarDescriptors::VarInfo); |
| 1511 uint8_t* data = result.UnsafeMutableNonPointer( | 1447 uint8_t* data = result.UnsafeMutableNonPointer( |
| 1512 reinterpret_cast<const uint8_t*>(result.raw()->data())); | 1448 reinterpret_cast<const uint8_t*>(result.raw()->data())); |
| 1513 reader->ReadBytes(data, len); | 1449 reader->ReadBytes(data, len); |
| 1514 } | 1450 } |
| 1515 | 1451 |
| 1516 return result.raw(); | 1452 return result.raw(); |
| 1517 } | 1453 } |
| 1518 | 1454 |
| 1519 | 1455 |
| 1520 void RawLocalVarDescriptors::WriteTo(SnapshotWriter* writer, | 1456 void RawLocalVarDescriptors::WriteTo(SnapshotWriter* writer, |
| 1521 intptr_t object_id, | 1457 intptr_t object_id, |
| 1522 Snapshot::Kind kind) { | 1458 Snapshot::Kind kind) { |
| 1523 ASSERT(writer->snapshot_code()); | 1459 ASSERT(writer->snapshot_code()); |
| 1460 ASSERT(kind == Snapshot::kFull); |
| 1524 | 1461 |
| 1525 // Write out the serialization header value for this object. | 1462 // Write out the serialization header value for this object. |
| 1526 writer->WriteInlinedObjectHeader(object_id); | 1463 writer->WriteInlinedObjectHeader(object_id); |
| 1527 writer->WriteIndexedObject(kLocalVarDescriptorsCid); | 1464 writer->WriteIndexedObject(kLocalVarDescriptorsCid); |
| 1528 writer->WriteTags(writer->GetObjectTags(this)); | 1465 writer->WriteTags(writer->GetObjectTags(this)); |
| 1529 writer->Write<int32_t>(ptr()->num_entries_); | 1466 writer->Write<int32_t>(ptr()->num_entries_); |
| 1530 for (intptr_t i = 0; i < ptr()->num_entries_; i++) { | 1467 for (intptr_t i = 0; i < ptr()->num_entries_; i++) { |
| 1531 writer->WriteObjectImpl(ptr()->names()[i], kAsInlinedObject); | 1468 writer->WriteObjectImpl(ptr()->names()[i], kAsReference); |
| 1532 } | 1469 } |
| 1533 if (ptr()->num_entries_ > 0) { | 1470 if (ptr()->num_entries_ > 0) { |
| 1534 intptr_t len = ptr()->num_entries_ * sizeof(VarInfo); | 1471 intptr_t len = ptr()->num_entries_ * sizeof(VarInfo); |
| 1535 uint8_t* data = reinterpret_cast<uint8_t*>(this->data()); | 1472 uint8_t* data = reinterpret_cast<uint8_t*>(this->data()); |
| 1536 writer->WriteBytes(data, len); | 1473 writer->WriteBytes(data, len); |
| 1537 } | 1474 } |
| 1538 } | 1475 } |
| 1539 | 1476 |
| 1540 | 1477 |
| 1541 RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader, | 1478 RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader, |
| 1542 intptr_t object_id, | 1479 intptr_t object_id, |
| 1543 intptr_t tags, | 1480 intptr_t tags, |
| 1544 Snapshot::Kind kind) { | 1481 Snapshot::Kind kind) { |
| 1545 UNREACHABLE(); // Untested. | |
| 1546 ASSERT(reader->snapshot_code()); | 1482 ASSERT(reader->snapshot_code()); |
| 1483 ASSERT(kind == Snapshot::kFull); |
| 1547 | 1484 |
| 1548 // handled_types_data. | 1485 const int32_t num_entries = reader->Read<int32_t>(); |
| 1549 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); | |
| 1550 | |
| 1551 ExceptionHandlers& result = | 1486 ExceptionHandlers& result = |
| 1552 ExceptionHandlers::ZoneHandle(reader->zone(), | 1487 ExceptionHandlers::ZoneHandle(reader->zone(), |
| 1553 ExceptionHandlers::New(*reader->ArrayHandle())); | 1488 NEW_OBJECT_WITH_LEN(ExceptionHandlers, |
| 1489 num_entries)); |
| 1554 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1490 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1555 | 1491 |
| 1556 if (result.num_entries() > 0) { | 1492 if (result.num_entries() > 0) { |
| 1557 NoSafepointScope no_safepoint; | 1493 NoSafepointScope no_safepoint; |
| 1558 const intptr_t len = | 1494 const intptr_t len = |
| 1559 result.num_entries() * sizeof(RawExceptionHandlers::HandlerInfo); | 1495 result.num_entries() * sizeof(RawExceptionHandlers::HandlerInfo); |
| 1560 uint8_t* data = result.UnsafeMutableNonPointer( | 1496 uint8_t* data = result.UnsafeMutableNonPointer( |
| 1561 reinterpret_cast<const uint8_t*>(result.raw_ptr()->data())); | 1497 reinterpret_cast<const uint8_t*>(result.raw_ptr()->data())); |
| 1562 reader->ReadBytes(data, len); | 1498 reader->ReadBytes(data, len); |
| 1563 } | 1499 } |
| 1564 | 1500 |
| 1501 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); |
| 1502 result.StorePointer(&result.raw_ptr()->handled_types_data_, |
| 1503 reader->ArrayHandle()->raw()); |
| 1504 |
| 1565 return result.raw(); | 1505 return result.raw(); |
| 1566 } | 1506 } |
| 1567 | 1507 |
| 1568 | 1508 |
| 1569 void RawExceptionHandlers::WriteTo(SnapshotWriter* writer, | 1509 void RawExceptionHandlers::WriteTo(SnapshotWriter* writer, |
| 1570 intptr_t object_id, | 1510 intptr_t object_id, |
| 1571 Snapshot::Kind kind) { | 1511 Snapshot::Kind kind) { |
| 1572 ASSERT(writer->snapshot_code()); | 1512 ASSERT(writer->snapshot_code()); |
| 1513 ASSERT(kind == Snapshot::kFull); |
| 1573 | 1514 |
| 1574 // Write out the serialization header value for this object. | 1515 // Write out the serialization header value for this object. |
| 1575 writer->WriteInlinedObjectHeader(object_id); | 1516 writer->WriteInlinedObjectHeader(object_id); |
| 1576 writer->WriteIndexedObject(kExceptionHandlersCid); | 1517 writer->WriteIndexedObject(kExceptionHandlersCid); |
| 1577 writer->WriteTags(writer->GetObjectTags(this)); | 1518 writer->WriteTags(writer->GetObjectTags(this)); |
| 1578 writer->WriteObjectImpl(ptr()->handled_types_data_, kAsInlinedObject); | 1519 writer->Write<int32_t>(ptr()->num_entries_); |
| 1579 | 1520 |
| 1580 if (ptr()->num_entries_ > 0) { | 1521 if (ptr()->num_entries_ > 0) { |
| 1581 intptr_t len = ptr()->num_entries_ * sizeof(HandlerInfo); | 1522 intptr_t len = ptr()->num_entries_ * sizeof(HandlerInfo); |
| 1582 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); | 1523 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); |
| 1583 writer->WriteBytes(data, len); | 1524 writer->WriteBytes(data, len); |
| 1584 } | 1525 } |
| 1526 |
| 1527 writer->WriteObjectImpl(ptr()->handled_types_data_, kAsInlinedObject); |
| 1585 } | 1528 } |
| 1586 | 1529 |
| 1587 | 1530 |
| 1588 RawContext* Context::ReadFrom(SnapshotReader* reader, | 1531 RawContext* Context::ReadFrom(SnapshotReader* reader, |
| 1589 intptr_t object_id, | 1532 intptr_t object_id, |
| 1590 intptr_t tags, | 1533 intptr_t tags, |
| 1591 Snapshot::Kind kind) { | 1534 Snapshot::Kind kind) { |
| 1592 ASSERT(reader != NULL); | 1535 ASSERT(reader != NULL); |
| 1593 | 1536 |
| 1594 // Allocate context object. | 1537 // Allocate context object. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 | 1582 |
| 1640 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, | 1583 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, |
| 1641 intptr_t object_id, | 1584 intptr_t object_id, |
| 1642 intptr_t tags, | 1585 intptr_t tags, |
| 1643 Snapshot::Kind kind) { | 1586 Snapshot::Kind kind) { |
| 1644 ASSERT(reader != NULL); | 1587 ASSERT(reader != NULL); |
| 1645 | 1588 |
| 1646 // Allocate context object. | 1589 // Allocate context object. |
| 1647 bool is_implicit = reader->Read<bool>(); | 1590 bool is_implicit = reader->Read<bool>(); |
| 1648 if (is_implicit) { | 1591 if (is_implicit) { |
| 1649 ContextScope& context_scope = | 1592 ContextScope& context_scope = ContextScope::ZoneHandle(); |
| 1650 ContextScope::ZoneHandle(ContextScope::New(1, true)); | 1593 if (kind == Snapshot::kFull) { |
| 1594 context_scope = reader->NewContextScope(1); |
| 1595 context_scope.set_is_implicit(true); |
| 1596 } else { |
| 1597 context_scope = ContextScope::New(1, true); |
| 1598 } |
| 1651 reader->AddBackRef(object_id, &context_scope, kIsDeserialized); | 1599 reader->AddBackRef(object_id, &context_scope, kIsDeserialized); |
| 1652 | 1600 |
| 1653 *reader->TypeHandle() ^= reader->ReadObjectImpl(kAsInlinedObject); | 1601 *reader->TypeHandle() ^= reader->ReadObjectImpl(kAsInlinedObject); |
| 1654 | 1602 |
| 1655 // Create a descriptor for 'this' variable. | 1603 // Create a descriptor for 'this' variable. |
| 1656 context_scope.SetTokenIndexAt(0, 0); | 1604 context_scope.SetTokenIndexAt(0, 0); |
| 1657 context_scope.SetNameAt(0, Symbols::This()); | 1605 context_scope.SetNameAt(0, Symbols::This()); |
| 1658 context_scope.SetIsFinalAt(0, true); | 1606 context_scope.SetIsFinalAt(0, true); |
| 1659 context_scope.SetIsConstAt(0, false); | 1607 context_scope.SetIsConstAt(0, false); |
| 1660 context_scope.SetTypeAt(0, *reader->TypeHandle()); | 1608 context_scope.SetTypeAt(0, *reader->TypeHandle()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1692 return; | 1640 return; |
| 1693 } | 1641 } |
| 1694 UNREACHABLE(); | 1642 UNREACHABLE(); |
| 1695 } | 1643 } |
| 1696 | 1644 |
| 1697 | 1645 |
| 1698 RawICData* ICData::ReadFrom(SnapshotReader* reader, | 1646 RawICData* ICData::ReadFrom(SnapshotReader* reader, |
| 1699 intptr_t object_id, | 1647 intptr_t object_id, |
| 1700 intptr_t tags, | 1648 intptr_t tags, |
| 1701 Snapshot::Kind kind) { | 1649 Snapshot::Kind kind) { |
| 1702 UNREACHABLE(); // Untested. | |
| 1703 ASSERT(reader->snapshot_code()); | 1650 ASSERT(reader->snapshot_code()); |
| 1704 ASSERT(kind == Snapshot::kFull); | 1651 ASSERT(kind == Snapshot::kFull); |
| 1705 | 1652 |
| 1706 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); | 1653 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); |
| 1707 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1654 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1708 | 1655 |
| 1709 result.set_deopt_id(reader->Read<int32_t>()); | 1656 result.set_deopt_id(reader->Read<int32_t>()); |
| 1710 result.set_state_bits(reader->Read<uint32_t>()); | 1657 result.set_state_bits(reader->Read<uint32_t>()); |
| 1711 | 1658 |
| 1712 // Set all the object fields. | 1659 // Set all the object fields. |
| 1713 // TODO(5411462): Need to assert No GC can happen here, even though | 1660 READ_OBJECT_FIELDS(result, |
| 1714 // allocations may happen. | 1661 result.raw()->from(), result.raw()->to(), |
| 1715 intptr_t num_flds = (result.raw()->to() - result.raw()->from()); | 1662 kAsReference); |
| 1716 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 1717 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 1718 result.StorePointer((result.raw()->from() + i), | |
| 1719 reader->PassiveObjectHandle()->raw()); | |
| 1720 } | |
| 1721 | 1663 |
| 1722 return result.raw(); | 1664 return result.raw(); |
| 1723 } | 1665 } |
| 1724 | 1666 |
| 1725 | 1667 |
| 1726 void RawICData::WriteTo(SnapshotWriter* writer, | 1668 void RawICData::WriteTo(SnapshotWriter* writer, |
| 1727 intptr_t object_id, | 1669 intptr_t object_id, |
| 1728 Snapshot::Kind kind) { | 1670 Snapshot::Kind kind) { |
| 1729 ASSERT(writer->snapshot_code()); | 1671 ASSERT(writer->snapshot_code()); |
| 1730 ASSERT(kind == Snapshot::kFull); | 1672 ASSERT(kind == Snapshot::kFull); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1743 // Write out all the object pointer fields. | 1685 // Write out all the object pointer fields. |
| 1744 SnapshotWriterVisitor visitor(writer); | 1686 SnapshotWriterVisitor visitor(writer); |
| 1745 visitor.VisitPointers(from(), to()); | 1687 visitor.VisitPointers(from(), to()); |
| 1746 } | 1688 } |
| 1747 | 1689 |
| 1748 | 1690 |
| 1749 RawMegamorphicCache* MegamorphicCache::ReadFrom(SnapshotReader* reader, | 1691 RawMegamorphicCache* MegamorphicCache::ReadFrom(SnapshotReader* reader, |
| 1750 intptr_t object_id, | 1692 intptr_t object_id, |
| 1751 intptr_t tags, | 1693 intptr_t tags, |
| 1752 Snapshot::Kind kind) { | 1694 Snapshot::Kind kind) { |
| 1753 UNREACHABLE(); // Untested. | |
| 1754 ASSERT(reader->snapshot_code()); | 1695 ASSERT(reader->snapshot_code()); |
| 1755 ASSERT(kind == Snapshot::kFull); | 1696 ASSERT(kind == Snapshot::kFull); |
| 1756 | 1697 |
| 1757 MegamorphicCache& result = | 1698 MegamorphicCache& result = |
| 1758 MegamorphicCache::ZoneHandle(reader->zone(), | 1699 MegamorphicCache::ZoneHandle(reader->zone(), |
| 1759 NEW_OBJECT(MegamorphicCache)); | 1700 NEW_OBJECT(MegamorphicCache)); |
| 1760 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1701 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1761 | 1702 |
| 1762 result.set_filled_entry_count(reader->Read<int32_t>()); | 1703 result.set_filled_entry_count(reader->Read<int32_t>()); |
| 1763 | 1704 |
| 1764 // Set all the object fields. | 1705 // Set all the object fields. |
| 1765 // TODO(5411462): Need to assert No GC can happen here, even though | 1706 READ_OBJECT_FIELDS(result, |
| 1766 // allocations may happen. | 1707 result.raw()->from(), result.raw()->to(), |
| 1767 intptr_t num_flds = (result.raw()->to() - result.raw()->from()); | 1708 kAsReference); |
| 1768 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 1769 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 1770 result.StorePointer((result.raw()->from() + i), | |
| 1771 reader->PassiveObjectHandle()->raw()); | |
| 1772 } | |
| 1773 | 1709 |
| 1774 return result.raw(); | 1710 return result.raw(); |
| 1775 } | 1711 } |
| 1776 | 1712 |
| 1777 | 1713 |
| 1778 void RawMegamorphicCache::WriteTo(SnapshotWriter* writer, | 1714 void RawMegamorphicCache::WriteTo(SnapshotWriter* writer, |
| 1779 intptr_t object_id, | 1715 intptr_t object_id, |
| 1780 Snapshot::Kind kind) { | 1716 Snapshot::Kind kind) { |
| 1781 ASSERT(writer->snapshot_code()); | 1717 ASSERT(writer->snapshot_code()); |
| 1782 ASSERT(kind == Snapshot::kFull); | 1718 ASSERT(kind == Snapshot::kFull); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1794 // Write out all the object pointer fields. | 1730 // Write out all the object pointer fields. |
| 1795 SnapshotWriterVisitor visitor(writer); | 1731 SnapshotWriterVisitor visitor(writer); |
| 1796 visitor.VisitPointers(from(), to()); | 1732 visitor.VisitPointers(from(), to()); |
| 1797 } | 1733 } |
| 1798 | 1734 |
| 1799 | 1735 |
| 1800 RawSubtypeTestCache* SubtypeTestCache::ReadFrom(SnapshotReader* reader, | 1736 RawSubtypeTestCache* SubtypeTestCache::ReadFrom(SnapshotReader* reader, |
| 1801 intptr_t object_id, | 1737 intptr_t object_id, |
| 1802 intptr_t tags, | 1738 intptr_t tags, |
| 1803 Snapshot::Kind kind) { | 1739 Snapshot::Kind kind) { |
| 1804 UNREACHABLE(); // Untested. | |
| 1805 ASSERT(reader->snapshot_code()); | 1740 ASSERT(reader->snapshot_code()); |
| 1806 ASSERT(kind == Snapshot::kFull); | 1741 ASSERT(kind == Snapshot::kFull); |
| 1807 | 1742 |
| 1808 SubtypeTestCache& result = | 1743 SubtypeTestCache& result = |
| 1809 SubtypeTestCache::ZoneHandle(reader->zone(), | 1744 SubtypeTestCache::ZoneHandle(reader->zone(), |
| 1810 NEW_OBJECT(SubtypeTestCache)); | 1745 NEW_OBJECT(SubtypeTestCache)); |
| 1811 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1746 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1812 | 1747 |
| 1813 // Set all the object fields. | 1748 // Set all the object fields. |
| 1814 // TODO(5411462): Need to assert No GC can happen here, even though | 1749 // TODO(5411462): Need to assert No GC can happen here, even though |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 intptr_t tags, | 1795 intptr_t tags, |
| 1861 Snapshot::Kind kind) { | 1796 Snapshot::Kind kind) { |
| 1862 ASSERT(reader != NULL); | 1797 ASSERT(reader != NULL); |
| 1863 | 1798 |
| 1864 // Allocate ApiError object. | 1799 // Allocate ApiError object. |
| 1865 ApiError& api_error = | 1800 ApiError& api_error = |
| 1866 ApiError::ZoneHandle(reader->zone(), NEW_OBJECT(ApiError)); | 1801 ApiError::ZoneHandle(reader->zone(), NEW_OBJECT(ApiError)); |
| 1867 reader->AddBackRef(object_id, &api_error, kIsDeserialized); | 1802 reader->AddBackRef(object_id, &api_error, kIsDeserialized); |
| 1868 | 1803 |
| 1869 // Set all the object fields. | 1804 // Set all the object fields. |
| 1870 // TODO(5411462): Need to assert No GC can happen here, even though | 1805 READ_OBJECT_FIELDS(api_error, |
| 1871 // allocations may happen. | 1806 api_error.raw()->from(), api_error.raw()->to(), |
| 1872 intptr_t num_flds = (api_error.raw()->to() - api_error.raw()->from()); | 1807 kAsReference); |
| 1873 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 1874 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 1875 api_error.StorePointer((api_error.raw()->from() + i), | |
| 1876 reader->PassiveObjectHandle()->raw()); | |
| 1877 } | |
| 1878 | 1808 |
| 1879 return api_error.raw(); | 1809 return api_error.raw(); |
| 1880 } | 1810 } |
| 1881 | 1811 |
| 1882 | 1812 |
| 1883 void RawApiError::WriteTo(SnapshotWriter* writer, | 1813 void RawApiError::WriteTo(SnapshotWriter* writer, |
| 1884 intptr_t object_id, | 1814 intptr_t object_id, |
| 1885 Snapshot::Kind kind) { | 1815 Snapshot::Kind kind) { |
| 1886 ASSERT(writer != NULL); | 1816 ASSERT(writer != NULL); |
| 1887 | 1817 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1907 // Allocate LanguageError object. | 1837 // Allocate LanguageError object. |
| 1908 LanguageError& language_error = | 1838 LanguageError& language_error = |
| 1909 LanguageError::ZoneHandle(reader->zone(), NEW_OBJECT(LanguageError)); | 1839 LanguageError::ZoneHandle(reader->zone(), NEW_OBJECT(LanguageError)); |
| 1910 reader->AddBackRef(object_id, &language_error, kIsDeserialized); | 1840 reader->AddBackRef(object_id, &language_error, kIsDeserialized); |
| 1911 | 1841 |
| 1912 // Set all non object fields. | 1842 // Set all non object fields. |
| 1913 language_error.set_token_pos(reader->Read<int32_t>()); | 1843 language_error.set_token_pos(reader->Read<int32_t>()); |
| 1914 language_error.set_kind(reader->Read<uint8_t>()); | 1844 language_error.set_kind(reader->Read<uint8_t>()); |
| 1915 | 1845 |
| 1916 // Set all the object fields. | 1846 // Set all the object fields. |
| 1917 // TODO(5411462): Need to assert No GC can happen here, even though | 1847 READ_OBJECT_FIELDS(language_error, |
| 1918 // allocations may happen. | 1848 language_error.raw()->from(), language_error.raw()->to(), |
| 1919 intptr_t num_flds = | 1849 kAsReference); |
| 1920 (language_error.raw()->to() - language_error.raw()->from()); | |
| 1921 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 1922 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 1923 language_error.StorePointer((language_error.raw()->from() + i), | |
| 1924 reader->PassiveObjectHandle()->raw()); | |
| 1925 } | |
| 1926 | 1850 |
| 1927 return language_error.raw(); | 1851 return language_error.raw(); |
| 1928 } | 1852 } |
| 1929 | 1853 |
| 1930 | 1854 |
| 1931 void RawLanguageError::WriteTo(SnapshotWriter* writer, | 1855 void RawLanguageError::WriteTo(SnapshotWriter* writer, |
| 1932 intptr_t object_id, | 1856 intptr_t object_id, |
| 1933 Snapshot::Kind kind) { | 1857 Snapshot::Kind kind) { |
| 1934 ASSERT(writer != NULL); | 1858 ASSERT(writer != NULL); |
| 1935 | 1859 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1952 | 1876 |
| 1953 RawUnhandledException* UnhandledException::ReadFrom(SnapshotReader* reader, | 1877 RawUnhandledException* UnhandledException::ReadFrom(SnapshotReader* reader, |
| 1954 intptr_t object_id, | 1878 intptr_t object_id, |
| 1955 intptr_t tags, | 1879 intptr_t tags, |
| 1956 Snapshot::Kind kind) { | 1880 Snapshot::Kind kind) { |
| 1957 UnhandledException& result = UnhandledException::ZoneHandle( | 1881 UnhandledException& result = UnhandledException::ZoneHandle( |
| 1958 reader->zone(), NEW_OBJECT(UnhandledException)); | 1882 reader->zone(), NEW_OBJECT(UnhandledException)); |
| 1959 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1883 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1960 | 1884 |
| 1961 // Set all the object fields. | 1885 // Set all the object fields. |
| 1962 // TODO(5411462): Need to assert No GC can happen here, even though | 1886 READ_OBJECT_FIELDS(result, |
| 1963 // allocations may happen. | 1887 result.raw()->from(), result.raw()->to(), |
| 1964 intptr_t num_flds = (result.raw()->to() - result.raw()->from()); | 1888 kAsReference); |
| 1965 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 1966 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 1967 result.StorePointer((result.raw()->from() + i), | |
| 1968 reader->PassiveObjectHandle()->raw()); | |
| 1969 } | |
| 1970 | 1889 |
| 1971 return result.raw(); | 1890 return result.raw(); |
| 1972 } | 1891 } |
| 1973 | 1892 |
| 1974 | 1893 |
| 1975 void RawUnhandledException::WriteTo(SnapshotWriter* writer, | 1894 void RawUnhandledException::WriteTo(SnapshotWriter* writer, |
| 1976 intptr_t object_id, | 1895 intptr_t object_id, |
| 1977 Snapshot::Kind kind) { | 1896 Snapshot::Kind kind) { |
| 1978 // Write out the serialization header value for this object. | 1897 // Write out the serialization header value for this object. |
| 1979 writer->WriteInlinedObjectHeader(object_id); | 1898 writer->WriteInlinedObjectHeader(object_id); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 intptr_t object_id, | 2030 intptr_t object_id, |
| 2112 intptr_t tags, | 2031 intptr_t tags, |
| 2113 Snapshot::Kind kind) { | 2032 Snapshot::Kind kind) { |
| 2114 ASSERT(reader != NULL); | 2033 ASSERT(reader != NULL); |
| 2115 | 2034 |
| 2116 // Allocate bigint object. | 2035 // Allocate bigint object. |
| 2117 Bigint& obj = Bigint::ZoneHandle(reader->zone(), NEW_OBJECT(Bigint)); | 2036 Bigint& obj = Bigint::ZoneHandle(reader->zone(), NEW_OBJECT(Bigint)); |
| 2118 reader->AddBackRef(object_id, &obj, kIsDeserialized); | 2037 reader->AddBackRef(object_id, &obj, kIsDeserialized); |
| 2119 | 2038 |
| 2120 // Set all the object fields. | 2039 // Set all the object fields. |
| 2121 // TODO(5411462): Need to assert No GC can happen here, even though | 2040 READ_OBJECT_FIELDS(obj, obj.raw()->from(), obj.raw()->to(), kAsInlinedObject); |
| 2122 // allocations may happen. | |
| 2123 intptr_t num_flds = (obj.raw()->to() - obj.raw()->from()); | |
| 2124 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 2125 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsInlinedObject); | |
| 2126 obj.StorePointer(obj.raw()->from() + i, | |
| 2127 reader->PassiveObjectHandle()->raw()); | |
| 2128 } | |
| 2129 | 2041 |
| 2130 // If it is a canonical constant make it one. | 2042 // If it is a canonical constant make it one. |
| 2131 // When reading a full snapshot we don't need to canonicalize the object | 2043 // When reading a full snapshot we don't need to canonicalize the object |
| 2132 // as it would already be a canonical object. | 2044 // as it would already be a canonical object. |
| 2133 // When reading a script snapshot or a message snapshot we always have | 2045 // When reading a script snapshot or a message snapshot we always have |
| 2134 // to canonicalize the object. | 2046 // to canonicalize the object. |
| 2135 if (RawObject::IsCanonical(tags)) { | 2047 if (RawObject::IsCanonical(tags)) { |
| 2136 if (kind == Snapshot::kFull) { | 2048 if (kind == Snapshot::kFull) { |
| 2137 // Set the canonical bit. | 2049 // Set the canonical bit. |
| 2138 obj.SetCanonical(); | 2050 obj.SetCanonical(); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 | 2508 |
| 2597 | 2509 |
| 2598 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader, | 2510 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader, |
| 2599 intptr_t object_id, | 2511 intptr_t object_id, |
| 2600 intptr_t tags, | 2512 intptr_t tags, |
| 2601 Snapshot::Kind kind) { | 2513 Snapshot::Kind kind) { |
| 2602 ASSERT(reader != NULL); | 2514 ASSERT(reader != NULL); |
| 2603 | 2515 |
| 2604 LinkedHashMap& map = LinkedHashMap::ZoneHandle( | 2516 LinkedHashMap& map = LinkedHashMap::ZoneHandle( |
| 2605 reader->zone(), LinkedHashMap::null()); | 2517 reader->zone(), LinkedHashMap::null()); |
| 2606 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { | 2518 if ((kind == Snapshot::kFull && !reader->snapshot_code()) || |
| 2519 kind == Snapshot::kScript) { |
| 2607 // The immutable maps that seed map literals are not yet VM-internal, so | 2520 // The immutable maps that seed map literals are not yet VM-internal, so |
| 2608 // we don't reach this. | 2521 // we don't reach this. |
| 2609 UNREACHABLE(); | 2522 UNREACHABLE(); |
| 2610 } else { | 2523 } else { |
| 2611 // Since the map might contain itself as a key or value, allocate first. | 2524 // Since the map might contain itself as a key or value, allocate first. |
| 2612 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); | 2525 if (kind == Snapshot::kFull) { |
| 2526 map = reader->NewLinkedHashMap(); |
| 2527 } else { |
| 2528 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); |
| 2529 } |
| 2613 } | 2530 } |
| 2614 reader->AddBackRef(object_id, &map, kIsDeserialized); | 2531 reader->AddBackRef(object_id, &map, kIsDeserialized); |
| 2615 | 2532 |
| 2616 // Read the type arguments. | 2533 // Read the type arguments. |
| 2617 const intptr_t typeargs_offset = | 2534 const intptr_t typeargs_offset = |
| 2618 GrowableObjectArray::type_arguments_offset() / kWordSize; | 2535 GrowableObjectArray::type_arguments_offset() / kWordSize; |
| 2619 *reader->TypeArgumentsHandle() ^= | 2536 *reader->TypeArgumentsHandle() ^= |
| 2620 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset); | 2537 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset); |
| 2621 map.SetTypeArguments(*reader->TypeArgumentsHandle()); | 2538 map.SetTypeArguments(*reader->TypeArgumentsHandle()); |
| 2622 | 2539 |
| 2623 // Read the number of key/value pairs. | 2540 // Read the number of key/value pairs. |
| 2624 intptr_t len = reader->ReadSmiValue(); | 2541 intptr_t len = reader->ReadSmiValue(); |
| 2625 intptr_t used_data = (len << 1); | 2542 intptr_t used_data = (len << 1); |
| 2626 map.SetUsedData(used_data); | 2543 map.SetUsedData(used_data); |
| 2627 | 2544 |
| 2628 // Allocate the data array. | 2545 // Allocate the data array. |
| 2629 intptr_t data_size = Utils::Maximum( | 2546 intptr_t data_size = Utils::Maximum( |
| 2630 Utils::RoundUpToPowerOfTwo(used_data), | 2547 Utils::RoundUpToPowerOfTwo(used_data), |
| 2631 static_cast<uintptr_t>(LinkedHashMap::kInitialIndexSize)); | 2548 static_cast<uintptr_t>(LinkedHashMap::kInitialIndexSize)); |
| 2632 Array& data = Array::ZoneHandle(reader->zone(), | 2549 Array& data = Array::ZoneHandle(reader->zone(), |
| 2633 Array::New(data_size, HEAP_SPACE(kind))); | 2550 NEW_OBJECT_WITH_LEN_SPACE(Array, |
| 2551 data_size, |
| 2552 kind)); |
| 2634 map.SetData(data); | 2553 map.SetData(data); |
| 2635 map.SetDeletedKeys(0); | 2554 map.SetDeletedKeys(0); |
| 2636 | 2555 |
| 2637 // The index and hashMask is regenerated by the maps themselves on demand. | 2556 // The index and hashMask is regenerated by the maps themselves on demand. |
| 2638 // Thus, the index will probably be allocated in new space (unless it's huge). | 2557 // Thus, the index will probably be allocated in new space (unless it's huge). |
| 2639 // TODO(koda): Eagerly rehash here when no keys have user-defined '==', and | 2558 // TODO(koda): Eagerly rehash here when no keys have user-defined '==', and |
| 2640 // in particular, if/when (const) maps are needed in the VM isolate snapshot. | 2559 // in particular, if/when (const) maps are needed in the VM isolate snapshot. |
| 2641 ASSERT(reader->isolate() != Dart::vm_isolate()); | 2560 ASSERT(reader->isolate() != Dart::vm_isolate()); |
| 2642 map.SetHashMask(0); // Prefer sentinel 0 over null for better type feedback. | 2561 map.SetHashMask(0); // Prefer sentinel 0 over null for better type feedback. |
| 2643 | 2562 |
| 2644 // Read the keys and values. | 2563 // Read the keys and values. |
| 2645 bool as_reference = RawObject::IsCanonical(tags) ? false : true; | 2564 bool as_reference = RawObject::IsCanonical(tags) ? false : true; |
| 2646 for (intptr_t i = 0; i < used_data; i++) { | 2565 for (intptr_t i = 0; i < used_data; i++) { |
| 2647 *reader->PassiveObjectHandle() = reader->ReadObjectImpl(as_reference); | 2566 *reader->PassiveObjectHandle() = reader->ReadObjectImpl(as_reference); |
| 2648 data.SetAt(i, *reader->PassiveObjectHandle()); | 2567 data.SetAt(i, *reader->PassiveObjectHandle()); |
| 2649 } | 2568 } |
| 2650 return map.raw(); | 2569 return map.raw(); |
| 2651 } | 2570 } |
| 2652 | 2571 |
| 2653 | 2572 |
| 2654 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer, | 2573 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer, |
| 2655 intptr_t object_id, | 2574 intptr_t object_id, |
| 2656 Snapshot::Kind kind) { | 2575 Snapshot::Kind kind) { |
| 2657 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { | 2576 if ((kind == Snapshot::kFull && !writer->snapshot_code()) || |
| 2577 kind == Snapshot::kScript) { |
| 2658 // The immutable maps that seed map literals are not yet VM-internal, so | 2578 // The immutable maps that seed map literals are not yet VM-internal, so |
| 2659 // we don't reach this. | 2579 // we don't reach this. |
| 2660 UNREACHABLE(); | |
| 2661 } | 2580 } |
| 2662 ASSERT(writer != NULL); | 2581 ASSERT(writer != NULL); |
| 2663 | 2582 |
| 2664 // Write out the serialization header value for this object. | 2583 // Write out the serialization header value for this object. |
| 2665 writer->WriteInlinedObjectHeader(object_id); | 2584 writer->WriteInlinedObjectHeader(object_id); |
| 2666 | 2585 |
| 2667 // Write out the class and tags information. | 2586 // Write out the class and tags information. |
| 2668 writer->WriteIndexedObject(kLinkedHashMapCid); | 2587 writer->WriteIndexedObject(kLinkedHashMapCid); |
| 2669 const uword tags = writer->GetObjectTags(this); | 2588 const uword tags = writer->GetObjectTags(this); |
| 2670 writer->WriteTags(tags); | 2589 writer->WriteTags(tags); |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3096 } else { | 3015 } else { |
| 3097 UNREACHABLE(); | 3016 UNREACHABLE(); |
| 3098 } | 3017 } |
| 3099 } | 3018 } |
| 3100 | 3019 |
| 3101 | 3020 |
| 3102 RawSendPort* SendPort::ReadFrom(SnapshotReader* reader, | 3021 RawSendPort* SendPort::ReadFrom(SnapshotReader* reader, |
| 3103 intptr_t object_id, | 3022 intptr_t object_id, |
| 3104 intptr_t tags, | 3023 intptr_t tags, |
| 3105 Snapshot::Kind kind) { | 3024 Snapshot::Kind kind) { |
| 3025 ASSERT(kind == Snapshot::kMessage || reader->snapshot_code()); |
| 3026 |
| 3106 uint64_t id = reader->Read<uint64_t>(); | 3027 uint64_t id = reader->Read<uint64_t>(); |
| 3107 uint64_t origin_id = reader->Read<uint64_t>(); | 3028 uint64_t origin_id = reader->Read<uint64_t>(); |
| 3108 | 3029 |
| 3109 SendPort& result = SendPort::ZoneHandle(reader->zone(), | 3030 SendPort& result = SendPort::ZoneHandle(reader->zone()); |
| 3110 SendPort::New(id, origin_id)); | 3031 if (reader->snapshot_code()) { |
| 3032 // TODO(rmacnak): Reset fields in precompiled snapshots and assert |
| 3033 // this is unreachable. |
| 3034 } else { |
| 3035 result = SendPort::New(id, origin_id); |
| 3036 } |
| 3111 reader->AddBackRef(object_id, &result, kIsDeserialized); | 3037 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 3112 return result.raw(); | 3038 return result.raw(); |
| 3113 } | 3039 } |
| 3114 | 3040 |
| 3115 | 3041 |
| 3116 void RawSendPort::WriteTo(SnapshotWriter* writer, | 3042 void RawSendPort::WriteTo(SnapshotWriter* writer, |
| 3117 intptr_t object_id, | 3043 intptr_t object_id, |
| 3118 Snapshot::Kind kind) { | 3044 Snapshot::Kind kind) { |
| 3119 // Write out the serialization header value for this object. | 3045 // Write out the serialization header value for this object. |
| 3120 writer->WriteInlinedObjectHeader(object_id); | 3046 writer->WriteInlinedObjectHeader(object_id); |
| 3121 | 3047 |
| 3122 // Write out the class and tags information. | 3048 // Write out the class and tags information. |
| 3123 writer->WriteIndexedObject(kSendPortCid); | 3049 writer->WriteIndexedObject(kSendPortCid); |
| 3124 writer->WriteTags(writer->GetObjectTags(this)); | 3050 writer->WriteTags(writer->GetObjectTags(this)); |
| 3125 | 3051 |
| 3126 writer->Write<uint64_t>(ptr()->id_); | 3052 writer->Write<uint64_t>(ptr()->id_); |
| 3127 writer->Write<uint64_t>(ptr()->origin_id_); | 3053 writer->Write<uint64_t>(ptr()->origin_id_); |
| 3128 } | 3054 } |
| 3129 | 3055 |
| 3130 | 3056 |
| 3131 RawStacktrace* Stacktrace::ReadFrom(SnapshotReader* reader, | 3057 RawStacktrace* Stacktrace::ReadFrom(SnapshotReader* reader, |
| 3132 intptr_t object_id, | 3058 intptr_t object_id, |
| 3133 intptr_t tags, | 3059 intptr_t tags, |
| 3134 Snapshot::Kind kind) { | 3060 Snapshot::Kind kind) { |
| 3135 if (kind == Snapshot::kFull) { | 3061 if (kind == Snapshot::kFull) { |
| 3136 Stacktrace& result = Stacktrace::ZoneHandle(reader->zone(), | 3062 Stacktrace& result = Stacktrace::ZoneHandle(reader->zone(), |
| 3137 reader->NewStacktrace()); | 3063 reader->NewStacktrace()); |
| 3138 reader->AddBackRef(object_id, &result, kIsDeserialized); | 3064 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 3139 | 3065 |
| 3140 // Set all the object fields. | |
| 3141 // TODO(5411462): Need to assert No GC can happen here, even though | |
| 3142 // allocations may happen. | |
| 3143 intptr_t num_flds = (result.raw()->to() - result.raw()->from()); | |
| 3144 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 3145 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 3146 result.StorePointer((result.raw()->from() + i), | |
| 3147 reader->PassiveObjectHandle()->raw()); | |
| 3148 } | |
| 3149 | |
| 3150 bool expand_inlined = reader->Read<bool>(); | 3066 bool expand_inlined = reader->Read<bool>(); |
| 3151 result.set_expand_inlined(expand_inlined); | 3067 result.set_expand_inlined(expand_inlined); |
| 3152 | 3068 |
| 3069 // Set all the object fields. |
| 3070 READ_OBJECT_FIELDS(result, |
| 3071 result.raw()->from(), result.raw()->to(), |
| 3072 kAsReference); |
| 3073 |
| 3153 return result.raw(); | 3074 return result.raw(); |
| 3154 } | 3075 } |
| 3155 UNREACHABLE(); // Stacktraces are not sent in a snapshot. | 3076 UNREACHABLE(); // Stacktraces are not sent in a snapshot. |
| 3156 return Stacktrace::null(); | 3077 return Stacktrace::null(); |
| 3157 } | 3078 } |
| 3158 | 3079 |
| 3159 | 3080 |
| 3160 void RawStacktrace::WriteTo(SnapshotWriter* writer, | 3081 void RawStacktrace::WriteTo(SnapshotWriter* writer, |
| 3161 intptr_t object_id, | 3082 intptr_t object_id, |
| 3162 Snapshot::Kind kind) { | 3083 Snapshot::Kind kind) { |
| 3163 if (kind == Snapshot::kFull) { | 3084 if (kind == Snapshot::kFull) { |
| 3164 ASSERT(writer != NULL); | 3085 ASSERT(writer != NULL); |
| 3165 ASSERT(this == Isolate::Current()->object_store()-> | 3086 ASSERT(this == Isolate::Current()->object_store()-> |
| 3166 preallocated_stack_trace()); | 3087 preallocated_stack_trace()); |
| 3167 | 3088 |
| 3168 // Write out the serialization header value for this object. | 3089 // Write out the serialization header value for this object. |
| 3169 writer->WriteInlinedObjectHeader(object_id); | 3090 writer->WriteInlinedObjectHeader(object_id); |
| 3170 | 3091 |
| 3171 // Write out the class and tags information. | 3092 // Write out the class and tags information. |
| 3172 writer->WriteIndexedObject(kStacktraceCid); | 3093 writer->WriteIndexedObject(kStacktraceCid); |
| 3173 writer->WriteTags(writer->GetObjectTags(this)); | 3094 writer->WriteTags(writer->GetObjectTags(this)); |
| 3174 | 3095 |
| 3096 writer->Write(ptr()->expand_inlined_); |
| 3097 |
| 3175 // Write out all the object pointer fields. | 3098 // Write out all the object pointer fields. |
| 3176 SnapshotWriterVisitor visitor(writer); | 3099 SnapshotWriterVisitor visitor(writer); |
| 3177 visitor.VisitPointers(from(), to()); | 3100 visitor.VisitPointers(from(), to()); |
| 3178 | |
| 3179 writer->Write(ptr()->expand_inlined_); | |
| 3180 } else { | 3101 } else { |
| 3181 // Stacktraces are not allowed in other snapshot forms. | 3102 // Stacktraces are not allowed in other snapshot forms. |
| 3182 writer->SetWriteException(Exceptions::kArgument, | 3103 writer->SetWriteException(Exceptions::kArgument, |
| 3183 "Illegal argument in isolate message" | 3104 "Illegal argument in isolate message" |
| 3184 " : (object is a stacktrace)"); | 3105 " : (object is a stacktrace)"); |
| 3185 } | 3106 } |
| 3186 } | 3107 } |
| 3187 | 3108 |
| 3188 | 3109 |
| 3189 RawJSRegExp* JSRegExp::ReadFrom(SnapshotReader* reader, | 3110 RawJSRegExp* JSRegExp::ReadFrom(SnapshotReader* reader, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3239 intptr_t tags, | 3160 intptr_t tags, |
| 3240 Snapshot::Kind kind) { | 3161 Snapshot::Kind kind) { |
| 3241 ASSERT(reader != NULL); | 3162 ASSERT(reader != NULL); |
| 3242 | 3163 |
| 3243 // Allocate the weak property object. | 3164 // Allocate the weak property object. |
| 3244 WeakProperty& weak_property = WeakProperty::ZoneHandle( | 3165 WeakProperty& weak_property = WeakProperty::ZoneHandle( |
| 3245 reader->zone(), WeakProperty::New(HEAP_SPACE(kind))); | 3166 reader->zone(), WeakProperty::New(HEAP_SPACE(kind))); |
| 3246 reader->AddBackRef(object_id, &weak_property, kIsDeserialized); | 3167 reader->AddBackRef(object_id, &weak_property, kIsDeserialized); |
| 3247 | 3168 |
| 3248 // Set all the object fields. | 3169 // Set all the object fields. |
| 3249 // TODO(5411462): Need to assert No GC can happen here, even though | 3170 READ_OBJECT_FIELDS(weak_property, |
| 3250 // allocations may happen. | 3171 weak_property.raw()->from(), weak_property.raw()->to(), |
| 3251 intptr_t num_flds = (weak_property.raw()->to() - | 3172 kAsReference); |
| 3252 weak_property.raw()->from()); | |
| 3253 for (intptr_t i = 0; i <= num_flds; i++) { | |
| 3254 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); | |
| 3255 weak_property.StorePointer((weak_property.raw()->from() + i), | |
| 3256 reader->PassiveObjectHandle()->raw()); | |
| 3257 } | |
| 3258 | 3173 |
| 3259 return weak_property.raw(); | 3174 return weak_property.raw(); |
| 3260 } | 3175 } |
| 3261 | 3176 |
| 3262 | 3177 |
| 3263 void RawWeakProperty::WriteTo(SnapshotWriter* writer, | 3178 void RawWeakProperty::WriteTo(SnapshotWriter* writer, |
| 3264 intptr_t object_id, | 3179 intptr_t object_id, |
| 3265 Snapshot::Kind kind) { | 3180 Snapshot::Kind kind) { |
| 3266 ASSERT(writer != NULL); | 3181 ASSERT(writer != NULL); |
| 3267 | 3182 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3317 // We do not allow objects with native fields in an isolate message. | 3232 // We do not allow objects with native fields in an isolate message. |
| 3318 writer->SetWriteException(Exceptions::kArgument, | 3233 writer->SetWriteException(Exceptions::kArgument, |
| 3319 "Illegal argument in isolate message" | 3234 "Illegal argument in isolate message" |
| 3320 " : (object is a UserTag)"); | 3235 " : (object is a UserTag)"); |
| 3321 } else { | 3236 } else { |
| 3322 UNREACHABLE(); | 3237 UNREACHABLE(); |
| 3323 } | 3238 } |
| 3324 } | 3239 } |
| 3325 | 3240 |
| 3326 } // namespace dart | 3241 } // namespace dart |
| OLD | NEW |