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/code-stubs.h" | 5 #include "src/code-stubs.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 5128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5139 descriptor->Initialize( | 5139 descriptor->Initialize( |
5140 FUNCTION_ADDR(Runtime_TransitionStoreIC_MissFromStubFailure)); | 5140 FUNCTION_ADDR(Runtime_TransitionStoreIC_MissFromStubFailure)); |
5141 } | 5141 } |
5142 | 5142 |
5143 void NumberToStringStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { | 5143 void NumberToStringStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { |
5144 descriptor->Initialize( | 5144 descriptor->Initialize( |
5145 Runtime::FunctionForId(Runtime::kNumberToString)->entry); | 5145 Runtime::FunctionForId(Runtime::kNumberToString)->entry); |
5146 descriptor->SetMissHandler(Runtime::kNumberToString); | 5146 descriptor->SetMissHandler(Runtime::kNumberToString); |
5147 } | 5147 } |
5148 | 5148 |
5149 | |
5150 void FastCloneShallowArrayStub::InitializeDescriptor( | |
5151 CodeStubDescriptor* descriptor) { | |
5152 FastCloneShallowArrayDescriptor call_descriptor(isolate()); | |
5153 descriptor->Initialize( | |
5154 Runtime::FunctionForId(Runtime::kCreateArrayLiteralStubBailout)->entry); | |
5155 descriptor->SetMissHandler(Runtime::kCreateArrayLiteralStubBailout); | |
5156 } | |
5157 | |
5158 void RegExpConstructResultStub::InitializeDescriptor( | 5149 void RegExpConstructResultStub::InitializeDescriptor( |
5159 CodeStubDescriptor* descriptor) { | 5150 CodeStubDescriptor* descriptor) { |
5160 descriptor->Initialize( | 5151 descriptor->Initialize( |
5161 Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry); | 5152 Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry); |
5162 descriptor->SetMissHandler(Runtime::kRegExpConstructResult); | 5153 descriptor->SetMissHandler(Runtime::kRegExpConstructResult); |
5163 } | 5154 } |
5164 | 5155 |
5165 | 5156 |
5166 void TransitionElementsKindStub::InitializeDescriptor( | 5157 void TransitionElementsKindStub::InitializeDescriptor( |
5167 CodeStubDescriptor* descriptor) { | 5158 CodeStubDescriptor* descriptor) { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5656 Node* closure = assembler->Parameter(Descriptor::kClosure); | 5647 Node* closure = assembler->Parameter(Descriptor::kClosure); |
5657 Node* literal_index = assembler->Parameter(Descriptor::kLiteralIndex); | 5648 Node* literal_index = assembler->Parameter(Descriptor::kLiteralIndex); |
5658 Node* pattern = assembler->Parameter(Descriptor::kPattern); | 5649 Node* pattern = assembler->Parameter(Descriptor::kPattern); |
5659 Node* flags = assembler->Parameter(Descriptor::kFlags); | 5650 Node* flags = assembler->Parameter(Descriptor::kFlags); |
5660 Node* context = assembler->Parameter(Descriptor::kContext); | 5651 Node* context = assembler->Parameter(Descriptor::kContext); |
5661 | 5652 |
5662 assembler->Return( | 5653 assembler->Return( |
5663 Generate(assembler, closure, literal_index, pattern, flags, context)); | 5654 Generate(assembler, closure, literal_index, pattern, flags, context)); |
5664 } | 5655 } |
5665 | 5656 |
5657 namespace { | |
5658 | |
5659 compiler::Node* NonEmptyShallowClone(CodeStubAssembler* assembler, | |
5660 compiler::Node* boilerplate, | |
5661 compiler::Node* boilerplate_map, | |
5662 compiler::Node* boilerplate_elements, | |
5663 compiler::Node* allocation_site, | |
5664 compiler::Node* capacity, | |
5665 ElementsKind kind) { | |
5666 typedef compiler::Node Node; | |
5667 typedef CodeStubAssembler::ParameterMode ParameterMode; | |
5668 | |
5669 ParameterMode param_mode = CodeStubAssembler::SMI_PARAMETERS; | |
5670 | |
5671 Node* length = assembler->LoadJSArrayLength(boilerplate); | |
5672 | |
5673 if (assembler->Is64()) { | |
5674 capacity = assembler->SmiUntag(capacity); | |
5675 param_mode = CodeStubAssembler::INTEGER_PARAMETERS; | |
5676 } | |
5677 | |
5678 Node *array, *elements; | |
5679 std::tie(array, elements) = assembler->AllocateUninitializedJSArray( | |
5680 kind, boilerplate_map, length, allocation_site, capacity, param_mode); | |
5681 | |
5682 assembler->Comment("copy elements header"); | |
5683 for (int offset = 0; offset < FixedArrayBase::kHeaderSize; | |
5684 offset += kPointerSize) { | |
5685 Node* value = assembler->LoadObjectField(boilerplate_elements, offset); | |
5686 assembler->StoreObjectField(elements, offset, value); | |
5687 } | |
5688 | |
5689 if (assembler->Is64()) { | |
5690 length = assembler->SmiUntag(length); | |
5691 } | |
5692 | |
5693 assembler->Comment("copy boilerplate elements"); | |
5694 assembler->CopyFixedArrayElements(kind, boilerplate_elements, elements, | |
5695 length, SKIP_WRITE_BARRIER, param_mode); | |
5696 assembler->IncrementCounter( | |
5697 assembler->isolate()->counters()->inlined_copied_elements(), 1); | |
5698 | |
5699 return array; | |
5700 } | |
5701 | |
5702 } // namespace | |
5703 | |
5704 // static | |
5705 compiler::Node* FastCloneShallowArrayStub::Generate( | |
5706 CodeStubAssembler* assembler, compiler::Node* closure, | |
5707 compiler::Node* literal_index, compiler::Node* constant_elements, | |
5708 compiler::Node* context, AllocationSiteMode allocation_site_mode) { | |
5709 typedef CodeStubAssembler::Label Label; | |
5710 typedef CodeStubAssembler::Variable Variable; | |
5711 typedef compiler::Node Node; | |
5712 | |
5713 Label call_runtime(assembler, Label::kDeferred), zero_capacity(assembler), | |
5714 cow_elements(assembler), fast_elements(assembler), | |
5715 return_result(assembler); | |
5716 Variable result(assembler, MachineRepresentation::kTagged); | |
5717 | |
5718 Node* undefined = assembler->UndefinedConstant(); | |
5719 | |
5720 Node* literals_array = | |
5721 assembler->LoadObjectField(closure, JSFunction::kLiteralsOffset); | |
5722 Node* allocation_site = assembler->LoadFixedArrayElement( | |
5723 literals_array, literal_index, | |
5724 LiteralsArray::kFirstLiteralIndex * kPointerSize, | |
5725 CodeStubAssembler::SMI_PARAMETERS); | |
5726 | |
5727 assembler->GotoIf(assembler->WordEqual(allocation_site, undefined), | |
5728 &call_runtime); | |
5729 | |
5730 Node* boilerplate = assembler->LoadObjectField( | |
5731 allocation_site, AllocationSite::kTransitionInfoOffset); | |
5732 Node* boilerplate_map = assembler->LoadMap(boilerplate); | |
5733 Node* boilerplate_elements = assembler->LoadElements(boilerplate); | |
5734 Node* capacity = assembler->LoadFixedArrayBaseLength(boilerplate_elements); | |
5735 allocation_site = | |
5736 allocation_site_mode == TRACK_ALLOCATION_SITE ? allocation_site : nullptr; | |
5737 | |
5738 Node* zero = assembler->SmiConstant(Smi::FromInt(0)); | |
5739 assembler->GotoIf(assembler->SmiEqual(capacity, zero), &zero_capacity); | |
5740 | |
5741 Node* elements_map = assembler->LoadMap(boilerplate_elements); | |
5742 assembler->GotoIf( | |
5743 assembler->WordEqual(elements_map, assembler->FixedCowArrayMapConstant()), | |
5744 &cow_elements); | |
5745 | |
5746 assembler->GotoIf( | |
5747 assembler->WordEqual(elements_map, assembler->FixedArrayMapConstant()), | |
5748 &fast_elements); | |
5749 { | |
5750 assembler->Comment("fast double elements path"); | |
5751 if (FLAG_debug_code) { | |
5752 Label correct_elements_map(assembler), abort(assembler); | |
rmcilroy
2016/09/16 08:53:52
kDeferred on abort label.
klaasb
2016/09/19 12:17:59
Done.
| |
5753 assembler->BranchIf( | |
5754 assembler->WordEqual(elements_map, | |
5755 assembler->FixedDoubleArrayMapConstant()), | |
5756 &correct_elements_map, &abort); | |
5757 | |
5758 assembler->Bind(&abort); | |
5759 { | |
5760 Node* abort_id = | |
5761 assembler->SmiConstant(Smi::FromInt(BailoutReason::kUnexpectedMap)); | |
rmcilroy
2016/09/16 08:53:52
This could be more specific (i.e., "expected fixed
klaasb
2016/09/19 12:17:59
Done.
| |
5762 assembler->TailCallRuntime(Runtime::kAbort, context, abort_id); | |
5763 } | |
5764 assembler->Bind(&correct_elements_map); | |
5765 } | |
5766 Node* array = NonEmptyShallowClone(assembler, boilerplate, boilerplate_map, | |
rmcilroy
2016/09/16 08:53:51
nit - newline above
klaasb
2016/09/19 12:17:59
Done.
| |
5767 boilerplate_elements, allocation_site, | |
5768 capacity, FAST_DOUBLE_ELEMENTS); | |
5769 result.Bind(array); | |
5770 assembler->Goto(&return_result); | |
5771 } | |
5772 | |
5773 assembler->Bind(&fast_elements); | |
5774 { | |
5775 assembler->Comment("fast elements path"); | |
5776 Node* array = NonEmptyShallowClone(assembler, boilerplate, boilerplate_map, | |
5777 boilerplate_elements, allocation_site, | |
5778 capacity, FAST_ELEMENTS); | |
5779 result.Bind(array); | |
5780 assembler->Goto(&return_result); | |
5781 } | |
5782 | |
5783 Variable length(assembler, MachineRepresentation::kTagged), | |
5784 elements(assembler, MachineRepresentation::kTagged); | |
5785 Label allocate_without_elements(assembler); | |
5786 | |
5787 assembler->Bind(&cow_elements); | |
5788 { | |
5789 assembler->Comment("fixed cow path"); | |
5790 length.Bind(assembler->LoadJSArrayLength(boilerplate)); | |
5791 elements.Bind(boilerplate_elements); | |
5792 | |
5793 assembler->Goto(&allocate_without_elements); | |
5794 } | |
5795 | |
5796 assembler->Bind(&zero_capacity); | |
5797 { | |
5798 assembler->Comment("zero capacity path"); | |
5799 length.Bind(zero); | |
5800 elements.Bind(assembler->LoadRoot(Heap::kEmptyFixedArrayRootIndex)); | |
5801 | |
5802 assembler->Goto(&allocate_without_elements); | |
5803 } | |
5804 | |
5805 assembler->Bind(&allocate_without_elements); | |
5806 { | |
5807 Node* array = assembler->AllocateUninitializedJSArrayWithoutElements( | |
5808 FAST_ELEMENTS, boilerplate_map, length.value(), allocation_site); | |
5809 assembler->StoreObjectField(array, JSObject::kElementsOffset, | |
5810 elements.value()); | |
5811 result.Bind(array); | |
5812 assembler->Goto(&return_result); | |
5813 } | |
5814 | |
5815 assembler->Bind(&call_runtime); | |
5816 { | |
5817 assembler->Comment("call runtime"); | |
5818 Node* flags = assembler->SmiConstant( | |
5819 Smi::FromInt(ArrayLiteral::kShallowElements | | |
5820 (allocation_site_mode == TRACK_ALLOCATION_SITE | |
5821 ? 0 | |
5822 : ArrayLiteral::kDisableMementos))); | |
5823 Node* array = | |
5824 assembler->CallRuntime(Runtime::kCreateArrayLiteral, context, closure, | |
5825 literal_index, constant_elements, flags); | |
5826 result.Bind(array); | |
5827 assembler->Goto(&return_result); | |
5828 } | |
5829 | |
5830 assembler->Bind(&return_result); | |
5831 return result.value(); | |
5832 } | |
5833 | |
5834 void FastCloneShallowArrayStub::GenerateAssembly( | |
5835 CodeStubAssembler* assembler) const { | |
5836 typedef compiler::Node Node; | |
5837 Node* closure = assembler->Parameter(Descriptor::kClosure); | |
5838 Node* literal_index = assembler->Parameter(Descriptor::kLiteralIndex); | |
5839 Node* constant_elements = assembler->Parameter(Descriptor::kConstantElements); | |
5840 Node* context = assembler->Parameter(Descriptor::kContext); | |
5841 | |
5842 assembler->Return(Generate(assembler, closure, literal_index, | |
5843 constant_elements, context, | |
5844 allocation_site_mode())); | |
5845 } | |
5846 | |
5666 void CreateAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) { | 5847 void CreateAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) { |
5667 CreateAllocationSiteStub stub(isolate); | 5848 CreateAllocationSiteStub stub(isolate); |
5668 stub.GetCode(); | 5849 stub.GetCode(); |
5669 } | 5850 } |
5670 | 5851 |
5671 | 5852 |
5672 void CreateWeakCellStub::GenerateAheadOfTime(Isolate* isolate) { | 5853 void CreateWeakCellStub::GenerateAheadOfTime(Isolate* isolate) { |
5673 CreateWeakCellStub stub(isolate); | 5854 CreateWeakCellStub stub(isolate); |
5674 stub.GetCode(); | 5855 stub.GetCode(); |
5675 } | 5856 } |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6061 | 6242 |
6062 if (type == MachineType::Pointer()) { | 6243 if (type == MachineType::Pointer()) { |
6063 return Representation::External(); | 6244 return Representation::External(); |
6064 } | 6245 } |
6065 | 6246 |
6066 return Representation::Tagged(); | 6247 return Representation::Tagged(); |
6067 } | 6248 } |
6068 | 6249 |
6069 } // namespace internal | 6250 } // namespace internal |
6070 } // namespace v8 | 6251 } // namespace v8 |
OLD | NEW |