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

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

Issue 1542963002: [runtime] Introduce dedicated JSBoundFunction to represent bound functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@FunctionConstructor
Patch Set: [arm64] Poke does not preserve flags with --debug-code. Created 4 years, 11 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
« no previous file with comments | « src/api-natives.cc ('k') | src/arm/code-stubs-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_ARM 5 #if V8_TARGET_ARCH_ARM
6 6
7 #include "src/codegen.h" 7 #include "src/codegen.h"
8 #include "src/debug/debug.h" 8 #include "src/debug/debug.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 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 // The function is a "classConstructor", need to raise an exception. 1886 // The function is a "classConstructor", need to raise an exception.
1887 __ bind(&class_constructor); 1887 __ bind(&class_constructor);
1888 { 1888 {
1889 FrameScope frame(masm, StackFrame::INTERNAL); 1889 FrameScope frame(masm, StackFrame::INTERNAL);
1890 __ push(r1); 1890 __ push(r1);
1891 __ CallRuntime(Runtime::kThrowConstructorNonCallableError, 1); 1891 __ CallRuntime(Runtime::kThrowConstructorNonCallableError, 1);
1892 } 1892 }
1893 } 1893 }
1894 1894
1895 1895
1896 namespace {
1897
1898 void Generate_PushBoundArguments(MacroAssembler* masm) {
1899 // ----------- S t a t e -------------
1900 // -- r0 : the number of arguments (not including the receiver)
1901 // -- r1 : target (checked to be a JSBoundFunction)
1902 // -- r3 : new.target (only in case of [[Construct]])
1903 // -----------------------------------
1904
1905 // Load [[BoundArguments]] into r2 and length of that into r4.
1906 Label no_bound_arguments;
1907 __ ldr(r2, FieldMemOperand(r1, JSBoundFunction::kBoundArgumentsOffset));
1908 __ ldr(r4, FieldMemOperand(r2, FixedArray::kLengthOffset));
1909 __ SmiUntag(r4);
1910 __ cmp(r4, Operand(0));
1911 __ b(eq, &no_bound_arguments);
1912 {
1913 // ----------- S t a t e -------------
1914 // -- r0 : the number of arguments (not including the receiver)
1915 // -- r1 : target (checked to be a JSBoundFunction)
1916 // -- r2 : the [[BoundArguments]] (implemented as FixedArray)
1917 // -- r3 : new.target (only in case of [[Construct]])
1918 // -- r4 : the number of [[BoundArguments]]
1919 // -----------------------------------
1920
1921 // Reserve stack space for the [[BoundArguments]].
1922 {
1923 Label done;
1924 __ sub(sp, sp, Operand(r4, LSL, kPointerSizeLog2));
1925 // Check the stack for overflow. We are not trying to catch interruptions
1926 // (i.e. debug break and preemption) here, so check the "real stack
1927 // limit".
1928 __ CompareRoot(sp, Heap::kRealStackLimitRootIndex);
1929 __ b(gt, &done); // Signed comparison.
1930 // Restore the stack pointer.
1931 __ add(sp, sp, Operand(r4, LSL, kPointerSizeLog2));
1932 {
1933 FrameScope scope(masm, StackFrame::MANUAL);
1934 __ EnterFrame(StackFrame::INTERNAL);
1935 __ CallRuntime(Runtime::kThrowStackOverflow, 0);
1936 }
1937 __ bind(&done);
1938 }
1939
1940 // Relocate arguments down the stack.
1941 {
1942 Label loop, done_loop;
1943 __ mov(r5, Operand(0));
1944 __ bind(&loop);
1945 __ cmp(r5, r0);
1946 __ b(gt, &done_loop);
1947 __ ldr(ip, MemOperand(sp, r4, LSL, kPointerSizeLog2));
1948 __ str(ip, MemOperand(sp, r5, LSL, kPointerSizeLog2));
1949 __ add(r4, r4, Operand(1));
1950 __ add(r5, r5, Operand(1));
1951 __ b(&loop);
1952 __ bind(&done_loop);
1953 }
1954
1955 // Copy [[BoundArguments]] to the stack (below the arguments).
1956 {
1957 Label loop;
1958 __ ldr(r4, FieldMemOperand(r2, FixedArray::kLengthOffset));
1959 __ SmiUntag(r4);
1960 __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1961 __ bind(&loop);
1962 __ sub(r4, r4, Operand(1), SetCC);
1963 __ ldr(ip, MemOperand(r2, r4, LSL, kPointerSizeLog2));
1964 __ str(ip, MemOperand(sp, r0, LSL, kPointerSizeLog2));
1965 __ add(r0, r0, Operand(1));
1966 __ b(gt, &loop);
1967 }
1968 }
1969 __ bind(&no_bound_arguments);
1970 }
1971
1972 } // namespace
1973
1974
1975 // static
1976 void Builtins::Generate_CallBoundFunction(MacroAssembler* masm) {
1977 // ----------- S t a t e -------------
1978 // -- r0 : the number of arguments (not including the receiver)
1979 // -- r1 : the function to call (checked to be a JSBoundFunction)
1980 // -----------------------------------
1981 __ AssertBoundFunction(r1);
1982
1983 // Patch the receiver to [[BoundThis]].
1984 __ ldr(ip, FieldMemOperand(r1, JSBoundFunction::kBoundThisOffset));
1985 __ str(ip, MemOperand(sp, r0, LSL, kPointerSizeLog2));
1986
1987 // Push the [[BoundArguments]] onto the stack.
1988 Generate_PushBoundArguments(masm);
1989
1990 // Call the [[BoundTargetFunction]] via the Call builtin.
1991 __ ldr(r1, FieldMemOperand(r1, JSBoundFunction::kBoundTargetFunctionOffset));
1992 __ mov(ip, Operand(ExternalReference(Builtins::kCall_ReceiverIsAny,
1993 masm->isolate())));
1994 __ ldr(ip, MemOperand(ip));
1995 __ add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
1996 }
1997
1998
1896 // static 1999 // static
1897 void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) { 2000 void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
1898 // ----------- S t a t e ------------- 2001 // ----------- S t a t e -------------
1899 // -- r0 : the number of arguments (not including the receiver) 2002 // -- r0 : the number of arguments (not including the receiver)
1900 // -- r1 : the target to call (can be any Object). 2003 // -- r1 : the target to call (can be any Object).
1901 // ----------------------------------- 2004 // -----------------------------------
1902 2005
1903 Label non_callable, non_function, non_smi; 2006 Label non_callable, non_function, non_smi;
1904 __ JumpIfSmi(r1, &non_callable); 2007 __ JumpIfSmi(r1, &non_callable);
1905 __ bind(&non_smi); 2008 __ bind(&non_smi);
1906 __ CompareObjectType(r1, r4, r5, JS_FUNCTION_TYPE); 2009 __ CompareObjectType(r1, r4, r5, JS_FUNCTION_TYPE);
1907 __ Jump(masm->isolate()->builtins()->CallFunction(mode), 2010 __ Jump(masm->isolate()->builtins()->CallFunction(mode),
1908 RelocInfo::CODE_TARGET, eq); 2011 RelocInfo::CODE_TARGET, eq);
2012 __ cmp(r5, Operand(JS_BOUND_FUNCTION_TYPE));
2013 __ Jump(masm->isolate()->builtins()->CallBoundFunction(),
2014 RelocInfo::CODE_TARGET, eq);
1909 __ cmp(r5, Operand(JS_PROXY_TYPE)); 2015 __ cmp(r5, Operand(JS_PROXY_TYPE));
1910 __ b(ne, &non_function); 2016 __ b(ne, &non_function);
1911 2017
1912 // 1. Runtime fallback for Proxy [[Call]]. 2018 // 1. Runtime fallback for Proxy [[Call]].
1913 __ Push(r1); 2019 __ Push(r1);
1914 // Increase the arguments size to include the pushed function and the 2020 // Increase the arguments size to include the pushed function and the
1915 // existing receiver on the stack. 2021 // existing receiver on the stack.
1916 __ add(r0, r0, Operand(2)); 2022 __ add(r0, r0, Operand(2));
1917 // Tail-call to the runtime. 2023 // Tail-call to the runtime.
1918 __ JumpToExternalReference( 2024 __ JumpToExternalReference(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 2064
1959 // Tail call to the function-specific construct stub (still in the caller 2065 // Tail call to the function-specific construct stub (still in the caller
1960 // context at this point). 2066 // context at this point).
1961 __ ldr(r4, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); 2067 __ ldr(r4, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
1962 __ ldr(r4, FieldMemOperand(r4, SharedFunctionInfo::kConstructStubOffset)); 2068 __ ldr(r4, FieldMemOperand(r4, SharedFunctionInfo::kConstructStubOffset));
1963 __ add(pc, r4, Operand(Code::kHeaderSize - kHeapObjectTag)); 2069 __ add(pc, r4, Operand(Code::kHeaderSize - kHeapObjectTag));
1964 } 2070 }
1965 2071
1966 2072
1967 // static 2073 // static
2074 void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) {
2075 // ----------- S t a t e -------------
2076 // -- r0 : the number of arguments (not including the receiver)
2077 // -- r1 : the function to call (checked to be a JSBoundFunction)
2078 // -- r3 : the new target (checked to be a constructor)
2079 // -----------------------------------
2080 __ AssertBoundFunction(r1);
2081
2082 // Push the [[BoundArguments]] onto the stack.
2083 Generate_PushBoundArguments(masm);
2084
2085 // Patch new.target to [[BoundTargetFunction]] if new.target equals target.
2086 __ cmp(r1, r3);
2087 __ ldr(r3, FieldMemOperand(r1, JSBoundFunction::kBoundTargetFunctionOffset),
2088 eq);
2089
2090 // Construct the [[BoundTargetFunction]] via the Construct builtin.
2091 __ ldr(r1, FieldMemOperand(r1, JSBoundFunction::kBoundTargetFunctionOffset));
2092 __ mov(ip, Operand(ExternalReference(Builtins::kConstruct, masm->isolate())));
2093 __ ldr(ip, MemOperand(ip));
2094 __ add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
2095 }
2096
2097
2098 // static
1968 void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { 2099 void Builtins::Generate_ConstructProxy(MacroAssembler* masm) {
1969 // ----------- S t a t e ------------- 2100 // ----------- S t a t e -------------
1970 // -- r0 : the number of arguments (not including the receiver) 2101 // -- r0 : the number of arguments (not including the receiver)
1971 // -- r1 : the constructor to call (checked to be a JSProxy) 2102 // -- r1 : the constructor to call (checked to be a JSProxy)
1972 // -- r3 : the new target (either the same as the constructor or 2103 // -- r3 : the new target (either the same as the constructor or
1973 // the JSFunction on which new was invoked initially) 2104 // the JSFunction on which new was invoked initially)
1974 // ----------------------------------- 2105 // -----------------------------------
1975 2106
1976 // Call into the Runtime for Proxy [[Construct]]. 2107 // Call into the Runtime for Proxy [[Construct]].
1977 __ Push(r1); 2108 __ Push(r1);
(...skipping 22 matching lines...) Expand all
2000 // Dispatch based on instance type. 2131 // Dispatch based on instance type.
2001 __ CompareObjectType(r1, r4, r5, JS_FUNCTION_TYPE); 2132 __ CompareObjectType(r1, r4, r5, JS_FUNCTION_TYPE);
2002 __ Jump(masm->isolate()->builtins()->ConstructFunction(), 2133 __ Jump(masm->isolate()->builtins()->ConstructFunction(),
2003 RelocInfo::CODE_TARGET, eq); 2134 RelocInfo::CODE_TARGET, eq);
2004 2135
2005 // Check if target has a [[Construct]] internal method. 2136 // Check if target has a [[Construct]] internal method.
2006 __ ldrb(r2, FieldMemOperand(r4, Map::kBitFieldOffset)); 2137 __ ldrb(r2, FieldMemOperand(r4, Map::kBitFieldOffset));
2007 __ tst(r2, Operand(1 << Map::kIsConstructor)); 2138 __ tst(r2, Operand(1 << Map::kIsConstructor));
2008 __ b(eq, &non_constructor); 2139 __ b(eq, &non_constructor);
2009 2140
2141 // Only dispatch to bound functions after checking whether they are
2142 // constructors.
2143 __ cmp(r5, Operand(JS_BOUND_FUNCTION_TYPE));
2144 __ Jump(masm->isolate()->builtins()->ConstructBoundFunction(),
2145 RelocInfo::CODE_TARGET, eq);
2146
2010 // Only dispatch to proxies after checking whether they are constructors. 2147 // Only dispatch to proxies after checking whether they are constructors.
2011 __ cmp(r5, Operand(JS_PROXY_TYPE)); 2148 __ cmp(r5, Operand(JS_PROXY_TYPE));
2012 __ Jump(masm->isolate()->builtins()->ConstructProxy(), RelocInfo::CODE_TARGET, 2149 __ Jump(masm->isolate()->builtins()->ConstructProxy(), RelocInfo::CODE_TARGET,
2013 eq); 2150 eq);
2014 2151
2015 // Called Construct on an exotic Object with a [[Construct]] internal method. 2152 // Called Construct on an exotic Object with a [[Construct]] internal method.
2016 { 2153 {
2017 // Overwrite the original receiver with the (original) target. 2154 // Overwrite the original receiver with the (original) target.
2018 __ str(r1, MemOperand(sp, r0, LSL, kPointerSizeLog2)); 2155 __ str(r1, MemOperand(sp, r0, LSL, kPointerSizeLog2));
2019 // Let the "call_as_constructor_delegate" take care of the rest. 2156 // Let the "call_as_constructor_delegate" take care of the rest.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 } 2312 }
2176 } 2313 }
2177 2314
2178 2315
2179 #undef __ 2316 #undef __
2180 2317
2181 } // namespace internal 2318 } // namespace internal
2182 } // namespace v8 2319 } // namespace v8
2183 2320
2184 #endif // V8_TARGET_ARCH_ARM 2321 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « src/api-natives.cc ('k') | src/arm/code-stubs-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698