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/snapshot.h" | 5 #include "vm/snapshot.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 RawApiError* error = VerifyVersion(); | 489 RawApiError* error = VerifyVersion(); |
490 if (error != ApiError::null()) { | 490 if (error != ApiError::null()) { |
491 return error; | 491 return error; |
492 } | 492 } |
493 | 493 |
494 // The version string matches. Read the rest of the snapshot. | 494 // The version string matches. Read the rest of the snapshot. |
495 | 495 |
496 // TODO(asiva): Add a check here to ensure we have the right heap | 496 // TODO(asiva): Add a check here to ensure we have the right heap |
497 // size for the full snapshot being read. | 497 // size for the full snapshot being read. |
498 { | 498 { |
499 NoGCScope no_gc; | 499 NoSafepointScope no_safepoint; |
500 HeapLocker hl(isolate, old_space()); | 500 HeapLocker hl(isolate, old_space()); |
501 | 501 |
502 // Read in all the objects stored in the object store. | 502 // Read in all the objects stored in the object store. |
503 intptr_t num_flds = (object_store->to() - object_store->from()); | 503 intptr_t num_flds = (object_store->to() - object_store->from()); |
504 for (intptr_t i = 0; i <= num_flds; i++) { | 504 for (intptr_t i = 0; i <= num_flds; i++) { |
505 *(object_store->from() + i) = ReadObjectImpl(); | 505 *(object_store->from() + i) = ReadObjectImpl(); |
506 } | 506 } |
507 for (intptr_t i = 0; i < backward_references_.length(); i++) { | 507 for (intptr_t i = 0; i < backward_references_.length(); i++) { |
508 if (!backward_references_[i].is_deserialized()) { | 508 if (!backward_references_[i].is_deserialized()) { |
509 ReadObjectImpl(); | 509 ReadObjectImpl(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 const String& msg = String::Handle(String::New(message_buffer)); | 584 const String& msg = String::Handle(String::New(message_buffer)); |
585 return ApiError::New(msg); | 585 return ApiError::New(msg); |
586 } | 586 } |
587 Advance(version_len); | 587 Advance(version_len); |
588 return ApiError::null(); | 588 return ApiError::null(); |
589 } | 589 } |
590 | 590 |
591 | 591 |
592 #define ALLOC_NEW_OBJECT_WITH_LEN(type, length) \ | 592 #define ALLOC_NEW_OBJECT_WITH_LEN(type, length) \ |
593 ASSERT(kind_ == Snapshot::kFull); \ | 593 ASSERT(kind_ == Snapshot::kFull); \ |
594 ASSERT(isolate()->no_gc_scope_depth() != 0); \ | 594 ASSERT(isolate()->no_safepoint_scope_depth() != 0); \ |
595 Raw##type* obj = reinterpret_cast<Raw##type*>( \ | 595 Raw##type* obj = reinterpret_cast<Raw##type*>( \ |
596 AllocateUninitialized(k##type##Cid, type::InstanceSize(length))); \ | 596 AllocateUninitialized(k##type##Cid, type::InstanceSize(length))); \ |
597 obj->StoreSmi(&(obj->ptr()->length_), Smi::New(length)); \ | 597 obj->StoreSmi(&(obj->ptr()->length_), Smi::New(length)); \ |
598 return obj; \ | 598 return obj; \ |
599 | 599 |
600 | 600 |
601 RawArray* SnapshotReader::NewArray(intptr_t len) { | 601 RawArray* SnapshotReader::NewArray(intptr_t len) { |
602 ALLOC_NEW_OBJECT_WITH_LEN(Array, len); | 602 ALLOC_NEW_OBJECT_WITH_LEN(Array, len); |
603 } | 603 } |
604 | 604 |
(...skipping 13 matching lines...) Expand all Loading... |
618 } | 618 } |
619 | 619 |
620 | 620 |
621 RawTypeArguments* SnapshotReader::NewTypeArguments(intptr_t len) { | 621 RawTypeArguments* SnapshotReader::NewTypeArguments(intptr_t len) { |
622 ALLOC_NEW_OBJECT_WITH_LEN(TypeArguments, len); | 622 ALLOC_NEW_OBJECT_WITH_LEN(TypeArguments, len); |
623 } | 623 } |
624 | 624 |
625 | 625 |
626 RawTokenStream* SnapshotReader::NewTokenStream(intptr_t len) { | 626 RawTokenStream* SnapshotReader::NewTokenStream(intptr_t len) { |
627 ASSERT(kind_ == Snapshot::kFull); | 627 ASSERT(kind_ == Snapshot::kFull); |
628 ASSERT(isolate()->no_gc_scope_depth() != 0); | 628 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
629 stream_ = reinterpret_cast<RawTokenStream*>( | 629 stream_ = reinterpret_cast<RawTokenStream*>( |
630 AllocateUninitialized(kTokenStreamCid, TokenStream::InstanceSize())); | 630 AllocateUninitialized(kTokenStreamCid, TokenStream::InstanceSize())); |
631 uint8_t* array = const_cast<uint8_t*>(CurrentBufferAddress()); | 631 uint8_t* array = const_cast<uint8_t*>(CurrentBufferAddress()); |
632 ASSERT(array != NULL); | 632 ASSERT(array != NULL); |
633 Advance(len); | 633 Advance(len); |
634 data_ = reinterpret_cast<RawExternalTypedData*>( | 634 data_ = reinterpret_cast<RawExternalTypedData*>( |
635 AllocateUninitialized(kExternalTypedDataUint8ArrayCid, | 635 AllocateUninitialized(kExternalTypedDataUint8ArrayCid, |
636 ExternalTypedData::InstanceSize())); | 636 ExternalTypedData::InstanceSize())); |
637 data_.SetData(array); | 637 data_.SetData(array); |
638 data_.SetLength(len); | 638 data_.SetLength(len); |
639 stream_.SetStream(data_); | 639 stream_.SetStream(data_); |
640 return stream_.raw(); | 640 return stream_.raw(); |
641 } | 641 } |
642 | 642 |
643 | 643 |
644 RawContext* SnapshotReader::NewContext(intptr_t num_variables) { | 644 RawContext* SnapshotReader::NewContext(intptr_t num_variables) { |
645 ASSERT(kind_ == Snapshot::kFull); | 645 ASSERT(kind_ == Snapshot::kFull); |
646 ASSERT(isolate()->no_gc_scope_depth() != 0); | 646 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
647 RawContext* obj = reinterpret_cast<RawContext*>( | 647 RawContext* obj = reinterpret_cast<RawContext*>( |
648 AllocateUninitialized(kContextCid, Context::InstanceSize(num_variables))); | 648 AllocateUninitialized(kContextCid, Context::InstanceSize(num_variables))); |
649 obj->ptr()->num_variables_ = num_variables; | 649 obj->ptr()->num_variables_ = num_variables; |
650 return obj; | 650 return obj; |
651 } | 651 } |
652 | 652 |
653 | 653 |
654 RawClass* SnapshotReader::NewClass(intptr_t class_id) { | 654 RawClass* SnapshotReader::NewClass(intptr_t class_id) { |
655 ASSERT(kind_ == Snapshot::kFull); | 655 ASSERT(kind_ == Snapshot::kFull); |
656 ASSERT(isolate()->no_gc_scope_depth() != 0); | 656 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
657 if (class_id < kNumPredefinedCids) { | 657 if (class_id < kNumPredefinedCids) { |
658 ASSERT((class_id >= kInstanceCid) && | 658 ASSERT((class_id >= kInstanceCid) && |
659 (class_id <= kNullCid)); | 659 (class_id <= kNullCid)); |
660 return isolate()->class_table()->At(class_id); | 660 return isolate()->class_table()->At(class_id); |
661 } | 661 } |
662 RawClass* obj = reinterpret_cast<RawClass*>( | 662 RawClass* obj = reinterpret_cast<RawClass*>( |
663 AllocateUninitialized(kClassCid, Class::InstanceSize())); | 663 AllocateUninitialized(kClassCid, Class::InstanceSize())); |
664 Instance fake; | 664 Instance fake; |
665 obj->ptr()->handle_vtable_ = fake.vtable(); | 665 obj->ptr()->handle_vtable_ = fake.vtable(); |
666 cls_ = obj; | 666 cls_ = obj; |
667 cls_.set_id(class_id); | 667 cls_.set_id(class_id); |
668 isolate()->RegisterClassAt(class_id, cls_); | 668 isolate()->RegisterClassAt(class_id, cls_); |
669 return cls_.raw(); | 669 return cls_.raw(); |
670 } | 670 } |
671 | 671 |
672 | 672 |
673 RawInstance* SnapshotReader::NewInstance() { | 673 RawInstance* SnapshotReader::NewInstance() { |
674 ASSERT(kind_ == Snapshot::kFull); | 674 ASSERT(kind_ == Snapshot::kFull); |
675 ASSERT(isolate()->no_gc_scope_depth() != 0); | 675 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
676 RawInstance* obj = reinterpret_cast<RawInstance*>( | 676 RawInstance* obj = reinterpret_cast<RawInstance*>( |
677 AllocateUninitialized(kObjectCid, Instance::InstanceSize())); | 677 AllocateUninitialized(kObjectCid, Instance::InstanceSize())); |
678 return obj; | 678 return obj; |
679 } | 679 } |
680 | 680 |
681 | 681 |
682 RawMint* SnapshotReader::NewMint(int64_t value) { | 682 RawMint* SnapshotReader::NewMint(int64_t value) { |
683 ASSERT(kind_ == Snapshot::kFull); | 683 ASSERT(kind_ == Snapshot::kFull); |
684 ASSERT(isolate()->no_gc_scope_depth() != 0); | 684 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
685 RawMint* obj = reinterpret_cast<RawMint*>( | 685 RawMint* obj = reinterpret_cast<RawMint*>( |
686 AllocateUninitialized(kMintCid, Mint::InstanceSize())); | 686 AllocateUninitialized(kMintCid, Mint::InstanceSize())); |
687 obj->ptr()->value_ = value; | 687 obj->ptr()->value_ = value; |
688 return obj; | 688 return obj; |
689 } | 689 } |
690 | 690 |
691 | 691 |
692 RawDouble* SnapshotReader::NewDouble(double value) { | 692 RawDouble* SnapshotReader::NewDouble(double value) { |
693 ASSERT(kind_ == Snapshot::kFull); | 693 ASSERT(kind_ == Snapshot::kFull); |
694 ASSERT(isolate()->no_gc_scope_depth() != 0); | 694 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
695 RawDouble* obj = reinterpret_cast<RawDouble*>( | 695 RawDouble* obj = reinterpret_cast<RawDouble*>( |
696 AllocateUninitialized(kDoubleCid, Double::InstanceSize())); | 696 AllocateUninitialized(kDoubleCid, Double::InstanceSize())); |
697 obj->ptr()->value_ = value; | 697 obj->ptr()->value_ = value; |
698 return obj; | 698 return obj; |
699 } | 699 } |
700 | 700 |
701 | 701 |
702 RawTypedData* SnapshotReader::NewTypedData(intptr_t class_id, intptr_t len) { | 702 RawTypedData* SnapshotReader::NewTypedData(intptr_t class_id, intptr_t len) { |
703 ASSERT(kind_ == Snapshot::kFull); | 703 ASSERT(kind_ == Snapshot::kFull); |
704 ASSERT(isolate()->no_gc_scope_depth() != 0); | 704 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
705 const intptr_t lengthInBytes = len * TypedData::ElementSizeInBytes(class_id); | 705 const intptr_t lengthInBytes = len * TypedData::ElementSizeInBytes(class_id); |
706 RawTypedData* obj = reinterpret_cast<RawTypedData*>( | 706 RawTypedData* obj = reinterpret_cast<RawTypedData*>( |
707 AllocateUninitialized(class_id, TypedData::InstanceSize(lengthInBytes))); | 707 AllocateUninitialized(class_id, TypedData::InstanceSize(lengthInBytes))); |
708 obj->StoreSmi(&(obj->ptr()->length_), Smi::New(len)); | 708 obj->StoreSmi(&(obj->ptr()->length_), Smi::New(len)); |
709 return obj; | 709 return obj; |
710 } | 710 } |
711 | 711 |
712 | 712 |
713 #define ALLOC_NEW_OBJECT(type) \ | 713 #define ALLOC_NEW_OBJECT(type) \ |
714 ASSERT(kind_ == Snapshot::kFull); \ | 714 ASSERT(kind_ == Snapshot::kFull); \ |
715 ASSERT(isolate()->no_gc_scope_depth() != 0); \ | 715 ASSERT(isolate()->no_safepoint_scope_depth() != 0); \ |
716 return reinterpret_cast<Raw##type*>( \ | 716 return reinterpret_cast<Raw##type*>( \ |
717 AllocateUninitialized(k##type##Cid, type::InstanceSize())); \ | 717 AllocateUninitialized(k##type##Cid, type::InstanceSize())); \ |
718 | 718 |
719 | 719 |
720 RawBigint* SnapshotReader::NewBigint() { | 720 RawBigint* SnapshotReader::NewBigint() { |
721 ALLOC_NEW_OBJECT(Bigint); | 721 ALLOC_NEW_OBJECT(Bigint); |
722 } | 722 } |
723 | 723 |
724 | 724 |
725 RawUnresolvedClass* SnapshotReader::NewUnresolvedClass() { | 725 RawUnresolvedClass* SnapshotReader::NewUnresolvedClass() { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 | 803 |
804 | 804 |
805 RawGrowableObjectArray* SnapshotReader::NewGrowableObjectArray() { | 805 RawGrowableObjectArray* SnapshotReader::NewGrowableObjectArray() { |
806 ALLOC_NEW_OBJECT(GrowableObjectArray); | 806 ALLOC_NEW_OBJECT(GrowableObjectArray); |
807 } | 807 } |
808 | 808 |
809 | 809 |
810 RawFloat32x4* SnapshotReader::NewFloat32x4(float v0, float v1, float v2, | 810 RawFloat32x4* SnapshotReader::NewFloat32x4(float v0, float v1, float v2, |
811 float v3) { | 811 float v3) { |
812 ASSERT(kind_ == Snapshot::kFull); | 812 ASSERT(kind_ == Snapshot::kFull); |
813 ASSERT(isolate()->no_gc_scope_depth() != 0); | 813 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
814 RawFloat32x4* obj = reinterpret_cast<RawFloat32x4*>( | 814 RawFloat32x4* obj = reinterpret_cast<RawFloat32x4*>( |
815 AllocateUninitialized(kFloat32x4Cid, Float32x4::InstanceSize())); | 815 AllocateUninitialized(kFloat32x4Cid, Float32x4::InstanceSize())); |
816 obj->ptr()->value_[0] = v0; | 816 obj->ptr()->value_[0] = v0; |
817 obj->ptr()->value_[1] = v1; | 817 obj->ptr()->value_[1] = v1; |
818 obj->ptr()->value_[2] = v2; | 818 obj->ptr()->value_[2] = v2; |
819 obj->ptr()->value_[3] = v3; | 819 obj->ptr()->value_[3] = v3; |
820 return obj; | 820 return obj; |
821 } | 821 } |
822 | 822 |
823 | 823 |
824 RawInt32x4* SnapshotReader::NewInt32x4(uint32_t v0, uint32_t v1, uint32_t v2, | 824 RawInt32x4* SnapshotReader::NewInt32x4(uint32_t v0, uint32_t v1, uint32_t v2, |
825 uint32_t v3) { | 825 uint32_t v3) { |
826 ASSERT(kind_ == Snapshot::kFull); | 826 ASSERT(kind_ == Snapshot::kFull); |
827 ASSERT(isolate()->no_gc_scope_depth() != 0); | 827 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
828 RawInt32x4* obj = reinterpret_cast<RawInt32x4*>( | 828 RawInt32x4* obj = reinterpret_cast<RawInt32x4*>( |
829 AllocateUninitialized(kInt32x4Cid, Int32x4::InstanceSize())); | 829 AllocateUninitialized(kInt32x4Cid, Int32x4::InstanceSize())); |
830 obj->ptr()->value_[0] = v0; | 830 obj->ptr()->value_[0] = v0; |
831 obj->ptr()->value_[1] = v1; | 831 obj->ptr()->value_[1] = v1; |
832 obj->ptr()->value_[2] = v2; | 832 obj->ptr()->value_[2] = v2; |
833 obj->ptr()->value_[3] = v3; | 833 obj->ptr()->value_[3] = v3; |
834 return obj; | 834 return obj; |
835 } | 835 } |
836 | 836 |
837 | 837 |
838 RawFloat64x2* SnapshotReader::NewFloat64x2(double v0, double v1) { | 838 RawFloat64x2* SnapshotReader::NewFloat64x2(double v0, double v1) { |
839 ASSERT(kind_ == Snapshot::kFull); | 839 ASSERT(kind_ == Snapshot::kFull); |
840 ASSERT(isolate()->no_gc_scope_depth() != 0); | 840 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
841 RawFloat64x2* obj = reinterpret_cast<RawFloat64x2*>( | 841 RawFloat64x2* obj = reinterpret_cast<RawFloat64x2*>( |
842 AllocateUninitialized(kFloat64x2Cid, Float64x2::InstanceSize())); | 842 AllocateUninitialized(kFloat64x2Cid, Float64x2::InstanceSize())); |
843 obj->ptr()->value_[0] = v0; | 843 obj->ptr()->value_[0] = v0; |
844 obj->ptr()->value_[1] = v1; | 844 obj->ptr()->value_[1] = v1; |
845 return obj; | 845 return obj; |
846 } | 846 } |
847 | 847 |
848 | 848 |
849 RawApiError* SnapshotReader::NewApiError() { | 849 RawApiError* SnapshotReader::NewApiError() { |
850 ALLOC_NEW_OBJECT(ApiError); | 850 ALLOC_NEW_OBJECT(ApiError); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 } | 889 } |
890 ASSERT(SerializedHeaderTag::decode(class_header) == kObjectId); | 890 ASSERT(SerializedHeaderTag::decode(class_header) == kObjectId); |
891 intptr_t class_id = SerializedHeaderData::decode(class_header); | 891 intptr_t class_id = SerializedHeaderData::decode(class_header); |
892 ASSERT(IsObjectStoreClassId(class_id)); | 892 ASSERT(IsObjectStoreClassId(class_id)); |
893 return class_id; | 893 return class_id; |
894 } | 894 } |
895 | 895 |
896 | 896 |
897 RawObject* SnapshotReader::AllocateUninitialized(intptr_t class_id, | 897 RawObject* SnapshotReader::AllocateUninitialized(intptr_t class_id, |
898 intptr_t size) { | 898 intptr_t size) { |
899 ASSERT(isolate()->no_gc_scope_depth() != 0); | 899 ASSERT(isolate()->no_safepoint_scope_depth() != 0); |
900 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 900 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
901 | 901 |
902 // Allocate memory where all words look like smis. This is currently | 902 // Allocate memory where all words look like smis. This is currently |
903 // only needed for DEBUG-mode validation in StorePointer/StoreSmi, but will | 903 // only needed for DEBUG-mode validation in StorePointer/StoreSmi, but will |
904 // be essential with the upcoming deletion barrier. | 904 // be essential with the upcoming deletion barrier. |
905 uword address = | 905 uword address = |
906 old_space()->TryAllocateSmiInitializedLocked(size, | 906 old_space()->TryAllocateSmiInitializedLocked(size, |
907 PageSpace::kForceGrowth); | 907 PageSpace::kForceGrowth); |
908 if (address == 0) { | 908 if (address == 0) { |
909 // Use the preallocated out of memory exception to avoid calling | 909 // Use the preallocated out of memory exception to avoid calling |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 UNREACHABLE(); | 1213 UNREACHABLE(); |
1214 } | 1214 } |
1215 | 1215 |
1216 | 1216 |
1217 void SnapshotWriter::WriteObjectRef(RawObject* raw) { | 1217 void SnapshotWriter::WriteObjectRef(RawObject* raw) { |
1218 // First check if object can be written as a simple predefined type. | 1218 // First check if object can be written as a simple predefined type. |
1219 if (CheckAndWritePredefinedObject(raw)) { | 1219 if (CheckAndWritePredefinedObject(raw)) { |
1220 return; | 1220 return; |
1221 } | 1221 } |
1222 | 1222 |
1223 NoGCScope no_gc; | 1223 NoSafepointScope no_safepoint; |
1224 RawClass* cls = class_table_->At(raw->GetClassId()); | 1224 RawClass* cls = class_table_->At(raw->GetClassId()); |
1225 intptr_t class_id = cls->ptr()->id_; | 1225 intptr_t class_id = cls->ptr()->id_; |
1226 ASSERT(class_id == raw->GetClassId()); | 1226 ASSERT(class_id == raw->GetClassId()); |
1227 if (class_id >= kNumPredefinedCids) { | 1227 if (class_id >= kNumPredefinedCids) { |
1228 WriteInstanceRef(raw, cls); | 1228 WriteInstanceRef(raw, cls); |
1229 return; | 1229 return; |
1230 } | 1230 } |
1231 if (class_id == kArrayCid) { | 1231 if (class_id == kArrayCid) { |
1232 // Object is being referenced, add it to the forward ref list and mark | 1232 // Object is being referenced, add it to the forward ref list and mark |
1233 // it so that future references to this object in the snapshot will use | 1233 // it so that future references to this object in the snapshot will use |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 LongJumpScope jump; | 1328 LongJumpScope jump; |
1329 if (setjmp(*jump.Set()) == 0) { | 1329 if (setjmp(*jump.Set()) == 0) { |
1330 // Reserve space in the output buffer for a snapshot header. | 1330 // Reserve space in the output buffer for a snapshot header. |
1331 ReserveHeader(); | 1331 ReserveHeader(); |
1332 | 1332 |
1333 // Write out the version string. | 1333 // Write out the version string. |
1334 WriteVersion(); | 1334 WriteVersion(); |
1335 | 1335 |
1336 // Write out the full snapshot. | 1336 // Write out the full snapshot. |
1337 { | 1337 { |
1338 NoGCScope no_gc; | 1338 NoSafepointScope no_safepoint; |
1339 | 1339 |
1340 // Write out all the objects in the object store of the isolate which | 1340 // Write out all the objects in the object store of the isolate which |
1341 // is the root set for all dart allocated objects at this point. | 1341 // is the root set for all dart allocated objects at this point. |
1342 SnapshotWriterVisitor visitor(this, false); | 1342 SnapshotWriterVisitor visitor(this, false); |
1343 object_store->VisitObjectPointers(&visitor); | 1343 object_store->VisitObjectPointers(&visitor); |
1344 | 1344 |
1345 // Write out all forwarded objects. | 1345 // Write out all forwarded objects. |
1346 WriteForwardedObjects(); | 1346 WriteForwardedObjects(); |
1347 | 1347 |
1348 FillHeader(kind()); | 1348 FillHeader(kind()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 ForwardList::~ForwardList() { | 1383 ForwardList::~ForwardList() { |
1384 PageSpace* page_space = Isolate::Current()->heap()->old_space(); | 1384 PageSpace* page_space = Isolate::Current()->heap()->old_space(); |
1385 MonitorLocker ml(page_space->tasks_lock()); | 1385 MonitorLocker ml(page_space->tasks_lock()); |
1386 ASSERT(page_space->tasks() == 1); | 1386 ASSERT(page_space->tasks() == 1); |
1387 page_space->set_tasks(0); | 1387 page_space->set_tasks(0); |
1388 ml.Notify(); | 1388 ml.Notify(); |
1389 } | 1389 } |
1390 | 1390 |
1391 | 1391 |
1392 intptr_t ForwardList::MarkAndAddObject(RawObject* raw, SerializeState state) { | 1392 intptr_t ForwardList::MarkAndAddObject(RawObject* raw, SerializeState state) { |
1393 NoGCScope no_gc; | 1393 NoSafepointScope no_safepoint; |
1394 intptr_t object_id = next_object_id(); | 1394 intptr_t object_id = next_object_id(); |
1395 ASSERT(object_id <= kMaxObjectId); | 1395 ASSERT(object_id <= kMaxObjectId); |
1396 uword value = 0; | 1396 uword value = 0; |
1397 value = SerializedHeaderTag::update(kObjectId, value); | 1397 value = SerializedHeaderTag::update(kObjectId, value); |
1398 value = SerializedHeaderData::update(object_id, value); | 1398 value = SerializedHeaderData::update(object_id, value); |
1399 uword tags = raw->ptr()->tags_; | 1399 uword tags = raw->ptr()->tags_; |
1400 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId); | 1400 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId); |
1401 raw->ptr()->tags_ = value; | 1401 raw->ptr()->tags_ = value; |
1402 Node* node = new Node(raw, tags, state); | 1402 Node* node = new Node(raw, tags, state); |
1403 ASSERT(node != NULL); | 1403 ASSERT(node != NULL); |
1404 nodes_.Add(node); | 1404 nodes_.Add(node); |
1405 return object_id; | 1405 return object_id; |
1406 } | 1406 } |
1407 | 1407 |
1408 | 1408 |
1409 void ForwardList::UnmarkAll() const { | 1409 void ForwardList::UnmarkAll() const { |
1410 NoGCScope no_gc; | 1410 NoSafepointScope no_safepoint; |
1411 for (intptr_t id = first_object_id(); id < next_object_id(); ++id) { | 1411 for (intptr_t id = first_object_id(); id < next_object_id(); ++id) { |
1412 const Node* node = NodeForObjectId(id); | 1412 const Node* node = NodeForObjectId(id); |
1413 RawObject* raw = node->raw(); | 1413 RawObject* raw = node->raw(); |
1414 raw->ptr()->tags_ = node->tags(); // Restore original tags. | 1414 raw->ptr()->tags_ = node->tags(); // Restore original tags. |
1415 } | 1415 } |
1416 } | 1416 } |
1417 | 1417 |
1418 | 1418 |
1419 bool SnapshotWriter::CheckAndWritePredefinedObject(RawObject* rawobj) { | 1419 bool SnapshotWriter::CheckAndWritePredefinedObject(RawObject* rawobj) { |
1420 // Check if object can be written in one of the following ways: | 1420 // Check if object can be written in one of the following ways: |
1421 // - Smi: the Smi value is written as is (last bit is not tagged). | 1421 // - Smi: the Smi value is written as is (last bit is not tagged). |
1422 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3) | 1422 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3) |
1423 // - Object that has already been written: (negative id in stream | 0x3) | 1423 // - Object that has already been written: (negative id in stream | 0x3) |
1424 | 1424 |
1425 NoGCScope no_gc; | 1425 NoSafepointScope no_safepoint; |
1426 | 1426 |
1427 // First check if it is a Smi (i.e not a heap object). | 1427 // First check if it is a Smi (i.e not a heap object). |
1428 if (!rawobj->IsHeapObject()) { | 1428 if (!rawobj->IsHeapObject()) { |
1429 Write<int64_t>(reinterpret_cast<intptr_t>(rawobj)); | 1429 Write<int64_t>(reinterpret_cast<intptr_t>(rawobj)); |
1430 return true; | 1430 return true; |
1431 } | 1431 } |
1432 | 1432 |
1433 intptr_t cid = rawobj->GetClassId(); | 1433 intptr_t cid = rawobj->GetClassId(); |
1434 | 1434 |
1435 if ((kind_ == Snapshot::kMessage) && (cid == kDoubleCid)) { | 1435 if ((kind_ == Snapshot::kMessage) && (cid == kDoubleCid)) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 WriteInlinedObject(raw); | 1517 WriteInlinedObject(raw); |
1518 } | 1518 } |
1519 | 1519 |
1520 | 1520 |
1521 void SnapshotWriter::WriteInlinedObject(RawObject* raw) { | 1521 void SnapshotWriter::WriteInlinedObject(RawObject* raw) { |
1522 // Now write the object out inline in the stream as follows: | 1522 // Now write the object out inline in the stream as follows: |
1523 // - Object is seen for the first time (inlined as follows): | 1523 // - Object is seen for the first time (inlined as follows): |
1524 // (object size in multiples of kObjectAlignment | 0x1) | 1524 // (object size in multiples of kObjectAlignment | 0x1) |
1525 // serialized fields of the object | 1525 // serialized fields of the object |
1526 // ...... | 1526 // ...... |
1527 NoGCScope no_gc; | 1527 NoSafepointScope no_safepoint; |
1528 uword tags = raw->ptr()->tags_; | 1528 uword tags = raw->ptr()->tags_; |
1529 ASSERT(SerializedHeaderTag::decode(tags) == kObjectId); | 1529 ASSERT(SerializedHeaderTag::decode(tags) == kObjectId); |
1530 intptr_t object_id = SerializedHeaderData::decode(tags); | 1530 intptr_t object_id = SerializedHeaderData::decode(tags); |
1531 tags = forward_list_.NodeForObjectId(object_id)->tags(); | 1531 tags = forward_list_.NodeForObjectId(object_id)->tags(); |
1532 RawClass* cls = class_table_->At(RawObject::ClassIdTag::decode(tags)); | 1532 RawClass* cls = class_table_->At(RawObject::ClassIdTag::decode(tags)); |
1533 intptr_t class_id = cls->ptr()->id_; | 1533 intptr_t class_id = cls->ptr()->id_; |
1534 | 1534 |
1535 if (!IsSplitClassId(class_id)) { | 1535 if (!IsSplitClassId(class_id)) { |
1536 object_id = kOmittedObjectId; | 1536 object_id = kOmittedObjectId; |
1537 } | 1537 } |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 LongJumpScope jump; | 1908 LongJumpScope jump; |
1909 if (setjmp(*jump.Set()) == 0) { | 1909 if (setjmp(*jump.Set()) == 0) { |
1910 // Reserve space in the output buffer for a snapshot header. | 1910 // Reserve space in the output buffer for a snapshot header. |
1911 ReserveHeader(); | 1911 ReserveHeader(); |
1912 | 1912 |
1913 // Write out the version string. | 1913 // Write out the version string. |
1914 WriteVersion(); | 1914 WriteVersion(); |
1915 | 1915 |
1916 // Write out the library object. | 1916 // Write out the library object. |
1917 { | 1917 { |
1918 NoGCScope no_gc; | 1918 NoSafepointScope no_safepoint; |
1919 | 1919 |
1920 // Write out the library object. | 1920 // Write out the library object. |
1921 WriteObject(lib.raw()); | 1921 WriteObject(lib.raw()); |
1922 | 1922 |
1923 FillHeader(kind()); | 1923 FillHeader(kind()); |
1924 UnmarkAll(); | 1924 UnmarkAll(); |
1925 } | 1925 } |
1926 } else { | 1926 } else { |
1927 ThrowException(exception_type(), exception_msg()); | 1927 ThrowException(exception_type(), exception_msg()); |
1928 } | 1928 } |
(...skipping 13 matching lines...) Expand all Loading... |
1942 | 1942 |
1943 | 1943 |
1944 void MessageWriter::WriteMessage(const Object& obj) { | 1944 void MessageWriter::WriteMessage(const Object& obj) { |
1945 ASSERT(kind() == Snapshot::kMessage); | 1945 ASSERT(kind() == Snapshot::kMessage); |
1946 ASSERT(isolate() != NULL); | 1946 ASSERT(isolate() != NULL); |
1947 | 1947 |
1948 // Setup for long jump in case there is an exception while writing | 1948 // Setup for long jump in case there is an exception while writing |
1949 // the message. | 1949 // the message. |
1950 LongJumpScope jump; | 1950 LongJumpScope jump; |
1951 if (setjmp(*jump.Set()) == 0) { | 1951 if (setjmp(*jump.Set()) == 0) { |
1952 NoGCScope no_gc; | 1952 NoSafepointScope no_safepoint; |
1953 WriteObject(obj.raw()); | 1953 WriteObject(obj.raw()); |
1954 UnmarkAll(); | 1954 UnmarkAll(); |
1955 } else { | 1955 } else { |
1956 ThrowException(exception_type(), exception_msg()); | 1956 ThrowException(exception_type(), exception_msg()); |
1957 } | 1957 } |
1958 } | 1958 } |
1959 | 1959 |
1960 | 1960 |
1961 } // namespace dart | 1961 } // namespace dart |
OLD | NEW |