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

Side by Side Diff: src/parser.cc

Issue 11377132: Support all fast elements kinds in the major array operations. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments (and rebased) Created 8 years, 1 month 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/objects-inl.h ('k') | src/runtime.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 3697 matching lines...) Expand 10 before | Expand all | Expand 10 after
3708 Expect(Token::RBRACK, CHECK_OK); 3708 Expect(Token::RBRACK, CHECK_OK);
3709 3709
3710 // Update the scope information before the pre-parsing bailout. 3710 // Update the scope information before the pre-parsing bailout.
3711 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); 3711 int literal_index = current_function_state_->NextMaterializedLiteralIndex();
3712 3712
3713 // Allocate a fixed array to hold all the object literals. 3713 // Allocate a fixed array to hold all the object literals.
3714 Handle<FixedArray> object_literals = 3714 Handle<FixedArray> object_literals =
3715 isolate()->factory()->NewFixedArray(values->length(), TENURED); 3715 isolate()->factory()->NewFixedArray(values->length(), TENURED);
3716 Handle<FixedDoubleArray> double_literals; 3716 Handle<FixedDoubleArray> double_literals;
3717 ElementsKind elements_kind = FAST_SMI_ELEMENTS; 3717 ElementsKind elements_kind = FAST_SMI_ELEMENTS;
3718 bool has_only_undefined_values = true;
3719 bool has_hole_values = false; 3718 bool has_hole_values = false;
3720 3719
3721 // Fill in the literals. 3720 // Fill in the literals.
3722 Heap* heap = isolate()->heap(); 3721 Heap* heap = isolate()->heap();
3723 bool is_simple = true; 3722 bool is_simple = true;
3724 int depth = 1; 3723 int depth = 1;
3725 for (int i = 0, n = values->length(); i < n; i++) { 3724 for (int i = 0, n = values->length(); i < n; i++) {
3726 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); 3725 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral();
3727 if (m_literal != NULL && m_literal->depth() + 1 > depth) { 3726 if (m_literal != NULL && m_literal->depth() + 1 > depth) {
3728 depth = m_literal->depth() + 1; 3727 depth = m_literal->depth() + 1;
(...skipping 11 matching lines...) Expand all
3740 if (elements_kind == FAST_DOUBLE_ELEMENTS) { 3739 if (elements_kind == FAST_DOUBLE_ELEMENTS) {
3741 double_literals->set(i, 0); 3740 double_literals->set(i, 0);
3742 } 3741 }
3743 } else { 3742 } else {
3744 // Examine each literal element, and adjust the ElementsKind if the 3743 // Examine each literal element, and adjust the ElementsKind if the
3745 // literal element is not of a type that can be stored in the current 3744 // literal element is not of a type that can be stored in the current
3746 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to 3745 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to
3747 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember 3746 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember
3748 // the tagged value, no matter what the ElementsKind is in case we 3747 // the tagged value, no matter what the ElementsKind is in case we
3749 // ultimately end up in FAST_ELEMENTS. 3748 // ultimately end up in FAST_ELEMENTS.
3750 has_only_undefined_values = false;
3751 object_literals->set(i, *boilerplate_value); 3749 object_literals->set(i, *boilerplate_value);
3752 if (elements_kind == FAST_SMI_ELEMENTS) { 3750 if (elements_kind == FAST_SMI_ELEMENTS) {
3753 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or 3751 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or
3754 // FAST_ELEMENTS is required. 3752 // FAST_ELEMENTS is required.
3755 if (!boilerplate_value->IsSmi()) { 3753 if (!boilerplate_value->IsSmi()) {
3756 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { 3754 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) {
3757 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to 3755 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to
3758 // avoid over-allocating in TENURED space. 3756 // avoid over-allocating in TENURED space.
3759 double_literals = isolate()->factory()->NewFixedDoubleArray( 3757 double_literals = isolate()->factory()->NewFixedDoubleArray(
3760 values->length(), TENURED); 3758 values->length(), TENURED);
(...skipping 18 matching lines...) Expand all
3779 // until the first value is seen that can't be stored as a double. 3777 // until the first value is seen that can't be stored as a double.
3780 if (boilerplate_value->IsNumber()) { 3778 if (boilerplate_value->IsNumber()) {
3781 double_literals->set(i, boilerplate_value->Number()); 3779 double_literals->set(i, boilerplate_value->Number());
3782 } else { 3780 } else {
3783 elements_kind = FAST_ELEMENTS; 3781 elements_kind = FAST_ELEMENTS;
3784 } 3782 }
3785 } 3783 }
3786 } 3784 }
3787 } 3785 }
3788 3786
3789 // Very small array literals that don't have a concrete hint about their type
3790 // from a constant value should default to the slow case to avoid lots of
3791 // elements transitions on really small objects.
3792 if (has_only_undefined_values && values->length() <= 2) {
3793 elements_kind = FAST_ELEMENTS;
3794 }
3795
3796 // Simple and shallow arrays can be lazily copied, we transform the 3787 // Simple and shallow arrays can be lazily copied, we transform the
3797 // elements array to a copy-on-write array. 3788 // elements array to a copy-on-write array.
3798 if (is_simple && depth == 1 && values->length() > 0 && 3789 if (is_simple && depth == 1 && values->length() > 0 &&
3799 elements_kind != FAST_DOUBLE_ELEMENTS) { 3790 elements_kind != FAST_DOUBLE_ELEMENTS) {
3800 object_literals->set_map(heap->fixed_cow_array_map()); 3791 object_literals->set_map(heap->fixed_cow_array_map());
3801 } 3792 }
3802 3793
3803 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS 3794 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS
3804 ? Handle<FixedArrayBase>(double_literals) 3795 ? Handle<FixedArrayBase>(double_literals)
3805 : Handle<FixedArrayBase>(object_literals); 3796 : Handle<FixedArrayBase>(object_literals);
(...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after
5980 ASSERT(info->isolate()->has_pending_exception()); 5971 ASSERT(info->isolate()->has_pending_exception());
5981 } else { 5972 } else {
5982 result = parser.ParseProgram(); 5973 result = parser.ParseProgram();
5983 } 5974 }
5984 } 5975 }
5985 info->SetFunction(result); 5976 info->SetFunction(result);
5986 return (result != NULL); 5977 return (result != NULL);
5987 } 5978 }
5988 5979
5989 } } // namespace v8::internal 5980 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698