Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/ast/ast.h" | 5 #include "src/ast/ast.h" |
| 6 | 6 |
| 7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
| 8 | 8 |
| 9 #include "src/ast/compile-time-value.h" | 9 #include "src/ast/compile-time-value.h" |
| 10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 set_depth(depth_acc); | 573 set_depth(depth_acc); |
| 574 } | 574 } |
| 575 | 575 |
| 576 | 576 |
| 577 void ArrayLiteral::BuildConstantElements(Isolate* isolate) { | 577 void ArrayLiteral::BuildConstantElements(Isolate* isolate) { |
| 578 DCHECK_LT(first_spread_index_, 0); | 578 DCHECK_LT(first_spread_index_, 0); |
| 579 | 579 |
| 580 if (!constant_elements_.is_null()) return; | 580 if (!constant_elements_.is_null()) return; |
| 581 | 581 |
| 582 int constants_length = values()->length(); | 582 int constants_length = values()->length(); |
| 583 | 583 ElementsKind kind = FAST_SMI_ELEMENTS; |
|
Toon Verwaest
2016/11/08 10:18:02
FIRST_FAST_ELEMENTS_KIND?
Yang
2016/11/09 07:32:23
Done.
| |
| 584 // Allocate a fixed array to hold all the object literals. | 584 Handle<FixedArray> fixed_array = |
| 585 Handle<JSArray> array = isolate->factory()->NewJSArray( | 585 isolate->factory()->NewFixedArrayWithHoles(constants_length); |
| 586 FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length, | |
| 587 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | |
| 588 | 586 |
| 589 // Fill in the literals. | 587 // Fill in the literals. |
| 590 bool is_simple = true; | 588 bool is_simple = true; |
| 591 int depth_acc = 1; | 589 int depth_acc = 1; |
| 592 bool is_holey = false; | 590 bool is_holey = false; |
| 593 int array_index = 0; | 591 int array_index = 0; |
| 594 for (; array_index < constants_length; array_index++) { | 592 for (; array_index < constants_length; array_index++) { |
| 595 Expression* element = values()->at(array_index); | 593 Expression* element = values()->at(array_index); |
| 596 DCHECK(!element->IsSpread()); | 594 DCHECK(!element->IsSpread()); |
| 597 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); | 595 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); |
| 598 if (m_literal != NULL) { | 596 if (m_literal != NULL) { |
| 599 m_literal->BuildConstants(isolate); | 597 m_literal->BuildConstants(isolate); |
| 600 if (m_literal->depth() + 1 > depth_acc) { | 598 if (m_literal->depth() + 1 > depth_acc) { |
| 601 depth_acc = m_literal->depth() + 1; | 599 depth_acc = m_literal->depth() + 1; |
| 602 } | 600 } |
| 603 } | 601 } |
| 604 | 602 |
| 605 // New handle scope here, needs to be after BuildContants(). | 603 // New handle scope here, needs to be after BuildContants(). |
| 606 HandleScope scope(isolate); | 604 HandleScope scope(isolate); |
| 607 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate); | 605 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate); |
| 608 if (boilerplate_value->IsTheHole(isolate)) { | 606 if (boilerplate_value->IsTheHole(isolate)) { |
| 609 is_holey = true; | 607 is_holey = true; |
|
Toon Verwaest
2016/11/08 10:16:54
if you already do kind = GetHoleyElementsKind(kind
Yang
2016/11/09 07:32:23
Unfortunately this does not work due to how GetMor
| |
| 610 continue; | 608 continue; |
| 611 } | 609 } |
| 612 | 610 |
| 613 if (boilerplate_value->IsUninitialized(isolate)) { | 611 if (boilerplate_value->IsUninitialized(isolate)) { |
| 614 boilerplate_value = handle(Smi::kZero, isolate); | 612 boilerplate_value = handle(Smi::kZero, isolate); |
| 615 is_simple = false; | 613 is_simple = false; |
| 616 } | 614 } |
| 617 | 615 |
| 618 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE) | 616 kind = GetMoreGeneralElementsKind(kind, |
| 619 .Assert(); | 617 boilerplate_value->OptimalElementsKind()); |
| 618 fixed_array->set(array_index, *boilerplate_value); | |
| 620 } | 619 } |
| 621 | 620 |
| 622 JSObject::ValidateElements(array); | |
| 623 Handle<FixedArrayBase> element_values(array->elements()); | |
| 624 | |
| 625 // Simple and shallow arrays can be lazily copied, we transform the | 621 // Simple and shallow arrays can be lazily copied, we transform the |
| 626 // elements array to a copy-on-write array. | 622 // elements array to a copy-on-write array. |
| 627 if (is_simple && depth_acc == 1 && array_index > 0 && | 623 if (is_simple && depth_acc == 1 && array_index > 0 && |
| 628 array->HasFastSmiOrObjectElements()) { | 624 IsFastSmiOrObjectElementsKind(kind)) { |
| 629 element_values->set_map(isolate->heap()->fixed_cow_array_map()); | 625 fixed_array->set_map(isolate->heap()->fixed_cow_array_map()); |
| 630 } | 626 } |
| 631 | 627 |
| 628 Handle<FixedArrayBase> elements = fixed_array; | |
| 629 | |
| 630 // In case of only double elements, copy over into a FixedDoubleArray. | |
| 631 if (IsFastDoubleElementsKind(kind)) { | |
| 632 Handle<FixedDoubleArray> fixed_double_array = | |
| 633 Handle<FixedDoubleArray>::cast( | |
| 634 isolate->factory()->NewFixedDoubleArray(constants_length)); | |
| 635 for (int i = 0; i < constants_length; i++) { | |
| 636 Object* element = fixed_array->get(i); | |
| 637 if (element->IsTheHole(isolate)) { | |
| 638 DCHECK(is_holey); | |
| 639 fixed_double_array->set_the_hole(i); | |
| 640 } else { | |
| 641 fixed_double_array->set(i, element->Number()); | |
|
Toon Verwaest
2016/11/08 10:16:54
What about having a CopyElements on the elements a
Yang
2016/11/09 07:32:23
Done.
| |
| 642 } | |
| 643 } | |
| 644 elements = fixed_double_array; | |
| 645 } | |
| 646 | |
| 647 if (is_holey) kind = GetHoleyElementsKind(kind); | |
| 648 | |
| 632 // Remember both the literal's constant values as well as the ElementsKind | 649 // Remember both the literal's constant values as well as the ElementsKind |
| 633 // in a 2-element FixedArray. | 650 // in a 2-element FixedArray. |
| 634 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED); | 651 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED); |
| 635 | |
| 636 ElementsKind kind = array->GetElementsKind(); | |
| 637 kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind); | |
| 638 | |
| 639 literals->set(0, Smi::FromInt(kind)); | 652 literals->set(0, Smi::FromInt(kind)); |
| 640 literals->set(1, *element_values); | 653 literals->set(1, *elements); |
| 641 | 654 |
| 642 constant_elements_ = literals; | 655 constant_elements_ = literals; |
| 643 set_is_simple(is_simple); | 656 set_is_simple(is_simple); |
| 644 set_depth(depth_acc); | 657 set_depth(depth_acc); |
| 645 } | 658 } |
| 646 | 659 |
| 647 | 660 |
| 648 void ArrayLiteral::AssignFeedbackVectorSlots(Isolate* isolate, | 661 void ArrayLiteral::AssignFeedbackVectorSlots(Isolate* isolate, |
| 649 FeedbackVectorSpec* spec, | 662 FeedbackVectorSpec* spec, |
| 650 FeedbackVectorSlotCache* cache) { | 663 FeedbackVectorSlotCache* cache) { |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 943 // static | 956 // static |
| 944 bool Literal::Match(void* literal1, void* literal2) { | 957 bool Literal::Match(void* literal1, void* literal2) { |
| 945 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 958 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
| 946 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 959 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
| 947 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || | 960 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || |
| 948 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 961 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
| 949 } | 962 } |
| 950 | 963 |
| 951 } // namespace internal | 964 } // namespace internal |
| 952 } // namespace v8 | 965 } // namespace v8 |
| OLD | NEW |