OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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_LOOKUP_CACHE_H_ | 5 #ifndef V8_LOOKUP_CACHE_H_ |
6 #define V8_LOOKUP_CACHE_H_ | 6 #define V8_LOOKUP_CACHE_H_ |
7 | 7 |
8 #include "src/objects.h" | 8 #include "src/objects.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 Name* name; | 45 Name* name; |
46 }; | 46 }; |
47 | 47 |
48 Key keys_[kLength]; | 48 Key keys_[kLength]; |
49 int results_[kLength]; | 49 int results_[kLength]; |
50 | 50 |
51 friend class Isolate; | 51 friend class Isolate; |
52 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); | 52 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); |
53 }; | 53 }; |
54 | 54 |
55 // Cache for mapping (map, property name) into field offset. | |
56 // Cleared at startup and prior to mark sweep collection. | |
57 class KeyedLookupCache { | |
58 public: | |
59 // Lookup field offset for (map, name). If absent, -1 is returned. | |
60 int Lookup(Handle<Map> map, Handle<Name> name); | |
61 | |
62 // Update an element in the cache. | |
63 void Update(Handle<Map> map, Handle<Name> name, int field_offset); | |
64 | |
65 // Clear the cache. | |
66 void Clear(); | |
67 | |
68 static const int kLength = 256; | |
69 static const int kCapacityMask = kLength - 1; | |
70 static const int kMapHashShift = 5; | |
71 static const int kHashMask = -4; // Zero the last two bits. | |
72 static const int kEntriesPerBucket = 4; | |
73 static const int kEntryLength = 2; | |
74 static const int kMapIndex = 0; | |
75 static const int kKeyIndex = 1; | |
76 static const int kNotFound = -1; | |
77 | |
78 // kEntriesPerBucket should be a power of 2. | |
79 STATIC_ASSERT((kEntriesPerBucket & (kEntriesPerBucket - 1)) == 0); | |
80 STATIC_ASSERT(kEntriesPerBucket == -kHashMask); | |
81 | |
82 private: | |
83 KeyedLookupCache() { | |
84 for (int i = 0; i < kLength; ++i) { | |
85 keys_[i].map = NULL; | |
86 keys_[i].name = NULL; | |
87 field_offsets_[i] = kNotFound; | |
88 } | |
89 } | |
90 | |
91 static inline int Hash(Handle<Map> map, Handle<Name> name); | |
92 | |
93 // Get the address of the keys and field_offsets arrays. Used in | |
94 // generated code to perform cache lookups. | |
95 Address keys_address() { return reinterpret_cast<Address>(&keys_); } | |
96 | |
97 Address field_offsets_address() { | |
98 return reinterpret_cast<Address>(&field_offsets_); | |
99 } | |
100 | |
101 struct Key { | |
102 Map* map; | |
103 Name* name; | |
104 }; | |
105 | |
106 Key keys_[kLength]; | |
107 int field_offsets_[kLength]; | |
108 | |
109 friend class ExternalReference; | |
110 friend class Isolate; | |
111 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache); | |
112 }; | |
113 | |
114 } // namespace internal | 55 } // namespace internal |
115 } // namespace v8 | 56 } // namespace v8 |
116 | 57 |
117 #endif // V8_LOOKUP_CACHE_H_ | 58 #endif // V8_LOOKUP_CACHE_H_ |
OLD | NEW |