Chromium Code Reviews| 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" |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 ASSERT(reader != NULL); | 497 ASSERT(reader != NULL); |
| 498 | 498 |
| 499 // Allocate function object. | 499 // Allocate function object. |
| 500 PatchClass& cls = PatchClass::ZoneHandle(reader->zone(), | 500 PatchClass& cls = PatchClass::ZoneHandle(reader->zone(), |
| 501 NEW_OBJECT(PatchClass)); | 501 NEW_OBJECT(PatchClass)); |
| 502 reader->AddBackRef(object_id, &cls, kIsDeserialized); | 502 reader->AddBackRef(object_id, &cls, kIsDeserialized); |
| 503 | 503 |
| 504 // Set all the object fields. | 504 // Set all the object fields. |
| 505 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); | 505 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); |
| 506 | 506 |
| 507 ASSERT(((kind == Snapshot::kScript) && | 507 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 508 !Class::IsInFullSnapshot(cls.source_class())) || | |
| 509 (kind == Snapshot::kFull)); | |
| 510 | |
| 511 return cls.raw(); | 508 return cls.raw(); |
| 512 } | 509 } |
| 513 | 510 |
| 514 | 511 |
| 515 void RawPatchClass::WriteTo(SnapshotWriter* writer, | 512 void RawPatchClass::WriteTo(SnapshotWriter* writer, |
| 516 intptr_t object_id, | 513 intptr_t object_id, |
| 517 Snapshot::Kind kind) { | 514 Snapshot::Kind kind) { |
| 518 ASSERT(writer != NULL); | 515 ASSERT(writer != NULL); |
| 519 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 516 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 520 | 517 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 } | 621 } |
| 625 | 622 |
| 626 | 623 |
| 627 RawFunction* Function::ReadFrom(SnapshotReader* reader, | 624 RawFunction* Function::ReadFrom(SnapshotReader* reader, |
| 628 intptr_t object_id, | 625 intptr_t object_id, |
| 629 intptr_t tags, | 626 intptr_t tags, |
| 630 Snapshot::Kind kind) { | 627 Snapshot::Kind kind) { |
| 631 ASSERT(reader != NULL); | 628 ASSERT(reader != NULL); |
| 632 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 629 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 633 | 630 |
| 634 // Allocate function object. | 631 bool is_in_fullsnapshot = reader->Read<bool>(); |
| 635 Function& func = Function::ZoneHandle( | 632 if ((kind == Snapshot::kFull) || !is_in_fullsnapshot) { |
| 636 reader->zone(), NEW_OBJECT(Function)); | 633 // Allocate function object. |
| 637 reader->AddBackRef(object_id, &func, kIsDeserialized); | 634 Function& func = Function::ZoneHandle( |
| 635 reader->zone(), NEW_OBJECT(Function)); | |
| 636 reader->AddBackRef(object_id, &func, kIsDeserialized); | |
| 638 | 637 |
| 639 // Set all the non object fields. | 638 // Set all the non object fields. |
| 640 func.set_token_pos(reader->Read<int32_t>()); | 639 func.set_token_pos(reader->Read<int32_t>()); |
| 641 func.set_end_token_pos(reader->Read<int32_t>()); | 640 func.set_end_token_pos(reader->Read<int32_t>()); |
| 642 func.set_usage_counter(reader->Read<int32_t>()); | 641 func.set_usage_counter(reader->Read<int32_t>()); |
| 643 func.set_num_fixed_parameters(reader->Read<int16_t>()); | 642 func.set_num_fixed_parameters(reader->Read<int16_t>()); |
| 644 func.set_num_optional_parameters(reader->Read<int16_t>()); | 643 func.set_num_optional_parameters(reader->Read<int16_t>()); |
| 645 func.set_deoptimization_counter(reader->Read<int16_t>()); | 644 func.set_deoptimization_counter(reader->Read<int16_t>()); |
| 646 func.set_kind_tag(reader->Read<uint32_t>()); | 645 func.set_kind_tag(reader->Read<uint32_t>()); |
| 647 func.set_optimized_instruction_count(reader->Read<uint16_t>()); | 646 func.set_optimized_instruction_count(reader->Read<uint16_t>()); |
| 648 func.set_optimized_call_site_count(reader->Read<uint16_t>()); | 647 func.set_optimized_call_site_count(reader->Read<uint16_t>()); |
| 649 | 648 |
| 650 // Set all the object fields. | 649 // Set all the object fields. |
| 651 READ_OBJECT_FIELDS(func, | 650 READ_OBJECT_FIELDS(func, |
| 652 func.raw()->from(), | 651 func.raw()->from(), |
| 653 reader->snapshot_code() ? func.raw()->to() | 652 reader->snapshot_code() ? func.raw()->to() |
| 654 : func.raw()->to_snapshot(), | 653 : func.raw()->to_snapshot(), |
| 655 kAsReference); | 654 kAsReference); |
| 656 | 655 |
| 657 if (!reader->snapshot_code()) { | 656 if (!reader->snapshot_code()) { |
| 658 // Initialize all fields that are not part of the snapshot. | 657 // Initialize all fields that are not part of the snapshot. |
| 659 func.ClearICDataArray(); | 658 if (func.usage_counter() == 0) { |
|
rmacnak
2015/09/14 23:34:17
Might as well clear it on the write-side to make t
siva
2015/09/15 21:40:04
Done.
| |
| 660 func.ClearCode(); | 659 func.ClearICDataArray(); |
| 660 } | |
| 661 func.ClearCode(); | |
| 662 } else { | |
| 663 // TODO(rmacnak): Fix entry_point_. | |
| 664 } | |
| 665 return func.raw(); | |
| 661 } else { | 666 } else { |
| 662 // TODO(rmacnak): Fix entry_point_. | 667 return reader->ReadFunctionId(object_id); |
| 663 } | 668 } |
| 664 return func.raw(); | |
| 665 } | 669 } |
| 666 | 670 |
| 667 | 671 |
| 668 void RawFunction::WriteTo(SnapshotWriter* writer, | 672 void RawFunction::WriteTo(SnapshotWriter* writer, |
| 669 intptr_t object_id, | 673 intptr_t object_id, |
| 670 Snapshot::Kind kind) { | 674 Snapshot::Kind kind) { |
| 671 ASSERT(writer != NULL); | 675 ASSERT(writer != NULL); |
| 672 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 676 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 677 bool is_in_fullsnapshot = false; | |
| 678 bool owner_is_class = false; | |
| 679 if (kind == Snapshot::kScript) { | |
| 680 intptr_t tags = writer->GetObjectTags(ptr()->owner_); | |
| 681 intptr_t cid = ClassIdTag::decode(tags); | |
| 682 owner_is_class = (cid == kClassCid); | |
| 683 is_in_fullsnapshot = owner_is_class ? | |
| 684 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) : | |
| 685 PatchClass::IsInFullSnapshot( | |
| 686 reinterpret_cast<RawPatchClass*>(ptr()->owner_)); | |
| 687 } | |
| 673 | 688 |
| 674 // Write out the serialization header value for this object. | 689 // Write out the serialization header value for this object. |
| 675 writer->WriteInlinedObjectHeader(object_id); | 690 writer->WriteInlinedObjectHeader(object_id); |
| 676 | 691 |
| 677 // Write out the class and tags information. | 692 // Write out the class and tags information. |
| 678 writer->WriteVMIsolateObject(kFunctionCid); | 693 writer->WriteVMIsolateObject(kFunctionCid); |
| 679 writer->WriteTags(writer->GetObjectTags(this)); | 694 writer->WriteTags(writer->GetObjectTags(this)); |
| 680 | 695 |
| 681 // Write out all the non object fields. | 696 // Write out the boolean is_in_fullsnapshot first as this will |
| 682 writer->Write<int32_t>(ptr()->token_pos_); | 697 // help the reader decide how the rest of the information needs |
| 683 writer->Write<int32_t>(ptr()->end_token_pos_); | 698 // to be interpreted. |
| 684 if (Code::IsOptimized(ptr()->instructions_->ptr()->code_)) { | 699 writer->Write<bool>(is_in_fullsnapshot); |
| 685 writer->Write<int32_t>(FLAG_optimization_counter_threshold); | 700 |
| 701 if (kind == Snapshot::kFull || !is_in_fullsnapshot) { | |
| 702 // Write out all the non object fields. | |
| 703 writer->Write<int32_t>(ptr()->token_pos_); | |
| 704 writer->Write<int32_t>(ptr()->end_token_pos_); | |
| 705 if (Code::IsOptimized(ptr()->instructions_->ptr()->code_)) { | |
| 706 writer->Write<int32_t>(FLAG_optimization_counter_threshold); | |
| 707 } else { | |
| 708 writer->Write<int32_t>(0); | |
| 709 } | |
| 710 writer->Write<int16_t>(ptr()->num_fixed_parameters_); | |
| 711 writer->Write<int16_t>(ptr()->num_optional_parameters_); | |
| 712 writer->Write<int16_t>(ptr()->deoptimization_counter_); | |
| 713 writer->Write<uint32_t>(ptr()->kind_tag_); | |
| 714 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); | |
| 715 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); | |
| 716 | |
| 717 // Write out all the object pointer fields. | |
| 718 SnapshotWriterVisitor visitor(writer); | |
| 719 visitor.VisitPointers( | |
| 720 from(), writer->snapshot_code() ? to() : to_snapshot()); | |
| 686 } else { | 721 } else { |
| 687 writer->Write<int32_t>(0); | 722 writer->WriteFunctionId(this, owner_is_class); |
| 688 } | 723 } |
| 689 writer->Write<int16_t>(ptr()->num_fixed_parameters_); | |
| 690 writer->Write<int16_t>(ptr()->num_optional_parameters_); | |
| 691 writer->Write<int16_t>(ptr()->deoptimization_counter_); | |
| 692 writer->Write<uint32_t>(ptr()->kind_tag_); | |
| 693 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); | |
| 694 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); | |
| 695 | |
| 696 // Write out all the object pointer fields. | |
| 697 SnapshotWriterVisitor visitor(writer); | |
| 698 visitor.VisitPointers(from(), writer->snapshot_code() ? to() | |
| 699 : to_snapshot()); | |
| 700 } | 724 } |
| 701 | 725 |
| 702 | 726 |
| 703 RawField* Field::ReadFrom(SnapshotReader* reader, | 727 RawField* Field::ReadFrom(SnapshotReader* reader, |
| 704 intptr_t object_id, | 728 intptr_t object_id, |
| 705 intptr_t tags, | 729 intptr_t tags, |
| 706 Snapshot::Kind kind) { | 730 Snapshot::Kind kind) { |
| 707 ASSERT(reader != NULL); | 731 ASSERT(reader != NULL); |
| 708 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 732 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 709 | 733 |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1658 return; | 1682 return; |
| 1659 } | 1683 } |
| 1660 UNREACHABLE(); | 1684 UNREACHABLE(); |
| 1661 } | 1685 } |
| 1662 | 1686 |
| 1663 | 1687 |
| 1664 RawICData* ICData::ReadFrom(SnapshotReader* reader, | 1688 RawICData* ICData::ReadFrom(SnapshotReader* reader, |
| 1665 intptr_t object_id, | 1689 intptr_t object_id, |
| 1666 intptr_t tags, | 1690 intptr_t tags, |
| 1667 Snapshot::Kind kind) { | 1691 Snapshot::Kind kind) { |
| 1668 ASSERT(reader->snapshot_code()); | 1692 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 1669 ASSERT(kind == Snapshot::kFull); | |
| 1670 | 1693 |
| 1671 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); | 1694 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); |
| 1672 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1695 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1673 | 1696 |
| 1674 result.set_deopt_id(reader->Read<int32_t>()); | 1697 result.set_deopt_id(reader->Read<int32_t>()); |
| 1675 result.set_state_bits(reader->Read<uint32_t>()); | 1698 result.set_state_bits(reader->Read<uint32_t>()); |
| 1676 | 1699 |
| 1677 // Set all the object fields. | 1700 // Set all the object fields. |
| 1678 READ_OBJECT_FIELDS(result, | 1701 READ_OBJECT_FIELDS(result, |
| 1679 result.raw()->from(), result.raw()->to(), | 1702 result.raw()->from(), result.raw()->to(), |
| 1680 kAsReference); | 1703 kAsReference); |
| 1681 | 1704 |
| 1682 return result.raw(); | 1705 return result.raw(); |
| 1683 } | 1706 } |
| 1684 | 1707 |
| 1685 | 1708 |
| 1686 void RawICData::WriteTo(SnapshotWriter* writer, | 1709 void RawICData::WriteTo(SnapshotWriter* writer, |
| 1687 intptr_t object_id, | 1710 intptr_t object_id, |
| 1688 Snapshot::Kind kind) { | 1711 Snapshot::Kind kind) { |
| 1689 ASSERT(writer->snapshot_code()); | 1712 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 1690 ASSERT(kind == Snapshot::kFull); | |
| 1691 | 1713 |
| 1692 // Write out the serialization header value for this object. | 1714 // Write out the serialization header value for this object. |
| 1693 writer->WriteInlinedObjectHeader(object_id); | 1715 writer->WriteInlinedObjectHeader(object_id); |
| 1694 | 1716 |
| 1695 // Write out the class and tags information. | 1717 // Write out the class and tags information. |
| 1696 writer->WriteVMIsolateObject(kICDataCid); | 1718 writer->WriteVMIsolateObject(kICDataCid); |
| 1697 writer->WriteTags(writer->GetObjectTags(this)); | 1719 writer->WriteTags(writer->GetObjectTags(this)); |
| 1698 | 1720 |
| 1699 // Write out all the non object fields. | 1721 // Write out all the non object fields. |
| 1700 writer->Write<int32_t>(ptr()->deopt_id_); | 1722 writer->Write<int32_t>(ptr()->deopt_id_); |
| (...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3250 // We do not allow objects with native fields in an isolate message. | 3272 // We do not allow objects with native fields in an isolate message. |
| 3251 writer->SetWriteException(Exceptions::kArgument, | 3273 writer->SetWriteException(Exceptions::kArgument, |
| 3252 "Illegal argument in isolate message" | 3274 "Illegal argument in isolate message" |
| 3253 " : (object is a UserTag)"); | 3275 " : (object is a UserTag)"); |
| 3254 } else { | 3276 } else { |
| 3255 UNREACHABLE(); | 3277 UNREACHABLE(); |
| 3256 } | 3278 } |
| 3257 } | 3279 } |
| 3258 | 3280 |
| 3259 } // namespace dart | 3281 } // namespace dart |
| OLD | NEW |