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

Side by Side Diff: src/x64/builtins-x64.cc

Issue 1523753002: [es6] Correct Function.prototype.apply, Reflect.construct and Reflect.apply. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Mark mjsunit/apply as TIMEOUT (for tsan). Created 5 years 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 | « src/type-feedback-vector.cc ('k') | test/cctest/heap/test-heap.cc » ('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 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/codegen.h" 8 #include "src/codegen.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 __ j(not_zero, &loop); // While non-zero. 1002 __ j(not_zero, &loop); // While non-zero.
1003 __ DropUnderReturnAddress(1, rbx); // Drop one slot under return address. 1003 __ DropUnderReturnAddress(1, rbx); // Drop one slot under return address.
1004 __ decp(rax); // One fewer argument (first argument is new receiver). 1004 __ decp(rax); // One fewer argument (first argument is new receiver).
1005 } 1005 }
1006 1006
1007 // 4. Call the callable. 1007 // 4. Call the callable.
1008 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); 1008 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1009 } 1009 }
1010 1010
1011 1011
1012 static void Generate_PushAppliedArguments(MacroAssembler* masm, 1012 void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
1013 const int vectorOffset, 1013 // ----------- S t a t e -------------
1014 const int argumentsOffset, 1014 // -- rax : argc
1015 const int indexOffset, 1015 // -- rsp[0] : return address
1016 const int limitOffset) { 1016 // -- rsp[8] : argArray
1017 Register receiver = LoadDescriptor::ReceiverRegister(); 1017 // -- rsp[16] : thisArg
1018 Register key = LoadDescriptor::NameRegister(); 1018 // -- rsp[24] : receiver
1019 Register slot = LoadDescriptor::SlotRegister(); 1019 // -----------------------------------
1020 Register vector = LoadWithVectorDescriptor::VectorRegister(); 1020
1021 1021 // 1. Load receiver into rdi, argArray into rax (if present), remove all
1022 // Copy all arguments from the array to the stack. 1022 // arguments from the stack (including the receiver), and push thisArg (if
1023 Label entry, loop; 1023 // present) instead.
1024 __ movp(key, Operand(rbp, indexOffset)); 1024 {
1025 __ jmp(&entry); 1025 Label no_arg_array, no_this_arg;
1026 __ bind(&loop); 1026 StackArgumentsAccessor args(rsp, rax);
1027 __ movp(receiver, Operand(rbp, argumentsOffset)); // load arguments 1027 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
1028 1028 __ movp(rbx, rdx);
1029 // Use inline caching to speed up access to arguments. 1029 __ movp(rdi, args.GetReceiverOperand());
1030 int slot_index = TypeFeedbackVector::PushAppliedArgumentsIndex(); 1030 __ testp(rax, rax);
1031 __ Move(slot, Smi::FromInt(slot_index)); 1031 __ j(zero, &no_this_arg, Label::kNear);
1032 __ movp(vector, Operand(rbp, vectorOffset)); 1032 {
1033 Handle<Code> ic = 1033 __ movp(rdx, args.GetArgumentOperand(1));
1034 KeyedLoadICStub(masm->isolate(), LoadICState(kNoExtraICState)).GetCode(); 1034 __ cmpp(rax, Immediate(1));
1035 __ Call(ic, RelocInfo::CODE_TARGET); 1035 __ j(equal, &no_arg_array, Label::kNear);
1036 // It is important that we do not have a test instruction after the 1036 __ movp(rbx, args.GetArgumentOperand(2));
1037 // call. A test instruction after the call is used to indicate that 1037 __ bind(&no_arg_array);
1038 // we have generated an inline version of the keyed load. In this
1039 // case, we know that we are not generating a test instruction next.
1040
1041 // Push the nth argument.
1042 __ Push(rax);
1043
1044 // Update the index on the stack and in register key.
1045 __ movp(key, Operand(rbp, indexOffset));
1046 __ SmiAddConstant(key, key, Smi::FromInt(1));
1047 __ movp(Operand(rbp, indexOffset), key);
1048
1049 __ bind(&entry);
1050 __ cmpp(key, Operand(rbp, limitOffset));
1051 __ j(not_equal, &loop);
1052
1053 // On exit, the pushed arguments count is in rax, untagged
1054 __ SmiToInteger64(rax, key);
1055 }
1056
1057
1058 // Used by FunctionApply and ReflectApply
1059 static void Generate_ApplyHelper(MacroAssembler* masm, bool targetIsArgument) {
1060 const int kFormalParameters = targetIsArgument ? 3 : 2;
1061 const int kStackSize = kFormalParameters + 1;
1062
1063 // Stack at entry:
1064 // rsp : return address
1065 // rsp[8] : arguments
1066 // rsp[16] : receiver ("this")
1067 // rsp[24] : function
1068 {
1069 FrameScope frame_scope(masm, StackFrame::INTERNAL);
1070 // Stack frame:
1071 // rbp : Old base pointer
1072 // rbp[8] : return address
1073 // rbp[16] : function arguments
1074 // rbp[24] : receiver
1075 // rbp[32] : function
1076 static const int kArgumentsOffset = kFPOnStackSize + kPCOnStackSize;
1077 static const int kReceiverOffset = kArgumentsOffset + kPointerSize;
1078 static const int kFunctionOffset = kReceiverOffset + kPointerSize;
1079 static const int kVectorOffset =
1080 InternalFrameConstants::kCodeOffset - 1 * kPointerSize;
1081
1082 // Push the vector.
1083 __ movp(rdi, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
1084 __ movp(rdi, FieldOperand(rdi, SharedFunctionInfo::kFeedbackVectorOffset));
1085 __ Push(rdi);
1086
1087 __ Push(Operand(rbp, kFunctionOffset));
1088 __ Push(Operand(rbp, kArgumentsOffset));
1089 if (targetIsArgument) {
1090 __ InvokeBuiltin(Context::REFLECT_APPLY_PREPARE_BUILTIN_INDEX,
1091 CALL_FUNCTION);
1092 } else {
1093 __ InvokeBuiltin(Context::APPLY_PREPARE_BUILTIN_INDEX, CALL_FUNCTION);
1094 } 1038 }
1095 1039 __ bind(&no_this_arg);
1096 Generate_CheckStackOverflow(masm, kRaxIsSmiTagged); 1040 __ PopReturnAddressTo(rcx);
1097 1041 __ leap(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize));
1098 // Push current index and limit, and receiver. 1042 __ Push(rdx);
1099 const int kLimitOffset = kVectorOffset - 1 * kPointerSize; 1043 __ PushReturnAddressFrom(rcx);
1100 const int kIndexOffset = kLimitOffset - 1 * kPointerSize; 1044 __ movp(rax, rbx);
1101 __ Push(rax); // limit 1045 }
1102 __ Push(Immediate(0)); // index 1046
1103 __ Push(Operand(rbp, kReceiverOffset)); // receiver 1047 // ----------- S t a t e -------------
1104 1048 // -- rax : argArray
1105 // Loop over the arguments array, pushing each value to the stack 1049 // -- rdi : receiver
1106 Generate_PushAppliedArguments(masm, kVectorOffset, kArgumentsOffset, 1050 // -- rsp[0] : return address
1107 kIndexOffset, kLimitOffset); 1051 // -- rsp[8] : thisArg
1108 1052 // -----------------------------------
1109 // Call the callable. 1053
1110 // TODO(bmeurer): This should be a tail call according to ES6. 1054 // 2. Make sure the receiver is actually callable.
1111 __ movp(rdi, Operand(rbp, kFunctionOffset)); 1055 Label receiver_not_callable;
1112 __ Call(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); 1056 __ JumpIfSmi(rdi, &receiver_not_callable, Label::kNear);
1113 1057 __ movp(rcx, FieldOperand(rdi, HeapObject::kMapOffset));
1114 // Leave internal frame. 1058 __ testb(FieldOperand(rcx, Map::kBitFieldOffset),
1115 } 1059 Immediate(1 << Map::kIsCallable));
1116 __ ret(kStackSize * kPointerSize); // remove this, receiver, and arguments 1060 __ j(zero, &receiver_not_callable, Label::kNear);
1117 } 1061
1118 1062 // 3. Tail call with no arguments if argArray is null or undefined.
1119 1063 Label no_arguments;
1120 // Used by ReflectConstruct 1064 __ JumpIfRoot(rax, Heap::kNullValueRootIndex, &no_arguments, Label::kNear);
1121 static void Generate_ConstructHelper(MacroAssembler* masm) { 1065 __ JumpIfRoot(rax, Heap::kUndefinedValueRootIndex, &no_arguments,
1122 const int kFormalParameters = 3; 1066 Label::kNear);
1123 const int kStackSize = kFormalParameters + 1; 1067
1124 1068 // 4a. Apply the receiver to the given argArray (passing undefined for
1125 // Stack at entry: 1069 // new.target).
1126 // rsp : return address 1070 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
1127 // rsp[8] : new target 1071 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1128 // rsp[16] : arguments 1072
1129 // rsp[24] : constructor 1073 // 4b. The argArray is either null or undefined, so we tail call without any
1130 { 1074 // arguments to the receiver.
1131 FrameScope frame_scope(masm, StackFrame::INTERNAL); 1075 __ bind(&no_arguments);
1132 // Stack frame: 1076 {
1133 // rbp : Old base pointer 1077 __ Set(rax, 0);
1134 // rbp[8] : return address 1078 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1135 // rbp[16] : new target 1079 }
1136 // rbp[24] : arguments 1080
1137 // rbp[32] : constructor 1081 // 4c. The receiver is not callable, throw an appropriate TypeError.
1138 static const int kNewTargetOffset = kFPOnStackSize + kPCOnStackSize; 1082 __ bind(&receiver_not_callable);
1139 static const int kArgumentsOffset = kNewTargetOffset + kPointerSize; 1083 {
1140 static const int kFunctionOffset = kArgumentsOffset + kPointerSize; 1084 StackArgumentsAccessor args(rsp, 0);
1141 1085 __ movp(args.GetReceiverOperand(), rdi);
1142 static const int kVectorOffset = 1086 __ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1, 1);
1143 InternalFrameConstants::kCodeOffset - 1 * kPointerSize; 1087 }
1144
1145 // Push the vector.
1146 __ movp(rdi, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
1147 __ movp(rdi, FieldOperand(rdi, SharedFunctionInfo::kFeedbackVectorOffset));
1148 __ Push(rdi);
1149
1150 // If newTarget is not supplied, set it to constructor
1151 Label validate_arguments;
1152 __ movp(rax, Operand(rbp, kNewTargetOffset));
1153 __ CompareRoot(rax, Heap::kUndefinedValueRootIndex);
1154 __ j(not_equal, &validate_arguments, Label::kNear);
1155 __ movp(rax, Operand(rbp, kFunctionOffset));
1156 __ movp(Operand(rbp, kNewTargetOffset), rax);
1157
1158 // Validate arguments
1159 __ bind(&validate_arguments);
1160 __ Push(Operand(rbp, kFunctionOffset));
1161 __ Push(Operand(rbp, kArgumentsOffset));
1162 __ Push(Operand(rbp, kNewTargetOffset));
1163 __ InvokeBuiltin(Context::REFLECT_CONSTRUCT_PREPARE_BUILTIN_INDEX,
1164 CALL_FUNCTION);
1165
1166 Generate_CheckStackOverflow(masm, kRaxIsSmiTagged);
1167
1168 // Push current index and limit.
1169 const int kLimitOffset = kVectorOffset - 1 * kPointerSize;
1170 const int kIndexOffset = kLimitOffset - 1 * kPointerSize;
1171 __ Push(rax); // limit
1172 __ Push(Immediate(0)); // index
1173 // Push the constructor function as callee.
1174 __ Push(Operand(rbp, kFunctionOffset));
1175
1176 // Loop over the arguments array, pushing each value to the stack
1177 Generate_PushAppliedArguments(masm, kVectorOffset, kArgumentsOffset,
1178 kIndexOffset, kLimitOffset);
1179
1180 // Use undefined feedback vector
1181 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex);
1182 __ movp(rdi, Operand(rbp, kFunctionOffset));
1183 __ movp(rdx, Operand(rbp, kNewTargetOffset));
1184
1185 // Call the function.
1186 __ Call(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
1187
1188 // Leave internal frame.
1189 }
1190 // remove this, target, arguments and newTarget
1191 __ ret(kStackSize * kPointerSize);
1192 }
1193
1194
1195 void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
1196 Generate_ApplyHelper(masm, false);
1197 } 1088 }
1198 1089
1199 1090
1200 void Builtins::Generate_ReflectApply(MacroAssembler* masm) { 1091 void Builtins::Generate_ReflectApply(MacroAssembler* masm) {
1201 Generate_ApplyHelper(masm, true); 1092 // ----------- S t a t e -------------
1093 // -- rax : argc
1094 // -- rsp[0] : return address
1095 // -- rsp[8] : argumentsList
1096 // -- rsp[16] : thisArgument
1097 // -- rsp[24] : target
1098 // -- rsp[32] : receiver
1099 // -----------------------------------
1100
1101 // 1. Load target into rdi (if present), argumentsList into rax (if present),
1102 // remove all arguments from the stack (including the receiver), and push
1103 // thisArgument (if present) instead.
1104 {
1105 Label done;
1106 StackArgumentsAccessor args(rsp, rax);
1107 __ LoadRoot(rdi, Heap::kUndefinedValueRootIndex);
1108 __ movp(rdx, rdi);
1109 __ movp(rbx, rdi);
1110 __ cmpp(rax, Immediate(1));
1111 __ j(below, &done, Label::kNear);
1112 __ movp(rdi, args.GetArgumentOperand(1)); // target
1113 __ j(equal, &done, Label::kNear);
1114 __ movp(rdx, args.GetArgumentOperand(2)); // thisArgument
1115 __ cmpp(rax, Immediate(3));
1116 __ j(below, &done, Label::kNear);
1117 __ movp(rbx, args.GetArgumentOperand(3)); // argumentsList
1118 __ bind(&done);
1119 __ PopReturnAddressTo(rcx);
1120 __ leap(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize));
1121 __ Push(rdx);
1122 __ PushReturnAddressFrom(rcx);
1123 __ movp(rax, rbx);
1124 }
1125
1126 // ----------- S t a t e -------------
1127 // -- rax : argumentsList
1128 // -- rdi : target
1129 // -- rsp[0] : return address
1130 // -- rsp[8] : thisArgument
1131 // -----------------------------------
1132
1133 // 2. Make sure the target is actually callable.
1134 Label target_not_callable;
1135 __ JumpIfSmi(rdi, &target_not_callable, Label::kNear);
1136 __ movp(rcx, FieldOperand(rdi, HeapObject::kMapOffset));
1137 __ testb(FieldOperand(rcx, Map::kBitFieldOffset),
1138 Immediate(1 << Map::kIsCallable));
1139 __ j(zero, &target_not_callable, Label::kNear);
1140
1141 // 3a. Apply the target to the given argumentsList (passing undefined for
1142 // new.target).
1143 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
1144 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1145
1146 // 3b. The target is not callable, throw an appropriate TypeError.
1147 __ bind(&target_not_callable);
1148 {
1149 StackArgumentsAccessor args(rsp, 0);
1150 __ movp(args.GetReceiverOperand(), rdi);
1151 __ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1, 1);
1152 }
1202 } 1153 }
1203 1154
1204 1155
1205 void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) { 1156 void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
1206 Generate_ConstructHelper(masm); 1157 // ----------- S t a t e -------------
1207 } 1158 // -- rax : argc
1208 1159 // -- rsp[0] : return address
1209 1160 // -- rsp[8] : new.target (optional)
1161 // -- rsp[16] : argumentsList
1162 // -- rsp[24] : target
1163 // -- rsp[32] : receiver
1164 // -----------------------------------
1165
1166 // 1. Load target into rdi (if present), argumentsList into rax (if present),
1167 // new.target into rdx (if present, otherwise use target), remove all
1168 // arguments from the stack (including the receiver), and push thisArgument
1169 // (if present) instead.
1170 {
1171 Label done;
1172 StackArgumentsAccessor args(rsp, rax);
1173 __ LoadRoot(rdi, Heap::kUndefinedValueRootIndex);
1174 __ movp(rdx, rdi);
1175 __ movp(rbx, rdi);
1176 __ cmpp(rax, Immediate(1));
1177 __ j(below, &done, Label::kNear);
1178 __ movp(rdi, args.GetArgumentOperand(1)); // target
1179 __ movp(rdx, rdi); // new.target defaults to target
1180 __ j(equal, &done, Label::kNear);
1181 __ movp(rbx, args.GetArgumentOperand(2)); // argumentsList
1182 __ cmpp(rax, Immediate(3));
1183 __ j(below, &done, Label::kNear);
1184 __ movp(rdx, args.GetArgumentOperand(3)); // new.target
1185 __ bind(&done);
1186 __ PopReturnAddressTo(rcx);
1187 __ leap(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize));
1188 __ PushRoot(Heap::kUndefinedValueRootIndex);
1189 __ PushReturnAddressFrom(rcx);
1190 __ movp(rax, rbx);
1191 }
1192
1193 // ----------- S t a t e -------------
1194 // -- rax : argumentsList
1195 // -- rdx : new.target
1196 // -- rdi : target
1197 // -- rsp[0] : return address
1198 // -- rsp[8] : receiver (undefined)
1199 // -----------------------------------
1200
1201 // 2. Make sure the target is actually a constructor.
1202 Label target_not_constructor;
1203 __ JumpIfSmi(rdi, &target_not_constructor, Label::kNear);
1204 __ movp(rcx, FieldOperand(rdi, HeapObject::kMapOffset));
1205 __ testb(FieldOperand(rcx, Map::kBitFieldOffset),
1206 Immediate(1 << Map::kIsConstructor));
1207 __ j(zero, &target_not_constructor, Label::kNear);
1208
1209 // 3. Make sure the target is actually a constructor.
1210 Label new_target_not_constructor;
1211 __ JumpIfSmi(rdx, &new_target_not_constructor, Label::kNear);
1212 __ movp(rcx, FieldOperand(rdx, HeapObject::kMapOffset));
1213 __ testb(FieldOperand(rcx, Map::kBitFieldOffset),
1214 Immediate(1 << Map::kIsConstructor));
1215 __ j(zero, &new_target_not_constructor, Label::kNear);
1216
1217 // 4a. Construct the target with the given new.target and argumentsList.
1218 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1219
1220 // 4b. The target is not a constructor, throw an appropriate TypeError.
1221 __ bind(&target_not_constructor);
1222 {
1223 StackArgumentsAccessor args(rsp, 0);
1224 __ movp(args.GetReceiverOperand(), rdi);
1225 __ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1, 1);
1226 }
1227
1228 // 4c. The new.target is not a constructor, throw an appropriate TypeError.
1229 __ bind(&new_target_not_constructor);
1230 {
1231 StackArgumentsAccessor args(rsp, 0);
1232 __ movp(args.GetReceiverOperand(), rdx);
1233 __ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1, 1);
1234 }
1235 }
1236
1237
1210 void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) { 1238 void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
1211 // ----------- S t a t e ------------- 1239 // ----------- S t a t e -------------
1212 // -- rax : argc 1240 // -- rax : argc
1213 // -- rsp[0] : return address 1241 // -- rsp[0] : return address
1214 // -- rsp[8] : last argument 1242 // -- rsp[8] : last argument
1215 // ----------------------------------- 1243 // -----------------------------------
1216 Label generic_array_code; 1244 Label generic_array_code;
1217 1245
1218 // Get the InternalArray function. 1246 // Get the InternalArray function.
1219 __ LoadNativeContextSlot(Context::INTERNAL_ARRAY_FUNCTION_INDEX, rdi); 1247 __ LoadNativeContextSlot(Context::INTERNAL_ARRAY_FUNCTION_INDEX, rdi);
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 __ bind(&stack_overflow); 1636 __ bind(&stack_overflow);
1609 { 1637 {
1610 FrameScope frame(masm, StackFrame::MANUAL); 1638 FrameScope frame(masm, StackFrame::MANUAL);
1611 __ CallRuntime(Runtime::kThrowStackOverflow, 0); 1639 __ CallRuntime(Runtime::kThrowStackOverflow, 0);
1612 __ int3(); 1640 __ int3();
1613 } 1641 }
1614 } 1642 }
1615 1643
1616 1644
1617 // static 1645 // static
1646 void Builtins::Generate_Apply(MacroAssembler* masm) {
1647 // ----------- S t a t e -------------
1648 // -- rax : argumentsList
1649 // -- rdi : target
1650 // -- rdx : new.target (checked to be constructor or undefined)
1651 // -- rsp[0] : return address.
1652 // -- rsp[8] : thisArgument
1653 // -----------------------------------
1654
1655 // Create the list of arguments from the array-like argumentsList.
1656 {
1657 Label create_arguments, create_array, create_runtime, done_create;
1658 __ JumpIfSmi(rax, &create_runtime);
1659
1660 // Load the map of argumentsList into rcx.
1661 __ movp(rcx, FieldOperand(rax, HeapObject::kMapOffset));
1662
1663 // Load native context into rbx.
1664 __ movp(rbx, NativeContextOperand());
1665
1666 // Check if argumentsList is an (unmodified) arguments object.
1667 __ cmpp(rcx, ContextOperand(rbx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1668 __ j(equal, &create_arguments);
1669 __ cmpp(rcx, ContextOperand(rbx, Context::STRICT_ARGUMENTS_MAP_INDEX));
1670 __ j(equal, &create_arguments);
1671
1672 // Check if argumentsList is a fast JSArray.
1673 __ CmpInstanceType(rcx, JS_ARRAY_TYPE);
1674 __ j(equal, &create_array);
1675
1676 // Ask the runtime to create the list (actually a FixedArray).
1677 __ bind(&create_runtime);
1678 {
1679 FrameScope scope(masm, StackFrame::INTERNAL);
1680 __ Push(rdi);
1681 __ Push(rdx);
1682 __ Push(rax);
1683 __ CallRuntime(Runtime::kCreateListFromArrayLike, 1);
1684 __ Pop(rdx);
1685 __ Pop(rdi);
1686 __ SmiToInteger32(rbx, FieldOperand(rax, FixedArray::kLengthOffset));
1687 }
1688 __ jmp(&done_create);
1689
1690 // Try to create the list from an arguments object.
1691 __ bind(&create_arguments);
1692 __ movp(rbx,
1693 FieldOperand(rax, JSObject::kHeaderSize +
1694 Heap::kArgumentsLengthIndex * kPointerSize));
1695 __ movp(rcx, FieldOperand(rax, JSObject::kElementsOffset));
1696 __ cmpp(rbx, FieldOperand(rcx, FixedArray::kLengthOffset));
1697 __ j(not_equal, &create_runtime);
1698 __ SmiToInteger32(rbx, rbx);
1699 __ movp(rax, rcx);
1700 __ jmp(&done_create);
1701
1702 // Try to create the list from a JSArray object.
1703 __ bind(&create_array);
1704 __ movzxbp(rcx, FieldOperand(rcx, Map::kBitField2Offset));
1705 __ DecodeField<Map::ElementsKindBits>(rcx);
1706 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
1707 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
1708 STATIC_ASSERT(FAST_ELEMENTS == 2);
1709 __ cmpl(rcx, Immediate(FAST_ELEMENTS));
1710 __ j(above, &create_runtime);
1711 __ cmpl(rcx, Immediate(FAST_HOLEY_SMI_ELEMENTS));
1712 __ j(equal, &create_runtime);
1713 __ SmiToInteger32(rbx, FieldOperand(rax, JSArray::kLengthOffset));
1714 __ movp(rax, FieldOperand(rax, JSArray::kElementsOffset));
1715
1716 __ bind(&done_create);
1717 }
1718
1719 // Check for stack overflow.
1720 {
1721 // Check the stack for overflow. We are not trying to catch interruptions
1722 // (i.e. debug break and preemption) here, so check the "real stack limit".
1723 Label done;
1724 __ LoadRoot(kScratchRegister, Heap::kRealStackLimitRootIndex);
1725 __ movp(rcx, rsp);
1726 // Make rcx the space we have left. The stack might already be overflowed
1727 // here which will cause rcx to become negative.
1728 __ subp(rcx, kScratchRegister);
1729 __ sarp(rcx, Immediate(kPointerSizeLog2));
1730 // Check if the arguments will overflow the stack.
1731 __ cmpp(rcx, rbx);
1732 __ j(greater, &done, Label::kNear); // Signed comparison.
1733 __ TailCallRuntime(Runtime::kThrowStackOverflow, 1, 1);
1734 __ bind(&done);
1735 }
1736
1737 // ----------- S t a t e -------------
1738 // -- rdi : target
1739 // -- rax : args (a FixedArray built from argumentsList)
1740 // -- rbx : len (number of elements to push from args)
1741 // -- rdx : new.target (checked to be constructor or undefined)
1742 // -- rsp[0] : return address.
1743 // -- rsp[8] : thisArgument
1744 // -----------------------------------
1745
1746 // Push arguments onto the stack (thisArgument is already on the stack).
1747 {
1748 __ PopReturnAddressTo(r8);
1749 __ Set(rcx, 0);
1750 Label done, loop;
1751 __ bind(&loop);
1752 __ cmpl(rcx, rbx);
1753 __ j(equal, &done, Label::kNear);
1754 __ Push(
1755 FieldOperand(rax, rcx, times_pointer_size, FixedArray::kHeaderSize));
1756 __ incl(rcx);
1757 __ jmp(&loop);
1758 __ bind(&done);
1759 __ PushReturnAddressFrom(r8);
1760 __ Move(rax, rcx);
1761 }
1762
1763 // Dispatch to Call or Construct depending on whether new.target is undefined.
1764 {
1765 __ CompareRoot(rdx, Heap::kUndefinedValueRootIndex);
1766 __ j(equal, masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1767 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
1768 }
1769 }
1770
1771
1772 // static
1618 void Builtins::Generate_CallFunction(MacroAssembler* masm, 1773 void Builtins::Generate_CallFunction(MacroAssembler* masm,
1619 ConvertReceiverMode mode) { 1774 ConvertReceiverMode mode) {
1620 // ----------- S t a t e ------------- 1775 // ----------- S t a t e -------------
1621 // -- rax : the number of arguments (not including the receiver) 1776 // -- rax : the number of arguments (not including the receiver)
1622 // -- rdi : the function to call (checked to be a JSFunction) 1777 // -- rdi : the function to call (checked to be a JSFunction)
1623 // ----------------------------------- 1778 // -----------------------------------
1624 StackArgumentsAccessor args(rsp, rax); 1779 StackArgumentsAccessor args(rsp, rax);
1625 __ AssertFunction(rdi); 1780 __ AssertFunction(rdi);
1626 1781
1627 // ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList) 1782 // ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 __ ret(0); 2208 __ ret(0);
2054 } 2209 }
2055 2210
2056 2211
2057 #undef __ 2212 #undef __
2058 2213
2059 } // namespace internal 2214 } // namespace internal
2060 } // namespace v8 2215 } // namespace v8
2061 2216
2062 #endif // V8_TARGET_ARCH_X64 2217 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/type-feedback-vector.cc ('k') | test/cctest/heap/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698