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 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 DCHECK(!ExpectedTransitionKey(map).is_null()); | 1894 DCHECK(!ExpectedTransitionKey(map).is_null()); |
1895 return Handle<Map>(map->transitions()->GetTarget( | 1895 return Handle<Map>(map->transitions()->GetTarget( |
1896 TransitionArray::kSimpleTransitionIndex)); | 1896 TransitionArray::kSimpleTransitionIndex)); |
1897 } | 1897 } |
1898 | 1898 |
1899 | 1899 |
1900 Handle<Map> Map::FindTransitionToField(Handle<Map> map, Handle<Name> key) { | 1900 Handle<Map> Map::FindTransitionToField(Handle<Map> map, Handle<Name> key) { |
1901 DisallowHeapAllocation no_allocation; | 1901 DisallowHeapAllocation no_allocation; |
1902 if (!map->HasTransitionArray()) return Handle<Map>::null(); | 1902 if (!map->HasTransitionArray()) return Handle<Map>::null(); |
1903 TransitionArray* transitions = map->transitions(); | 1903 TransitionArray* transitions = map->transitions(); |
1904 int transition = transitions->Search(FIELD, *key, NONE); | 1904 int transition = transitions->Search(*key); |
1905 if (transition == TransitionArray::kNotFound) return Handle<Map>::null(); | 1905 if (transition == TransitionArray::kNotFound) return Handle<Map>::null(); |
1906 PropertyDetails details = transitions->GetTargetDetails(transition); | 1906 PropertyDetails target_details = transitions->GetTargetDetails(transition); |
1907 if (details.type() != FIELD) return Handle<Map>::null(); | 1907 if (target_details.type() != FIELD) return Handle<Map>::null(); |
1908 DCHECK_EQ(NONE, details.attributes()); | 1908 if (target_details.attributes() != NONE) return Handle<Map>::null(); |
1909 return Handle<Map>(transitions->GetTarget(transition)); | 1909 return Handle<Map>(transitions->GetTarget(transition)); |
1910 } | 1910 } |
1911 | 1911 |
1912 | 1912 |
1913 ACCESSORS(Oddball, to_string, String, kToStringOffset) | 1913 ACCESSORS(Oddball, to_string, String, kToStringOffset) |
1914 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) | 1914 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) |
1915 | 1915 |
1916 | 1916 |
1917 byte Oddball::kind() const { | 1917 byte Oddball::kind() const { |
1918 return Smi::cast(READ_FIELD(this, kKindOffset))->value(); | 1918 return Smi::cast(READ_FIELD(this, kKindOffset))->value(); |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2988 void Map::LookupDescriptor(JSObject* holder, | 2988 void Map::LookupDescriptor(JSObject* holder, |
2989 Name* name, | 2989 Name* name, |
2990 LookupResult* result) { | 2990 LookupResult* result) { |
2991 DescriptorArray* descriptors = this->instance_descriptors(); | 2991 DescriptorArray* descriptors = this->instance_descriptors(); |
2992 int number = descriptors->SearchWithCache(name, this); | 2992 int number = descriptors->SearchWithCache(name, this); |
2993 if (number == DescriptorArray::kNotFound) return result->NotFound(); | 2993 if (number == DescriptorArray::kNotFound) return result->NotFound(); |
2994 result->DescriptorResult(holder, descriptors->GetDetails(number), number); | 2994 result->DescriptorResult(holder, descriptors->GetDetails(number), number); |
2995 } | 2995 } |
2996 | 2996 |
2997 | 2997 |
2998 void Map::LookupTransition(JSObject* holder, Name* name, | 2998 void Map::LookupTransition(JSObject* holder, Name* name, LookupResult* result) { |
2999 PropertyAttributes attributes, | 2999 int transition_index = this->SearchTransition(name); |
3000 LookupResult* result) { | |
3001 int transition_index = this->SearchTransition(FIELD, name, attributes); | |
3002 if (transition_index == TransitionArray::kNotFound) return result->NotFound(); | 3000 if (transition_index == TransitionArray::kNotFound) return result->NotFound(); |
3003 result->TransitionResult(holder, this->GetTransition(transition_index)); | 3001 result->TransitionResult(holder, this->GetTransition(transition_index)); |
3004 } | 3002 } |
3005 | 3003 |
3006 | 3004 |
3007 FixedArrayBase* Map::GetInitialElements() { | 3005 FixedArrayBase* Map::GetInitialElements() { |
3008 if (has_fast_smi_or_object_elements() || | 3006 if (has_fast_smi_or_object_elements() || |
3009 has_fast_double_elements()) { | 3007 has_fast_double_elements()) { |
3010 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 3008 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
3011 return GetHeap()->empty_fixed_array(); | 3009 return GetHeap()->empty_fixed_array(); |
(...skipping 2301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5313 } | 5311 } |
5314 | 5312 |
5315 | 5313 |
5316 bool Map::HasTransitionArray() const { | 5314 bool Map::HasTransitionArray() const { |
5317 Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset); | 5315 Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset); |
5318 return object->IsTransitionArray(); | 5316 return object->IsTransitionArray(); |
5319 } | 5317 } |
5320 | 5318 |
5321 | 5319 |
5322 Map* Map::elements_transition_map() { | 5320 Map* Map::elements_transition_map() { |
5323 int index = | 5321 int index = transitions()->Search(GetHeap()->elements_transition_symbol()); |
5324 transitions()->SearchSpecial(GetHeap()->elements_transition_symbol()); | |
5325 return transitions()->GetTarget(index); | 5322 return transitions()->GetTarget(index); |
5326 } | 5323 } |
5327 | 5324 |
5328 | 5325 |
5329 bool Map::CanHaveMoreTransitions() { | 5326 bool Map::CanHaveMoreTransitions() { |
5330 if (!HasTransitionArray()) return true; | 5327 if (!HasTransitionArray()) return true; |
5331 return transitions()->number_of_transitions() < | 5328 return transitions()->number_of_transitions() < |
5332 TransitionArray::kMaxNumberOfTransitions; | 5329 TransitionArray::kMaxNumberOfTransitions; |
5333 } | 5330 } |
5334 | 5331 |
5335 | 5332 |
5336 Map* Map::GetTransition(int transition_index) { | 5333 Map* Map::GetTransition(int transition_index) { |
5337 return transitions()->GetTarget(transition_index); | 5334 return transitions()->GetTarget(transition_index); |
5338 } | 5335 } |
5339 | 5336 |
5340 | 5337 |
5341 int Map::SearchSpecialTransition(Symbol* name) { | 5338 int Map::SearchTransition(Name* name) { |
5342 if (HasTransitionArray()) { | 5339 if (HasTransitionArray()) return transitions()->Search(name); |
5343 return transitions()->SearchSpecial(name); | |
5344 } | |
5345 return TransitionArray::kNotFound; | 5340 return TransitionArray::kNotFound; |
5346 } | 5341 } |
5347 | 5342 |
5348 | |
5349 int Map::SearchTransition(PropertyType type, Name* name, | |
5350 PropertyAttributes attributes) { | |
5351 if (HasTransitionArray()) { | |
5352 return transitions()->Search(type, name, attributes); | |
5353 } | |
5354 return TransitionArray::kNotFound; | |
5355 } | |
5356 | |
5357 | 5343 |
5358 FixedArray* Map::GetPrototypeTransitions() { | 5344 FixedArray* Map::GetPrototypeTransitions() { |
5359 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); | 5345 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); |
5360 if (!transitions()->HasPrototypeTransitions()) { | 5346 if (!transitions()->HasPrototypeTransitions()) { |
5361 return GetHeap()->empty_fixed_array(); | 5347 return GetHeap()->empty_fixed_array(); |
5362 } | 5348 } |
5363 return transitions()->GetPrototypeTransitions(); | 5349 return transitions()->GetPrototypeTransitions(); |
5364 } | 5350 } |
5365 | 5351 |
5366 | 5352 |
(...skipping 27 matching lines...) Expand all Loading... |
5394 // Transition arrays are not shared. When one is replaced, it should not | 5380 // Transition arrays are not shared. When one is replaced, it should not |
5395 // keep referenced objects alive, so we zap it. | 5381 // keep referenced objects alive, so we zap it. |
5396 // When there is another reference to the array somewhere (e.g. a handle), | 5382 // When there is another reference to the array somewhere (e.g. a handle), |
5397 // not zapping turns from a waste of memory into a source of crashes. | 5383 // not zapping turns from a waste of memory into a source of crashes. |
5398 if (HasTransitionArray()) { | 5384 if (HasTransitionArray()) { |
5399 #ifdef DEBUG | 5385 #ifdef DEBUG |
5400 for (int i = 0; i < transitions()->number_of_transitions(); i++) { | 5386 for (int i = 0; i < transitions()->number_of_transitions(); i++) { |
5401 Map* target = transitions()->GetTarget(i); | 5387 Map* target = transitions()->GetTarget(i); |
5402 if (target->instance_descriptors() == instance_descriptors()) { | 5388 if (target->instance_descriptors() == instance_descriptors()) { |
5403 Name* key = transitions()->GetKey(i); | 5389 Name* key = transitions()->GetKey(i); |
5404 int new_target_index; | 5390 int new_target_index = transition_array->Search(key); |
5405 if (TransitionArray::IsSpecialTransition(key)) { | 5391 DCHECK(new_target_index != TransitionArray::kNotFound); |
5406 new_target_index = transition_array->SearchSpecial(Symbol::cast(key)); | 5392 DCHECK(transition_array->GetTarget(new_target_index) == target); |
5407 } else { | |
5408 PropertyDetails details = | |
5409 TransitionArray::GetTargetDetails(key, target); | |
5410 new_target_index = transition_array->Search(details.type(), key, | |
5411 details.attributes()); | |
5412 } | |
5413 DCHECK_NE(TransitionArray::kNotFound, new_target_index); | |
5414 DCHECK_EQ(target, transition_array->GetTarget(new_target_index)); | |
5415 } | 5393 } |
5416 } | 5394 } |
5417 #endif | 5395 #endif |
5418 DCHECK(transitions() != transition_array); | 5396 DCHECK(transitions() != transition_array); |
5419 ZapTransitions(); | 5397 ZapTransitions(); |
5420 } | 5398 } |
5421 | 5399 |
5422 WRITE_FIELD(this, kTransitionsOrBackPointerOffset, transition_array); | 5400 WRITE_FIELD(this, kTransitionsOrBackPointerOffset, transition_array); |
5423 CONDITIONAL_WRITE_BARRIER( | 5401 CONDITIONAL_WRITE_BARRIER( |
5424 GetHeap(), this, kTransitionsOrBackPointerOffset, transition_array, mode); | 5402 GetHeap(), this, kTransitionsOrBackPointerOffset, transition_array, mode); |
(...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7473 #undef READ_SHORT_FIELD | 7451 #undef READ_SHORT_FIELD |
7474 #undef WRITE_SHORT_FIELD | 7452 #undef WRITE_SHORT_FIELD |
7475 #undef READ_BYTE_FIELD | 7453 #undef READ_BYTE_FIELD |
7476 #undef WRITE_BYTE_FIELD | 7454 #undef WRITE_BYTE_FIELD |
7477 #undef NOBARRIER_READ_BYTE_FIELD | 7455 #undef NOBARRIER_READ_BYTE_FIELD |
7478 #undef NOBARRIER_WRITE_BYTE_FIELD | 7456 #undef NOBARRIER_WRITE_BYTE_FIELD |
7479 | 7457 |
7480 } } // namespace v8::internal | 7458 } } // namespace v8::internal |
7481 | 7459 |
7482 #endif // V8_OBJECTS_INL_H_ | 7460 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |