Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/lookup.h

Issue 1765713003: Reland "Speed up the LookupIterator" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: wrap in assertThrows Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/objects-visiting.cc ('k') | src/lookup.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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_H_ 5 #ifndef V8_LOOKUP_H_
6 #define V8_LOOKUP_H_ 6 #define V8_LOOKUP_H_
7 7
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 29 matching lines...) Expand all
40 DATA, 40 DATA,
41 TRANSITION, 41 TRANSITION,
42 // Set state_ to BEFORE_PROPERTY to ensure that the next lookup will be a 42 // Set state_ to BEFORE_PROPERTY to ensure that the next lookup will be a
43 // PROPERTY lookup. 43 // PROPERTY lookup.
44 BEFORE_PROPERTY = INTERCEPTOR 44 BEFORE_PROPERTY = INTERCEPTOR
45 }; 45 };
46 46
47 LookupIterator(Handle<Object> receiver, Handle<Name> name, 47 LookupIterator(Handle<Object> receiver, Handle<Name> name,
48 Configuration configuration = DEFAULT) 48 Configuration configuration = DEFAULT)
49 : configuration_(ComputeConfiguration(configuration, name)), 49 : configuration_(ComputeConfiguration(configuration, name)),
50 state_(NOT_FOUND),
51 interceptor_state_(InterceptorState::kUninitialized), 50 interceptor_state_(InterceptorState::kUninitialized),
52 property_details_(PropertyDetails::Empty()), 51 property_details_(PropertyDetails::Empty()),
53 isolate_(name->GetIsolate()), 52 isolate_(name->GetIsolate()),
54 name_(isolate_->factory()->InternalizeName(name)), 53 name_(isolate_->factory()->InternalizeName(name)),
55 // kMaxUInt32 isn't a valid index. 54 // kMaxUInt32 isn't a valid index.
56 index_(kMaxUInt32), 55 index_(kMaxUInt32),
57 receiver_(receiver), 56 receiver_(receiver),
58 holder_(GetRoot(isolate_, receiver)), 57 initial_holder_(GetRoot(isolate_, receiver)) {
59 initial_holder_(holder_),
60 number_(DescriptorArray::kNotFound) {
61 #ifdef DEBUG 58 #ifdef DEBUG
62 uint32_t index; // Assert that the name is not an array index. 59 uint32_t index; // Assert that the name is not an array index.
63 DCHECK(!name->AsArrayIndex(&index)); 60 DCHECK(!name->AsArrayIndex(&index));
64 #endif // DEBUG 61 #endif // DEBUG
65 Next(); 62 Start<false>();
66 } 63 }
67 64
68 LookupIterator(Handle<Object> receiver, Handle<Name> name, 65 LookupIterator(Handle<Object> receiver, Handle<Name> name,
69 Handle<JSReceiver> holder, 66 Handle<JSReceiver> holder,
70 Configuration configuration = DEFAULT) 67 Configuration configuration = DEFAULT)
71 : configuration_(ComputeConfiguration(configuration, name)), 68 : configuration_(ComputeConfiguration(configuration, name)),
72 state_(NOT_FOUND),
73 interceptor_state_(InterceptorState::kUninitialized), 69 interceptor_state_(InterceptorState::kUninitialized),
74 property_details_(PropertyDetails::Empty()), 70 property_details_(PropertyDetails::Empty()),
75 isolate_(name->GetIsolate()), 71 isolate_(name->GetIsolate()),
76 name_(isolate_->factory()->InternalizeName(name)), 72 name_(isolate_->factory()->InternalizeName(name)),
77 // kMaxUInt32 isn't a valid index. 73 // kMaxUInt32 isn't a valid index.
78 index_(kMaxUInt32), 74 index_(kMaxUInt32),
79 receiver_(receiver), 75 receiver_(receiver),
80 holder_(holder), 76 initial_holder_(holder) {
81 initial_holder_(holder_),
82 number_(DescriptorArray::kNotFound) {
83 #ifdef DEBUG 77 #ifdef DEBUG
84 uint32_t index; // Assert that the name is not an array index. 78 uint32_t index; // Assert that the name is not an array index.
85 DCHECK(!name->AsArrayIndex(&index)); 79 DCHECK(!name->AsArrayIndex(&index));
86 #endif // DEBUG 80 #endif // DEBUG
87 Next(); 81 Start<false>();
88 } 82 }
89 83
90 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, 84 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index,
91 Configuration configuration = DEFAULT) 85 Configuration configuration = DEFAULT)
92 : configuration_(configuration), 86 : configuration_(configuration),
93 state_(NOT_FOUND),
94 interceptor_state_(InterceptorState::kUninitialized), 87 interceptor_state_(InterceptorState::kUninitialized),
95 property_details_(PropertyDetails::Empty()), 88 property_details_(PropertyDetails::Empty()),
96 isolate_(isolate), 89 isolate_(isolate),
97 name_(), 90 name_(),
98 index_(index), 91 index_(index),
99 receiver_(receiver), 92 receiver_(receiver),
100 holder_(GetRoot(isolate, receiver, index)), 93 initial_holder_(GetRoot(isolate, receiver, index)) {
101 initial_holder_(holder_),
102 number_(DescriptorArray::kNotFound) {
103 // kMaxUInt32 isn't a valid index. 94 // kMaxUInt32 isn't a valid index.
104 DCHECK_NE(kMaxUInt32, index_); 95 DCHECK_NE(kMaxUInt32, index_);
105 Next(); 96 Start<true>();
106 } 97 }
107 98
108 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, 99 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index,
109 Handle<JSReceiver> holder, 100 Handle<JSReceiver> holder,
110 Configuration configuration = DEFAULT) 101 Configuration configuration = DEFAULT)
111 : configuration_(configuration), 102 : configuration_(configuration),
112 state_(NOT_FOUND),
113 interceptor_state_(InterceptorState::kUninitialized), 103 interceptor_state_(InterceptorState::kUninitialized),
114 property_details_(PropertyDetails::Empty()), 104 property_details_(PropertyDetails::Empty()),
115 isolate_(isolate), 105 isolate_(isolate),
116 name_(), 106 name_(),
117 index_(index), 107 index_(index),
118 receiver_(receiver), 108 receiver_(receiver),
119 holder_(holder), 109 initial_holder_(holder) {
120 initial_holder_(holder_),
121 number_(DescriptorArray::kNotFound) {
122 // kMaxUInt32 isn't a valid index. 110 // kMaxUInt32 isn't a valid index.
123 DCHECK_NE(kMaxUInt32, index_); 111 DCHECK_NE(kMaxUInt32, index_);
124 Next(); 112 Start<true>();
125 } 113 }
126 114
127 static LookupIterator PropertyOrElement( 115 static LookupIterator PropertyOrElement(
128 Isolate* isolate, Handle<Object> receiver, Handle<Name> name, 116 Isolate* isolate, Handle<Object> receiver, Handle<Name> name,
129 Configuration configuration = DEFAULT) { 117 Configuration configuration = DEFAULT) {
130 uint32_t index; 118 uint32_t index;
131 if (name->AsArrayIndex(&index)) { 119 if (name->AsArrayIndex(&index)) {
132 LookupIterator it = 120 LookupIterator it =
133 LookupIterator(isolate, receiver, index, configuration); 121 LookupIterator(isolate, receiver, index, configuration);
134 it.name_ = name; 122 it.name_ = name;
(...skipping 12 matching lines...) Expand all
147 it.name_ = name; 135 it.name_ = name;
148 return it; 136 return it;
149 } 137 }
150 return LookupIterator(receiver, name, holder, configuration); 138 return LookupIterator(receiver, name, holder, configuration);
151 } 139 }
152 140
153 static LookupIterator PropertyOrElement( 141 static LookupIterator PropertyOrElement(
154 Isolate* isolate, Handle<Object> receiver, Handle<Object> key, 142 Isolate* isolate, Handle<Object> receiver, Handle<Object> key,
155 bool* success, Configuration configuration = DEFAULT); 143 bool* success, Configuration configuration = DEFAULT);
156 144
157 void Restart() { RestartInternal(InterceptorState::kUninitialized); } 145 void Restart() {
146 InterceptorState state = InterceptorState::kUninitialized;
147 IsElement() ? RestartInternal<true>(state) : RestartInternal<false>(state);
148 }
158 149
159 Isolate* isolate() const { return isolate_; } 150 Isolate* isolate() const { return isolate_; }
160 State state() const { return state_; } 151 State state() const { return state_; }
161 152
162 Handle<Name> name() const { 153 Handle<Name> name() const {
163 DCHECK(!IsElement()); 154 DCHECK(!IsElement());
164 return name_; 155 return name_;
165 } 156 }
166 Handle<Name> GetName() { 157 Handle<Name> GetName() {
167 if (name_.is_null()) { 158 if (name_.is_null()) {
168 DCHECK(IsElement()); 159 DCHECK(IsElement());
169 name_ = factory()->Uint32ToString(index_); 160 name_ = factory()->Uint32ToString(index_);
170 } 161 }
171 return name_; 162 return name_;
172 } 163 }
173 uint32_t index() const { return index_; } 164 uint32_t index() const { return index_; }
174 165
175 bool IsElement() const { return index_ != kMaxUInt32; } 166 bool IsElement() const { return index_ != kMaxUInt32; }
176 167
177 bool IsFound() const { return state_ != NOT_FOUND; } 168 bool IsFound() const { return state_ != NOT_FOUND; }
178 void Next(); 169 void Next();
179 void NotFound() { 170 void NotFound() {
180 has_property_ = false; 171 has_property_ = false;
181 state_ = NOT_FOUND; 172 state_ = NOT_FOUND;
182 } 173 }
183 174
184 Heap* heap() const { return isolate_->heap(); } 175 Heap* heap() const { return isolate_->heap(); }
185 Factory* factory() const { return isolate_->factory(); } 176 Factory* factory() const { return isolate_->factory(); }
186 Handle<Object> GetReceiver() const { return receiver_; } 177 Handle<Object> GetReceiver() const { return receiver_; }
187 Handle<JSObject> GetStoreTarget() const; 178
179 Handle<JSObject> GetStoreTarget() const {
180 if (receiver_->IsJSGlobalProxy()) {
181 Map* map = JSGlobalProxy::cast(*receiver_)->map();
182 if (map->has_hidden_prototype()) {
183 return handle(JSGlobalObject::cast(map->prototype()), isolate_);
184 }
185 }
186 return Handle<JSObject>::cast(receiver_);
187 }
188
188 bool is_dictionary_holder() const { return !holder_->HasFastProperties(); } 189 bool is_dictionary_holder() const { return !holder_->HasFastProperties(); }
189 Handle<Map> transition_map() const { 190 Handle<Map> transition_map() const {
190 DCHECK_EQ(TRANSITION, state_); 191 DCHECK_EQ(TRANSITION, state_);
191 return Handle<Map>::cast(transition_); 192 return Handle<Map>::cast(transition_);
192 } 193 }
193 template <class T> 194 template <class T>
194 Handle<T> GetHolder() const { 195 Handle<T> GetHolder() const {
195 DCHECK(IsFound()); 196 DCHECK(IsFound());
196 return Handle<T>::cast(holder_); 197 return Handle<T>::cast(holder_);
197 } 198 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 int GetAccessorIndex() const; 250 int GetAccessorIndex() const;
250 int GetConstantIndex() const; 251 int GetConstantIndex() const;
251 Handle<PropertyCell> GetPropertyCell() const; 252 Handle<PropertyCell> GetPropertyCell() const;
252 Handle<Object> GetAccessors() const; 253 Handle<Object> GetAccessors() const;
253 inline Handle<InterceptorInfo> GetInterceptor() const { 254 inline Handle<InterceptorInfo> GetInterceptor() const {
254 DCHECK_EQ(INTERCEPTOR, state_); 255 DCHECK_EQ(INTERCEPTOR, state_);
255 return handle(GetInterceptor(JSObject::cast(*holder_)), isolate_); 256 return handle(GetInterceptor(JSObject::cast(*holder_)), isolate_);
256 } 257 }
257 Handle<Object> GetDataValue() const; 258 Handle<Object> GetDataValue() const;
258 void WriteDataValue(Handle<Object> value); 259 void WriteDataValue(Handle<Object> value);
259 void UpdateProtector(); 260 inline void UpdateProtector() {
261 if (FLAG_harmony_species && !IsElement() &&
262 (*name_ == heap()->constructor_string() ||
263 *name_ == heap()->species_symbol())) {
264 InternalUpdateProtector();
265 }
266 }
260 267
261 private: 268 private:
269 void InternalUpdateProtector();
270
262 enum class InterceptorState { 271 enum class InterceptorState {
263 kUninitialized, 272 kUninitialized,
264 kSkipNonMasking, 273 kSkipNonMasking,
265 kProcessNonMasking 274 kProcessNonMasking
266 }; 275 };
267 276
268 Handle<Map> GetReceiverMap() const; 277 Handle<Map> GetReceiverMap() const;
269 278
270 MUST_USE_RESULT inline JSReceiver* NextHolder(Map* map); 279 MUST_USE_RESULT inline JSReceiver* NextHolder(Map* map);
271 inline State LookupInHolder(Map* map, JSReceiver* holder); 280
281 template <bool is_element>
282 void Start();
283 template <bool is_element>
284 void NextInternal(Map* map, JSReceiver* holder);
285 template <bool is_element>
286 inline State LookupInHolder(Map* map, JSReceiver* holder) {
287 return map->instance_type() <= LAST_SPECIAL_RECEIVER_TYPE
288 ? LookupInSpecialHolder<is_element>(map, holder)
289 : LookupInRegularHolder<is_element>(map, holder);
290 }
291 template <bool is_element>
292 State LookupInRegularHolder(Map* map, JSReceiver* holder);
293 template <bool is_element>
294 State LookupInSpecialHolder(Map* map, JSReceiver* holder);
295 template <bool is_element>
272 void RestartLookupForNonMaskingInterceptors() { 296 void RestartLookupForNonMaskingInterceptors() {
273 RestartInternal(InterceptorState::kProcessNonMasking); 297 RestartInternal<is_element>(InterceptorState::kProcessNonMasking);
274 } 298 }
299 template <bool is_element>
275 void RestartInternal(InterceptorState interceptor_state); 300 void RestartInternal(InterceptorState interceptor_state);
276 State LookupNonMaskingInterceptorInHolder(Map* map, JSReceiver* holder);
277 Handle<Object> FetchValue() const; 301 Handle<Object> FetchValue() const;
302 template <bool is_element>
278 void ReloadPropertyInformation(); 303 void ReloadPropertyInformation();
304
279 inline bool SkipInterceptor(JSObject* holder); 305 inline bool SkipInterceptor(JSObject* holder);
280 bool HasInterceptor(Map* map) const;
281 inline InterceptorInfo* GetInterceptor(JSObject* holder) const { 306 inline InterceptorInfo* GetInterceptor(JSObject* holder) const {
282 if (IsElement()) return holder->GetIndexedInterceptor(); 307 if (IsElement()) return holder->GetIndexedInterceptor();
283 return holder->GetNamedInterceptor(); 308 return holder->GetNamedInterceptor();
284 } 309 }
285 310
286 bool check_hidden() const { return (configuration_ & kHidden) != 0; } 311 bool check_hidden() const { return (configuration_ & kHidden) != 0; }
287 bool check_interceptor() const { 312 bool check_interceptor() const {
288 return (configuration_ & kInterceptor) != 0; 313 return (configuration_ & kInterceptor) != 0;
289 } 314 }
290 int descriptor_number() const { 315 int descriptor_number() const {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 Handle<JSReceiver> holder_; 363 Handle<JSReceiver> holder_;
339 const Handle<JSReceiver> initial_holder_; 364 const Handle<JSReceiver> initial_holder_;
340 uint32_t number_; 365 uint32_t number_;
341 }; 366 };
342 367
343 368
344 } // namespace internal 369 } // namespace internal
345 } // namespace v8 370 } // namespace v8
346 371
347 #endif // V8_LOOKUP_H_ 372 #endif // V8_LOOKUP_H_
OLDNEW
« no previous file with comments | « src/heap/objects-visiting.cc ('k') | src/lookup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698