OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_STUB_CACHE_H_ | 5 #ifndef V8_STUB_CACHE_H_ |
6 #define V8_STUB_CACHE_H_ | 6 #define V8_STUB_CACHE_H_ |
7 | 7 |
8 #include "src/macro-assembler.h" | 8 #include "src/macro-assembler.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return NULL; | 85 return NULL; |
86 } | 86 } |
87 | 87 |
88 Isolate* isolate() { return isolate_; } | 88 Isolate* isolate() { return isolate_; } |
89 | 89 |
90 // Setting the entry size such that the index is shifted by Name::kHashShift | 90 // Setting the entry size such that the index is shifted by Name::kHashShift |
91 // is convenient; shifting down the length field (to extract the hash code) | 91 // is convenient; shifting down the length field (to extract the hash code) |
92 // automatically discards the hash bit field. | 92 // automatically discards the hash bit field. |
93 static const int kCacheIndexShift = Name::kHashShift; | 93 static const int kCacheIndexShift = Name::kHashShift; |
94 | 94 |
95 private: | 95 static const int kPrimaryTableBits = 11; |
| 96 static const int kPrimaryTableSize = (1 << kPrimaryTableBits); |
| 97 static const int kSecondaryTableBits = 9; |
| 98 static const int kSecondaryTableSize = (1 << kSecondaryTableBits); |
| 99 |
| 100 static int PrimaryOffsetForTesting(Name* name, Code::Flags flags, Map* map) { |
| 101 return PrimaryOffset(name, flags, map); |
| 102 } |
| 103 |
| 104 static int SecondaryOffsetForTesting(Name* name, Code::Flags flags, |
| 105 int seed) { |
| 106 return SecondaryOffset(name, flags, seed); |
| 107 } |
| 108 |
| 109 // The constructor is made public only for the purposes of testing. |
96 explicit StubCache(Isolate* isolate); | 110 explicit StubCache(Isolate* isolate); |
97 | 111 |
| 112 private: |
98 // The stub cache has a primary and secondary level. The two levels have | 113 // The stub cache has a primary and secondary level. The two levels have |
99 // different hashing algorithms in order to avoid simultaneous collisions | 114 // different hashing algorithms in order to avoid simultaneous collisions |
100 // in both caches. Unlike a probing strategy (quadratic or otherwise) the | 115 // in both caches. Unlike a probing strategy (quadratic or otherwise) the |
101 // update strategy on updates is fairly clear and simple: Any existing entry | 116 // update strategy on updates is fairly clear and simple: Any existing entry |
102 // in the primary cache is moved to the secondary cache, and secondary cache | 117 // in the primary cache is moved to the secondary cache, and secondary cache |
103 // entries are overwritten. | 118 // entries are overwritten. |
104 | 119 |
105 // Hash algorithm for the primary table. This algorithm is replicated in | 120 // Hash algorithm for the primary table. This algorithm is replicated in |
106 // assembler for every architecture. Returns an index into the table that | 121 // assembler for every architecture. Returns an index into the table that |
107 // is scaled by 1 << kCacheIndexShift. | 122 // is scaled by 1 << kCacheIndexShift. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // we do in generated code. We generate an hash code that already | 158 // we do in generated code. We generate an hash code that already |
144 // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple | 159 // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple |
145 // of sizeof(Entry). This makes it easier to avoid making mistakes | 160 // of sizeof(Entry). This makes it easier to avoid making mistakes |
146 // in the hashed offset computations. | 161 // in the hashed offset computations. |
147 static Entry* entry(Entry* table, int offset) { | 162 static Entry* entry(Entry* table, int offset) { |
148 const int multiplier = sizeof(*table) >> Name::kHashShift; | 163 const int multiplier = sizeof(*table) >> Name::kHashShift; |
149 return reinterpret_cast<Entry*>(reinterpret_cast<Address>(table) + | 164 return reinterpret_cast<Entry*>(reinterpret_cast<Address>(table) + |
150 offset * multiplier); | 165 offset * multiplier); |
151 } | 166 } |
152 | 167 |
153 static const int kPrimaryTableBits = 11; | |
154 static const int kPrimaryTableSize = (1 << kPrimaryTableBits); | |
155 static const int kSecondaryTableBits = 9; | |
156 static const int kSecondaryTableSize = (1 << kSecondaryTableBits); | |
157 | |
158 private: | 168 private: |
159 Entry primary_[kPrimaryTableSize]; | 169 Entry primary_[kPrimaryTableSize]; |
160 Entry secondary_[kSecondaryTableSize]; | 170 Entry secondary_[kSecondaryTableSize]; |
161 Isolate* isolate_; | 171 Isolate* isolate_; |
162 | 172 |
163 friend class Isolate; | 173 friend class Isolate; |
164 friend class SCTableReference; | 174 friend class SCTableReference; |
165 | 175 |
166 DISALLOW_COPY_AND_ASSIGN(StubCache); | 176 DISALLOW_COPY_AND_ASSIGN(StubCache); |
167 }; | 177 }; |
168 } // namespace internal | 178 } // namespace internal |
169 } // namespace v8 | 179 } // namespace v8 |
170 | 180 |
171 #endif // V8_STUB_CACHE_H_ | 181 #endif // V8_STUB_CACHE_H_ |
OLD | NEW |