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)); |
| 398 | __ cmp(scratch, Operand(Factory::the_hole_value())); |
| 399 | __ b(ne, miss); |
| 400 | } |
| 401 | object = JSObject::cast(object->GetPrototype()); |
| 402 | } |
| 403 | |
| 404 | // Return the register containin the holder. |
| 405 | return result; |
| 406 | } |
| 407 | |
| 408 | |
| 409 | void StubCompiler::GenerateLoadField(JSObject* object, |
| 410 | JSObject* holder, |
| 411 | Register receiver, |
| 412 | Register scratch1, |
| 413 | Register scratch2, |
| 414 | int index, |
| 415 | String* name, |
| 416 | Label* miss) { |
| 417 | // Check that the receiver isn't a smi. |
| 418 | __ tst(receiver, Operand(kSmiTagMask)); |
| 419 | __ b(eq, miss); |
| 420 | |
| 421 | // Check that the maps haven't changed. |
| 422 | Register reg = |
| 423 | CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss); |
| 424 | GenerateFastPropertyLoad(masm(), r0, reg, holder, index); |
| 425 | __ Ret(); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | void StubCompiler::GenerateLoadConstant(JSObject* object, |
| 430 | JSObject* holder, |
| 431 | Register receiver, |
| 432 | Register scratch1, |
| 433 | Register scratch2, |
| 434 | Object* value, |
| 435 | String* name, |
| 436 | Label* miss) { |
| 437 | // Check that the receiver isn't a smi. |
| 438 | __ tst(receiver, Operand(kSmiTagMask)); |
| 439 | __ b(eq, miss); |
| 440 | |
| 441 | // Check that the maps haven't changed. |
| 442 | Register reg = |
| 443 | CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss); |
| 444 | |
| 445 | // Return the constant value. |
| 446 | __ mov(r0, Operand(Handle<Object>(value))); |
| 447 | __ Ret(); |
| 448 | } |
| 449 | |
| 450 | |
| 451 | void StubCompiler::GenerateLoadCallback(JSObject* object, |
| 452 | JSObject* holder, |
| 453 | Register receiver, |
| 454 | Register name_reg, |
| 455 | Register scratch1, |
| 456 | Register scratch2, |
| 457 | AccessorInfo* callback, |
| 458 | String* name, |
| 459 | Label* miss) { |
| 460 | // Check that the receiver isn't a smi. |
| 461 | __ tst(receiver, Operand(kSmiTagMask)); |
| 462 | __ b(eq, miss); |
| 463 | |
| 464 | // Check that the maps haven't changed. |
| 465 | Register reg = |
| 466 | CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss); |
| 467 | |
| 468 | // Push the arguments on the JS stack of the caller. |
| 469 | __ push(receiver); // receiver |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 470 | __ push(reg); // holder |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 471 | __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback data |
| 472 | __ push(ip); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 473 | __ ldr(reg, FieldMemOperand(ip, AccessorInfo::kDataOffset)); |
| 474 | __ push(reg); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 475 | __ push(name_reg); // name |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 476 | |
| 477 | // Do tail-call to the runtime system. |
| 478 | ExternalReference load_callback_property = |
| 479 | ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 480 | __ TailCallRuntime(load_callback_property, 5); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | |
| 484 | void StubCompiler::GenerateLoadInterceptor(JSObject* object, |
| 485 | JSObject* holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 486 | LookupResult* lookup, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 487 | Register receiver, |
| 488 | Register name_reg, |
| 489 | Register scratch1, |
| 490 | Register scratch2, |
| 491 | String* name, |
| 492 | Label* miss) { |
| 493 | // Check that the receiver isn't a smi. |
| 494 | __ tst(receiver, Operand(kSmiTagMask)); |
| 495 | __ b(eq, miss); |
| 496 | |
| 497 | // Check that the maps haven't changed. |
| 498 | Register reg = |
| 499 | CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss); |
| 500 | |
| 501 | // Push the arguments on the JS stack of the caller. |
| 502 | __ push(receiver); // receiver |
| 503 | __ push(reg); // holder |
| 504 | __ push(name_reg); // name |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 505 | |
| 506 | InterceptorInfo* interceptor = holder->GetNamedInterceptor(); |
| 507 | ASSERT(!Heap::InNewSpace(interceptor)); |
| 508 | __ mov(scratch1, Operand(Handle<Object>(interceptor))); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 509 | __ push(scratch1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 510 | __ ldr(scratch2, FieldMemOperand(scratch1, InterceptorInfo::kDataOffset)); |
| 511 | __ push(scratch2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 512 | |
| 513 | // Do tail-call to the runtime system. |
| 514 | ExternalReference load_ic_property = |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 515 | ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); |
| 516 | __ TailCallRuntime(load_ic_property, 5); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | Object* StubCompiler::CompileLazyCompile(Code::Flags flags) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 521 | // ----------- S t a t e ------------- |
| 522 | // -- r1: function |
| 523 | // -- lr: return address |
| 524 | // ----------------------------------- |
| 525 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 526 | // Enter an internal frame. |
| 527 | __ EnterInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 528 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 529 | // Preserve the function. |
| 530 | __ push(r1); |
| 531 | |
| 532 | // Push the function on the stack as the argument to the runtime function. |
| 533 | __ push(r1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | __ CallRuntime(Runtime::kLazyCompile, 1); |
| 535 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 536 | // Calculate the entry point. |
| 537 | __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 539 | // Restore saved function. |
| 540 | __ pop(r1); |
| 541 | |
| 542 | // Tear down temporary frame. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 543 | __ LeaveInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 544 | |
| 545 | // Do a tail-call of the compiled function. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 546 | __ Jump(r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 548 | return GetCodeWithFlags(flags, "LazyCompileStub"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | |
| 552 | Object* CallStubCompiler::CompileCallField(Object* object, |
| 553 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 554 | int index, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 555 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 556 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | // -- lr: return address |
| 558 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 559 | Label miss; |
| 560 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 561 | const int argc = arguments().immediate(); |
| 562 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 563 | // Get the receiver of the function from the stack into r0. |
| 564 | __ ldr(r0, MemOperand(sp, argc * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | // Check that the receiver isn't a smi. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 566 | __ tst(r0, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 567 | __ b(eq, &miss); |
| 568 | |
| 569 | // Do the right check and compute the holder register. |
| 570 | Register reg = |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 571 | CheckPrototypes(JSObject::cast(object), r0, holder, r3, r2, name, &miss); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 572 | GenerateFastPropertyLoad(masm(), r1, reg, holder, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | |
| 574 | // Check that the function really is a function. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 575 | __ tst(r1, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 576 | __ b(eq, &miss); |
| 577 | // Get the map. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 578 | __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 579 | __ b(ne, &miss); |
| 580 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 581 | // Patch the receiver on the stack with the global proxy if |
| 582 | // necessary. |
| 583 | if (object->IsGlobalObject()) { |
| 584 | __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset)); |
| 585 | __ str(r3, MemOperand(sp, argc * kPointerSize)); |
| 586 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 587 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 588 | // Invoke the function. |
| 589 | __ InvokeFunction(r1, arguments(), JUMP_FUNCTION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | |
| 591 | // Handle call cache miss. |
| 592 | __ bind(&miss); |
| 593 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 594 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 595 | |
| 596 | // Return the generated code. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 597 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | |
| 601 | Object* CallStubCompiler::CompileCallConstant(Object* object, |
| 602 | JSObject* holder, |
| 603 | JSFunction* function, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 604 | String* name, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 605 | CheckType check) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 606 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 607 | // -- lr: return address |
| 608 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 609 | Label miss; |
| 610 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 611 | // Get the receiver from the stack |
| 612 | const int argc = arguments().immediate(); |
| 613 | __ ldr(r1, MemOperand(sp, argc * kPointerSize)); |
| 614 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 615 | // Check that the receiver isn't a smi. |
| 616 | if (check != NUMBER_CHECK) { |
| 617 | __ tst(r1, Operand(kSmiTagMask)); |
| 618 | __ b(eq, &miss); |
| 619 | } |
| 620 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 621 | // Make sure that it's okay not to patch the on stack receiver |
| 622 | // unless we're doing a receiver map check. |
| 623 | ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK); |
| 624 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 625 | switch (check) { |
| 626 | case RECEIVER_MAP_CHECK: |
| 627 | // Check that the maps haven't changed. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 628 | CheckPrototypes(JSObject::cast(object), r1, holder, r3, r2, name, &miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 629 | |
| 630 | // Patch the receiver on the stack with the global proxy if |
| 631 | // necessary. |
| 632 | if (object->IsGlobalObject()) { |
| 633 | __ ldr(r3, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 634 | __ str(r3, MemOperand(sp, argc * kPointerSize)); |
| 635 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | break; |
| 637 | |
| 638 | case STRING_CHECK: |
| 639 | // 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] | 640 | __ CompareObjectType(r1, r2, r2, FIRST_NONSTRING_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 641 | __ b(hs, &miss); |
| 642 | // Check that the maps starting from the prototype haven't changed. |
| 643 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 644 | Context::STRING_FUNCTION_INDEX, |
| 645 | r2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 646 | CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3, |
| 647 | r1, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 648 | break; |
| 649 | |
| 650 | case NUMBER_CHECK: { |
| 651 | Label fast; |
| 652 | // Check that the object is a smi or a heap number. |
| 653 | __ tst(r1, Operand(kSmiTagMask)); |
| 654 | __ b(eq, &fast); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 655 | __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 656 | __ b(ne, &miss); |
| 657 | __ bind(&fast); |
| 658 | // Check that the maps starting from the prototype haven't changed. |
| 659 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 660 | Context::NUMBER_FUNCTION_INDEX, |
| 661 | r2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 662 | CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3, |
| 663 | r1, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 664 | break; |
| 665 | } |
| 666 | |
| 667 | case BOOLEAN_CHECK: { |
| 668 | Label fast; |
| 669 | // Check that the object is a boolean. |
| 670 | __ cmp(r1, Operand(Factory::true_value())); |
| 671 | __ b(eq, &fast); |
| 672 | __ cmp(r1, Operand(Factory::false_value())); |
| 673 | __ b(ne, &miss); |
| 674 | __ bind(&fast); |
| 675 | // Check that the maps starting from the prototype haven't changed. |
| 676 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 677 | Context::BOOLEAN_FUNCTION_INDEX, |
| 678 | r2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 679 | CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3, |
| 680 | r1, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 681 | break; |
| 682 | } |
| 683 | |
| 684 | case JSARRAY_HAS_FAST_ELEMENTS_CHECK: |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 685 | CheckPrototypes(JSObject::cast(object), r1, holder, r3, r2, name, &miss); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 686 | // Make sure object->HasFastElements(). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 687 | // Get the elements array of the object. |
| 688 | __ ldr(r3, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 689 | // Check that the object is in fast mode (not dictionary). |
| 690 | __ ldr(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 691 | __ cmp(r2, Operand(Factory::fixed_array_map())); |
| 692 | __ b(ne, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 693 | break; |
| 694 | |
| 695 | default: |
| 696 | UNREACHABLE(); |
| 697 | } |
| 698 | |
| 699 | // Get the function and setup the context. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 700 | __ mov(r1, Operand(Handle<JSFunction>(function))); |
| 701 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 702 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 703 | // Jump to the cached code (tail call). |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 704 | ASSERT(function->is_compiled()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 705 | Handle<Code> code(function->code()); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 706 | ParameterCount expected(function->shared()->formal_parameter_count()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 707 | __ InvokeCode(code, expected, arguments(), |
| 708 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | |
| 710 | // Handle call cache miss. |
| 711 | __ bind(&miss); |
| 712 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 713 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 714 | |
| 715 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 716 | String* function_name = NULL; |
| 717 | if (function->shared()->name()->IsString()) { |
| 718 | function_name = String::cast(function->shared()->name()); |
| 719 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 720 | return GetCode(CONSTANT_FUNCTION, function_name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | |
| 724 | Object* CallStubCompiler::CompileCallInterceptor(Object* object, |
| 725 | JSObject* holder, |
| 726 | String* name) { |
| 727 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 728 | // -- lr: return address |
| 729 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 730 | Label miss; |
| 731 | |
| 732 | // TODO(1224669): Implement. |
| 733 | |
| 734 | // Handle call cache miss. |
| 735 | __ bind(&miss); |
| 736 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 737 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 738 | |
| 739 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 740 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 744 | Object* CallStubCompiler::CompileCallGlobal(JSObject* object, |
| 745 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 746 | JSGlobalPropertyCell* cell, |
| 747 | JSFunction* function, |
| 748 | String* name) { |
| 749 | // ----------- S t a t e ------------- |
| 750 | // -- lr: return address |
| 751 | // ----------------------------------- |
| 752 | Label miss; |
| 753 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 754 | // Get the number of arguments. |
| 755 | const int argc = arguments().immediate(); |
| 756 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 757 | // Get the receiver from the stack. |
| 758 | __ ldr(r0, MemOperand(sp, argc * kPointerSize)); |
| 759 | |
| 760 | // If the object is the holder then we know that it's a global |
| 761 | // object which can only happen for contextual calls. In this case, |
| 762 | // the receiver cannot be a smi. |
| 763 | if (object != holder) { |
| 764 | __ tst(r0, Operand(kSmiTagMask)); |
| 765 | __ b(eq, &miss); |
| 766 | } |
| 767 | |
| 768 | // Check that the maps haven't changed. |
| 769 | CheckPrototypes(object, r0, holder, r3, r2, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 770 | |
| 771 | // Get the value from the cell. |
| 772 | __ mov(r3, Operand(Handle<JSGlobalPropertyCell>(cell))); |
| 773 | __ ldr(r1, FieldMemOperand(r3, JSGlobalPropertyCell::kValueOffset)); |
| 774 | |
| 775 | // Check that the cell contains the same function. |
| 776 | __ cmp(r1, Operand(Handle<JSFunction>(function))); |
| 777 | __ b(ne, &miss); |
| 778 | |
| 779 | // Patch the receiver on the stack with the global proxy if |
| 780 | // necessary. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 781 | if (object->IsGlobalObject()) { |
| 782 | __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset)); |
| 783 | __ str(r3, MemOperand(sp, argc * kPointerSize)); |
| 784 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 785 | |
| 786 | // Setup the context (function already in r1). |
| 787 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 788 | |
| 789 | // Jump to the cached code (tail call). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 790 | __ IncrementCounter(&Counters::call_global_inline, 1, r1, r3); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 791 | ASSERT(function->is_compiled()); |
| 792 | Handle<Code> code(function->code()); |
| 793 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 794 | __ InvokeCode(code, expected, arguments(), |
| 795 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
| 796 | |
| 797 | // Handle call cache miss. |
| 798 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 799 | __ IncrementCounter(&Counters::call_global_inline_miss, 1, r1, r3); |
| 800 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
| 801 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 802 | |
| 803 | // Return the generated code. |
| 804 | return GetCode(NORMAL, name); |
| 805 | } |
| 806 | |
| 807 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 808 | Object* StoreStubCompiler::CompileStoreField(JSObject* object, |
| 809 | int index, |
| 810 | Map* transition, |
| 811 | String* name) { |
| 812 | // ----------- S t a t e ------------- |
| 813 | // -- r0 : value |
| 814 | // -- r2 : name |
| 815 | // -- lr : return address |
| 816 | // -- [sp] : receiver |
| 817 | // ----------------------------------- |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 818 | Label miss; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 819 | |
| 820 | // Get the receiver from the stack. |
| 821 | __ ldr(r3, MemOperand(sp, 0 * kPointerSize)); |
| 822 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 823 | // name register might be clobbered. |
| 824 | GenerateStoreField(masm(), |
| 825 | Builtins::StoreIC_ExtendStorage, |
| 826 | object, |
| 827 | index, |
| 828 | transition, |
| 829 | r3, r2, r1, |
| 830 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 831 | __ bind(&miss); |
| 832 | __ mov(r2, Operand(Handle<String>(name))); // restore name |
| 833 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 834 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 835 | |
| 836 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 837 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | |
| 841 | Object* StoreStubCompiler::CompileStoreCallback(JSObject* object, |
| 842 | AccessorInfo* callback, |
| 843 | String* name) { |
| 844 | // ----------- S t a t e ------------- |
| 845 | // -- r0 : value |
| 846 | // -- r2 : name |
| 847 | // -- lr : return address |
| 848 | // -- [sp] : receiver |
| 849 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 850 | Label miss; |
| 851 | |
| 852 | // Get the object from the stack. |
| 853 | __ ldr(r3, MemOperand(sp, 0 * kPointerSize)); |
| 854 | |
| 855 | // Check that the object isn't a smi. |
| 856 | __ tst(r3, Operand(kSmiTagMask)); |
| 857 | __ b(eq, &miss); |
| 858 | |
| 859 | // Check that the map of the object hasn't changed. |
| 860 | __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 861 | __ cmp(r1, Operand(Handle<Map>(object->map()))); |
| 862 | __ b(ne, &miss); |
| 863 | |
| 864 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 865 | if (object->IsJSGlobalProxy()) { |
| 866 | __ CheckAccessGlobalProxy(r3, r1, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | // Stub never generated for non-global objects that require access |
| 870 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 871 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | |
| 873 | __ ldr(ip, MemOperand(sp)); // receiver |
| 874 | __ push(ip); |
| 875 | __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback info |
| 876 | __ push(ip); |
| 877 | __ push(r2); // name |
| 878 | __ push(r0); // value |
| 879 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 880 | // Do tail-call to the runtime system. |
| 881 | ExternalReference store_callback_property = |
| 882 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty)); |
| 883 | __ TailCallRuntime(store_callback_property, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | |
| 885 | // Handle store cache miss. |
| 886 | __ bind(&miss); |
| 887 | __ mov(r2, Operand(Handle<String>(name))); // restore name |
| 888 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 889 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 890 | |
| 891 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 892 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | |
| 896 | Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver, |
| 897 | String* name) { |
| 898 | // ----------- S t a t e ------------- |
| 899 | // -- r0 : value |
| 900 | // -- r2 : name |
| 901 | // -- lr : return address |
| 902 | // -- [sp] : receiver |
| 903 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 904 | Label miss; |
| 905 | |
| 906 | // Get the object from the stack. |
| 907 | __ ldr(r3, MemOperand(sp, 0 * kPointerSize)); |
| 908 | |
| 909 | // Check that the object isn't a smi. |
| 910 | __ tst(r3, Operand(kSmiTagMask)); |
| 911 | __ b(eq, &miss); |
| 912 | |
| 913 | // Check that the map of the object hasn't changed. |
| 914 | __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 915 | __ cmp(r1, Operand(Handle<Map>(receiver->map()))); |
| 916 | __ b(ne, &miss); |
| 917 | |
| 918 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 919 | if (receiver->IsJSGlobalProxy()) { |
| 920 | __ CheckAccessGlobalProxy(r3, r1, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | // Stub never generated for non-global objects that require access |
| 924 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 925 | ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 926 | |
| 927 | __ ldr(ip, MemOperand(sp)); // receiver |
| 928 | __ push(ip); |
| 929 | __ push(r2); // name |
| 930 | __ push(r0); // value |
| 931 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 932 | // Do tail-call to the runtime system. |
| 933 | ExternalReference store_ic_property = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 934 | ExternalReference(IC_Utility(IC::kStoreInterceptorProperty)); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 935 | __ TailCallRuntime(store_ic_property, 3); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | |
| 937 | // Handle store cache miss. |
| 938 | __ bind(&miss); |
| 939 | __ mov(r2, Operand(Handle<String>(name))); // restore name |
| 940 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 941 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 942 | |
| 943 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 944 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 948 | Object* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object, |
| 949 | JSGlobalPropertyCell* cell, |
| 950 | String* name) { |
| 951 | // ----------- S t a t e ------------- |
| 952 | // -- r0 : value |
| 953 | // -- r2 : name |
| 954 | // -- lr : return address |
| 955 | // -- [sp] : receiver |
| 956 | // ----------------------------------- |
| 957 | Label miss; |
| 958 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 959 | // Check that the map of the global has not changed. |
| 960 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| 961 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 962 | __ cmp(r3, Operand(Handle<Map>(object->map()))); |
| 963 | __ b(ne, &miss); |
| 964 | |
| 965 | // Store the value in the cell. |
| 966 | __ mov(r2, Operand(Handle<JSGlobalPropertyCell>(cell))); |
| 967 | __ str(r0, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 968 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 969 | __ IncrementCounter(&Counters::named_store_global_inline, 1, r1, r3); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 970 | __ Ret(); |
| 971 | |
| 972 | // Handle store cache miss. |
| 973 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 974 | __ IncrementCounter(&Counters::named_store_global_inline_miss, 1, r1, r3); |
| 975 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
| 976 | __ Jump(ic, RelocInfo::CODE_TARGET); |
| 977 | |
| 978 | // Return the generated code. |
| 979 | return GetCode(NORMAL, name); |
| 980 | } |
| 981 | |
| 982 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 983 | Object* LoadStubCompiler::CompileLoadField(JSObject* object, |
| 984 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 985 | int index, |
| 986 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 987 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 988 | // -- r2 : name |
| 989 | // -- lr : return address |
| 990 | // -- [sp] : receiver |
| 991 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 992 | Label miss; |
| 993 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 994 | __ ldr(r0, MemOperand(sp, 0)); |
| 995 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 996 | GenerateLoadField(object, holder, r0, r3, r1, index, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 997 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 998 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 999 | |
| 1000 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1001 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | Object* LoadStubCompiler::CompileLoadCallback(JSObject* object, |
| 1006 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1007 | AccessorInfo* callback, |
| 1008 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1009 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1010 | // -- r2 : name |
| 1011 | // -- lr : return address |
| 1012 | // -- [sp] : receiver |
| 1013 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1014 | Label miss; |
| 1015 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1016 | __ ldr(r0, MemOperand(sp, 0)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1017 | GenerateLoadCallback(object, holder, r0, r2, r3, r1, callback, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1018 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1019 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1020 | |
| 1021 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1022 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | |
| 1026 | Object* LoadStubCompiler::CompileLoadConstant(JSObject* object, |
| 1027 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1028 | Object* value, |
| 1029 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1030 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1031 | // -- r2 : name |
| 1032 | // -- lr : return address |
| 1033 | // -- [sp] : receiver |
| 1034 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1035 | Label miss; |
| 1036 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1037 | __ ldr(r0, MemOperand(sp, 0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1038 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1039 | GenerateLoadConstant(object, holder, r0, r3, r1, value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1040 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1041 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1042 | |
| 1043 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1044 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* object, |
| 1049 | JSObject* holder, |
| 1050 | String* name) { |
| 1051 | // ----------- S t a t e ------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1052 | // -- r2 : name |
| 1053 | // -- lr : return address |
| 1054 | // -- [sp] : receiver |
| 1055 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | Label miss; |
| 1057 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1058 | __ ldr(r0, MemOperand(sp, 0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1059 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1060 | LookupResult lookup; |
| 1061 | holder->LocalLookupRealNamedProperty(name, &lookup); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1062 | GenerateLoadInterceptor(object, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1063 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1064 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1065 | r0, |
| 1066 | r2, |
| 1067 | r3, |
| 1068 | r1, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1069 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1070 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1071 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1072 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1073 | |
| 1074 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1075 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1079 | Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object, |
| 1080 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1081 | JSGlobalPropertyCell* cell, |
| 1082 | String* name, |
| 1083 | bool is_dont_delete) { |
| 1084 | // ----------- S t a t e ------------- |
| 1085 | // -- r2 : name |
| 1086 | // -- lr : return address |
| 1087 | // -- [sp] : receiver |
| 1088 | // ----------------------------------- |
| 1089 | Label miss; |
| 1090 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1091 | // Get the receiver from the stack. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1092 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1093 | |
| 1094 | // If the object is the holder then we know that it's a global |
| 1095 | // object which can only happen for contextual calls. In this case, |
| 1096 | // the receiver cannot be a smi. |
| 1097 | if (object != holder) { |
| 1098 | __ tst(r1, Operand(kSmiTagMask)); |
| 1099 | __ b(eq, &miss); |
| 1100 | } |
| 1101 | |
| 1102 | // Check that the map of the global has not changed. |
| 1103 | CheckPrototypes(object, r1, holder, r3, r0, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1104 | |
| 1105 | // Get the value from the cell. |
| 1106 | __ mov(r3, Operand(Handle<JSGlobalPropertyCell>(cell))); |
| 1107 | __ ldr(r0, FieldMemOperand(r3, JSGlobalPropertyCell::kValueOffset)); |
| 1108 | |
| 1109 | // Check for deleted property if property can actually be deleted. |
| 1110 | if (!is_dont_delete) { |
| 1111 | __ cmp(r0, Operand(Factory::the_hole_value())); |
| 1112 | __ b(eq, &miss); |
| 1113 | } |
| 1114 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1115 | __ IncrementCounter(&Counters::named_load_global_inline, 1, r1, r3); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1116 | __ Ret(); |
| 1117 | |
| 1118 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1119 | __ IncrementCounter(&Counters::named_load_global_inline_miss, 1, r1, r3); |
| 1120 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1121 | |
| 1122 | // Return the generated code. |
| 1123 | return GetCode(NORMAL, name); |
| 1124 | } |
| 1125 | |
| 1126 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1127 | Object* KeyedLoadStubCompiler::CompileLoadField(String* name, |
| 1128 | JSObject* receiver, |
| 1129 | JSObject* holder, |
| 1130 | int index) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1131 | // ----------- S t a t e ------------- |
| 1132 | // -- lr : return address |
| 1133 | // -- sp[0] : key |
| 1134 | // -- sp[4] : receiver |
| 1135 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1136 | Label miss; |
| 1137 | |
| 1138 | __ ldr(r2, MemOperand(sp, 0)); |
| 1139 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1140 | |
| 1141 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1142 | __ b(ne, &miss); |
| 1143 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1144 | GenerateLoadField(receiver, holder, r0, r3, r1, index, name, &miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1145 | __ bind(&miss); |
| 1146 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1147 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1148 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name, |
| 1153 | JSObject* receiver, |
| 1154 | JSObject* holder, |
| 1155 | AccessorInfo* callback) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1156 | // ----------- S t a t e ------------- |
| 1157 | // -- lr : return address |
| 1158 | // -- sp[0] : key |
| 1159 | // -- sp[4] : receiver |
| 1160 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1161 | Label miss; |
| 1162 | |
| 1163 | __ ldr(r2, MemOperand(sp, 0)); |
| 1164 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1165 | |
| 1166 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1167 | __ b(ne, &miss); |
| 1168 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1169 | GenerateLoadCallback(receiver, holder, r0, r2, r3, r1, callback, name, &miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1170 | __ bind(&miss); |
| 1171 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1172 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1173 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name, |
| 1178 | JSObject* receiver, |
| 1179 | JSObject* holder, |
| 1180 | Object* value) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1181 | // ----------- S t a t e ------------- |
| 1182 | // -- lr : return address |
| 1183 | // -- sp[0] : key |
| 1184 | // -- sp[4] : receiver |
| 1185 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1186 | Label miss; |
| 1187 | |
| 1188 | // Check the key is the cached one |
| 1189 | __ ldr(r2, MemOperand(sp, 0)); |
| 1190 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1191 | |
| 1192 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1193 | __ b(ne, &miss); |
| 1194 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1195 | GenerateLoadConstant(receiver, holder, r0, r3, r1, value, name, &miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1196 | __ bind(&miss); |
| 1197 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1198 | |
| 1199 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1200 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | |
| 1204 | Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 1205 | JSObject* holder, |
| 1206 | String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1207 | // ----------- S t a t e ------------- |
| 1208 | // -- lr : return address |
| 1209 | // -- sp[0] : key |
| 1210 | // -- sp[4] : receiver |
| 1211 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1212 | Label miss; |
| 1213 | |
| 1214 | // Check the key is the cached one |
| 1215 | __ ldr(r2, MemOperand(sp, 0)); |
| 1216 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1217 | |
| 1218 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1219 | __ b(ne, &miss); |
| 1220 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1221 | LookupResult lookup; |
| 1222 | holder->LocalLookupRealNamedProperty(name, &lookup); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1223 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1224 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1225 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1226 | r0, |
| 1227 | r2, |
| 1228 | r3, |
| 1229 | r1, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1230 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1231 | &miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1232 | __ bind(&miss); |
| 1233 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1234 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1235 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | |
| 1239 | Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1240 | // ----------- S t a t e ------------- |
| 1241 | // -- lr : return address |
| 1242 | // -- sp[0] : key |
| 1243 | // -- sp[4] : receiver |
| 1244 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1245 | Label miss; |
| 1246 | |
| 1247 | // Check the key is the cached one |
| 1248 | __ ldr(r2, MemOperand(sp, 0)); |
| 1249 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1250 | |
| 1251 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1252 | __ b(ne, &miss); |
| 1253 | |
| 1254 | GenerateLoadArrayLength(masm(), r0, r3, &miss); |
| 1255 | __ bind(&miss); |
| 1256 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1257 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1258 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1262 | Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1263 | // ----------- S t a t e ------------- |
| 1264 | // -- lr : return address |
| 1265 | // -- sp[0] : key |
| 1266 | // -- sp[4] : receiver |
| 1267 | // ----------------------------------- |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1268 | Label miss; |
| 1269 | __ IncrementCounter(&Counters::keyed_load_string_length, 1, r1, r3); |
| 1270 | |
| 1271 | __ ldr(r2, MemOperand(sp)); |
| 1272 | __ ldr(r0, MemOperand(sp, kPointerSize)); // receiver |
| 1273 | |
| 1274 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1275 | __ b(ne, &miss); |
| 1276 | |
| 1277 | GenerateLoadStringLength2(masm(), r0, r1, r3, &miss); |
| 1278 | __ bind(&miss); |
| 1279 | __ DecrementCounter(&Counters::keyed_load_string_length, 1, r1, r3); |
| 1280 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1281 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1282 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1283 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1287 | // TODO(1224671): implement the fast case. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1288 | Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1289 | // ----------- S t a t e ------------- |
| 1290 | // -- lr : return address |
| 1291 | // -- sp[0] : key |
| 1292 | // -- sp[4] : receiver |
| 1293 | // ----------------------------------- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1294 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1295 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1296 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | |
| 1300 | Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object, |
| 1301 | int index, |
| 1302 | Map* transition, |
| 1303 | String* name) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1304 | // ----------- S t a t e ------------- |
| 1305 | // -- r0 : value |
| 1306 | // -- r2 : name |
| 1307 | // -- lr : return address |
| 1308 | // -- [sp] : receiver |
| 1309 | // ----------------------------------- |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1310 | Label miss; |
| 1311 | |
| 1312 | __ IncrementCounter(&Counters::keyed_store_field, 1, r1, r3); |
| 1313 | |
| 1314 | // Check that the name has not changed. |
| 1315 | __ cmp(r2, Operand(Handle<String>(name))); |
| 1316 | __ b(ne, &miss); |
| 1317 | |
| 1318 | // Load receiver from the stack. |
| 1319 | __ ldr(r3, MemOperand(sp)); |
| 1320 | // r1 is used as scratch register, r3 and r2 might be clobbered. |
| 1321 | GenerateStoreField(masm(), |
| 1322 | Builtins::StoreIC_ExtendStorage, |
| 1323 | object, |
| 1324 | index, |
| 1325 | transition, |
| 1326 | r3, r2, r1, |
| 1327 | &miss); |
| 1328 | __ bind(&miss); |
| 1329 | |
| 1330 | __ DecrementCounter(&Counters::keyed_store_field, 1, r1, r3); |
| 1331 | __ mov(r2, Operand(Handle<String>(name))); // restore name register. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1332 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss)); |
| 1333 | __ Jump(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1334 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1335 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1336 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1337 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1338 | |
| 1339 | |
| 1340 | #undef __ |
| 1341 | |
| 1342 | } } // namespace v8::internal |