OLD | NEW |
---|---|
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 3359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3370 } | 3370 } |
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 | |
3380 ElementsKind elements_kind = FAST_SMI_ONLY_ELEMENTS; | 3381 ElementsKind elements_kind = FAST_SMI_ONLY_ELEMENTS; |
3382 bool has_ony_undefined_values = true; | |
Jakob Kummerow
2011/12/06 10:01:12
s/ony/only/
| |
3381 | 3383 |
3382 // Fill in the literals. | 3384 // Fill in the literals. |
3383 bool is_simple = true; | 3385 bool is_simple = true; |
3384 int depth = 1; | 3386 int depth = 1; |
3385 for (int i = 0, n = values->length(); i < n; i++) { | 3387 for (int i = 0, n = values->length(); i < n; i++) { |
3386 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); | 3388 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); |
3387 if (m_literal != NULL && m_literal->depth() + 1 > depth) { | 3389 if (m_literal != NULL && m_literal->depth() + 1 > depth) { |
3388 depth = m_literal->depth() + 1; | 3390 depth = m_literal->depth() + 1; |
3389 } | 3391 } |
3390 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); | 3392 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); |
3391 if (boilerplate_value->IsUndefined()) { | 3393 if (boilerplate_value->IsUndefined()) { |
3392 object_literals->set_the_hole(i); | 3394 object_literals->set_the_hole(i); |
3393 if (elements_kind == FAST_DOUBLE_ELEMENTS) { | 3395 if (elements_kind == FAST_DOUBLE_ELEMENTS) { |
3394 double_literals->set_the_hole(i); | 3396 double_literals->set_the_hole(i); |
3395 } | 3397 } |
3396 is_simple = false; | 3398 is_simple = false; |
3397 } else { | 3399 } else { |
3398 // Examine each literal element, and adjust the ElementsKind if the | 3400 // 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 | 3401 // 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 | 3402 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to |
3401 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember | 3403 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember |
3402 // the tagged value, no matter what the ElementsKind is in case we | 3404 // the tagged value, no matter what the ElementsKind is in case we |
3403 // ultimately end up in FAST_ELEMENTS. | 3405 // ultimately end up in FAST_ELEMENTS. |
3406 has_ony_undefined_values = false; | |
Jakob Kummerow
2011/12/06 10:01:12
s/ony/only/
| |
3404 object_literals->set(i, *boilerplate_value); | 3407 object_literals->set(i, *boilerplate_value); |
3405 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) { | 3408 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) { |
3406 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or | 3409 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or |
3407 // FAST_ELEMENTS is required. | 3410 // FAST_ELEMENTS is required. |
3408 if (!boilerplate_value->IsSmi()) { | 3411 if (!boilerplate_value->IsSmi()) { |
3409 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { | 3412 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { |
3410 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to | 3413 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to |
3411 // avoid over-allocating in TENURED space. | 3414 // avoid over-allocating in TENURED space. |
3412 double_literals = isolate()->factory()->NewFixedDoubleArray( | 3415 double_literals = isolate()->factory()->NewFixedDoubleArray( |
3413 values->length(), TENURED); | 3416 values->length(), TENURED); |
(...skipping 18 matching lines...) Expand all Loading... | |
3432 // until the first value is seen that can't be stored as a double. | 3435 // until the first value is seen that can't be stored as a double. |
3433 if (boilerplate_value->IsNumber()) { | 3436 if (boilerplate_value->IsNumber()) { |
3434 double_literals->set(i, boilerplate_value->Number()); | 3437 double_literals->set(i, boilerplate_value->Number()); |
3435 } else { | 3438 } else { |
3436 elements_kind = FAST_ELEMENTS; | 3439 elements_kind = FAST_ELEMENTS; |
3437 } | 3440 } |
3438 } | 3441 } |
3439 } | 3442 } |
3440 } | 3443 } |
3441 | 3444 |
3445 // Very small array literals that don't have a concrete hint about their type | |
3446 // from a constant value should default to the slow case to avoid lots of | |
3447 // elements transitions on really small objects. | |
3448 if (has_ony_undefined_values && values->length() <= 2) { | |
Jakob Kummerow
2011/12/06 10:01:12
s/ony/only/
| |
3449 elements_kind = FAST_ELEMENTS; | |
3450 } | |
3451 | |
3442 // Simple and shallow arrays can be lazily copied, we transform the | 3452 // Simple and shallow arrays can be lazily copied, we transform the |
3443 // elements array to a copy-on-write array. | 3453 // elements array to a copy-on-write array. |
3444 if (is_simple && depth == 1 && values->length() > 0 && | 3454 if (is_simple && depth == 1 && values->length() > 0 && |
3445 elements_kind != FAST_DOUBLE_ELEMENTS) { | 3455 elements_kind != FAST_DOUBLE_ELEMENTS) { |
3446 object_literals->set_map(isolate()->heap()->fixed_cow_array_map()); | 3456 object_literals->set_map(isolate()->heap()->fixed_cow_array_map()); |
3447 } | 3457 } |
3448 | 3458 |
3449 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS | 3459 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS |
3450 ? Handle<FixedArrayBase>(double_literals) | 3460 ? Handle<FixedArrayBase>(double_literals) |
3451 : Handle<FixedArrayBase>(object_literals); | 3461 : Handle<FixedArrayBase>(object_literals); |
(...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5666 ASSERT(info->isolate()->has_pending_exception()); | 5676 ASSERT(info->isolate()->has_pending_exception()); |
5667 } else { | 5677 } else { |
5668 result = parser.ParseProgram(info); | 5678 result = parser.ParseProgram(info); |
5669 } | 5679 } |
5670 } | 5680 } |
5671 info->SetFunction(result); | 5681 info->SetFunction(result); |
5672 return (result != NULL); | 5682 return (result != NULL); |
5673 } | 5683 } |
5674 | 5684 |
5675 } } // namespace v8::internal | 5685 } } // namespace v8::internal |
OLD | NEW |