Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/parser.cc

Issue 11414155: Ensure double arrays are filled with holes when extended from variations of empty arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: u Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/stub-cache-ia32.cc ('k') | src/x64/stub-cache-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
3722 bool has_hole_values = false; 3721 bool has_hole_values = false;
3723 3722
3724 // Fill in the literals. 3723 // Fill in the literals.
3725 Heap* heap = isolate()->heap(); 3724 Heap* heap = isolate()->heap();
3726 bool is_simple = true; 3725 bool is_simple = true;
3727 int depth = 1; 3726 int depth = 1;
3728 for (int i = 0, n = values->length(); i < n; i++) { 3727 for (int i = 0, n = values->length(); i < n; i++) {
3729 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); 3728 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral();
3730 if (m_literal != NULL && m_literal->depth() + 1 > depth) { 3729 if (m_literal != NULL && m_literal->depth() + 1 > depth) {
3731 depth = m_literal->depth() + 1; 3730 depth = m_literal->depth() + 1;
(...skipping 11 matching lines...) Expand all
3743 if (elements_kind == FAST_DOUBLE_ELEMENTS) { 3742 if (elements_kind == FAST_DOUBLE_ELEMENTS) {
3744 double_literals->set(i, 0); 3743 double_literals->set(i, 0);
3745 } 3744 }
3746 } else { 3745 } else {
3747 // Examine each literal element, and adjust the ElementsKind if the 3746 // Examine each literal element, and adjust the ElementsKind if the
3748 // literal element is not of a type that can be stored in the current 3747 // literal element is not of a type that can be stored in the current
3749 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to 3748 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to
3750 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember 3749 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember
3751 // the tagged value, no matter what the ElementsKind is in case we 3750 // the tagged value, no matter what the ElementsKind is in case we
3752 // ultimately end up in FAST_ELEMENTS. 3751 // ultimately end up in FAST_ELEMENTS.
3753 has_only_undefined_values = false;
3754 object_literals->set(i, *boilerplate_value); 3752 object_literals->set(i, *boilerplate_value);
3755 if (elements_kind == FAST_SMI_ELEMENTS) { 3753 if (elements_kind == FAST_SMI_ELEMENTS) {
3756 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or 3754 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or
3757 // FAST_ELEMENTS is required. 3755 // FAST_ELEMENTS is required.
3758 if (!boilerplate_value->IsSmi()) { 3756 if (!boilerplate_value->IsSmi()) {
3759 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { 3757 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) {
3760 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to 3758 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to
3761 // avoid over-allocating in TENURED space. 3759 // avoid over-allocating in TENURED space.
3762 double_literals = isolate()->factory()->NewFixedDoubleArray( 3760 double_literals = isolate()->factory()->NewFixedDoubleArray(
3763 values->length(), TENURED); 3761 values->length(), TENURED);
(...skipping 18 matching lines...) Expand all
3782 // until the first value is seen that can't be stored as a double. 3780 // until the first value is seen that can't be stored as a double.
3783 if (boilerplate_value->IsNumber()) { 3781 if (boilerplate_value->IsNumber()) {
3784 double_literals->set(i, boilerplate_value->Number()); 3782 double_literals->set(i, boilerplate_value->Number());
3785 } else { 3783 } else {
3786 elements_kind = FAST_ELEMENTS; 3784 elements_kind = FAST_ELEMENTS;
3787 } 3785 }
3788 } 3786 }
3789 } 3787 }
3790 } 3788 }
3791 3789
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
3799 // Simple and shallow arrays can be lazily copied, we transform the 3790 // Simple and shallow arrays can be lazily copied, we transform the
3800 // elements array to a copy-on-write array. 3791 // elements array to a copy-on-write array.
3801 if (is_simple && depth == 1 && values->length() > 0 && 3792 if (is_simple && depth == 1 && values->length() > 0 &&
3802 elements_kind != FAST_DOUBLE_ELEMENTS) { 3793 elements_kind != FAST_DOUBLE_ELEMENTS) {
3803 object_literals->set_map(heap->fixed_cow_array_map()); 3794 object_literals->set_map(heap->fixed_cow_array_map());
3804 } 3795 }
3805 3796
3806 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS 3797 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS
3807 ? Handle<FixedArrayBase>(double_literals) 3798 ? Handle<FixedArrayBase>(double_literals)
3808 : Handle<FixedArrayBase>(object_literals); 3799 : Handle<FixedArrayBase>(object_literals);
(...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after
5983 ASSERT(info->isolate()->has_pending_exception()); 5974 ASSERT(info->isolate()->has_pending_exception());
5984 } else { 5975 } else {
5985 result = parser.ParseProgram(); 5976 result = parser.ParseProgram();
5986 } 5977 }
5987 } 5978 }
5988 info->SetFunction(result); 5979 info->SetFunction(result);
5989 return (result != NULL); 5980 return (result != NULL);
5990 } 5981 }
5991 5982
5992 } } // namespace v8::internal 5983 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/stub-cache-ia32.cc ('k') | src/x64/stub-cache-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698