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 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 // The function is a "classConstructor", need to raise an exception. | 1874 // The function is a "classConstructor", need to raise an exception. |
1875 __ bind(&class_constructor); | 1875 __ bind(&class_constructor); |
1876 { | 1876 { |
1877 FrameScope frame(masm, StackFrame::INTERNAL); | 1877 FrameScope frame(masm, StackFrame::INTERNAL); |
1878 __ Push(x1); | 1878 __ Push(x1); |
1879 __ CallRuntime(Runtime::kThrowConstructorNonCallableError, 1); | 1879 __ CallRuntime(Runtime::kThrowConstructorNonCallableError, 1); |
1880 } | 1880 } |
1881 } | 1881 } |
1882 | 1882 |
1883 | 1883 |
1884 namespace { | |
1885 | |
1886 void Generate_PushBoundArguments(MacroAssembler* masm) { | |
1887 // ----------- S t a t e ------------- | |
1888 // -- x0 : the number of arguments (not including the receiver) | |
1889 // -- x1 : target (checked to be a JSBoundFunction) | |
1890 // -- x3 : new.target (only in case of [[Construct]]) | |
1891 // ----------------------------------- | |
1892 | |
1893 // Load [[BoundArguments]] into x2 and length of that into x4. | |
1894 Label no_bound_arguments; | |
1895 __ Ldr(x2, FieldMemOperand(x1, JSBoundFunction::kBoundArgumentsOffset)); | |
1896 __ Ldrsw(x4, UntagSmiFieldMemOperand(x2, FixedArray::kLengthOffset)); | |
1897 __ Cmp(x4, 0); | |
1898 __ B(eq, &no_bound_arguments); | |
1899 { | |
1900 // ----------- S t a t e ------------- | |
1901 // -- x0 : the number of arguments (not including the receiver) | |
1902 // -- x1 : target (checked to be a JSBoundFunction) | |
1903 // -- x2 : the [[BoundArguments]] (implemented as FixedArray) | |
1904 // -- x3 : new.target (only in case of [[Construct]]) | |
1905 // -- x4 : the number of [[BoundArguments]] | |
1906 // ----------------------------------- | |
1907 | |
1908 // Reserve stack space for the [[BoundArguments]]. | |
1909 { | |
1910 Label done; | |
1911 __ Claim(x4); | |
1912 // Check the stack for overflow. We are not trying to catch interruptions | |
1913 // (i.e. debug break and preemption) here, so check the "real stack | |
1914 // limit". | |
1915 __ CompareRoot(jssp, Heap::kRealStackLimitRootIndex); | |
1916 __ B(gt, &done); // Signed comparison. | |
1917 // Restore the stack pointer. | |
1918 __ Drop(x4); | |
1919 { | |
1920 FrameScope scope(masm, StackFrame::MANUAL); | |
1921 __ EnterFrame(StackFrame::INTERNAL); | |
1922 __ CallRuntime(Runtime::kThrowStackOverflow, 0); | |
1923 } | |
1924 __ Bind(&done); | |
1925 } | |
1926 | |
1927 // Relocate arguments down the stack. | |
1928 { | |
1929 Label loop, done_loop; | |
1930 __ Mov(x5, 0); | |
1931 __ Bind(&loop); | |
1932 __ Cmp(x5, x0); | |
1933 __ B(gt, &done_loop); | |
1934 __ Peek(x10, Operand(x4, LSL, kPointerSizeLog2)); | |
1935 __ Poke(x10, Operand(x5, LSL, kPointerSizeLog2)); | |
1936 __ Add(x4, x4, 1); | |
1937 __ Add(x5, x5, 1); | |
1938 __ B(&loop); | |
1939 __ Bind(&done_loop); | |
1940 } | |
1941 | |
1942 // Copy [[BoundArguments]] to the stack (below the arguments). | |
1943 { | |
1944 Label loop; | |
1945 __ Ldrsw(x4, UntagSmiFieldMemOperand(x2, FixedArray::kLengthOffset)); | |
1946 __ Add(x2, x2, FixedArray::kHeaderSize - kHeapObjectTag); | |
1947 __ Bind(&loop); | |
1948 __ Subs(x4, x4, 1); | |
1949 __ Ldr(x10, MemOperand(x2, x4, LSL, kPointerSizeLog2)); | |
1950 __ Poke(x10, Operand(x0, LSL, kPointerSizeLog2)); | |
1951 __ Add(x0, x0, 1); | |
1952 __ B(gt, &loop); | |
1953 } | |
1954 } | |
1955 __ Bind(&no_bound_arguments); | |
1956 } | |
1957 | |
1958 } // namespace | |
1959 | |
1960 | |
1961 // static | |
1962 void Builtins::Generate_CallBoundFunction(MacroAssembler* masm) { | |
1963 // ----------- S t a t e ------------- | |
1964 // -- x0 : the number of arguments (not including the receiver) | |
1965 // -- x1 : the function to call (checked to be a JSBoundFunction) | |
1966 // ----------------------------------- | |
1967 __ AssertBoundFunction(x1); | |
1968 | |
1969 // Patch the receiver to [[BoundThis]]. | |
1970 __ Ldr(x10, FieldMemOperand(x1, JSBoundFunction::kBoundThisOffset)); | |
1971 __ Poke(x10, Operand(x0, LSL, kPointerSizeLog2)); | |
1972 | |
1973 // Push the [[BoundArguments]] onto the stack. | |
1974 Generate_PushBoundArguments(masm); | |
1975 | |
1976 // Call the [[BoundTargetFunction]] via the Call builtin. | |
1977 __ Ldr(x1, FieldMemOperand(x1, JSBoundFunction::kBoundTargetFunctionOffset)); | |
1978 __ Mov(x10, | |
1979 ExternalReference(Builtins::kCall_ReceiverIsAny, masm->isolate())); | |
1980 __ Ldr(x11, MemOperand(x10)); | |
1981 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag); | |
1982 __ Br(x12); | |
1983 } | |
1984 | |
1985 | |
1986 // static | 1884 // static |
1987 void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) { | 1885 void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) { |
1988 // ----------- S t a t e ------------- | 1886 // ----------- S t a t e ------------- |
1989 // -- x0 : the number of arguments (not including the receiver) | 1887 // -- x0 : the number of arguments (not including the receiver) |
1990 // -- x1 : the target to call (can be any Object). | 1888 // -- x1 : the target to call (can be any Object). |
1991 // ----------------------------------- | 1889 // ----------------------------------- |
1992 | 1890 |
1993 Label non_callable, non_function, non_smi; | 1891 Label non_callable, non_function, non_smi; |
1994 __ JumpIfSmi(x1, &non_callable); | 1892 __ JumpIfSmi(x1, &non_callable); |
1995 __ Bind(&non_smi); | 1893 __ Bind(&non_smi); |
1996 __ CompareObjectType(x1, x4, x5, JS_FUNCTION_TYPE); | 1894 __ CompareObjectType(x1, x4, x5, JS_FUNCTION_TYPE); |
1997 __ Jump(masm->isolate()->builtins()->CallFunction(mode), | 1895 __ Jump(masm->isolate()->builtins()->CallFunction(mode), |
1998 RelocInfo::CODE_TARGET, eq); | 1896 RelocInfo::CODE_TARGET, eq); |
1999 __ Cmp(x5, JS_BOUND_FUNCTION_TYPE); | |
2000 __ Jump(masm->isolate()->builtins()->CallBoundFunction(), | |
2001 RelocInfo::CODE_TARGET, eq); | |
2002 __ Cmp(x5, JS_PROXY_TYPE); | 1897 __ Cmp(x5, JS_PROXY_TYPE); |
2003 __ B(ne, &non_function); | 1898 __ B(ne, &non_function); |
2004 | 1899 |
2005 // 1. Runtime fallback for Proxy [[Call]]. | 1900 // 1. Runtime fallback for Proxy [[Call]]. |
2006 __ Push(x1); | 1901 __ Push(x1); |
2007 // Increase the arguments size to include the pushed function and the | 1902 // Increase the arguments size to include the pushed function and the |
2008 // existing receiver on the stack. | 1903 // existing receiver on the stack. |
2009 __ Add(x0, x0, Operand(2)); | 1904 __ Add(x0, x0, Operand(2)); |
2010 // Tail-call to the runtime. | 1905 // Tail-call to the runtime. |
2011 __ JumpToExternalReference( | 1906 __ JumpToExternalReference( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 // Tail call to the function-specific construct stub (still in the caller | 1946 // Tail call to the function-specific construct stub (still in the caller |
2052 // context at this point). | 1947 // context at this point). |
2053 __ Ldr(x4, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); | 1948 __ Ldr(x4, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); |
2054 __ Ldr(x4, FieldMemOperand(x4, SharedFunctionInfo::kConstructStubOffset)); | 1949 __ Ldr(x4, FieldMemOperand(x4, SharedFunctionInfo::kConstructStubOffset)); |
2055 __ Add(x4, x4, Code::kHeaderSize - kHeapObjectTag); | 1950 __ Add(x4, x4, Code::kHeaderSize - kHeapObjectTag); |
2056 __ Br(x4); | 1951 __ Br(x4); |
2057 } | 1952 } |
2058 | 1953 |
2059 | 1954 |
2060 // static | 1955 // static |
2061 void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) { | |
2062 // ----------- S t a t e ------------- | |
2063 // -- x0 : the number of arguments (not including the receiver) | |
2064 // -- x1 : the function to call (checked to be a JSBoundFunction) | |
2065 // -- x3 : the new target (checked to be a constructor) | |
2066 // ----------------------------------- | |
2067 __ AssertBoundFunction(x1); | |
2068 | |
2069 // Push the [[BoundArguments]] onto the stack. | |
2070 Generate_PushBoundArguments(masm); | |
2071 | |
2072 // Patch new.target to [[BoundTargetFunction]] if new.target equals target. | |
2073 { | |
2074 Label done; | |
2075 __ Cmp(x1, x3); | |
2076 __ B(ne, &done); | |
2077 __ Ldr(x3, | |
2078 FieldMemOperand(x1, JSBoundFunction::kBoundTargetFunctionOffset)); | |
2079 __ Bind(&done); | |
2080 } | |
2081 | |
2082 // Construct the [[BoundTargetFunction]] via the Construct builtin. | |
2083 __ Ldr(x1, FieldMemOperand(x1, JSBoundFunction::kBoundTargetFunctionOffset)); | |
2084 __ Mov(x10, ExternalReference(Builtins::kConstruct, masm->isolate())); | |
2085 __ Ldr(x11, MemOperand(x10)); | |
2086 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag); | |
2087 __ Br(x12); | |
2088 } | |
2089 | |
2090 | |
2091 // static | |
2092 void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { | 1956 void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { |
2093 // ----------- S t a t e ------------- | 1957 // ----------- S t a t e ------------- |
2094 // -- x0 : the number of arguments (not including the receiver) | 1958 // -- x0 : the number of arguments (not including the receiver) |
2095 // -- x1 : the constructor to call (checked to be a JSProxy) | 1959 // -- x1 : the constructor to call (checked to be a JSProxy) |
2096 // -- x3 : the new target (either the same as the constructor or | 1960 // -- x3 : the new target (either the same as the constructor or |
2097 // the JSFunction on which new was invoked initially) | 1961 // the JSFunction on which new was invoked initially) |
2098 // ----------------------------------- | 1962 // ----------------------------------- |
2099 | 1963 |
2100 // Call into the Runtime for Proxy [[Construct]]. | 1964 // Call into the Runtime for Proxy [[Construct]]. |
2101 __ Push(x1); | 1965 __ Push(x1); |
(...skipping 21 matching lines...) Expand all Loading... |
2123 | 1987 |
2124 // Dispatch based on instance type. | 1988 // Dispatch based on instance type. |
2125 __ CompareObjectType(x1, x4, x5, JS_FUNCTION_TYPE); | 1989 __ CompareObjectType(x1, x4, x5, JS_FUNCTION_TYPE); |
2126 __ Jump(masm->isolate()->builtins()->ConstructFunction(), | 1990 __ Jump(masm->isolate()->builtins()->ConstructFunction(), |
2127 RelocInfo::CODE_TARGET, eq); | 1991 RelocInfo::CODE_TARGET, eq); |
2128 | 1992 |
2129 // Check if target has a [[Construct]] internal method. | 1993 // Check if target has a [[Construct]] internal method. |
2130 __ Ldrb(x2, FieldMemOperand(x4, Map::kBitFieldOffset)); | 1994 __ Ldrb(x2, FieldMemOperand(x4, Map::kBitFieldOffset)); |
2131 __ TestAndBranchIfAllClear(x2, 1 << Map::kIsConstructor, &non_constructor); | 1995 __ TestAndBranchIfAllClear(x2, 1 << Map::kIsConstructor, &non_constructor); |
2132 | 1996 |
2133 // Only dispatch to bound functions after checking whether they are | |
2134 // constructors. | |
2135 __ Cmp(x5, JS_BOUND_FUNCTION_TYPE); | |
2136 __ Jump(masm->isolate()->builtins()->ConstructBoundFunction(), | |
2137 RelocInfo::CODE_TARGET, eq); | |
2138 | |
2139 // Only dispatch to proxies after checking whether they are constructors. | 1997 // Only dispatch to proxies after checking whether they are constructors. |
2140 __ Cmp(x5, JS_PROXY_TYPE); | 1998 __ Cmp(x5, JS_PROXY_TYPE); |
2141 __ Jump(masm->isolate()->builtins()->ConstructProxy(), RelocInfo::CODE_TARGET, | 1999 __ Jump(masm->isolate()->builtins()->ConstructProxy(), RelocInfo::CODE_TARGET, |
2142 eq); | 2000 eq); |
2143 | 2001 |
2144 // Called Construct on an exotic Object with a [[Construct]] internal method. | 2002 // Called Construct on an exotic Object with a [[Construct]] internal method. |
2145 { | 2003 { |
2146 // Overwrite the original receiver with the (original) target. | 2004 // Overwrite the original receiver with the (original) target. |
2147 __ Poke(x1, Operand(x0, LSL, kXRegSizeLog2)); | 2005 __ Poke(x1, Operand(x0, LSL, kXRegSizeLog2)); |
2148 // Let the "call_as_constructor_delegate" take care of the rest. | 2006 // Let the "call_as_constructor_delegate" take care of the rest. |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2398 } | 2256 } |
2399 } | 2257 } |
2400 | 2258 |
2401 | 2259 |
2402 #undef __ | 2260 #undef __ |
2403 | 2261 |
2404 } // namespace internal | 2262 } // namespace internal |
2405 } // namespace v8 | 2263 } // namespace v8 |
2406 | 2264 |
2407 #endif // V8_TARGET_ARCH_ARM | 2265 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |