OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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_ARM64 | 5 #if V8_TARGET_ARCH_ARM64 |
6 | 6 |
7 #include "src/arm64/frames-arm64.h" | 7 #include "src/arm64/frames-arm64.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 // Push function as argument and compile for baseline. | 1164 // Push function as argument and compile for baseline. |
1165 __ push(x1); | 1165 __ push(x1); |
1166 __ CallRuntime(Runtime::kCompileBaseline); | 1166 __ CallRuntime(Runtime::kCompileBaseline); |
1167 | 1167 |
1168 // Restore return value. | 1168 // Restore return value. |
1169 __ pop(x0); | 1169 __ pop(x0); |
1170 } | 1170 } |
1171 __ Ret(); | 1171 __ Ret(); |
1172 } | 1172 } |
1173 | 1173 |
| 1174 static void Generate_StackOverflowCheck(MacroAssembler* masm, Register num_args, |
| 1175 Register scratch, |
| 1176 Label* stack_overflow) { |
| 1177 // Check the stack for overflow. |
| 1178 // We are not trying to catch interruptions (e.g. debug break and |
| 1179 // preemption) here, so the "real stack limit" is checked. |
| 1180 Label enough_stack_space; |
| 1181 __ LoadRoot(scratch, Heap::kRealStackLimitRootIndex); |
| 1182 // Make scratch the space we have left. The stack might already be overflowed |
| 1183 // here which will cause scratch to become negative. |
| 1184 __ Sub(scratch, jssp, scratch); |
| 1185 // Check if the arguments will overflow the stack. |
| 1186 __ Cmp(scratch, Operand(num_args, LSL, kPointerSizeLog2)); |
| 1187 __ B(le, stack_overflow); |
| 1188 } |
| 1189 |
1174 static void Generate_InterpreterPushArgs(MacroAssembler* masm, | 1190 static void Generate_InterpreterPushArgs(MacroAssembler* masm, |
1175 Register num_args, Register index, | 1191 Register num_args, Register index, |
1176 Register last_arg, Register stack_addr, | 1192 Register last_arg, Register stack_addr, |
1177 Register scratch) { | 1193 Register scratch, |
| 1194 Label* stack_overflow) { |
| 1195 // Add a stack check before pushing arguments. |
| 1196 Generate_StackOverflowCheck(masm, num_args, scratch, stack_overflow); |
| 1197 |
1178 __ Mov(scratch, num_args); | 1198 __ Mov(scratch, num_args); |
1179 __ lsl(scratch, scratch, kPointerSizeLog2); | 1199 __ lsl(scratch, scratch, kPointerSizeLog2); |
1180 __ sub(last_arg, index, scratch); | 1200 __ sub(last_arg, index, scratch); |
1181 | 1201 |
1182 // Set stack pointer and where to stop. | 1202 // Set stack pointer and where to stop. |
1183 __ Mov(stack_addr, jssp); | 1203 __ Mov(stack_addr, jssp); |
1184 __ Claim(scratch, 1); | 1204 __ Claim(scratch, 1); |
1185 | 1205 |
1186 // TODO(mythria): Add a stack check before pushing arguments. | |
1187 // Push the arguments. | 1206 // Push the arguments. |
1188 Label loop_header, loop_check; | 1207 Label loop_header, loop_check; |
1189 __ B(&loop_check); | 1208 __ B(&loop_check); |
1190 __ Bind(&loop_header); | 1209 __ Bind(&loop_header); |
1191 // TODO(rmcilroy): Push two at a time once we ensure we keep stack aligned. | 1210 // TODO(rmcilroy): Push two at a time once we ensure we keep stack aligned. |
1192 __ Ldr(scratch, MemOperand(index, -kPointerSize, PostIndex)); | 1211 __ Ldr(scratch, MemOperand(index, -kPointerSize, PostIndex)); |
1193 __ Str(scratch, MemOperand(stack_addr, -kPointerSize, PreIndex)); | 1212 __ Str(scratch, MemOperand(stack_addr, -kPointerSize, PreIndex)); |
1194 __ Bind(&loop_check); | 1213 __ Bind(&loop_check); |
1195 __ Cmp(index, last_arg); | 1214 __ Cmp(index, last_arg); |
1196 __ B(gt, &loop_header); | 1215 __ B(gt, &loop_header); |
1197 } | 1216 } |
1198 | 1217 |
1199 // static | 1218 // static |
1200 void Builtins::Generate_InterpreterPushArgsAndCallImpl( | 1219 void Builtins::Generate_InterpreterPushArgsAndCallImpl( |
1201 MacroAssembler* masm, TailCallMode tail_call_mode, | 1220 MacroAssembler* masm, TailCallMode tail_call_mode, |
1202 CallableType function_type) { | 1221 CallableType function_type) { |
1203 // ----------- S t a t e ------------- | 1222 // ----------- S t a t e ------------- |
1204 // -- x0 : the number of arguments (not including the receiver) | 1223 // -- x0 : the number of arguments (not including the receiver) |
1205 // -- x2 : the address of the first argument to be pushed. Subsequent | 1224 // -- x2 : the address of the first argument to be pushed. Subsequent |
1206 // arguments should be consecutive above this, in the same order as | 1225 // arguments should be consecutive above this, in the same order as |
1207 // they are to be pushed onto the stack. | 1226 // they are to be pushed onto the stack. |
1208 // -- x1 : the target to call (can be any Object). | 1227 // -- x1 : the target to call (can be any Object). |
1209 // ----------------------------------- | 1228 // ----------------------------------- |
| 1229 Label stack_overflow; |
1210 | 1230 |
1211 // Add one for the receiver. | 1231 // Add one for the receiver. |
1212 __ add(x3, x0, Operand(1)); | 1232 __ add(x3, x0, Operand(1)); |
1213 | 1233 |
1214 // Push the arguments. x2, x4, x5, x6 will be modified. | 1234 // Push the arguments. x2, x4, x5, x6 will be modified. |
1215 Generate_InterpreterPushArgs(masm, x3, x2, x4, x5, x6); | 1235 Generate_InterpreterPushArgs(masm, x3, x2, x4, x5, x6, &stack_overflow); |
1216 | 1236 |
1217 // Call the target. | 1237 // Call the target. |
1218 if (function_type == CallableType::kJSFunction) { | 1238 if (function_type == CallableType::kJSFunction) { |
1219 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, | 1239 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, |
1220 tail_call_mode), | 1240 tail_call_mode), |
1221 RelocInfo::CODE_TARGET); | 1241 RelocInfo::CODE_TARGET); |
1222 } else { | 1242 } else { |
1223 DCHECK_EQ(function_type, CallableType::kAny); | 1243 DCHECK_EQ(function_type, CallableType::kAny); |
1224 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, | 1244 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, |
1225 tail_call_mode), | 1245 tail_call_mode), |
1226 RelocInfo::CODE_TARGET); | 1246 RelocInfo::CODE_TARGET); |
1227 } | 1247 } |
| 1248 |
| 1249 __ bind(&stack_overflow); |
| 1250 { |
| 1251 __ TailCallRuntime(Runtime::kThrowStackOverflow); |
| 1252 __ Unreachable(); |
| 1253 } |
1228 } | 1254 } |
1229 | 1255 |
1230 // static | 1256 // static |
1231 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( | 1257 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( |
1232 MacroAssembler* masm, CallableType construct_type) { | 1258 MacroAssembler* masm, CallableType construct_type) { |
1233 // ----------- S t a t e ------------- | 1259 // ----------- S t a t e ------------- |
1234 // -- x0 : argument count (not including receiver) | 1260 // -- x0 : argument count (not including receiver) |
1235 // -- x3 : new target | 1261 // -- x3 : new target |
1236 // -- x1 : constructor to call | 1262 // -- x1 : constructor to call |
1237 // -- x2 : allocation site feedback if available, undefined otherwise | 1263 // -- x2 : allocation site feedback if available, undefined otherwise |
1238 // -- x4 : address of the first argument | 1264 // -- x4 : address of the first argument |
1239 // ----------------------------------- | 1265 // ----------------------------------- |
| 1266 Label stack_overflow; |
1240 | 1267 |
1241 // Push a slot for the receiver. | 1268 // Push a slot for the receiver. |
1242 __ Push(xzr); | 1269 __ Push(xzr); |
1243 | 1270 |
1244 // Push the arguments. x5, x4, x6, x7 will be modified. | 1271 // Push the arguments. x5, x4, x6, x7 will be modified. |
1245 Generate_InterpreterPushArgs(masm, x0, x4, x5, x6, x7); | 1272 Generate_InterpreterPushArgs(masm, x0, x4, x5, x6, x7, &stack_overflow); |
1246 | 1273 |
1247 __ AssertUndefinedOrAllocationSite(x2, x6); | 1274 __ AssertUndefinedOrAllocationSite(x2, x6); |
1248 if (construct_type == CallableType::kJSFunction) { | 1275 if (construct_type == CallableType::kJSFunction) { |
1249 __ AssertFunction(x1); | 1276 __ AssertFunction(x1); |
1250 | 1277 |
1251 // Tail call to the function-specific construct stub (still in the caller | 1278 // Tail call to the function-specific construct stub (still in the caller |
1252 // context at this point). | 1279 // context at this point). |
1253 __ Ldr(x4, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); | 1280 __ Ldr(x4, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); |
1254 __ Ldr(x4, FieldMemOperand(x4, SharedFunctionInfo::kConstructStubOffset)); | 1281 __ Ldr(x4, FieldMemOperand(x4, SharedFunctionInfo::kConstructStubOffset)); |
1255 __ Add(x4, x4, Code::kHeaderSize - kHeapObjectTag); | 1282 __ Add(x4, x4, Code::kHeaderSize - kHeapObjectTag); |
1256 __ Br(x4); | 1283 __ Br(x4); |
1257 } else { | 1284 } else { |
1258 DCHECK_EQ(construct_type, CallableType::kAny); | 1285 DCHECK_EQ(construct_type, CallableType::kAny); |
1259 // Call the constructor with x0, x1, and x3 unmodified. | 1286 // Call the constructor with x0, x1, and x3 unmodified. |
1260 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); | 1287 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
1261 } | 1288 } |
| 1289 |
| 1290 __ bind(&stack_overflow); |
| 1291 { |
| 1292 __ TailCallRuntime(Runtime::kThrowStackOverflow); |
| 1293 __ Unreachable(); |
| 1294 } |
1262 } | 1295 } |
1263 | 1296 |
1264 // static | 1297 // static |
1265 void Builtins::Generate_InterpreterPushArgsAndConstructArray( | 1298 void Builtins::Generate_InterpreterPushArgsAndConstructArray( |
1266 MacroAssembler* masm) { | 1299 MacroAssembler* masm) { |
1267 // ----------- S t a t e ------------- | 1300 // ----------- S t a t e ------------- |
1268 // -- x0 : argument count (not including receiver) | 1301 // -- x0 : argument count (not including receiver) |
1269 // -- x1 : target to call verified to be Array function | 1302 // -- x1 : target to call verified to be Array function |
1270 // -- x2 : allocation site feedback if available, undefined otherwise. | 1303 // -- x2 : allocation site feedback if available, undefined otherwise. |
1271 // -- x3 : address of the first argument | 1304 // -- x3 : address of the first argument |
1272 // ----------------------------------- | 1305 // ----------------------------------- |
| 1306 Label stack_overflow; |
1273 | 1307 |
1274 __ add(x4, x0, Operand(1)); // Add one for the receiver. | 1308 __ add(x4, x0, Operand(1)); // Add one for the receiver. |
1275 | 1309 |
1276 // Push the arguments. x3, x5, x6, x7 will be modified. | 1310 // Push the arguments. x3, x5, x6, x7 will be modified. |
1277 Generate_InterpreterPushArgs(masm, x4, x3, x5, x6, x7); | 1311 Generate_InterpreterPushArgs(masm, x4, x3, x5, x6, x7, &stack_overflow); |
1278 | 1312 |
1279 // Array constructor expects constructor in x3. It is same as call target. | 1313 // Array constructor expects constructor in x3. It is same as call target. |
1280 __ mov(x3, x1); | 1314 __ mov(x3, x1); |
1281 | 1315 |
1282 ArrayConstructorStub stub(masm->isolate()); | 1316 ArrayConstructorStub stub(masm->isolate()); |
1283 __ TailCallStub(&stub); | 1317 __ TailCallStub(&stub); |
| 1318 |
| 1319 __ bind(&stack_overflow); |
| 1320 { |
| 1321 __ TailCallRuntime(Runtime::kThrowStackOverflow); |
| 1322 __ Unreachable(); |
| 1323 } |
1284 } | 1324 } |
1285 | 1325 |
1286 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { | 1326 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { |
1287 // Set the return address to the correct point in the interpreter entry | 1327 // Set the return address to the correct point in the interpreter entry |
1288 // trampoline. | 1328 // trampoline. |
1289 Smi* interpreter_entry_return_pc_offset( | 1329 Smi* interpreter_entry_return_pc_offset( |
1290 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); | 1330 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); |
1291 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); | 1331 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); |
1292 __ LoadObject(x1, masm->isolate()->builtins()->InterpreterEntryTrampoline()); | 1332 __ LoadObject(x1, masm->isolate()->builtins()->InterpreterEntryTrampoline()); |
1293 __ Add(lr, x1, Operand(interpreter_entry_return_pc_offset->value() + | 1333 __ Add(lr, x1, Operand(interpreter_entry_return_pc_offset->value() + |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2198 } | 2238 } |
2199 | 2239 |
2200 // 4c. The new.target is not a constructor, throw an appropriate TypeError. | 2240 // 4c. The new.target is not a constructor, throw an appropriate TypeError. |
2201 __ Bind(&new_target_not_constructor); | 2241 __ Bind(&new_target_not_constructor); |
2202 { | 2242 { |
2203 __ Poke(new_target, 0); | 2243 __ Poke(new_target, 0); |
2204 __ TailCallRuntime(Runtime::kThrowCalledNonCallable); | 2244 __ TailCallRuntime(Runtime::kThrowCalledNonCallable); |
2205 } | 2245 } |
2206 } | 2246 } |
2207 | 2247 |
2208 static void ArgumentAdaptorStackCheck(MacroAssembler* masm, | |
2209 Label* stack_overflow) { | |
2210 // ----------- S t a t e ------------- | |
2211 // -- x0 : actual number of arguments | |
2212 // -- x1 : function (passed through to callee) | |
2213 // -- x2 : expected number of arguments | |
2214 // -- x3 : new target (passed through to callee) | |
2215 // ----------------------------------- | |
2216 // Check the stack for overflow. | |
2217 // We are not trying to catch interruptions (e.g. debug break and | |
2218 // preemption) here, so the "real stack limit" is checked. | |
2219 Label enough_stack_space; | |
2220 __ LoadRoot(x10, Heap::kRealStackLimitRootIndex); | |
2221 // Make x10 the space we have left. The stack might already be overflowed | |
2222 // here which will cause x10 to become negative. | |
2223 __ Sub(x10, jssp, x10); | |
2224 // Check if the arguments will overflow the stack. | |
2225 __ Cmp(x10, Operand(x2, LSL, kPointerSizeLog2)); | |
2226 __ B(le, stack_overflow); | |
2227 } | |
2228 | |
2229 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { | 2248 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { |
2230 __ SmiTag(x10, x0); | 2249 __ SmiTag(x10, x0); |
2231 __ Mov(x11, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); | 2250 __ Mov(x11, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
2232 __ Push(lr, fp); | 2251 __ Push(lr, fp); |
2233 __ Push(x11, x1, x10); | 2252 __ Push(x11, x1, x10); |
2234 __ Add(fp, jssp, | 2253 __ Add(fp, jssp, |
2235 StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize); | 2254 StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize); |
2236 } | 2255 } |
2237 | 2256 |
2238 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { | 2257 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2953 Label invoke, dont_adapt_arguments, stack_overflow; | 2972 Label invoke, dont_adapt_arguments, stack_overflow; |
2954 | 2973 |
2955 Label enough, too_few; | 2974 Label enough, too_few; |
2956 __ Cmp(argc_actual, argc_expected); | 2975 __ Cmp(argc_actual, argc_expected); |
2957 __ B(lt, &too_few); | 2976 __ B(lt, &too_few); |
2958 __ Cmp(argc_expected, SharedFunctionInfo::kDontAdaptArgumentsSentinel); | 2977 __ Cmp(argc_expected, SharedFunctionInfo::kDontAdaptArgumentsSentinel); |
2959 __ B(eq, &dont_adapt_arguments); | 2978 __ B(eq, &dont_adapt_arguments); |
2960 | 2979 |
2961 { // Enough parameters: actual >= expected | 2980 { // Enough parameters: actual >= expected |
2962 EnterArgumentsAdaptorFrame(masm); | 2981 EnterArgumentsAdaptorFrame(masm); |
2963 ArgumentAdaptorStackCheck(masm, &stack_overflow); | 2982 Generate_StackOverflowCheck(masm, x2, x10, &stack_overflow); |
2964 | 2983 |
2965 Register copy_start = x10; | 2984 Register copy_start = x10; |
2966 Register copy_end = x11; | 2985 Register copy_end = x11; |
2967 Register copy_to = x12; | 2986 Register copy_to = x12; |
2968 Register scratch1 = x13, scratch2 = x14; | 2987 Register scratch1 = x13, scratch2 = x14; |
2969 | 2988 |
2970 __ Lsl(scratch2, argc_expected, kPointerSizeLog2); | 2989 __ Lsl(scratch2, argc_expected, kPointerSizeLog2); |
2971 | 2990 |
2972 // Adjust for fp, lr, and the receiver. | 2991 // Adjust for fp, lr, and the receiver. |
2973 __ Add(copy_start, fp, 3 * kPointerSize); | 2992 __ Add(copy_start, fp, 3 * kPointerSize); |
(...skipping 26 matching lines...) Expand all Loading... |
3000 | 3019 |
3001 { // Too few parameters: Actual < expected | 3020 { // Too few parameters: Actual < expected |
3002 __ Bind(&too_few); | 3021 __ Bind(&too_few); |
3003 | 3022 |
3004 Register copy_from = x10; | 3023 Register copy_from = x10; |
3005 Register copy_end = x11; | 3024 Register copy_end = x11; |
3006 Register copy_to = x12; | 3025 Register copy_to = x12; |
3007 Register scratch1 = x13, scratch2 = x14; | 3026 Register scratch1 = x13, scratch2 = x14; |
3008 | 3027 |
3009 EnterArgumentsAdaptorFrame(masm); | 3028 EnterArgumentsAdaptorFrame(masm); |
3010 ArgumentAdaptorStackCheck(masm, &stack_overflow); | 3029 Generate_StackOverflowCheck(masm, x2, x10, &stack_overflow); |
3011 | 3030 |
3012 __ Lsl(scratch2, argc_expected, kPointerSizeLog2); | 3031 __ Lsl(scratch2, argc_expected, kPointerSizeLog2); |
3013 __ Lsl(argc_actual, argc_actual, kPointerSizeLog2); | 3032 __ Lsl(argc_actual, argc_actual, kPointerSizeLog2); |
3014 | 3033 |
3015 // Adjust for fp, lr, and the receiver. | 3034 // Adjust for fp, lr, and the receiver. |
3016 __ Add(copy_from, fp, 3 * kPointerSize); | 3035 __ Add(copy_from, fp, 3 * kPointerSize); |
3017 __ Add(copy_from, copy_from, argc_actual); | 3036 __ Add(copy_from, copy_from, argc_actual); |
3018 __ Mov(copy_to, jssp); | 3037 __ Mov(copy_to, jssp); |
3019 __ Sub(copy_end, copy_to, 1 * kPointerSize); // Adjust for the receiver. | 3038 __ Sub(copy_end, copy_to, 1 * kPointerSize); // Adjust for the receiver. |
3020 __ Sub(copy_end, copy_end, argc_actual); | 3039 __ Sub(copy_end, copy_end, argc_actual); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3080 __ Unreachable(); | 3099 __ Unreachable(); |
3081 } | 3100 } |
3082 } | 3101 } |
3083 | 3102 |
3084 #undef __ | 3103 #undef __ |
3085 | 3104 |
3086 } // namespace internal | 3105 } // namespace internal |
3087 } // namespace v8 | 3106 } // namespace v8 |
3088 | 3107 |
3089 #endif // V8_TARGET_ARCH_ARM | 3108 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |