OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_SERIALIZE_H_ | 5 #ifndef V8_SERIALIZE_H_ |
6 #define V8_SERIALIZE_H_ | 6 #define V8_SERIALIZE_H_ |
7 | 7 |
8 #include "src/hashmap.h" | 8 #include "src/hashmap.h" |
9 #include "src/heap-profiler.h" | 9 #include "src/heap-profiler.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 uint32_t Encode(Address key) const; | 56 uint32_t Encode(Address key) const; |
57 | 57 |
58 const char* NameOfAddress(Isolate* isolate, Address address) const; | 58 const char* NameOfAddress(Isolate* isolate, Address address) const; |
59 | 59 |
60 private: | 60 private: |
61 static uint32_t Hash(Address key) { | 61 static uint32_t Hash(Address key) { |
62 return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> | 62 return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> |
63 kPointerSizeLog2); | 63 kPointerSizeLog2); |
64 } | 64 } |
65 | 65 |
66 HashMap map_; | 66 HashMap* map_; |
67 | 67 |
68 DISALLOW_COPY_AND_ASSIGN(ExternalReferenceEncoder); | 68 DISALLOW_COPY_AND_ASSIGN(ExternalReferenceEncoder); |
69 }; | 69 }; |
70 | 70 |
71 | 71 |
72 class AddressMapBase { | 72 class AddressMapBase { |
73 protected: | 73 protected: |
74 static void SetValue(HashMap::Entry* entry, uint32_t v) { | 74 static void SetValue(HashMap::Entry* entry, uint32_t v) { |
75 entry->value = reinterpret_cast<void*>(v); | 75 entry->value = reinterpret_cast<void*>(v); |
76 } | 76 } |
(...skipping 18 matching lines...) Expand all Loading... |
95 }; | 95 }; |
96 | 96 |
97 | 97 |
98 class RootIndexMap : public AddressMapBase { | 98 class RootIndexMap : public AddressMapBase { |
99 public: | 99 public: |
100 explicit RootIndexMap(Isolate* isolate); | 100 explicit RootIndexMap(Isolate* isolate); |
101 | 101 |
102 static const int kInvalidRootIndex = -1; | 102 static const int kInvalidRootIndex = -1; |
103 | 103 |
104 int Lookup(HeapObject* obj) { | 104 int Lookup(HeapObject* obj) { |
105 HashMap::Entry* entry = LookupEntry(&map_, obj, false); | 105 HashMap::Entry* entry = LookupEntry(map_, obj, false); |
106 if (entry) return GetValue(entry); | 106 if (entry) return GetValue(entry); |
107 return kInvalidRootIndex; | 107 return kInvalidRootIndex; |
108 } | 108 } |
109 | 109 |
110 private: | 110 private: |
111 HashMap map_; | 111 HashMap* map_; |
112 | 112 |
113 DISALLOW_COPY_AND_ASSIGN(RootIndexMap); | 113 DISALLOW_COPY_AND_ASSIGN(RootIndexMap); |
114 }; | 114 }; |
115 | 115 |
116 | 116 |
117 class PartialCacheIndexMap : public AddressMapBase { | 117 class PartialCacheIndexMap : public AddressMapBase { |
118 public: | 118 public: |
119 PartialCacheIndexMap() : map_(HashMap::PointersMatch) {} | 119 PartialCacheIndexMap() : map_(HashMap::PointersMatch) {} |
120 | 120 |
121 static const int kInvalidIndex = -1; | 121 static const int kInvalidIndex = -1; |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); | 680 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); |
681 } | 681 } |
682 } | 682 } |
683 | 683 |
684 bool BackReferenceIsAlreadyAllocated(BackReference back_reference); | 684 bool BackReferenceIsAlreadyAllocated(BackReference back_reference); |
685 | 685 |
686 // This will return the space for an object. | 686 // This will return the space for an object. |
687 BackReference AllocateLargeObject(int size); | 687 BackReference AllocateLargeObject(int size); |
688 BackReference Allocate(AllocationSpace space, int size); | 688 BackReference Allocate(AllocationSpace space, int size); |
689 int EncodeExternalReference(Address addr) { | 689 int EncodeExternalReference(Address addr) { |
690 return external_reference_encoder_->Encode(addr); | 690 return external_reference_encoder_.Encode(addr); |
691 } | 691 } |
692 | 692 |
693 // GetInt reads 4 bytes at once, requiring padding at the end. | 693 // GetInt reads 4 bytes at once, requiring padding at the end. |
694 void Pad(); | 694 void Pad(); |
695 | 695 |
696 // Some roots should not be serialized, because their actual value depends on | 696 // Some roots should not be serialized, because their actual value depends on |
697 // absolute addresses and they are reset after deserialization, anyway. | 697 // absolute addresses and they are reset after deserialization, anyway. |
698 bool ShouldBeSkipped(Object** current); | 698 bool ShouldBeSkipped(Object** current); |
699 | 699 |
700 // We may not need the code address map for logging for every instance | 700 // We may not need the code address map for logging for every instance |
701 // of the serializer. Initialize it on demand. | 701 // of the serializer. Initialize it on demand. |
702 void InitializeCodeAddressMap(); | 702 void InitializeCodeAddressMap(); |
703 | 703 |
704 Code* CopyCode(Code* code); | 704 Code* CopyCode(Code* code); |
705 | 705 |
706 inline uint32_t max_chunk_size(int space) const { | 706 inline uint32_t max_chunk_size(int space) const { |
707 DCHECK_LE(0, space); | 707 DCHECK_LE(0, space); |
708 DCHECK_LT(space, kNumberOfSpaces); | 708 DCHECK_LT(space, kNumberOfSpaces); |
709 return max_chunk_size_[space]; | 709 return max_chunk_size_[space]; |
710 } | 710 } |
711 | 711 |
712 SnapshotByteSink* sink() const { return sink_; } | 712 SnapshotByteSink* sink() const { return sink_; } |
713 | 713 |
714 Isolate* isolate_; | 714 Isolate* isolate_; |
715 | 715 |
716 SnapshotByteSink* sink_; | 716 SnapshotByteSink* sink_; |
717 ExternalReferenceEncoder* external_reference_encoder_; | 717 ExternalReferenceEncoder external_reference_encoder_; |
718 | 718 |
719 BackReferenceMap back_reference_map_; | 719 BackReferenceMap back_reference_map_; |
720 RootIndexMap root_index_map_; | 720 RootIndexMap root_index_map_; |
721 | 721 |
722 friend class Deserializer; | 722 friend class Deserializer; |
723 friend class ObjectSerializer; | 723 friend class ObjectSerializer; |
724 friend class SnapshotData; | 724 friend class SnapshotData; |
725 | 725 |
726 private: | 726 private: |
727 CodeAddressMap* code_address_map_; | 727 CodeAddressMap* code_address_map_; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 kNumInternalizedStringsOffset + kInt32Size; | 971 kNumInternalizedStringsOffset + kInt32Size; |
972 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; | 972 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; |
973 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; | 973 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; |
974 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; | 974 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; |
975 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; | 975 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; |
976 static const int kHeaderSize = kChecksum2Offset + kInt32Size; | 976 static const int kHeaderSize = kChecksum2Offset + kInt32Size; |
977 }; | 977 }; |
978 } } // namespace v8::internal | 978 } } // namespace v8::internal |
979 | 979 |
980 #endif // V8_SERIALIZE_H_ | 980 #endif // V8_SERIALIZE_H_ |
OLD | NEW |