OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 DeleteArray(encodings_[type]); | 658 DeleteArray(encodings_[type]); |
659 } | 659 } |
660 DeleteArray(encodings_); | 660 DeleteArray(encodings_); |
661 } | 661 } |
662 | 662 |
663 | 663 |
664 bool Serializer::serialization_enabled_ = false; | 664 bool Serializer::serialization_enabled_ = false; |
665 bool Serializer::too_late_to_enable_now_ = false; | 665 bool Serializer::too_late_to_enable_now_ = false; |
666 | 666 |
667 | 667 |
668 class CodeAddressMap: public CodeEventLogger { | |
669 public: | |
670 explicit CodeAddressMap(Isolate* isolate) | |
671 : isolate_(isolate) { | |
672 isolate->logger()->addLogger(this); | |
673 } | |
674 | |
675 virtual ~CodeAddressMap() { | |
676 isolate_->logger()->removeLogger(this); | |
677 } | |
678 | |
679 virtual void CodeMoveEvent(Address from, Address to) { | |
680 address_to_name_map_.Move(from, to); | |
681 } | |
682 | |
683 virtual void CodeDeleteEvent(Address from) { | |
684 address_to_name_map_.Remove(from); | |
685 } | |
686 | |
687 const char* Lookup(Address address) { | |
688 return address_to_name_map_.Lookup(address); | |
689 } | |
690 | |
691 private: | |
692 class NameMap { | |
693 public: | |
694 NameMap() : impl_(&PointerEquals) {} | |
695 | |
696 ~NameMap() { | |
697 for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) { | |
698 DeleteArray(static_cast<const char*>(p->value)); | |
699 } | |
700 } | |
701 | |
702 void Insert(Address code_address, const char* name, int name_size) { | |
703 HashMap::Entry* entry = FindOrCreateEntry(code_address); | |
704 if (entry->value == NULL) { | |
705 entry->value = CopyName(name, name_size); | |
706 } | |
707 } | |
708 | |
709 const char* Lookup(Address code_address) { | |
710 HashMap::Entry* entry = FindEntry(code_address); | |
711 return (entry != NULL) ? static_cast<const char*>(entry->value) : NULL; | |
712 } | |
713 | |
714 void Remove(Address code_address) { | |
715 HashMap::Entry* entry = FindEntry(code_address); | |
716 if (entry != NULL) { | |
717 DeleteArray(static_cast<char*>(entry->value)); | |
718 RemoveEntry(entry); | |
719 } | |
720 } | |
721 | |
722 void Move(Address from, Address to) { | |
723 if (from == to) return; | |
724 HashMap::Entry* from_entry = FindEntry(from); | |
725 ASSERT(from_entry != NULL); | |
726 void* value = from_entry->value; | |
727 RemoveEntry(from_entry); | |
728 HashMap::Entry* to_entry = FindOrCreateEntry(to); | |
729 ASSERT(to_entry->value == NULL); | |
730 to_entry->value = value; | |
731 } | |
732 | |
733 private: | |
734 static bool PointerEquals(void* lhs, void* rhs) { | |
735 return lhs == rhs; | |
736 } | |
737 | |
738 static char* CopyName(const char* name, int name_size) { | |
739 char* result = NewArray<char>(name_size + 1); | |
740 for (int i = 0; i < name_size; ++i) { | |
741 char c = name[i]; | |
742 if (c == '\0') c = ' '; | |
743 result[i] = c; | |
744 } | |
745 result[name_size] = '\0'; | |
746 return result; | |
747 } | |
748 | |
749 HashMap::Entry* FindOrCreateEntry(Address code_address) { | |
750 return impl_.Lookup(code_address, ComputePointerHash(code_address), true); | |
751 } | |
752 | |
753 HashMap::Entry* FindEntry(Address code_address) { | |
754 return impl_.Lookup(code_address, | |
755 ComputePointerHash(code_address), | |
756 false); | |
757 } | |
758 | |
759 void RemoveEntry(HashMap::Entry* entry) { | |
760 impl_.Remove(entry->key, entry->hash); | |
761 } | |
762 | |
763 HashMap impl_; | |
764 | |
765 DISALLOW_COPY_AND_ASSIGN(NameMap); | |
766 }; | |
767 | |
768 virtual void LogRecordedBuffer(Code* code, | |
769 SharedFunctionInfo*, | |
770 const char* name, | |
771 int length) { | |
772 address_to_name_map_.Insert(code->address(), name, length); | |
773 } | |
774 | |
775 NameMap address_to_name_map_; | |
776 Isolate* isolate_; | |
777 }; | |
778 | |
779 | |
780 CodeAddressMap* Serializer::code_address_map_ = NULL; | |
781 | |
782 | |
783 void Serializer::Enable() { | |
784 if (!serialization_enabled_) { | |
785 ASSERT(!too_late_to_enable_now_); | |
786 } | |
yurys
2013/07/26 08:04:54
Should return early in else branch.
| |
787 i::Isolate* isolate = Isolate::Current(); | |
788 isolate->InitializeLoggingAndCounters(); | |
789 code_address_map_ = new CodeAddressMap(isolate); | |
790 serialization_enabled_ = true; | |
791 } | |
792 | |
793 | |
794 void Serializer::Disable() { | |
795 serialization_enabled_ = false; | |
yurys
2013/07/26 08:04:54
ASSERT(serialization_enabled_) ?
| |
796 delete code_address_map_; | |
797 code_address_map_ = NULL; | |
798 } | |
799 | |
800 | |
668 Deserializer::Deserializer(SnapshotByteSource* source) | 801 Deserializer::Deserializer(SnapshotByteSource* source) |
669 : isolate_(NULL), | 802 : isolate_(NULL), |
670 source_(source), | 803 source_(source), |
671 external_reference_decoder_(NULL) { | 804 external_reference_decoder_(NULL) { |
672 for (int i = 0; i < LAST_SPACE + 1; i++) { | 805 for (int i = 0; i < LAST_SPACE + 1; i++) { |
673 reservations_[i] = kUninitializedReservation; | 806 reservations_[i] = kUninitializedReservation; |
674 } | 807 } |
675 } | 808 } |
676 | 809 |
677 | 810 |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1451 | 1584 |
1452 | 1585 |
1453 void Serializer::ObjectSerializer::Serialize() { | 1586 void Serializer::ObjectSerializer::Serialize() { |
1454 int space = Serializer::SpaceOfObject(object_); | 1587 int space = Serializer::SpaceOfObject(object_); |
1455 int size = object_->Size(); | 1588 int size = object_->Size(); |
1456 | 1589 |
1457 sink_->Put(kNewObject + reference_representation_ + space, | 1590 sink_->Put(kNewObject + reference_representation_ + space, |
1458 "ObjectSerialization"); | 1591 "ObjectSerialization"); |
1459 sink_->PutInt(size >> kObjectAlignmentBits, "Size in words"); | 1592 sink_->PutInt(size >> kObjectAlignmentBits, "Size in words"); |
1460 | 1593 |
1594 ASSERT(code_address_map_); | |
1595 const char* code_name = code_address_map_->Lookup(object_->address()); | |
1596 LOG(i::Isolate::Current(), | |
1597 CodeNameEvent(object_->address(), sink_->Position(), code_name)); | |
1461 LOG(i::Isolate::Current(), | 1598 LOG(i::Isolate::Current(), |
1462 SnapshotPositionEvent(object_->address(), sink_->Position())); | 1599 SnapshotPositionEvent(object_->address(), sink_->Position())); |
1463 | 1600 |
1464 // Mark this object as already serialized. | 1601 // Mark this object as already serialized. |
1465 int offset = serializer_->Allocate(space, size); | 1602 int offset = serializer_->Allocate(space, size); |
1466 serializer_->address_mapper()->AddMapping(object_, offset); | 1603 serializer_->address_mapper()->AddMapping(object_, offset); |
1467 | 1604 |
1468 // Serialize the map (first word of the object). | 1605 // Serialize the map (first word of the object). |
1469 serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject, 0); | 1606 serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject, 0); |
1470 | 1607 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1717 | 1854 |
1718 bool SnapshotByteSource::AtEOF() { | 1855 bool SnapshotByteSource::AtEOF() { |
1719 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; | 1856 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; |
1720 for (int x = position_; x < length_; x++) { | 1857 for (int x = position_; x < length_; x++) { |
1721 if (data_[x] != SerializerDeserializer::nop()) return false; | 1858 if (data_[x] != SerializerDeserializer::nop()) return false; |
1722 } | 1859 } |
1723 return true; | 1860 return true; |
1724 } | 1861 } |
1725 | 1862 |
1726 } } // namespace v8::internal | 1863 } } // namespace v8::internal |
OLD | NEW |