kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 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 | |
| 30 | #include "ic-inl.h" |
| 31 | #include "codegen-inl.h" |
| 32 | #include "stub-cache.h" |
| 33 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 34 | namespace v8 { |
| 35 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 37 | #define __ ACCESS_MASM(masm) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
| 39 | |
| 40 | static void ProbeTable(MacroAssembler* masm, |
| 41 | Code::Flags flags, |
| 42 | StubCache::Table table, |
| 43 | Register name, |
| 44 | Register offset) { |
| 45 | ExternalReference key_offset(SCTableReference::keyReference(table)); |
| 46 | ExternalReference value_offset(SCTableReference::valueReference(table)); |
| 47 | |
| 48 | Label miss; |
| 49 | |
| 50 | // Save the offset on the stack. |
| 51 | __ push(offset); |
| 52 | |
| 53 | // Check that the key in the entry matches the name. |
| 54 | __ mov(ip, Operand(key_offset)); |
| 55 | __ ldr(ip, MemOperand(ip, offset, LSL, 1)); |
| 56 | __ cmp(name, Operand(ip)); |
| 57 | __ b(ne, &miss); |
| 58 | |
| 59 | // Get the code entry from the cache. |
| 60 | __ mov(ip, Operand(value_offset)); |
| 61 | __ ldr(offset, MemOperand(ip, offset, LSL, 1)); |
| 62 | |
| 63 | // Check that the flags match what we're looking for. |
| 64 | __ ldr(offset, FieldMemOperand(offset, Code::kFlagsOffset)); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 65 | __ and_(offset, offset, Operand(~Code::kFlagsNotUsedInLookup)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | __ cmp(offset, Operand(flags)); |
| 67 | __ b(ne, &miss); |
| 68 | |
| 69 | // Restore offset and re-load code entry from cache. |
| 70 | __ pop(offset); |
| 71 | __ mov(ip, Operand(value_offset)); |
| 72 | __ ldr(offset, MemOperand(ip, offset, LSL, 1)); |
| 73 | |
| 74 | // Jump to the first instruction in the code stub. |
| 75 | __ add(offset, offset, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 76 | __ Jump(offset); |
| 77 | |
| 78 | // Miss: Restore offset and fall through. |
| 79 | __ bind(&miss); |
| 80 | __ pop(offset); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | void StubCache::GenerateProbe(MacroAssembler* masm, |
| 85 | Code::Flags flags, |
| 86 | Register receiver, |
| 87 | Register name, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 88 | Register scratch, |
| 89 | Register extra) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 90 | Label miss; |
| 91 | |
| 92 | // Make sure that code is valid. The shifting code relies on the |
| 93 | // entry size being 8. |
| 94 | ASSERT(sizeof(Entry) == 8); |
| 95 | |
| 96 | // Make sure the flags does not name a specific type. |
| 97 | ASSERT(Code::ExtractTypeFromFlags(flags) == 0); |
| 98 | |
| 99 | // Make sure that there are no register conflicts. |
| 100 | ASSERT(!scratch.is(receiver)); |
| 101 | ASSERT(!scratch.is(name)); |
| 102 | |
| 103 | // Check that the receiver isn't a smi. |
| 104 | __ tst(receiver, Operand(kSmiTagMask)); |
| 105 | __ b(eq, &miss); |
| 106 | |
| 107 | // Get the map of the receiver and compute the hash. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 108 | __ ldr(scratch, FieldMemOperand(name, String::kLengthOffset)); |
| 109 | __ ldr(ip, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | __ add(scratch, scratch, Operand(ip)); |
| 111 | __ eor(scratch, scratch, Operand(flags)); |
| 112 | __ and_(scratch, |
| 113 | scratch, |
| 114 | Operand((kPrimaryTableSize - 1) << kHeapObjectTagSize)); |
| 115 | |
| 116 | // Probe the primary table. |
| 117 | ProbeTable(masm, flags, kPrimary, name, scratch); |
| 118 | |
| 119 | // Primary miss: Compute hash for secondary probe. |
| 120 | __ sub(scratch, scratch, Operand(name)); |
| 121 | __ add(scratch, scratch, Operand(flags)); |
| 122 | __ and_(scratch, |
| 123 | scratch, |
| 124 | Operand((kSecondaryTableSize - 1) << kHeapObjectTagSize)); |
| 125 | |
| 126 | // Probe the secondary table. |
| 127 | ProbeTable(masm, flags, kSecondary, name, scratch); |
| 128 | |
| 129 | // Cache miss: Fall-through and let caller handle the miss by |
| 130 | // entering the runtime system. |
| 131 | __ bind(&miss); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, |
| 136 | int index, |
| 137 | Register prototype) { |
| 138 | // Load the global or builtins object from the current context. |
| 139 | __ ldr(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 140 | // Load the global context from the global or builtins object. |
| 141 | __ ldr(prototype, |
| 142 | FieldMemOperand(prototype, GlobalObject::kGlobalContextOffset)); |
| 143 | // Load the function from the global context. |
| 144 | __ ldr(prototype, MemOperand(prototype, Context::SlotOffset(index))); |
| 145 | // Load the initial map. The global functions all have initial maps. |
| 146 | __ ldr(prototype, |
| 147 | FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset)); |
| 148 | // Load the prototype from the initial map. |
| 149 | __ ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset)); |
| 150 | } |
| 151 | |
| 152 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 153 | // Load a fast property out of a holder object (src). In-object properties |
| 154 | // are loaded directly otherwise the property is loaded from the properties |
| 155 | // fixed array. |
| 156 | void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm, |
| 157 | Register dst, Register src, |
| 158 | JSObject* holder, int index) { |
| 159 | // Adjust for the number of properties stored in the holder. |
| 160 | index -= holder->map()->inobject_properties(); |
| 161 | if (index < 0) { |
| 162 | // Get the property straight out of the holder. |
| 163 | int offset = holder->map()->instance_size() + (index * kPointerSize); |
| 164 | __ ldr(dst, FieldMemOperand(src, offset)); |
| 165 | } else { |
| 166 | // Calculate the offset into the properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 167 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 168 | __ ldr(dst, FieldMemOperand(src, JSObject::kPropertiesOffset)); |
| 169 | __ ldr(dst, FieldMemOperand(dst, offset)); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 174 | void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm, |
| 175 | Register receiver, |
| 176 | Register scratch, |
| 177 | Label* miss_label) { |
| 178 | // Check that the receiver isn't a smi. |
| 179 | __ tst(receiver, Operand(kSmiTagMask)); |
| 180 | __ b(eq, miss_label); |
| 181 | |
| 182 | // Check that the object is a JS array. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 183 | __ CompareObjectType(receiver, scratch, scratch, JS_ARRAY_TYPE); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 184 | __ b(ne, miss_label); |
| 185 | |
| 186 | // Load length directly from the JS array. |
| 187 | __ ldr(r0, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 188 | __ Ret(); |
| 189 | } |
| 190 | |
| 191 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 192 | // Generate code to check if an object is a string. If the object is |
| 193 | // a string, the map's instance type is left in the scratch1 register. |
| 194 | static void GenerateStringCheck(MacroAssembler* masm, |
| 195 | Register receiver, |
| 196 | Register scratch1, |
| 197 | Register scratch2, |
| 198 | Label* smi, |
| 199 | Label* non_string_object) { |
| 200 | // Check that the receiver isn't a smi. |
| 201 | __ tst(receiver, Operand(kSmiTagMask)); |
| 202 | __ b(eq, smi); |
| 203 | |
| 204 | // Check that the object is a string. |
| 205 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 206 | __ ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 207 | __ and_(scratch2, scratch1, Operand(kIsNotStringMask)); |
| 208 | // The cast is to resolve the overload for the argument of 0x0. |
| 209 | __ cmp(scratch2, Operand(static_cast<int32_t>(kStringTag))); |
| 210 | __ b(ne, non_string_object); |
| 211 | } |
| 212 | |
| 213 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 214 | // Generate code to load the length from a string object and return the length. |
| 215 | // If the receiver object is not a string or a wrapped string object the |
| 216 | // execution continues at the miss label. The register containing the |
| 217 | // receiver is potentially clobbered. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 218 | void StubCompiler::GenerateLoadStringLength2(MacroAssembler* masm, |
| 219 | Register receiver, |
| 220 | Register scratch1, |
| 221 | Register scratch2, |
| 222 | Label* miss) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 223 | Label check_string, check_wrapper; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 224 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 225 | __ bind(&check_string); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 226 | // Check if the object is a string leaving the instance type in the |
| 227 | // scratch1 register. |
| 228 | GenerateStringCheck(masm, receiver, scratch1, scratch2, |
| 229 | miss, &check_wrapper); |
| 230 | |
| 231 | // Load length directly from the string. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 232 | __ and_(scratch1, scratch1, Operand(kStringSizeMask)); |
| 233 | __ add(scratch1, scratch1, Operand(String::kHashShift)); |
| 234 | __ ldr(r0, FieldMemOperand(receiver, String::kLengthOffset)); |
| 235 | __ mov(r0, Operand(r0, LSR, scratch1)); |
| 236 | __ mov(r0, Operand(r0, LSL, kSmiTagSize)); |
| 237 | __ Ret(); |
| 238 | |
| 239 | // Check if the object is a JSValue wrapper. |
| 240 | __ bind(&check_wrapper); |
| 241 | __ cmp(scratch1, Operand(JS_VALUE_TYPE)); |
| 242 | __ b(ne, miss); |
| 243 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 244 | // Unwrap the value in place and check if the wrapped value is a string. |
| 245 | __ ldr(receiver, FieldMemOperand(receiver, JSValue::kValueOffset)); |
| 246 | __ b(&check_string); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 250 | void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm, |
| 251 | Register receiver, |
| 252 | Register scratch1, |
| 253 | Register scratch2, |
| 254 | Label* miss_label) { |
| 255 | __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); |
| 256 | __ mov(r0, scratch1); |
| 257 | __ Ret(); |
| 258 | } |
| 259 | |
| 260 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 261 | // Generate StoreField code, value is passed in r0 register. |
| 262 | // After executing generated code, the receiver_reg and name_reg |
| 263 | // may be clobbered. |
| 264 | void StubCompiler::GenerateStoreField(MacroAssembler* masm, |
| 265 | Builtins::Name storage_extend, |
| 266 | JSObject* object, |
| 267 | int index, |
| 268 | Map* transition, |
| 269 | Register receiver_reg, |
| 270 | Register name_reg, |
| 271 | Register scratch, |
| 272 | Label* miss_label) { |
| 273 | // r0 : value |
| 274 | Label exit; |
| 275 | |
| 276 | // Check that the receiver isn't a smi. |
| 277 | __ tst(receiver_reg, Operand(kSmiTagMask)); |
| 278 | __ b(eq, miss_label); |
| 279 | |
| 280 | // Check that the map of the receiver hasn't changed. |
| 281 | __ ldr(scratch, FieldMemOperand(receiver_reg, HeapObject::kMapOffset)); |
| 282 | __ cmp(scratch, Operand(Handle<Map>(object->map()))); |
| 283 | __ b(ne, miss_label); |
| 284 | |
| 285 | // Perform global security token check if needed. |
| 286 | if (object->IsJSGlobalProxy()) { |
| 287 | __ CheckAccessGlobalProxy(receiver_reg, scratch, miss_label); |
| 288 | } |
| 289 | |
| 290 | // Stub never generated for non-global objects that require access |
| 291 | // checks. |
| 292 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
| 293 | |
| 294 | // Perform map transition for the receiver if necessary. |
| 295 | if ((transition != NULL) && (object->map()->unused_property_fields() == 0)) { |
| 296 | // The properties must be extended before we can store the value. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 297 | // We jump to a runtime call that extends the properties array. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 298 | __ mov(r2, Operand(Handle<Map>(transition))); |
| 299 | // Please note, if we implement keyed store for arm we need |
| 300 | // to call the Builtins::KeyedStoreIC_ExtendStorage. |
| 301 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_ExtendStorage)); |
| 302 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | if (transition != NULL) { |
| 307 | // Update the map of the object; no write barrier updating is |
| 308 | // needed because the map is never in new space. |
| 309 | __ mov(ip, Operand(Handle<Map>(transition))); |
| 310 | __ str(ip, FieldMemOperand(receiver_reg, HeapObject::kMapOffset)); |
| 311 | } |
| 312 | |
| 313 | // Adjust for the number of properties stored in the object. Even in the |
| 314 | // face of a transition we can use the old map here because the size of the |
| 315 | // object and the number of in-object properties is not going to change. |
| 316 | index -= object->map()->inobject_properties(); |
| 317 | |
| 318 | if (index < 0) { |
| 319 | // Set the property straight into the object. |
| 320 | int offset = object->map()->instance_size() + (index * kPointerSize); |
| 321 | __ str(r0, FieldMemOperand(receiver_reg, offset)); |
| 322 | |
| 323 | // Skip updating write barrier if storing a smi. |
| 324 | __ tst(r0, Operand(kSmiTagMask)); |
| 325 | __ b(eq, &exit); |
| 326 | |
| 327 | // Update the write barrier for the array address. |
| 328 | // Pass the value being stored in the now unused name_reg. |
| 329 | __ mov(name_reg, Operand(offset)); |
| 330 | __ RecordWrite(receiver_reg, name_reg, scratch); |
| 331 | } else { |
| 332 | // Write to the properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 333 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 334 | // Get the properties array |
| 335 | __ ldr(scratch, FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset)); |
| 336 | __ str(r0, FieldMemOperand(scratch, offset)); |
| 337 | |
| 338 | // Skip updating write barrier if storing a smi. |
| 339 | __ tst(r0, Operand(kSmiTagMask)); |
| 340 | __ b(eq, &exit); |
| 341 | |
| 342 | // Update the write barrier for the array address. |
| 343 | // Ok to clobber receiver_reg and name_reg, since we return. |
| 344 | __ mov(name_reg, Operand(offset)); |
| 345 | __ RecordWrite(scratch, name_reg, receiver_reg); |
| 346 | } |
| 347 | |
| 348 | // Return the value (register r0). |
| 349 | __ bind(&exit); |
| 350 | __ Ret(); |
| 351 | } |
| 352 | |
| 353 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 354 | void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) { |
| 355 | ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC); |
| 356 | Code* code = NULL; |
| 357 | if (kind == Code::LOAD_IC) { |
| 358 | code = Builtins::builtin(Builtins::LoadIC_Miss); |
| 359 | } else { |
| 360 | code = Builtins::builtin(Builtins::KeyedLoadIC_Miss); |
| 361 | } |
| 362 | |
| 363 | Handle<Code> ic(code); |
| 364 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 365 | } |
| 366 | |
| 367 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 368 | #undef __ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 369 | #define __ ACCESS_MASM(masm()) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 370 | |
| 371 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 372 | Register StubCompiler::CheckPrototypes(JSObject* object, |
| 373 | Register object_reg, |
| 374 | JSObject* holder, |
| 375 | Register holder_reg, |
| 376 | Register scratch, |
| 377 | String* name, |
| 378 | Label* miss) { |
| 379 | // Check that the maps haven't changed. |
| 380 | Register result = |
| 381 | masm()->CheckMaps(object, object_reg, holder, holder_reg, scratch, miss); |
| 382 | |
| 383 | // If we've skipped any global objects, it's not enough to verify |
| 384 | // that their maps haven't changed. |
| 385 | while (object != holder) { |
| 386 | if (object->IsGlobalObject()) { |
| 387 | GlobalObject* global = GlobalObject::cast(object); |
| 388 | Object* probe = global->EnsurePropertyCell(name); |
| 389 | if (probe->IsFailure()) { |
| 390 | set_failure(Failure::cast(probe)); |
| 391 | return result; |
| 392 | } |
| 393 | JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(probe); |
| 394 | ASSERT(cell->value()->IsTheHole()); |
| 395 | __ mov(scratch, Operand(Handle<Object>(cell))); |
| 396 | __ ldr(scratch, |
| 397 | FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 398 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 399 | __ cmp(scratch, ip); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 400 | __ b(ne, miss); |
| 401 | } |
| 402 | object = JSObject::cast(object->GetPrototype()); |
| 403 | } |
| 404 | |
| 405 | // Return the register containin the holder. |
| 406 | return result; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | void StubCompiler::GenerateLoadField(JSObject* object, |
| 411 | JSObject* holder, |
| 412 | Register receiver, |
| 413 | Register scratch1, |
| 414 | Register scratch2, |
| 415 | int index, |
| 416 | String* name, |
| 417 | Label* miss) { |
| 418 | // Check that the receiver isn't a smi. |
| 419 | __ tst(receiver, Operand(kSmiTagMask)); |
| 420 | __ b(eq, miss); |
| 421 | |
| 422 | // Check that the maps haven't changed. |
| 423 | Register reg = |
| 424 | CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss); |
| 425 | GenerateFastPropertyLoad(masm(), r0, reg, holder, index); |
| 426 | __ Ret(); |
| 427 | } |
| 428 | |
| 429 | |
| 430 | void StubCompiler::GenerateLoadConstant(JSObject* object, |
| 431 | JSObject* holder, |
| 432 | Register receiver, |
| 433 | Register scratch1, |
| 434 | Register scratch2, |
| 435 | Object* value, |
| 436 | String* name, |
| 437 | Label* miss) { |
| 438 | // Check that the receiver isn't a smi. |
| 439 | __ tst(receiver, Operand(kSmiTagMask)); |
| 440 | __ b(eq, miss); |
| 441 | |
| 442 | // Check that the maps haven't changed. |
| 443 | Register reg = |
| 444 | CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss); |
| 445 | |
| 446 | // Return the constant value. |
| 447 | __ mov(r0, Operand(Handle<Object>(value))); |
| 448 | __ Ret(); |
| 449 | } |
| 450 | |
| 451 | |
| 452 | void StubCompiler::GenerateLoadCallback(JSObject* object, |
| 453 | JSObject* holder, |
| 454 | Register receiver, |
| 455 | Register name_reg, |
| 456 | Register scratch1, |
| 457 | Register scratch2, |
| 458 | AccessorInfo* callback, |
| 459 | String* name, |
| 460 | Label* miss) { |
| 461 | // Check that the receiver isn't a smi. |
| 462 | __ tst(receiver, Operand(kSmiTagMask)); |
| 463 | __ b(eq, miss); |
| 464 | |
| 465 | // Check that the maps haven't changed. |
| 466 | Register reg = |
| 467 | CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss); |
| 468 | |
| 469 | // Push the arguments on the JS stack of the caller. |
| 470 | __ push(receiver); // receiver |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 471 | __ push(reg); // holder |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 472 | __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback data |
| 473 | __ push(ip); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 474 | __ ldr(reg, FieldMemOperand(ip, AccessorInfo::kDataOffset)); |
| 475 | __ push(reg); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 476 | __ push(name_reg); // name |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 477 | |
| 478 | // Do tail-call to the runtime system. |
| 479 | ExternalReference load_callback_property = |
| 480 | ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 481 | __ TailCallRuntime(load_callback_property, 5, 1); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | |
| 485 | void StubCompiler::GenerateLoadInterceptor(JSObject* object, |
| 486 | JSObject* holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 487 | LookupResult* lookup, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 488 | Register receiver, |
| 489 | Register name_reg, |
| 490 | Register scratch1, |
| 491 | Register scratch2, |
| 492 | String* name, |
| 493 | Label* miss) { |
| 494 | // Check that the receiver isn't a smi. |
| 495 | __ tst(receiver, Operand(kSmiTagMask)); |
| 496 | __ b(eq, miss); |
| 497 | |
| 498 | // Check that the maps haven't changed. |
| 499 | Register reg = |
| 500 | CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss); |
| 501 | |
| 502 | // Push the arguments on the JS stack of the caller. |
| 503 | __ push(receiver); // receiver |
| 504 | __ push(reg); // holder |
| 505 | __ push(name_reg); // name |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 506 | |
| 507 | InterceptorInfo* interceptor = holder->GetNamedInterceptor(); |
| 508 | ASSERT(!Heap::InNewSpace(interceptor)); |
| 509 | __ mov(scratch1, Operand(Handle<Object>(interceptor))); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 510 | __ push(scratch1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 511 | __ ldr(scratch2, FieldMemOperand(scratch1, InterceptorInfo::kDataOffset)); |
| 512 | __ push(scratch2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 513 | |
| 514 | // Do tail-call to the runtime system. |
| 515 | ExternalReference load_ic_property = |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 516 | ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 517 | __ TailCallRuntime(load_ic_property, 5, 1); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 521 | Object* StubCompiler::CompileLazyCompile(Code::Flags flags) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 522 | // ----------- S t a t e ------------- |
| 523 | // -- r1: function |
| 524 | // -- lr: return address |
| 525 | // ----------------------------------- |
| 526 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 527 | // Enter an internal frame. |
| 528 | __ EnterInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 529 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 530 | // Preserve the function. |
| 531 | __ push(r1); |
| 532 | |
| 533 | // Push the function on the stack as the argument to the runtime function. |
| 534 | __ push(r1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 535 | __ CallRuntime(Runtime::kLazyCompile, 1); |
| 536 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 537 | // Calculate the entry point. |
| 538 | __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 539 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 540 | // Restore saved function. |
| 541 | __ pop(r1); |
| 542 | |
| 543 | // Tear down temporary frame. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 544 | __ LeaveInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | |
| 546 | // Do a tail-call of the compiled function. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 547 | __ Jump(r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 549 | return GetCodeWithFlags(flags, "LazyCompileStub"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | |
| 553 | Object* CallStubCompiler::CompileCallField(Object* object, |
| 554 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 555 | int index, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 556 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 558 | // -- lr: return address |
| 559 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 560 | Label miss; |
| 561 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 562 | const int argc = arguments().immediate(); |
| 563 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 564 | // Get the receiver of the function from the stack into r0. |
| 565 | __ ldr(r0, MemOperand(sp, argc * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | // Check that the receiver isn't a smi. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 567 | __ tst(r0, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | __ b(eq, &miss); |
| 569 | |
| 570 | // Do the right check and compute the holder register. |
| 571 | Register reg = |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 572 | CheckPrototypes(JSObject::cast(object), r0, holder, r3, r2, name, &miss); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 573 | GenerateFastPropertyLoad(masm(), r1, reg, holder, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | |
| 575 | // Check that the function really is a function. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 576 | __ tst(r1, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 577 | __ b(eq, &miss); |
| 578 | // Get the map. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 579 | __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | __ b(ne, &miss); |
| 581 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 582 | // Patch the receiver on the stack with the global proxy if |
| 583 | // necessary. |
| 584 | if (object->IsGlobalObject()) { |
| 585 | __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset)); |
| 586 | __ str(r3, MemOperand(sp, argc * kPointerSize)); |
| 587 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 588 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 589 | // Invoke the function. |
| 590 | __ InvokeFunction(r1, arguments(), JUMP_FUNCTION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | |
| 592 | // Handle call cache miss. |
| 593 | __ bind(&miss); |
| 594 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 595 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 596 | |
| 597 | // Return the generated code. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 598 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | |
| 602 | Object* CallStubCompiler::CompileCallConstant(Object* object, |
| 603 | JSObject* holder, |
| 604 | JSFunction* function, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 605 | String* name, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 606 | CheckType check) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 607 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 608 | // -- lr: return address |
| 609 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 610 | Label miss; |
| 611 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 612 | // Get the receiver from the stack |
| 613 | const int argc = arguments().immediate(); |
| 614 | __ ldr(r1, MemOperand(sp, argc * kPointerSize)); |
| 615 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 616 | // Check that the receiver isn't a smi. |
| 617 | if (check != NUMBER_CHECK) { |
| 618 | __ tst(r1, Operand(kSmiTagMask)); |
| 619 | __ b(eq, &miss); |
| 620 | } |
| 621 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 622 | // Make sure that it's okay not to patch the on stack receiver |
| 623 | // unless we're doing a receiver map check. |
| 624 | ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK); |
| 625 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 626 | switch (check) { |
| 627 | case RECEIVER_MAP_CHECK: |
| 628 | // Check that the maps haven't changed. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 629 | CheckPrototypes(JSObject::cast(object), r1, holder, r3, r2, name, &miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 630 | |
| 631 | // Patch the receiver on the stack with the global proxy if |
| 632 | // necessary. |
| 633 | if (object->IsGlobalObject()) { |
| 634 | __ ldr(r3, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 635 | __ str(r3, MemOperand(sp, argc * kPointerSize)); |
| 636 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 637 | break; |
| 638 | |
| 639 | case STRING_CHECK: |
| 640 | // Check that the object is a two-byte string or a symbol. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 641 | __ CompareObjectType(r1, r2, r2, FIRST_NONSTRING_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 642 | __ b(hs, &miss); |
| 643 | // Check that the maps starting from the prototype haven't changed. |
| 644 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 645 | Context::STRING_FUNCTION_INDEX, |
| 646 | r2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 647 | CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3, |
| 648 | r1, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 649 | break; |
| 650 | |
| 651 | case NUMBER_CHECK: { |
| 652 | Label fast; |
| 653 | // Check that the object is a smi or a heap number. |
| 654 | __ tst(r1, Operand(kSmiTagMask)); |
| 655 | __ b(eq, &fast); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 656 | __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 657 | __ b(ne, &miss); |
| 658 | __ bind(&fast); |
| 659 | // Check that the maps starting from the prototype haven't changed. |
| 660 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 661 | Context::NUMBER_FUNCTION_INDEX, |
| 662 | r2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 663 | CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3, |
| 664 | r1, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | break; |
| 666 | } |
| 667 | |
| 668 | case BOOLEAN_CHECK: { |
| 669 | Label fast; |
| 670 | // Check that the object is a boolean. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 671 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 672 | __ cmp(r1, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 673 | __ b(eq, &fast); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 674 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 675 | __ cmp(r1, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 676 | __ b(ne, &miss); |
| 677 | __ bind(&fast); |
| 678 | // Check that the maps starting from the prototype haven't changed. |
| 679 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 680 | Context::BOOLEAN_FUNCTION_INDEX, |
| 681 | r2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 682 | CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3, |
| 683 | r1, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 684 | break; |
| 685 | } |
| 686 | |
| 687 | case JSARRAY_HAS_FAST_ELEMENTS_CHECK: |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 688 | CheckPrototypes(JSObject::cast(object), r1, holder, r3, r2, name, &miss); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 689 | // Make sure object->HasFastElements(). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 690 | // Get the elements array of the object. |
| 691 | __ ldr(r3, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 692 | // Check that the object is in fast mode (not dictionary). |
| 693 | __ ldr(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 694 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 695 | __ cmp(r2, ip); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 696 | __ b(ne, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 697 | break; |
| 698 | |
| 699 | default: |
| 700 | UNREACHABLE(); |
| 701 | } |
| 702 | |
| 703 | // Get the function and setup the context. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 704 | __ mov(r1, Operand(Handle<JSFunction>(function))); |
| 705 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 707 | // Jump to the cached code (tail call). |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 708 | ASSERT(function->is_compiled()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | Handle<Code> code(function->code()); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 710 | ParameterCount expected(function->shared()->formal_parameter_count()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 711 | __ InvokeCode(code, expected, arguments(), |
| 712 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 713 | |
| 714 | // Handle call cache miss. |
| 715 | __ bind(&miss); |
| 716 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 717 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 718 | |
| 719 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 720 | String* function_name = NULL; |
| 721 | if (function->shared()->name()->IsString()) { |
| 722 | function_name = String::cast(function->shared()->name()); |
| 723 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 724 | return GetCode(CONSTANT_FUNCTION, function_name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | |
| 728 | Object* CallStubCompiler::CompileCallInterceptor(Object* object, |
| 729 | JSObject* holder, |
| 730 | String* name) { |
| 731 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 732 | // -- lr: return address |
| 733 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 734 | Label miss; |
| 735 | |
| 736 | // TODO(1224669): Implement. |
| 737 | |
| 738 | // Handle call cache miss. |
| 739 | __ bind(&miss); |
| 740 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 741 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 742 | |
| 743 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 744 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 748 | Object* CallStubCompiler::CompileCallGlobal(JSObject* object, |
| 749 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 750 | JSGlobalPropertyCell* cell, |
| 751 | JSFunction* function, |
| 752 | String* name) { |
| 753 | // ----------- S t a t e ------------- |
| 754 | // -- lr: return address |
| 755 | // ----------------------------------- |
| 756 | Label miss; |
| 757 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 758 | // Get the number of arguments. |
| 759 | const int argc = arguments().immediate(); |
| 760 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 761 | // Get the receiver from the stack. |
| 762 | __ ldr(r0, MemOperand(sp, argc * kPointerSize)); |
| 763 | |
| 764 | // If the object is the holder then we know that it's a global |
| 765 | // object which can only happen for contextual calls. In this case, |
| 766 | // the receiver cannot be a smi. |
| 767 | if (object != holder) { |
| 768 | __ tst(r0, Operand(kSmiTagMask)); |
| 769 | __ b(eq, &miss); |
| 770 | } |
| 771 | |
| 772 | // Check that the maps haven't changed. |
| 773 | CheckPrototypes(object, r0, holder, r3, r2, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 774 | |
| 775 | // Get the value from the cell. |
| 776 | __ mov(r3, Operand(Handle<JSGlobalPropertyCell>(cell))); |
| 777 | __ ldr(r1, FieldMemOperand(r3, JSGlobalPropertyCell::kValueOffset)); |
| 778 | |
| 779 | // Check that the cell contains the same function. |
| 780 | __ cmp(r1, Operand(Handle<JSFunction>(function))); |
| 781 | __ b(ne, &miss); |
| 782 | |
| 783 | // Patch the receiver on the stack with the global proxy if |
| 784 | // necessary. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 785 | if (object->IsGlobalObject()) { |
| 786 | __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset)); |
| 787 | __ str(r3, MemOperand(sp, argc * kPointerSize)); |
| 788 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 789 | |
| 790 | // Setup the context (function already in r1). |
| 791 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 792 | |
| 793 | // Jump to the cached code (tail call). |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 794 | __ IncrementCounter(&Counters::call_global_inline, 1, r2, r3); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 795 | ASSERT(function->is_compiled()); |
| 796 | Handle<Code> code(function->code()); |
| 797 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 798 | __ InvokeCode(code, expected, arguments(), |
| 799 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
| 800 | |
| 801 | // Handle call cache miss. |
| 802 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 803 | __ IncrementCounter(&Counters::call_global_inline_miss, 1, r1, r3); |
| 804 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
| 805 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 806 | |
| 807 | // Return the generated code. |
| 808 | return GetCode(NORMAL, name); |
| 809 | } |
| 810 | |
| 811 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 812 | Object* StoreStubCompiler::CompileStoreField(JSObject* object, |
| 813 | int index, |
| 814 | Map* transition, |
| 815 | String* name) { |
| 816 | // ----------- S t a t e ------------- |
| 817 | // -- r0 : value |
| 818 | // -- r2 : name |
| 819 | // -- lr : return address |
| 820 | // -- [sp] : receiver |
| 821 | // ----------------------------------- |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 822 | Label miss; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 823 | |
| 824 | // Get the receiver from the stack. |
| 825 | __ ldr(r3, MemOperand(sp, 0 * kPointerSize)); |
| 826 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 827 | // name register might be clobbered. |
| 828 | GenerateStoreField(masm(), |
| 829 | Builtins::StoreIC_ExtendStorage, |
| 830 | object, |
| 831 | index, |
| 832 | transition, |
| 833 | r3, r2, r1, |
| 834 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 835 | __ bind(&miss); |
| 836 | __ mov(r2, Operand(Handle<String>(name))); // restore name |
| 837 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 838 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 839 | |
| 840 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 841 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | |
| 845 | Object* StoreStubCompiler::CompileStoreCallback(JSObject* object, |
| 846 | AccessorInfo* callback, |
| 847 | String* name) { |
| 848 | // ----------- S t a t e ------------- |
| 849 | // -- r0 : value |
| 850 | // -- r2 : name |
| 851 | // -- lr : return address |
| 852 | // -- [sp] : receiver |
| 853 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 854 | Label miss; |
| 855 | |
| 856 | // Get the object from the stack. |
| 857 | __ ldr(r3, MemOperand(sp, 0 * kPointerSize)); |
| 858 | |
| 859 | // Check that the object isn't a smi. |
| 860 | __ tst(r3, Operand(kSmiTagMask)); |
| 861 | __ b(eq, &miss); |
| 862 | |
| 863 | // Check that the map of the object hasn't changed. |
| 864 | __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 865 | __ cmp(r1, Operand(Handle<Map>(object->map()))); |
| 866 | __ b(ne, &miss); |
| 867 | |
| 868 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 869 | if (object->IsJSGlobalProxy()) { |
| 870 | __ CheckAccessGlobalProxy(r3, r1, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | // Stub never generated for non-global objects that require access |
| 874 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 875 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 876 | |
| 877 | __ ldr(ip, MemOperand(sp)); // receiver |
| 878 | __ push(ip); |
| 879 | __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback info |
| 880 | __ push(ip); |
| 881 | __ push(r2); // name |
| 882 | __ push(r0); // value |
| 883 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 884 | // Do tail-call to the runtime system. |
| 885 | ExternalReference store_callback_property = |
| 886 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 887 | __ TailCallRuntime(store_callback_property, 4, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 888 | |
| 889 | // Handle store cache miss. |
| 890 | __ bind(&miss); |
| 891 | __ mov(r2, Operand(Handle<String>(name))); // restore name |
| 892 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 893 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 894 | |
| 895 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 896 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | |
| 900 | Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver, |
| 901 | String* name) { |
| 902 | // ----------- S t a t e ------------- |
| 903 | // -- r0 : value |
| 904 | // -- r2 : name |
| 905 | // -- lr : return address |
| 906 | // -- [sp] : receiver |
| 907 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 908 | Label miss; |
| 909 | |
| 910 | // Get the object from the stack. |
| 911 | __ ldr(r3, MemOperand(sp, 0 * kPointerSize)); |
| 912 | |
| 913 | // Check that the object isn't a smi. |
| 914 | __ tst(r3, Operand(kSmiTagMask)); |
| 915 | __ b(eq, &miss); |
| 916 | |
| 917 | // Check that the map of the object hasn't changed. |
| 918 | __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 919 | __ cmp(r1, Operand(Handle<Map>(receiver->map()))); |
| 920 | __ b(ne, &miss); |
| 921 | |
| 922 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 923 | if (receiver->IsJSGlobalProxy()) { |
| 924 | __ CheckAccessGlobalProxy(r3, r1, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | // Stub never generated for non-global objects that require access |
| 928 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 929 | ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 930 | |
| 931 | __ ldr(ip, MemOperand(sp)); // receiver |
| 932 | __ push(ip); |
| 933 | __ push(r2); // name |
| 934 | __ push(r0); // value |
| 935 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 936 | // Do tail-call to the runtime system. |
| 937 | ExternalReference store_ic_property = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 938 | ExternalReference(IC_Utility(IC::kStoreInterceptorProperty)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 939 | __ TailCallRuntime(store_ic_property, 3, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | |
| 941 | // Handle store cache miss. |
| 942 | __ bind(&miss); |
| 943 | __ mov(r2, Operand(Handle<String>(name))); // restore name |
| 944 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 945 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 946 | |
| 947 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 948 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 952 | Object* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object, |
| 953 | JSGlobalPropertyCell* cell, |
| 954 | String* name) { |
| 955 | // ----------- S t a t e ------------- |
| 956 | // -- r0 : value |
| 957 | // -- r2 : name |
| 958 | // -- lr : return address |
| 959 | // -- [sp] : receiver |
| 960 | // ----------------------------------- |
| 961 | Label miss; |
| 962 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 963 | // Check that the map of the global has not changed. |
| 964 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| 965 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 966 | __ cmp(r3, Operand(Handle<Map>(object->map()))); |
| 967 | __ b(ne, &miss); |
| 968 | |
| 969 | // Store the value in the cell. |
| 970 | __ mov(r2, Operand(Handle<JSGlobalPropertyCell>(cell))); |
| 971 | __ str(r0, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 972 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 973 | __ IncrementCounter(&Counters::named_store_global_inline, 1, r1, r3); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 974 | __ Ret(); |
| 975 | |
| 976 | // Handle store cache miss. |
| 977 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 978 | __ IncrementCounter(&Counters::named_store_global_inline_miss, 1, r1, r3); |
| 979 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
| 980 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 981 | |
| 982 | // Return the generated code. |
| 983 | return GetCode(NORMAL, name); |
| 984 | } |
| 985 | |
| 986 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 987 | Object* LoadStubCompiler::CompileLoadField(JSObject* object, |
| 988 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 989 | int index, |
| 990 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 991 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 992 | // -- r2 : name |
| 993 | // -- lr : return address |
| 994 | // -- [sp] : receiver |
| 995 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 996 | Label miss; |
| 997 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 998 | __ ldr(r0, MemOperand(sp, 0)); |
| 999 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1000 | GenerateLoadField(object, holder, r0, r3, r1, index, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1001 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1002 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1003 | |
| 1004 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1005 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | Object* LoadStubCompiler::CompileLoadCallback(JSObject* object, |
| 1010 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1011 | AccessorInfo* callback, |
| 1012 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1013 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1014 | // -- r2 : name |
| 1015 | // -- lr : return address |
| 1016 | // -- [sp] : receiver |
| 1017 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1018 | Label miss; |
| 1019 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1020 | __ ldr(r0, MemOperand(sp, 0)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1021 | GenerateLoadCallback(object, holder, r0, r2, r3, r1, callback, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1022 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1023 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1024 | |
| 1025 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1026 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | |
| 1030 | Object* LoadStubCompiler::CompileLoadConstant(JSObject* object, |
| 1031 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1032 | Object* value, |
| 1033 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1034 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1035 | // -- r2 : name |
| 1036 | // -- lr : return address |
| 1037 | // -- [sp] : receiver |
| 1038 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1039 | Label miss; |
| 1040 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1041 | __ ldr(r0, MemOperand(sp, 0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1042 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1043 | GenerateLoadConstant(object, holder, r0, r3, r1, value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1044 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1045 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1046 | |
| 1047 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1048 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* object, |
| 1053 | JSObject* holder, |
| 1054 | String* name) { |
| 1055 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | // -- r2 : name |
| 1057 | // -- lr : return address |
| 1058 | // -- [sp] : receiver |
| 1059 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1060 | Label miss; |
| 1061 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1062 | __ ldr(r0, MemOperand(sp, 0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1063 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1064 | LookupResult lookup; |
| 1065 | holder->LocalLookupRealNamedProperty(name, &lookup); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1066 | GenerateLoadInterceptor(object, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1067 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1068 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1069 | r0, |
| 1070 | r2, |
| 1071 | r3, |
| 1072 | r1, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1073 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1074 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1075 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1076 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1077 | |
| 1078 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1079 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1083 | Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object, |
| 1084 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1085 | JSGlobalPropertyCell* cell, |
| 1086 | String* name, |
| 1087 | bool is_dont_delete) { |
| 1088 | // ----------- S t a t e ------------- |
| 1089 | // -- r2 : name |
| 1090 | // -- lr : return address |
| 1091 | // -- [sp] : receiver |
| 1092 | // ----------------------------------- |
| 1093 | Label miss; |
| 1094 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1095 | // Get the receiver from the stack. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1096 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1097 | |
| 1098 | // If the object is the holder then we know that it's a global |
| 1099 | // object which can only happen for contextual calls. In this case, |
| 1100 | // the receiver cannot be a smi. |
| 1101 | if (object != holder) { |
| 1102 | __ tst(r1, Operand(kSmiTagMask)); |
| 1103 | __ b(eq, &miss); |
| 1104 | } |
| 1105 | |
| 1106 | // Check that the map of the global has not changed. |
| 1107 | CheckPrototypes(object, r1, holder, r3, r0, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1108 | |
| 1109 | // Get the value from the cell. |
| 1110 | __ mov(r3, Operand(Handle<JSGlobalPropertyCell>(cell))); |
| 1111 | __ ldr(r0, FieldMemOperand(r3, JSGlobalPropertyCell::kValueOffset)); |
| 1112 | |
| 1113 | // Check for deleted property if property can actually be deleted. |
| 1114 | if (!is_dont_delete) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1115 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1116 | __ cmp(r0, ip); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1117 | __ b(eq, &miss); |
| 1118 | } |
| 1119 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1120 | __ IncrementCounter(&Counters::named_load_global_inline, 1, r1, r3); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1121 | __ Ret(); |
| 1122 | |
| 1123 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1124 | __ IncrementCounter(&Counters::named_load_global_inline_miss, 1, r1, r3); |
| 1125 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1126 | |
| 1127 | // Return the generated code. |
| 1128 | return GetCode(NORMAL, name); |
| 1129 | } |
| 1130 | |
| 1131 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1132 | Object* KeyedLoadStubCompiler::CompileLoadField(String* name, |
| 1133 | JSObject* receiver, |
| 1134 | JSObject* holder, |
| 1135 | int index) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1136 | // ----------- S t a t e ------------- |
| 1137 | // -- lr : return address |
| 1138 | // -- sp[0] : key |
| 1139 | // -- sp[4] : receiver |
| 1140 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1141 | Label miss; |
| 1142 | |
| 1143 | __ ldr(r2, MemOperand(sp, 0)); |
| 1144 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1145 | |
| 1146 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1147 | __ b(ne, &miss); |
| 1148 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1149 | GenerateLoadField(receiver, holder, r0, r3, r1, index, name, &miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1150 | __ bind(&miss); |
| 1151 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1152 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1153 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | |
| 1157 | Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name, |
| 1158 | JSObject* receiver, |
| 1159 | JSObject* holder, |
| 1160 | AccessorInfo* callback) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1161 | // ----------- S t a t e ------------- |
| 1162 | // -- lr : return address |
| 1163 | // -- sp[0] : key |
| 1164 | // -- sp[4] : receiver |
| 1165 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1166 | Label miss; |
| 1167 | |
| 1168 | __ ldr(r2, MemOperand(sp, 0)); |
| 1169 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1170 | |
| 1171 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1172 | __ b(ne, &miss); |
| 1173 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1174 | GenerateLoadCallback(receiver, holder, r0, r2, r3, r1, callback, name, &miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1175 | __ bind(&miss); |
| 1176 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1177 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1178 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | |
| 1182 | Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name, |
| 1183 | JSObject* receiver, |
| 1184 | JSObject* holder, |
| 1185 | Object* value) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1186 | // ----------- S t a t e ------------- |
| 1187 | // -- lr : return address |
| 1188 | // -- sp[0] : key |
| 1189 | // -- sp[4] : receiver |
| 1190 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1191 | Label miss; |
| 1192 | |
| 1193 | // Check the key is the cached one |
| 1194 | __ ldr(r2, MemOperand(sp, 0)); |
| 1195 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1196 | |
| 1197 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1198 | __ b(ne, &miss); |
| 1199 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1200 | GenerateLoadConstant(receiver, holder, r0, r3, r1, value, name, &miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1201 | __ bind(&miss); |
| 1202 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1203 | |
| 1204 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1205 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 1210 | JSObject* holder, |
| 1211 | String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1212 | // ----------- S t a t e ------------- |
| 1213 | // -- lr : return address |
| 1214 | // -- sp[0] : key |
| 1215 | // -- sp[4] : receiver |
| 1216 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1217 | Label miss; |
| 1218 | |
| 1219 | // Check the key is the cached one |
| 1220 | __ ldr(r2, MemOperand(sp, 0)); |
| 1221 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1222 | |
| 1223 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1224 | __ b(ne, &miss); |
| 1225 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1226 | LookupResult lookup; |
| 1227 | holder->LocalLookupRealNamedProperty(name, &lookup); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1228 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1229 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1230 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1231 | r0, |
| 1232 | r2, |
| 1233 | r3, |
| 1234 | r1, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1235 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1236 | &miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1237 | __ bind(&miss); |
| 1238 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1239 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1240 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1245 | // ----------- S t a t e ------------- |
| 1246 | // -- lr : return address |
| 1247 | // -- sp[0] : key |
| 1248 | // -- sp[4] : receiver |
| 1249 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1250 | Label miss; |
| 1251 | |
| 1252 | // Check the key is the cached one |
| 1253 | __ ldr(r2, MemOperand(sp, 0)); |
| 1254 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1255 | |
| 1256 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1257 | __ b(ne, &miss); |
| 1258 | |
| 1259 | GenerateLoadArrayLength(masm(), r0, r3, &miss); |
| 1260 | __ bind(&miss); |
| 1261 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1262 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1263 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1267 | Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1268 | // ----------- S t a t e ------------- |
| 1269 | // -- lr : return address |
| 1270 | // -- sp[0] : key |
| 1271 | // -- sp[4] : receiver |
| 1272 | // ----------------------------------- |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1273 | Label miss; |
| 1274 | __ IncrementCounter(&Counters::keyed_load_string_length, 1, r1, r3); |
| 1275 | |
| 1276 | __ ldr(r2, MemOperand(sp)); |
| 1277 | __ ldr(r0, MemOperand(sp, kPointerSize)); // receiver |
| 1278 | |
| 1279 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1280 | __ b(ne, &miss); |
| 1281 | |
| 1282 | GenerateLoadStringLength2(masm(), r0, r1, r3, &miss); |
| 1283 | __ bind(&miss); |
| 1284 | __ DecrementCounter(&Counters::keyed_load_string_length, 1, r1, r3); |
| 1285 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1286 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1287 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1288 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1292 | // TODO(1224671): implement the fast case. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1293 | Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1294 | // ----------- S t a t e ------------- |
| 1295 | // -- lr : return address |
| 1296 | // -- sp[0] : key |
| 1297 | // -- sp[4] : receiver |
| 1298 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1299 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1300 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1301 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | |
| 1305 | Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object, |
| 1306 | int index, |
| 1307 | Map* transition, |
| 1308 | String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1309 | // ----------- S t a t e ------------- |
| 1310 | // -- r0 : value |
| 1311 | // -- r2 : name |
| 1312 | // -- lr : return address |
| 1313 | // -- [sp] : receiver |
| 1314 | // ----------------------------------- |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1315 | Label miss; |
| 1316 | |
| 1317 | __ IncrementCounter(&Counters::keyed_store_field, 1, r1, r3); |
| 1318 | |
| 1319 | // Check that the name has not changed. |
| 1320 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1321 | __ b(ne, &miss); |
| 1322 | |
| 1323 | // Load receiver from the stack. |
| 1324 | __ ldr(r3, MemOperand(sp)); |
| 1325 | // r1 is used as scratch register, r3 and r2 might be clobbered. |
| 1326 | GenerateStoreField(masm(), |
| 1327 | Builtins::StoreIC_ExtendStorage, |
| 1328 | object, |
| 1329 | index, |
| 1330 | transition, |
| 1331 | r3, r2, r1, |
| 1332 | &miss); |
| 1333 | __ bind(&miss); |
| 1334 | |
| 1335 | __ DecrementCounter(&Counters::keyed_store_field, 1, r1, r3); |
| 1336 | __ mov(r2, Operand(Handle<String>(name))); // restore name register. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1337 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss)); |
| 1338 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1339 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1340 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1341 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1342 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1343 | |
| 1344 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1345 | Object* ConstructStubCompiler::CompileConstructStub( |
| 1346 | SharedFunctionInfo* shared) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1347 | // ----------- S t a t e ------------- |
| 1348 | // -- r0 : argc |
| 1349 | // -- r1 : constructor |
| 1350 | // -- lr : return address |
| 1351 | // -- [sp] : last argument |
| 1352 | // ----------------------------------- |
| 1353 | Label generic_stub_call; |
| 1354 | |
| 1355 | // Use r7 for holding undefined which is used in several places below. |
| 1356 | __ LoadRoot(r7, Heap::kUndefinedValueRootIndex); |
| 1357 | |
| 1358 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1359 | // Check to see whether there are any break points in the function code. If |
| 1360 | // there are jump to the generic constructor stub which calls the actual |
| 1361 | // code for the function thereby hitting the break points. |
| 1362 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 1363 | __ ldr(r2, FieldMemOperand(r2, SharedFunctionInfo::kDebugInfoOffset)); |
| 1364 | __ cmp(r2, r7); |
| 1365 | __ b(ne, &generic_stub_call); |
| 1366 | #endif |
| 1367 | |
| 1368 | // Load the initial map and verify that it is in fact a map. |
| 1369 | // r1: constructor function |
| 1370 | // r7: undefined |
| 1371 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1372 | __ tst(r2, Operand(kSmiTagMask)); |
| 1373 | __ b(eq, &generic_stub_call); |
| 1374 | __ CompareObjectType(r2, r3, r4, MAP_TYPE); |
| 1375 | __ b(ne, &generic_stub_call); |
| 1376 | |
| 1377 | #ifdef DEBUG |
| 1378 | // Cannot construct functions this way. |
| 1379 | // r0: argc |
| 1380 | // r1: constructor function |
| 1381 | // r2: initial map |
| 1382 | // r7: undefined |
| 1383 | __ CompareInstanceType(r2, r3, JS_FUNCTION_TYPE); |
| 1384 | __ Check(ne, "Function constructed by construct stub."); |
| 1385 | #endif |
| 1386 | |
| 1387 | // Now allocate the JSObject in new space. |
| 1388 | // r0: argc |
| 1389 | // r1: constructor function |
| 1390 | // r2: initial map |
| 1391 | // r7: undefined |
| 1392 | __ ldrb(r3, FieldMemOperand(r2, Map::kInstanceSizeOffset)); |
| 1393 | __ AllocateObjectInNewSpace(r3, |
| 1394 | r4, |
| 1395 | r5, |
| 1396 | r6, |
| 1397 | &generic_stub_call, |
| 1398 | NO_ALLOCATION_FLAGS); |
| 1399 | |
| 1400 | // Allocated the JSObject, now initialize the fields. Map is set to initial |
| 1401 | // map and properties and elements are set to empty fixed array. |
| 1402 | // r0: argc |
| 1403 | // r1: constructor function |
| 1404 | // r2: initial map |
| 1405 | // r3: object size (in words) |
| 1406 | // r4: JSObject (not tagged) |
| 1407 | // r7: undefined |
| 1408 | __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex); |
| 1409 | __ mov(r5, r4); |
| 1410 | ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset); |
| 1411 | __ str(r2, MemOperand(r5, kPointerSize, PostIndex)); |
| 1412 | ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset); |
| 1413 | __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
| 1414 | ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset); |
| 1415 | __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
| 1416 | |
| 1417 | // Calculate the location of the first argument. The stack contains only the |
| 1418 | // argc arguments. |
| 1419 | __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 1420 | |
| 1421 | // Fill all the in-object properties with undefined. |
| 1422 | // r0: argc |
| 1423 | // r1: first argument |
| 1424 | // r3: object size (in words) |
| 1425 | // r4: JSObject (not tagged) |
| 1426 | // r5: First in-object property of JSObject (not tagged) |
| 1427 | // r7: undefined |
| 1428 | // Fill the initialized properties with a constant value or a passed argument |
| 1429 | // depending on the this.x = ...; assignment in the function. |
| 1430 | for (int i = 0; i < shared->this_property_assignments_count(); i++) { |
| 1431 | if (shared->IsThisPropertyAssignmentArgument(i)) { |
| 1432 | Label not_passed, next; |
| 1433 | // Check if the argument assigned to the property is actually passed. |
| 1434 | int arg_number = shared->GetThisPropertyAssignmentArgument(i); |
| 1435 | __ cmp(r0, Operand(arg_number)); |
| 1436 | __ b(le, ¬_passed); |
| 1437 | // Argument passed - find it on the stack. |
| 1438 | __ ldr(r2, MemOperand(r1, (arg_number + 1) * -kPointerSize)); |
| 1439 | __ str(r2, MemOperand(r5, kPointerSize, PostIndex)); |
| 1440 | __ b(&next); |
| 1441 | __ bind(¬_passed); |
| 1442 | // Set the property to undefined. |
| 1443 | __ str(r7, MemOperand(r5, kPointerSize, PostIndex)); |
| 1444 | __ bind(&next); |
| 1445 | } else { |
| 1446 | // Set the property to the constant value. |
| 1447 | Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i)); |
| 1448 | __ mov(r2, Operand(constant)); |
| 1449 | __ str(r2, MemOperand(r5, kPointerSize, PostIndex)); |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | // Fill the unused in-object property fields with undefined. |
| 1454 | for (int i = shared->this_property_assignments_count(); |
| 1455 | i < shared->CalculateInObjectProperties(); |
| 1456 | i++) { |
| 1457 | __ str(r7, MemOperand(r5, kPointerSize, PostIndex)); |
| 1458 | } |
| 1459 | |
| 1460 | // r0: argc |
| 1461 | // r4: JSObject (not tagged) |
| 1462 | // Move argc to r1 and the JSObject to return to r0 and tag it. |
| 1463 | __ mov(r1, r0); |
| 1464 | __ mov(r0, r4); |
| 1465 | __ orr(r0, r0, Operand(kHeapObjectTag)); |
| 1466 | |
| 1467 | // r0: JSObject |
| 1468 | // r1: argc |
| 1469 | // Remove caller arguments and receiver from the stack and return. |
| 1470 | __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2)); |
| 1471 | __ add(sp, sp, Operand(kPointerSize)); |
| 1472 | __ IncrementCounter(&Counters::constructed_objects, 1, r1, r2); |
| 1473 | __ IncrementCounter(&Counters::constructed_objects_stub, 1, r1, r2); |
| 1474 | __ Jump(lr); |
| 1475 | |
| 1476 | // Jump to the generic stub in case the specialized code cannot handle the |
| 1477 | // construction. |
| 1478 | __ bind(&generic_stub_call); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1479 | Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); |
| 1480 | Handle<Code> generic_construct_stub(code); |
| 1481 | __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 1482 | |
| 1483 | // Return the generated code. |
| 1484 | return GetCode(); |
| 1485 | } |
| 1486 | |
| 1487 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1488 | #undef __ |
| 1489 | |
| 1490 | } } // namespace v8::internal |