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

Side by Side Diff: src/transitions-inl.h

Issue 793453004: Reland of "TransitionArray now uses <is_data_property, name, attributes> tuple as a key, which allo… (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Post-rebase fixes Created 6 years 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/transitions.cc ('k') | test/cctest/cctest.gyp » ('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 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_TRANSITIONS_INL_H_ 5 #ifndef V8_TRANSITIONS_INL_H_
6 #define V8_TRANSITIONS_INL_H_ 6 #define V8_TRANSITIONS_INL_H_
7 7
8 #include "src/transitions.h" 8 #include "src/transitions.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 28
29 29
30 TransitionArray* TransitionArray::cast(Object* object) { 30 TransitionArray* TransitionArray::cast(Object* object) {
31 DCHECK(object->IsTransitionArray()); 31 DCHECK(object->IsTransitionArray());
32 return reinterpret_cast<TransitionArray*>(object); 32 return reinterpret_cast<TransitionArray*>(object);
33 } 33 }
34 34
35 35
36 bool TransitionArray::HasElementsTransition() { 36 bool TransitionArray::HasElementsTransition() {
37 return Search(GetHeap()->elements_transition_symbol()) != kNotFound; 37 return SearchSpecial(GetHeap()->elements_transition_symbol()) != kNotFound;
38 } 38 }
39 39
40 40
41 Object* TransitionArray::back_pointer_storage() { 41 Object* TransitionArray::back_pointer_storage() {
42 return get(kBackPointerStorageIndex); 42 return get(kBackPointerStorageIndex);
43 } 43 }
44 44
45 45
46 void TransitionArray::set_back_pointer_storage(Object* back_pointer, 46 void TransitionArray::set_back_pointer_storage(Object* back_pointer,
47 WriteBarrierMode mode) { 47 WriteBarrierMode mode) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return map->GetLastDescriptorDetails(); 133 return map->GetLastDescriptorDetails();
134 } 134 }
135 135
136 136
137 Object* TransitionArray::GetTargetValue(int transition_number) { 137 Object* TransitionArray::GetTargetValue(int transition_number) {
138 Map* map = GetTarget(transition_number); 138 Map* map = GetTarget(transition_number);
139 return map->instance_descriptors()->GetValue(map->LastAdded()); 139 return map->instance_descriptors()->GetValue(map->LastAdded());
140 } 140 }
141 141
142 142
143 int TransitionArray::Search(Name* name, int* out_insertion_index) { 143 int TransitionArray::SearchName(Name* name, int* out_insertion_index) {
144 if (IsSimpleTransition()) { 144 if (IsSimpleTransition()) {
145 Name* key = GetKey(kSimpleTransitionIndex); 145 Name* key = GetKey(kSimpleTransitionIndex);
146 if (key->Equals(name)) return kSimpleTransitionIndex; 146 if (key->Equals(name)) return kSimpleTransitionIndex;
147 if (out_insertion_index != NULL) { 147 if (out_insertion_index != NULL) {
148 *out_insertion_index = key->Hash() > name->Hash() ? 0 : 1; 148 *out_insertion_index = key->Hash() > name->Hash() ? 0 : 1;
149 } 149 }
150 return kNotFound; 150 return kNotFound;
151 } 151 }
152 return internal::Search<ALL_ENTRIES>(this, name, 0, out_insertion_index); 152 return internal::Search<ALL_ENTRIES>(this, name, 0, out_insertion_index);
153 } 153 }
154 154
155 155
156 #ifdef DEBUG
157 bool TransitionArray::IsSpecialTransition(Name* name) {
158 if (!name->IsSymbol()) return false;
159 Heap* heap = name->GetHeap();
160 return name == heap->frozen_symbol() ||
161 name == heap->elements_transition_symbol() ||
162 name == heap->observed_symbol();
163 }
164 #endif
165
166
167 int TransitionArray::CompareKeys(Name* key1, uint32_t hash1,
168 bool is_data_property1,
169 PropertyAttributes attributes1, Name* key2,
170 uint32_t hash2, bool is_data_property2,
171 PropertyAttributes attributes2) {
172 int cmp = CompareNames(key1, hash1, key2, hash2);
173 if (cmp != 0) return cmp;
174
175 return CompareDetails(is_data_property1, attributes1, is_data_property2,
176 attributes2);
177 }
178
179
180 int TransitionArray::CompareNames(Name* key1, uint32_t hash1, Name* key2,
181 uint32_t hash2) {
182 if (key1 != key2) {
183 // In case of hash collisions key1 is always "less" than key2.
184 return hash1 <= hash2 ? -1 : 1;
185 }
186
187 return 0;
188 }
189
190
191 int TransitionArray::CompareDetails(bool is_data_property1,
192 PropertyAttributes attributes1,
193 bool is_data_property2,
194 PropertyAttributes attributes2) {
195 if (is_data_property1 != is_data_property2) {
196 return static_cast<int>(is_data_property1) <
197 static_cast<int>(is_data_property2)
198 ? -1
199 : 1;
200 }
201
202 if (attributes1 != attributes2) {
203 return static_cast<int>(attributes1) < static_cast<int>(attributes2) ? -1
204 : 1;
205 }
206
207 return 0;
208 }
209
210
211 PropertyDetails TransitionArray::GetTargetDetails(Name* name, Map* target) {
212 DCHECK(!IsSpecialTransition(name));
213 int descriptor = target->LastAdded();
214 DescriptorArray* descriptors = target->instance_descriptors();
215 // Transitions are allowed only for the last added property.
216 DCHECK(descriptors->GetKey(descriptor)->Equals(name));
217 return descriptors->GetDetails(descriptor);
218 }
219
220
156 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number, 221 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
157 Name* key, 222 Name* key,
158 Map* target) { 223 Map* target) {
159 FixedArray::NoIncrementalWriteBarrierSet( 224 FixedArray::NoIncrementalWriteBarrierSet(
160 this, ToKeyIndex(transition_number), key); 225 this, ToKeyIndex(transition_number), key);
161 FixedArray::NoIncrementalWriteBarrierSet( 226 FixedArray::NoIncrementalWriteBarrierSet(
162 this, ToTargetIndex(transition_number), target); 227 this, ToTargetIndex(transition_number), target);
163 } 228 }
164 229
165 230
166 void TransitionArray::SetNumberOfTransitions(int number_of_transitions) { 231 void TransitionArray::SetNumberOfTransitions(int number_of_transitions) {
167 if (IsFullTransitionArray()) { 232 if (IsFullTransitionArray()) {
168 DCHECK(number_of_transitions <= number_of_transitions_storage()); 233 DCHECK(number_of_transitions <= number_of_transitions_storage());
169 WRITE_FIELD(this, kTransitionLengthOffset, 234 WRITE_FIELD(this, kTransitionLengthOffset,
170 Smi::FromInt(number_of_transitions)); 235 Smi::FromInt(number_of_transitions));
171 } 236 }
172 } 237 }
173 238
174 239
175 #undef FIELD_ADDR 240 #undef FIELD_ADDR
176 #undef WRITE_FIELD 241 #undef WRITE_FIELD
177 #undef CONDITIONAL_WRITE_BARRIER 242 #undef CONDITIONAL_WRITE_BARRIER
178 243
179 244
180 } } // namespace v8::internal 245 } } // namespace v8::internal
181 246
182 #endif // V8_TRANSITIONS_INL_H_ 247 #endif // V8_TRANSITIONS_INL_H_
OLDNEW
« no previous file with comments | « src/transitions.cc ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698