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