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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 ASSERT(reader != NULL); | 498 ASSERT(reader != NULL); |
499 | 499 |
500 // Allocate function object. | 500 // Allocate function object. |
501 PatchClass& cls = PatchClass::ZoneHandle(reader->zone(), | 501 PatchClass& cls = PatchClass::ZoneHandle(reader->zone(), |
502 NEW_OBJECT(PatchClass)); | 502 NEW_OBJECT(PatchClass)); |
503 reader->AddBackRef(object_id, &cls, kIsDeserialized); | 503 reader->AddBackRef(object_id, &cls, kIsDeserialized); |
504 | 504 |
505 // Set all the object fields. | 505 // Set all the object fields. |
506 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); | 506 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); |
507 | 507 |
508 ASSERT(((kind == Snapshot::kScript) && | 508 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
509 !Class::IsInFullSnapshot(cls.source_class())) || | |
510 (kind == Snapshot::kFull)); | |
511 | |
512 return cls.raw(); | 509 return cls.raw(); |
513 } | 510 } |
514 | 511 |
515 | 512 |
516 void RawPatchClass::WriteTo(SnapshotWriter* writer, | 513 void RawPatchClass::WriteTo(SnapshotWriter* writer, |
517 intptr_t object_id, | 514 intptr_t object_id, |
518 Snapshot::Kind kind) { | 515 Snapshot::Kind kind) { |
519 ASSERT(writer != NULL); | 516 ASSERT(writer != NULL); |
520 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 517 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
521 | 518 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 } | 622 } |
626 | 623 |
627 | 624 |
628 RawFunction* Function::ReadFrom(SnapshotReader* reader, | 625 RawFunction* Function::ReadFrom(SnapshotReader* reader, |
629 intptr_t object_id, | 626 intptr_t object_id, |
630 intptr_t tags, | 627 intptr_t tags, |
631 Snapshot::Kind kind) { | 628 Snapshot::Kind kind) { |
632 ASSERT(reader != NULL); | 629 ASSERT(reader != NULL); |
633 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 630 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
634 | 631 |
635 // Allocate function object. | 632 bool is_in_fullsnapshot = reader->Read<bool>(); |
636 Function& func = Function::ZoneHandle( | 633 if ((kind == Snapshot::kFull) || !is_in_fullsnapshot) { |
637 reader->zone(), NEW_OBJECT(Function)); | 634 // Allocate function object. |
638 reader->AddBackRef(object_id, &func, kIsDeserialized); | 635 Function& func = Function::ZoneHandle( |
| 636 reader->zone(), NEW_OBJECT(Function)); |
| 637 reader->AddBackRef(object_id, &func, kIsDeserialized); |
639 | 638 |
640 // Set all the non object fields. | 639 // Set all the non object fields. |
641 func.set_token_pos(reader->Read<int32_t>()); | 640 func.set_token_pos(reader->Read<int32_t>()); |
642 func.set_end_token_pos(reader->Read<int32_t>()); | 641 func.set_end_token_pos(reader->Read<int32_t>()); |
643 func.set_usage_counter(reader->Read<int32_t>()); | 642 func.set_usage_counter(reader->Read<int32_t>()); |
644 func.set_num_fixed_parameters(reader->Read<int16_t>()); | 643 func.set_num_fixed_parameters(reader->Read<int16_t>()); |
645 func.set_num_optional_parameters(reader->Read<int16_t>()); | 644 func.set_num_optional_parameters(reader->Read<int16_t>()); |
646 func.set_deoptimization_counter(reader->Read<int16_t>()); | 645 func.set_deoptimization_counter(reader->Read<int16_t>()); |
647 func.set_kind_tag(reader->Read<uint32_t>()); | 646 func.set_kind_tag(reader->Read<uint32_t>()); |
648 func.set_optimized_instruction_count(reader->Read<uint16_t>()); | 647 func.set_optimized_instruction_count(reader->Read<uint16_t>()); |
649 func.set_optimized_call_site_count(reader->Read<uint16_t>()); | 648 func.set_optimized_call_site_count(reader->Read<uint16_t>()); |
650 | 649 |
651 // Set all the object fields. | 650 // Set all the object fields. |
652 READ_OBJECT_FIELDS(func, | 651 bool is_optimized = func.usage_counter() != 0; |
653 func.raw()->from(), | 652 RawObject** toobj = reader->snapshot_code() ? func.raw()->to() : |
654 reader->snapshot_code() ? func.raw()->to() | 653 (is_optimized ? func.raw()->to_optimized_snapshot() : |
655 : func.raw()->to_snapshot(), | 654 func.raw()->to_snapshot()); |
656 kAsReference); | 655 READ_OBJECT_FIELDS(func, |
657 | 656 func.raw()->from(), toobj, |
658 if (!reader->snapshot_code()) { | 657 kAsReference); |
659 // Initialize all fields that are not part of the snapshot. | 658 if (!reader->snapshot_code()) { |
660 func.ClearICDataArray(); | 659 // Initialize all fields that are not part of the snapshot. |
661 func.ClearCode(); | 660 if (!is_optimized) { |
| 661 func.ClearICDataArray(); |
| 662 } |
| 663 func.ClearCode(); |
| 664 } else { |
| 665 // TODO(rmacnak): Fix entry_point_. |
| 666 } |
| 667 return func.raw(); |
662 } else { | 668 } else { |
663 // TODO(rmacnak): Fix entry_point_. | 669 return reader->ReadFunctionId(object_id); |
664 } | 670 } |
665 return func.raw(); | |
666 } | 671 } |
667 | 672 |
668 | 673 |
669 void RawFunction::WriteTo(SnapshotWriter* writer, | 674 void RawFunction::WriteTo(SnapshotWriter* writer, |
670 intptr_t object_id, | 675 intptr_t object_id, |
671 Snapshot::Kind kind) { | 676 Snapshot::Kind kind) { |
672 ASSERT(writer != NULL); | 677 ASSERT(writer != NULL); |
673 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 678 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| 679 bool is_in_fullsnapshot = false; |
| 680 bool owner_is_class = false; |
| 681 if (kind == Snapshot::kScript) { |
| 682 intptr_t tags = writer->GetObjectTags(ptr()->owner_); |
| 683 intptr_t cid = ClassIdTag::decode(tags); |
| 684 owner_is_class = (cid == kClassCid); |
| 685 is_in_fullsnapshot = owner_is_class ? |
| 686 Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) : |
| 687 PatchClass::IsInFullSnapshot( |
| 688 reinterpret_cast<RawPatchClass*>(ptr()->owner_)); |
| 689 } |
674 | 690 |
675 // Write out the serialization header value for this object. | 691 // Write out the serialization header value for this object. |
676 writer->WriteInlinedObjectHeader(object_id); | 692 writer->WriteInlinedObjectHeader(object_id); |
677 | 693 |
678 // Write out the class and tags information. | 694 // Write out the class and tags information. |
679 writer->WriteVMIsolateObject(kFunctionCid); | 695 writer->WriteVMIsolateObject(kFunctionCid); |
680 writer->WriteTags(writer->GetObjectTags(this)); | 696 writer->WriteTags(writer->GetObjectTags(this)); |
681 | 697 |
682 // Write out all the non object fields. | 698 // Write out the boolean is_in_fullsnapshot first as this will |
683 writer->Write<int32_t>(ptr()->token_pos_); | 699 // help the reader decide how the rest of the information needs |
684 writer->Write<int32_t>(ptr()->end_token_pos_); | 700 // to be interpreted. |
685 if (Code::IsOptimized(ptr()->instructions_->ptr()->code_)) { | 701 writer->Write<bool>(is_in_fullsnapshot); |
686 writer->Write<int32_t>(FLAG_optimization_counter_threshold); | 702 |
| 703 if (kind == Snapshot::kFull || !is_in_fullsnapshot) { |
| 704 bool is_optimized = Code::IsOptimized(ptr()->instructions_->ptr()->code_); |
| 705 |
| 706 // Write out all the non object fields. |
| 707 writer->Write<int32_t>(ptr()->token_pos_); |
| 708 writer->Write<int32_t>(ptr()->end_token_pos_); |
| 709 if (is_optimized) { |
| 710 writer->Write<int32_t>(FLAG_optimization_counter_threshold); |
| 711 } else { |
| 712 writer->Write<int32_t>(0); |
| 713 } |
| 714 writer->Write<int16_t>(ptr()->num_fixed_parameters_); |
| 715 writer->Write<int16_t>(ptr()->num_optional_parameters_); |
| 716 writer->Write<int16_t>(ptr()->deoptimization_counter_); |
| 717 writer->Write<uint32_t>(ptr()->kind_tag_); |
| 718 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); |
| 719 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); |
| 720 |
| 721 // Write out all the object pointer fields. |
| 722 RawObject** toobj = |
| 723 writer->snapshot_code() ? to() : |
| 724 (is_optimized ? to_optimized_snapshot() : to_snapshot()); |
| 725 SnapshotWriterVisitor visitor(writer); |
| 726 visitor.VisitPointers(from(), toobj); |
687 } else { | 727 } else { |
688 writer->Write<int32_t>(0); | 728 writer->WriteFunctionId(this, owner_is_class); |
689 } | 729 } |
690 writer->Write<int16_t>(ptr()->num_fixed_parameters_); | |
691 writer->Write<int16_t>(ptr()->num_optional_parameters_); | |
692 writer->Write<int16_t>(ptr()->deoptimization_counter_); | |
693 writer->Write<uint32_t>(ptr()->kind_tag_); | |
694 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); | |
695 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); | |
696 | |
697 // Write out all the object pointer fields. | |
698 SnapshotWriterVisitor visitor(writer); | |
699 visitor.VisitPointers(from(), writer->snapshot_code() ? to() | |
700 : to_snapshot()); | |
701 } | 730 } |
702 | 731 |
703 | 732 |
704 RawField* Field::ReadFrom(SnapshotReader* reader, | 733 RawField* Field::ReadFrom(SnapshotReader* reader, |
705 intptr_t object_id, | 734 intptr_t object_id, |
706 intptr_t tags, | 735 intptr_t tags, |
707 Snapshot::Kind kind) { | 736 Snapshot::Kind kind) { |
708 ASSERT(reader != NULL); | 737 ASSERT(reader != NULL); |
709 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); | 738 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
710 | 739 |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 return; | 1701 return; |
1673 } | 1702 } |
1674 UNREACHABLE(); | 1703 UNREACHABLE(); |
1675 } | 1704 } |
1676 | 1705 |
1677 | 1706 |
1678 RawICData* ICData::ReadFrom(SnapshotReader* reader, | 1707 RawICData* ICData::ReadFrom(SnapshotReader* reader, |
1679 intptr_t object_id, | 1708 intptr_t object_id, |
1680 intptr_t tags, | 1709 intptr_t tags, |
1681 Snapshot::Kind kind) { | 1710 Snapshot::Kind kind) { |
1682 ASSERT(reader->snapshot_code()); | 1711 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
1683 ASSERT(kind == Snapshot::kFull); | |
1684 | 1712 |
1685 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); | 1713 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); |
1686 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1714 reader->AddBackRef(object_id, &result, kIsDeserialized); |
1687 | 1715 |
1688 result.set_deopt_id(reader->Read<int32_t>()); | 1716 result.set_deopt_id(reader->Read<int32_t>()); |
1689 result.set_state_bits(reader->Read<uint32_t>()); | 1717 result.set_state_bits(reader->Read<uint32_t>()); |
1690 | 1718 |
1691 // Set all the object fields. | 1719 // Set all the object fields. |
1692 READ_OBJECT_FIELDS(result, | 1720 READ_OBJECT_FIELDS(result, |
1693 result.raw()->from(), result.raw()->to(), | 1721 result.raw()->from(), result.raw()->to(), |
1694 kAsReference); | 1722 kAsReference); |
1695 | 1723 |
1696 return result.raw(); | 1724 return result.raw(); |
1697 } | 1725 } |
1698 | 1726 |
1699 | 1727 |
1700 void RawICData::WriteTo(SnapshotWriter* writer, | 1728 void RawICData::WriteTo(SnapshotWriter* writer, |
1701 intptr_t object_id, | 1729 intptr_t object_id, |
1702 Snapshot::Kind kind) { | 1730 Snapshot::Kind kind) { |
1703 ASSERT(writer->snapshot_code()); | 1731 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
1704 ASSERT(kind == Snapshot::kFull); | |
1705 | 1732 |
1706 // Write out the serialization header value for this object. | 1733 // Write out the serialization header value for this object. |
1707 writer->WriteInlinedObjectHeader(object_id); | 1734 writer->WriteInlinedObjectHeader(object_id); |
1708 | 1735 |
1709 // Write out the class and tags information. | 1736 // Write out the class and tags information. |
1710 writer->WriteVMIsolateObject(kICDataCid); | 1737 writer->WriteVMIsolateObject(kICDataCid); |
1711 writer->WriteTags(writer->GetObjectTags(this)); | 1738 writer->WriteTags(writer->GetObjectTags(this)); |
1712 | 1739 |
1713 // Write out all the non object fields. | 1740 // Write out all the non object fields. |
1714 writer->Write<int32_t>(ptr()->deopt_id_); | 1741 writer->Write<int32_t>(ptr()->deopt_id_); |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3264 // We do not allow objects with native fields in an isolate message. | 3291 // We do not allow objects with native fields in an isolate message. |
3265 writer->SetWriteException(Exceptions::kArgument, | 3292 writer->SetWriteException(Exceptions::kArgument, |
3266 "Illegal argument in isolate message" | 3293 "Illegal argument in isolate message" |
3267 " : (object is a UserTag)"); | 3294 " : (object is a UserTag)"); |
3268 } else { | 3295 } else { |
3269 UNREACHABLE(); | 3296 UNREACHABLE(); |
3270 } | 3297 } |
3271 } | 3298 } |
3272 | 3299 |
3273 } // namespace dart | 3300 } // namespace dart |
OLD | NEW |