OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/clustered_snapshot.h" | 5 #include "vm/clustered_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.h" | 10 #include "vm/dart.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 void WriteClass(Serializer* s, RawClass* cls) { | 108 void WriteClass(Serializer* s, RawClass* cls) { |
109 Snapshot::Kind kind = s->kind(); | 109 Snapshot::Kind kind = s->kind(); |
110 RawObject** from = cls->from(); | 110 RawObject** from = cls->from(); |
111 RawObject** to = cls->to_snapshot(kind); | 111 RawObject** to = cls->to_snapshot(kind); |
112 for (RawObject** p = from; p <= to; p++) { | 112 for (RawObject** p = from; p <= to; p++) { |
113 s->WriteRef(*p); | 113 s->WriteRef(*p); |
114 } | 114 } |
115 intptr_t class_id = cls->ptr()->id_; | 115 intptr_t class_id = cls->ptr()->id_; |
116 if (class_id == kIllegalCid) { | 116 if (class_id == kIllegalCid) { |
117 FATAL1("Attempting to serialize class with illegal cid: %s\n", | 117 s->UnexpectedObject(cls, "Class with illegal cid"); |
118 Class::Handle(cls).ToCString()); | |
119 } | 118 } |
120 s->WriteCid(class_id); | 119 s->WriteCid(class_id); |
121 s->Write<int32_t>(cls->ptr()->instance_size_in_words_); | 120 s->Write<int32_t>(cls->ptr()->instance_size_in_words_); |
122 s->Write<int32_t>(cls->ptr()->next_field_offset_in_words_); | 121 s->Write<int32_t>(cls->ptr()->next_field_offset_in_words_); |
123 s->Write<int32_t>(cls->ptr()->type_arguments_field_offset_in_words_); | 122 s->Write<int32_t>(cls->ptr()->type_arguments_field_offset_in_words_); |
124 s->Write<uint16_t>(cls->ptr()->num_type_arguments_); | 123 s->Write<uint16_t>(cls->ptr()->num_type_arguments_); |
125 s->Write<uint16_t>(cls->ptr()->num_own_type_arguments_); | 124 s->Write<uint16_t>(cls->ptr()->num_own_type_arguments_); |
126 s->Write<uint16_t>(cls->ptr()->num_native_fields_); | 125 s->Write<uint16_t>(cls->ptr()->num_native_fields_); |
127 s->WriteTokenPosition(cls->ptr()->token_pos_); | 126 s->WriteTokenPosition(cls->ptr()->token_pos_); |
128 s->Write<uint16_t>(cls->ptr()->state_bits_); | 127 s->Write<uint16_t>(cls->ptr()->state_bits_); |
(...skipping 4368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4497 heap_(thread->isolate()->heap()), | 4496 heap_(thread->isolate()->heap()), |
4498 zone_(thread->zone()), | 4497 zone_(thread->zone()), |
4499 kind_(kind), | 4498 kind_(kind), |
4500 stream_(buffer, alloc, initial_size), | 4499 stream_(buffer, alloc, initial_size), |
4501 image_writer_(image_writer), | 4500 image_writer_(image_writer), |
4502 clusters_by_cid_(NULL), | 4501 clusters_by_cid_(NULL), |
4503 stack_(), | 4502 stack_(), |
4504 num_cids_(0), | 4503 num_cids_(0), |
4505 num_base_objects_(0), | 4504 num_base_objects_(0), |
4506 num_written_objects_(0), | 4505 num_written_objects_(0), |
4507 next_ref_index_(1) { | 4506 next_ref_index_(1) |
| 4507 #if defined(SNAPSHOT_BACKTRACE) |
| 4508 , |
| 4509 current_parent_(Object::null()), |
| 4510 parent_pairs_() |
| 4511 #endif |
| 4512 { |
4508 num_cids_ = thread->isolate()->class_table()->NumCids(); | 4513 num_cids_ = thread->isolate()->class_table()->NumCids(); |
4509 clusters_by_cid_ = new SerializationCluster*[num_cids_]; | 4514 clusters_by_cid_ = new SerializationCluster*[num_cids_]; |
4510 for (intptr_t i = 0; i < num_cids_; i++) { | 4515 for (intptr_t i = 0; i < num_cids_; i++) { |
4511 clusters_by_cid_[i] = NULL; | 4516 clusters_by_cid_[i] = NULL; |
4512 } | 4517 } |
4513 } | 4518 } |
4514 | 4519 |
4515 | 4520 |
4516 Serializer::~Serializer() { | 4521 Serializer::~Serializer() { |
4517 delete[] clusters_by_cid_; | 4522 delete[] clusters_by_cid_; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4642 default: | 4647 default: |
4643 break; | 4648 break; |
4644 } | 4649 } |
4645 | 4650 |
4646 FATAL1("No cluster defined for cid %" Pd, cid); | 4651 FATAL1("No cluster defined for cid %" Pd, cid); |
4647 return NULL; | 4652 return NULL; |
4648 #endif // !DART_PRECOMPILED_RUNTIME | 4653 #endif // !DART_PRECOMPILED_RUNTIME |
4649 } | 4654 } |
4650 | 4655 |
4651 | 4656 |
| 4657 void Serializer::Push(RawObject* object) { |
| 4658 if (!object->IsHeapObject()) { |
| 4659 RawSmi* smi = Smi::RawCast(object); |
| 4660 if (smi_ids_.Lookup(smi) == NULL) { |
| 4661 SmiObjectIdPair pair; |
| 4662 pair.smi_ = smi; |
| 4663 pair.id_ = 1; |
| 4664 smi_ids_.Insert(pair); |
| 4665 stack_.Add(object); |
| 4666 num_written_objects_++; |
| 4667 } |
| 4668 return; |
| 4669 } |
| 4670 |
| 4671 if (object->IsCode() && !Snapshot::IncludesCode(kind_)) { |
| 4672 return; // Do not trace, will write null. |
| 4673 } |
| 4674 |
| 4675 if (object->IsSendPort()) { |
| 4676 // TODO(rmacnak): Do a better job of resetting fields in precompilation |
| 4677 // and assert this is unreachable. |
| 4678 return; // Do not trace, will write null. |
| 4679 } |
| 4680 |
| 4681 intptr_t id = heap_->GetObjectId(object); |
| 4682 if (id == 0) { |
| 4683 heap_->SetObjectId(object, 1); |
| 4684 ASSERT(heap_->GetObjectId(object) != 0); |
| 4685 stack_.Add(object); |
| 4686 num_written_objects_++; |
| 4687 |
| 4688 #if defined(SNAPSHOT_BACKTRACE) |
| 4689 parent_pairs_.Add(&Object::Handle(object)); |
| 4690 parent_pairs_.Add(&Object::Handle(current_parent_)); |
| 4691 #endif |
| 4692 } |
| 4693 } |
| 4694 |
| 4695 |
4652 void Serializer::Trace(RawObject* object) { | 4696 void Serializer::Trace(RawObject* object) { |
4653 intptr_t cid; | 4697 intptr_t cid; |
4654 if (!object->IsHeapObject()) { | 4698 if (!object->IsHeapObject()) { |
4655 // Smis are merged into the Mint cluster because Smis for the writer might | 4699 // Smis are merged into the Mint cluster because Smis for the writer might |
4656 // become Mints for the reader and vice versa. | 4700 // become Mints for the reader and vice versa. |
4657 cid = kMintCid; | 4701 cid = kMintCid; |
4658 } else { | 4702 } else { |
4659 cid = object->GetClassId(); | 4703 cid = object->GetClassId(); |
4660 } | 4704 } |
4661 | 4705 |
4662 SerializationCluster* cluster = clusters_by_cid_[cid]; | 4706 SerializationCluster* cluster = clusters_by_cid_[cid]; |
4663 if (cluster == NULL) { | 4707 if (cluster == NULL) { |
4664 cluster = NewClusterForClass(cid); | 4708 cluster = NewClusterForClass(cid); |
4665 clusters_by_cid_[cid] = cluster; | 4709 clusters_by_cid_[cid] = cluster; |
4666 } | 4710 } |
4667 ASSERT(cluster != NULL); | 4711 ASSERT(cluster != NULL); |
| 4712 |
| 4713 #if defined(SNAPSHOT_BACKTRACE) |
| 4714 current_parent_ = object; |
| 4715 #endif |
| 4716 |
4668 cluster->Trace(this, object); | 4717 cluster->Trace(this, object); |
| 4718 |
| 4719 #if defined(SNAPSHOT_BACKTRACE) |
| 4720 current_parent_ = Object::null(); |
| 4721 #endif |
4669 } | 4722 } |
4670 | 4723 |
4671 | 4724 |
| 4725 void Serializer::UnexpectedObject(RawObject* raw_object, const char* message) { |
| 4726 Object& object = Object::Handle(raw_object); |
| 4727 OS::PrintErr("Unexpected object (%s): %s\n", message, object.ToCString()); |
| 4728 #if defined(SNAPSHOT_BACKTRACE) |
| 4729 while (!object.IsNull()) { |
| 4730 object = ParentOf(object); |
| 4731 OS::PrintErr("referenced by %s\n", object.ToCString()); |
| 4732 } |
| 4733 #endif |
| 4734 OS::Abort(); |
| 4735 } |
| 4736 |
| 4737 |
| 4738 #if defined(SNAPSHOT_BACKTRACE) |
| 4739 RawObject* Serializer::ParentOf(const Object& object) { |
| 4740 for (intptr_t i = 0; i < parent_pairs_.length(); i += 2) { |
| 4741 if (parent_pairs_[i]->raw() == object.raw()) { |
| 4742 return parent_pairs_[i + 1]->raw(); |
| 4743 } |
| 4744 } |
| 4745 return Object::null(); |
| 4746 } |
| 4747 #endif // SNAPSHOT_BACKTRACE |
| 4748 |
| 4749 |
4672 void Serializer::WriteVersionAndFeatures() { | 4750 void Serializer::WriteVersionAndFeatures() { |
4673 const char* expected_version = Version::SnapshotString(); | 4751 const char* expected_version = Version::SnapshotString(); |
4674 ASSERT(expected_version != NULL); | 4752 ASSERT(expected_version != NULL); |
4675 const intptr_t version_len = strlen(expected_version); | 4753 const intptr_t version_len = strlen(expected_version); |
4676 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); | 4754 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); |
4677 | 4755 |
4678 const char* expected_features = | 4756 const char* expected_features = |
4679 Dart::FeaturesString(Isolate::Current(), kind_); | 4757 Dart::FeaturesString(Isolate::Current(), kind_); |
4680 ASSERT(expected_features != NULL); | 4758 ASSERT(expected_features != NULL); |
4681 const intptr_t features_len = strlen(expected_features); | 4759 const intptr_t features_len = strlen(expected_features); |
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5558 thread_->isolate()->SetupImagePage(data_buffer_, | 5636 thread_->isolate()->SetupImagePage(data_buffer_, |
5559 /* is_executable */ false); | 5637 /* is_executable */ false); |
5560 } | 5638 } |
5561 | 5639 |
5562 deserializer.ReadIsolateSnapshot(thread_->isolate()->object_store()); | 5640 deserializer.ReadIsolateSnapshot(thread_->isolate()->object_store()); |
5563 | 5641 |
5564 return ApiError::null(); | 5642 return ApiError::null(); |
5565 } | 5643 } |
5566 | 5644 |
5567 } // namespace dart | 5645 } // namespace dart |
OLD | NEW |