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

Side by Side Diff: src/parser.cc

Issue 8816009: Don't track Smi->Double->Object element transitions for small undefined arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback Created 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3360 matching lines...) Expand 10 before | Expand all | Expand 10 after
3371 Expect(Token::RBRACK, CHECK_OK); 3371 Expect(Token::RBRACK, CHECK_OK);
3372 3372
3373 // Update the scope information before the pre-parsing bailout. 3373 // Update the scope information before the pre-parsing bailout.
3374 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); 3374 int literal_index = current_function_state_->NextMaterializedLiteralIndex();
3375 3375
3376 // Allocate a fixed array to hold all the object literals. 3376 // Allocate a fixed array to hold all the object literals.
3377 Handle<FixedArray> object_literals = 3377 Handle<FixedArray> object_literals =
3378 isolate()->factory()->NewFixedArray(values->length(), TENURED); 3378 isolate()->factory()->NewFixedArray(values->length(), TENURED);
3379 Handle<FixedDoubleArray> double_literals; 3379 Handle<FixedDoubleArray> double_literals;
3380 ElementsKind elements_kind = FAST_SMI_ONLY_ELEMENTS; 3380 ElementsKind elements_kind = FAST_SMI_ONLY_ELEMENTS;
3381 bool has_only_undefined_values = true;
3381 3382
3382 // Fill in the literals. 3383 // Fill in the literals.
3383 bool is_simple = true; 3384 bool is_simple = true;
3384 int depth = 1; 3385 int depth = 1;
3385 for (int i = 0, n = values->length(); i < n; i++) { 3386 for (int i = 0, n = values->length(); i < n; i++) {
3386 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); 3387 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral();
3387 if (m_literal != NULL && m_literal->depth() + 1 > depth) { 3388 if (m_literal != NULL && m_literal->depth() + 1 > depth) {
3388 depth = m_literal->depth() + 1; 3389 depth = m_literal->depth() + 1;
3389 } 3390 }
3390 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); 3391 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i));
3391 if (boilerplate_value->IsUndefined()) { 3392 if (boilerplate_value->IsUndefined()) {
3392 object_literals->set_the_hole(i); 3393 object_literals->set_the_hole(i);
3393 if (elements_kind == FAST_DOUBLE_ELEMENTS) { 3394 if (elements_kind == FAST_DOUBLE_ELEMENTS) {
3394 double_literals->set_the_hole(i); 3395 double_literals->set_the_hole(i);
3395 } 3396 }
3396 is_simple = false; 3397 is_simple = false;
3397 } else { 3398 } else {
3398 // Examine each literal element, and adjust the ElementsKind if the 3399 // Examine each literal element, and adjust the ElementsKind if the
3399 // literal element is not of a type that can be stored in the current 3400 // literal element is not of a type that can be stored in the current
3400 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to 3401 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to
3401 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember 3402 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember
3402 // the tagged value, no matter what the ElementsKind is in case we 3403 // the tagged value, no matter what the ElementsKind is in case we
3403 // ultimately end up in FAST_ELEMENTS. 3404 // ultimately end up in FAST_ELEMENTS.
3405 has_only_undefined_values = false;
3404 object_literals->set(i, *boilerplate_value); 3406 object_literals->set(i, *boilerplate_value);
3405 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) { 3407 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) {
3406 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or 3408 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or
3407 // FAST_ELEMENTS is required. 3409 // FAST_ELEMENTS is required.
3408 if (!boilerplate_value->IsSmi()) { 3410 if (!boilerplate_value->IsSmi()) {
3409 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { 3411 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) {
3410 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to 3412 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to
3411 // avoid over-allocating in TENURED space. 3413 // avoid over-allocating in TENURED space.
3412 double_literals = isolate()->factory()->NewFixedDoubleArray( 3414 double_literals = isolate()->factory()->NewFixedDoubleArray(
3413 values->length(), TENURED); 3415 values->length(), TENURED);
(...skipping 18 matching lines...) Expand all
3432 // until the first value is seen that can't be stored as a double. 3434 // until the first value is seen that can't be stored as a double.
3433 if (boilerplate_value->IsNumber()) { 3435 if (boilerplate_value->IsNumber()) {
3434 double_literals->set(i, boilerplate_value->Number()); 3436 double_literals->set(i, boilerplate_value->Number());
3435 } else { 3437 } else {
3436 elements_kind = FAST_ELEMENTS; 3438 elements_kind = FAST_ELEMENTS;
3437 } 3439 }
3438 } 3440 }
3439 } 3441 }
3440 } 3442 }
3441 3443
3444 // Very small array literals that don't have a concrete hint about their type
3445 // from a constant value should default to the slow case to avoid lots of
3446 // elements transitions on really small objects.
3447 if (has_only_undefined_values && values->length() <= 2) {
3448 elements_kind = FAST_ELEMENTS;
3449 }
3450
3442 // Simple and shallow arrays can be lazily copied, we transform the 3451 // Simple and shallow arrays can be lazily copied, we transform the
3443 // elements array to a copy-on-write array. 3452 // elements array to a copy-on-write array.
3444 if (is_simple && depth == 1 && values->length() > 0 && 3453 if (is_simple && depth == 1 && values->length() > 0 &&
3445 elements_kind != FAST_DOUBLE_ELEMENTS) { 3454 elements_kind != FAST_DOUBLE_ELEMENTS) {
3446 object_literals->set_map(isolate()->heap()->fixed_cow_array_map()); 3455 object_literals->set_map(isolate()->heap()->fixed_cow_array_map());
3447 } 3456 }
3448 3457
3449 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS 3458 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS
3450 ? Handle<FixedArrayBase>(double_literals) 3459 ? Handle<FixedArrayBase>(double_literals)
3451 : Handle<FixedArrayBase>(object_literals); 3460 : Handle<FixedArrayBase>(object_literals);
(...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after
5666 ASSERT(info->isolate()->has_pending_exception()); 5675 ASSERT(info->isolate()->has_pending_exception());
5667 } else { 5676 } else {
5668 result = parser.ParseProgram(info); 5677 result = parser.ParseProgram(info);
5669 } 5678 }
5670 } 5679 }
5671 info->SetFunction(result); 5680 info->SetFunction(result);
5672 return (result != NULL); 5681 return (result != NULL);
5673 } 5682 }
5674 5683
5675 } } // namespace v8::internal 5684 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698