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 #include "src/identity-map.h" | 5 #include "src/identity-map.h" |
6 | 6 |
7 #include "src/heap/heap.h" | 7 #include "src/base/functional.h" |
8 #include "src/heap/heap-inl.h" | 8 #include "src/heap/heap-inl.h" |
9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 static const int kInitialIdentityMapSize = 4; | 14 static const int kInitialIdentityMapSize = 4; |
15 static const int kResizeFactor = 4; | 15 static const int kResizeFactor = 4; |
16 | 16 |
17 IdentityMapBase::~IdentityMapBase() { Clear(); } | 17 IdentityMapBase::~IdentityMapBase() { Clear(); } |
(...skipping 17 matching lines...) Expand all Loading... | |
35 IdentityMapBase::RawEntry IdentityMapBase::Insert(Object* key) { | 35 IdentityMapBase::RawEntry IdentityMapBase::Insert(Object* key) { |
36 int index = InsertIndex(key); | 36 int index = InsertIndex(key); |
37 DCHECK_GE(index, 0); | 37 DCHECK_GE(index, 0); |
38 return &values_[index]; | 38 return &values_[index]; |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 int IdentityMapBase::Hash(Object* address) { | 42 int IdentityMapBase::Hash(Object* address) { |
43 CHECK_NE(address, heap_->not_mapped_symbol()); | 43 CHECK_NE(address, heap_->not_mapped_symbol()); |
44 uintptr_t raw_address = reinterpret_cast<uintptr_t>(address); | 44 uintptr_t raw_address = reinterpret_cast<uintptr_t>(address); |
45 // Xor some of the upper bits, since the lower 2 or 3 are usually aligned. | 45 return static_cast<int>(hasher_(raw_address)); |
titzer
2016/02/16 13:02:27
What about the original comment? Objects will typi
rmcilroy
2016/02/16 14:00:55
It uses 64-bit mix functions: https://gist.github.
| |
46 return static_cast<int>((raw_address >> 11) ^ raw_address); | |
47 } | 46 } |
48 | 47 |
49 | 48 |
50 int IdentityMapBase::LookupIndex(Object* address) { | 49 int IdentityMapBase::LookupIndex(Object* address) { |
51 int start = Hash(address) & mask_; | 50 int start = Hash(address) & mask_; |
52 Object* not_mapped = heap_->not_mapped_symbol(); | 51 Object* not_mapped = heap_->not_mapped_symbol(); |
53 for (int index = start; index < size_; index++) { | 52 for (int index = start; index < size_; index++) { |
54 if (keys_[index] == address) return index; // Found. | 53 if (keys_[index] == address) return index; // Found. |
55 if (keys_[index] == not_mapped) return -1; // Not found. | 54 if (keys_[index] == not_mapped) return -1; // Not found. |
56 } | 55 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 DCHECK_GE(index, 0); | 187 DCHECK_GE(index, 0); |
189 values_[index] = old_values[i]; | 188 values_[index] = old_values[i]; |
190 } | 189 } |
191 | 190 |
192 // Unregister old keys and register new keys. | 191 // Unregister old keys and register new keys. |
193 heap_->UnregisterStrongRoots(old_keys); | 192 heap_->UnregisterStrongRoots(old_keys); |
194 heap_->RegisterStrongRoots(keys_, keys_ + size_); | 193 heap_->RegisterStrongRoots(keys_, keys_ + size_); |
195 } | 194 } |
196 } // namespace internal | 195 } // namespace internal |
197 } // namespace v8 | 196 } // namespace v8 |
OLD | NEW |