Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(963)

Side by Side Diff: src/address-map.h

Issue 1991793002: [serializer] cosmetic changes to SerializerReference. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/snapshot/deserializer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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_ADDRESS_MAP_H_ 5 #ifndef V8_ADDRESS_MAP_H_
6 #define V8_ADDRESS_MAP_H_ 6 #define V8_ADDRESS_MAP_H_
7 7
8 #include "src/assert-scope.h" 8 #include "src/assert-scope.h"
9 #include "src/hashmap.h" 9 #include "src/hashmap.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 private: 55 private:
56 HashMap* map_; 56 HashMap* map_;
57 57
58 DISALLOW_COPY_AND_ASSIGN(RootIndexMap); 58 DISALLOW_COPY_AND_ASSIGN(RootIndexMap);
59 }; 59 };
60 60
61 class SerializerReference { 61 class SerializerReference {
62 public: 62 public:
63 explicit SerializerReference(uint32_t bitfield) : bitfield_(bitfield) {}
64 SerializerReference() : bitfield_(Special(kInvalidValue)) {} 63 SerializerReference() : bitfield_(Special(kInvalidValue)) {}
65 64
65 static SerializerReference FromBitfield(uint32_t bitfield) {
66 return SerializerReference(bitfield);
67 }
68
66 static SerializerReference BackReference(AllocationSpace space, 69 static SerializerReference BackReference(AllocationSpace space,
67 uint32_t chunk_index, 70 uint32_t chunk_index,
68 uint32_t chunk_offset) { 71 uint32_t chunk_offset) {
69 DCHECK(IsAligned(chunk_offset, kObjectAlignment)); 72 DCHECK(IsAligned(chunk_offset, kObjectAlignment));
70 DCHECK_NE(LO_SPACE, space); 73 DCHECK_NE(LO_SPACE, space);
71 return SerializerReference( 74 return SerializerReference(
72 SpaceBits::encode(space) | ChunkIndexBits::encode(chunk_index) | 75 SpaceBits::encode(space) | ChunkIndexBits::encode(chunk_index) |
73 ChunkOffsetBits::encode(chunk_offset >> kObjectAlignmentBits)); 76 ChunkOffsetBits::encode(chunk_offset >> kObjectAlignmentBits));
74 } 77 }
75 78
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 bool is_attached_reference() const { 125 bool is_attached_reference() const {
123 return SpaceBits::decode(bitfield_) == kAttachedReferenceSpace; 126 return SpaceBits::decode(bitfield_) == kAttachedReferenceSpace;
124 } 127 }
125 128
126 int attached_reference_index() const { 129 int attached_reference_index() const {
127 DCHECK(is_attached_reference()); 130 DCHECK(is_attached_reference());
128 return ValueIndexBits::decode(bitfield_); 131 return ValueIndexBits::decode(bitfield_);
129 } 132 }
130 133
131 private: 134 private:
135 explicit SerializerReference(uint32_t bitfield) : bitfield_(bitfield) {}
136
132 inline static uint32_t Special(int value) { 137 inline static uint32_t Special(int value) {
133 return SpaceBits::encode(kSpecialValueSpace) | 138 return SpaceBits::encode(kSpecialValueSpace) |
134 ValueIndexBits::encode(value); 139 ValueIndexBits::encode(value);
135 } 140 }
136 141
137 // We use the 32-bit bitfield to encode either a back reference, a special 142 // We use the 32-bit bitfield to encode either a back reference, a special
138 // value, or a attached reference index. 143 // value, or an attached reference index.
139 // Back reference: 144 // Back reference:
140 // [ Space index ] [ Chunk index ] [ Chunk offset ] 145 // [ Space index ] [ Chunk index ] [ Chunk offset ]
141 // [ LO_SPACE ] [ large object index ] 146 // [ LO_SPACE ] [ large object index ]
142 // Special value 147 // Special value
143 // [ kSpecialValueSpace ] [ Special value index ] 148 // [ kSpecialValueSpace ] [ Special value index ]
144 // Attached reference 149 // Attached reference
145 // [ kAttachedReferenceSpace ] [ Attached reference index ] 150 // [ kAttachedReferenceSpace ] [ Attached reference index ]
146 151
147 static const int kChunkOffsetSize = kPageSizeBits - kObjectAlignmentBits; 152 static const int kChunkOffsetSize = kPageSizeBits - kObjectAlignmentBits;
148 static const int kChunkIndexSize = 32 - kChunkOffsetSize - kSpaceTagSize; 153 static const int kChunkIndexSize = 32 - kChunkOffsetSize - kSpaceTagSize;
149 static const int kValueIndexSize = kChunkOffsetSize + kChunkIndexSize; 154 static const int kValueIndexSize = kChunkOffsetSize + kChunkIndexSize;
150 155
151 static const int kSpecialValueSpace = LAST_SPACE + 1; 156 static const int kSpecialValueSpace = LAST_SPACE + 1;
152 static const int kAttachedReferenceSpace = kSpecialValueSpace + 1; 157 static const int kAttachedReferenceSpace = kSpecialValueSpace + 1;
153 STATIC_ASSERT(kAttachedReferenceSpace < (1 << kSpaceTagSize)); 158 STATIC_ASSERT(kAttachedReferenceSpace < (1 << kSpaceTagSize));
154 159
155 static const int kInvalidValue = 0; 160 static const int kInvalidValue = 0;
156 static const int kDummyValue = 1; 161 static const int kDummyValue = 1;
157 162
158 // The chunk offset can also be used to encode the index of special values. 163 // The chunk offset can also be used to encode the index of special values.
159 class ChunkOffsetBits : public BitField<uint32_t, 0, kChunkOffsetSize> {}; 164 class ChunkOffsetBits : public BitField<uint32_t, 0, kChunkOffsetSize> {};
160 class ChunkIndexBits 165 class ChunkIndexBits
161 : public BitField<uint32_t, ChunkOffsetBits::kNext, kChunkIndexSize> {}; 166 : public BitField<uint32_t, ChunkOffsetBits::kNext, kChunkIndexSize> {};
162 class ValueIndexBits : public BitField<uint32_t, 0, kValueIndexSize> {}; 167 class ValueIndexBits : public BitField<uint32_t, 0, kValueIndexSize> {};
168 STATIC_ASSERT(ChunkIndexBits::kNext == ValueIndexBits::kNext);
163 class SpaceBits : public BitField<int, kValueIndexSize, kSpaceTagSize> {}; 169 class SpaceBits : public BitField<int, kValueIndexSize, kSpaceTagSize> {};
164 STATIC_ASSERT(SpaceBits::kNext == 32); 170 STATIC_ASSERT(SpaceBits::kNext == 32);
165 171
166 uint32_t bitfield_; 172 uint32_t bitfield_;
167 173
168 friend class SerializerReferenceMap; 174 friend class SerializerReferenceMap;
169 }; 175 };
170 176
171 // Mapping objects to their location after deserialization. 177 // Mapping objects to their location after deserialization.
172 // This is used during building, but not at runtime by V8. 178 // This is used during building, but not at runtime by V8.
173 class SerializerReferenceMap : public AddressMapBase { 179 class SerializerReferenceMap : public AddressMapBase {
174 public: 180 public:
175 SerializerReferenceMap() 181 SerializerReferenceMap()
176 : no_allocation_(), 182 : no_allocation_(),
177 map_(new HashMap(HashMap::PointersMatch)), 183 map_(HashMap::PointersMatch),
178 attached_reference_index_(0) {} 184 attached_reference_index_(0) {}
179 185
180 ~SerializerReferenceMap() { delete map_; }
181
182 SerializerReference Lookup(HeapObject* obj) { 186 SerializerReference Lookup(HeapObject* obj) {
183 HashMap::Entry* entry = LookupEntry(map_, obj, false); 187 HashMap::Entry* entry = LookupEntry(&map_, obj, false);
184 return entry ? SerializerReference(GetValue(entry)) : SerializerReference(); 188 return entry ? SerializerReference(GetValue(entry)) : SerializerReference();
185 } 189 }
186 190
187 void Add(HeapObject* obj, SerializerReference b) { 191 void Add(HeapObject* obj, SerializerReference b) {
188 DCHECK(b.is_valid()); 192 DCHECK(b.is_valid());
189 DCHECK_NULL(LookupEntry(map_, obj, false)); 193 DCHECK_NULL(LookupEntry(&map_, obj, false));
190 HashMap::Entry* entry = LookupEntry(map_, obj, true); 194 HashMap::Entry* entry = LookupEntry(&map_, obj, true);
191 SetValue(entry, b.bitfield_); 195 SetValue(entry, b.bitfield_);
192 } 196 }
193 197
194 SerializerReference AddAttachedReference(HeapObject* attached_reference) { 198 SerializerReference AddAttachedReference(HeapObject* attached_reference) {
195 SerializerReference reference = 199 SerializerReference reference =
196 SerializerReference::AttachedReference(attached_reference_index_++); 200 SerializerReference::AttachedReference(attached_reference_index_++);
197 Add(attached_reference, reference); 201 Add(attached_reference, reference);
198 return reference; 202 return reference;
199 } 203 }
200 204
201 private: 205 private:
202 DisallowHeapAllocation no_allocation_; 206 DisallowHeapAllocation no_allocation_;
203 HashMap* map_; 207 HashMap map_;
204 int attached_reference_index_; 208 int attached_reference_index_;
205 DISALLOW_COPY_AND_ASSIGN(SerializerReferenceMap); 209 DISALLOW_COPY_AND_ASSIGN(SerializerReferenceMap);
206 }; 210 };
207 211
208 } // namespace internal 212 } // namespace internal
209 } // namespace v8 213 } // namespace v8
210 214
211 #endif // V8_ADDRESS_MAP_H_ 215 #endif // V8_ADDRESS_MAP_H_
OLDNEW
« no previous file with comments | « no previous file | src/snapshot/deserializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698