| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3711 Expect(Token::RBRACK, CHECK_OK); | 3711 Expect(Token::RBRACK, CHECK_OK); |
| 3712 | 3712 |
| 3713 // Update the scope information before the pre-parsing bailout. | 3713 // Update the scope information before the pre-parsing bailout. |
| 3714 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); | 3714 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); |
| 3715 | 3715 |
| 3716 // Allocate a fixed array to hold all the object literals. | 3716 // Allocate a fixed array to hold all the object literals. |
| 3717 Handle<FixedArray> object_literals = | 3717 Handle<FixedArray> object_literals = |
| 3718 isolate()->factory()->NewFixedArray(values->length(), TENURED); | 3718 isolate()->factory()->NewFixedArray(values->length(), TENURED); |
| 3719 Handle<FixedDoubleArray> double_literals; | 3719 Handle<FixedDoubleArray> double_literals; |
| 3720 ElementsKind elements_kind = FAST_SMI_ELEMENTS; | 3720 ElementsKind elements_kind = FAST_SMI_ELEMENTS; |
| 3721 bool has_only_undefined_values = true; |
| 3721 bool has_hole_values = false; | 3722 bool has_hole_values = false; |
| 3722 | 3723 |
| 3723 // Fill in the literals. | 3724 // Fill in the literals. |
| 3724 Heap* heap = isolate()->heap(); | 3725 Heap* heap = isolate()->heap(); |
| 3725 bool is_simple = true; | 3726 bool is_simple = true; |
| 3726 int depth = 1; | 3727 int depth = 1; |
| 3727 for (int i = 0, n = values->length(); i < n; i++) { | 3728 for (int i = 0, n = values->length(); i < n; i++) { |
| 3728 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); | 3729 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); |
| 3729 if (m_literal != NULL && m_literal->depth() + 1 > depth) { | 3730 if (m_literal != NULL && m_literal->depth() + 1 > depth) { |
| 3730 depth = m_literal->depth() + 1; | 3731 depth = m_literal->depth() + 1; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3742 if (elements_kind == FAST_DOUBLE_ELEMENTS) { | 3743 if (elements_kind == FAST_DOUBLE_ELEMENTS) { |
| 3743 double_literals->set(i, 0); | 3744 double_literals->set(i, 0); |
| 3744 } | 3745 } |
| 3745 } else { | 3746 } else { |
| 3746 // Examine each literal element, and adjust the ElementsKind if the | 3747 // Examine each literal element, and adjust the ElementsKind if the |
| 3747 // literal element is not of a type that can be stored in the current | 3748 // literal element is not of a type that can be stored in the current |
| 3748 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to | 3749 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to |
| 3749 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember | 3750 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember |
| 3750 // the tagged value, no matter what the ElementsKind is in case we | 3751 // the tagged value, no matter what the ElementsKind is in case we |
| 3751 // ultimately end up in FAST_ELEMENTS. | 3752 // ultimately end up in FAST_ELEMENTS. |
| 3753 has_only_undefined_values = false; |
| 3752 object_literals->set(i, *boilerplate_value); | 3754 object_literals->set(i, *boilerplate_value); |
| 3753 if (elements_kind == FAST_SMI_ELEMENTS) { | 3755 if (elements_kind == FAST_SMI_ELEMENTS) { |
| 3754 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or | 3756 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or |
| 3755 // FAST_ELEMENTS is required. | 3757 // FAST_ELEMENTS is required. |
| 3756 if (!boilerplate_value->IsSmi()) { | 3758 if (!boilerplate_value->IsSmi()) { |
| 3757 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { | 3759 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { |
| 3758 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to | 3760 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to |
| 3759 // avoid over-allocating in TENURED space. | 3761 // avoid over-allocating in TENURED space. |
| 3760 double_literals = isolate()->factory()->NewFixedDoubleArray( | 3762 double_literals = isolate()->factory()->NewFixedDoubleArray( |
| 3761 values->length(), TENURED); | 3763 values->length(), TENURED); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3780 // until the first value is seen that can't be stored as a double. | 3782 // until the first value is seen that can't be stored as a double. |
| 3781 if (boilerplate_value->IsNumber()) { | 3783 if (boilerplate_value->IsNumber()) { |
| 3782 double_literals->set(i, boilerplate_value->Number()); | 3784 double_literals->set(i, boilerplate_value->Number()); |
| 3783 } else { | 3785 } else { |
| 3784 elements_kind = FAST_ELEMENTS; | 3786 elements_kind = FAST_ELEMENTS; |
| 3785 } | 3787 } |
| 3786 } | 3788 } |
| 3787 } | 3789 } |
| 3788 } | 3790 } |
| 3789 | 3791 |
| 3792 // Very small array literals that don't have a concrete hint about their type |
| 3793 // from a constant value should default to the slow case to avoid lots of |
| 3794 // elements transitions on really small objects. |
| 3795 if (has_only_undefined_values && values->length() <= 2) { |
| 3796 elements_kind = FAST_ELEMENTS; |
| 3797 } |
| 3798 |
| 3790 // Simple and shallow arrays can be lazily copied, we transform the | 3799 // Simple and shallow arrays can be lazily copied, we transform the |
| 3791 // elements array to a copy-on-write array. | 3800 // elements array to a copy-on-write array. |
| 3792 if (is_simple && depth == 1 && values->length() > 0 && | 3801 if (is_simple && depth == 1 && values->length() > 0 && |
| 3793 elements_kind != FAST_DOUBLE_ELEMENTS) { | 3802 elements_kind != FAST_DOUBLE_ELEMENTS) { |
| 3794 object_literals->set_map(heap->fixed_cow_array_map()); | 3803 object_literals->set_map(heap->fixed_cow_array_map()); |
| 3795 } | 3804 } |
| 3796 | 3805 |
| 3797 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS | 3806 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS |
| 3798 ? Handle<FixedArrayBase>(double_literals) | 3807 ? Handle<FixedArrayBase>(double_literals) |
| 3799 : Handle<FixedArrayBase>(object_literals); | 3808 : Handle<FixedArrayBase>(object_literals); |
| (...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5974 ASSERT(info->isolate()->has_pending_exception()); | 5983 ASSERT(info->isolate()->has_pending_exception()); |
| 5975 } else { | 5984 } else { |
| 5976 result = parser.ParseProgram(); | 5985 result = parser.ParseProgram(); |
| 5977 } | 5986 } |
| 5978 } | 5987 } |
| 5979 info->SetFunction(result); | 5988 info->SetFunction(result); |
| 5980 return (result != NULL); | 5989 return (result != NULL); |
| 5981 } | 5990 } |
| 5982 | 5991 |
| 5983 } } // namespace v8::internal | 5992 } } // namespace v8::internal |
| OLD | NEW |