| 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 #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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 ++num_extra_args; | 49 ++num_extra_args; |
| 50 __ Push(rdx); | 50 __ Push(rdx); |
| 51 } | 51 } |
| 52 __ PushReturnAddressFrom(kScratchRegister); | 52 __ PushReturnAddressFrom(kScratchRegister); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // JumpToExternalReference expects rax to contain the number of arguments | 55 // JumpToExternalReference expects rax to contain the number of arguments |
| 56 // including the receiver and the extra arguments. | 56 // including the receiver and the extra arguments. |
| 57 __ addp(rax, Immediate(num_extra_args + 1)); | 57 __ addp(rax, Immediate(num_extra_args + 1)); |
| 58 | 58 |
| 59 __ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1); | 59 __ JumpToExternalReference(ExternalReference(id, masm->isolate())); |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 static void CallRuntimePassFunction( | 63 static void CallRuntimePassFunction( |
| 64 MacroAssembler* masm, Runtime::FunctionId function_id) { | 64 MacroAssembler* masm, Runtime::FunctionId function_id) { |
| 65 // ----------- S t a t e ------------- | 65 // ----------- S t a t e ------------- |
| 66 // -- rdx : new target (preserved for callee) | 66 // -- rdx : new target (preserved for callee) |
| 67 // -- rdi : target function (preserved for callee) | 67 // -- rdi : target function (preserved for callee) |
| 68 // ----------------------------------- | 68 // ----------------------------------- |
| 69 | 69 |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 { | 1119 { |
| 1120 __ Set(rax, 0); | 1120 __ Set(rax, 0); |
| 1121 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); | 1121 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 // 4c. The receiver is not callable, throw an appropriate TypeError. | 1124 // 4c. The receiver is not callable, throw an appropriate TypeError. |
| 1125 __ bind(&receiver_not_callable); | 1125 __ bind(&receiver_not_callable); |
| 1126 { | 1126 { |
| 1127 StackArgumentsAccessor args(rsp, 0); | 1127 StackArgumentsAccessor args(rsp, 0); |
| 1128 __ movp(args.GetReceiverOperand(), rdi); | 1128 __ movp(args.GetReceiverOperand(), rdi); |
| 1129 __ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1, 1); | 1129 __ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1); |
| 1130 } | 1130 } |
| 1131 } | 1131 } |
| 1132 | 1132 |
| 1133 | 1133 |
| 1134 // static | 1134 // static |
| 1135 void Builtins::Generate_FunctionPrototypeCall(MacroAssembler* masm) { | 1135 void Builtins::Generate_FunctionPrototypeCall(MacroAssembler* masm) { |
| 1136 // Stack Layout: | 1136 // Stack Layout: |
| 1137 // rsp[0] : Return address | 1137 // rsp[0] : Return address |
| 1138 // rsp[8] : Argument n | 1138 // rsp[8] : Argument n |
| 1139 // rsp[16] : Argument n-1 | 1139 // rsp[16] : Argument n-1 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 // 3a. Apply the target to the given argumentsList (passing undefined for | 1235 // 3a. Apply the target to the given argumentsList (passing undefined for |
| 1236 // new.target). | 1236 // new.target). |
| 1237 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 1237 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
| 1238 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET); | 1238 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET); |
| 1239 | 1239 |
| 1240 // 3b. The target is not callable, throw an appropriate TypeError. | 1240 // 3b. The target is not callable, throw an appropriate TypeError. |
| 1241 __ bind(&target_not_callable); | 1241 __ bind(&target_not_callable); |
| 1242 { | 1242 { |
| 1243 StackArgumentsAccessor args(rsp, 0); | 1243 StackArgumentsAccessor args(rsp, 0); |
| 1244 __ movp(args.GetReceiverOperand(), rdi); | 1244 __ movp(args.GetReceiverOperand(), rdi); |
| 1245 __ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1, 1); | 1245 __ TailCallRuntime(Runtime::kThrowApplyNonFunction, 1); |
| 1246 } | 1246 } |
| 1247 } | 1247 } |
| 1248 | 1248 |
| 1249 | 1249 |
| 1250 void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) { | 1250 void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) { |
| 1251 // ----------- S t a t e ------------- | 1251 // ----------- S t a t e ------------- |
| 1252 // -- rax : argc | 1252 // -- rax : argc |
| 1253 // -- rsp[0] : return address | 1253 // -- rsp[0] : return address |
| 1254 // -- rsp[8] : new.target (optional) | 1254 // -- rsp[8] : new.target (optional) |
| 1255 // -- rsp[16] : argumentsList | 1255 // -- rsp[16] : argumentsList |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 __ j(zero, &new_target_not_constructor, Label::kNear); | 1309 __ j(zero, &new_target_not_constructor, Label::kNear); |
| 1310 | 1310 |
| 1311 // 4a. Construct the target with the given new.target and argumentsList. | 1311 // 4a. Construct the target with the given new.target and argumentsList. |
| 1312 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET); | 1312 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET); |
| 1313 | 1313 |
| 1314 // 4b. The target is not a constructor, throw an appropriate TypeError. | 1314 // 4b. The target is not a constructor, throw an appropriate TypeError. |
| 1315 __ bind(&target_not_constructor); | 1315 __ bind(&target_not_constructor); |
| 1316 { | 1316 { |
| 1317 StackArgumentsAccessor args(rsp, 0); | 1317 StackArgumentsAccessor args(rsp, 0); |
| 1318 __ movp(args.GetReceiverOperand(), rdi); | 1318 __ movp(args.GetReceiverOperand(), rdi); |
| 1319 __ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1, 1); | 1319 __ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1); |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 // 4c. The new.target is not a constructor, throw an appropriate TypeError. | 1322 // 4c. The new.target is not a constructor, throw an appropriate TypeError. |
| 1323 __ bind(&new_target_not_constructor); | 1323 __ bind(&new_target_not_constructor); |
| 1324 { | 1324 { |
| 1325 StackArgumentsAccessor args(rsp, 0); | 1325 StackArgumentsAccessor args(rsp, 0); |
| 1326 __ movp(args.GetReceiverOperand(), rdx); | 1326 __ movp(args.GetReceiverOperand(), rdx); |
| 1327 __ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1, 1); | 1327 __ TailCallRuntime(Runtime::kThrowCalledNonCallable, 1); |
| 1328 } | 1328 } |
| 1329 } | 1329 } |
| 1330 | 1330 |
| 1331 | 1331 |
| 1332 void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) { | 1332 void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) { |
| 1333 // ----------- S t a t e ------------- | 1333 // ----------- S t a t e ------------- |
| 1334 // -- rax : argc | 1334 // -- rax : argc |
| 1335 // -- rsp[0] : return address | 1335 // -- rsp[0] : return address |
| 1336 // -- rsp[8] : last argument | 1336 // -- rsp[8] : last argument |
| 1337 // ----------------------------------- | 1337 // ----------------------------------- |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 ToStringStub stub(masm->isolate()); | 1439 ToStringStub stub(masm->isolate()); |
| 1440 __ TailCallStub(&stub); | 1440 __ TailCallStub(&stub); |
| 1441 } | 1441 } |
| 1442 | 1442 |
| 1443 // 3b. Convert symbol in rax to a string. | 1443 // 3b. Convert symbol in rax to a string. |
| 1444 __ bind(&symbol_descriptive_string); | 1444 __ bind(&symbol_descriptive_string); |
| 1445 { | 1445 { |
| 1446 __ PopReturnAddressTo(rcx); | 1446 __ PopReturnAddressTo(rcx); |
| 1447 __ Push(rax); | 1447 __ Push(rax); |
| 1448 __ PushReturnAddressFrom(rcx); | 1448 __ PushReturnAddressFrom(rcx); |
| 1449 __ TailCallRuntime(Runtime::kSymbolDescriptiveString, 1, 1); | 1449 __ TailCallRuntime(Runtime::kSymbolDescriptiveString, 1); |
| 1450 } | 1450 } |
| 1451 } | 1451 } |
| 1452 | 1452 |
| 1453 | 1453 |
| 1454 // static | 1454 // static |
| 1455 void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { | 1455 void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { |
| 1456 // ----------- S t a t e ------------- | 1456 // ----------- S t a t e ------------- |
| 1457 // -- rax : number of arguments | 1457 // -- rax : number of arguments |
| 1458 // -- rdi : constructor function | 1458 // -- rdi : constructor function |
| 1459 // -- rdx : new target | 1459 // -- rdx : new target |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1817 Label done; | 1817 Label done; |
| 1818 __ LoadRoot(kScratchRegister, Heap::kRealStackLimitRootIndex); | 1818 __ LoadRoot(kScratchRegister, Heap::kRealStackLimitRootIndex); |
| 1819 __ movp(rcx, rsp); | 1819 __ movp(rcx, rsp); |
| 1820 // Make rcx the space we have left. The stack might already be overflowed | 1820 // Make rcx the space we have left. The stack might already be overflowed |
| 1821 // here which will cause rcx to become negative. | 1821 // here which will cause rcx to become negative. |
| 1822 __ subp(rcx, kScratchRegister); | 1822 __ subp(rcx, kScratchRegister); |
| 1823 __ sarp(rcx, Immediate(kPointerSizeLog2)); | 1823 __ sarp(rcx, Immediate(kPointerSizeLog2)); |
| 1824 // Check if the arguments will overflow the stack. | 1824 // Check if the arguments will overflow the stack. |
| 1825 __ cmpp(rcx, rbx); | 1825 __ cmpp(rcx, rbx); |
| 1826 __ j(greater, &done, Label::kNear); // Signed comparison. | 1826 __ j(greater, &done, Label::kNear); // Signed comparison. |
| 1827 __ TailCallRuntime(Runtime::kThrowStackOverflow, 1, 1); | 1827 __ TailCallRuntime(Runtime::kThrowStackOverflow, 1); |
| 1828 __ bind(&done); | 1828 __ bind(&done); |
| 1829 } | 1829 } |
| 1830 | 1830 |
| 1831 // ----------- S t a t e ------------- | 1831 // ----------- S t a t e ------------- |
| 1832 // -- rdi : target | 1832 // -- rdi : target |
| 1833 // -- rax : args (a FixedArray built from argumentsList) | 1833 // -- rax : args (a FixedArray built from argumentsList) |
| 1834 // -- rbx : len (number of elements to push from args) | 1834 // -- rbx : len (number of elements to push from args) |
| 1835 // -- rdx : new.target (checked to be constructor or undefined) | 1835 // -- rdx : new.target (checked to be constructor or undefined) |
| 1836 // -- rsp[0] : return address. | 1836 // -- rsp[0] : return address. |
| 1837 // -- rsp[8] : thisArgument | 1837 // -- rsp[8] : thisArgument |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 | 2111 |
| 2112 // 1. Runtime fallback for Proxy [[Call]]. | 2112 // 1. Runtime fallback for Proxy [[Call]]. |
| 2113 __ PopReturnAddressTo(kScratchRegister); | 2113 __ PopReturnAddressTo(kScratchRegister); |
| 2114 __ Push(rdi); | 2114 __ Push(rdi); |
| 2115 __ PushReturnAddressFrom(kScratchRegister); | 2115 __ PushReturnAddressFrom(kScratchRegister); |
| 2116 // Increase the arguments size to include the pushed function and the | 2116 // Increase the arguments size to include the pushed function and the |
| 2117 // existing receiver on the stack. | 2117 // existing receiver on the stack. |
| 2118 __ addp(rax, Immediate(2)); | 2118 __ addp(rax, Immediate(2)); |
| 2119 // Tail-call to the runtime. | 2119 // Tail-call to the runtime. |
| 2120 __ JumpToExternalReference( | 2120 __ JumpToExternalReference( |
| 2121 ExternalReference(Runtime::kJSProxyCall, masm->isolate()), 1); | 2121 ExternalReference(Runtime::kJSProxyCall, masm->isolate())); |
| 2122 | 2122 |
| 2123 // 2. Call to something else, which might have a [[Call]] internal method (if | 2123 // 2. Call to something else, which might have a [[Call]] internal method (if |
| 2124 // not we raise an exception). | 2124 // not we raise an exception). |
| 2125 __ bind(&non_function); | 2125 __ bind(&non_function); |
| 2126 // Check if target has a [[Call]] internal method. | 2126 // Check if target has a [[Call]] internal method. |
| 2127 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), | 2127 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), |
| 2128 Immediate(1 << Map::kIsCallable)); | 2128 Immediate(1 << Map::kIsCallable)); |
| 2129 __ j(zero, &non_callable, Label::kNear); | 2129 __ j(zero, &non_callable, Label::kNear); |
| 2130 // Overwrite the original receiver with the (original) target. | 2130 // Overwrite the original receiver with the (original) target. |
| 2131 __ movp(args.GetReceiverOperand(), rdi); | 2131 __ movp(args.GetReceiverOperand(), rdi); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 // ----------------------------------- | 2207 // ----------------------------------- |
| 2208 | 2208 |
| 2209 // Call into the Runtime for Proxy [[Construct]]. | 2209 // Call into the Runtime for Proxy [[Construct]]. |
| 2210 __ PopReturnAddressTo(kScratchRegister); | 2210 __ PopReturnAddressTo(kScratchRegister); |
| 2211 __ Push(rdi); | 2211 __ Push(rdi); |
| 2212 __ Push(rdx); | 2212 __ Push(rdx); |
| 2213 __ PushReturnAddressFrom(kScratchRegister); | 2213 __ PushReturnAddressFrom(kScratchRegister); |
| 2214 // Include the pushed new_target, constructor and the receiver. | 2214 // Include the pushed new_target, constructor and the receiver. |
| 2215 __ addp(rax, Immediate(3)); | 2215 __ addp(rax, Immediate(3)); |
| 2216 __ JumpToExternalReference( | 2216 __ JumpToExternalReference( |
| 2217 ExternalReference(Runtime::kJSProxyConstruct, masm->isolate()), 1); | 2217 ExternalReference(Runtime::kJSProxyConstruct, masm->isolate())); |
| 2218 } | 2218 } |
| 2219 | 2219 |
| 2220 | 2220 |
| 2221 // static | 2221 // static |
| 2222 void Builtins::Generate_Construct(MacroAssembler* masm) { | 2222 void Builtins::Generate_Construct(MacroAssembler* masm) { |
| 2223 // ----------- S t a t e ------------- | 2223 // ----------- S t a t e ------------- |
| 2224 // -- rax : the number of arguments (not including the receiver) | 2224 // -- rax : the number of arguments (not including the receiver) |
| 2225 // -- rdx : the new target (either the same as the constructor or | 2225 // -- rdx : the new target (either the same as the constructor or |
| 2226 // the JSFunction on which new was invoked initially) | 2226 // the JSFunction on which new was invoked initially) |
| 2227 // -- rdi : the constructor to call (can be any Object) | 2227 // -- rdi : the constructor to call (can be any Object) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2387 | 2387 |
| 2388 // Compatible receiver check failed: pop return address, arguments and | 2388 // Compatible receiver check failed: pop return address, arguments and |
| 2389 // receiver and throw an Illegal Invocation exception. | 2389 // receiver and throw an Illegal Invocation exception. |
| 2390 __ bind(&receiver_check_failed); | 2390 __ bind(&receiver_check_failed); |
| 2391 __ PopReturnAddressTo(rbx); | 2391 __ PopReturnAddressTo(rbx); |
| 2392 __ leap(rax, Operand(rax, times_pointer_size, 1 * kPointerSize)); | 2392 __ leap(rax, Operand(rax, times_pointer_size, 1 * kPointerSize)); |
| 2393 __ addp(rsp, rax); | 2393 __ addp(rsp, rax); |
| 2394 __ PushReturnAddressFrom(rbx); | 2394 __ PushReturnAddressFrom(rbx); |
| 2395 { | 2395 { |
| 2396 FrameScope scope(masm, StackFrame::INTERNAL); | 2396 FrameScope scope(masm, StackFrame::INTERNAL); |
| 2397 __ TailCallRuntime(Runtime::kThrowIllegalInvocation, 0, 1); | 2397 __ TailCallRuntime(Runtime::kThrowIllegalInvocation, 0); |
| 2398 } | 2398 } |
| 2399 } | 2399 } |
| 2400 | 2400 |
| 2401 | 2401 |
| 2402 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { | 2402 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { |
| 2403 // Lookup the function in the JavaScript frame. | 2403 // Lookup the function in the JavaScript frame. |
| 2404 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 2404 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 2405 { | 2405 { |
| 2406 FrameScope scope(masm, StackFrame::INTERNAL); | 2406 FrameScope scope(masm, StackFrame::INTERNAL); |
| 2407 // Pass function as argument. | 2407 // Pass function as argument. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2451 __ ret(0); | 2451 __ ret(0); |
| 2452 } | 2452 } |
| 2453 | 2453 |
| 2454 | 2454 |
| 2455 #undef __ | 2455 #undef __ |
| 2456 | 2456 |
| 2457 } // namespace internal | 2457 } // namespace internal |
| 2458 } // namespace v8 | 2458 } // namespace v8 |
| 2459 | 2459 |
| 2460 #endif // V8_TARGET_ARCH_X64 | 2460 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |