| OLD | NEW |
| 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 Loading... |
| 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_ |
| OLD | NEW |