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

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

Issue 2010243003: Move hashmap into base/. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 6 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 | « BUILD.gn ('k') | src/address-map.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/base/hashmap.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 class AddressMapBase { 15 class AddressMapBase {
16 protected: 16 protected:
17 static void SetValue(HashMap::Entry* entry, uint32_t v) { 17 static void SetValue(base::HashMap::Entry* entry, uint32_t v) {
18 entry->value = reinterpret_cast<void*>(v); 18 entry->value = reinterpret_cast<void*>(v);
19 } 19 }
20 20
21 static uint32_t GetValue(HashMap::Entry* entry) { 21 static uint32_t GetValue(base::HashMap::Entry* entry) {
22 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value)); 22 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value));
23 } 23 }
24 24
25 inline static HashMap::Entry* LookupEntry(HashMap* map, HeapObject* obj, 25 inline static base::HashMap::Entry* LookupEntry(base::HashMap* map,
26 bool insert) { 26 HeapObject* obj,
27 bool insert) {
27 if (insert) { 28 if (insert) {
28 map->LookupOrInsert(Key(obj), Hash(obj)); 29 map->LookupOrInsert(Key(obj), Hash(obj));
29 } 30 }
30 return map->Lookup(Key(obj), Hash(obj)); 31 return map->Lookup(Key(obj), Hash(obj));
31 } 32 }
32 33
33 private: 34 private:
34 static uint32_t Hash(HeapObject* obj) { 35 static uint32_t Hash(HeapObject* obj) {
35 return static_cast<int32_t>(reinterpret_cast<intptr_t>(obj->address())); 36 return static_cast<int32_t>(reinterpret_cast<intptr_t>(obj->address()));
36 } 37 }
37 38
38 static void* Key(HeapObject* obj) { 39 static void* Key(HeapObject* obj) {
39 return reinterpret_cast<void*>(obj->address()); 40 return reinterpret_cast<void*>(obj->address());
40 } 41 }
41 }; 42 };
42 43
43 class RootIndexMap : public AddressMapBase { 44 class RootIndexMap : public AddressMapBase {
44 public: 45 public:
45 explicit RootIndexMap(Isolate* isolate); 46 explicit RootIndexMap(Isolate* isolate);
46 47
47 static const int kInvalidRootIndex = -1; 48 static const int kInvalidRootIndex = -1;
48 49
49 int Lookup(HeapObject* obj) { 50 int Lookup(HeapObject* obj) {
50 HashMap::Entry* entry = LookupEntry(map_, obj, false); 51 base::HashMap::Entry* entry = LookupEntry(map_, obj, false);
51 if (entry) return GetValue(entry); 52 if (entry) return GetValue(entry);
52 return kInvalidRootIndex; 53 return kInvalidRootIndex;
53 } 54 }
54 55
55 private: 56 private:
56 HashMap* map_; 57 base::HashMap* map_;
57 58
58 DISALLOW_COPY_AND_ASSIGN(RootIndexMap); 59 DISALLOW_COPY_AND_ASSIGN(RootIndexMap);
59 }; 60 };
60 61
61 class SerializerReference { 62 class SerializerReference {
62 public: 63 public:
63 SerializerReference() : bitfield_(Special(kInvalidValue)) {} 64 SerializerReference() : bitfield_(Special(kInvalidValue)) {}
64 65
65 static SerializerReference FromBitfield(uint32_t bitfield) { 66 static SerializerReference FromBitfield(uint32_t bitfield) {
66 return SerializerReference(bitfield); 67 return SerializerReference(bitfield);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 174
174 friend class SerializerReferenceMap; 175 friend class SerializerReferenceMap;
175 }; 176 };
176 177
177 // Mapping objects to their location after deserialization. 178 // Mapping objects to their location after deserialization.
178 // This is used during building, but not at runtime by V8. 179 // This is used during building, but not at runtime by V8.
179 class SerializerReferenceMap : public AddressMapBase { 180 class SerializerReferenceMap : public AddressMapBase {
180 public: 181 public:
181 SerializerReferenceMap() 182 SerializerReferenceMap()
182 : no_allocation_(), 183 : no_allocation_(),
183 map_(HashMap::PointersMatch), 184 map_(base::HashMap::PointersMatch),
184 attached_reference_index_(0) {} 185 attached_reference_index_(0) {}
185 186
186 SerializerReference Lookup(HeapObject* obj) { 187 SerializerReference Lookup(HeapObject* obj) {
187 HashMap::Entry* entry = LookupEntry(&map_, obj, false); 188 base::HashMap::Entry* entry = LookupEntry(&map_, obj, false);
188 return entry ? SerializerReference(GetValue(entry)) : SerializerReference(); 189 return entry ? SerializerReference(GetValue(entry)) : SerializerReference();
189 } 190 }
190 191
191 void Add(HeapObject* obj, SerializerReference b) { 192 void Add(HeapObject* obj, SerializerReference b) {
192 DCHECK(b.is_valid()); 193 DCHECK(b.is_valid());
193 DCHECK_NULL(LookupEntry(&map_, obj, false)); 194 DCHECK_NULL(LookupEntry(&map_, obj, false));
194 HashMap::Entry* entry = LookupEntry(&map_, obj, true); 195 base::HashMap::Entry* entry = LookupEntry(&map_, obj, true);
195 SetValue(entry, b.bitfield_); 196 SetValue(entry, b.bitfield_);
196 } 197 }
197 198
198 SerializerReference AddAttachedReference(HeapObject* attached_reference) { 199 SerializerReference AddAttachedReference(HeapObject* attached_reference) {
199 SerializerReference reference = 200 SerializerReference reference =
200 SerializerReference::AttachedReference(attached_reference_index_++); 201 SerializerReference::AttachedReference(attached_reference_index_++);
201 Add(attached_reference, reference); 202 Add(attached_reference, reference);
202 return reference; 203 return reference;
203 } 204 }
204 205
205 private: 206 private:
206 DisallowHeapAllocation no_allocation_; 207 DisallowHeapAllocation no_allocation_;
207 HashMap map_; 208 base::HashMap map_;
208 int attached_reference_index_; 209 int attached_reference_index_;
209 DISALLOW_COPY_AND_ASSIGN(SerializerReferenceMap); 210 DISALLOW_COPY_AND_ASSIGN(SerializerReferenceMap);
210 }; 211 };
211 212
212 } // namespace internal 213 } // namespace internal
213 } // namespace v8 214 } // namespace v8
214 215
215 #endif // V8_ADDRESS_MAP_H_ 216 #endif // V8_ADDRESS_MAP_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/address-map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698