| 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 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1710 __ InvokeCode(rdx, expected, actual, JUMP_FUNCTION, NullCallWrapper()); | 1710 __ InvokeCode(rdx, expected, actual, JUMP_FUNCTION, NullCallWrapper()); |
| 1711 } | 1711 } |
| 1712 | 1712 |
| 1713 | 1713 |
| 1714 // static | 1714 // static |
| 1715 void Builtins::Generate_Call(MacroAssembler* masm) { | 1715 void Builtins::Generate_Call(MacroAssembler* masm) { |
| 1716 // ----------- S t a t e ------------- | 1716 // ----------- S t a t e ------------- |
| 1717 // -- rax : the number of arguments (not including the receiver) | 1717 // -- rax : the number of arguments (not including the receiver) |
| 1718 // -- rdi : the target to call (can be any Object) | 1718 // -- rdi : the target to call (can be any Object) |
| 1719 // ----------------------------------- | 1719 // ----------------------------------- |
| 1720 StackArgumentsAccessor args(rsp, rax); |
| 1720 | 1721 |
| 1721 Label non_smi, non_function; | 1722 Label non_callable, non_function, non_smi; |
| 1722 __ JumpIfSmi(rdi, &non_function); | 1723 __ JumpIfSmi(rdi, &non_callable); |
| 1723 __ bind(&non_smi); | 1724 __ bind(&non_smi); |
| 1724 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rdx); | 1725 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
| 1725 __ j(equal, masm->isolate()->builtins()->CallFunction(), | 1726 __ j(equal, masm->isolate()->builtins()->CallFunction(), |
| 1726 RelocInfo::CODE_TARGET); | 1727 RelocInfo::CODE_TARGET); |
| 1727 __ CmpInstanceType(rdx, JS_FUNCTION_PROXY_TYPE); | 1728 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); |
| 1728 __ j(not_equal, &non_function); | 1729 __ j(not_equal, &non_function); |
| 1729 | 1730 |
| 1730 // 1. Call to function proxy. | 1731 // 1. Call to function proxy. |
| 1731 // TODO(neis): This doesn't match the ES6 spec for [[Call]] on proxies. | 1732 // TODO(neis): This doesn't match the ES6 spec for [[Call]] on proxies. |
| 1732 __ movp(rdi, FieldOperand(rdi, JSFunctionProxy::kCallTrapOffset)); | 1733 __ movp(rdi, FieldOperand(rdi, JSFunctionProxy::kCallTrapOffset)); |
| 1733 __ AssertNotSmi(rdi); | 1734 __ AssertNotSmi(rdi); |
| 1734 __ jmp(&non_smi); | 1735 __ jmp(&non_smi); |
| 1735 | 1736 |
| 1736 // 2. Call to something else, which might have a [[Call]] internal method (if | 1737 // 2. Call to something else, which might have a [[Call]] internal method (if |
| 1737 // not we raise an exception). | 1738 // not we raise an exception). |
| 1738 __ bind(&non_function); | 1739 __ bind(&non_function); |
| 1739 // TODO(bmeurer): I wonder why we prefer to have slow API calls? This could | 1740 // Check if target has a [[Call]] internal method. |
| 1740 // be awesome instead; i.e. a trivial improvement would be to call into the | 1741 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), |
| 1741 // runtime and just deal with the API function there instead of returning a | 1742 Immediate(1 << Map::kIsCallable)); |
| 1742 // delegate from a runtime call that just jumps back to the runtime once | 1743 __ j(zero, &non_callable, Label::kNear); |
| 1743 // called. Or, bonus points, call directly into the C API function here, as | |
| 1744 // we do in some Crankshaft fast cases. | |
| 1745 StackArgumentsAccessor args(rsp, rax); | |
| 1746 // Overwrite the original receiver with the (original) target. | 1744 // Overwrite the original receiver with the (original) target. |
| 1747 __ movp(args.GetReceiverOperand(), rdi); | 1745 __ movp(args.GetReceiverOperand(), rdi); |
| 1746 // Let the "call_as_function_delegate" take care of the rest. |
| 1747 __ LoadGlobalFunction(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, rdi); |
| 1748 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); |
| 1749 |
| 1750 // 3. Call to something that is not callable. |
| 1751 __ bind(&non_callable); |
| 1748 { | 1752 { |
| 1749 // Determine the delegate for the target (if any). | |
| 1750 FrameScope scope(masm, StackFrame::INTERNAL); | 1753 FrameScope scope(masm, StackFrame::INTERNAL); |
| 1751 __ Integer32ToSmi(rax, rax); | |
| 1752 __ Push(rax); | |
| 1753 __ Push(rdi); | 1754 __ Push(rdi); |
| 1754 __ CallRuntime(Runtime::kGetFunctionDelegate, 1); | 1755 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); |
| 1755 __ movp(rdi, rax); | |
| 1756 __ Pop(rax); | |
| 1757 __ SmiToInteger32(rax, rax); | |
| 1758 } | 1756 } |
| 1759 // The delegate is always a regular function. | |
| 1760 __ AssertFunction(rdi); | |
| 1761 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); | |
| 1762 } | 1757 } |
| 1763 | 1758 |
| 1764 | 1759 |
| 1765 // static | 1760 // static |
| 1766 void Builtins::Generate_ConstructFunction(MacroAssembler* masm) { | 1761 void Builtins::Generate_ConstructFunction(MacroAssembler* masm) { |
| 1767 // ----------- S t a t e ------------- | 1762 // ----------- S t a t e ------------- |
| 1768 // -- rax : the number of arguments (not including the receiver) | 1763 // -- rax : the number of arguments (not including the receiver) |
| 1769 // -- rdx : the original constructor (checked to be a JSFunction) | 1764 // -- rdx : the original constructor (checked to be a JSFunction) |
| 1770 // -- rdi : the constructor to call (checked to be a JSFunction) | 1765 // -- rdi : the constructor to call (checked to be a JSFunction) |
| 1771 // ----------------------------------- | 1766 // ----------------------------------- |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1786 | 1781 |
| 1787 | 1782 |
| 1788 // static | 1783 // static |
| 1789 void Builtins::Generate_Construct(MacroAssembler* masm) { | 1784 void Builtins::Generate_Construct(MacroAssembler* masm) { |
| 1790 // ----------- S t a t e ------------- | 1785 // ----------- S t a t e ------------- |
| 1791 // -- rax : the number of arguments (not including the receiver) | 1786 // -- rax : the number of arguments (not including the receiver) |
| 1792 // -- rdx : the original constructor (either the same as the constructor or | 1787 // -- rdx : the original constructor (either the same as the constructor or |
| 1793 // the JSFunction on which new was invoked initially) | 1788 // the JSFunction on which new was invoked initially) |
| 1794 // -- rdi : the constructor to call (can be any Object) | 1789 // -- rdi : the constructor to call (can be any Object) |
| 1795 // ----------------------------------- | 1790 // ----------------------------------- |
| 1791 StackArgumentsAccessor args(rsp, rax); |
| 1796 | 1792 |
| 1797 Label slow; | 1793 Label non_callable, non_function; |
| 1798 __ JumpIfSmi(rdi, &slow, Label::kNear); | 1794 __ JumpIfSmi(rdi, &non_callable); |
| 1799 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 1795 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
| 1800 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), | 1796 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), |
| 1801 RelocInfo::CODE_TARGET); | 1797 RelocInfo::CODE_TARGET); |
| 1802 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); | 1798 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); |
| 1803 __ j(not_equal, &slow, Label::kNear); | 1799 __ j(not_equal, &non_function, Label::kNear); |
| 1804 | 1800 |
| 1801 // 1. Construct of function proxy. |
| 1805 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. | 1802 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. |
| 1806 __ movp(rdi, FieldOperand(rdi, JSFunctionProxy::kConstructTrapOffset)); | 1803 __ movp(rdi, FieldOperand(rdi, JSFunctionProxy::kConstructTrapOffset)); |
| 1807 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); | 1804 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); |
| 1808 | 1805 |
| 1809 __ bind(&slow); | 1806 // 2. Construct of something else, which might have a [[Construct]] internal |
| 1807 // method (if not we raise an exception). |
| 1808 __ bind(&non_function); |
| 1809 // Check if target has a [[Call]] internal method. |
| 1810 // TODO(bmeurer): This shoud use IsConstructor once available. |
| 1811 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), |
| 1812 Immediate(1 << Map::kIsCallable)); |
| 1813 __ j(zero, &non_callable, Label::kNear); |
| 1814 // Overwrite the original receiver with the (original) target. |
| 1815 __ movp(args.GetReceiverOperand(), rdi); |
| 1816 // Let the "call_as_constructor_delegate" take care of the rest. |
| 1817 __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, rdi); |
| 1818 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); |
| 1819 |
| 1820 // 3. Construct of something that is not callable. |
| 1821 __ bind(&non_callable); |
| 1810 { | 1822 { |
| 1811 // Determine the delegate for the target (if any). | |
| 1812 FrameScope scope(masm, StackFrame::INTERNAL); | 1823 FrameScope scope(masm, StackFrame::INTERNAL); |
| 1813 __ Integer32ToSmi(rax, rax); | |
| 1814 __ Push(rax); | |
| 1815 __ Push(rdi); | 1824 __ Push(rdi); |
| 1816 __ CallRuntime(Runtime::kGetConstructorDelegate, 1); | 1825 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); |
| 1817 __ movp(rdi, rax); | |
| 1818 __ Pop(rax); | |
| 1819 __ SmiToInteger32(rax, rax); | |
| 1820 } | 1826 } |
| 1821 // The delegate is always a regular function. | |
| 1822 __ AssertFunction(rdi); | |
| 1823 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); | |
| 1824 } | 1827 } |
| 1825 | 1828 |
| 1826 | 1829 |
| 1827 // static | 1830 // static |
| 1828 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { | 1831 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { |
| 1829 // ----------- S t a t e ------------- | 1832 // ----------- S t a t e ------------- |
| 1830 // -- rax : the number of arguments (not including the receiver) | 1833 // -- rax : the number of arguments (not including the receiver) |
| 1831 // -- rbx : the address of the first argument to be pushed. Subsequent | 1834 // -- rbx : the address of the first argument to be pushed. Subsequent |
| 1832 // arguments should be consecutive above this, in the same order as | 1835 // arguments should be consecutive above this, in the same order as |
| 1833 // they are to be pushed onto the stack. | 1836 // they are to be pushed onto the stack. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 __ ret(0); | 1914 __ ret(0); |
| 1912 } | 1915 } |
| 1913 | 1916 |
| 1914 | 1917 |
| 1915 #undef __ | 1918 #undef __ |
| 1916 | 1919 |
| 1917 } // namespace internal | 1920 } // namespace internal |
| 1918 } // namespace v8 | 1921 } // namespace v8 |
| 1919 | 1922 |
| 1920 #endif // V8_TARGET_ARCH_X64 | 1923 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |