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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/field-index.h" | 8 #include "src/field-index.h" |
9 #include "src/hydrogen.h" | 9 #include "src/hydrogen.h" |
10 #include "src/lithium.h" | 10 #include "src/lithium.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 return arguments_length_; | 56 return arguments_length_; |
57 } | 57 } |
58 CompilationInfo* info() { return &info_; } | 58 CompilationInfo* info() { return &info_; } |
59 HydrogenCodeStub* stub() { return info_.code_stub(); } | 59 HydrogenCodeStub* stub() { return info_.code_stub(); } |
60 HContext* context() { return context_; } | 60 HContext* context() { return context_; } |
61 Isolate* isolate() { return info_.isolate(); } | 61 Isolate* isolate() { return info_.isolate(); } |
62 | 62 |
63 HLoadNamedField* BuildLoadNamedField(HValue* object, | 63 HLoadNamedField* BuildLoadNamedField(HValue* object, |
64 FieldIndex index); | 64 FieldIndex index); |
65 void BuildStoreNamedField(HValue* object, HValue* value, FieldIndex index, | 65 void BuildStoreNamedField(HValue* object, HValue* value, FieldIndex index, |
66 Representation representation); | 66 Representation representation, |
67 bool transition_to_field); | |
67 | 68 |
68 enum ArgumentClass { | 69 enum ArgumentClass { |
69 NONE, | 70 NONE, |
70 SINGLE, | 71 SINGLE, |
71 MULTIPLE | 72 MULTIPLE |
72 }; | 73 }; |
73 | 74 |
74 HValue* BuildArrayConstructor(ElementsKind kind, | 75 HValue* BuildArrayConstructor(ElementsKind kind, |
75 AllocationSiteOverrideMode override_mode, | 76 AllocationSiteOverrideMode override_mode, |
76 ArgumentClass argument_class); | 77 ArgumentClass argument_class); |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 return Add<HLoadNamedField>(descriptors, static_cast<HValue*>(NULL), | 596 return Add<HLoadNamedField>(descriptors, static_cast<HValue*>(NULL), |
596 value_access); | 597 value_access); |
597 } | 598 } |
598 | 599 |
599 | 600 |
600 Handle<Code> LoadConstantStub::GenerateCode() { return DoGenerateCode(this); } | 601 Handle<Code> LoadConstantStub::GenerateCode() { return DoGenerateCode(this); } |
601 | 602 |
602 | 603 |
603 void CodeStubGraphBuilderBase::BuildStoreNamedField( | 604 void CodeStubGraphBuilderBase::BuildStoreNamedField( |
604 HValue* object, HValue* value, FieldIndex index, | 605 HValue* object, HValue* value, FieldIndex index, |
605 Representation representation) { | 606 Representation representation, bool transition_to_field) { |
606 DCHECK(!index.is_double() || representation.IsDouble()); | 607 DCHECK(!index.is_double() || representation.IsDouble()); |
607 int offset = index.offset(); | 608 int offset = index.offset(); |
608 HObjectAccess access = | 609 HObjectAccess access = |
609 index.is_inobject() | 610 index.is_inobject() |
610 ? HObjectAccess::ForObservableJSObjectOffset(offset, representation) | 611 ? HObjectAccess::ForObservableJSObjectOffset(offset, representation) |
611 : HObjectAccess::ForBackingStoreOffset(offset, representation); | 612 : HObjectAccess::ForBackingStoreOffset(offset, representation); |
612 | 613 |
613 if (representation.IsDouble()) { | 614 if (representation.IsDouble()) { |
614 // Load the heap number. | 615 HObjectAccess heap_number_access = |
615 object = Add<HLoadNamedField>( | 616 access.WithRepresentation(Representation::Tagged()); |
616 object, static_cast<HValue*>(NULL), | 617 if (transition_to_field) { |
617 access.WithRepresentation(Representation::Tagged())); | 618 // The store requires a mutable HeapNumber to be allocated. |
618 // Store the double value into it. | 619 NoObservableSideEffectsScope no_side_effects(this); |
619 access = HObjectAccess::ForHeapNumberValue(); | 620 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize); |
621 | |
622 // TODO(hpayer): Allocation site pretenuring support. | |
623 HInstruction* heap_number = | |
624 Add<HAllocate>(heap_number_size, HType::HeapObject(), NOT_TENURED, | |
625 MUTABLE_HEAP_NUMBER_TYPE); | |
626 AddStoreMapConstant(heap_number, | |
627 isolate()->factory()->mutable_heap_number_map()); | |
628 Add<HStoreNamedField>(heap_number, HObjectAccess::ForHeapNumberValue(), | |
629 value); | |
630 // Store the new mutable heap number into the object. | |
631 access = heap_number_access; | |
632 value = heap_number; | |
633 } else { | |
634 // Load the heap number. | |
635 object = Add<HLoadNamedField>(object, static_cast<HValue*>(NULL), | |
636 heap_number_access); | |
637 // Store the double value into it. | |
638 access = HObjectAccess::ForHeapNumberValue(); | |
639 } | |
620 } else if (representation.IsHeapObject()) { | 640 } else if (representation.IsHeapObject()) { |
621 BuildCheckHeapObject(value); | 641 BuildCheckHeapObject(value); |
622 } | 642 } |
623 | 643 |
624 Add<HStoreNamedField>(object, access, value, INITIALIZING_STORE); | 644 Add<HStoreNamedField>(object, access, value, INITIALIZING_STORE); |
625 } | 645 } |
626 | 646 |
627 | 647 |
628 template <> | 648 template <> |
629 HValue* CodeStubGraphBuilder<StoreFieldStub>::BuildCodeStub() { | 649 HValue* CodeStubGraphBuilder<StoreFieldStub>::BuildCodeStub() { |
630 BuildStoreNamedField(GetParameter(0), GetParameter(2), casted_stub()->index(), | 650 BuildStoreNamedField(GetParameter(0), GetParameter(2), casted_stub()->index(), |
631 casted_stub()->representation()); | 651 casted_stub()->representation(), false); |
632 return GetParameter(2); | 652 return GetParameter(2); |
633 } | 653 } |
634 | 654 |
635 | 655 |
636 Handle<Code> StoreFieldStub::GenerateCode() { return DoGenerateCode(this); } | 656 Handle<Code> StoreFieldStub::GenerateCode() { return DoGenerateCode(this); } |
637 | 657 |
638 | 658 |
639 template <> | 659 template <> |
660 HValue* CodeStubGraphBuilder<ExtendStorageStub>::BuildCodeStub() { | |
661 HValue* object = GetParameter(ExtendStorageDescriptor::kReceiverIndex); | |
662 HValue* properties = | |
663 Add<HLoadNamedField>(object, static_cast<HValue*>(NULL), | |
664 HObjectAccess::ForPropertiesPointer()); | |
665 HValue* length = AddLoadFixedArrayLength(properties); | |
666 HValue* delta = Add<HConstant>(static_cast<int32_t>(JSObject::kFieldsAdded)); | |
667 HValue* new_capacity = AddUncasted<HAdd>(length, delta); | |
668 | |
669 // Grow properties array. | |
670 ElementsKind kind = FAST_ELEMENTS; | |
671 Add<HBoundsCheck>(new_capacity, | |
672 Add<HConstant>((Page::kMaxRegularHeapObjectSize - | |
673 FixedArray::kHeaderSize) >> | |
674 ElementsKindToShiftSize(kind))); | |
675 | |
676 // Reuse this code for properties backing store allocation. | |
677 HValue* new_properties = | |
678 BuildAllocateElementsAndInitializeElementsHeader(kind, new_capacity); | |
Yang
2014/09/29 11:10:38
The name of that function is now somewhat misleadi
Igor Sheludko
2014/09/29 12:33:11
Done.
| |
679 | |
680 BuildCopyProperties(properties, new_properties, length, new_capacity); | |
681 | |
682 // Store the new value into the "extended" object. | |
683 Add<HStoreNamedField>(object, HObjectAccess::ForPropertiesPointer(), | |
684 new_properties); | |
685 | |
686 BuildStoreNamedField(GetParameter(ExtendStorageDescriptor::kReceiverIndex), | |
Yang
2014/09/29 11:10:38
Isn't this just 'object'?
Igor Sheludko
2014/09/29 12:33:11
Done.
| |
687 GetParameter(ExtendStorageDescriptor::kValueIndex), | |
688 casted_stub()->index(), casted_stub()->representation(), | |
689 true); | |
690 | |
691 // And finally update the map after the new field is added. | |
692 Add<HStoreNamedField>(object, HObjectAccess::ForMap(), | |
693 GetParameter(ExtendStorageDescriptor::kMapIndex)); | |
694 | |
695 return GetParameter(ExtendStorageDescriptor::kValueIndex); | |
696 } | |
697 | |
698 | |
699 Handle<Code> ExtendStorageStub::GenerateCode() { return DoGenerateCode(this); } | |
700 | |
701 | |
702 template <> | |
640 HValue* CodeStubGraphBuilder<StringLengthStub>::BuildCodeStub() { | 703 HValue* CodeStubGraphBuilder<StringLengthStub>::BuildCodeStub() { |
641 HValue* string = BuildLoadNamedField(GetParameter(0), | 704 HValue* string = BuildLoadNamedField(GetParameter(0), |
642 FieldIndex::ForInObjectOffset(JSValue::kValueOffset)); | 705 FieldIndex::ForInObjectOffset(JSValue::kValueOffset)); |
643 return BuildLoadNamedField(string, | 706 return BuildLoadNamedField(string, |
644 FieldIndex::ForInObjectOffset(String::kLengthOffset)); | 707 FieldIndex::ForInObjectOffset(String::kLengthOffset)); |
645 } | 708 } |
646 | 709 |
647 | 710 |
648 Handle<Code> StringLengthStub::GenerateCode() { | 711 Handle<Code> StringLengthStub::GenerateCode() { |
649 return DoGenerateCode(this); | 712 return DoGenerateCode(this); |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1823 | 1886 |
1824 // Probe the stub cache. | 1887 // Probe the stub cache. |
1825 Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( | 1888 Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( |
1826 Code::ComputeHandlerFlags(Code::LOAD_IC)); | 1889 Code::ComputeHandlerFlags(Code::LOAD_IC)); |
1827 Add<HTailCallThroughMegamorphicCache>(receiver, name, flags); | 1890 Add<HTailCallThroughMegamorphicCache>(receiver, name, flags); |
1828 | 1891 |
1829 // We never continue. | 1892 // We never continue. |
1830 return graph()->GetConstant0(); | 1893 return graph()->GetConstant0(); |
1831 } | 1894 } |
1832 } } // namespace v8::internal | 1895 } } // namespace v8::internal |
OLD | NEW |