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 5211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5222 } | 5222 } |
5223 } | 5223 } |
5224 | 5224 |
5225 | 5225 |
5226 void NumberToStringStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { | 5226 void NumberToStringStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { |
5227 descriptor->Initialize( | 5227 descriptor->Initialize( |
5228 Runtime::FunctionForId(Runtime::kNumberToString)->entry); | 5228 Runtime::FunctionForId(Runtime::kNumberToString)->entry); |
5229 descriptor->SetMissHandler(Runtime::kNumberToString); | 5229 descriptor->SetMissHandler(Runtime::kNumberToString); |
5230 } | 5230 } |
5231 | 5231 |
5232 | |
5233 void FastCloneShallowArrayStub::InitializeDescriptor( | |
5234 CodeStubDescriptor* descriptor) { | |
5235 FastCloneShallowArrayDescriptor call_descriptor(isolate()); | |
5236 descriptor->Initialize( | |
5237 Runtime::FunctionForId(Runtime::kCreateArrayLiteralStubBailout)->entry); | |
5238 descriptor->SetMissHandler(Runtime::kCreateArrayLiteralStubBailout); | |
5239 } | |
5240 | |
5241 void RegExpConstructResultStub::InitializeDescriptor( | 5232 void RegExpConstructResultStub::InitializeDescriptor( |
5242 CodeStubDescriptor* descriptor) { | 5233 CodeStubDescriptor* descriptor) { |
5243 descriptor->Initialize( | 5234 descriptor->Initialize( |
5244 Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry); | 5235 Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry); |
5245 descriptor->SetMissHandler(Runtime::kRegExpConstructResult); | 5236 descriptor->SetMissHandler(Runtime::kRegExpConstructResult); |
5246 } | 5237 } |
5247 | 5238 |
5248 | 5239 |
5249 void TransitionElementsKindStub::InitializeDescriptor( | 5240 void TransitionElementsKindStub::InitializeDescriptor( |
5250 CodeStubDescriptor* descriptor) { | 5241 CodeStubDescriptor* descriptor) { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5739 Node* closure = assembler->Parameter(Descriptor::kClosure); | 5730 Node* closure = assembler->Parameter(Descriptor::kClosure); |
5740 Node* literal_index = assembler->Parameter(Descriptor::kLiteralIndex); | 5731 Node* literal_index = assembler->Parameter(Descriptor::kLiteralIndex); |
5741 Node* pattern = assembler->Parameter(Descriptor::kPattern); | 5732 Node* pattern = assembler->Parameter(Descriptor::kPattern); |
5742 Node* flags = assembler->Parameter(Descriptor::kFlags); | 5733 Node* flags = assembler->Parameter(Descriptor::kFlags); |
5743 Node* context = assembler->Parameter(Descriptor::kContext); | 5734 Node* context = assembler->Parameter(Descriptor::kContext); |
5744 | 5735 |
5745 assembler->Return( | 5736 assembler->Return( |
5746 Generate(assembler, closure, literal_index, pattern, flags, context)); | 5737 Generate(assembler, closure, literal_index, pattern, flags, context)); |
5747 } | 5738 } |
5748 | 5739 |
| 5740 namespace { |
| 5741 |
| 5742 compiler::Node* NonEmptyShallowClone(CodeStubAssembler* assembler, |
| 5743 compiler::Node* boilerplate, |
| 5744 compiler::Node* boilerplate_map, |
| 5745 compiler::Node* boilerplate_elements, |
| 5746 compiler::Node* allocation_site, |
| 5747 compiler::Node* capacity, |
| 5748 ElementsKind kind) { |
| 5749 typedef compiler::Node Node; |
| 5750 typedef CodeStubAssembler::ParameterMode ParameterMode; |
| 5751 |
| 5752 ParameterMode param_mode = CodeStubAssembler::SMI_PARAMETERS; |
| 5753 |
| 5754 Node* length = assembler->LoadJSArrayLength(boilerplate); |
| 5755 |
| 5756 if (assembler->Is64()) { |
| 5757 capacity = assembler->SmiUntag(capacity); |
| 5758 param_mode = CodeStubAssembler::INTEGER_PARAMETERS; |
| 5759 } |
| 5760 |
| 5761 Node *array, *elements; |
| 5762 std::tie(array, elements) = |
| 5763 assembler->AllocateUninitializedJSArrayWithElements( |
| 5764 kind, boilerplate_map, length, allocation_site, capacity, param_mode); |
| 5765 |
| 5766 assembler->Comment("copy elements header"); |
| 5767 for (int offset = 0; offset < FixedArrayBase::kHeaderSize; |
| 5768 offset += kPointerSize) { |
| 5769 Node* value = assembler->LoadObjectField(boilerplate_elements, offset); |
| 5770 assembler->StoreObjectField(elements, offset, value); |
| 5771 } |
| 5772 |
| 5773 if (assembler->Is64()) { |
| 5774 length = assembler->SmiUntag(length); |
| 5775 } |
| 5776 |
| 5777 assembler->Comment("copy boilerplate elements"); |
| 5778 assembler->CopyFixedArrayElements(kind, boilerplate_elements, elements, |
| 5779 length, SKIP_WRITE_BARRIER, param_mode); |
| 5780 assembler->IncrementCounter( |
| 5781 assembler->isolate()->counters()->inlined_copied_elements(), 1); |
| 5782 |
| 5783 return array; |
| 5784 } |
| 5785 |
| 5786 } // namespace |
| 5787 |
| 5788 // static |
| 5789 compiler::Node* FastCloneShallowArrayStub::Generate( |
| 5790 CodeStubAssembler* assembler, compiler::Node* closure, |
| 5791 compiler::Node* literal_index, compiler::Node* constant_elements, |
| 5792 compiler::Node* context, AllocationSiteMode allocation_site_mode) { |
| 5793 typedef CodeStubAssembler::Label Label; |
| 5794 typedef CodeStubAssembler::Variable Variable; |
| 5795 typedef compiler::Node Node; |
| 5796 |
| 5797 Label call_runtime(assembler, Label::kDeferred), zero_capacity(assembler), |
| 5798 cow_elements(assembler), fast_elements(assembler), |
| 5799 return_result(assembler); |
| 5800 Variable result(assembler, MachineRepresentation::kTagged); |
| 5801 |
| 5802 Node* undefined = assembler->UndefinedConstant(); |
| 5803 |
| 5804 Node* literals_array = |
| 5805 assembler->LoadObjectField(closure, JSFunction::kLiteralsOffset); |
| 5806 Node* allocation_site = assembler->LoadFixedArrayElement( |
| 5807 literals_array, literal_index, |
| 5808 LiteralsArray::kFirstLiteralIndex * kPointerSize, |
| 5809 CodeStubAssembler::SMI_PARAMETERS); |
| 5810 |
| 5811 assembler->GotoIf(assembler->WordEqual(allocation_site, undefined), |
| 5812 &call_runtime); |
| 5813 |
| 5814 Node* boilerplate = assembler->LoadObjectField( |
| 5815 allocation_site, AllocationSite::kTransitionInfoOffset); |
| 5816 Node* boilerplate_map = assembler->LoadMap(boilerplate); |
| 5817 Node* boilerplate_elements = assembler->LoadElements(boilerplate); |
| 5818 Node* capacity = assembler->LoadFixedArrayBaseLength(boilerplate_elements); |
| 5819 allocation_site = |
| 5820 allocation_site_mode == TRACK_ALLOCATION_SITE ? allocation_site : nullptr; |
| 5821 |
| 5822 Node* zero = assembler->SmiConstant(Smi::FromInt(0)); |
| 5823 assembler->GotoIf(assembler->SmiEqual(capacity, zero), &zero_capacity); |
| 5824 |
| 5825 Node* elements_map = assembler->LoadMap(boilerplate_elements); |
| 5826 assembler->GotoIf( |
| 5827 assembler->WordEqual(elements_map, assembler->FixedCowArrayMapConstant()), |
| 5828 &cow_elements); |
| 5829 |
| 5830 assembler->GotoIf( |
| 5831 assembler->WordEqual(elements_map, assembler->FixedArrayMapConstant()), |
| 5832 &fast_elements); |
| 5833 { |
| 5834 assembler->Comment("fast double elements path"); |
| 5835 if (FLAG_debug_code) { |
| 5836 Label correct_elements_map(assembler), abort(assembler, Label::kDeferred); |
| 5837 assembler->BranchIf( |
| 5838 assembler->WordEqual(elements_map, |
| 5839 assembler->FixedDoubleArrayMapConstant()), |
| 5840 &correct_elements_map, &abort); |
| 5841 |
| 5842 assembler->Bind(&abort); |
| 5843 { |
| 5844 Node* abort_id = assembler->SmiConstant( |
| 5845 Smi::FromInt(BailoutReason::kExpectedFixedDoubleArrayMap)); |
| 5846 assembler->TailCallRuntime(Runtime::kAbort, context, abort_id); |
| 5847 } |
| 5848 assembler->Bind(&correct_elements_map); |
| 5849 } |
| 5850 |
| 5851 Node* array = NonEmptyShallowClone(assembler, boilerplate, boilerplate_map, |
| 5852 boilerplate_elements, allocation_site, |
| 5853 capacity, FAST_DOUBLE_ELEMENTS); |
| 5854 result.Bind(array); |
| 5855 assembler->Goto(&return_result); |
| 5856 } |
| 5857 |
| 5858 assembler->Bind(&fast_elements); |
| 5859 { |
| 5860 assembler->Comment("fast elements path"); |
| 5861 Node* array = NonEmptyShallowClone(assembler, boilerplate, boilerplate_map, |
| 5862 boilerplate_elements, allocation_site, |
| 5863 capacity, FAST_ELEMENTS); |
| 5864 result.Bind(array); |
| 5865 assembler->Goto(&return_result); |
| 5866 } |
| 5867 |
| 5868 Variable length(assembler, MachineRepresentation::kTagged), |
| 5869 elements(assembler, MachineRepresentation::kTagged); |
| 5870 Label allocate_without_elements(assembler); |
| 5871 |
| 5872 assembler->Bind(&cow_elements); |
| 5873 { |
| 5874 assembler->Comment("fixed cow path"); |
| 5875 length.Bind(assembler->LoadJSArrayLength(boilerplate)); |
| 5876 elements.Bind(boilerplate_elements); |
| 5877 |
| 5878 assembler->Goto(&allocate_without_elements); |
| 5879 } |
| 5880 |
| 5881 assembler->Bind(&zero_capacity); |
| 5882 { |
| 5883 assembler->Comment("zero capacity path"); |
| 5884 length.Bind(zero); |
| 5885 elements.Bind(assembler->LoadRoot(Heap::kEmptyFixedArrayRootIndex)); |
| 5886 |
| 5887 assembler->Goto(&allocate_without_elements); |
| 5888 } |
| 5889 |
| 5890 assembler->Bind(&allocate_without_elements); |
| 5891 { |
| 5892 Node* array = assembler->AllocateUninitializedJSArrayWithoutElements( |
| 5893 FAST_ELEMENTS, boilerplate_map, length.value(), allocation_site); |
| 5894 assembler->StoreObjectField(array, JSObject::kElementsOffset, |
| 5895 elements.value()); |
| 5896 result.Bind(array); |
| 5897 assembler->Goto(&return_result); |
| 5898 } |
| 5899 |
| 5900 assembler->Bind(&call_runtime); |
| 5901 { |
| 5902 assembler->Comment("call runtime"); |
| 5903 Node* flags = assembler->SmiConstant( |
| 5904 Smi::FromInt(ArrayLiteral::kShallowElements | |
| 5905 (allocation_site_mode == TRACK_ALLOCATION_SITE |
| 5906 ? 0 |
| 5907 : ArrayLiteral::kDisableMementos))); |
| 5908 Node* array = |
| 5909 assembler->CallRuntime(Runtime::kCreateArrayLiteral, context, closure, |
| 5910 literal_index, constant_elements, flags); |
| 5911 result.Bind(array); |
| 5912 assembler->Goto(&return_result); |
| 5913 } |
| 5914 |
| 5915 assembler->Bind(&return_result); |
| 5916 return result.value(); |
| 5917 } |
| 5918 |
| 5919 void FastCloneShallowArrayStub::GenerateAssembly( |
| 5920 CodeStubAssembler* assembler) const { |
| 5921 typedef compiler::Node Node; |
| 5922 Node* closure = assembler->Parameter(Descriptor::kClosure); |
| 5923 Node* literal_index = assembler->Parameter(Descriptor::kLiteralIndex); |
| 5924 Node* constant_elements = assembler->Parameter(Descriptor::kConstantElements); |
| 5925 Node* context = assembler->Parameter(Descriptor::kContext); |
| 5926 |
| 5927 assembler->Return(Generate(assembler, closure, literal_index, |
| 5928 constant_elements, context, |
| 5929 allocation_site_mode())); |
| 5930 } |
| 5931 |
5749 void CreateAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) { | 5932 void CreateAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) { |
5750 CreateAllocationSiteStub stub(isolate); | 5933 CreateAllocationSiteStub stub(isolate); |
5751 stub.GetCode(); | 5934 stub.GetCode(); |
5752 } | 5935 } |
5753 | 5936 |
5754 | 5937 |
5755 void CreateWeakCellStub::GenerateAheadOfTime(Isolate* isolate) { | 5938 void CreateWeakCellStub::GenerateAheadOfTime(Isolate* isolate) { |
5756 CreateWeakCellStub stub(isolate); | 5939 CreateWeakCellStub stub(isolate); |
5757 stub.GetCode(); | 5940 stub.GetCode(); |
5758 } | 5941 } |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6124 | 6307 |
6125 if (type == MachineType::Pointer()) { | 6308 if (type == MachineType::Pointer()) { |
6126 return Representation::External(); | 6309 return Representation::External(); |
6127 } | 6310 } |
6128 | 6311 |
6129 return Representation::Tagged(); | 6312 return Representation::Tagged(); |
6130 } | 6313 } |
6131 | 6314 |
6132 } // namespace internal | 6315 } // namespace internal |
6133 } // namespace v8 | 6316 } // namespace v8 |
OLD | NEW |