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 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 } | 1417 } |
1418 __ Ret(); | 1418 __ Ret(); |
1419 } | 1419 } |
1420 | 1420 |
1421 | 1421 |
1422 static void ArgumentsAdaptorStackCheck(MacroAssembler* masm, | 1422 static void ArgumentsAdaptorStackCheck(MacroAssembler* masm, |
1423 Label* stack_overflow) { | 1423 Label* stack_overflow) { |
1424 // ----------- S t a t e ------------- | 1424 // ----------- S t a t e ------------- |
1425 // -- rax : actual number of arguments | 1425 // -- rax : actual number of arguments |
1426 // -- rbx : expected number of arguments | 1426 // -- rbx : expected number of arguments |
1427 // -- rdi: function (passed through to callee) | 1427 // -- rdx : new target (passed through to callee) |
| 1428 // -- rdi : function (passed through to callee) |
1428 // ----------------------------------- | 1429 // ----------------------------------- |
1429 // Check the stack for overflow. We are not trying to catch | 1430 // Check the stack for overflow. We are not trying to catch |
1430 // interruptions (e.g. debug break and preemption) here, so the "real stack | 1431 // interruptions (e.g. debug break and preemption) here, so the "real stack |
1431 // limit" is checked. | 1432 // limit" is checked. |
1432 Label okay; | 1433 Label okay; |
1433 __ LoadRoot(rdx, Heap::kRealStackLimitRootIndex); | 1434 __ LoadRoot(r8, Heap::kRealStackLimitRootIndex); |
1434 __ movp(rcx, rsp); | 1435 __ movp(rcx, rsp); |
1435 // Make rcx the space we have left. The stack might already be overflowed | 1436 // Make rcx the space we have left. The stack might already be overflowed |
1436 // here which will cause rcx to become negative. | 1437 // here which will cause rcx to become negative. |
1437 __ subp(rcx, rdx); | 1438 __ subp(rcx, r8); |
1438 // Make rdx the space we need for the array when it is unrolled onto the | 1439 // Make r8 the space we need for the array when it is unrolled onto the |
1439 // stack. | 1440 // stack. |
1440 __ movp(rdx, rbx); | 1441 __ movp(r8, rbx); |
1441 __ shlp(rdx, Immediate(kPointerSizeLog2)); | 1442 __ shlp(r8, Immediate(kPointerSizeLog2)); |
1442 // Check if the arguments will overflow the stack. | 1443 // Check if the arguments will overflow the stack. |
1443 __ cmpp(rcx, rdx); | 1444 __ cmpp(rcx, r8); |
1444 __ j(less_equal, stack_overflow); // Signed comparison. | 1445 __ j(less_equal, stack_overflow); // Signed comparison. |
1445 } | 1446 } |
1446 | 1447 |
1447 | 1448 |
1448 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { | 1449 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { |
1449 __ pushq(rbp); | 1450 __ pushq(rbp); |
1450 __ movp(rbp, rsp); | 1451 __ movp(rbp, rsp); |
1451 | 1452 |
1452 // Store the arguments adaptor context sentinel. | 1453 // Store the arguments adaptor context sentinel. |
1453 __ Push(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); | 1454 __ Push(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
(...skipping 22 matching lines...) Expand all Loading... |
1476 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); | 1477 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); |
1477 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); | 1478 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); |
1478 __ PushReturnAddressFrom(rcx); | 1479 __ PushReturnAddressFrom(rcx); |
1479 } | 1480 } |
1480 | 1481 |
1481 | 1482 |
1482 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { | 1483 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { |
1483 // ----------- S t a t e ------------- | 1484 // ----------- S t a t e ------------- |
1484 // -- rax : actual number of arguments | 1485 // -- rax : actual number of arguments |
1485 // -- rbx : expected number of arguments | 1486 // -- rbx : expected number of arguments |
1486 // -- rdi: function (passed through to callee) | 1487 // -- rdx : new target (passed through to callee) |
| 1488 // -- rdi : function (passed through to callee) |
1487 // ----------------------------------- | 1489 // ----------------------------------- |
1488 | 1490 |
1489 Label invoke, dont_adapt_arguments; | 1491 Label invoke, dont_adapt_arguments, stack_overflow; |
1490 Counters* counters = masm->isolate()->counters(); | 1492 Counters* counters = masm->isolate()->counters(); |
1491 __ IncrementCounter(counters->arguments_adaptors(), 1); | 1493 __ IncrementCounter(counters->arguments_adaptors(), 1); |
1492 | 1494 |
1493 Label stack_overflow; | |
1494 ArgumentsAdaptorStackCheck(masm, &stack_overflow); | |
1495 | |
1496 Label enough, too_few; | 1495 Label enough, too_few; |
1497 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); | |
1498 __ cmpp(rax, rbx); | 1496 __ cmpp(rax, rbx); |
1499 __ j(less, &too_few); | 1497 __ j(less, &too_few); |
1500 __ cmpp(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); | 1498 __ cmpp(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); |
1501 __ j(equal, &dont_adapt_arguments); | 1499 __ j(equal, &dont_adapt_arguments); |
1502 | 1500 |
1503 { // Enough parameters: Actual >= expected. | 1501 { // Enough parameters: Actual >= expected. |
1504 __ bind(&enough); | 1502 __ bind(&enough); |
1505 EnterArgumentsAdaptorFrame(masm); | 1503 EnterArgumentsAdaptorFrame(masm); |
| 1504 ArgumentsAdaptorStackCheck(masm, &stack_overflow); |
1506 | 1505 |
1507 // Copy receiver and all expected arguments. | 1506 // Copy receiver and all expected arguments. |
1508 const int offset = StandardFrameConstants::kCallerSPOffset; | 1507 const int offset = StandardFrameConstants::kCallerSPOffset; |
1509 __ leap(rax, Operand(rbp, rax, times_pointer_size, offset)); | 1508 __ leap(rax, Operand(rbp, rax, times_pointer_size, offset)); |
1510 __ Set(r8, -1); // account for receiver | 1509 __ Set(r8, -1); // account for receiver |
1511 | 1510 |
1512 Label copy; | 1511 Label copy; |
1513 __ bind(©); | 1512 __ bind(©); |
1514 __ incp(r8); | 1513 __ incp(r8); |
1515 __ Push(Operand(rax, 0)); | 1514 __ Push(Operand(rax, 0)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 __ j(greater_equal, &no_strong_error, Label::kNear); | 1549 __ j(greater_equal, &no_strong_error, Label::kNear); |
1551 | 1550 |
1552 { | 1551 { |
1553 FrameScope frame(masm, StackFrame::MANUAL); | 1552 FrameScope frame(masm, StackFrame::MANUAL); |
1554 EnterArgumentsAdaptorFrame(masm); | 1553 EnterArgumentsAdaptorFrame(masm); |
1555 __ CallRuntime(Runtime::kThrowStrongModeTooFewArguments, 0); | 1554 __ CallRuntime(Runtime::kThrowStrongModeTooFewArguments, 0); |
1556 } | 1555 } |
1557 | 1556 |
1558 __ bind(&no_strong_error); | 1557 __ bind(&no_strong_error); |
1559 EnterArgumentsAdaptorFrame(masm); | 1558 EnterArgumentsAdaptorFrame(masm); |
| 1559 ArgumentsAdaptorStackCheck(masm, &stack_overflow); |
1560 | 1560 |
1561 // Copy receiver and all actual arguments. | 1561 // Copy receiver and all actual arguments. |
1562 const int offset = StandardFrameConstants::kCallerSPOffset; | 1562 const int offset = StandardFrameConstants::kCallerSPOffset; |
1563 __ leap(rdi, Operand(rbp, rax, times_pointer_size, offset)); | 1563 __ leap(rdi, Operand(rbp, rax, times_pointer_size, offset)); |
1564 __ Set(r8, -1); // account for receiver | 1564 __ Set(r8, -1); // account for receiver |
1565 | 1565 |
1566 Label copy; | 1566 Label copy; |
1567 __ bind(©); | 1567 __ bind(©); |
1568 __ incp(r8); | 1568 __ incp(r8); |
1569 __ Push(Operand(rdi, 0)); | 1569 __ Push(Operand(rdi, 0)); |
(...skipping 11 matching lines...) Expand all Loading... |
1581 __ j(less, &fill); | 1581 __ j(less, &fill); |
1582 | 1582 |
1583 // Restore function pointer. | 1583 // Restore function pointer. |
1584 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1584 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
1585 } | 1585 } |
1586 | 1586 |
1587 // Call the entry point. | 1587 // Call the entry point. |
1588 __ bind(&invoke); | 1588 __ bind(&invoke); |
1589 __ movp(rax, rbx); | 1589 __ movp(rax, rbx); |
1590 // rax : expected number of arguments | 1590 // rax : expected number of arguments |
1591 // rdi: function (passed through to callee) | 1591 // rdx : new target (passed through to callee) |
1592 __ call(rdx); | 1592 // rdi : function (passed through to callee) |
| 1593 __ movp(rcx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
| 1594 __ call(rcx); |
1593 | 1595 |
1594 // Store offset of return address for deoptimizer. | 1596 // Store offset of return address for deoptimizer. |
1595 masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset()); | 1597 masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset()); |
1596 | 1598 |
1597 // Leave frame and return. | 1599 // Leave frame and return. |
1598 LeaveArgumentsAdaptorFrame(masm); | 1600 LeaveArgumentsAdaptorFrame(masm); |
1599 __ ret(0); | 1601 __ ret(0); |
1600 | 1602 |
1601 // ------------------------------------------- | 1603 // ------------------------------------------- |
1602 // Dont adapt arguments. | 1604 // Dont adapt arguments. |
1603 // ------------------------------------------- | 1605 // ------------------------------------------- |
1604 __ bind(&dont_adapt_arguments); | 1606 __ bind(&dont_adapt_arguments); |
1605 __ jmp(rdx); | 1607 __ movp(rcx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
| 1608 __ jmp(rcx); |
1606 | 1609 |
1607 __ bind(&stack_overflow); | 1610 __ bind(&stack_overflow); |
1608 { | 1611 { |
1609 FrameScope frame(masm, StackFrame::MANUAL); | 1612 FrameScope frame(masm, StackFrame::MANUAL); |
1610 EnterArgumentsAdaptorFrame(masm); | |
1611 __ CallRuntime(Runtime::kThrowStackOverflow, 0); | 1613 __ CallRuntime(Runtime::kThrowStackOverflow, 0); |
1612 __ int3(); | 1614 __ int3(); |
1613 } | 1615 } |
1614 } | 1616 } |
1615 | 1617 |
1616 | 1618 |
1617 // static | 1619 // static |
1618 void Builtins::Generate_CallFunction(MacroAssembler* masm, | 1620 void Builtins::Generate_CallFunction(MacroAssembler* masm, |
1619 ConvertReceiverMode mode) { | 1621 ConvertReceiverMode mode) { |
1620 // ----------- S t a t e ------------- | 1622 // ----------- S t a t e ------------- |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 __ ret(0); | 1915 __ ret(0); |
1914 } | 1916 } |
1915 | 1917 |
1916 | 1918 |
1917 #undef __ | 1919 #undef __ |
1918 | 1920 |
1919 } // namespace internal | 1921 } // namespace internal |
1920 } // namespace v8 | 1922 } // namespace v8 |
1921 | 1923 |
1922 #endif // V8_TARGET_ARCH_X64 | 1924 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |