OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 8170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8181 { Object* object; | 8181 { Object* object; |
8182 MaybeObject* maybe = heap->AllocateFixedArrayWithHoles(capacity); | 8182 MaybeObject* maybe = heap->AllocateFixedArrayWithHoles(capacity); |
8183 if (!maybe->ToObject(&object)) return maybe; | 8183 if (!maybe->ToObject(&object)) return maybe; |
8184 new_elements = FixedArray::cast(object); | 8184 new_elements = FixedArray::cast(object); |
8185 } | 8185 } |
8186 | 8186 |
8187 // Find the new map to use for this object if there is a map change. | 8187 // Find the new map to use for this object if there is a map change. |
8188 Map* new_map = NULL; | 8188 Map* new_map = NULL; |
8189 if (elements()->map() != heap->non_strict_arguments_elements_map()) { | 8189 if (elements()->map() != heap->non_strict_arguments_elements_map()) { |
8190 Object* object; | 8190 Object* object; |
| 8191 // The resized array has FAST_SMI_ONLY_ELEMENTS if the capacity mode forces |
| 8192 // it, or if it's allowed and the old elements array contained only SMIs. |
8191 bool has_fast_smi_only_elements = | 8193 bool has_fast_smi_only_elements = |
8192 (set_capacity_mode == kAllowSmiOnlyElements) && | 8194 (set_capacity_mode == kForceSmiOnlyElements) || |
8193 (elements()->map()->has_fast_smi_only_elements() || | 8195 ((set_capacity_mode == kAllowSmiOnlyElements) && |
8194 elements() == heap->empty_fixed_array()); | 8196 (elements()->map()->has_fast_smi_only_elements() || |
| 8197 elements() == heap->empty_fixed_array())); |
8195 ElementsKind elements_kind = has_fast_smi_only_elements | 8198 ElementsKind elements_kind = has_fast_smi_only_elements |
8196 ? FAST_SMI_ONLY_ELEMENTS | 8199 ? FAST_SMI_ONLY_ELEMENTS |
8197 : FAST_ELEMENTS; | 8200 : FAST_ELEMENTS; |
8198 MaybeObject* maybe = GetElementsTransitionMap(elements_kind); | 8201 MaybeObject* maybe = GetElementsTransitionMap(elements_kind); |
8199 if (!maybe->ToObject(&object)) return maybe; | 8202 if (!maybe->ToObject(&object)) return maybe; |
8200 new_map = Map::cast(object); | 8203 new_map = Map::cast(object); |
8201 } | 8204 } |
8202 | 8205 |
8203 FixedArrayBase* old_elements_raw = elements(); | 8206 FixedArrayBase* old_elements_raw = elements(); |
8204 ElementsKind elements_kind = GetElementsKind(); | 8207 ElementsKind elements_kind = GetElementsKind(); |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9234 } | 9237 } |
9235 | 9238 |
9236 // Attempt to put this object back in fast case. | 9239 // Attempt to put this object back in fast case. |
9237 if (ShouldConvertToFastElements()) { | 9240 if (ShouldConvertToFastElements()) { |
9238 uint32_t new_length = 0; | 9241 uint32_t new_length = 0; |
9239 if (IsJSArray()) { | 9242 if (IsJSArray()) { |
9240 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&new_length)); | 9243 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&new_length)); |
9241 } else { | 9244 } else { |
9242 new_length = dictionary->max_number_key() + 1; | 9245 new_length = dictionary->max_number_key() + 1; |
9243 } | 9246 } |
9244 MaybeObject* result = CanConvertToFastDoubleElements() | 9247 SetFastElementsCapacityMode set_capacity_mode = FLAG_smi_only_arrays |
| 9248 ? kAllowSmiOnlyElements |
| 9249 : kDontAllowSmiOnlyElements; |
| 9250 bool has_smi_only_elements = false; |
| 9251 bool should_convert_to_fast_double_elements = |
| 9252 ShouldConvertToFastDoubleElements(&has_smi_only_elements); |
| 9253 if (has_smi_only_elements) { |
| 9254 set_capacity_mode = kForceSmiOnlyElements; |
| 9255 } |
| 9256 MaybeObject* result = should_convert_to_fast_double_elements |
9245 ? SetFastDoubleElementsCapacityAndLength(new_length, new_length) | 9257 ? SetFastDoubleElementsCapacityAndLength(new_length, new_length) |
9246 : SetFastElementsCapacityAndLength(new_length, | 9258 : SetFastElementsCapacityAndLength(new_length, |
9247 new_length, | 9259 new_length, |
9248 kDontAllowSmiOnlyElements); | 9260 set_capacity_mode); |
9249 if (result->IsFailure()) return result; | 9261 if (result->IsFailure()) return result; |
9250 #ifdef DEBUG | 9262 #ifdef DEBUG |
9251 if (FLAG_trace_normalization) { | 9263 if (FLAG_trace_normalization) { |
9252 PrintF("Object elements are fast case again:\n"); | 9264 PrintF("Object elements are fast case again:\n"); |
9253 Print(); | 9265 Print(); |
9254 } | 9266 } |
9255 #endif | 9267 #endif |
9256 } | 9268 } |
9257 return value; | 9269 return value; |
9258 } | 9270 } |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9717 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_size)); | 9729 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_size)); |
9718 } else { | 9730 } else { |
9719 array_size = dictionary->max_number_key(); | 9731 array_size = dictionary->max_number_key(); |
9720 } | 9732 } |
9721 uint32_t dictionary_size = static_cast<uint32_t>(dictionary->Capacity()) * | 9733 uint32_t dictionary_size = static_cast<uint32_t>(dictionary->Capacity()) * |
9722 NumberDictionary::kEntrySize; | 9734 NumberDictionary::kEntrySize; |
9723 return 2 * dictionary_size >= array_size; | 9735 return 2 * dictionary_size >= array_size; |
9724 } | 9736 } |
9725 | 9737 |
9726 | 9738 |
9727 bool JSObject::CanConvertToFastDoubleElements() { | 9739 bool JSObject::ShouldConvertToFastDoubleElements( |
| 9740 bool* has_smi_only_elements) { |
| 9741 *has_smi_only_elements = false; |
9728 if (FLAG_unbox_double_arrays) { | 9742 if (FLAG_unbox_double_arrays) { |
9729 ASSERT(HasDictionaryElements()); | 9743 ASSERT(HasDictionaryElements()); |
9730 NumberDictionary* dictionary = NumberDictionary::cast(elements()); | 9744 NumberDictionary* dictionary = NumberDictionary::cast(elements()); |
| 9745 bool found_double = false; |
9731 for (int i = 0; i < dictionary->Capacity(); i++) { | 9746 for (int i = 0; i < dictionary->Capacity(); i++) { |
9732 Object* key = dictionary->KeyAt(i); | 9747 Object* key = dictionary->KeyAt(i); |
9733 if (key->IsNumber()) { | 9748 if (key->IsNumber()) { |
9734 if (!dictionary->ValueAt(i)->IsNumber()) return false; | 9749 Object* value = dictionary->ValueAt(i); |
| 9750 if (!value->IsNumber()) return false; |
| 9751 if (!value->IsSmi()) { |
| 9752 found_double = true; |
| 9753 } |
9735 } | 9754 } |
9736 } | 9755 } |
9737 return true; | 9756 *has_smi_only_elements = !found_double; |
| 9757 return found_double; |
9738 } else { | 9758 } else { |
9739 return false; | 9759 return false; |
9740 } | 9760 } |
9741 } | 9761 } |
9742 | 9762 |
9743 | 9763 |
9744 // Certain compilers request function template instantiation when they | 9764 // Certain compilers request function template instantiation when they |
9745 // see the definition of the other template functions in the | 9765 // see the definition of the other template functions in the |
9746 // class. This requires us to have the template functions put | 9766 // class. This requires us to have the template functions put |
9747 // together, so even though this function belongs in objects-debug.cc, | 9767 // together, so even though this function belongs in objects-debug.cc, |
(...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12554 if (break_point_objects()->IsUndefined()) return 0; | 12574 if (break_point_objects()->IsUndefined()) return 0; |
12555 // Single break point. | 12575 // Single break point. |
12556 if (!break_point_objects()->IsFixedArray()) return 1; | 12576 if (!break_point_objects()->IsFixedArray()) return 1; |
12557 // Multiple break points. | 12577 // Multiple break points. |
12558 return FixedArray::cast(break_point_objects())->length(); | 12578 return FixedArray::cast(break_point_objects())->length(); |
12559 } | 12579 } |
12560 #endif // ENABLE_DEBUGGER_SUPPORT | 12580 #endif // ENABLE_DEBUGGER_SUPPORT |
12561 | 12581 |
12562 | 12582 |
12563 } } // namespace v8::internal | 12583 } } // namespace v8::internal |
OLD | NEW |