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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/heap/heap.h" | 7 #include "src/heap/heap.h" |
8 #include "src/heap/identity-map.h" | 8 #include "src/heap/identity-map.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 20 matching lines...) Expand all Loading... |
31 IdentityMapBase::RawEntry IdentityMapBase::Insert(Handle<Object> key) { | 31 IdentityMapBase::RawEntry IdentityMapBase::Insert(Handle<Object> key) { |
32 AllowHandleDereference for_lookup; | 32 AllowHandleDereference for_lookup; |
33 int index = InsertIndex(*key); | 33 int index = InsertIndex(*key); |
34 DCHECK_GE(index, 0); | 34 DCHECK_GE(index, 0); |
35 return &values_[index]; | 35 return &values_[index]; |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 int IdentityMapBase::Hash(Object* address) { | 39 int IdentityMapBase::Hash(Object* address) { |
40 uintptr_t raw_address = reinterpret_cast<uintptr_t>(address); | 40 uintptr_t raw_address = reinterpret_cast<uintptr_t>(address); |
41 CHECK_NE(0, raw_address); // Cannot store Smi 0 as a key here, sorry. | 41 CHECK_NE(0U, raw_address); // Cannot store Smi 0 as a key here, sorry. |
42 // Xor some of the upper bits, since the lower 2 or 3 are usually aligned. | 42 // Xor some of the upper bits, since the lower 2 or 3 are usually aligned. |
43 return static_cast<int>((raw_address >> 11) ^ raw_address); | 43 return static_cast<int>((raw_address >> 11) ^ raw_address); |
44 } | 44 } |
45 | 45 |
46 | 46 |
47 int IdentityMapBase::LookupIndex(Object* address) { | 47 int IdentityMapBase::LookupIndex(Object* address) { |
48 int start = Hash(address) & mask_; | 48 int start = Hash(address) & mask_; |
49 for (int index = start; index < size_; index++) { | 49 for (int index = start; index < size_; index++) { |
50 if (keys_[index] == address) return index; // Found. | 50 if (keys_[index] == address) return index; // Found. |
51 if (keys_[index] == nullptr) return -1; // Not found. | 51 if (keys_[index] == nullptr) return -1; // Not found. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 DCHECK_GE(index, 0); | 182 DCHECK_GE(index, 0); |
183 values_[index] = old_values[i]; | 183 values_[index] = old_values[i]; |
184 } | 184 } |
185 | 185 |
186 // Unregister old keys and register new keys. | 186 // Unregister old keys and register new keys. |
187 heap_->UnregisterStrongRoots(old_keys); | 187 heap_->UnregisterStrongRoots(old_keys); |
188 heap_->RegisterStrongRoots(keys_, keys_ + size_); | 188 heap_->RegisterStrongRoots(keys_, keys_ + size_); |
189 } | 189 } |
190 } | 190 } |
191 } // namespace v8::internal | 191 } // namespace v8::internal |
OLD | NEW |