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 7669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7680 fast_double_elements->set_the_hole(i); | 7680 fast_double_elements->set_the_hole(i); |
7681 } | 7681 } |
7682 } | 7682 } |
7683 } | 7683 } |
7684 JSArray::cast(this)->set_length(Smi::cast(smi_length)); | 7684 JSArray::cast(this)->set_length(Smi::cast(smi_length)); |
7685 } | 7685 } |
7686 return this; | 7686 return this; |
7687 } | 7687 } |
7688 int min = NewElementsCapacity(old_capacity); | 7688 int min = NewElementsCapacity(old_capacity); |
7689 int new_capacity = value > min ? value : min; | 7689 int new_capacity = value > min ? value : min; |
7690 if (new_capacity <= kMaxFastElementsLength || | 7690 if (!ShouldConvertToSlowElements(new_capacity)) { |
7691 !ShouldConvertToSlowElements(new_capacity)) { | |
7692 MaybeObject* result; | 7691 MaybeObject* result; |
7693 if (GetElementsKind() == FAST_ELEMENTS) { | 7692 if (GetElementsKind() == FAST_ELEMENTS) { |
7694 result = SetFastElementsCapacityAndLength(new_capacity, value); | 7693 result = SetFastElementsCapacityAndLength(new_capacity, value); |
7695 } else { | 7694 } else { |
7696 ASSERT(GetElementsKind() == FAST_DOUBLE_ELEMENTS); | 7695 ASSERT(GetElementsKind() == FAST_DOUBLE_ELEMENTS); |
7697 result = SetFastDoubleElementsCapacityAndLength(new_capacity, | 7696 result = SetFastDoubleElementsCapacityAndLength(new_capacity, |
7698 value); | 7697 value); |
7699 } | 7698 } |
7700 if (result->IsFailure()) return result; | 7699 if (result->IsFailure()) return result; |
7701 return this; | 7700 return this; |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8427 JSArray::cast(this)->set_length(Smi::FromInt(index + 1)); | 8426 JSArray::cast(this)->set_length(Smi::FromInt(index + 1)); |
8428 } | 8427 } |
8429 } | 8428 } |
8430 return value; | 8429 return value; |
8431 } | 8430 } |
8432 | 8431 |
8433 // Allow gap in fast case. | 8432 // Allow gap in fast case. |
8434 if ((index - length) < kMaxGap) { | 8433 if ((index - length) < kMaxGap) { |
8435 // Try allocating extra space. | 8434 // Try allocating extra space. |
8436 int new_capacity = NewElementsCapacity(index + 1); | 8435 int new_capacity = NewElementsCapacity(index + 1); |
8437 if (new_capacity <= kMaxFastElementsLength || | 8436 if (!ShouldConvertToSlowElements(new_capacity)) { |
8438 !ShouldConvertToSlowElements(new_capacity)) { | |
8439 ASSERT(static_cast<uint32_t>(new_capacity) > index); | 8437 ASSERT(static_cast<uint32_t>(new_capacity) > index); |
8440 Object* new_elements; | 8438 Object* new_elements; |
8441 MaybeObject* maybe = | 8439 MaybeObject* maybe = |
8442 SetFastElementsCapacityAndLength(new_capacity, index + 1); | 8440 SetFastElementsCapacityAndLength(new_capacity, index + 1); |
8443 if (!maybe->ToObject(&new_elements)) return maybe; | 8441 if (!maybe->ToObject(&new_elements)) return maybe; |
8444 FixedArray::cast(new_elements)->set(index, value); | 8442 FixedArray::cast(new_elements)->set(index, value); |
8445 return value; | 8443 return value; |
8446 } | 8444 } |
8447 } | 8445 } |
8448 | 8446 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8610 JSArray::cast(this)->set_length(Smi::FromInt(index + 1)); | 8608 JSArray::cast(this)->set_length(Smi::FromInt(index + 1)); |
8611 } | 8609 } |
8612 } | 8610 } |
8613 return value; | 8611 return value; |
8614 } | 8612 } |
8615 | 8613 |
8616 // Allow gap in fast case. | 8614 // Allow gap in fast case. |
8617 if ((index - elms_length) < kMaxGap) { | 8615 if ((index - elms_length) < kMaxGap) { |
8618 // Try allocating extra space. | 8616 // Try allocating extra space. |
8619 int new_capacity = NewElementsCapacity(index+1); | 8617 int new_capacity = NewElementsCapacity(index+1); |
8620 if (new_capacity <= kMaxFastElementsLength || | 8618 if (!ShouldConvertToSlowElements(new_capacity)) { |
8621 !ShouldConvertToSlowElements(new_capacity)) { | |
8622 ASSERT(static_cast<uint32_t>(new_capacity) > index); | 8619 ASSERT(static_cast<uint32_t>(new_capacity) > index); |
8623 Object* obj; | 8620 Object* obj; |
8624 { MaybeObject* maybe_obj = | 8621 { MaybeObject* maybe_obj = |
8625 SetFastDoubleElementsCapacityAndLength(new_capacity, | 8622 SetFastDoubleElementsCapacityAndLength(new_capacity, |
8626 index + 1); | 8623 index + 1); |
8627 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 8624 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
8628 } | 8625 } |
8629 FixedDoubleArray::cast(elements())->set(index, double_value); | 8626 FixedDoubleArray::cast(elements())->set(index, double_value); |
8630 return value; | 8627 return value; |
8631 } | 8628 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9134 case EXTERNAL_FLOAT_ELEMENTS: | 9131 case EXTERNAL_FLOAT_ELEMENTS: |
9135 case EXTERNAL_DOUBLE_ELEMENTS: { | 9132 case EXTERNAL_DOUBLE_ELEMENTS: { |
9136 return true; | 9133 return true; |
9137 } | 9134 } |
9138 } | 9135 } |
9139 return (capacity == 0) || (number_of_elements > (capacity / 2)); | 9136 return (capacity == 0) || (number_of_elements > (capacity / 2)); |
9140 } | 9137 } |
9141 | 9138 |
9142 | 9139 |
9143 bool JSObject::ShouldConvertToSlowElements(int new_capacity) { | 9140 bool JSObject::ShouldConvertToSlowElements(int new_capacity) { |
| 9141 if (new_capacity <= kMaxFastElementsLength) return false; |
9144 // Keep the array in fast case if the current backing storage is | 9142 // Keep the array in fast case if the current backing storage is |
9145 // almost filled and if the new capacity is no more than twice the | 9143 // almost filled and if the new capacity is no more than twice the |
9146 // old capacity. | 9144 // old capacity. |
9147 int elements_length = 0; | 9145 int old_capacity = 0; |
9148 if (elements()->map() == GetHeap()->non_strict_arguments_elements_map()) { | 9146 if (elements()->map() == GetHeap()->non_strict_arguments_elements_map()) { |
9149 FixedArray* backing_store = FixedArray::cast(elements()); | 9147 FixedArray* backing_store = FixedArray::cast(elements()); |
9150 elements_length = FixedArray::cast(backing_store->get(1))->length(); | 9148 old_capacity = FixedArray::cast(backing_store->get(1))->length(); |
9151 } else if (HasFastElements()) { | 9149 } else if (HasFastElements()) { |
9152 elements_length = FixedArray::cast(elements())->length(); | 9150 old_capacity = FixedArray::cast(elements())->length(); |
9153 } else if (HasFastDoubleElements()) { | 9151 } else if (HasFastDoubleElements()) { |
9154 elements_length = FixedDoubleArray::cast(elements())->length(); | 9152 old_capacity = FixedDoubleArray::cast(elements())->length(); |
9155 } else { | 9153 } else { |
9156 UNREACHABLE(); | 9154 UNREACHABLE(); |
9157 } | 9155 } |
9158 return !HasDenseElements() || ((new_capacity / 2) > elements_length); | 9156 return !HasDenseElements() || ((new_capacity / 2) > old_capacity); |
9159 } | 9157 } |
9160 | 9158 |
9161 | 9159 |
9162 bool JSObject::ShouldConvertToFastElements() { | 9160 bool JSObject::ShouldConvertToFastElements() { |
9163 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); | 9161 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); |
9164 // If the elements are sparse, we should not go back to fast case. | 9162 // If the elements are sparse, we should not go back to fast case. |
9165 if (!HasDenseElements()) return false; | 9163 if (!HasDenseElements()) return false; |
9166 // An object requiring access checks is never allowed to have fast | 9164 // An object requiring access checks is never allowed to have fast |
9167 // elements. If it had fast elements we would skip security checks. | 9165 // elements. If it had fast elements we would skip security checks. |
9168 if (IsAccessCheckNeeded()) return false; | 9166 if (IsAccessCheckNeeded()) return false; |
(...skipping 2677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11846 if (break_point_objects()->IsUndefined()) return 0; | 11844 if (break_point_objects()->IsUndefined()) return 0; |
11847 // Single beak point. | 11845 // Single beak point. |
11848 if (!break_point_objects()->IsFixedArray()) return 1; | 11846 if (!break_point_objects()->IsFixedArray()) return 1; |
11849 // Multiple break points. | 11847 // Multiple break points. |
11850 return FixedArray::cast(break_point_objects())->length(); | 11848 return FixedArray::cast(break_point_objects())->length(); |
11851 } | 11849 } |
11852 #endif | 11850 #endif |
11853 | 11851 |
11854 | 11852 |
11855 } } // namespace v8::internal | 11853 } } // namespace v8::internal |
OLD | NEW |