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 // Review notes: | 5 // Review notes: |
6 // | 6 // |
7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
10 // | 10 // |
(...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1877 DCHECK(!ExpectedTransitionKey(map).is_null()); | 1877 DCHECK(!ExpectedTransitionKey(map).is_null()); |
1878 return Handle<Map>(map->transitions()->GetTarget( | 1878 return Handle<Map>(map->transitions()->GetTarget( |
1879 TransitionArray::kSimpleTransitionIndex)); | 1879 TransitionArray::kSimpleTransitionIndex)); |
1880 } | 1880 } |
1881 | 1881 |
1882 | 1882 |
1883 Handle<Map> Map::FindTransitionToField(Handle<Map> map, Handle<Name> key) { | 1883 Handle<Map> Map::FindTransitionToField(Handle<Map> map, Handle<Name> key) { |
1884 DisallowHeapAllocation no_allocation; | 1884 DisallowHeapAllocation no_allocation; |
1885 if (!map->HasTransitionArray()) return Handle<Map>::null(); | 1885 if (!map->HasTransitionArray()) return Handle<Map>::null(); |
1886 TransitionArray* transitions = map->transitions(); | 1886 TransitionArray* transitions = map->transitions(); |
1887 int transition = transitions->Search(*key); | 1887 int transition = transitions->Search(FIELD, *key, NONE); |
1888 if (transition == TransitionArray::kNotFound) return Handle<Map>::null(); | 1888 if (transition == TransitionArray::kNotFound) return Handle<Map>::null(); |
1889 PropertyDetails target_details = transitions->GetTargetDetails(transition); | 1889 DCHECK_EQ(FIELD, transitions->GetTargetDetails(transition).type()); |
1890 if (target_details.type() != FIELD) return Handle<Map>::null(); | 1890 DCHECK_EQ(NONE, transitions->GetTargetDetails(transition).attributes()); |
1891 if (target_details.attributes() != NONE) return Handle<Map>::null(); | |
1892 return Handle<Map>(transitions->GetTarget(transition)); | 1891 return Handle<Map>(transitions->GetTarget(transition)); |
1893 } | 1892 } |
1894 | 1893 |
1895 | 1894 |
1896 ACCESSORS(Oddball, to_string, String, kToStringOffset) | 1895 ACCESSORS(Oddball, to_string, String, kToStringOffset) |
1897 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) | 1896 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) |
1898 | 1897 |
1899 | 1898 |
1900 byte Oddball::kind() const { | 1899 byte Oddball::kind() const { |
1901 return Smi::cast(READ_FIELD(this, kKindOffset))->value(); | 1900 return Smi::cast(READ_FIELD(this, kKindOffset))->value(); |
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2936 void Map::LookupDescriptor(JSObject* holder, | 2935 void Map::LookupDescriptor(JSObject* holder, |
2937 Name* name, | 2936 Name* name, |
2938 LookupResult* result) { | 2937 LookupResult* result) { |
2939 DescriptorArray* descriptors = this->instance_descriptors(); | 2938 DescriptorArray* descriptors = this->instance_descriptors(); |
2940 int number = descriptors->SearchWithCache(name, this); | 2939 int number = descriptors->SearchWithCache(name, this); |
2941 if (number == DescriptorArray::kNotFound) return result->NotFound(); | 2940 if (number == DescriptorArray::kNotFound) return result->NotFound(); |
2942 result->DescriptorResult(holder, descriptors->GetDetails(number), number); | 2941 result->DescriptorResult(holder, descriptors->GetDetails(number), number); |
2943 } | 2942 } |
2944 | 2943 |
2945 | 2944 |
2946 void Map::LookupTransition(JSObject* holder, | 2945 void Map::LookupTransition(JSObject* holder, Name* name, |
2947 Name* name, | 2946 PropertyAttributes attributes, |
2948 LookupResult* result) { | 2947 LookupResult* result) { |
2949 int transition_index = this->SearchTransition(name); | 2948 int transition_index = this->SearchTransition(FIELD, name, attributes); |
2950 if (transition_index == TransitionArray::kNotFound) return result->NotFound(); | 2949 if (transition_index == TransitionArray::kNotFound) return result->NotFound(); |
2951 result->TransitionResult(holder, this->GetTransition(transition_index)); | 2950 result->TransitionResult(holder, this->GetTransition(transition_index)); |
2952 } | 2951 } |
2953 | 2952 |
2954 | 2953 |
2955 FixedArrayBase* Map::GetInitialElements() { | 2954 FixedArrayBase* Map::GetInitialElements() { |
2956 if (has_fast_smi_or_object_elements() || | 2955 if (has_fast_smi_or_object_elements() || |
2957 has_fast_double_elements()) { | 2956 has_fast_double_elements()) { |
2958 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 2957 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
2959 return GetHeap()->empty_fixed_array(); | 2958 return GetHeap()->empty_fixed_array(); |
(...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5210 } | 5209 } |
5211 | 5210 |
5212 | 5211 |
5213 bool Map::HasTransitionArray() const { | 5212 bool Map::HasTransitionArray() const { |
5214 Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset); | 5213 Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset); |
5215 return object->IsTransitionArray(); | 5214 return object->IsTransitionArray(); |
5216 } | 5215 } |
5217 | 5216 |
5218 | 5217 |
5219 Map* Map::elements_transition_map() { | 5218 Map* Map::elements_transition_map() { |
5220 int index = transitions()->Search(GetHeap()->elements_transition_symbol()); | 5219 int index = |
| 5220 transitions()->SearchSpecial(GetHeap()->elements_transition_symbol()); |
5221 return transitions()->GetTarget(index); | 5221 return transitions()->GetTarget(index); |
5222 } | 5222 } |
5223 | 5223 |
5224 | 5224 |
5225 bool Map::CanHaveMoreTransitions() { | 5225 bool Map::CanHaveMoreTransitions() { |
5226 if (!HasTransitionArray()) return true; | 5226 if (!HasTransitionArray()) return true; |
5227 return transitions()->number_of_transitions() < | 5227 return transitions()->number_of_transitions() < |
5228 TransitionArray::kMaxNumberOfTransitions; | 5228 TransitionArray::kMaxNumberOfTransitions; |
5229 } | 5229 } |
5230 | 5230 |
5231 | 5231 |
5232 Map* Map::GetTransition(int transition_index) { | 5232 Map* Map::GetTransition(int transition_index) { |
5233 return transitions()->GetTarget(transition_index); | 5233 return transitions()->GetTarget(transition_index); |
5234 } | 5234 } |
5235 | 5235 |
5236 | 5236 |
5237 int Map::SearchTransition(Name* name) { | 5237 int Map::SearchSpecialTransition(Symbol* name) { |
5238 if (HasTransitionArray()) return transitions()->Search(name); | 5238 if (HasTransitionArray()) { |
| 5239 return transitions()->SearchSpecial(name); |
| 5240 } |
5239 return TransitionArray::kNotFound; | 5241 return TransitionArray::kNotFound; |
5240 } | 5242 } |
5241 | 5243 |
| 5244 |
| 5245 int Map::SearchTransition(PropertyType type, Name* name, |
| 5246 PropertyAttributes attributes) { |
| 5247 if (HasTransitionArray()) { |
| 5248 return transitions()->Search(type, name, attributes); |
| 5249 } |
| 5250 return TransitionArray::kNotFound; |
| 5251 } |
| 5252 |
5242 | 5253 |
5243 FixedArray* Map::GetPrototypeTransitions() { | 5254 FixedArray* Map::GetPrototypeTransitions() { |
5244 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); | 5255 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); |
5245 if (!transitions()->HasPrototypeTransitions()) { | 5256 if (!transitions()->HasPrototypeTransitions()) { |
5246 return GetHeap()->empty_fixed_array(); | 5257 return GetHeap()->empty_fixed_array(); |
5247 } | 5258 } |
5248 return transitions()->GetPrototypeTransitions(); | 5259 return transitions()->GetPrototypeTransitions(); |
5249 } | 5260 } |
5250 | 5261 |
5251 | 5262 |
(...skipping 29 matching lines...) Expand all Loading... |
5281 // Transition arrays are not shared. When one is replaced, it should not | 5292 // Transition arrays are not shared. When one is replaced, it should not |
5282 // keep referenced objects alive, so we zap it. | 5293 // keep referenced objects alive, so we zap it. |
5283 // When there is another reference to the array somewhere (e.g. a handle), | 5294 // When there is another reference to the array somewhere (e.g. a handle), |
5284 // not zapping turns from a waste of memory into a source of crashes. | 5295 // not zapping turns from a waste of memory into a source of crashes. |
5285 if (HasTransitionArray()) { | 5296 if (HasTransitionArray()) { |
5286 #ifdef DEBUG | 5297 #ifdef DEBUG |
5287 for (int i = 0; i < transitions()->number_of_transitions(); i++) { | 5298 for (int i = 0; i < transitions()->number_of_transitions(); i++) { |
5288 Map* target = transitions()->GetTarget(i); | 5299 Map* target = transitions()->GetTarget(i); |
5289 if (target->instance_descriptors() == instance_descriptors()) { | 5300 if (target->instance_descriptors() == instance_descriptors()) { |
5290 Name* key = transitions()->GetKey(i); | 5301 Name* key = transitions()->GetKey(i); |
5291 int new_target_index = transition_array->Search(key); | 5302 int new_target_index; |
5292 DCHECK(new_target_index != TransitionArray::kNotFound); | 5303 if (TransitionArray::IsSpecialTransition(key)) { |
5293 DCHECK(transition_array->GetTarget(new_target_index) == target); | 5304 new_target_index = transition_array->SearchSpecial(Symbol::cast(key)); |
| 5305 } else { |
| 5306 PropertyDetails details = |
| 5307 TransitionArray::GetTargetDetails(key, target); |
| 5308 new_target_index = transition_array->Search(details.type(), key, |
| 5309 details.attributes()); |
| 5310 } |
| 5311 DCHECK_NE(TransitionArray::kNotFound, new_target_index); |
| 5312 DCHECK_EQ(target, transition_array->GetTarget(new_target_index)); |
5294 } | 5313 } |
5295 } | 5314 } |
5296 #endif | 5315 #endif |
5297 DCHECK(transitions() != transition_array); | 5316 DCHECK(transitions() != transition_array); |
5298 ZapTransitions(); | 5317 ZapTransitions(); |
5299 } | 5318 } |
5300 | 5319 |
5301 WRITE_FIELD(this, kTransitionsOrBackPointerOffset, transition_array); | 5320 WRITE_FIELD(this, kTransitionsOrBackPointerOffset, transition_array); |
5302 CONDITIONAL_WRITE_BARRIER( | 5321 CONDITIONAL_WRITE_BARRIER( |
5303 GetHeap(), this, kTransitionsOrBackPointerOffset, transition_array, mode); | 5322 GetHeap(), this, kTransitionsOrBackPointerOffset, transition_array, mode); |
(...skipping 2012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7316 #undef READ_SHORT_FIELD | 7335 #undef READ_SHORT_FIELD |
7317 #undef WRITE_SHORT_FIELD | 7336 #undef WRITE_SHORT_FIELD |
7318 #undef READ_BYTE_FIELD | 7337 #undef READ_BYTE_FIELD |
7319 #undef WRITE_BYTE_FIELD | 7338 #undef WRITE_BYTE_FIELD |
7320 #undef NOBARRIER_READ_BYTE_FIELD | 7339 #undef NOBARRIER_READ_BYTE_FIELD |
7321 #undef NOBARRIER_WRITE_BYTE_FIELD | 7340 #undef NOBARRIER_WRITE_BYTE_FIELD |
7322 | 7341 |
7323 } } // namespace v8::internal | 7342 } } // namespace v8::internal |
7324 | 7343 |
7325 #endif // V8_OBJECTS_INL_H_ | 7344 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |