Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/v8.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #if V8_TARGET_ARCH_ARM |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/codegen.h" |
| 10 | #include "src/debug.h" |
| 11 | #include "src/deoptimizer.h" |
| 12 | #include "src/full-codegen.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 13 | #include "src/runtime/runtime.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | |
| 18 | |
| 19 | #define __ ACCESS_MASM(masm) |
| 20 | |
| 21 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 22 | void Builtins::Generate_Adaptor(MacroAssembler* masm, |
| 23 | CFunctionId id, |
| 24 | BuiltinExtraArguments extra_args) { |
| 25 | // ----------- S t a t e ------------- |
| 26 | // -- r0 : number of arguments excluding receiver |
| 27 | // -- r1 : called function (only guaranteed when |
| 28 | // extra_args requires it) |
| 29 | // -- cp : context |
| 30 | // -- sp[0] : last argument |
| 31 | // -- ... |
| 32 | // -- sp[4 * (argc - 1)] : first argument (argc == r0) |
| 33 | // -- sp[4 * argc] : receiver |
| 34 | // ----------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 35 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 36 | // Insert extra arguments. |
| 37 | int num_extra_args = 0; |
| 38 | if (extra_args == NEEDS_CALLED_FUNCTION) { |
| 39 | num_extra_args = 1; |
| 40 | __ push(r1); |
| 41 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 42 | DCHECK(extra_args == NO_EXTRA_ARGUMENTS); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 45 | // JumpToExternalReference expects r0 to contain the number of arguments |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 46 | // including the receiver and the extra arguments. |
| 47 | __ add(r0, r0, Operand(num_extra_args + 1)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 48 | __ JumpToExternalReference(ExternalReference(id, masm->isolate())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 52 | // Load the built-in InternalArray function from the current context. |
| 53 | static void GenerateLoadInternalArrayFunction(MacroAssembler* masm, |
| 54 | Register result) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 55 | // Load the native context. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 56 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 57 | __ ldr(result, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 59 | __ ldr(result, |
| 60 | FieldMemOperand(result, GlobalObject::kNativeContextOffset)); |
| 61 | // Load the InternalArray function from the native context. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 62 | __ ldr(result, |
| 63 | MemOperand(result, |
| 64 | Context::SlotOffset( |
| 65 | Context::INTERNAL_ARRAY_FUNCTION_INDEX))); |
| 66 | } |
| 67 | |
| 68 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 69 | // Load the built-in Array function from the current context. |
| 70 | static void GenerateLoadArrayFunction(MacroAssembler* masm, Register result) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | // Load the native context. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 72 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 73 | __ ldr(result, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 74 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 75 | __ ldr(result, |
| 76 | FieldMemOperand(result, GlobalObject::kNativeContextOffset)); |
| 77 | // Load the Array function from the native context. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 78 | __ ldr(result, |
| 79 | MemOperand(result, |
| 80 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 81 | } |
| 82 | |
| 83 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 84 | void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) { |
| 85 | // ----------- S t a t e ------------- |
| 86 | // -- r0 : number of arguments |
| 87 | // -- lr : return address |
| 88 | // -- sp[...]: constructor arguments |
| 89 | // ----------------------------------- |
| 90 | Label generic_array_code, one_or_more_arguments, two_or_more_arguments; |
| 91 | |
| 92 | // Get the InternalArray function. |
| 93 | GenerateLoadInternalArrayFunction(masm, r1); |
| 94 | |
| 95 | if (FLAG_debug_code) { |
| 96 | // Initial map for the builtin InternalArray functions should be maps. |
| 97 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 98 | __ SmiTst(r2); |
| 99 | __ Assert(ne, kUnexpectedInitialMapForInternalArrayFunction); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 100 | __ CompareObjectType(r2, r3, r4, MAP_TYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 101 | __ Assert(eq, kUnexpectedInitialMapForInternalArrayFunction); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | // Run the native code for the InternalArray function called as a normal |
| 105 | // function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 106 | // tail call a stub |
| 107 | InternalArrayConstructorStub stub(masm->isolate()); |
| 108 | __ TailCallStub(&stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
| 112 | void Builtins::Generate_ArrayCode(MacroAssembler* masm) { |
| 113 | // ----------- S t a t e ------------- |
| 114 | // -- r0 : number of arguments |
| 115 | // -- lr : return address |
| 116 | // -- sp[...]: constructor arguments |
| 117 | // ----------------------------------- |
| 118 | Label generic_array_code, one_or_more_arguments, two_or_more_arguments; |
| 119 | |
| 120 | // Get the Array function. |
| 121 | GenerateLoadArrayFunction(masm, r1); |
| 122 | |
| 123 | if (FLAG_debug_code) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 124 | // Initial map for the builtin Array functions should be maps. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 125 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 126 | __ SmiTst(r2); |
| 127 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 128 | __ CompareObjectType(r2, r3, r4, MAP_TYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 129 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Run the native code for the Array function called as a normal function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 133 | // tail call a stub |
| 134 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 135 | ArrayConstructorStub stub(masm->isolate()); |
| 136 | __ TailCallStub(&stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 140 | void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 141 | // ----------- S t a t e ------------- |
| 142 | // -- r0 : number of arguments |
| 143 | // -- r1 : constructor function |
| 144 | // -- lr : return address |
| 145 | // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) |
| 146 | // -- sp[argc * 4] : receiver |
| 147 | // ----------------------------------- |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 148 | Counters* counters = masm->isolate()->counters(); |
| 149 | __ IncrementCounter(counters->string_ctor_calls(), 1, r2, r3); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 150 | |
| 151 | Register function = r1; |
| 152 | if (FLAG_debug_code) { |
| 153 | __ LoadGlobalFunction(Context::STRING_FUNCTION_INDEX, r2); |
| 154 | __ cmp(function, Operand(r2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 155 | __ Assert(eq, kUnexpectedStringFunction); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | // Load the first arguments in r0 and get rid of the rest. |
| 159 | Label no_arguments; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 160 | __ cmp(r0, Operand::Zero()); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 161 | __ b(eq, &no_arguments); |
| 162 | // First args = sp[(argc - 1) * 4]. |
| 163 | __ sub(r0, r0, Operand(1)); |
| 164 | __ ldr(r0, MemOperand(sp, r0, LSL, kPointerSizeLog2, PreIndex)); |
| 165 | // sp now point to args[0], drop args[0] + receiver. |
| 166 | __ Drop(2); |
| 167 | |
| 168 | Register argument = r2; |
| 169 | Label not_cached, argument_is_string; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 170 | __ LookupNumberStringCache(r0, // Input. |
| 171 | argument, // Result. |
| 172 | r3, // Scratch. |
| 173 | r4, // Scratch. |
| 174 | r5, // Scratch. |
| 175 | ¬_cached); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 176 | __ IncrementCounter(counters->string_ctor_cached_number(), 1, r3, r4); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 177 | __ bind(&argument_is_string); |
| 178 | |
| 179 | // ----------- S t a t e ------------- |
| 180 | // -- r2 : argument converted to string |
| 181 | // -- r1 : constructor function |
| 182 | // -- lr : return address |
| 183 | // ----------------------------------- |
| 184 | |
| 185 | Label gc_required; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | __ Allocate(JSValue::kSize, |
| 187 | r0, // Result. |
| 188 | r3, // Scratch. |
| 189 | r4, // Scratch. |
| 190 | &gc_required, |
| 191 | TAG_OBJECT); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 192 | |
| 193 | // Initialising the String Object. |
| 194 | Register map = r3; |
| 195 | __ LoadGlobalFunctionInitialMap(function, map, r4); |
| 196 | if (FLAG_debug_code) { |
| 197 | __ ldrb(r4, FieldMemOperand(map, Map::kInstanceSizeOffset)); |
| 198 | __ cmp(r4, Operand(JSValue::kSize >> kPointerSizeLog2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 199 | __ Assert(eq, kUnexpectedStringWrapperInstanceSize); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 200 | __ ldrb(r4, FieldMemOperand(map, Map::kUnusedPropertyFieldsOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 201 | __ cmp(r4, Operand::Zero()); |
| 202 | __ Assert(eq, kUnexpectedUnusedPropertiesOfStringWrapper); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 203 | } |
| 204 | __ str(map, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 205 | |
| 206 | __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex); |
| 207 | __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 208 | __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 209 | |
| 210 | __ str(argument, FieldMemOperand(r0, JSValue::kValueOffset)); |
| 211 | |
| 212 | // Ensure the object is fully initialized. |
| 213 | STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize); |
| 214 | |
| 215 | __ Ret(); |
| 216 | |
| 217 | // The argument was not found in the number to string cache. Check |
| 218 | // if it's a string already before calling the conversion builtin. |
| 219 | Label convert_argument; |
| 220 | __ bind(¬_cached); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 221 | __ JumpIfSmi(r0, &convert_argument); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 222 | |
| 223 | // Is it a String? |
| 224 | __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 225 | __ ldrb(r3, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 226 | STATIC_ASSERT(kNotStringTag != 0); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 227 | __ tst(r3, Operand(kIsNotStringMask)); |
| 228 | __ b(ne, &convert_argument); |
| 229 | __ mov(argument, r0); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 230 | __ IncrementCounter(counters->string_ctor_conversions(), 1, r3, r4); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 231 | __ b(&argument_is_string); |
| 232 | |
| 233 | // Invoke the conversion builtin and put the result into r2. |
| 234 | __ bind(&convert_argument); |
| 235 | __ push(function); // Preserve the function. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 236 | __ IncrementCounter(counters->string_ctor_conversions(), 1, r3, r4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 237 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 239 | __ push(r0); |
| 240 | __ InvokeBuiltin(Builtins::TO_STRING, CALL_FUNCTION); |
| 241 | } |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 242 | __ pop(function); |
| 243 | __ mov(argument, r0); |
| 244 | __ b(&argument_is_string); |
| 245 | |
| 246 | // Load the empty string into r2, remove the receiver from the |
| 247 | // stack, and jump back to the case where the argument is a string. |
| 248 | __ bind(&no_arguments); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 249 | __ LoadRoot(argument, Heap::kempty_stringRootIndex); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 250 | __ Drop(1); |
| 251 | __ b(&argument_is_string); |
| 252 | |
| 253 | // At this point the argument is already a string. Call runtime to |
| 254 | // create a string wrapper. |
| 255 | __ bind(&gc_required); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 256 | __ IncrementCounter(counters->string_ctor_gc_required(), 1, r3, r4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 257 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 258 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 259 | __ push(argument); |
| 260 | __ CallRuntime(Runtime::kNewStringWrapper, 1); |
| 261 | } |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 262 | __ Ret(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 266 | static void CallRuntimePassFunction( |
| 267 | MacroAssembler* masm, Runtime::FunctionId function_id) { |
| 268 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
| 269 | // Push a copy of the function onto the stack. |
| 270 | __ push(r1); |
| 271 | // Push function as parameter to the runtime call. |
| 272 | __ Push(r1); |
| 273 | |
| 274 | __ CallRuntime(function_id, 1); |
| 275 | // Restore receiver. |
| 276 | __ pop(r1); |
| 277 | } |
| 278 | |
| 279 | |
| 280 | static void GenerateTailCallToSharedCode(MacroAssembler* masm) { |
| 281 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 282 | __ ldr(r2, FieldMemOperand(r2, SharedFunctionInfo::kCodeOffset)); |
| 283 | __ add(r2, r2, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 284 | __ Jump(r2); |
| 285 | } |
| 286 | |
| 287 | |
| 288 | static void GenerateTailCallToReturnedCode(MacroAssembler* masm) { |
| 289 | __ add(r0, r0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 290 | __ Jump(r0); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { |
| 295 | // Checking whether the queued function is ready for install is optional, |
| 296 | // since we come across interrupts and stack checks elsewhere. However, |
| 297 | // not checking may delay installing ready functions, and always checking |
| 298 | // would be quite expensive. A good compromise is to first check against |
| 299 | // stack limit as a cue for an interrupt signal. |
| 300 | Label ok; |
| 301 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 302 | __ cmp(sp, Operand(ip)); |
| 303 | __ b(hs, &ok); |
| 304 | |
| 305 | CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); |
| 306 | GenerateTailCallToReturnedCode(masm); |
| 307 | |
| 308 | __ bind(&ok); |
| 309 | GenerateTailCallToSharedCode(masm); |
| 310 | } |
| 311 | |
| 312 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 313 | static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 314 | bool is_api_function, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 315 | bool create_memento) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 316 | // ----------- S t a t e ------------- |
| 317 | // -- r0 : number of arguments |
| 318 | // -- r1 : constructor function |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 319 | // -- r2 : allocation site or undefined |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 320 | // -- lr : return address |
| 321 | // -- sp[...]: constructor arguments |
| 322 | // ----------------------------------- |
| 323 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 324 | // Should never create mementos for api functions. |
| 325 | DCHECK(!is_api_function || !create_memento); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 326 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 327 | Isolate* isolate = masm->isolate(); |
| 328 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 329 | // Enter a construct frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 330 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 331 | FrameAndConstantPoolScope scope(masm, StackFrame::CONSTRUCT); |
| 332 | |
| 333 | if (create_memento) { |
| 334 | __ AssertUndefinedOrAllocationSite(r2, r3); |
| 335 | __ push(r2); |
| 336 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 337 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 338 | // Preserve the two incoming parameters on the stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 339 | __ SmiTag(r0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 340 | __ push(r0); // Smi-tagged arguments count. |
| 341 | __ push(r1); // Constructor function. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 342 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 343 | // Try to allocate the object without transitioning into C code. If any of |
| 344 | // the preconditions is not met, the code bails out to the runtime call. |
| 345 | Label rt_call, allocated; |
| 346 | if (FLAG_inline_new) { |
| 347 | Label undo_allocation; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 348 | ExternalReference debug_step_in_fp = |
| 349 | ExternalReference::debug_step_in_fp_address(isolate); |
| 350 | __ mov(r2, Operand(debug_step_in_fp)); |
| 351 | __ ldr(r2, MemOperand(r2)); |
| 352 | __ tst(r2, r2); |
| 353 | __ b(ne, &rt_call); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 354 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 355 | // Load the initial map and verify that it is in fact a map. |
| 356 | // r1: constructor function |
| 357 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 358 | __ JumpIfSmi(r2, &rt_call); |
| 359 | __ CompareObjectType(r2, r3, r4, MAP_TYPE); |
| 360 | __ b(ne, &rt_call); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 361 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 362 | // Check that the constructor is not constructing a JSFunction (see |
| 363 | // comments in Runtime_NewObject in runtime.cc). In which case the |
| 364 | // initial map's instance type would be JS_FUNCTION_TYPE. |
| 365 | // r1: constructor function |
| 366 | // r2: initial map |
| 367 | __ CompareInstanceType(r2, r3, JS_FUNCTION_TYPE); |
| 368 | __ b(eq, &rt_call); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 370 | if (!is_api_function) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 371 | Label allocate; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 372 | MemOperand bit_field3 = FieldMemOperand(r2, Map::kBitField3Offset); |
| 373 | // Check if slack tracking is enabled. |
| 374 | __ ldr(r4, bit_field3); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 375 | __ DecodeField<Map::Counter>(r3, r4); |
| 376 | __ cmp(r3, Operand(Map::kSlackTrackingCounterEnd)); |
| 377 | __ b(lt, &allocate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 378 | // Decrease generous allocation count. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 379 | __ sub(r4, r4, Operand(1 << Map::Counter::kShift)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 380 | __ str(r4, bit_field3); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 381 | __ cmp(r3, Operand(Map::kSlackTrackingCounterEnd)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 382 | __ b(ne, &allocate); |
| 383 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 384 | __ push(r1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 385 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 386 | __ Push(r2, r1); // r1 = constructor |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 387 | __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); |
| 388 | |
| 389 | __ pop(r2); |
| 390 | __ pop(r1); |
| 391 | |
| 392 | __ bind(&allocate); |
| 393 | } |
| 394 | |
| 395 | // Now allocate the JSObject on the heap. |
| 396 | // r1: constructor function |
| 397 | // r2: initial map |
| 398 | __ ldrb(r3, FieldMemOperand(r2, Map::kInstanceSizeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 399 | if (create_memento) { |
| 400 | __ add(r3, r3, Operand(AllocationMemento::kSize / kPointerSize)); |
| 401 | } |
| 402 | |
| 403 | __ Allocate(r3, r4, r5, r6, &rt_call, SIZE_IN_WORDS); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 404 | |
| 405 | // Allocated the JSObject, now initialize the fields. Map is set to |
| 406 | // initial map and properties and elements are set to empty fixed array. |
| 407 | // r1: constructor function |
| 408 | // r2: initial map |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 409 | // r3: object size (not including memento if create_memento) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 410 | // r4: JSObject (not tagged) |
| 411 | __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex); |
| 412 | __ mov(r5, r4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 413 | DCHECK_EQ(0 * kPointerSize, JSObject::kMapOffset); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 414 | __ str(r2, MemOperand(r5, kPointerSize, PostIndex)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 415 | DCHECK_EQ(1 * kPointerSize, JSObject::kPropertiesOffset); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 416 | __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 417 | DCHECK_EQ(2 * kPointerSize, JSObject::kElementsOffset); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 418 | __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
| 419 | |
| 420 | // Fill all the in-object properties with the appropriate filler. |
| 421 | // r1: constructor function |
| 422 | // r2: initial map |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 423 | // r3: object size (in words, including memento if create_memento) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 424 | // r4: JSObject (not tagged) |
| 425 | // r5: First in-object property of JSObject (not tagged) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 426 | DCHECK_EQ(3 * kPointerSize, JSObject::kHeaderSize); |
| 427 | __ LoadRoot(r6, Heap::kUndefinedValueRootIndex); |
| 428 | |
| 429 | if (!is_api_function) { |
| 430 | Label no_inobject_slack_tracking; |
| 431 | |
| 432 | // Check if slack tracking is enabled. |
| 433 | __ ldr(ip, FieldMemOperand(r2, Map::kBitField3Offset)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 434 | __ DecodeField<Map::Counter>(ip); |
| 435 | __ cmp(ip, Operand(Map::kSlackTrackingCounterEnd)); |
| 436 | __ b(lt, &no_inobject_slack_tracking); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 437 | |
| 438 | // Allocate object with a slack. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 439 | __ ldr(r0, FieldMemOperand(r2, Map::kInstanceSizesOffset)); |
| 440 | __ Ubfx(r0, r0, Map::kPreAllocatedPropertyFieldsByte * kBitsPerByte, |
| 441 | kBitsPerByte); |
| 442 | __ add(r0, r5, Operand(r0, LSL, kPointerSizeLog2)); |
| 443 | // r0: offset of first field after pre-allocated fields |
| 444 | if (FLAG_debug_code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 445 | __ add(ip, r4, Operand(r3, LSL, kPointerSizeLog2)); // End of object. |
| 446 | __ cmp(r0, ip); |
| 447 | __ Assert(le, kUnexpectedNumberOfPreAllocatedPropertyFields); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 448 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 449 | __ InitializeFieldsWithFiller(r5, r0, r6); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 450 | // To allow for truncation. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 451 | __ LoadRoot(r6, Heap::kOnePointerFillerMapRootIndex); |
| 452 | // Fill the remaining fields with one pointer filler map. |
| 453 | |
| 454 | __ bind(&no_inobject_slack_tracking); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 455 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 456 | |
| 457 | if (create_memento) { |
| 458 | __ sub(ip, r3, Operand(AllocationMemento::kSize / kPointerSize)); |
| 459 | __ add(r0, r4, Operand(ip, LSL, kPointerSizeLog2)); // End of object. |
| 460 | __ InitializeFieldsWithFiller(r5, r0, r6); |
| 461 | |
| 462 | // Fill in memento fields. |
| 463 | // r5: points to the allocated but uninitialized memento. |
| 464 | __ LoadRoot(r6, Heap::kAllocationMementoMapRootIndex); |
| 465 | DCHECK_EQ(0 * kPointerSize, AllocationMemento::kMapOffset); |
| 466 | __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
| 467 | // Load the AllocationSite |
| 468 | __ ldr(r6, MemOperand(sp, 2 * kPointerSize)); |
| 469 | DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset); |
| 470 | __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
| 471 | } else { |
| 472 | __ add(r0, r4, Operand(r3, LSL, kPointerSizeLog2)); // End of object. |
| 473 | __ InitializeFieldsWithFiller(r5, r0, r6); |
| 474 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 475 | |
| 476 | // Add the object tag to make the JSObject real, so that we can continue |
| 477 | // and jump into the continuation code at any time from now on. Any |
| 478 | // failures need to undo the allocation, so that the heap is in a |
| 479 | // consistent state and verifiable. |
| 480 | __ add(r4, r4, Operand(kHeapObjectTag)); |
| 481 | |
| 482 | // Check if a non-empty properties array is needed. Continue with |
| 483 | // allocated object if not fall through to runtime call if it is. |
| 484 | // r1: constructor function |
| 485 | // r4: JSObject |
| 486 | // r5: start of next object (not tagged) |
| 487 | __ ldrb(r3, FieldMemOperand(r2, Map::kUnusedPropertyFieldsOffset)); |
| 488 | // The field instance sizes contains both pre-allocated property fields |
| 489 | // and in-object properties. |
| 490 | __ ldr(r0, FieldMemOperand(r2, Map::kInstanceSizesOffset)); |
| 491 | __ Ubfx(r6, r0, Map::kPreAllocatedPropertyFieldsByte * kBitsPerByte, |
| 492 | kBitsPerByte); |
| 493 | __ add(r3, r3, Operand(r6)); |
| 494 | __ Ubfx(r6, r0, Map::kInObjectPropertiesByte * kBitsPerByte, |
| 495 | kBitsPerByte); |
| 496 | __ sub(r3, r3, Operand(r6), SetCC); |
| 497 | |
| 498 | // Done if no extra properties are to be allocated. |
| 499 | __ b(eq, &allocated); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 500 | __ Assert(pl, kPropertyAllocationCountFailed); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 501 | |
| 502 | // Scale the number of elements by pointer size and add the header for |
| 503 | // FixedArrays to the start of the next object calculation from above. |
| 504 | // r1: constructor |
| 505 | // r3: number of elements in properties array |
| 506 | // r4: JSObject |
| 507 | // r5: start of next object |
| 508 | __ add(r0, r3, Operand(FixedArray::kHeaderSize / kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 509 | __ Allocate( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 510 | r0, |
| 511 | r5, |
| 512 | r6, |
| 513 | r2, |
| 514 | &undo_allocation, |
| 515 | static_cast<AllocationFlags>(RESULT_CONTAINS_TOP | SIZE_IN_WORDS)); |
| 516 | |
| 517 | // Initialize the FixedArray. |
| 518 | // r1: constructor |
| 519 | // r3: number of elements in properties array |
| 520 | // r4: JSObject |
| 521 | // r5: FixedArray (not tagged) |
| 522 | __ LoadRoot(r6, Heap::kFixedArrayMapRootIndex); |
| 523 | __ mov(r2, r5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 524 | DCHECK_EQ(0 * kPointerSize, JSObject::kMapOffset); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 525 | __ str(r6, MemOperand(r2, kPointerSize, PostIndex)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 526 | DCHECK_EQ(1 * kPointerSize, FixedArray::kLengthOffset); |
| 527 | __ SmiTag(r0, r3); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 528 | __ str(r0, MemOperand(r2, kPointerSize, PostIndex)); |
| 529 | |
| 530 | // Initialize the fields to undefined. |
| 531 | // r1: constructor function |
| 532 | // r2: First element of FixedArray (not tagged) |
| 533 | // r3: number of elements in properties array |
| 534 | // r4: JSObject |
| 535 | // r5: FixedArray (not tagged) |
| 536 | __ add(r6, r2, Operand(r3, LSL, kPointerSizeLog2)); // End of object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 537 | DCHECK_EQ(2 * kPointerSize, FixedArray::kHeaderSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 538 | { Label loop, entry; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 539 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 540 | __ b(&entry); |
| 541 | __ bind(&loop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 542 | __ str(r0, MemOperand(r2, kPointerSize, PostIndex)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 543 | __ bind(&entry); |
| 544 | __ cmp(r2, r6); |
| 545 | __ b(lt, &loop); |
| 546 | } |
| 547 | |
| 548 | // Store the initialized FixedArray into the properties field of |
| 549 | // the JSObject |
| 550 | // r1: constructor function |
| 551 | // r4: JSObject |
| 552 | // r5: FixedArray (not tagged) |
| 553 | __ add(r5, r5, Operand(kHeapObjectTag)); // Add the heap tag. |
| 554 | __ str(r5, FieldMemOperand(r4, JSObject::kPropertiesOffset)); |
| 555 | |
| 556 | // Continue with JSObject being successfully allocated |
| 557 | // r1: constructor function |
| 558 | // r4: JSObject |
| 559 | __ jmp(&allocated); |
| 560 | |
| 561 | // Undo the setting of the new top so that the heap is verifiable. For |
| 562 | // example, the map's unused properties potentially do not match the |
| 563 | // allocated objects unused properties. |
| 564 | // r4: JSObject (previous new top) |
| 565 | __ bind(&undo_allocation); |
| 566 | __ UndoAllocationInNewSpace(r4, r5); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 569 | // Allocate the new receiver object using the runtime call. |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 570 | // r1: constructor function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 571 | __ bind(&rt_call); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 572 | if (create_memento) { |
| 573 | // Get the cell or allocation site. |
| 574 | __ ldr(r2, MemOperand(sp, 2 * kPointerSize)); |
| 575 | __ push(r2); |
| 576 | } |
| 577 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 578 | __ push(r1); // argument for Runtime_NewObject |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 579 | if (create_memento) { |
| 580 | __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 2); |
| 581 | } else { |
| 582 | __ CallRuntime(Runtime::kNewObject, 1); |
| 583 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 584 | __ mov(r4, r0); |
| 585 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 586 | // If we ended up using the runtime, and we want a memento, then the |
| 587 | // runtime call made it for us, and we shouldn't do create count |
| 588 | // increment. |
| 589 | Label count_incremented; |
| 590 | if (create_memento) { |
| 591 | __ jmp(&count_incremented); |
| 592 | } |
| 593 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 594 | // Receiver for constructor call allocated. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 595 | // r4: JSObject |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 596 | __ bind(&allocated); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 597 | |
| 598 | if (create_memento) { |
| 599 | __ ldr(r2, MemOperand(sp, kPointerSize * 2)); |
| 600 | __ LoadRoot(r5, Heap::kUndefinedValueRootIndex); |
| 601 | __ cmp(r2, r5); |
| 602 | __ b(eq, &count_incremented); |
| 603 | // r2 is an AllocationSite. We are creating a memento from it, so we |
| 604 | // need to increment the memento create count. |
| 605 | __ ldr(r3, FieldMemOperand(r2, |
| 606 | AllocationSite::kPretenureCreateCountOffset)); |
| 607 | __ add(r3, r3, Operand(Smi::FromInt(1))); |
| 608 | __ str(r3, FieldMemOperand(r2, |
| 609 | AllocationSite::kPretenureCreateCountOffset)); |
| 610 | __ bind(&count_incremented); |
| 611 | } |
| 612 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 613 | __ push(r4); |
| 614 | __ push(r4); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 615 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 616 | // Reload the number of arguments and the constructor from the stack. |
| 617 | // sp[0]: receiver |
| 618 | // sp[1]: receiver |
| 619 | // sp[2]: constructor function |
| 620 | // sp[3]: number of arguments (smi-tagged) |
| 621 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
| 622 | __ ldr(r3, MemOperand(sp, 3 * kPointerSize)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 623 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 624 | // Set up pointer to last argument. |
| 625 | __ add(r2, fp, Operand(StandardFrameConstants::kCallerSPOffset)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 626 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 627 | // Set up number of arguments for function call below |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 628 | __ SmiUntag(r0, r3); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 629 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 630 | // Copy arguments and receiver to the expression stack. |
| 631 | // r0: number of arguments |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 632 | // r1: constructor function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 633 | // r2: address of last argument (caller sp) |
| 634 | // r3: number of arguments (smi-tagged) |
| 635 | // sp[0]: receiver |
| 636 | // sp[1]: receiver |
| 637 | // sp[2]: constructor function |
| 638 | // sp[3]: number of arguments (smi-tagged) |
| 639 | Label loop, entry; |
| 640 | __ b(&entry); |
| 641 | __ bind(&loop); |
| 642 | __ ldr(ip, MemOperand(r2, r3, LSL, kPointerSizeLog2 - 1)); |
| 643 | __ push(ip); |
| 644 | __ bind(&entry); |
| 645 | __ sub(r3, r3, Operand(2), SetCC); |
| 646 | __ b(ge, &loop); |
| 647 | |
| 648 | // Call the function. |
| 649 | // r0: number of arguments |
| 650 | // r1: constructor function |
| 651 | if (is_api_function) { |
| 652 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 653 | Handle<Code> code = |
| 654 | masm->isolate()->builtins()->HandleApiCallConstruct(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 655 | __ Call(code, RelocInfo::CODE_TARGET); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 656 | } else { |
| 657 | ParameterCount actual(r0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 658 | __ InvokeFunction(r1, actual, CALL_FUNCTION, NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 661 | // Store offset of return address for deoptimizer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 662 | if (!is_api_function) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 663 | masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); |
| 664 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 665 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 666 | // Restore context from the frame. |
| 667 | // r0: result |
| 668 | // sp[0]: receiver |
| 669 | // sp[1]: constructor function |
| 670 | // sp[2]: number of arguments (smi-tagged) |
| 671 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 672 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 673 | // If the result is an object (in the ECMA sense), we should get rid |
| 674 | // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
| 675 | // on page 74. |
| 676 | Label use_receiver, exit; |
| 677 | |
| 678 | // If the result is a smi, it is *not* an object in the ECMA sense. |
| 679 | // r0: result |
| 680 | // sp[0]: receiver (newly allocated object) |
| 681 | // sp[1]: constructor function |
| 682 | // sp[2]: number of arguments (smi-tagged) |
| 683 | __ JumpIfSmi(r0, &use_receiver); |
| 684 | |
| 685 | // If the type of the result (stored in its map) is less than |
| 686 | // FIRST_SPEC_OBJECT_TYPE, it is not an object in the ECMA sense. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 687 | __ CompareObjectType(r0, r1, r3, FIRST_SPEC_OBJECT_TYPE); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 688 | __ b(ge, &exit); |
| 689 | |
| 690 | // Throw away the result of the constructor invocation and use the |
| 691 | // on-stack receiver as the result. |
| 692 | __ bind(&use_receiver); |
| 693 | __ ldr(r0, MemOperand(sp)); |
| 694 | |
| 695 | // Remove receiver from the stack, remove caller arguments, and |
| 696 | // return. |
| 697 | __ bind(&exit); |
| 698 | // r0: result |
| 699 | // sp[0]: receiver (newly allocated object) |
| 700 | // sp[1]: constructor function |
| 701 | // sp[2]: number of arguments (smi-tagged) |
| 702 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
| 703 | |
| 704 | // Leave construct frame. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 707 | __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - 1)); |
| 708 | __ add(sp, sp, Operand(kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 709 | __ IncrementCounter(isolate->counters()->constructed_objects(), 1, r1, r2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 710 | __ Jump(lr); |
| 711 | } |
| 712 | |
| 713 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 714 | void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 715 | Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | |
| 719 | void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 720 | Generate_JSConstructStubHelper(masm, true, false); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 724 | static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
| 725 | bool is_construct) { |
| 726 | // Called from Generate_JS_Entry |
| 727 | // r0: code entry |
| 728 | // r1: function |
| 729 | // r2: receiver |
| 730 | // r3: argc |
| 731 | // r4: argv |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 732 | // r5-r6, r8 (if not FLAG_enable_ool_constant_pool) and cp may be clobbered |
| 733 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 734 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 735 | // Clear the context before we push it when entering the internal frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 736 | __ mov(cp, Operand::Zero()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 737 | |
| 738 | // Enter an internal frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 739 | { |
| 740 | FrameScope scope(masm, StackFrame::INTERNAL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 741 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 742 | // Set up the context from the function argument. |
| 743 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 744 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 745 | __ InitializeRootRegister(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 746 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 747 | // Push the function and the receiver onto the stack. |
| 748 | __ push(r1); |
| 749 | __ push(r2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 750 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 751 | // Copy arguments to the stack in a loop. |
| 752 | // r1: function |
| 753 | // r3: argc |
| 754 | // r4: argv, i.e. points to first arg |
| 755 | Label loop, entry; |
| 756 | __ add(r2, r4, Operand(r3, LSL, kPointerSizeLog2)); |
| 757 | // r2 points past last arg. |
| 758 | __ b(&entry); |
| 759 | __ bind(&loop); |
| 760 | __ ldr(r0, MemOperand(r4, kPointerSize, PostIndex)); // read next parameter |
| 761 | __ ldr(r0, MemOperand(r0)); // dereference handle |
| 762 | __ push(r0); // push parameter |
| 763 | __ bind(&entry); |
| 764 | __ cmp(r4, r2); |
| 765 | __ b(ne, &loop); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 766 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 767 | // Initialize all JavaScript callee-saved registers, since they will be seen |
| 768 | // by the garbage collector as part of handlers. |
| 769 | __ LoadRoot(r4, Heap::kUndefinedValueRootIndex); |
| 770 | __ mov(r5, Operand(r4)); |
| 771 | __ mov(r6, Operand(r4)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 772 | if (!FLAG_enable_ool_constant_pool) { |
| 773 | __ mov(r8, Operand(r4)); |
| 774 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 775 | if (kR9Available == 1) { |
| 776 | __ mov(r9, Operand(r4)); |
| 777 | } |
| 778 | |
| 779 | // Invoke the code and pass argc as r0. |
| 780 | __ mov(r0, Operand(r3)); |
| 781 | if (is_construct) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 782 | // No type feedback cell is available |
| 783 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 784 | CallConstructStub stub(masm->isolate(), NO_CALL_CONSTRUCTOR_FLAGS); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 785 | __ CallStub(&stub); |
| 786 | } else { |
| 787 | ParameterCount actual(r0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 788 | __ InvokeFunction(r1, actual, CALL_FUNCTION, NullCallWrapper()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 789 | } |
| 790 | // Exit the JS frame and remove the parameters (except function), and |
| 791 | // return. |
| 792 | // Respect ABI stack constraint. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 793 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 794 | __ Jump(lr); |
| 795 | |
| 796 | // r0: result |
| 797 | } |
| 798 | |
| 799 | |
| 800 | void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { |
| 801 | Generate_JSEntryTrampolineHelper(masm, false); |
| 802 | } |
| 803 | |
| 804 | |
| 805 | void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { |
| 806 | Generate_JSEntryTrampolineHelper(masm, true); |
| 807 | } |
| 808 | |
| 809 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 810 | void Builtins::Generate_CompileLazy(MacroAssembler* masm) { |
| 811 | CallRuntimePassFunction(masm, Runtime::kCompileLazy); |
| 812 | GenerateTailCallToReturnedCode(masm); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 816 | static void CallCompileOptimized(MacroAssembler* masm, bool concurrent) { |
| 817 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
| 818 | // Push a copy of the function onto the stack. |
| 819 | __ push(r1); |
| 820 | // Push function as parameter to the runtime call. |
| 821 | __ Push(r1); |
| 822 | // Whether to compile in a background thread. |
| 823 | __ Push(masm->isolate()->factory()->ToBoolean(concurrent)); |
| 824 | |
| 825 | __ CallRuntime(Runtime::kCompileOptimized, 2); |
| 826 | // Restore receiver. |
| 827 | __ pop(r1); |
| 828 | } |
| 829 | |
| 830 | |
| 831 | void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { |
| 832 | CallCompileOptimized(masm, false); |
| 833 | GenerateTailCallToReturnedCode(masm); |
| 834 | } |
| 835 | |
| 836 | |
| 837 | void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { |
| 838 | CallCompileOptimized(masm, true); |
| 839 | GenerateTailCallToReturnedCode(masm); |
| 840 | } |
| 841 | |
| 842 | |
| 843 | static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) { |
| 844 | // For now, we are relying on the fact that make_code_young doesn't do any |
| 845 | // garbage collection which allows us to save/restore the registers without |
| 846 | // worrying about which of them contain pointers. We also don't build an |
| 847 | // internal frame to make the code faster, since we shouldn't have to do stack |
| 848 | // crawls in MakeCodeYoung. This seems a bit fragile. |
| 849 | |
| 850 | // The following registers must be saved and restored when calling through to |
| 851 | // the runtime: |
| 852 | // r0 - contains return address (beginning of patch sequence) |
| 853 | // r1 - isolate |
| 854 | FrameScope scope(masm, StackFrame::MANUAL); |
| 855 | __ stm(db_w, sp, r0.bit() | r1.bit() | fp.bit() | lr.bit()); |
| 856 | __ PrepareCallCFunction(2, 0, r2); |
| 857 | __ mov(r1, Operand(ExternalReference::isolate_address(masm->isolate()))); |
| 858 | __ CallCFunction( |
| 859 | ExternalReference::get_make_code_young_function(masm->isolate()), 2); |
| 860 | __ ldm(ia_w, sp, r0.bit() | r1.bit() | fp.bit() | lr.bit()); |
| 861 | __ mov(pc, r0); |
| 862 | } |
| 863 | |
| 864 | #define DEFINE_CODE_AGE_BUILTIN_GENERATOR(C) \ |
| 865 | void Builtins::Generate_Make##C##CodeYoungAgainEvenMarking( \ |
| 866 | MacroAssembler* masm) { \ |
| 867 | GenerateMakeCodeYoungAgainCommon(masm); \ |
| 868 | } \ |
| 869 | void Builtins::Generate_Make##C##CodeYoungAgainOddMarking( \ |
| 870 | MacroAssembler* masm) { \ |
| 871 | GenerateMakeCodeYoungAgainCommon(masm); \ |
| 872 | } |
| 873 | CODE_AGE_LIST(DEFINE_CODE_AGE_BUILTIN_GENERATOR) |
| 874 | #undef DEFINE_CODE_AGE_BUILTIN_GENERATOR |
| 875 | |
| 876 | |
| 877 | void Builtins::Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm) { |
| 878 | // For now, as in GenerateMakeCodeYoungAgainCommon, we are relying on the fact |
| 879 | // that make_code_young doesn't do any garbage collection which allows us to |
| 880 | // save/restore the registers without worrying about which of them contain |
| 881 | // pointers. |
| 882 | |
| 883 | // The following registers must be saved and restored when calling through to |
| 884 | // the runtime: |
| 885 | // r0 - contains return address (beginning of patch sequence) |
| 886 | // r1 - isolate |
| 887 | FrameScope scope(masm, StackFrame::MANUAL); |
| 888 | __ stm(db_w, sp, r0.bit() | r1.bit() | fp.bit() | lr.bit()); |
| 889 | __ PrepareCallCFunction(2, 0, r2); |
| 890 | __ mov(r1, Operand(ExternalReference::isolate_address(masm->isolate()))); |
| 891 | __ CallCFunction(ExternalReference::get_mark_code_as_executed_function( |
| 892 | masm->isolate()), 2); |
| 893 | __ ldm(ia_w, sp, r0.bit() | r1.bit() | fp.bit() | lr.bit()); |
| 894 | |
| 895 | // Perform prologue operations usually performed by the young code stub. |
| 896 | __ PushFixedFrame(r1); |
| 897 | __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 898 | |
| 899 | // Jump to point after the code-age stub. |
| 900 | __ add(r0, r0, Operand(kNoCodeAgeSequenceLength)); |
| 901 | __ mov(pc, r0); |
| 902 | } |
| 903 | |
| 904 | |
| 905 | void Builtins::Generate_MarkCodeAsExecutedTwice(MacroAssembler* masm) { |
| 906 | GenerateMakeCodeYoungAgainCommon(masm); |
| 907 | } |
| 908 | |
| 909 | |
| 910 | static void Generate_NotifyStubFailureHelper(MacroAssembler* masm, |
| 911 | SaveFPRegsMode save_doubles) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 912 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 913 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 914 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 915 | // Preserve registers across notification, this is important for compiled |
| 916 | // stubs that tail call the runtime on deopts passing their parameters in |
| 917 | // registers. |
| 918 | __ stm(db_w, sp, kJSCallerSaved | kCalleeSaved); |
| 919 | // Pass the function and deoptimization type to the runtime system. |
| 920 | __ CallRuntime(Runtime::kNotifyStubFailure, 0, save_doubles); |
| 921 | __ ldm(ia_w, sp, kJSCallerSaved | kCalleeSaved); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 922 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 923 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 924 | __ add(sp, sp, Operand(kPointerSize)); // Ignore state |
| 925 | __ mov(pc, lr); // Jump to miss handler |
| 926 | } |
| 927 | |
| 928 | |
| 929 | void Builtins::Generate_NotifyStubFailure(MacroAssembler* masm) { |
| 930 | Generate_NotifyStubFailureHelper(masm, kDontSaveFPRegs); |
| 931 | } |
| 932 | |
| 933 | |
| 934 | void Builtins::Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm) { |
| 935 | Generate_NotifyStubFailureHelper(masm, kSaveFPRegs); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | |
| 939 | static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm, |
| 940 | Deoptimizer::BailoutType type) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 941 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 942 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 943 | // Pass the function and deoptimization type to the runtime system. |
| 944 | __ mov(r0, Operand(Smi::FromInt(static_cast<int>(type)))); |
| 945 | __ push(r0); |
| 946 | __ CallRuntime(Runtime::kNotifyDeoptimized, 1); |
| 947 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 948 | |
| 949 | // Get the full codegen state from the stack and untag it -> r6. |
| 950 | __ ldr(r6, MemOperand(sp, 0 * kPointerSize)); |
| 951 | __ SmiUntag(r6); |
| 952 | // Switch on the state. |
| 953 | Label with_tos_register, unknown_state; |
| 954 | __ cmp(r6, Operand(FullCodeGenerator::NO_REGISTERS)); |
| 955 | __ b(ne, &with_tos_register); |
| 956 | __ add(sp, sp, Operand(1 * kPointerSize)); // Remove state. |
| 957 | __ Ret(); |
| 958 | |
| 959 | __ bind(&with_tos_register); |
| 960 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); |
| 961 | __ cmp(r6, Operand(FullCodeGenerator::TOS_REG)); |
| 962 | __ b(ne, &unknown_state); |
| 963 | __ add(sp, sp, Operand(2 * kPointerSize)); // Remove state. |
| 964 | __ Ret(); |
| 965 | |
| 966 | __ bind(&unknown_state); |
| 967 | __ stop("no cases left"); |
| 968 | } |
| 969 | |
| 970 | |
| 971 | void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { |
| 972 | Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER); |
| 973 | } |
| 974 | |
| 975 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 976 | void Builtins::Generate_NotifySoftDeoptimized(MacroAssembler* masm) { |
| 977 | Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::SOFT); |
| 978 | } |
| 979 | |
| 980 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 981 | void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) { |
| 982 | Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY); |
| 983 | } |
| 984 | |
| 985 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 986 | void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 987 | // Lookup the function in the JavaScript frame. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 988 | __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 989 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 990 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
| 991 | // Pass function as argument. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 992 | __ push(r0); |
| 993 | __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); |
| 994 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 995 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 996 | // If the code object is null, just return to the unoptimized code. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 997 | Label skip; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 998 | __ cmp(r0, Operand(Smi::FromInt(0))); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 999 | __ b(ne, &skip); |
| 1000 | __ Ret(); |
| 1001 | |
| 1002 | __ bind(&skip); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1003 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1004 | // Load deoptimization data from the code object. |
| 1005 | // <deopt_data> = <code>[#deoptimization_data_offset] |
| 1006 | __ ldr(r1, FieldMemOperand(r0, Code::kDeoptimizationDataOffset)); |
| 1007 | |
| 1008 | { ConstantPoolUnavailableScope constant_pool_unavailable(masm); |
| 1009 | if (FLAG_enable_ool_constant_pool) { |
| 1010 | __ ldr(pp, FieldMemOperand(r0, Code::kConstantPoolOffset)); |
| 1011 | } |
| 1012 | |
| 1013 | // Load the OSR entrypoint offset from the deoptimization data. |
| 1014 | // <osr_offset> = <deopt_data>[#header_size + #osr_pc_offset] |
| 1015 | __ ldr(r1, FieldMemOperand(r1, FixedArray::OffsetOfElementAt( |
| 1016 | DeoptimizationInputData::kOsrPcOffsetIndex))); |
| 1017 | |
| 1018 | // Compute the target address = code_obj + header_size + osr_offset |
| 1019 | // <entry_addr> = <code_obj> + #header_size + <osr_offset> |
| 1020 | __ add(r0, r0, Operand::SmiUntag(r1)); |
| 1021 | __ add(lr, r0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1022 | |
| 1023 | // And "return" to the OSR entry point of the function. |
| 1024 | __ Ret(); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | void Builtins::Generate_OsrAfterStackCheck(MacroAssembler* masm) { |
| 1030 | // We check the stack limit as indicator that recompilation might be done. |
| 1031 | Label ok; |
| 1032 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 1033 | __ cmp(sp, Operand(ip)); |
| 1034 | __ b(hs, &ok); |
| 1035 | { |
| 1036 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
| 1037 | __ CallRuntime(Runtime::kStackGuard, 0); |
| 1038 | } |
| 1039 | __ Jump(masm->isolate()->builtins()->OnStackReplacement(), |
| 1040 | RelocInfo::CODE_TARGET); |
| 1041 | |
| 1042 | __ bind(&ok); |
| 1043 | __ Ret(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1047 | void Builtins::Generate_FunctionCall(MacroAssembler* masm) { |
| 1048 | // 1. Make sure we have at least one argument. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1049 | // r0: actual number of arguments |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1050 | { Label done; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1051 | __ cmp(r0, Operand::Zero()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1052 | __ b(ne, &done); |
| 1053 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 1054 | __ push(r2); |
| 1055 | __ add(r0, r0, Operand(1)); |
| 1056 | __ bind(&done); |
| 1057 | } |
| 1058 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1059 | // 2. Get the function to call (passed as receiver) from the stack, check |
| 1060 | // if it is a function. |
| 1061 | // r0: actual number of arguments |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1062 | Label slow, non_function; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1063 | __ ldr(r1, MemOperand(sp, r0, LSL, kPointerSizeLog2)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1064 | __ JumpIfSmi(r1, &non_function); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1065 | __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1066 | __ b(ne, &slow); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1067 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1068 | // 3a. Patch the first argument if necessary when calling a function. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1069 | // r0: actual number of arguments |
| 1070 | // r1: function |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1071 | Label shift_arguments; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1072 | __ mov(r4, Operand::Zero()); // indicate regular JS_FUNCTION |
| 1073 | { Label convert_to_object, use_global_proxy, patch_receiver; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1074 | // Change context eagerly in case we need the global receiver. |
| 1075 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 1076 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1077 | // Do not transform the receiver for strict mode functions. |
| 1078 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1079 | __ ldr(r3, FieldMemOperand(r2, SharedFunctionInfo::kCompilerHintsOffset)); |
| 1080 | __ tst(r3, Operand(1 << (SharedFunctionInfo::kStrictModeFunction + |
| 1081 | kSmiTagSize))); |
| 1082 | __ b(ne, &shift_arguments); |
| 1083 | |
| 1084 | // Do not transform the receiver for native (Compilerhints already in r3). |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1085 | __ tst(r3, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1086 | __ b(ne, &shift_arguments); |
| 1087 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1088 | // Compute the receiver in sloppy mode. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1089 | __ add(r2, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 1090 | __ ldr(r2, MemOperand(r2, -kPointerSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1091 | // r0: actual number of arguments |
| 1092 | // r1: function |
| 1093 | // r2: first argument |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1094 | __ JumpIfSmi(r2, &convert_to_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1095 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1096 | __ LoadRoot(r3, Heap::kUndefinedValueRootIndex); |
| 1097 | __ cmp(r2, r3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1098 | __ b(eq, &use_global_proxy); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1099 | __ LoadRoot(r3, Heap::kNullValueRootIndex); |
| 1100 | __ cmp(r2, r3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1101 | __ b(eq, &use_global_proxy); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1102 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1103 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 1104 | __ CompareObjectType(r2, r3, r3, FIRST_SPEC_OBJECT_TYPE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1105 | __ b(ge, &shift_arguments); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1106 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1107 | __ bind(&convert_to_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1108 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1109 | { |
| 1110 | // Enter an internal frame in order to preserve argument count. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1111 | FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
| 1112 | __ SmiTag(r0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1113 | __ push(r0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1114 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1115 | __ push(r2); |
| 1116 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1117 | __ mov(r2, r0); |
| 1118 | |
| 1119 | __ pop(r0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1120 | __ SmiUntag(r0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1121 | |
| 1122 | // Exit the internal frame. |
| 1123 | } |
| 1124 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1125 | // Restore the function to r1, and the flag to r4. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1126 | __ ldr(r1, MemOperand(sp, r0, LSL, kPointerSizeLog2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1127 | __ mov(r4, Operand::Zero()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1128 | __ jmp(&patch_receiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1129 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1130 | __ bind(&use_global_proxy); |
| 1131 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX)); |
| 1132 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalProxyOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1133 | |
| 1134 | __ bind(&patch_receiver); |
| 1135 | __ add(r3, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 1136 | __ str(r2, MemOperand(r3, -kPointerSize)); |
| 1137 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1138 | __ jmp(&shift_arguments); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1141 | // 3b. Check for function proxy. |
| 1142 | __ bind(&slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1143 | __ mov(r4, Operand(1, RelocInfo::NONE32)); // indicate function proxy |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1144 | __ cmp(r2, Operand(JS_FUNCTION_PROXY_TYPE)); |
| 1145 | __ b(eq, &shift_arguments); |
| 1146 | __ bind(&non_function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1147 | __ mov(r4, Operand(2, RelocInfo::NONE32)); // indicate non-function |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1148 | |
| 1149 | // 3c. Patch the first argument when calling a non-function. The |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1150 | // CALL_NON_FUNCTION builtin expects the non-function callee as |
| 1151 | // receiver, so overwrite the first argument which will ultimately |
| 1152 | // become the receiver. |
| 1153 | // r0: actual number of arguments |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1154 | // r1: function |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1155 | // r4: call type (0: JS function, 1: function proxy, 2: non-function) |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1156 | __ add(r2, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 1157 | __ str(r1, MemOperand(r2, -kPointerSize)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1158 | |
| 1159 | // 4. Shift arguments and return address one slot down on the stack |
| 1160 | // (overwriting the original receiver). Adjust argument count to make |
| 1161 | // the original first argument the new receiver. |
| 1162 | // r0: actual number of arguments |
| 1163 | // r1: function |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1164 | // r4: call type (0: JS function, 1: function proxy, 2: non-function) |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1165 | __ bind(&shift_arguments); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1166 | { Label loop; |
| 1167 | // Calculate the copy start address (destination). Copy end address is sp. |
| 1168 | __ add(r2, sp, Operand(r0, LSL, kPointerSizeLog2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1169 | |
| 1170 | __ bind(&loop); |
| 1171 | __ ldr(ip, MemOperand(r2, -kPointerSize)); |
| 1172 | __ str(ip, MemOperand(r2)); |
| 1173 | __ sub(r2, r2, Operand(kPointerSize)); |
| 1174 | __ cmp(r2, sp); |
| 1175 | __ b(ne, &loop); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1176 | // Adjust the actual number of arguments and remove the top element |
| 1177 | // (which is a copy of the last argument). |
| 1178 | __ sub(r0, r0, Operand(1)); |
| 1179 | __ pop(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1182 | // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin, |
| 1183 | // or a function proxy via CALL_FUNCTION_PROXY. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1184 | // r0: actual number of arguments |
| 1185 | // r1: function |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1186 | // r4: call type (0: JS function, 1: function proxy, 2: non-function) |
| 1187 | { Label function, non_proxy; |
| 1188 | __ tst(r4, r4); |
| 1189 | __ b(eq, &function); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1190 | // Expected number of arguments is 0 for CALL_NON_FUNCTION. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1191 | __ mov(r2, Operand::Zero()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1192 | __ cmp(r4, Operand(1)); |
| 1193 | __ b(ne, &non_proxy); |
| 1194 | |
| 1195 | __ push(r1); // re-add proxy object as additional argument |
| 1196 | __ add(r0, r0, Operand(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1197 | __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1198 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 1199 | RelocInfo::CODE_TARGET); |
| 1200 | |
| 1201 | __ bind(&non_proxy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1202 | __ GetBuiltinFunction(r1, Builtins::CALL_NON_FUNCTION); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1203 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 1204 | RelocInfo::CODE_TARGET); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1205 | __ bind(&function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1206 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1207 | |
| 1208 | // 5b. Get the code to call from the function and check that the number of |
| 1209 | // expected arguments matches what we're providing. If so, jump |
| 1210 | // (tail-call) to the code in register edx without checking arguments. |
| 1211 | // r0: actual number of arguments |
| 1212 | // r1: function |
| 1213 | __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 1214 | __ ldr(r2, |
| 1215 | FieldMemOperand(r3, SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1216 | __ SmiUntag(r2); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1217 | __ cmp(r2, r0); // Check formal and actual parameter counts. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1218 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 1219 | RelocInfo::CODE_TARGET, |
| 1220 | ne); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1221 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1222 | __ ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1223 | ParameterCount expected(0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1224 | __ InvokeCode(r3, expected, expected, JUMP_FUNCTION, NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | void Builtins::Generate_FunctionApply(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1229 | const int kIndexOffset = |
| 1230 | StandardFrameConstants::kExpressionsOffset - (2 * kPointerSize); |
| 1231 | const int kLimitOffset = |
| 1232 | StandardFrameConstants::kExpressionsOffset - (1 * kPointerSize); |
| 1233 | const int kArgsOffset = 2 * kPointerSize; |
| 1234 | const int kRecvOffset = 3 * kPointerSize; |
| 1235 | const int kFunctionOffset = 4 * kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1236 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1237 | { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1238 | FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1239 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1240 | __ ldr(r0, MemOperand(fp, kFunctionOffset)); // get the function |
| 1241 | __ push(r0); |
| 1242 | __ ldr(r0, MemOperand(fp, kArgsOffset)); // get the args array |
| 1243 | __ push(r0); |
| 1244 | __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1245 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1246 | // Check the stack for overflow. We are not trying to catch |
| 1247 | // interruptions (e.g. debug break and preemption) here, so the "real stack |
| 1248 | // limit" is checked. |
| 1249 | Label okay; |
| 1250 | __ LoadRoot(r2, Heap::kRealStackLimitRootIndex); |
| 1251 | // Make r2 the space we have left. The stack might already be overflowed |
| 1252 | // here which will cause r2 to become negative. |
| 1253 | __ sub(r2, sp, r2); |
| 1254 | // Check if the arguments will overflow the stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1255 | __ cmp(r2, Operand::PointerOffsetFromSmiKey(r0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1256 | __ b(gt, &okay); // Signed comparison. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1257 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1258 | // Out of stack space. |
| 1259 | __ ldr(r1, MemOperand(fp, kFunctionOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1260 | __ Push(r1, r0); |
| 1261 | __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1262 | // End of stack check. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1263 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1264 | // Push current limit and index. |
| 1265 | __ bind(&okay); |
| 1266 | __ push(r0); // limit |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1267 | __ mov(r1, Operand::Zero()); // initial index |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1268 | __ push(r1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1269 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1270 | // Get the receiver. |
| 1271 | __ ldr(r0, MemOperand(fp, kRecvOffset)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1272 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1273 | // Check that the function is a JS function (otherwise it must be a proxy). |
| 1274 | Label push_receiver; |
| 1275 | __ ldr(r1, MemOperand(fp, kFunctionOffset)); |
| 1276 | __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE); |
| 1277 | __ b(ne, &push_receiver); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1278 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1279 | // Change context eagerly to get the right global object if necessary. |
| 1280 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 1281 | // Load the shared function info while the function is still in r1. |
| 1282 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1283 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1284 | // Compute the receiver. |
| 1285 | // Do not transform the receiver for strict mode functions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1286 | Label call_to_object, use_global_proxy; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1287 | __ ldr(r2, FieldMemOperand(r2, SharedFunctionInfo::kCompilerHintsOffset)); |
| 1288 | __ tst(r2, Operand(1 << (SharedFunctionInfo::kStrictModeFunction + |
| 1289 | kSmiTagSize))); |
| 1290 | __ b(ne, &push_receiver); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1291 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1292 | // Do not transform the receiver for strict mode functions. |
| 1293 | __ tst(r2, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize))); |
| 1294 | __ b(ne, &push_receiver); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1295 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1296 | // Compute the receiver in sloppy mode. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1297 | __ JumpIfSmi(r0, &call_to_object); |
| 1298 | __ LoadRoot(r1, Heap::kNullValueRootIndex); |
| 1299 | __ cmp(r0, r1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1300 | __ b(eq, &use_global_proxy); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1301 | __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); |
| 1302 | __ cmp(r0, r1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1303 | __ b(eq, &use_global_proxy); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1304 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1305 | // Check if the receiver is already a JavaScript object. |
| 1306 | // r0: receiver |
| 1307 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 1308 | __ CompareObjectType(r0, r1, r1, FIRST_SPEC_OBJECT_TYPE); |
| 1309 | __ b(ge, &push_receiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1310 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1311 | // Convert the receiver to a regular object. |
| 1312 | // r0: receiver |
| 1313 | __ bind(&call_to_object); |
| 1314 | __ push(r0); |
| 1315 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1316 | __ b(&push_receiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1317 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1318 | __ bind(&use_global_proxy); |
| 1319 | __ ldr(r0, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX)); |
| 1320 | __ ldr(r0, FieldMemOperand(r0, GlobalObject::kGlobalProxyOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1321 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1322 | // Push the receiver. |
| 1323 | // r0: receiver |
| 1324 | __ bind(&push_receiver); |
| 1325 | __ push(r0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1326 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1327 | // Copy all arguments from the array to the stack. |
| 1328 | Label entry, loop; |
| 1329 | __ ldr(r0, MemOperand(fp, kIndexOffset)); |
| 1330 | __ b(&entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1331 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1332 | // Load the current argument from the arguments array and push it to the |
| 1333 | // stack. |
| 1334 | // r0: current argument index |
| 1335 | __ bind(&loop); |
| 1336 | __ ldr(r1, MemOperand(fp, kArgsOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1337 | __ Push(r1, r0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1338 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1339 | // Call the runtime to access the property in the arguments array. |
| 1340 | __ CallRuntime(Runtime::kGetProperty, 2); |
| 1341 | __ push(r0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1342 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1343 | // Use inline caching to access the arguments. |
| 1344 | __ ldr(r0, MemOperand(fp, kIndexOffset)); |
| 1345 | __ add(r0, r0, Operand(1 << kSmiTagSize)); |
| 1346 | __ str(r0, MemOperand(fp, kIndexOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1347 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1348 | // Test if the copy loop has finished copying all the elements from the |
| 1349 | // arguments object. |
| 1350 | __ bind(&entry); |
| 1351 | __ ldr(r1, MemOperand(fp, kLimitOffset)); |
| 1352 | __ cmp(r0, r1); |
| 1353 | __ b(ne, &loop); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1354 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1355 | // Call the function. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1356 | Label call_proxy; |
| 1357 | ParameterCount actual(r0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1358 | __ SmiUntag(r0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1359 | __ ldr(r1, MemOperand(fp, kFunctionOffset)); |
| 1360 | __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE); |
| 1361 | __ b(ne, &call_proxy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1362 | __ InvokeFunction(r1, actual, CALL_FUNCTION, NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1363 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1364 | frame_scope.GenerateLeaveFrame(); |
| 1365 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 1366 | __ Jump(lr); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1367 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1368 | // Call the function proxy. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1369 | __ bind(&call_proxy); |
| 1370 | __ push(r1); // add function proxy as last argument |
| 1371 | __ add(r0, r0, Operand(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1372 | __ mov(r2, Operand::Zero()); |
| 1373 | __ GetBuiltinFunction(r1, Builtins::CALL_FUNCTION_PROXY); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1374 | __ Call(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 1375 | RelocInfo::CODE_TARGET); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1376 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1377 | // Tear down the internal frame and remove function, receiver and args. |
| 1378 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1379 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 1380 | __ Jump(lr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1384 | static void ArgumentAdaptorStackCheck(MacroAssembler* masm, |
| 1385 | Label* stack_overflow) { |
| 1386 | // ----------- S t a t e ------------- |
| 1387 | // -- r0 : actual number of arguments |
| 1388 | // -- r1 : function (passed through to callee) |
| 1389 | // -- r2 : expected number of arguments |
| 1390 | // ----------------------------------- |
| 1391 | // Check the stack for overflow. We are not trying to catch |
| 1392 | // interruptions (e.g. debug break and preemption) here, so the "real stack |
| 1393 | // limit" is checked. |
| 1394 | __ LoadRoot(r5, Heap::kRealStackLimitRootIndex); |
| 1395 | // Make r5 the space we have left. The stack might already be overflowed |
| 1396 | // here which will cause r5 to become negative. |
| 1397 | __ sub(r5, sp, r5); |
| 1398 | // Check if the arguments will overflow the stack. |
| 1399 | __ cmp(r5, Operand(r2, LSL, kPointerSizeLog2)); |
| 1400 | __ b(le, stack_overflow); // Signed comparison. |
| 1401 | } |
| 1402 | |
| 1403 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1404 | static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1405 | __ SmiTag(r0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1406 | __ mov(r4, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1407 | __ stm(db_w, sp, r0.bit() | r1.bit() | r4.bit() | |
| 1408 | (FLAG_enable_ool_constant_pool ? pp.bit() : 0) | |
| 1409 | fp.bit() | lr.bit()); |
| 1410 | __ add(fp, sp, |
| 1411 | Operand(StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | |
| 1415 | static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { |
| 1416 | // ----------- S t a t e ------------- |
| 1417 | // -- r0 : result being passed through |
| 1418 | // ----------------------------------- |
| 1419 | // Get the number of arguments passed (as a smi), tear down the frame and |
| 1420 | // then tear down the parameters. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1421 | __ ldr(r1, MemOperand(fp, -(StandardFrameConstants::kFixedFrameSizeFromFp + |
| 1422 | kPointerSize))); |
| 1423 | |
| 1424 | __ LeaveFrame(StackFrame::ARGUMENTS_ADAPTOR); |
| 1425 | __ add(sp, sp, Operand::PointerOffsetFromSmiKey(r1)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1426 | __ add(sp, sp, Operand(kPointerSize)); // adjust for receiver |
| 1427 | } |
| 1428 | |
| 1429 | |
| 1430 | void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { |
| 1431 | // ----------- S t a t e ------------- |
| 1432 | // -- r0 : actual number of arguments |
| 1433 | // -- r1 : function (passed through to callee) |
| 1434 | // -- r2 : expected number of arguments |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1435 | // ----------------------------------- |
| 1436 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1437 | Label stack_overflow; |
| 1438 | ArgumentAdaptorStackCheck(masm, &stack_overflow); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1439 | Label invoke, dont_adapt_arguments; |
| 1440 | |
| 1441 | Label enough, too_few; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1442 | __ ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1443 | __ cmp(r0, r2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1444 | __ b(lt, &too_few); |
| 1445 | __ cmp(r2, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); |
| 1446 | __ b(eq, &dont_adapt_arguments); |
| 1447 | |
| 1448 | { // Enough parameters: actual >= expected |
| 1449 | __ bind(&enough); |
| 1450 | EnterArgumentsAdaptorFrame(masm); |
| 1451 | |
| 1452 | // Calculate copy start address into r0 and copy end address into r2. |
| 1453 | // r0: actual number of arguments as a smi |
| 1454 | // r1: function |
| 1455 | // r2: expected number of arguments |
| 1456 | // r3: code entry to call |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1457 | __ add(r0, fp, Operand::PointerOffsetFromSmiKey(r0)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1458 | // adjust for return address and receiver |
| 1459 | __ add(r0, r0, Operand(2 * kPointerSize)); |
| 1460 | __ sub(r2, r0, Operand(r2, LSL, kPointerSizeLog2)); |
| 1461 | |
| 1462 | // Copy the arguments (including the receiver) to the new stack frame. |
| 1463 | // r0: copy start address |
| 1464 | // r1: function |
| 1465 | // r2: copy end address |
| 1466 | // r3: code entry to call |
| 1467 | |
| 1468 | Label copy; |
| 1469 | __ bind(©); |
| 1470 | __ ldr(ip, MemOperand(r0, 0)); |
| 1471 | __ push(ip); |
| 1472 | __ cmp(r0, r2); // Compare before moving to next argument. |
| 1473 | __ sub(r0, r0, Operand(kPointerSize)); |
| 1474 | __ b(ne, ©); |
| 1475 | |
| 1476 | __ b(&invoke); |
| 1477 | } |
| 1478 | |
| 1479 | { // Too few parameters: Actual < expected |
| 1480 | __ bind(&too_few); |
| 1481 | EnterArgumentsAdaptorFrame(masm); |
| 1482 | |
| 1483 | // Calculate copy start address into r0 and copy end address is fp. |
| 1484 | // r0: actual number of arguments as a smi |
| 1485 | // r1: function |
| 1486 | // r2: expected number of arguments |
| 1487 | // r3: code entry to call |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1488 | __ add(r0, fp, Operand::PointerOffsetFromSmiKey(r0)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1489 | |
| 1490 | // Copy the arguments (including the receiver) to the new stack frame. |
| 1491 | // r0: copy start address |
| 1492 | // r1: function |
| 1493 | // r2: expected number of arguments |
| 1494 | // r3: code entry to call |
| 1495 | Label copy; |
| 1496 | __ bind(©); |
| 1497 | // Adjust load for return address and receiver. |
| 1498 | __ ldr(ip, MemOperand(r0, 2 * kPointerSize)); |
| 1499 | __ push(ip); |
| 1500 | __ cmp(r0, fp); // Compare before moving to next argument. |
| 1501 | __ sub(r0, r0, Operand(kPointerSize)); |
| 1502 | __ b(ne, ©); |
| 1503 | |
| 1504 | // Fill the remaining expected arguments with undefined. |
| 1505 | // r1: function |
| 1506 | // r2: expected number of arguments |
| 1507 | // r3: code entry to call |
| 1508 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 1509 | __ sub(r2, fp, Operand(r2, LSL, kPointerSizeLog2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1510 | // Adjust for frame. |
| 1511 | __ sub(r2, r2, Operand(StandardFrameConstants::kFixedFrameSizeFromFp + |
| 1512 | 2 * kPointerSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1513 | |
| 1514 | Label fill; |
| 1515 | __ bind(&fill); |
| 1516 | __ push(ip); |
| 1517 | __ cmp(sp, r2); |
| 1518 | __ b(ne, &fill); |
| 1519 | } |
| 1520 | |
| 1521 | // Call the entry point. |
| 1522 | __ bind(&invoke); |
| 1523 | __ Call(r3); |
| 1524 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1525 | // Store offset of return address for deoptimizer. |
| 1526 | masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset()); |
| 1527 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1528 | // Exit frame and return. |
| 1529 | LeaveArgumentsAdaptorFrame(masm); |
| 1530 | __ Jump(lr); |
| 1531 | |
| 1532 | |
| 1533 | // ------------------------------------------- |
| 1534 | // Dont adapt arguments. |
| 1535 | // ------------------------------------------- |
| 1536 | __ bind(&dont_adapt_arguments); |
| 1537 | __ Jump(r3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1538 | |
| 1539 | __ bind(&stack_overflow); |
| 1540 | { |
| 1541 | FrameScope frame(masm, StackFrame::MANUAL); |
| 1542 | EnterArgumentsAdaptorFrame(masm); |
| 1543 | __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); |
| 1544 | __ bkpt(0); |
| 1545 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | |
| 1549 | #undef __ |
| 1550 | |
| 1551 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1552 | |
| 1553 | #endif // V8_TARGET_ARCH_ARM |