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

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

Issue 1360793002: [builtins] Refactor Invoke to deal with any kind of callable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months 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
OLDNEW
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 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 } 1640 }
1641 1641
1642 1642
1643 // static 1643 // static
1644 void Builtins::Generate_Call(MacroAssembler* masm) { 1644 void Builtins::Generate_Call(MacroAssembler* masm) {
1645 // ----------- S t a t e ------------- 1645 // ----------- S t a t e -------------
1646 // -- x0 : the number of arguments (not including the receiver) 1646 // -- x0 : the number of arguments (not including the receiver)
1647 // -- x1 : the target to call (can be any Object). 1647 // -- x1 : the target to call (can be any Object).
1648 // ----------------------------------- 1648 // -----------------------------------
1649 1649
1650 Label non_smi, non_jsfunction, non_function; 1650 Label non_callable, non_function, non_smi;
1651 __ JumpIfSmi(x1, &non_function); 1651 __ JumpIfSmi(x1, &non_callable);
1652 __ Bind(&non_smi); 1652 __ Bind(&non_smi);
1653 __ CompareObjectType(x1, x2, x2, JS_FUNCTION_TYPE); 1653 __ CompareObjectType(x1, x4, x5, JS_FUNCTION_TYPE);
1654 __ B(ne, &non_jsfunction); 1654 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET,
1655 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); 1655 eq);
1656 __ Bind(&non_jsfunction); 1656 __ Cmp(x5, JS_FUNCTION_PROXY_TYPE);
1657 __ Cmp(x2, JS_FUNCTION_PROXY_TYPE);
1658 __ B(ne, &non_function); 1657 __ B(ne, &non_function);
1659 1658
1660 // 1. Call to function proxy. 1659 // 1. Call to function proxy.
1661 // TODO(neis): This doesn't match the ES6 spec for [[Call]] on proxies. 1660 // TODO(neis): This doesn't match the ES6 spec for [[Call]] on proxies.
1662 __ Ldr(x1, FieldMemOperand(x1, JSFunctionProxy::kCallTrapOffset)); 1661 __ Ldr(x1, FieldMemOperand(x1, JSFunctionProxy::kCallTrapOffset));
1663 __ AssertNotSmi(x1); 1662 __ AssertNotSmi(x1);
1664 __ B(&non_smi); 1663 __ B(&non_smi);
1665 1664
1666 // 2. Call to something else, which might have a [[Call]] internal method (if 1665 // 2. Call to something else, which might have a [[Call]] internal method (if
1667 // not we raise an exception). 1666 // not we raise an exception).
1668 __ Bind(&non_function); 1667 __ Bind(&non_function);
1669 // TODO(bmeurer): I wonder why we prefer to have slow API calls? This could 1668 // Check if target has a [[Call]] internal method.
1670 // be awesome instead; i.e. a trivial improvement would be to call into the 1669 __ Ldrb(x4, FieldMemOperand(x4, Map::kBitFieldOffset));
1671 // runtime and just deal with the API function there instead of returning a 1670 __ TestAndBranchIfAllClear(x4, 1 << Map::kIsCallable, &non_callable);
1672 // delegate from a runtime call that just jumps back to the runtime once
1673 // called. Or, bonus points, call directly into the C API function here, as
1674 // we do in some Crankshaft fast cases.
1675 // Overwrite the original receiver with the (original) target. 1671 // Overwrite the original receiver with the (original) target.
1676 __ Poke(x1, Operand(x0, LSL, kXRegSizeLog2)); 1672 __ Poke(x1, Operand(x0, LSL, kXRegSizeLog2));
1673 // Let the "call_as_function_delegate" take care of the rest.
1674 __ LoadGlobalFunction(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, x1);
1675 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET);
1676
1677 // 3. Call to something that is not callable.
1678 __ bind(&non_callable);
1677 { 1679 {
1678 // Determine the delegate for the target (if any).
1679 FrameScope scope(masm, StackFrame::INTERNAL); 1680 FrameScope scope(masm, StackFrame::INTERNAL);
1680 __ SmiTag(x0); 1681 __ Push(x1);
1681 __ Push(x0, x1); 1682 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1);
1682 __ CallRuntime(Runtime::kGetFunctionDelegate, 1);
1683 __ Mov(x1, x0);
1684 __ Pop(x0);
1685 __ SmiUntag(x0);
1686 } 1683 }
1687 // The delegate is always a regular function.
1688 __ AssertFunction(x1);
1689 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET);
1690 } 1684 }
1691 1685
1692 1686
1693 // static 1687 // static
1694 void Builtins::Generate_ConstructFunction(MacroAssembler* masm) { 1688 void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
1695 // ----------- S t a t e ------------- 1689 // ----------- S t a t e -------------
1696 // -- x0 : the number of arguments (not including the receiver) 1690 // -- x0 : the number of arguments (not including the receiver)
1697 // -- x1 : the constructor to call (checked to be a JSFunction) 1691 // -- x1 : the constructor to call (checked to be a JSFunction)
1698 // -- x3 : the original constructor (checked to be a JSFunction) 1692 // -- x3 : the original constructor (checked to be a JSFunction)
1699 // ----------------------------------- 1693 // -----------------------------------
(...skipping 15 matching lines...) Expand all
1715 1709
1716 // static 1710 // static
1717 void Builtins::Generate_Construct(MacroAssembler* masm) { 1711 void Builtins::Generate_Construct(MacroAssembler* masm) {
1718 // ----------- S t a t e ------------- 1712 // ----------- S t a t e -------------
1719 // -- x0 : the number of arguments (not including the receiver) 1713 // -- x0 : the number of arguments (not including the receiver)
1720 // -- x1 : the constructor to call (can be any Object) 1714 // -- x1 : the constructor to call (can be any Object)
1721 // -- x3 : the original constructor (either the same as the constructor or 1715 // -- x3 : the original constructor (either the same as the constructor or
1722 // the JSFunction on which new was invoked initially) 1716 // the JSFunction on which new was invoked initially)
1723 // ----------------------------------- 1717 // -----------------------------------
1724 1718
1725 Label slow; 1719 Label non_callable, non_function;
1726 __ JumpIfSmi(x1, &slow); 1720 __ JumpIfSmi(x1, &non_callable);
1727 __ CompareObjectType(x1, x5, x5, JS_FUNCTION_TYPE); 1721 __ CompareObjectType(x1, x4, x5, JS_FUNCTION_TYPE);
1728 __ Jump(masm->isolate()->builtins()->ConstructFunction(), 1722 __ Jump(masm->isolate()->builtins()->ConstructFunction(),
1729 RelocInfo::CODE_TARGET, eq); 1723 RelocInfo::CODE_TARGET, eq);
1730 __ Cmp(x5, Operand(JS_FUNCTION_PROXY_TYPE)); 1724 __ Cmp(x5, JS_FUNCTION_PROXY_TYPE);
1731 __ B(ne, &slow); 1725 __ B(ne, &non_function);
1732 1726
1727 // 1. Construct of function proxy.
1733 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. 1728 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies.
1734 __ Ldr(x1, FieldMemOperand(x1, JSFunctionProxy::kConstructTrapOffset)); 1729 __ Ldr(x1, FieldMemOperand(x1, JSFunctionProxy::kConstructTrapOffset));
1735 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); 1730 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1736 1731
1737 __ Bind(&slow); 1732 // 2. Construct of something that else, which might have a [[Construct]]
1733 // internal method (if not we raise an exception).
1734 __ Bind(&non_function);
1735 // Check if target has a [[Call]] internal method.
1736 // TODO(bmeurer): This shoud use IsConstructor once available.
1737 __ Ldrb(x4, FieldMemOperand(x4, Map::kBitFieldOffset));
1738 __ TestAndBranchIfAllClear(x4, 1 << Map::kIsCallable, &non_callable);
1739 // Overwrite the original receiver with the (original) target.
1740 __ Poke(x1, Operand(x0, LSL, kXRegSizeLog2));
1741 // Let the "call_as_constructor_delegate" take care of the rest.
1742 __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, x1);
1743 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET);
1744
1745 // 3. Construct of something that is not callable.
1746 __ bind(&non_callable);
1738 { 1747 {
1739 // Determine the delegate for the target (if any).
1740 FrameScope scope(masm, StackFrame::INTERNAL); 1748 FrameScope scope(masm, StackFrame::INTERNAL);
1741 __ SmiTag(x0); 1749 __ Push(x1);
1742 __ Push(x0, x1); 1750 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1);
1743 __ CallRuntime(Runtime::kGetConstructorDelegate, 1);
1744 __ Mov(x1, x0);
1745 __ Pop(x0);
1746 __ SmiUntag(x0);
1747 } 1751 }
1748 // The delegate is always a regular function.
1749 __ AssertFunction(x1);
1750 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET);
1751 } 1752 }
1752 1753
1753 1754
1754 // static 1755 // static
1755 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { 1756 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) {
1756 // ----------- S t a t e ------------- 1757 // ----------- S t a t e -------------
1757 // -- x0 : the number of arguments (not including the receiver) 1758 // -- x0 : the number of arguments (not including the receiver)
1758 // -- x2 : the address of the first argument to be pushed. Subsequent 1759 // -- x2 : the address of the first argument to be pushed. Subsequent
1759 // arguments should be consecutive above this, in the same order as 1760 // arguments should be consecutive above this, in the same order as
1760 // they are to be pushed onto the stack. 1761 // they are to be pushed onto the stack.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 } 1952 }
1952 } 1953 }
1953 1954
1954 1955
1955 #undef __ 1956 #undef __
1956 1957
1957 } // namespace internal 1958 } // namespace internal
1958 } // namespace v8 1959 } // namespace v8
1959 1960
1960 #endif // V8_TARGET_ARCH_ARM 1961 #endif // V8_TARGET_ARCH_ARM
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698