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/native_entry.h" | 5 #include "vm/native_entry.h" |
6 #include "vm/object.h" | 6 #include "vm/object.h" |
7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
8 #include "vm/snapshot.h" | 8 #include "vm/snapshot.h" |
9 #include "vm/stub_code.h" | 9 #include "vm/stub_code.h" |
10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 | 277 |
278 // Write out all the object pointer fields. Since we will be canonicalizing | 278 // Write out all the object pointer fields. Since we will be canonicalizing |
279 // the type object when reading it back we should write out all the fields | 279 // the type object when reading it back we should write out all the fields |
280 // inline and not as references. | 280 // inline and not as references. |
281 ASSERT(ptr()->type_class_ != Object::null()); | 281 ASSERT(ptr()->type_class_ != Object::null()); |
282 SnapshotWriterVisitor visitor(writer, kAsReference); | 282 SnapshotWriterVisitor visitor(writer, kAsReference); |
283 visitor.VisitPointers(from(), to()); | 283 visitor.VisitPointers(from(), to()); |
284 } | 284 } |
285 | 285 |
286 | 286 |
287 RawFunctionType* FunctionType::ReadFrom(SnapshotReader* reader, | |
288 intptr_t object_id, | |
289 intptr_t tags, | |
290 Snapshot::Kind kind, | |
291 bool as_reference) { | |
292 ASSERT(reader != NULL); | |
293 | |
294 // Determine if the scope class of this function type is in the full snapshot. | |
295 bool scopeclass_is_in_fullsnapshot = reader->Read<bool>(); | |
296 | |
297 // Allocate function type object. | |
298 FunctionType& function_type = | |
299 FunctionType::ZoneHandle(reader->zone(), NEW_OBJECT(FunctionType)); | |
300 bool is_canonical = RawObject::IsCanonical(tags); | |
301 bool defer_canonicalization = is_canonical && | |
302 (kind != Snapshot::kFull && scopeclass_is_in_fullsnapshot); | |
303 reader->AddBackRef(object_id, | |
304 &function_type, | |
305 kIsDeserialized, | |
306 defer_canonicalization); | |
307 | |
308 // Set all non object fields. | |
309 function_type.set_token_pos(reader->Read<int32_t>()); | |
310 function_type.set_type_state(reader->Read<int8_t>()); | |
311 | |
312 // Set all the object fields. | |
313 READ_OBJECT_FIELDS(function_type, | |
314 function_type.raw()->from(), function_type.raw()->to(), | |
315 kAsReference); | |
316 | |
317 // Set the canonical bit. | |
318 if (!defer_canonicalization && RawObject::IsCanonical(tags)) { | |
siva
2016/01/19 21:11:00
if (!defer_canonicalization && is_canonical) {
regis
2016/01/19 23:15:30
Done here, in TypeArguments::ReadFrom, and in Type
| |
319 function_type.SetCanonical(); | |
320 } | |
321 | |
322 return function_type.raw(); | |
323 } | |
324 | |
325 | |
326 void RawFunctionType::WriteTo(SnapshotWriter* writer, | |
327 intptr_t object_id, | |
328 Snapshot::Kind kind, | |
329 bool as_reference) { | |
330 ASSERT(writer != NULL); | |
331 | |
332 // Only resolved and finalized function types should be written to a snapshot. | |
333 ASSERT((ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) || | |
334 (ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated)); | |
335 ASSERT(ptr()->scope_class_ != Object::null()); | |
336 | |
337 // Write out the serialization header value for this object. | |
338 writer->WriteInlinedObjectHeader(object_id); | |
339 | |
340 // Write out the class and tags information. | |
341 writer->WriteIndexedObject(kFunctionTypeCid); | |
342 writer->WriteTags(writer->GetObjectTags(this)); | |
343 | |
344 // Write out scopeclass_is_in_fullsnapshot first as this will | |
345 // help the reader decide on how to canonicalize the type object. | |
346 intptr_t tags = writer->GetObjectTags(ptr()->scope_class_); | |
347 bool scopeclass_is_in_fullsnapshot = | |
348 (ClassIdTag::decode(tags) == kClassCid) && | |
349 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->scope_class_)); | |
350 writer->Write<bool>(scopeclass_is_in_fullsnapshot); | |
351 | |
352 // Write out all the non object pointer fields. | |
353 writer->Write<int32_t>(ptr()->token_pos_); | |
354 writer->Write<int8_t>(ptr()->type_state_); | |
355 | |
356 // Write out all the object pointer fields. Since we will be canonicalizing | |
357 // the function type object when reading it back we should write out all the | |
358 // fields inline and not as references. | |
siva
2016/01/19 21:11:00
The comment says all the objects need to be writte
regis
2016/01/19 23:15:30
Removed the second sentence, here and in Type::Wri
| |
359 ASSERT(ptr()->scope_class_ != Object::null()); | |
360 SnapshotWriterVisitor visitor(writer, kAsReference); | |
361 visitor.VisitPointers(from(), to()); | |
362 } | |
363 | |
364 | |
287 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader, | 365 RawTypeRef* TypeRef::ReadFrom(SnapshotReader* reader, |
288 intptr_t object_id, | 366 intptr_t object_id, |
289 intptr_t tags, | 367 intptr_t tags, |
290 Snapshot::Kind kind, | 368 Snapshot::Kind kind, |
291 bool as_reference) { | 369 bool as_reference) { |
292 ASSERT(reader != NULL); | 370 ASSERT(reader != NULL); |
293 | 371 |
294 // Allocate type ref object. | 372 // Allocate type ref object. |
295 TypeRef& type_ref = TypeRef::ZoneHandle( | 373 TypeRef& type_ref = TypeRef::ZoneHandle( |
296 reader->zone(), NEW_OBJECT(TypeRef)); | 374 reader->zone(), NEW_OBJECT(TypeRef)); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 | 619 |
542 // Write out the class and tags information. | 620 // Write out the class and tags information. |
543 writer->WriteVMIsolateObject(kPatchClassCid); | 621 writer->WriteVMIsolateObject(kPatchClassCid); |
544 writer->WriteTags(writer->GetObjectTags(this)); | 622 writer->WriteTags(writer->GetObjectTags(this)); |
545 // Write out all the object pointer fields. | 623 // Write out all the object pointer fields. |
546 SnapshotWriterVisitor visitor(writer, kAsReference); | 624 SnapshotWriterVisitor visitor(writer, kAsReference); |
547 visitor.VisitPointers(from(), to()); | 625 visitor.VisitPointers(from(), to()); |
548 } | 626 } |
549 | 627 |
550 | 628 |
629 RawClosure* Closure::ReadFrom(SnapshotReader* reader, | |
630 intptr_t object_id, | |
631 intptr_t tags, | |
632 Snapshot::Kind kind, | |
633 bool as_reference) { | |
634 ASSERT(reader != NULL); | |
635 ASSERT(kind == Snapshot::kFull); | |
636 | |
637 // Allocate closure object. | |
638 Closure& closure = Closure::ZoneHandle( | |
639 reader->zone(), NEW_OBJECT(Closure)); | |
640 reader->AddBackRef(object_id, &closure, kIsDeserialized); | |
641 | |
642 // Set all the object fields. | |
643 READ_OBJECT_FIELDS(closure, | |
644 closure.raw()->from(), closure.raw()->to(), | |
645 kAsReference); | |
646 | |
647 return closure.raw(); | |
648 } | |
649 | |
650 | |
651 void RawClosure::WriteTo(SnapshotWriter* writer, | |
652 intptr_t object_id, | |
653 Snapshot::Kind kind, | |
654 bool as_reference) { | |
655 ASSERT(writer != NULL); | |
656 if ((kind == Snapshot::kMessage) || (kind == Snapshot::kScript)) { | |
657 // Check if closure is serializable, throw an exception otherwise. | |
658 RawFunction* func = writer->IsSerializableClosure(this); | |
659 if (func != Function::null()) { | |
660 writer->WriteStaticImplicitClosure(object_id, | |
661 func, | |
662 writer->GetObjectTags(this)); | |
663 return; | |
664 } | |
665 } | |
666 | |
667 // Write out the serialization header value for this object. | |
668 writer->WriteInlinedObjectHeader(object_id); | |
669 | |
670 // Write out the class and tags information. | |
671 writer->WriteIndexedObject(kClosureCid); | |
672 writer->WriteTags(writer->GetObjectTags(this)); | |
673 | |
674 // Write out all the object pointer fields. | |
675 SnapshotWriterVisitor visitor(writer, kAsReference); | |
676 visitor.VisitPointers(from(), to()); | |
677 } | |
678 | |
679 | |
551 RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader, | 680 RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader, |
552 intptr_t object_id, | 681 intptr_t object_id, |
553 intptr_t tags, | 682 intptr_t tags, |
554 Snapshot::Kind kind, | 683 Snapshot::Kind kind, |
555 bool as_reference) { | 684 bool as_reference) { |
556 ASSERT(reader != NULL); | 685 ASSERT(reader != NULL); |
557 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 686 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
558 | 687 |
559 // Allocate closure data object. | 688 // Allocate closure data object. |
560 ClosureData& data = ClosureData::ZoneHandle( | 689 ClosureData& data = ClosureData::ZoneHandle( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject); | 721 writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject); |
593 } else { | 722 } else { |
594 // We don't write non implicit context scopes in the snapshot. | 723 // We don't write non implicit context scopes in the snapshot. |
595 writer->WriteVMIsolateObject(kNullObject); | 724 writer->WriteVMIsolateObject(kNullObject); |
596 } | 725 } |
597 } | 726 } |
598 | 727 |
599 // Parent function. | 728 // Parent function. |
600 writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject); | 729 writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject); |
601 | 730 |
602 // Signature class. | 731 // Signature type. |
603 writer->WriteObjectImpl(ptr()->signature_class_, kAsInlinedObject); | 732 writer->WriteObjectImpl(ptr()->signature_type_, kAsInlinedObject); |
604 | 733 |
605 // Static closure/Closure allocation stub. | 734 // Static closure/Closure allocation stub. |
606 // We don't write the closure or allocation stub in the snapshot. | 735 // We don't write the closure or allocation stub in the snapshot. |
607 writer->WriteVMIsolateObject(kNullObject); | 736 writer->WriteVMIsolateObject(kNullObject); |
608 } | 737 } |
609 | 738 |
610 | 739 |
611 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, | 740 RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, |
612 intptr_t object_id, | 741 intptr_t object_id, |
613 intptr_t tags, | 742 intptr_t tags, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 | 842 |
714 | 843 |
715 void RawFunction::WriteTo(SnapshotWriter* writer, | 844 void RawFunction::WriteTo(SnapshotWriter* writer, |
716 intptr_t object_id, | 845 intptr_t object_id, |
717 Snapshot::Kind kind, | 846 Snapshot::Kind kind, |
718 bool as_reference) { | 847 bool as_reference) { |
719 ASSERT(writer != NULL); | 848 ASSERT(writer != NULL); |
720 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 849 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
721 bool is_in_fullsnapshot = false; | 850 bool is_in_fullsnapshot = false; |
722 bool owner_is_class = false; | 851 bool owner_is_class = false; |
723 if (kind == Snapshot::kScript) { | 852 if ((kind == Snapshot::kScript) && !Function::IsSignatureFunction(this)) { |
724 intptr_t tags = writer->GetObjectTags(ptr()->owner_); | 853 intptr_t tags = writer->GetObjectTags(ptr()->owner_); |
725 intptr_t cid = ClassIdTag::decode(tags); | 854 intptr_t cid = ClassIdTag::decode(tags); |
726 owner_is_class = (cid == kClassCid); | 855 owner_is_class = (cid == kClassCid); |
727 is_in_fullsnapshot = owner_is_class ? | 856 is_in_fullsnapshot = owner_is_class ? |
728 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) : | 857 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) : |
729 PatchClass::IsInFullSnapshot( | 858 PatchClass::IsInFullSnapshot( |
730 reinterpret_cast<RawPatchClass*>(ptr()->owner_)); | 859 reinterpret_cast<RawPatchClass*>(ptr()->owner_)); |
731 } | 860 } |
732 | 861 |
733 // Write out the serialization header value for this object. | 862 // Write out the serialization header value for this object. |
(...skipping 2778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3512 // We do not allow objects with native fields in an isolate message. | 3641 // We do not allow objects with native fields in an isolate message. |
3513 writer->SetWriteException(Exceptions::kArgument, | 3642 writer->SetWriteException(Exceptions::kArgument, |
3514 "Illegal argument in isolate message" | 3643 "Illegal argument in isolate message" |
3515 " : (object is a UserTag)"); | 3644 " : (object is a UserTag)"); |
3516 } else { | 3645 } else { |
3517 UNREACHABLE(); | 3646 UNREACHABLE(); |
3518 } | 3647 } |
3519 } | 3648 } |
3520 | 3649 |
3521 } // namespace dart | 3650 } // namespace dart |
OLD | NEW |