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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2913 void Map::LookupDescriptor(JSObject* holder, | 2912 void Map::LookupDescriptor(JSObject* holder, |
2914 Name* name, | 2913 Name* name, |
2915 LookupResult* result) { | 2914 LookupResult* result) { |
2916 DescriptorArray* descriptors = this->instance_descriptors(); | 2915 DescriptorArray* descriptors = this->instance_descriptors(); |
2917 int number = descriptors->SearchWithCache(name, this); | 2916 int number = descriptors->SearchWithCache(name, this); |
2918 if (number == DescriptorArray::kNotFound) return result->NotFound(); | 2917 if (number == DescriptorArray::kNotFound) return result->NotFound(); |
2919 result->DescriptorResult(holder, descriptors->GetDetails(number), number); | 2918 result->DescriptorResult(holder, descriptors->GetDetails(number), number); |
2920 } | 2919 } |
2921 | 2920 |
2922 | 2921 |
2923 void Map::LookupTransition(JSObject* holder, | 2922 void Map::LookupTransition(JSObject* holder, Name* name, |
2924 Name* name, | 2923 PropertyAttributes attributes, |
2925 LookupResult* result) { | 2924 LookupResult* result) { |
2926 int transition_index = this->SearchTransition(name); | 2925 int transition_index = this->SearchTransition(FIELD, name, attributes); |
2927 if (transition_index == TransitionArray::kNotFound) return result->NotFound(); | 2926 if (transition_index == TransitionArray::kNotFound) return result->NotFound(); |
2928 result->TransitionResult(holder, this->GetTransition(transition_index)); | 2927 result->TransitionResult(holder, this->GetTransition(transition_index)); |
2929 } | 2928 } |
2930 | 2929 |
2931 | 2930 |
2932 FixedArrayBase* Map::GetInitialElements() { | 2931 FixedArrayBase* Map::GetInitialElements() { |
2933 if (has_fast_smi_or_object_elements() || | 2932 if (has_fast_smi_or_object_elements() || |
2934 has_fast_double_elements()) { | 2933 has_fast_double_elements()) { |
2935 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 2934 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
2936 return GetHeap()->empty_fixed_array(); | 2935 return GetHeap()->empty_fixed_array(); |
(...skipping 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5193 } | 5192 } |
5194 | 5193 |
5195 | 5194 |
5196 bool Map::HasTransitionArray() const { | 5195 bool Map::HasTransitionArray() const { |
5197 Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset); | 5196 Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset); |
5198 return object->IsTransitionArray(); | 5197 return object->IsTransitionArray(); |
5199 } | 5198 } |
5200 | 5199 |
5201 | 5200 |
5202 Map* Map::elements_transition_map() { | 5201 Map* Map::elements_transition_map() { |
5203 int index = transitions()->Search(GetHeap()->elements_transition_symbol()); | 5202 int index = |
| 5203 transitions()->SearchSpecial(GetHeap()->elements_transition_symbol()); |
5204 return transitions()->GetTarget(index); | 5204 return transitions()->GetTarget(index); |
5205 } | 5205 } |
5206 | 5206 |
5207 | 5207 |
5208 bool Map::CanHaveMoreTransitions() { | 5208 bool Map::CanHaveMoreTransitions() { |
5209 if (!HasTransitionArray()) return true; | 5209 if (!HasTransitionArray()) return true; |
5210 return FixedArray::SizeFor(transitions()->length() + | 5210 return FixedArray::SizeFor(transitions()->length() + |
5211 TransitionArray::kTransitionSize) | 5211 TransitionArray::kTransitionSize) |
5212 <= Page::kMaxRegularHeapObjectSize; | 5212 <= Page::kMaxRegularHeapObjectSize; |
5213 } | 5213 } |
5214 | 5214 |
5215 | 5215 |
5216 Map* Map::GetTransition(int transition_index) { | 5216 Map* Map::GetTransition(int transition_index) { |
5217 return transitions()->GetTarget(transition_index); | 5217 return transitions()->GetTarget(transition_index); |
5218 } | 5218 } |
5219 | 5219 |
5220 | 5220 |
5221 int Map::SearchTransition(Name* name) { | 5221 int Map::SearchSpecialTransition(Symbol* name) { |
5222 if (HasTransitionArray()) return transitions()->Search(name); | 5222 if (HasTransitionArray()) { |
| 5223 return transitions()->SearchSpecial(name); |
| 5224 } |
5223 return TransitionArray::kNotFound; | 5225 return TransitionArray::kNotFound; |
5224 } | 5226 } |
5225 | 5227 |
| 5228 |
| 5229 int Map::SearchTransition(PropertyType type, Name* name, |
| 5230 PropertyAttributes attributes) { |
| 5231 if (HasTransitionArray()) { |
| 5232 return transitions()->Search(type, name, attributes); |
| 5233 } |
| 5234 return TransitionArray::kNotFound; |
| 5235 } |
| 5236 |
5226 | 5237 |
5227 FixedArray* Map::GetPrototypeTransitions() { | 5238 FixedArray* Map::GetPrototypeTransitions() { |
5228 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); | 5239 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); |
5229 if (!transitions()->HasPrototypeTransitions()) { | 5240 if (!transitions()->HasPrototypeTransitions()) { |
5230 return GetHeap()->empty_fixed_array(); | 5241 return GetHeap()->empty_fixed_array(); |
5231 } | 5242 } |
5232 return transitions()->GetPrototypeTransitions(); | 5243 return transitions()->GetPrototypeTransitions(); |
5233 } | 5244 } |
5234 | 5245 |
5235 | 5246 |
(...skipping 29 matching lines...) Expand all Loading... |
5265 // Transition arrays are not shared. When one is replaced, it should not | 5276 // Transition arrays are not shared. When one is replaced, it should not |
5266 // keep referenced objects alive, so we zap it. | 5277 // keep referenced objects alive, so we zap it. |
5267 // When there is another reference to the array somewhere (e.g. a handle), | 5278 // When there is another reference to the array somewhere (e.g. a handle), |
5268 // not zapping turns from a waste of memory into a source of crashes. | 5279 // not zapping turns from a waste of memory into a source of crashes. |
5269 if (HasTransitionArray()) { | 5280 if (HasTransitionArray()) { |
5270 #ifdef DEBUG | 5281 #ifdef DEBUG |
5271 for (int i = 0; i < transitions()->number_of_transitions(); i++) { | 5282 for (int i = 0; i < transitions()->number_of_transitions(); i++) { |
5272 Map* target = transitions()->GetTarget(i); | 5283 Map* target = transitions()->GetTarget(i); |
5273 if (target->instance_descriptors() == instance_descriptors()) { | 5284 if (target->instance_descriptors() == instance_descriptors()) { |
5274 Name* key = transitions()->GetKey(i); | 5285 Name* key = transitions()->GetKey(i); |
5275 int new_target_index = transition_array->Search(key); | 5286 int new_target_index; |
| 5287 if (TransitionArray::IsSpecialTransition(key)) { |
| 5288 new_target_index = transition_array->SearchSpecial(Symbol::cast(key)); |
| 5289 } else { |
| 5290 PropertyDetails details = |
| 5291 TransitionArray::GetTargetDetails(key, target); |
| 5292 new_target_index = transition_array->Search(details.type(), key, |
| 5293 details.attributes()); |
| 5294 } |
5276 DCHECK(new_target_index != TransitionArray::kNotFound); | 5295 DCHECK(new_target_index != TransitionArray::kNotFound); |
5277 DCHECK(transition_array->GetTarget(new_target_index) == target); | 5296 DCHECK(transition_array->GetTarget(new_target_index) == target); |
5278 } | 5297 } |
5279 } | 5298 } |
5280 #endif | 5299 #endif |
5281 DCHECK(transitions() != transition_array); | 5300 DCHECK(transitions() != transition_array); |
5282 ZapTransitions(); | 5301 ZapTransitions(); |
5283 } | 5302 } |
5284 | 5303 |
5285 WRITE_FIELD(this, kTransitionsOrBackPointerOffset, transition_array); | 5304 WRITE_FIELD(this, kTransitionsOrBackPointerOffset, transition_array); |
(...skipping 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7287 #undef READ_SHORT_FIELD | 7306 #undef READ_SHORT_FIELD |
7288 #undef WRITE_SHORT_FIELD | 7307 #undef WRITE_SHORT_FIELD |
7289 #undef READ_BYTE_FIELD | 7308 #undef READ_BYTE_FIELD |
7290 #undef WRITE_BYTE_FIELD | 7309 #undef WRITE_BYTE_FIELD |
7291 #undef NOBARRIER_READ_BYTE_FIELD | 7310 #undef NOBARRIER_READ_BYTE_FIELD |
7292 #undef NOBARRIER_WRITE_BYTE_FIELD | 7311 #undef NOBARRIER_WRITE_BYTE_FIELD |
7293 | 7312 |
7294 } } // namespace v8::internal | 7313 } } // namespace v8::internal |
7295 | 7314 |
7296 #endif // V8_OBJECTS_INL_H_ | 7315 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |