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 3749 matching lines...) Loading... |
3760 } | 3760 } |
3761 Expect(Token::RBRACK, CHECK_OK); | 3761 Expect(Token::RBRACK, CHECK_OK); |
3762 | 3762 |
3763 // Update the scope information before the pre-parsing bailout. | 3763 // Update the scope information before the pre-parsing bailout. |
3764 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); | 3764 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); |
3765 | 3765 |
3766 // Allocate a fixed array to hold all the object literals. | 3766 // Allocate a fixed array to hold all the object literals. |
3767 Handle<FixedArray> object_literals = | 3767 Handle<FixedArray> object_literals = |
3768 isolate()->factory()->NewFixedArray(values->length(), TENURED); | 3768 isolate()->factory()->NewFixedArray(values->length(), TENURED); |
3769 Handle<FixedDoubleArray> double_literals; | 3769 Handle<FixedDoubleArray> double_literals; |
3770 ElementsKind elements_kind = FAST_SMI_ONLY_ELEMENTS; | 3770 ElementsKind elements_kind = FAST_SMI_ELEMENTS; |
3771 bool has_only_undefined_values = true; | 3771 bool has_only_undefined_values = true; |
| 3772 bool has_hole_values = false; |
3772 | 3773 |
3773 // Fill in the literals. | 3774 // Fill in the literals. |
| 3775 Heap* heap = isolate()->heap(); |
3774 bool is_simple = true; | 3776 bool is_simple = true; |
3775 int depth = 1; | 3777 int depth = 1; |
3776 for (int i = 0, n = values->length(); i < n; i++) { | 3778 for (int i = 0, n = values->length(); i < n; i++) { |
3777 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); | 3779 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); |
3778 if (m_literal != NULL && m_literal->depth() + 1 > depth) { | 3780 if (m_literal != NULL && m_literal->depth() + 1 > depth) { |
3779 depth = m_literal->depth() + 1; | 3781 depth = m_literal->depth() + 1; |
3780 } | 3782 } |
3781 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); | 3783 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); |
3782 if (boilerplate_value->IsUndefined()) { | 3784 if (boilerplate_value->IsTheHole()) { |
| 3785 has_hole_values = true; |
3783 object_literals->set_the_hole(i); | 3786 object_literals->set_the_hole(i); |
3784 if (elements_kind == FAST_DOUBLE_ELEMENTS) { | 3787 if (elements_kind == FAST_DOUBLE_ELEMENTS) { |
3785 double_literals->set_the_hole(i); | 3788 double_literals->set_the_hole(i); |
3786 } | 3789 } |
| 3790 } else if (boilerplate_value->IsUndefined()) { |
3787 is_simple = false; | 3791 is_simple = false; |
| 3792 object_literals->set(i, Smi::FromInt(0)); |
| 3793 if (elements_kind == FAST_DOUBLE_ELEMENTS) { |
| 3794 double_literals->set(i, 0); |
| 3795 } |
3788 } else { | 3796 } else { |
3789 // Examine each literal element, and adjust the ElementsKind if the | 3797 // Examine each literal element, and adjust the ElementsKind if the |
3790 // literal element is not of a type that can be stored in the current | 3798 // literal element is not of a type that can be stored in the current |
3791 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to | 3799 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to |
3792 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember | 3800 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember |
3793 // the tagged value, no matter what the ElementsKind is in case we | 3801 // the tagged value, no matter what the ElementsKind is in case we |
3794 // ultimately end up in FAST_ELEMENTS. | 3802 // ultimately end up in FAST_ELEMENTS. |
3795 has_only_undefined_values = false; | 3803 has_only_undefined_values = false; |
3796 object_literals->set(i, *boilerplate_value); | 3804 object_literals->set(i, *boilerplate_value); |
3797 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) { | 3805 if (elements_kind == FAST_SMI_ELEMENTS) { |
3798 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or | 3806 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or |
3799 // FAST_ELEMENTS is required. | 3807 // FAST_ELEMENTS is required. |
3800 if (!boilerplate_value->IsSmi()) { | 3808 if (!boilerplate_value->IsSmi()) { |
3801 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { | 3809 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { |
3802 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to | 3810 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to |
3803 // avoid over-allocating in TENURED space. | 3811 // avoid over-allocating in TENURED space. |
3804 double_literals = isolate()->factory()->NewFixedDoubleArray( | 3812 double_literals = isolate()->factory()->NewFixedDoubleArray( |
3805 values->length(), TENURED); | 3813 values->length(), TENURED); |
3806 // Copy the contents of the FAST_SMI_ONLY_ELEMENT array to the | 3814 // Copy the contents of the FAST_SMI_ONLY_ELEMENT array to the |
3807 // FAST_DOUBLE_ELEMENTS array so that they are in sync. | 3815 // FAST_DOUBLE_ELEMENTS array so that they are in sync. |
(...skipping 27 matching lines...) Loading... |
3835 // from a constant value should default to the slow case to avoid lots of | 3843 // from a constant value should default to the slow case to avoid lots of |
3836 // elements transitions on really small objects. | 3844 // elements transitions on really small objects. |
3837 if (has_only_undefined_values && values->length() <= 2) { | 3845 if (has_only_undefined_values && values->length() <= 2) { |
3838 elements_kind = FAST_ELEMENTS; | 3846 elements_kind = FAST_ELEMENTS; |
3839 } | 3847 } |
3840 | 3848 |
3841 // Simple and shallow arrays can be lazily copied, we transform the | 3849 // Simple and shallow arrays can be lazily copied, we transform the |
3842 // elements array to a copy-on-write array. | 3850 // elements array to a copy-on-write array. |
3843 if (is_simple && depth == 1 && values->length() > 0 && | 3851 if (is_simple && depth == 1 && values->length() > 0 && |
3844 elements_kind != FAST_DOUBLE_ELEMENTS) { | 3852 elements_kind != FAST_DOUBLE_ELEMENTS) { |
3845 object_literals->set_map(isolate()->heap()->fixed_cow_array_map()); | 3853 object_literals->set_map(heap->fixed_cow_array_map()); |
3846 } | 3854 } |
3847 | 3855 |
3848 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS | 3856 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS |
3849 ? Handle<FixedArrayBase>(double_literals) | 3857 ? Handle<FixedArrayBase>(double_literals) |
3850 : Handle<FixedArrayBase>(object_literals); | 3858 : Handle<FixedArrayBase>(object_literals); |
3851 | 3859 |
3852 // Remember both the literal's constant values as well as the ElementsKind | 3860 // Remember both the literal's constant values as well as the ElementsKind |
3853 // in a 2-element FixedArray. | 3861 // in a 2-element FixedArray. |
3854 Handle<FixedArray> literals = | 3862 Handle<FixedArray> literals = |
3855 isolate()->factory()->NewFixedArray(2, TENURED); | 3863 isolate()->factory()->NewFixedArray(2, TENURED); |
3856 | 3864 |
| 3865 if (has_hole_values || !FLAG_packed_arrays) { |
| 3866 elements_kind = GetHoleyElementsKind(elements_kind); |
| 3867 } |
| 3868 |
3857 literals->set(0, Smi::FromInt(elements_kind)); | 3869 literals->set(0, Smi::FromInt(elements_kind)); |
3858 literals->set(1, *element_values); | 3870 literals->set(1, *element_values); |
3859 | 3871 |
3860 return factory()->NewArrayLiteral( | 3872 return factory()->NewArrayLiteral( |
3861 literals, values, literal_index, is_simple, depth); | 3873 literals, values, literal_index, is_simple, depth); |
3862 } | 3874 } |
3863 | 3875 |
3864 | 3876 |
3865 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 3877 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
3866 return property != NULL && | 3878 return property != NULL && |
(...skipping 2163 matching lines...) Loading... |
6030 ASSERT(info->isolate()->has_pending_exception()); | 6042 ASSERT(info->isolate()->has_pending_exception()); |
6031 } else { | 6043 } else { |
6032 result = parser.ParseProgram(info); | 6044 result = parser.ParseProgram(info); |
6033 } | 6045 } |
6034 } | 6046 } |
6035 info->SetFunction(result); | 6047 info->SetFunction(result); |
6036 return (result != NULL); | 6048 return (result != NULL); |
6037 } | 6049 } |
6038 | 6050 |
6039 } } // namespace v8::internal | 6051 } } // namespace v8::internal |
OLD | NEW |