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

Side by Side Diff: src/ast/ast.cc

Issue 2481363009: Revert of Compiling an array literal should be context-independent. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | src/elements.h » ('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 // 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"
11 #include "src/ast/scopes.h" 11 #include "src/ast/scopes.h"
12 #include "src/base/hashmap.h" 12 #include "src/base/hashmap.h"
13 #include "src/builtins/builtins.h" 13 #include "src/builtins/builtins.h"
14 #include "src/code-stubs.h" 14 #include "src/code-stubs.h"
15 #include "src/contexts.h" 15 #include "src/contexts.h"
16 #include "src/conversions.h" 16 #include "src/conversions.h"
17 #include "src/elements.h"
18 #include "src/property-details.h" 17 #include "src/property-details.h"
19 #include "src/property.h" 18 #include "src/property.h"
20 #include "src/string-stream.h" 19 #include "src/string-stream.h"
21 #include "src/type-info.h" 20 #include "src/type-info.h"
22 21
23 namespace v8 { 22 namespace v8 {
24 namespace internal { 23 namespace internal {
25 24
26 // ---------------------------------------------------------------------------- 25 // ----------------------------------------------------------------------------
27 // Implementation of other node functionality. 26 // Implementation of other node functionality.
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 set_depth(depth_acc); 573 set_depth(depth_acc);
575 } 574 }
576 575
577 576
578 void ArrayLiteral::BuildConstantElements(Isolate* isolate) { 577 void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
579 DCHECK_LT(first_spread_index_, 0); 578 DCHECK_LT(first_spread_index_, 0);
580 579
581 if (!constant_elements_.is_null()) return; 580 if (!constant_elements_.is_null()) return;
582 581
583 int constants_length = values()->length(); 582 int constants_length = values()->length();
584 ElementsKind kind = FIRST_FAST_ELEMENTS_KIND; 583
585 Handle<FixedArray> fixed_array = 584 // Allocate a fixed array to hold all the object literals.
586 isolate->factory()->NewFixedArrayWithHoles(constants_length); 585 Handle<JSArray> array = isolate->factory()->NewJSArray(
586 FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length,
587 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
587 588
588 // Fill in the literals. 589 // Fill in the literals.
589 bool is_simple = true; 590 bool is_simple = true;
590 int depth_acc = 1; 591 int depth_acc = 1;
591 bool is_holey = false; 592 bool is_holey = false;
592 int array_index = 0; 593 int array_index = 0;
593 for (; array_index < constants_length; array_index++) { 594 for (; array_index < constants_length; array_index++) {
594 Expression* element = values()->at(array_index); 595 Expression* element = values()->at(array_index);
595 DCHECK(!element->IsSpread()); 596 DCHECK(!element->IsSpread());
596 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); 597 MaterializedLiteral* m_literal = element->AsMaterializedLiteral();
(...skipping 10 matching lines...) Expand all
607 if (boilerplate_value->IsTheHole(isolate)) { 608 if (boilerplate_value->IsTheHole(isolate)) {
608 is_holey = true; 609 is_holey = true;
609 continue; 610 continue;
610 } 611 }
611 612
612 if (boilerplate_value->IsUninitialized(isolate)) { 613 if (boilerplate_value->IsUninitialized(isolate)) {
613 boilerplate_value = handle(Smi::kZero, isolate); 614 boilerplate_value = handle(Smi::kZero, isolate);
614 is_simple = false; 615 is_simple = false;
615 } 616 }
616 617
617 kind = GetMoreGeneralElementsKind(kind, 618 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE)
618 boilerplate_value->OptimalElementsKind()); 619 .Assert();
619 fixed_array->set(array_index, *boilerplate_value);
620 } 620 }
621 621
622 if (is_holey) kind = GetHoleyElementsKind(kind); 622 JSObject::ValidateElements(array);
623 Handle<FixedArrayBase> element_values(array->elements());
623 624
624 // Simple and shallow arrays can be lazily copied, we transform the 625 // Simple and shallow arrays can be lazily copied, we transform the
625 // elements array to a copy-on-write array. 626 // elements array to a copy-on-write array.
626 if (is_simple && depth_acc == 1 && array_index > 0 && 627 if (is_simple && depth_acc == 1 && array_index > 0 &&
627 IsFastSmiOrObjectElementsKind(kind)) { 628 array->HasFastSmiOrObjectElements()) {
628 fixed_array->set_map(isolate->heap()->fixed_cow_array_map()); 629 element_values->set_map(isolate->heap()->fixed_cow_array_map());
629 }
630
631 Handle<FixedArrayBase> elements = fixed_array;
632 if (IsFastDoubleElementsKind(kind)) {
633 ElementsAccessor* accessor = ElementsAccessor::ForKind(kind);
634 elements = isolate->factory()->NewFixedDoubleArray(constants_length);
635 // We are copying from non-fast-double to fast-double.
636 ElementsKind from_kind = TERMINAL_FAST_ELEMENTS_KIND;
637 accessor->CopyElements(fixed_array, from_kind, elements, constants_length);
638 } 630 }
639 631
640 // Remember both the literal's constant values as well as the ElementsKind 632 // Remember both the literal's constant values as well as the ElementsKind
641 // in a 2-element FixedArray. 633 // in a 2-element FixedArray.
642 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED); 634 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED);
635
636 ElementsKind kind = array->GetElementsKind();
637 kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind);
638
643 literals->set(0, Smi::FromInt(kind)); 639 literals->set(0, Smi::FromInt(kind));
644 literals->set(1, *elements); 640 literals->set(1, *element_values);
645 641
646 constant_elements_ = literals; 642 constant_elements_ = literals;
647 set_is_simple(is_simple); 643 set_is_simple(is_simple);
648 set_depth(depth_acc); 644 set_depth(depth_acc);
649 } 645 }
650 646
651 647
652 void ArrayLiteral::AssignFeedbackVectorSlots(Isolate* isolate, 648 void ArrayLiteral::AssignFeedbackVectorSlots(Isolate* isolate,
653 FeedbackVectorSpec* spec, 649 FeedbackVectorSpec* spec,
654 FeedbackVectorSlotCache* cache) { 650 FeedbackVectorSlotCache* cache) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 // static 943 // static
948 bool Literal::Match(void* literal1, void* literal2) { 944 bool Literal::Match(void* literal1, void* literal2) {
949 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 945 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
950 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 946 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
951 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 947 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
952 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 948 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
953 } 949 }
954 950
955 } // namespace internal 951 } // namespace internal
956 } // namespace v8 952 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/elements.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698