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. | |
8193 bool has_fast_smi_only_elements = | 8191 bool has_fast_smi_only_elements = |
8194 (set_capacity_mode == kForceSmiOnlyElements) || | 8192 (set_capacity_mode == kAllowSmiOnlyElements) && |
8195 ((set_capacity_mode == kAllowSmiOnlyElements) && | 8193 (elements()->map()->has_fast_smi_only_elements() || |
8196 (elements()->map()->has_fast_smi_only_elements() || | 8194 elements() == heap->empty_fixed_array()); |
8197 elements() == heap->empty_fixed_array())); | |
8198 ElementsKind elements_kind = has_fast_smi_only_elements | 8195 ElementsKind elements_kind = has_fast_smi_only_elements |
8199 ? FAST_SMI_ONLY_ELEMENTS | 8196 ? FAST_SMI_ONLY_ELEMENTS |
8200 : FAST_ELEMENTS; | 8197 : FAST_ELEMENTS; |
8201 MaybeObject* maybe = GetElementsTransitionMap(elements_kind); | 8198 MaybeObject* maybe = GetElementsTransitionMap(elements_kind); |
8202 if (!maybe->ToObject(&object)) return maybe; | 8199 if (!maybe->ToObject(&object)) return maybe; |
8203 new_map = Map::cast(object); | 8200 new_map = Map::cast(object); |
8204 } | 8201 } |
8205 | 8202 |
8206 FixedArrayBase* old_elements_raw = elements(); | 8203 FixedArrayBase* old_elements_raw = elements(); |
8207 ElementsKind elements_kind = GetElementsKind(); | 8204 ElementsKind elements_kind = GetElementsKind(); |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9237 } | 9234 } |
9238 | 9235 |
9239 // Attempt to put this object back in fast case. | 9236 // Attempt to put this object back in fast case. |
9240 if (ShouldConvertToFastElements()) { | 9237 if (ShouldConvertToFastElements()) { |
9241 uint32_t new_length = 0; | 9238 uint32_t new_length = 0; |
9242 if (IsJSArray()) { | 9239 if (IsJSArray()) { |
9243 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&new_length)); | 9240 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&new_length)); |
9244 } else { | 9241 } else { |
9245 new_length = dictionary->max_number_key() + 1; | 9242 new_length = dictionary->max_number_key() + 1; |
9246 } | 9243 } |
9247 SetFastElementsCapacityMode set_capacity_mode = FLAG_smi_only_arrays | 9244 MaybeObject* result = CanConvertToFastDoubleElements() |
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 | |
9257 ? SetFastDoubleElementsCapacityAndLength(new_length, new_length) | 9245 ? SetFastDoubleElementsCapacityAndLength(new_length, new_length) |
9258 : SetFastElementsCapacityAndLength(new_length, | 9246 : SetFastElementsCapacityAndLength(new_length, |
9259 new_length, | 9247 new_length, |
9260 set_capacity_mode); | 9248 kDontAllowSmiOnlyElements); |
9261 if (result->IsFailure()) return result; | 9249 if (result->IsFailure()) return result; |
9262 #ifdef DEBUG | 9250 #ifdef DEBUG |
9263 if (FLAG_trace_normalization) { | 9251 if (FLAG_trace_normalization) { |
9264 PrintF("Object elements are fast case again:\n"); | 9252 PrintF("Object elements are fast case again:\n"); |
9265 Print(); | 9253 Print(); |
9266 } | 9254 } |
9267 #endif | 9255 #endif |
9268 } | 9256 } |
9269 return value; | 9257 return value; |
9270 } | 9258 } |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9729 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_size)); | 9717 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_size)); |
9730 } else { | 9718 } else { |
9731 array_size = dictionary->max_number_key(); | 9719 array_size = dictionary->max_number_key(); |
9732 } | 9720 } |
9733 uint32_t dictionary_size = static_cast<uint32_t>(dictionary->Capacity()) * | 9721 uint32_t dictionary_size = static_cast<uint32_t>(dictionary->Capacity()) * |
9734 NumberDictionary::kEntrySize; | 9722 NumberDictionary::kEntrySize; |
9735 return 2 * dictionary_size >= array_size; | 9723 return 2 * dictionary_size >= array_size; |
9736 } | 9724 } |
9737 | 9725 |
9738 | 9726 |
9739 bool JSObject::ShouldConvertToFastDoubleElements( | 9727 bool JSObject::CanConvertToFastDoubleElements() { |
9740 bool* has_smi_only_elements) { | |
9741 *has_smi_only_elements = false; | |
9742 if (FLAG_unbox_double_arrays) { | 9728 if (FLAG_unbox_double_arrays) { |
9743 ASSERT(HasDictionaryElements()); | 9729 ASSERT(HasDictionaryElements()); |
9744 NumberDictionary* dictionary = NumberDictionary::cast(elements()); | 9730 NumberDictionary* dictionary = NumberDictionary::cast(elements()); |
9745 bool found_double = false; | |
9746 for (int i = 0; i < dictionary->Capacity(); i++) { | 9731 for (int i = 0; i < dictionary->Capacity(); i++) { |
9747 Object* key = dictionary->KeyAt(i); | 9732 Object* key = dictionary->KeyAt(i); |
9748 if (key->IsNumber()) { | 9733 if (key->IsNumber()) { |
9749 Object* value = dictionary->ValueAt(i); | 9734 if (!dictionary->ValueAt(i)->IsNumber()) return false; |
9750 if (!value->IsNumber()) return false; | |
9751 if (!value->IsSmi()) { | |
9752 found_double = true; | |
9753 } | |
9754 } | 9735 } |
9755 } | 9736 } |
9756 *has_smi_only_elements = !found_double; | 9737 return true; |
9757 return found_double; | |
9758 } else { | 9738 } else { |
9759 return false; | 9739 return false; |
9760 } | 9740 } |
9761 } | 9741 } |
9762 | 9742 |
9763 | 9743 |
9764 // Certain compilers request function template instantiation when they | 9744 // Certain compilers request function template instantiation when they |
9765 // see the definition of the other template functions in the | 9745 // see the definition of the other template functions in the |
9766 // class. This requires us to have the template functions put | 9746 // class. This requires us to have the template functions put |
9767 // together, so even though this function belongs in objects-debug.cc, | 9747 // together, so even though this function belongs in objects-debug.cc, |
(...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12574 if (break_point_objects()->IsUndefined()) return 0; | 12554 if (break_point_objects()->IsUndefined()) return 0; |
12575 // Single break point. | 12555 // Single break point. |
12576 if (!break_point_objects()->IsFixedArray()) return 1; | 12556 if (!break_point_objects()->IsFixedArray()) return 1; |
12577 // Multiple break points. | 12557 // Multiple break points. |
12578 return FixedArray::cast(break_point_objects())->length(); | 12558 return FixedArray::cast(break_point_objects())->length(); |
12579 } | 12559 } |
12580 #endif // ENABLE_DEBUGGER_SUPPORT | 12560 #endif // ENABLE_DEBUGGER_SUPPORT |
12581 | 12561 |
12582 | 12562 |
12583 } } // namespace v8::internal | 12563 } } // namespace v8::internal |
OLD | NEW |