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 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "ic-inl.h" |
| 33 | #include "codegen-inl.h" |
| 34 | #include "stub-cache.h" |
| 35 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 36 | namespace v8 { |
| 37 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 39 | #define __ ACCESS_MASM(masm) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | static void ProbeTable(MacroAssembler* masm, |
| 43 | Code::Flags flags, |
| 44 | StubCache::Table table, |
| 45 | Register name, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 46 | Register offset, |
| 47 | Register extra) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | ExternalReference key_offset(SCTableReference::keyReference(table)); |
| 49 | ExternalReference value_offset(SCTableReference::valueReference(table)); |
| 50 | |
| 51 | Label miss; |
| 52 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 53 | if (extra.is_valid()) { |
| 54 | // Get the code entry from the cache. |
| 55 | __ mov(extra, Operand::StaticArray(offset, times_2, value_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 57 | // Check that the key in the entry matches the name. |
| 58 | __ cmp(name, Operand::StaticArray(offset, times_2, key_offset)); |
| 59 | __ j(not_equal, &miss, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 61 | // Check that the flags match what we're looking for. |
| 62 | __ mov(offset, FieldOperand(extra, Code::kFlagsOffset)); |
| 63 | __ and_(offset, ~Code::kFlagsNotUsedInLookup); |
| 64 | __ cmp(offset, flags); |
| 65 | __ j(not_equal, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 67 | // Jump to the first instruction in the code stub. |
| 68 | __ add(Operand(extra), Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 69 | __ jmp(Operand(extra)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 71 | __ bind(&miss); |
| 72 | } else { |
| 73 | // Save the offset on the stack. |
| 74 | __ push(offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 75 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 76 | // Check that the key in the entry matches the name. |
| 77 | __ cmp(name, Operand::StaticArray(offset, times_2, key_offset)); |
| 78 | __ j(not_equal, &miss, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 79 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 80 | // Get the code entry from the cache. |
| 81 | __ mov(offset, Operand::StaticArray(offset, times_2, value_offset)); |
| 82 | |
| 83 | // Check that the flags match what we're looking for. |
| 84 | __ mov(offset, FieldOperand(offset, Code::kFlagsOffset)); |
| 85 | __ and_(offset, ~Code::kFlagsNotUsedInLookup); |
| 86 | __ cmp(offset, flags); |
| 87 | __ j(not_equal, &miss); |
| 88 | |
| 89 | // Restore offset and re-load code entry from cache. |
| 90 | __ pop(offset); |
| 91 | __ mov(offset, Operand::StaticArray(offset, times_2, value_offset)); |
| 92 | |
| 93 | // Jump to the first instruction in the code stub. |
| 94 | __ add(Operand(offset), Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 95 | __ jmp(Operand(offset)); |
| 96 | |
| 97 | // Pop at miss. |
| 98 | __ bind(&miss); |
| 99 | __ pop(offset); |
| 100 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 104 | // Helper function used to check that the dictionary doesn't contain |
| 105 | // the property. This function may return false negatives, so miss_label |
| 106 | // must always call a backup property check that is complete. |
| 107 | // This function is safe to call if the receiver has fast properties. |
| 108 | // Name must be a symbol and receiver must be a heap object. |
| 109 | static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, |
| 110 | Label* miss_label, |
| 111 | Register receiver, |
| 112 | String* name, |
| 113 | Register r0, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 114 | Register r1) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 115 | ASSERT(name->IsSymbol()); |
| 116 | __ IncrementCounter(&Counters::negative_lookups, 1); |
| 117 | __ IncrementCounter(&Counters::negative_lookups_miss, 1); |
| 118 | |
| 119 | Label done; |
| 120 | __ mov(r0, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 121 | |
| 122 | const int kInterceptorOrAccessCheckNeededMask = |
| 123 | (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 124 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 125 | // Bail out if the receiver has a named interceptor or requires access checks. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 126 | __ test_b(FieldOperand(r0, Map::kBitFieldOffset), |
| 127 | kInterceptorOrAccessCheckNeededMask); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 128 | __ j(not_zero, miss_label, not_taken); |
| 129 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 130 | // Check that receiver is a JSObject. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 131 | __ CmpInstanceType(r0, FIRST_JS_OBJECT_TYPE); |
| 132 | __ j(below, miss_label, not_taken); |
| 133 | |
| 134 | // Load properties array. |
| 135 | Register properties = r0; |
| 136 | __ mov(properties, FieldOperand(receiver, JSObject::kPropertiesOffset)); |
| 137 | |
| 138 | // Check that the properties array is a dictionary. |
| 139 | __ cmp(FieldOperand(properties, HeapObject::kMapOffset), |
| 140 | Immediate(Factory::hash_table_map())); |
| 141 | __ j(not_equal, miss_label); |
| 142 | |
| 143 | // Compute the capacity mask. |
| 144 | const int kCapacityOffset = |
| 145 | StringDictionary::kHeaderSize + |
| 146 | StringDictionary::kCapacityIndex * kPointerSize; |
| 147 | |
| 148 | // Generate an unrolled loop that performs a few probes before |
| 149 | // giving up. |
| 150 | static const int kProbes = 4; |
| 151 | const int kElementsStartOffset = |
| 152 | StringDictionary::kHeaderSize + |
| 153 | StringDictionary::kElementsStartIndex * kPointerSize; |
| 154 | |
| 155 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 156 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 157 | // undefined value), it guarantees the hash table doesn't contain the |
| 158 | // property. It's true even if some slots represent deleted properties |
| 159 | // (their names are the null value). |
| 160 | for (int i = 0; i < kProbes; i++) { |
| 161 | // r0 points to properties hash. |
| 162 | // Compute the masked index: (hash + i + i * i) & mask. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 163 | Register index = r1; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 164 | // Capacity is smi 2^n. |
| 165 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 166 | __ dec(index); |
| 167 | __ and_(Operand(index), |
| 168 | Immediate(Smi::FromInt(name->Hash() + |
| 169 | StringDictionary::GetProbeOffset(i)))); |
| 170 | |
| 171 | // Scale the index by multiplying by the entry size. |
| 172 | ASSERT(StringDictionary::kEntrySize == 3); |
| 173 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 174 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 175 | Register entity_name = r1; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 176 | // Having undefined at this place means the name is not contained. |
| 177 | ASSERT_EQ(kSmiTagSize, 1); |
| 178 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 179 | kElementsStartOffset - kHeapObjectTag)); |
| 180 | __ cmp(entity_name, Factory::undefined_value()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 181 | if (i != kProbes - 1) { |
| 182 | __ j(equal, &done, taken); |
| 183 | |
| 184 | // Stop if found the property. |
| 185 | __ cmp(entity_name, Handle<String>(name)); |
| 186 | __ j(equal, miss_label, not_taken); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 187 | |
| 188 | // Check if the entry name is not a symbol. |
| 189 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 190 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 191 | kIsSymbolMask); |
| 192 | __ j(zero, miss_label, not_taken); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 193 | } else { |
| 194 | // Give up probing if still not found the undefined value. |
| 195 | __ j(not_equal, miss_label, not_taken); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | __ bind(&done); |
| 200 | __ DecrementCounter(&Counters::negative_lookups_miss, 1); |
| 201 | } |
| 202 | |
| 203 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | void StubCache::GenerateProbe(MacroAssembler* masm, |
| 205 | Code::Flags flags, |
| 206 | Register receiver, |
| 207 | Register name, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 208 | Register scratch, |
| 209 | Register extra) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 210 | Label miss; |
| 211 | |
| 212 | // Make sure that code is valid. The shifting code relies on the |
| 213 | // entry size being 8. |
| 214 | ASSERT(sizeof(Entry) == 8); |
| 215 | |
| 216 | // Make sure the flags does not name a specific type. |
| 217 | ASSERT(Code::ExtractTypeFromFlags(flags) == 0); |
| 218 | |
| 219 | // Make sure that there are no register conflicts. |
| 220 | ASSERT(!scratch.is(receiver)); |
| 221 | ASSERT(!scratch.is(name)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 222 | ASSERT(!extra.is(receiver)); |
| 223 | ASSERT(!extra.is(name)); |
| 224 | ASSERT(!extra.is(scratch)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | |
| 226 | // Check that the receiver isn't a smi. |
| 227 | __ test(receiver, Immediate(kSmiTagMask)); |
| 228 | __ j(zero, &miss, not_taken); |
| 229 | |
| 230 | // Get the map of the receiver and compute the hash. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 231 | __ mov(scratch, FieldOperand(name, String::kHashFieldOffset)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 232 | __ add(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | __ xor_(scratch, flags); |
| 234 | __ and_(scratch, (kPrimaryTableSize - 1) << kHeapObjectTagSize); |
| 235 | |
| 236 | // Probe the primary table. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 237 | ProbeTable(masm, flags, kPrimary, name, scratch, extra); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 238 | |
| 239 | // Primary miss: Compute hash for secondary probe. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 240 | __ mov(scratch, FieldOperand(name, String::kHashFieldOffset)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 241 | __ add(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 242 | __ xor_(scratch, flags); |
| 243 | __ and_(scratch, (kPrimaryTableSize - 1) << kHeapObjectTagSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | __ sub(scratch, Operand(name)); |
| 245 | __ add(Operand(scratch), Immediate(flags)); |
| 246 | __ and_(scratch, (kSecondaryTableSize - 1) << kHeapObjectTagSize); |
| 247 | |
| 248 | // Probe the secondary table. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 249 | ProbeTable(masm, flags, kSecondary, name, scratch, extra); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | |
| 251 | // Cache miss: Fall-through and let caller handle the miss by |
| 252 | // entering the runtime system. |
| 253 | __ bind(&miss); |
| 254 | } |
| 255 | |
| 256 | |
| 257 | void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, |
| 258 | int index, |
| 259 | Register prototype) { |
| 260 | // Load the global or builtins object from the current context. |
| 261 | __ mov(prototype, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 262 | // Load the global context from the global or builtins object. |
| 263 | __ mov(prototype, |
| 264 | FieldOperand(prototype, GlobalObject::kGlobalContextOffset)); |
| 265 | // Load the function from the global context. |
| 266 | __ mov(prototype, Operand(prototype, Context::SlotOffset(index))); |
| 267 | // Load the initial map. The global functions all have initial maps. |
| 268 | __ mov(prototype, |
| 269 | FieldOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset)); |
| 270 | // Load the prototype from the initial map. |
| 271 | __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset)); |
| 272 | } |
| 273 | |
| 274 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 275 | void StubCompiler::GenerateDirectLoadGlobalFunctionPrototype( |
| 276 | MacroAssembler* masm, int index, Register prototype) { |
| 277 | // Get the global function with the given index. |
| 278 | JSFunction* function = JSFunction::cast(Top::global_context()->get(index)); |
| 279 | // Load its initial map. The global functions all have initial maps. |
| 280 | __ Set(prototype, Immediate(Handle<Map>(function->initial_map()))); |
| 281 | // Load the prototype from the initial map. |
| 282 | __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset)); |
| 283 | } |
| 284 | |
| 285 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm, |
| 287 | Register receiver, |
| 288 | Register scratch, |
| 289 | Label* miss_label) { |
| 290 | // Check that the receiver isn't a smi. |
| 291 | __ test(receiver, Immediate(kSmiTagMask)); |
| 292 | __ j(zero, miss_label, not_taken); |
| 293 | |
| 294 | // Check that the object is a JS array. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 295 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 296 | __ j(not_equal, miss_label, not_taken); |
| 297 | |
| 298 | // Load length directly from the JS array. |
| 299 | __ mov(eax, FieldOperand(receiver, JSArray::kLengthOffset)); |
| 300 | __ ret(0); |
| 301 | } |
| 302 | |
| 303 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 304 | // Generate code to check if an object is a string. If the object is |
| 305 | // a string, the map's instance type is left in the scratch register. |
| 306 | static void GenerateStringCheck(MacroAssembler* masm, |
| 307 | Register receiver, |
| 308 | Register scratch, |
| 309 | Label* smi, |
| 310 | Label* non_string_object) { |
| 311 | // Check that the object isn't a smi. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 312 | __ test(receiver, Immediate(kSmiTagMask)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 313 | __ j(zero, smi, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 315 | // Check that the object is a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | __ mov(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 317 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 318 | ASSERT(kNotStringTag != 0); |
| 319 | __ test(scratch, Immediate(kNotStringTag)); |
| 320 | __ j(not_zero, non_string_object, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 324 | void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm, |
| 325 | Register receiver, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 326 | Register scratch1, |
| 327 | Register scratch2, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 328 | Label* miss) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 329 | Label check_wrapper; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 331 | // Check if the object is a string leaving the instance type in the |
| 332 | // scratch register. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 333 | GenerateStringCheck(masm, receiver, scratch1, miss, &check_wrapper); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 334 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 335 | // Load length from the string and convert to a smi. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 336 | __ mov(eax, FieldOperand(receiver, String::kLengthOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | __ ret(0); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 338 | |
| 339 | // Check if the object is a JSValue wrapper. |
| 340 | __ bind(&check_wrapper); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 341 | __ cmp(scratch1, JS_VALUE_TYPE); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 342 | __ j(not_equal, miss, not_taken); |
| 343 | |
| 344 | // Check if the wrapped value is a string and load the length |
| 345 | // directly if it is. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 346 | __ mov(scratch2, FieldOperand(receiver, JSValue::kValueOffset)); |
| 347 | GenerateStringCheck(masm, scratch2, scratch1, miss, miss); |
| 348 | __ mov(eax, FieldOperand(scratch2, String::kLengthOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 349 | __ ret(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | |
| 353 | void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm, |
| 354 | Register receiver, |
| 355 | Register scratch1, |
| 356 | Register scratch2, |
| 357 | Label* miss_label) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 358 | __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 359 | __ mov(eax, Operand(scratch1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | __ ret(0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 361 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 362 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 363 | |
| 364 | // Load a fast property out of a holder object (src). In-object properties |
| 365 | // are loaded directly otherwise the property is loaded from the properties |
| 366 | // fixed array. |
| 367 | void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 368 | Register dst, Register src, |
| 369 | JSObject* holder, int index) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 370 | // Adjust for the number of properties stored in the holder. |
| 371 | index -= holder->map()->inobject_properties(); |
| 372 | if (index < 0) { |
| 373 | // Get the property straight out of the holder. |
| 374 | int offset = holder->map()->instance_size() + (index * kPointerSize); |
| 375 | __ mov(dst, FieldOperand(src, offset)); |
| 376 | } else { |
| 377 | // Calculate the offset into the properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 378 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 379 | __ mov(dst, FieldOperand(src, JSObject::kPropertiesOffset)); |
| 380 | __ mov(dst, FieldOperand(dst, offset)); |
| 381 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 385 | static void PushInterceptorArguments(MacroAssembler* masm, |
| 386 | Register receiver, |
| 387 | Register holder, |
| 388 | Register name, |
| 389 | JSObject* holder_obj) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 390 | __ push(name); |
| 391 | InterceptorInfo* interceptor = holder_obj->GetNamedInterceptor(); |
| 392 | ASSERT(!Heap::InNewSpace(interceptor)); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 393 | Register scratch = name; |
| 394 | __ mov(scratch, Immediate(Handle<Object>(interceptor))); |
| 395 | __ push(scratch); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 396 | __ push(receiver); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 397 | __ push(holder); |
| 398 | __ push(FieldOperand(scratch, InterceptorInfo::kDataOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 402 | static void CompileCallLoadPropertyWithInterceptor(MacroAssembler* masm, |
| 403 | Register receiver, |
| 404 | Register holder, |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 405 | Register name, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 406 | JSObject* holder_obj) { |
| 407 | PushInterceptorArguments(masm, receiver, holder, name, holder_obj); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 408 | __ CallExternalReference( |
| 409 | ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly)), |
| 410 | 5); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 414 | // Reserves space for the extra arguments to FastHandleApiCall in the |
| 415 | // caller's frame. |
| 416 | // |
| 417 | // These arguments are set by CheckPrototypes and GenerateFastApiCall. |
| 418 | static void ReserveSpaceForFastApiCall(MacroAssembler* masm, Register scratch) { |
| 419 | // ----------- S t a t e ------------- |
| 420 | // -- esp[0] : return address |
| 421 | // -- esp[4] : last argument in the internal frame of the caller |
| 422 | // ----------------------------------- |
| 423 | __ pop(scratch); |
| 424 | __ push(Immediate(Smi::FromInt(0))); |
| 425 | __ push(Immediate(Smi::FromInt(0))); |
| 426 | __ push(Immediate(Smi::FromInt(0))); |
| 427 | __ push(Immediate(Smi::FromInt(0))); |
| 428 | __ push(scratch); |
| 429 | } |
| 430 | |
| 431 | |
| 432 | // Undoes the effects of ReserveSpaceForFastApiCall. |
| 433 | static void FreeSpaceForFastApiCall(MacroAssembler* masm, Register scratch) { |
| 434 | // ----------- S t a t e ------------- |
| 435 | // -- esp[0] : return address |
| 436 | // -- esp[4] : last fast api call extra argument |
| 437 | // -- ... |
| 438 | // -- esp[16] : first fast api call extra argument |
| 439 | // -- esp[20] : last argument in the internal frame |
| 440 | // ----------------------------------- |
| 441 | __ pop(scratch); |
| 442 | __ add(Operand(esp), Immediate(kPointerSize * 4)); |
| 443 | __ push(scratch); |
| 444 | } |
| 445 | |
| 446 | |
| 447 | // Generates call to FastHandleApiCall builtin. |
| 448 | static void GenerateFastApiCall(MacroAssembler* masm, |
| 449 | const CallOptimization& optimization, |
| 450 | int argc) { |
| 451 | // ----------- S t a t e ------------- |
| 452 | // -- esp[0] : return address |
| 453 | // -- esp[4] : object passing the type check |
| 454 | // (last fast api call extra argument, |
| 455 | // set by CheckPrototypes) |
| 456 | // -- esp[8] : api call data |
| 457 | // -- esp[12] : api callback |
| 458 | // -- esp[16] : api function |
| 459 | // (first fast api call extra argument) |
| 460 | // -- esp[20] : last argument |
| 461 | // -- ... |
| 462 | // -- esp[(argc + 5) * 4] : first argument |
| 463 | // -- esp[(argc + 6) * 4] : receiver |
| 464 | // ----------------------------------- |
| 465 | |
| 466 | // Get the function and setup the context. |
| 467 | JSFunction* function = optimization.constant_function(); |
| 468 | __ mov(edi, Immediate(Handle<JSFunction>(function))); |
| 469 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 470 | |
| 471 | // Pass the additional arguments FastHandleApiCall expects. |
| 472 | __ mov(Operand(esp, 4 * kPointerSize), edi); |
| 473 | bool info_loaded = false; |
| 474 | Object* callback = optimization.api_call_info()->callback(); |
| 475 | if (Heap::InNewSpace(callback)) { |
| 476 | info_loaded = true; |
| 477 | __ mov(ecx, Handle<CallHandlerInfo>(optimization.api_call_info())); |
| 478 | __ mov(ebx, FieldOperand(ecx, CallHandlerInfo::kCallbackOffset)); |
| 479 | __ mov(Operand(esp, 3 * kPointerSize), ebx); |
| 480 | } else { |
| 481 | __ mov(Operand(esp, 3 * kPointerSize), Immediate(Handle<Object>(callback))); |
| 482 | } |
| 483 | Object* call_data = optimization.api_call_info()->data(); |
| 484 | if (Heap::InNewSpace(call_data)) { |
| 485 | if (!info_loaded) { |
| 486 | __ mov(ecx, Handle<CallHandlerInfo>(optimization.api_call_info())); |
| 487 | } |
| 488 | __ mov(ebx, FieldOperand(ecx, CallHandlerInfo::kDataOffset)); |
| 489 | __ mov(Operand(esp, 2 * kPointerSize), ebx); |
| 490 | } else { |
| 491 | __ mov(Operand(esp, 2 * kPointerSize), |
| 492 | Immediate(Handle<Object>(call_data))); |
| 493 | } |
| 494 | |
| 495 | // Set the number of arguments. |
| 496 | __ mov(eax, Immediate(argc + 4)); |
| 497 | |
| 498 | // Jump to the fast api call builtin (tail call). |
| 499 | Handle<Code> code = Handle<Code>( |
| 500 | Builtins::builtin(Builtins::FastHandleApiCall)); |
| 501 | ParameterCount expected(0); |
| 502 | __ InvokeCode(code, expected, expected, |
| 503 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
| 504 | } |
| 505 | |
| 506 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 507 | class CallInterceptorCompiler BASE_EMBEDDED { |
| 508 | public: |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 509 | CallInterceptorCompiler(StubCompiler* stub_compiler, |
| 510 | const ParameterCount& arguments, |
| 511 | Register name) |
| 512 | : stub_compiler_(stub_compiler), |
| 513 | arguments_(arguments), |
| 514 | name_(name) {} |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 515 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 516 | void Compile(MacroAssembler* masm, |
| 517 | JSObject* object, |
| 518 | JSObject* holder, |
| 519 | String* name, |
| 520 | LookupResult* lookup, |
| 521 | Register receiver, |
| 522 | Register scratch1, |
| 523 | Register scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 524 | Register scratch3, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 525 | Label* miss) { |
| 526 | ASSERT(holder->HasNamedInterceptor()); |
| 527 | ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 528 | |
| 529 | // Check that the receiver isn't a smi. |
| 530 | __ test(receiver, Immediate(kSmiTagMask)); |
| 531 | __ j(zero, miss, not_taken); |
| 532 | |
| 533 | CallOptimization optimization(lookup); |
| 534 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 535 | if (optimization.is_constant_call()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 536 | CompileCacheable(masm, |
| 537 | object, |
| 538 | receiver, |
| 539 | scratch1, |
| 540 | scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 541 | scratch3, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 542 | holder, |
| 543 | lookup, |
| 544 | name, |
| 545 | optimization, |
| 546 | miss); |
| 547 | } else { |
| 548 | CompileRegular(masm, |
| 549 | object, |
| 550 | receiver, |
| 551 | scratch1, |
| 552 | scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 553 | scratch3, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 554 | name, |
| 555 | holder, |
| 556 | miss); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | private: |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 561 | void CompileCacheable(MacroAssembler* masm, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 562 | JSObject* object, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 563 | Register receiver, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 564 | Register scratch1, |
| 565 | Register scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 566 | Register scratch3, |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 567 | JSObject* interceptor_holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 568 | LookupResult* lookup, |
| 569 | String* name, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 570 | const CallOptimization& optimization, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 571 | Label* miss_label) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 572 | ASSERT(optimization.is_constant_call()); |
| 573 | ASSERT(!lookup->holder()->IsGlobalObject()); |
| 574 | |
| 575 | int depth1 = kInvalidProtoDepth; |
| 576 | int depth2 = kInvalidProtoDepth; |
| 577 | bool can_do_fast_api_call = false; |
| 578 | if (optimization.is_simple_api_call() && |
| 579 | !lookup->holder()->IsGlobalObject()) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 580 | depth1 = |
| 581 | optimization.GetPrototypeDepthOfExpectedType(object, |
| 582 | interceptor_holder); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 583 | if (depth1 == kInvalidProtoDepth) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 584 | depth2 = |
| 585 | optimization.GetPrototypeDepthOfExpectedType(interceptor_holder, |
| 586 | lookup->holder()); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 587 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 588 | can_do_fast_api_call = (depth1 != kInvalidProtoDepth) || |
| 589 | (depth2 != kInvalidProtoDepth); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 590 | } |
| 591 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 592 | __ IncrementCounter(&Counters::call_const_interceptor, 1); |
| 593 | |
| 594 | if (can_do_fast_api_call) { |
| 595 | __ IncrementCounter(&Counters::call_const_interceptor_fast_api, 1); |
| 596 | ReserveSpaceForFastApiCall(masm, scratch1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 597 | } |
| 598 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 599 | // Check that the maps from receiver to interceptor's holder |
| 600 | // haven't changed and thus we can invoke interceptor. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 601 | Label miss_cleanup; |
| 602 | Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label; |
| 603 | Register holder = |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 604 | stub_compiler_->CheckPrototypes(object, receiver, |
| 605 | interceptor_holder, scratch1, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 606 | scratch2, scratch3, name, depth1, miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 607 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 608 | // Invoke an interceptor and if it provides a value, |
| 609 | // branch to |regular_invoke|. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 610 | Label regular_invoke; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 611 | LoadWithInterceptor(masm, receiver, holder, interceptor_holder, |
| 612 | ®ular_invoke); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 613 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 614 | // Interceptor returned nothing for this property. Try to use cached |
| 615 | // constant function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 616 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 617 | // Check that the maps from interceptor's holder to constant function's |
| 618 | // holder haven't changed and thus we can use cached constant function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 619 | if (interceptor_holder != lookup->holder()) { |
| 620 | stub_compiler_->CheckPrototypes(interceptor_holder, receiver, |
| 621 | lookup->holder(), scratch1, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 622 | scratch2, scratch3, name, depth2, miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 623 | } else { |
| 624 | // CheckPrototypes has a side effect of fetching a 'holder' |
| 625 | // for API (object which is instanceof for the signature). It's |
| 626 | // safe to omit it here, as if present, it should be fetched |
| 627 | // by the previous CheckPrototypes. |
| 628 | ASSERT(depth2 == kInvalidProtoDepth); |
| 629 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 630 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 631 | // Invoke function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 632 | if (can_do_fast_api_call) { |
| 633 | GenerateFastApiCall(masm, optimization, arguments_.immediate()); |
| 634 | } else { |
| 635 | __ InvokeFunction(optimization.constant_function(), arguments_, |
| 636 | JUMP_FUNCTION); |
| 637 | } |
| 638 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 639 | // Deferred code for fast API call case---clean preallocated space. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 640 | if (can_do_fast_api_call) { |
| 641 | __ bind(&miss_cleanup); |
| 642 | FreeSpaceForFastApiCall(masm, scratch1); |
| 643 | __ jmp(miss_label); |
| 644 | } |
| 645 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 646 | // Invoke a regular function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 647 | __ bind(®ular_invoke); |
| 648 | if (can_do_fast_api_call) { |
| 649 | FreeSpaceForFastApiCall(masm, scratch1); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | void CompileRegular(MacroAssembler* masm, |
| 654 | JSObject* object, |
| 655 | Register receiver, |
| 656 | Register scratch1, |
| 657 | Register scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 658 | Register scratch3, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 659 | String* name, |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 660 | JSObject* interceptor_holder, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 661 | Label* miss_label) { |
| 662 | Register holder = |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 663 | stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 664 | scratch1, scratch2, scratch3, name, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 665 | miss_label); |
| 666 | |
| 667 | __ EnterInternalFrame(); |
| 668 | // Save the name_ register across the call. |
| 669 | __ push(name_); |
| 670 | |
| 671 | PushInterceptorArguments(masm, |
| 672 | receiver, |
| 673 | holder, |
| 674 | name_, |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 675 | interceptor_holder); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 676 | |
| 677 | __ CallExternalReference( |
| 678 | ExternalReference( |
| 679 | IC_Utility(IC::kLoadPropertyWithInterceptorForCall)), |
| 680 | 5); |
| 681 | |
| 682 | // Restore the name_ register. |
| 683 | __ pop(name_); |
| 684 | __ LeaveInternalFrame(); |
| 685 | } |
| 686 | |
| 687 | void LoadWithInterceptor(MacroAssembler* masm, |
| 688 | Register receiver, |
| 689 | Register holder, |
| 690 | JSObject* holder_obj, |
| 691 | Label* interceptor_succeeded) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 692 | __ EnterInternalFrame(); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 693 | __ push(holder); // Save the holder. |
| 694 | __ push(name_); // Save the name. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 695 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 696 | CompileCallLoadPropertyWithInterceptor(masm, |
| 697 | receiver, |
| 698 | holder, |
| 699 | name_, |
| 700 | holder_obj); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 701 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 702 | __ pop(name_); // Restore the name. |
| 703 | __ pop(receiver); // Restore the holder. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 704 | __ LeaveInternalFrame(); |
| 705 | |
| 706 | __ cmp(eax, Factory::no_interceptor_result_sentinel()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 707 | __ j(not_equal, interceptor_succeeded); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 708 | } |
| 709 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 710 | StubCompiler* stub_compiler_; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 711 | const ParameterCount& arguments_; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 712 | Register name_; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 713 | }; |
| 714 | |
| 715 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) { |
| 717 | ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC); |
| 718 | Code* code = NULL; |
| 719 | if (kind == Code::LOAD_IC) { |
| 720 | code = Builtins::builtin(Builtins::LoadIC_Miss); |
| 721 | } else { |
| 722 | code = Builtins::builtin(Builtins::KeyedLoadIC_Miss); |
| 723 | } |
| 724 | |
| 725 | Handle<Code> ic(code); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 726 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 730 | // Both name_reg and receiver_reg are preserved on jumps to miss_label, |
| 731 | // but may be destroyed if store is successful. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 732 | void StubCompiler::GenerateStoreField(MacroAssembler* masm, |
| 733 | JSObject* object, |
| 734 | int index, |
| 735 | Map* transition, |
| 736 | Register receiver_reg, |
| 737 | Register name_reg, |
| 738 | Register scratch, |
| 739 | Label* miss_label) { |
| 740 | // Check that the object isn't a smi. |
| 741 | __ test(receiver_reg, Immediate(kSmiTagMask)); |
| 742 | __ j(zero, miss_label, not_taken); |
| 743 | |
| 744 | // Check that the map of the object hasn't changed. |
| 745 | __ cmp(FieldOperand(receiver_reg, HeapObject::kMapOffset), |
| 746 | Immediate(Handle<Map>(object->map()))); |
| 747 | __ j(not_equal, miss_label, not_taken); |
| 748 | |
| 749 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 750 | if (object->IsJSGlobalProxy()) { |
| 751 | __ CheckAccessGlobalProxy(receiver_reg, scratch, miss_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | // Stub never generated for non-global objects that require access |
| 755 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 756 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 757 | |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 758 | // Perform map transition for the receiver if necessary. |
| 759 | if ((transition != NULL) && (object->map()->unused_property_fields() == 0)) { |
| 760 | // The properties must be extended before we can store the value. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 761 | // We jump to a runtime call that extends the properties array. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 762 | __ pop(scratch); // Return address. |
| 763 | __ push(receiver_reg); |
| 764 | __ push(Immediate(Handle<Map>(transition))); |
| 765 | __ push(eax); |
| 766 | __ push(scratch); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 767 | __ TailCallExternalReference( |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 768 | ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage)), 3, 1); |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 769 | return; |
| 770 | } |
| 771 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 772 | if (transition != NULL) { |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 773 | // Update the map of the object; no write barrier updating is |
| 774 | // needed because the map is never in new space. |
| 775 | __ mov(FieldOperand(receiver_reg, HeapObject::kMapOffset), |
| 776 | Immediate(Handle<Map>(transition))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 777 | } |
| 778 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 779 | // Adjust for the number of properties stored in the object. Even in the |
| 780 | // face of a transition we can use the old map here because the size of the |
| 781 | // object and the number of in-object properties is not going to change. |
| 782 | index -= object->map()->inobject_properties(); |
| 783 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 784 | if (index < 0) { |
| 785 | // Set the property straight into the object. |
| 786 | int offset = object->map()->instance_size() + (index * kPointerSize); |
| 787 | __ mov(FieldOperand(receiver_reg, offset), eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 788 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 789 | // Update the write barrier for the array address. |
| 790 | // Pass the value being stored in the now unused name_reg. |
| 791 | __ mov(name_reg, Operand(eax)); |
| 792 | __ RecordWrite(receiver_reg, offset, name_reg, scratch); |
| 793 | } else { |
| 794 | // Write to the properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 795 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 796 | // Get the properties array (optimistically). |
| 797 | __ mov(scratch, FieldOperand(receiver_reg, JSObject::kPropertiesOffset)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 798 | __ mov(FieldOperand(scratch, offset), eax); |
| 799 | |
| 800 | // Update the write barrier for the array address. |
| 801 | // Pass the value being stored in the now unused name_reg. |
| 802 | __ mov(name_reg, Operand(eax)); |
| 803 | __ RecordWrite(scratch, offset, name_reg, receiver_reg); |
| 804 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 805 | |
| 806 | // Return the value (register eax). |
| 807 | __ ret(0); |
| 808 | } |
| 809 | |
| 810 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 811 | // Generate code to check that a global property cell is empty. Create |
| 812 | // the property cell at compilation time if no cell exists for the |
| 813 | // property. |
| 814 | static Object* GenerateCheckPropertyCell(MacroAssembler* masm, |
| 815 | GlobalObject* global, |
| 816 | String* name, |
| 817 | Register scratch, |
| 818 | Label* miss) { |
| 819 | Object* probe = global->EnsurePropertyCell(name); |
| 820 | if (probe->IsFailure()) return probe; |
| 821 | JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(probe); |
| 822 | ASSERT(cell->value()->IsTheHole()); |
| 823 | __ mov(scratch, Immediate(Handle<Object>(cell))); |
| 824 | __ cmp(FieldOperand(scratch, JSGlobalPropertyCell::kValueOffset), |
| 825 | Immediate(Factory::the_hole_value())); |
| 826 | __ j(not_equal, miss, not_taken); |
| 827 | return cell; |
| 828 | } |
| 829 | |
| 830 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 831 | // Calls GenerateCheckPropertyCell for each global object in the prototype chain |
| 832 | // from object to (but not including) holder. |
| 833 | static Object* GenerateCheckPropertyCells(MacroAssembler* masm, |
| 834 | JSObject* object, |
| 835 | JSObject* holder, |
| 836 | String* name, |
| 837 | Register scratch, |
| 838 | Label* miss) { |
| 839 | JSObject* current = object; |
| 840 | while (current != holder) { |
| 841 | if (current->IsGlobalObject()) { |
| 842 | Object* cell = GenerateCheckPropertyCell(masm, |
| 843 | GlobalObject::cast(current), |
| 844 | name, |
| 845 | scratch, |
| 846 | miss); |
| 847 | if (cell->IsFailure()) { |
| 848 | return cell; |
| 849 | } |
| 850 | } |
| 851 | ASSERT(current->IsJSObject()); |
| 852 | current = JSObject::cast(current->GetPrototype()); |
| 853 | } |
| 854 | return NULL; |
| 855 | } |
| 856 | |
| 857 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | #undef __ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 859 | #define __ ACCESS_MASM(masm()) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 860 | |
| 861 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 862 | Register StubCompiler::CheckPrototypes(JSObject* object, |
| 863 | Register object_reg, |
| 864 | JSObject* holder, |
| 865 | Register holder_reg, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 866 | Register scratch1, |
| 867 | Register scratch2, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 868 | String* name, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 869 | int save_at_depth, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 870 | Label* miss) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 871 | // Make sure there's no overlap between holder and object registers. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 872 | ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg)); |
| 873 | ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg) |
| 874 | && !scratch2.is(scratch1)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 875 | // Keep track of the current object in register reg. |
| 876 | Register reg = object_reg; |
| 877 | JSObject* current = object; |
| 878 | int depth = 0; |
| 879 | |
| 880 | if (save_at_depth == depth) { |
| 881 | __ mov(Operand(esp, kPointerSize), reg); |
| 882 | } |
| 883 | |
| 884 | // Traverse the prototype chain and check the maps in the prototype chain for |
| 885 | // fast and global objects or do negative lookup for normal objects. |
| 886 | while (current != holder) { |
| 887 | depth++; |
| 888 | |
| 889 | // Only global objects and objects that do not require access |
| 890 | // checks are allowed in stubs. |
| 891 | ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded()); |
| 892 | |
| 893 | ASSERT(current->GetPrototype()->IsJSObject()); |
| 894 | JSObject* prototype = JSObject::cast(current->GetPrototype()); |
| 895 | if (!current->HasFastProperties() && |
| 896 | !current->IsJSGlobalObject() && |
| 897 | !current->IsJSGlobalProxy()) { |
| 898 | if (!name->IsSymbol()) { |
| 899 | Object* lookup_result = Heap::LookupSymbol(name); |
| 900 | if (lookup_result->IsFailure()) { |
| 901 | set_failure(Failure::cast(lookup_result)); |
| 902 | return reg; |
| 903 | } else { |
| 904 | name = String::cast(lookup_result); |
| 905 | } |
| 906 | } |
| 907 | ASSERT(current->property_dictionary()->FindEntry(name) == |
| 908 | StringDictionary::kNotFound); |
| 909 | |
| 910 | GenerateDictionaryNegativeLookup(masm(), |
| 911 | miss, |
| 912 | reg, |
| 913 | name, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 914 | scratch1, |
| 915 | scratch2); |
| 916 | __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 917 | reg = holder_reg; // from now the object is in holder_reg |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 918 | __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 919 | } else if (Heap::InNewSpace(prototype)) { |
| 920 | // Get the map of the current object. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 921 | __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); |
| 922 | __ cmp(Operand(scratch1), Immediate(Handle<Map>(current->map()))); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 923 | // Branch on the result of the map check. |
| 924 | __ j(not_equal, miss, not_taken); |
| 925 | // Check access rights to the global object. This has to happen |
| 926 | // after the map check so that we know that the object is |
| 927 | // actually a global object. |
| 928 | if (current->IsJSGlobalProxy()) { |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 929 | __ CheckAccessGlobalProxy(reg, scratch1, miss); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 930 | |
| 931 | // Restore scratch register to be the map of the object. |
| 932 | // We load the prototype from the map in the scratch register. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 933 | __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 934 | } |
| 935 | // The prototype is in new space; we cannot store a reference |
| 936 | // to it in the code. Load it from the map. |
| 937 | reg = holder_reg; // from now the object is in holder_reg |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 938 | __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 939 | } else { |
| 940 | // Check the map of the current object. |
| 941 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 942 | Immediate(Handle<Map>(current->map()))); |
| 943 | // Branch on the result of the map check. |
| 944 | __ j(not_equal, miss, not_taken); |
| 945 | // Check access rights to the global object. This has to happen |
| 946 | // after the map check so that we know that the object is |
| 947 | // actually a global object. |
| 948 | if (current->IsJSGlobalProxy()) { |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 949 | __ CheckAccessGlobalProxy(reg, scratch1, miss); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 950 | } |
| 951 | // The prototype is in old space; load it directly. |
| 952 | reg = holder_reg; // from now the object is in holder_reg |
| 953 | __ mov(reg, Handle<JSObject>(prototype)); |
| 954 | } |
| 955 | |
| 956 | if (save_at_depth == depth) { |
| 957 | __ mov(Operand(esp, kPointerSize), reg); |
| 958 | } |
| 959 | |
| 960 | // Go to the next object in the prototype chain. |
| 961 | current = prototype; |
| 962 | } |
| 963 | ASSERT(current == holder); |
| 964 | |
| 965 | // Log the check depth. |
| 966 | LOG(IntEvent("check-maps-depth", depth + 1)); |
| 967 | |
| 968 | // Check the holder map. |
| 969 | __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 970 | Immediate(Handle<Map>(holder->map()))); |
| 971 | __ j(not_equal, miss, not_taken); |
| 972 | |
| 973 | // Perform security check for access to the global object. |
| 974 | ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded()); |
| 975 | if (holder->IsJSGlobalProxy()) { |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 976 | __ CheckAccessGlobalProxy(reg, scratch1, miss); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 977 | }; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 978 | |
| 979 | // If we've skipped any global objects, it's not enough to verify |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 980 | // that their maps haven't changed. We also need to check that the |
| 981 | // property cell for the property is still empty. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 982 | Object* result = GenerateCheckPropertyCells(masm(), |
| 983 | object, |
| 984 | holder, |
| 985 | name, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 986 | scratch1, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 987 | miss); |
| 988 | if (result->IsFailure()) set_failure(Failure::cast(result)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 989 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 990 | // Return the register containing the holder. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 991 | return reg; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | |
| 995 | void StubCompiler::GenerateLoadField(JSObject* object, |
| 996 | JSObject* holder, |
| 997 | Register receiver, |
| 998 | Register scratch1, |
| 999 | Register scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1000 | Register scratch3, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1001 | int index, |
| 1002 | String* name, |
| 1003 | Label* miss) { |
| 1004 | // Check that the receiver isn't a smi. |
| 1005 | __ test(receiver, Immediate(kSmiTagMask)); |
| 1006 | __ j(zero, miss, not_taken); |
| 1007 | |
| 1008 | // Check the prototype chain. |
| 1009 | Register reg = |
| 1010 | CheckPrototypes(object, receiver, holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1011 | scratch1, scratch2, scratch3, name, miss); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1012 | |
| 1013 | // Get the value from the properties. |
| 1014 | GenerateFastPropertyLoad(masm(), eax, reg, holder, index); |
| 1015 | __ ret(0); |
| 1016 | } |
| 1017 | |
| 1018 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1019 | bool StubCompiler::GenerateLoadCallback(JSObject* object, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1020 | JSObject* holder, |
| 1021 | Register receiver, |
| 1022 | Register name_reg, |
| 1023 | Register scratch1, |
| 1024 | Register scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1025 | Register scratch3, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1026 | AccessorInfo* callback, |
| 1027 | String* name, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1028 | Label* miss, |
| 1029 | Failure** failure) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1030 | // Check that the receiver isn't a smi. |
| 1031 | __ test(receiver, Immediate(kSmiTagMask)); |
| 1032 | __ j(zero, miss, not_taken); |
| 1033 | |
| 1034 | // Check that the maps haven't changed. |
| 1035 | Register reg = |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame^] | 1036 | CheckPrototypes(object, receiver, holder, scratch1, |
| 1037 | scratch2, scratch3, name, miss); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1038 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1039 | Handle<AccessorInfo> callback_handle(callback); |
| 1040 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1041 | __ EnterInternalFrame(); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame^] | 1042 | __ PushHandleScope(scratch2); |
| 1043 | // Push the stack address where the list of arguments ends. |
| 1044 | __ mov(scratch2, esp); |
| 1045 | __ sub(Operand(scratch2), Immediate(2 * kPointerSize)); |
| 1046 | __ push(scratch2); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1047 | __ push(receiver); // receiver |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1048 | __ push(reg); // holder |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1049 | // Push data from AccessorInfo. |
| 1050 | if (Heap::InNewSpace(callback_handle->data())) { |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame^] | 1051 | __ mov(scratch2, Immediate(callback_handle)); |
| 1052 | __ push(FieldOperand(scratch2, AccessorInfo::kDataOffset)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1053 | } else { |
| 1054 | __ push(Immediate(Handle<Object>(callback_handle->data()))); |
| 1055 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1056 | __ push(name_reg); // name |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1057 | // Save a pointer to where we pushed the arguments pointer. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1058 | // This will be passed as the const AccessorInfo& to the C++ callback. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1059 | __ mov(eax, esp); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1060 | __ add(Operand(eax), Immediate(4 * kPointerSize)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1061 | __ mov(ebx, esp); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1062 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1063 | // Do call through the api. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1064 | ASSERT_EQ(5, ApiGetterEntryStub::kStackSpace); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1065 | Address getter_address = v8::ToCData<Address>(callback->getter()); |
| 1066 | ApiFunction fun(getter_address); |
| 1067 | ApiGetterEntryStub stub(callback_handle, &fun); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1068 | // Emitting a stub call may try to allocate (if the code is not |
| 1069 | // already generated). Do not allow the assembler to perform a |
| 1070 | // garbage collection but instead return the allocation failure |
| 1071 | // object. |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1072 | Object* result = masm()->TryCallStub(&stub); |
| 1073 | if (result->IsFailure()) { |
| 1074 | *failure = Failure::cast(result); |
| 1075 | return false; |
| 1076 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1077 | |
| 1078 | // We need to avoid using eax since that now holds the result. |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame^] | 1079 | Register tmp = scratch2.is(eax) ? reg : scratch2; |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1080 | // Emitting PopHandleScope may try to allocate. Do not allow the |
| 1081 | // assembler to perform a garbage collection but instead return a |
| 1082 | // failure object. |
| 1083 | result = masm()->TryPopHandleScope(eax, tmp); |
| 1084 | if (result->IsFailure()) { |
| 1085 | *failure = Failure::cast(result); |
| 1086 | return false; |
| 1087 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1088 | __ LeaveInternalFrame(); |
| 1089 | |
| 1090 | __ ret(0); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1091 | return true; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | |
| 1095 | void StubCompiler::GenerateLoadConstant(JSObject* object, |
| 1096 | JSObject* holder, |
| 1097 | Register receiver, |
| 1098 | Register scratch1, |
| 1099 | Register scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1100 | Register scratch3, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1101 | Object* value, |
| 1102 | String* name, |
| 1103 | Label* miss) { |
| 1104 | // Check that the receiver isn't a smi. |
| 1105 | __ test(receiver, Immediate(kSmiTagMask)); |
| 1106 | __ j(zero, miss, not_taken); |
| 1107 | |
| 1108 | // Check that the maps haven't changed. |
| 1109 | Register reg = |
| 1110 | CheckPrototypes(object, receiver, holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1111 | scratch1, scratch2, scratch3, name, miss); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1112 | |
| 1113 | // Return the constant value. |
| 1114 | __ mov(eax, Handle<Object>(value)); |
| 1115 | __ ret(0); |
| 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | void StubCompiler::GenerateLoadInterceptor(JSObject* object, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1120 | JSObject* interceptor_holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1121 | LookupResult* lookup, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1122 | Register receiver, |
| 1123 | Register name_reg, |
| 1124 | Register scratch1, |
| 1125 | Register scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1126 | Register scratch3, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1127 | String* name, |
| 1128 | Label* miss) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1129 | ASSERT(interceptor_holder->HasNamedInterceptor()); |
| 1130 | ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 1131 | |
| 1132 | // Check that the receiver isn't a smi. |
| 1133 | __ test(receiver, Immediate(kSmiTagMask)); |
| 1134 | __ j(zero, miss, not_taken); |
| 1135 | |
| 1136 | // So far the most popular follow ups for interceptor loads are FIELD |
| 1137 | // and CALLBACKS, so inline only them, other cases may be added |
| 1138 | // later. |
| 1139 | bool compile_followup_inline = false; |
| 1140 | if (lookup->IsProperty() && lookup->IsCacheable()) { |
| 1141 | if (lookup->type() == FIELD) { |
| 1142 | compile_followup_inline = true; |
| 1143 | } else if (lookup->type() == CALLBACKS && |
| 1144 | lookup->GetCallbackObject()->IsAccessorInfo() && |
| 1145 | AccessorInfo::cast(lookup->GetCallbackObject())->getter() != NULL) { |
| 1146 | compile_followup_inline = true; |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | if (compile_followup_inline) { |
| 1151 | // Compile the interceptor call, followed by inline code to load the |
| 1152 | // property from further up the prototype chain if the call fails. |
| 1153 | // Check that the maps haven't changed. |
| 1154 | Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1155 | scratch1, scratch2, scratch3, |
| 1156 | name, miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1157 | ASSERT(holder_reg.is(receiver) || holder_reg.is(scratch1)); |
| 1158 | |
| 1159 | // Save necessary data before invoking an interceptor. |
| 1160 | // Requires a frame to make GC aware of pushed pointers. |
| 1161 | __ EnterInternalFrame(); |
| 1162 | |
| 1163 | if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) { |
| 1164 | // CALLBACKS case needs a receiver to be passed into C++ callback. |
| 1165 | __ push(receiver); |
| 1166 | } |
| 1167 | __ push(holder_reg); |
| 1168 | __ push(name_reg); |
| 1169 | |
| 1170 | // Invoke an interceptor. Note: map checks from receiver to |
| 1171 | // interceptor's holder has been compiled before (see a caller |
| 1172 | // of this method.) |
| 1173 | CompileCallLoadPropertyWithInterceptor(masm(), |
| 1174 | receiver, |
| 1175 | holder_reg, |
| 1176 | name_reg, |
| 1177 | interceptor_holder); |
| 1178 | |
| 1179 | // Check if interceptor provided a value for property. If it's |
| 1180 | // the case, return immediately. |
| 1181 | Label interceptor_failed; |
| 1182 | __ cmp(eax, Factory::no_interceptor_result_sentinel()); |
| 1183 | __ j(equal, &interceptor_failed); |
| 1184 | __ LeaveInternalFrame(); |
| 1185 | __ ret(0); |
| 1186 | |
| 1187 | __ bind(&interceptor_failed); |
| 1188 | __ pop(name_reg); |
| 1189 | __ pop(holder_reg); |
| 1190 | if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) { |
| 1191 | __ pop(receiver); |
| 1192 | } |
| 1193 | |
| 1194 | __ LeaveInternalFrame(); |
| 1195 | |
| 1196 | // Check that the maps from interceptor's holder to lookup's holder |
| 1197 | // haven't changed. And load lookup's holder into holder_reg. |
| 1198 | if (interceptor_holder != lookup->holder()) { |
| 1199 | holder_reg = CheckPrototypes(interceptor_holder, |
| 1200 | holder_reg, |
| 1201 | lookup->holder(), |
| 1202 | scratch1, |
| 1203 | scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1204 | scratch3, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1205 | name, |
| 1206 | miss); |
| 1207 | } |
| 1208 | |
| 1209 | if (lookup->type() == FIELD) { |
| 1210 | // We found FIELD property in prototype chain of interceptor's holder. |
| 1211 | // Retrieve a field from field's holder. |
| 1212 | GenerateFastPropertyLoad(masm(), eax, holder_reg, |
| 1213 | lookup->holder(), lookup->GetFieldIndex()); |
| 1214 | __ ret(0); |
| 1215 | } else { |
| 1216 | // We found CALLBACKS property in prototype chain of interceptor's |
| 1217 | // holder. |
| 1218 | ASSERT(lookup->type() == CALLBACKS); |
| 1219 | ASSERT(lookup->GetCallbackObject()->IsAccessorInfo()); |
| 1220 | AccessorInfo* callback = AccessorInfo::cast(lookup->GetCallbackObject()); |
| 1221 | ASSERT(callback != NULL); |
| 1222 | ASSERT(callback->getter() != NULL); |
| 1223 | |
| 1224 | // Tail call to runtime. |
| 1225 | // Important invariant in CALLBACKS case: the code above must be |
| 1226 | // structured to never clobber |receiver| register. |
| 1227 | __ pop(scratch2); // return address |
| 1228 | __ push(receiver); |
| 1229 | __ push(holder_reg); |
| 1230 | __ mov(holder_reg, Immediate(Handle<AccessorInfo>(callback))); |
| 1231 | __ push(holder_reg); |
| 1232 | __ push(FieldOperand(holder_reg, AccessorInfo::kDataOffset)); |
| 1233 | __ push(name_reg); |
| 1234 | __ push(scratch2); // restore return address |
| 1235 | |
| 1236 | ExternalReference ref = |
| 1237 | ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); |
| 1238 | __ TailCallExternalReference(ref, 5, 1); |
| 1239 | } |
| 1240 | } else { // !compile_followup_inline |
| 1241 | // Call the runtime system to load the interceptor. |
| 1242 | // Check that the maps haven't changed. |
| 1243 | Register holder_reg = |
| 1244 | CheckPrototypes(object, receiver, interceptor_holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1245 | scratch1, scratch2, scratch3, name, miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1246 | __ pop(scratch2); // save old return address |
| 1247 | PushInterceptorArguments(masm(), receiver, holder_reg, |
| 1248 | name_reg, interceptor_holder); |
| 1249 | __ push(scratch2); // restore old return address |
| 1250 | |
| 1251 | ExternalReference ref = ExternalReference( |
| 1252 | IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); |
| 1253 | __ TailCallExternalReference(ref, 5, 1); |
| 1254 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1258 | // TODO(1241006): Avoid having lazy compile stubs specialized by the |
| 1259 | // number of arguments. It is not needed anymore. |
| 1260 | Object* StubCompiler::CompileLazyCompile(Code::Flags flags) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1261 | // Enter an internal frame. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1262 | __ EnterInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1263 | |
| 1264 | // Push a copy of the function onto the stack. |
| 1265 | __ push(edi); |
| 1266 | |
| 1267 | __ push(edi); // function is also the parameter to the runtime call |
| 1268 | __ CallRuntime(Runtime::kLazyCompile, 1); |
| 1269 | __ pop(edi); |
| 1270 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1271 | // Tear down temporary frame. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1272 | __ LeaveInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1273 | |
| 1274 | // Do a tail-call of the compiled function. |
| 1275 | __ lea(ecx, FieldOperand(eax, Code::kHeaderSize)); |
| 1276 | __ jmp(Operand(ecx)); |
| 1277 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1278 | return GetCodeWithFlags(flags, "LazyCompileStub"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1282 | void CallStubCompiler::GenerateNameCheck(String* name, Label* miss) { |
| 1283 | if (kind_ == Code::KEYED_CALL_IC) { |
| 1284 | __ cmp(Operand(ecx), Immediate(Handle<String>(name))); |
| 1285 | __ j(not_equal, miss, not_taken); |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | |
| 1290 | void CallStubCompiler::GenerateMissBranch() { |
| 1291 | Handle<Code> ic = ComputeCallMiss(arguments().immediate(), kind_); |
| 1292 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 1293 | } |
| 1294 | |
| 1295 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1296 | Object* CallStubCompiler::CompileCallField(JSObject* object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1297 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1298 | int index, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1299 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1300 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1301 | // -- ecx : name |
| 1302 | // -- esp[0] : return address |
| 1303 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1304 | // -- ... |
| 1305 | // -- esp[(argc + 1) * 4] : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1306 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1307 | Label miss; |
| 1308 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1309 | GenerateNameCheck(name, &miss); |
| 1310 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1311 | // Get the receiver from the stack. |
| 1312 | const int argc = arguments().immediate(); |
| 1313 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1314 | |
| 1315 | // Check that the receiver isn't a smi. |
| 1316 | __ test(edx, Immediate(kSmiTagMask)); |
| 1317 | __ j(zero, &miss, not_taken); |
| 1318 | |
| 1319 | // Do the right check and compute the holder register. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1320 | Register reg = CheckPrototypes(object, edx, holder, ebx, eax, edi, |
| 1321 | name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1322 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1323 | GenerateFastPropertyLoad(masm(), edi, reg, holder, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1324 | |
| 1325 | // Check that the function really is a function. |
| 1326 | __ test(edi, Immediate(kSmiTagMask)); |
| 1327 | __ j(zero, &miss, not_taken); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1328 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1329 | __ j(not_equal, &miss, not_taken); |
| 1330 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1331 | // Patch the receiver on the stack with the global proxy if |
| 1332 | // necessary. |
| 1333 | if (object->IsGlobalObject()) { |
| 1334 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1335 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1336 | } |
| 1337 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1338 | // Invoke the function. |
| 1339 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION); |
| 1340 | |
| 1341 | // Handle call cache miss. |
| 1342 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1343 | GenerateMissBranch(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1344 | |
| 1345 | // Return the generated code. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1346 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1350 | Object* CallStubCompiler::CompileArrayPushCall(Object* object, |
| 1351 | JSObject* holder, |
| 1352 | JSFunction* function, |
| 1353 | String* name, |
| 1354 | CheckType check) { |
| 1355 | // ----------- S t a t e ------------- |
| 1356 | // -- ecx : name |
| 1357 | // -- esp[0] : return address |
| 1358 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1359 | // -- ... |
| 1360 | // -- esp[(argc + 1) * 4] : receiver |
| 1361 | // ----------------------------------- |
| 1362 | ASSERT(check == RECEIVER_MAP_CHECK); |
| 1363 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1364 | // If object is not an array, bail out to regular call. |
| 1365 | if (!object->IsJSArray()) { |
| 1366 | return Heap::undefined_value(); |
| 1367 | } |
| 1368 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1369 | Label miss; |
| 1370 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1371 | GenerateNameCheck(name, &miss); |
| 1372 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1373 | // Get the receiver from the stack. |
| 1374 | const int argc = arguments().immediate(); |
| 1375 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1376 | |
| 1377 | // Check that the receiver isn't a smi. |
| 1378 | __ test(edx, Immediate(kSmiTagMask)); |
| 1379 | __ j(zero, &miss); |
| 1380 | |
| 1381 | CheckPrototypes(JSObject::cast(object), edx, |
| 1382 | holder, ebx, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1383 | eax, edi, name, &miss); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1384 | |
| 1385 | if (argc == 0) { |
| 1386 | // Noop, return the length. |
| 1387 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1388 | __ ret((argc + 1) * kPointerSize); |
| 1389 | } else { |
| 1390 | // Get the elements array of the object. |
| 1391 | __ mov(ebx, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1392 | |
| 1393 | // Check that the elements are in fast mode (not dictionary). |
| 1394 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1395 | Immediate(Factory::fixed_array_map())); |
| 1396 | __ j(not_equal, &miss); |
| 1397 | |
| 1398 | if (argc == 1) { // Otherwise fall through to call builtin. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1399 | Label call_builtin, exit, with_write_barrier, attempt_to_grow_elements; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1400 | |
| 1401 | // Get the array's length into eax and calculate new length. |
| 1402 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1403 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1404 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1405 | __ add(Operand(eax), Immediate(Smi::FromInt(argc))); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1406 | |
| 1407 | // Get the element's length into ecx. |
| 1408 | __ mov(ecx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1409 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1410 | // Check if we could survive without allocation. |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1411 | __ cmp(eax, Operand(ecx)); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1412 | __ j(greater, &attempt_to_grow_elements); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1413 | |
| 1414 | // Save new length. |
| 1415 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1416 | |
| 1417 | // Push the element. |
| 1418 | __ lea(edx, FieldOperand(ebx, |
| 1419 | eax, times_half_pointer_size, |
| 1420 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 1421 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 1422 | __ mov(Operand(edx, 0), ecx); |
| 1423 | |
| 1424 | // Check if value is a smi. |
| 1425 | __ test(ecx, Immediate(kSmiTagMask)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1426 | __ j(not_zero, &with_write_barrier); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1427 | |
| 1428 | __ bind(&exit); |
| 1429 | __ ret((argc + 1) * kPointerSize); |
| 1430 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1431 | __ bind(&with_write_barrier); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1432 | |
| 1433 | __ InNewSpace(ebx, ecx, equal, &exit); |
| 1434 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1435 | __ RecordWriteHelper(ebx, edx, ecx); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1436 | __ ret((argc + 1) * kPointerSize); |
| 1437 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1438 | __ bind(&attempt_to_grow_elements); |
| 1439 | ExternalReference new_space_allocation_top = |
| 1440 | ExternalReference::new_space_allocation_top_address(); |
| 1441 | ExternalReference new_space_allocation_limit = |
| 1442 | ExternalReference::new_space_allocation_limit_address(); |
| 1443 | |
| 1444 | const int kAllocationDelta = 4; |
| 1445 | // Load top. |
| 1446 | __ mov(ecx, Operand::StaticVariable(new_space_allocation_top)); |
| 1447 | |
| 1448 | // Check if it's the end of elements. |
| 1449 | __ lea(edx, FieldOperand(ebx, |
| 1450 | eax, times_half_pointer_size, |
| 1451 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 1452 | __ cmp(edx, Operand(ecx)); |
| 1453 | __ j(not_equal, &call_builtin); |
| 1454 | __ add(Operand(ecx), Immediate(kAllocationDelta * kPointerSize)); |
| 1455 | __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1456 | __ j(above, &call_builtin); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1457 | |
| 1458 | // We fit and could grow elements. |
| 1459 | __ mov(Operand::StaticVariable(new_space_allocation_top), ecx); |
| 1460 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1461 | |
| 1462 | // Push the argument... |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1463 | __ mov(Operand(edx, 0), ecx); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1464 | // ... and fill the rest with holes. |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1465 | for (int i = 1; i < kAllocationDelta; i++) { |
| 1466 | __ mov(Operand(edx, i * kPointerSize), |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1467 | Immediate(Factory::the_hole_value())); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | // Restore receiver to edx as finish sequence assumes it's here. |
| 1471 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1472 | |
| 1473 | // Increment element's and array's sizes. |
| 1474 | __ add(FieldOperand(ebx, FixedArray::kLengthOffset), |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1475 | Immediate(Smi::FromInt(kAllocationDelta))); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1476 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1477 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1478 | // Elements are in new space, so write barrier is not required. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1479 | __ ret((argc + 1) * kPointerSize); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1480 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1481 | __ bind(&call_builtin); |
| 1482 | } |
| 1483 | |
| 1484 | __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush), |
| 1485 | argc + 1, |
| 1486 | 1); |
| 1487 | } |
| 1488 | |
| 1489 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1490 | GenerateMissBranch(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1491 | |
| 1492 | // Return the generated code. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1493 | return GetCode(function); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | |
| 1497 | Object* CallStubCompiler::CompileArrayPopCall(Object* object, |
| 1498 | JSObject* holder, |
| 1499 | JSFunction* function, |
| 1500 | String* name, |
| 1501 | CheckType check) { |
| 1502 | // ----------- S t a t e ------------- |
| 1503 | // -- ecx : name |
| 1504 | // -- esp[0] : return address |
| 1505 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1506 | // -- ... |
| 1507 | // -- esp[(argc + 1) * 4] : receiver |
| 1508 | // ----------------------------------- |
| 1509 | ASSERT(check == RECEIVER_MAP_CHECK); |
| 1510 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1511 | // If object is not an array, bail out to regular call. |
| 1512 | if (!object->IsJSArray()) { |
| 1513 | return Heap::undefined_value(); |
| 1514 | } |
| 1515 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1516 | Label miss, return_undefined, call_builtin; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1517 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1518 | GenerateNameCheck(name, &miss); |
| 1519 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1520 | // Get the receiver from the stack. |
| 1521 | const int argc = arguments().immediate(); |
| 1522 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1523 | |
| 1524 | // Check that the receiver isn't a smi. |
| 1525 | __ test(edx, Immediate(kSmiTagMask)); |
| 1526 | __ j(zero, &miss); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1527 | CheckPrototypes(JSObject::cast(object), edx, |
| 1528 | holder, ebx, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1529 | eax, edi, name, &miss); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1530 | |
| 1531 | // Get the elements array of the object. |
| 1532 | __ mov(ebx, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1533 | |
| 1534 | // Check that the elements are in fast mode (not dictionary). |
| 1535 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1536 | Immediate(Factory::fixed_array_map())); |
| 1537 | __ j(not_equal, &miss); |
| 1538 | |
| 1539 | // Get the array's length into ecx and calculate new length. |
| 1540 | __ mov(ecx, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1541 | __ sub(Operand(ecx), Immediate(Smi::FromInt(1))); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1542 | __ j(negative, &return_undefined); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1543 | |
| 1544 | // Get the last element. |
| 1545 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1546 | STATIC_ASSERT(kSmiTag == 0); |
| 1547 | __ mov(eax, FieldOperand(ebx, |
| 1548 | ecx, times_half_pointer_size, |
| 1549 | FixedArray::kHeaderSize)); |
| 1550 | __ cmp(Operand(eax), Immediate(Factory::the_hole_value())); |
| 1551 | __ j(equal, &call_builtin); |
| 1552 | |
| 1553 | // Set the array's length. |
| 1554 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), ecx); |
| 1555 | |
| 1556 | // Fill with the hole. |
| 1557 | __ mov(FieldOperand(ebx, |
| 1558 | ecx, times_half_pointer_size, |
| 1559 | FixedArray::kHeaderSize), |
| 1560 | Immediate(Factory::the_hole_value())); |
| 1561 | __ ret((argc + 1) * kPointerSize); |
| 1562 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1563 | __ bind(&return_undefined); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1564 | __ mov(eax, Immediate(Factory::undefined_value())); |
| 1565 | __ ret((argc + 1) * kPointerSize); |
| 1566 | |
| 1567 | __ bind(&call_builtin); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1568 | __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop), |
| 1569 | argc + 1, |
| 1570 | 1); |
| 1571 | |
| 1572 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1573 | GenerateMissBranch(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1574 | |
| 1575 | // Return the generated code. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1576 | return GetCode(function); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1580 | Object* CallStubCompiler::CompileStringCharCodeAtCall(Object* object, |
| 1581 | JSObject* holder, |
| 1582 | JSFunction* function, |
| 1583 | String* name, |
| 1584 | CheckType check) { |
| 1585 | // ----------- S t a t e ------------- |
| 1586 | // -- ecx : function name |
| 1587 | // -- esp[0] : return address |
| 1588 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1589 | // -- ... |
| 1590 | // -- esp[(argc + 1) * 4] : receiver |
| 1591 | // ----------------------------------- |
| 1592 | |
| 1593 | const int argc = arguments().immediate(); |
| 1594 | |
| 1595 | Label miss; |
| 1596 | Label index_out_of_range; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1597 | GenerateNameCheck(name, &miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1598 | |
| 1599 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1600 | GenerateDirectLoadGlobalFunctionPrototype(masm(), |
| 1601 | Context::STRING_FUNCTION_INDEX, |
| 1602 | eax); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1603 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1604 | ebx, edx, edi, name, &miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1605 | |
| 1606 | Register receiver = ebx; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1607 | Register index = edi; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1608 | Register scratch = edx; |
| 1609 | Register result = eax; |
| 1610 | __ mov(receiver, Operand(esp, (argc + 1) * kPointerSize)); |
| 1611 | if (argc > 0) { |
| 1612 | __ mov(index, Operand(esp, (argc - 0) * kPointerSize)); |
| 1613 | } else { |
| 1614 | __ Set(index, Immediate(Factory::undefined_value())); |
| 1615 | } |
| 1616 | |
| 1617 | StringCharCodeAtGenerator char_code_at_generator(receiver, |
| 1618 | index, |
| 1619 | scratch, |
| 1620 | result, |
| 1621 | &miss, // When not a string. |
| 1622 | &miss, // When not a number. |
| 1623 | &index_out_of_range, |
| 1624 | STRING_INDEX_IS_NUMBER); |
| 1625 | char_code_at_generator.GenerateFast(masm()); |
| 1626 | __ ret((argc + 1) * kPointerSize); |
| 1627 | |
| 1628 | ICRuntimeCallHelper call_helper; |
| 1629 | char_code_at_generator.GenerateSlow(masm(), call_helper); |
| 1630 | |
| 1631 | __ bind(&index_out_of_range); |
| 1632 | __ Set(eax, Immediate(Factory::nan_value())); |
| 1633 | __ ret((argc + 1) * kPointerSize); |
| 1634 | |
| 1635 | __ bind(&miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1636 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1637 | GenerateMissBranch(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1638 | |
| 1639 | // Return the generated code. |
| 1640 | return GetCode(function); |
| 1641 | } |
| 1642 | |
| 1643 | |
| 1644 | Object* CallStubCompiler::CompileStringCharAtCall(Object* object, |
| 1645 | JSObject* holder, |
| 1646 | JSFunction* function, |
| 1647 | String* name, |
| 1648 | CheckType check) { |
| 1649 | // ----------- S t a t e ------------- |
| 1650 | // -- ecx : function name |
| 1651 | // -- esp[0] : return address |
| 1652 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1653 | // -- ... |
| 1654 | // -- esp[(argc + 1) * 4] : receiver |
| 1655 | // ----------------------------------- |
| 1656 | |
| 1657 | const int argc = arguments().immediate(); |
| 1658 | |
| 1659 | Label miss; |
| 1660 | Label index_out_of_range; |
| 1661 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1662 | GenerateNameCheck(name, &miss); |
| 1663 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1664 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1665 | GenerateDirectLoadGlobalFunctionPrototype(masm(), |
| 1666 | Context::STRING_FUNCTION_INDEX, |
| 1667 | eax); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1668 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1669 | ebx, edx, edi, name, &miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1670 | |
| 1671 | Register receiver = eax; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1672 | Register index = edi; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1673 | Register scratch1 = ebx; |
| 1674 | Register scratch2 = edx; |
| 1675 | Register result = eax; |
| 1676 | __ mov(receiver, Operand(esp, (argc + 1) * kPointerSize)); |
| 1677 | if (argc > 0) { |
| 1678 | __ mov(index, Operand(esp, (argc - 0) * kPointerSize)); |
| 1679 | } else { |
| 1680 | __ Set(index, Immediate(Factory::undefined_value())); |
| 1681 | } |
| 1682 | |
| 1683 | StringCharAtGenerator char_at_generator(receiver, |
| 1684 | index, |
| 1685 | scratch1, |
| 1686 | scratch2, |
| 1687 | result, |
| 1688 | &miss, // When not a string. |
| 1689 | &miss, // When not a number. |
| 1690 | &index_out_of_range, |
| 1691 | STRING_INDEX_IS_NUMBER); |
| 1692 | char_at_generator.GenerateFast(masm()); |
| 1693 | __ ret((argc + 1) * kPointerSize); |
| 1694 | |
| 1695 | ICRuntimeCallHelper call_helper; |
| 1696 | char_at_generator.GenerateSlow(masm(), call_helper); |
| 1697 | |
| 1698 | __ bind(&index_out_of_range); |
| 1699 | __ Set(eax, Immediate(Factory::empty_string())); |
| 1700 | __ ret((argc + 1) * kPointerSize); |
| 1701 | |
| 1702 | __ bind(&miss); |
| 1703 | // Restore function name in ecx. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1704 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1705 | GenerateMissBranch(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1706 | |
| 1707 | // Return the generated code. |
| 1708 | return GetCode(function); |
| 1709 | } |
| 1710 | |
| 1711 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1712 | Object* CallStubCompiler::CompileCallConstant(Object* object, |
| 1713 | JSObject* holder, |
| 1714 | JSFunction* function, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1715 | String* name, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1716 | CheckType check) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1717 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1718 | // -- ecx : name |
| 1719 | // -- esp[0] : return address |
| 1720 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1721 | // -- ... |
| 1722 | // -- esp[(argc + 1) * 4] : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1723 | // ----------------------------------- |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1724 | |
| 1725 | SharedFunctionInfo* function_info = function->shared(); |
| 1726 | if (function_info->HasCustomCallGenerator()) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1727 | const int id = function_info->custom_call_generator_id(); |
| 1728 | Object* result = |
| 1729 | CompileCustomCall(id, object, holder, function, name, check); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1730 | // undefined means bail out to regular compiler. |
| 1731 | if (!result->IsUndefined()) { |
| 1732 | return result; |
| 1733 | } |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
sgjesse@chromium.org | 534ae57 | 2010-02-24 22:09:39 +0000 | [diff] [blame] | 1736 | Label miss_in_smi_check; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1737 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1738 | GenerateNameCheck(name, &miss_in_smi_check); |
| 1739 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1740 | // Get the receiver from the stack. |
| 1741 | const int argc = arguments().immediate(); |
| 1742 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1743 | |
| 1744 | // Check that the receiver isn't a smi. |
| 1745 | if (check != NUMBER_CHECK) { |
| 1746 | __ test(edx, Immediate(kSmiTagMask)); |
sgjesse@chromium.org | 534ae57 | 2010-02-24 22:09:39 +0000 | [diff] [blame] | 1747 | __ j(zero, &miss_in_smi_check, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1750 | // Make sure that it's okay not to patch the on stack receiver |
| 1751 | // unless we're doing a receiver map check. |
| 1752 | ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK); |
| 1753 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1754 | CallOptimization optimization(function); |
| 1755 | int depth = kInvalidProtoDepth; |
sgjesse@chromium.org | 534ae57 | 2010-02-24 22:09:39 +0000 | [diff] [blame] | 1756 | Label miss; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1757 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | switch (check) { |
| 1759 | case RECEIVER_MAP_CHECK: |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1760 | __ IncrementCounter(&Counters::call_const, 1); |
| 1761 | |
| 1762 | if (optimization.is_simple_api_call() && !object->IsGlobalObject()) { |
| 1763 | depth = optimization.GetPrototypeDepthOfExpectedType( |
| 1764 | JSObject::cast(object), holder); |
| 1765 | } |
| 1766 | |
| 1767 | if (depth != kInvalidProtoDepth) { |
| 1768 | __ IncrementCounter(&Counters::call_const_fast_api, 1); |
| 1769 | ReserveSpaceForFastApiCall(masm(), eax); |
| 1770 | } |
| 1771 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1772 | // Check that the maps haven't changed. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1773 | CheckPrototypes(JSObject::cast(object), edx, holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1774 | ebx, eax, edi, name, depth, &miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1775 | |
| 1776 | // Patch the receiver on the stack with the global proxy if |
| 1777 | // necessary. |
| 1778 | if (object->IsGlobalObject()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1779 | ASSERT(depth == kInvalidProtoDepth); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1780 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1781 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1782 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1783 | break; |
| 1784 | |
| 1785 | case STRING_CHECK: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1786 | if (!function->IsBuiltin()) { |
| 1787 | // Calling non-builtins with a value as receiver requires boxing. |
| 1788 | __ jmp(&miss); |
| 1789 | } else { |
| 1790 | // Check that the object is a string or a symbol. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1791 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1792 | __ j(above_equal, &miss, not_taken); |
| 1793 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1794 | GenerateDirectLoadGlobalFunctionPrototype( |
| 1795 | masm(), Context::STRING_FUNCTION_INDEX, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1796 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1797 | ebx, edx, edi, name, &miss); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1798 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1799 | break; |
| 1800 | |
| 1801 | case NUMBER_CHECK: { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1802 | if (!function->IsBuiltin()) { |
| 1803 | // Calling non-builtins with a value as receiver requires boxing. |
| 1804 | __ jmp(&miss); |
| 1805 | } else { |
| 1806 | Label fast; |
| 1807 | // Check that the object is a smi or a heap number. |
| 1808 | __ test(edx, Immediate(kSmiTagMask)); |
| 1809 | __ j(zero, &fast, taken); |
| 1810 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, eax); |
| 1811 | __ j(not_equal, &miss, not_taken); |
| 1812 | __ bind(&fast); |
| 1813 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1814 | GenerateDirectLoadGlobalFunctionPrototype( |
| 1815 | masm(), Context::NUMBER_FUNCTION_INDEX, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1816 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1817 | ebx, edx, edi, name, &miss); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1818 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1819 | break; |
| 1820 | } |
| 1821 | |
| 1822 | case BOOLEAN_CHECK: { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1823 | if (!function->IsBuiltin()) { |
| 1824 | // Calling non-builtins with a value as receiver requires boxing. |
| 1825 | __ jmp(&miss); |
| 1826 | } else { |
| 1827 | Label fast; |
| 1828 | // Check that the object is a boolean. |
| 1829 | __ cmp(edx, Factory::true_value()); |
| 1830 | __ j(equal, &fast, taken); |
| 1831 | __ cmp(edx, Factory::false_value()); |
| 1832 | __ j(not_equal, &miss, not_taken); |
| 1833 | __ bind(&fast); |
| 1834 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1835 | GenerateDirectLoadGlobalFunctionPrototype( |
| 1836 | masm(), Context::BOOLEAN_FUNCTION_INDEX, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1837 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1838 | ebx, edx, edi, name, &miss); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1839 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1840 | break; |
| 1841 | } |
| 1842 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1843 | default: |
| 1844 | UNREACHABLE(); |
| 1845 | } |
| 1846 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1847 | if (depth != kInvalidProtoDepth) { |
| 1848 | GenerateFastApiCall(masm(), optimization, argc); |
| 1849 | } else { |
| 1850 | __ InvokeFunction(function, arguments(), JUMP_FUNCTION); |
| 1851 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1852 | |
| 1853 | // Handle call cache miss. |
| 1854 | __ bind(&miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1855 | if (depth != kInvalidProtoDepth) { |
| 1856 | FreeSpaceForFastApiCall(masm(), eax); |
| 1857 | } |
sgjesse@chromium.org | 534ae57 | 2010-02-24 22:09:39 +0000 | [diff] [blame] | 1858 | __ bind(&miss_in_smi_check); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1859 | GenerateMissBranch(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1860 | |
| 1861 | // Return the generated code. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1862 | return GetCode(function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1866 | Object* CallStubCompiler::CompileCallInterceptor(JSObject* object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1867 | JSObject* holder, |
| 1868 | String* name) { |
| 1869 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1870 | // -- ecx : name |
| 1871 | // -- esp[0] : return address |
| 1872 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1873 | // -- ... |
| 1874 | // -- esp[(argc + 1) * 4] : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1875 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1876 | Label miss; |
| 1877 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1878 | GenerateNameCheck(name, &miss); |
| 1879 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1880 | // Get the number of arguments. |
| 1881 | const int argc = arguments().immediate(); |
| 1882 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1883 | LookupResult lookup; |
| 1884 | LookupPostInterceptor(holder, name, &lookup); |
| 1885 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1886 | // Get the receiver from the stack. |
| 1887 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1888 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1889 | CallInterceptorCompiler compiler(this, arguments(), ecx); |
| 1890 | compiler.Compile(masm(), |
| 1891 | object, |
| 1892 | holder, |
| 1893 | name, |
| 1894 | &lookup, |
| 1895 | edx, |
| 1896 | ebx, |
| 1897 | edi, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1898 | eax, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1899 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1900 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1901 | // Restore receiver. |
| 1902 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1903 | |
| 1904 | // Check that the function really is a function. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1905 | __ test(eax, Immediate(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1906 | __ j(zero, &miss, not_taken); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1907 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1908 | __ j(not_equal, &miss, not_taken); |
| 1909 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1910 | // Patch the receiver on the stack with the global proxy if |
| 1911 | // necessary. |
| 1912 | if (object->IsGlobalObject()) { |
| 1913 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1914 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1915 | } |
| 1916 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1917 | // Invoke the function. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1918 | __ mov(edi, eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1919 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION); |
| 1920 | |
| 1921 | // Handle load cache miss. |
| 1922 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1923 | GenerateMissBranch(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1924 | |
| 1925 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1926 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1930 | Object* CallStubCompiler::CompileCallGlobal(JSObject* object, |
| 1931 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1932 | JSGlobalPropertyCell* cell, |
| 1933 | JSFunction* function, |
| 1934 | String* name) { |
| 1935 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1936 | // -- ecx : name |
| 1937 | // -- esp[0] : return address |
| 1938 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1939 | // -- ... |
| 1940 | // -- esp[(argc + 1) * 4] : receiver |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1941 | // ----------------------------------- |
| 1942 | Label miss; |
| 1943 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1944 | GenerateNameCheck(name, &miss); |
| 1945 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1946 | // Get the number of arguments. |
| 1947 | const int argc = arguments().immediate(); |
| 1948 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1949 | // Get the receiver from the stack. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1950 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1951 | |
| 1952 | // If the object is the holder then we know that it's a global |
| 1953 | // object which can only happen for contextual calls. In this case, |
| 1954 | // the receiver cannot be a smi. |
| 1955 | if (object != holder) { |
| 1956 | __ test(edx, Immediate(kSmiTagMask)); |
| 1957 | __ j(zero, &miss, not_taken); |
| 1958 | } |
| 1959 | |
| 1960 | // Check that the maps haven't changed. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1961 | CheckPrototypes(object, edx, holder, ebx, eax, edi, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1962 | |
| 1963 | // Get the value from the cell. |
| 1964 | __ mov(edi, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1965 | __ mov(edi, FieldOperand(edi, JSGlobalPropertyCell::kValueOffset)); |
| 1966 | |
| 1967 | // Check that the cell contains the same function. |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1968 | if (Heap::InNewSpace(function)) { |
| 1969 | // We can't embed a pointer to a function in new space so we have |
| 1970 | // to verify that the shared function info is unchanged. This has |
| 1971 | // the nice side effect that multiple closures based on the same |
| 1972 | // function can all use this call IC. Before we load through the |
| 1973 | // function, we have to verify that it still is a function. |
| 1974 | __ test(edi, Immediate(kSmiTagMask)); |
| 1975 | __ j(zero, &miss, not_taken); |
| 1976 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ebx); |
| 1977 | __ j(not_equal, &miss, not_taken); |
| 1978 | |
| 1979 | // Check the shared function info. Make sure it hasn't changed. |
| 1980 | __ cmp(FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset), |
| 1981 | Immediate(Handle<SharedFunctionInfo>(function->shared()))); |
| 1982 | __ j(not_equal, &miss, not_taken); |
| 1983 | } else { |
| 1984 | __ cmp(Operand(edi), Immediate(Handle<JSFunction>(function))); |
| 1985 | __ j(not_equal, &miss, not_taken); |
| 1986 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1987 | |
| 1988 | // Patch the receiver on the stack with the global proxy. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1989 | if (object->IsGlobalObject()) { |
| 1990 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1991 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1992 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1993 | |
| 1994 | // Setup the context (function already in edi). |
| 1995 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1996 | |
| 1997 | // Jump to the cached code (tail call). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1998 | __ IncrementCounter(&Counters::call_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1999 | ASSERT(function->is_compiled()); |
| 2000 | Handle<Code> code(function->code()); |
| 2001 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 2002 | __ InvokeCode(code, expected, arguments(), |
| 2003 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
| 2004 | |
| 2005 | // Handle call cache miss. |
| 2006 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2007 | __ IncrementCounter(&Counters::call_global_inline_miss, 1); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2008 | GenerateMissBranch(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2009 | |
| 2010 | // Return the generated code. |
| 2011 | return GetCode(NORMAL, name); |
| 2012 | } |
| 2013 | |
| 2014 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2015 | Object* StoreStubCompiler::CompileStoreField(JSObject* object, |
| 2016 | int index, |
| 2017 | Map* transition, |
| 2018 | String* name) { |
| 2019 | // ----------- S t a t e ------------- |
| 2020 | // -- eax : value |
| 2021 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2022 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2023 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2024 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2025 | Label miss; |
| 2026 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2027 | // Generate store field code. Trashes the name register. |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 2028 | GenerateStoreField(masm(), |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 2029 | object, |
| 2030 | index, |
| 2031 | transition, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2032 | edx, ecx, ebx, |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 2033 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2034 | |
| 2035 | // Handle store cache miss. |
| 2036 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2037 | __ mov(ecx, Immediate(Handle<String>(name))); // restore name |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2038 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2039 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2040 | |
| 2041 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2042 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | |
| 2046 | Object* StoreStubCompiler::CompileStoreCallback(JSObject* object, |
| 2047 | AccessorInfo* callback, |
| 2048 | String* name) { |
| 2049 | // ----------- S t a t e ------------- |
| 2050 | // -- eax : value |
| 2051 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2052 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2053 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2054 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2055 | Label miss; |
| 2056 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2057 | // Check that the object isn't a smi. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2058 | __ test(edx, Immediate(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2059 | __ j(zero, &miss, not_taken); |
| 2060 | |
| 2061 | // Check that the map of the object hasn't changed. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2062 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2063 | Immediate(Handle<Map>(object->map()))); |
| 2064 | __ j(not_equal, &miss, not_taken); |
| 2065 | |
| 2066 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2067 | if (object->IsJSGlobalProxy()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2068 | __ CheckAccessGlobalProxy(edx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | // Stub never generated for non-global objects that require access |
| 2072 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2073 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2074 | |
| 2075 | __ pop(ebx); // remove the return address |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2076 | __ push(edx); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2077 | __ push(Immediate(Handle<AccessorInfo>(callback))); // callback info |
| 2078 | __ push(ecx); // name |
| 2079 | __ push(eax); // value |
| 2080 | __ push(ebx); // restore return address |
| 2081 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2082 | // Do tail-call to the runtime system. |
| 2083 | ExternalReference store_callback_property = |
| 2084 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2085 | __ TailCallExternalReference(store_callback_property, 4, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2086 | |
| 2087 | // Handle store cache miss. |
| 2088 | __ bind(&miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2089 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2090 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2091 | |
| 2092 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2093 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | |
| 2097 | Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver, |
| 2098 | String* name) { |
| 2099 | // ----------- S t a t e ------------- |
| 2100 | // -- eax : value |
| 2101 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2102 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2103 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2104 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2105 | Label miss; |
| 2106 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2107 | // Check that the object isn't a smi. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2108 | __ test(edx, Immediate(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2109 | __ j(zero, &miss, not_taken); |
| 2110 | |
| 2111 | // Check that the map of the object hasn't changed. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2112 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2113 | Immediate(Handle<Map>(receiver->map()))); |
| 2114 | __ j(not_equal, &miss, not_taken); |
| 2115 | |
| 2116 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2117 | if (receiver->IsJSGlobalProxy()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2118 | __ CheckAccessGlobalProxy(edx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | // Stub never generated for non-global objects that require access |
| 2122 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2123 | ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2124 | |
| 2125 | __ pop(ebx); // remove the return address |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2126 | __ push(edx); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2127 | __ push(ecx); // name |
| 2128 | __ push(eax); // value |
| 2129 | __ push(ebx); // restore return address |
| 2130 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2131 | // Do tail-call to the runtime system. |
| 2132 | ExternalReference store_ic_property = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2133 | ExternalReference(IC_Utility(IC::kStoreInterceptorProperty)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2134 | __ TailCallExternalReference(store_ic_property, 3, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2135 | |
| 2136 | // Handle store cache miss. |
| 2137 | __ bind(&miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2138 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2139 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2140 | |
| 2141 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2142 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2146 | Object* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object, |
| 2147 | JSGlobalPropertyCell* cell, |
| 2148 | String* name) { |
| 2149 | // ----------- S t a t e ------------- |
| 2150 | // -- eax : value |
| 2151 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2152 | // -- edx : receiver |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2153 | // -- esp[0] : return address |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2154 | // ----------------------------------- |
| 2155 | Label miss; |
| 2156 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2157 | // Check that the map of the global has not changed. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2158 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2159 | Immediate(Handle<Map>(object->map()))); |
| 2160 | __ j(not_equal, &miss, not_taken); |
| 2161 | |
| 2162 | // Store the value in the cell. |
| 2163 | __ mov(ecx, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 2164 | __ mov(FieldOperand(ecx, JSGlobalPropertyCell::kValueOffset), eax); |
| 2165 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2166 | // Return the value (register eax). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2167 | __ IncrementCounter(&Counters::named_store_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2168 | __ ret(0); |
| 2169 | |
| 2170 | // Handle store cache miss. |
| 2171 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2172 | __ IncrementCounter(&Counters::named_store_global_inline_miss, 1); |
| 2173 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
| 2174 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 2175 | |
| 2176 | // Return the generated code. |
| 2177 | return GetCode(NORMAL, name); |
| 2178 | } |
| 2179 | |
| 2180 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2181 | Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object, |
| 2182 | int index, |
| 2183 | Map* transition, |
| 2184 | String* name) { |
| 2185 | // ----------- S t a t e ------------- |
| 2186 | // -- eax : value |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2187 | // -- ecx : key |
| 2188 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2189 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2190 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2191 | Label miss; |
| 2192 | |
| 2193 | __ IncrementCounter(&Counters::keyed_store_field, 1); |
| 2194 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2195 | // Check that the name has not changed. |
| 2196 | __ cmp(Operand(ecx), Immediate(Handle<String>(name))); |
| 2197 | __ j(not_equal, &miss, not_taken); |
| 2198 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2199 | // Generate store field code. Trashes the name register. |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 2200 | GenerateStoreField(masm(), |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 2201 | object, |
| 2202 | index, |
| 2203 | transition, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2204 | edx, ecx, ebx, |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 2205 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2206 | |
| 2207 | // Handle store cache miss. |
| 2208 | __ bind(&miss); |
| 2209 | __ DecrementCounter(&Counters::keyed_store_field, 1); |
| 2210 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2211 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2212 | |
| 2213 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2214 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2218 | Object* LoadStubCompiler::CompileLoadNonexistent(String* name, |
| 2219 | JSObject* object, |
| 2220 | JSObject* last) { |
| 2221 | // ----------- S t a t e ------------- |
| 2222 | // -- eax : receiver |
| 2223 | // -- ecx : name |
| 2224 | // -- esp[0] : return address |
| 2225 | // ----------------------------------- |
| 2226 | Label miss; |
| 2227 | |
| 2228 | // Check that the receiver isn't a smi. |
| 2229 | __ test(eax, Immediate(kSmiTagMask)); |
| 2230 | __ j(zero, &miss, not_taken); |
| 2231 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2232 | ASSERT(last->IsGlobalObject() || last->HasFastProperties()); |
| 2233 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2234 | // Check the maps of the full prototype chain. Also check that |
| 2235 | // global property cells up to (but not including) the last object |
| 2236 | // in the prototype chain are empty. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2237 | CheckPrototypes(object, eax, last, ebx, edx, edi, name, &miss); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2238 | |
| 2239 | // If the last object in the prototype chain is a global object, |
| 2240 | // check that the global property cell is empty. |
| 2241 | if (last->IsGlobalObject()) { |
| 2242 | Object* cell = GenerateCheckPropertyCell(masm(), |
| 2243 | GlobalObject::cast(last), |
| 2244 | name, |
| 2245 | edx, |
| 2246 | &miss); |
| 2247 | if (cell->IsFailure()) return cell; |
| 2248 | } |
| 2249 | |
| 2250 | // Return undefined if maps of the full prototype chain are still the |
| 2251 | // same and no global property with this name contains a value. |
| 2252 | __ mov(eax, Factory::undefined_value()); |
| 2253 | __ ret(0); |
| 2254 | |
| 2255 | __ bind(&miss); |
| 2256 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2257 | |
| 2258 | // Return the generated code. |
| 2259 | return GetCode(NONEXISTENT, Heap::empty_string()); |
| 2260 | } |
| 2261 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2262 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2263 | Object* LoadStubCompiler::CompileLoadField(JSObject* object, |
| 2264 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2265 | int index, |
| 2266 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2267 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2268 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2269 | // -- ecx : name |
| 2270 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2271 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2272 | Label miss; |
| 2273 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2274 | GenerateLoadField(object, holder, eax, ebx, edx, edi, index, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2275 | __ bind(&miss); |
| 2276 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2277 | |
| 2278 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2279 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2283 | Object* LoadStubCompiler::CompileLoadCallback(String* name, |
| 2284 | JSObject* object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2285 | JSObject* holder, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2286 | AccessorInfo* callback) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2287 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2288 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2289 | // -- ecx : name |
| 2290 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2291 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2292 | Label miss; |
| 2293 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2294 | Failure* failure = Failure::InternalError(); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2295 | bool success = GenerateLoadCallback(object, holder, eax, ecx, ebx, edx, edi, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2296 | callback, name, &miss, &failure); |
| 2297 | if (!success) return failure; |
| 2298 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2299 | __ bind(&miss); |
| 2300 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2301 | |
| 2302 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2303 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | |
| 2307 | Object* LoadStubCompiler::CompileLoadConstant(JSObject* object, |
| 2308 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2309 | Object* value, |
| 2310 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2311 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2312 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2313 | // -- ecx : name |
| 2314 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2315 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2316 | Label miss; |
| 2317 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2318 | GenerateLoadConstant(object, holder, eax, ebx, edx, edi, value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2319 | __ bind(&miss); |
| 2320 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2321 | |
| 2322 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2323 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | |
| 2327 | Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 2328 | JSObject* holder, |
| 2329 | String* name) { |
| 2330 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2331 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2332 | // -- ecx : name |
| 2333 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2334 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2335 | Label miss; |
| 2336 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2337 | LookupResult lookup; |
| 2338 | LookupPostInterceptor(holder, name, &lookup); |
| 2339 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2340 | // TODO(368): Compile in the whole chain: all the interceptors in |
| 2341 | // prototypes and ultimate answer. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2342 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2343 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2344 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2345 | eax, |
| 2346 | ecx, |
| 2347 | edx, |
| 2348 | ebx, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2349 | edi, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2350 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2351 | &miss); |
| 2352 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2353 | __ bind(&miss); |
| 2354 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2355 | |
| 2356 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2357 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2361 | Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object, |
| 2362 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2363 | JSGlobalPropertyCell* cell, |
| 2364 | String* name, |
| 2365 | bool is_dont_delete) { |
| 2366 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2367 | // -- eax : receiver |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2368 | // -- ecx : name |
| 2369 | // -- esp[0] : return address |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2370 | // ----------------------------------- |
| 2371 | Label miss; |
| 2372 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2373 | // If the object is the holder then we know that it's a global |
| 2374 | // object which can only happen for contextual loads. In this case, |
| 2375 | // the receiver cannot be a smi. |
| 2376 | if (object != holder) { |
| 2377 | __ test(eax, Immediate(kSmiTagMask)); |
| 2378 | __ j(zero, &miss, not_taken); |
| 2379 | } |
| 2380 | |
| 2381 | // Check that the maps haven't changed. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2382 | CheckPrototypes(object, eax, holder, ebx, edx, edi, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2383 | |
| 2384 | // Get the value from the cell. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2385 | __ mov(ebx, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 2386 | __ mov(ebx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2387 | |
| 2388 | // Check for deleted property if property can actually be deleted. |
| 2389 | if (!is_dont_delete) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2390 | __ cmp(ebx, Factory::the_hole_value()); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2391 | __ j(equal, &miss, not_taken); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2392 | } else if (FLAG_debug_code) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2393 | __ cmp(ebx, Factory::the_hole_value()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2394 | __ Check(not_equal, "DontDelete cells can't contain the hole"); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2397 | __ IncrementCounter(&Counters::named_load_global_inline, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2398 | __ mov(eax, ebx); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2399 | __ ret(0); |
| 2400 | |
| 2401 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2402 | __ IncrementCounter(&Counters::named_load_global_inline_miss, 1); |
| 2403 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2404 | |
| 2405 | // Return the generated code. |
| 2406 | return GetCode(NORMAL, name); |
| 2407 | } |
| 2408 | |
| 2409 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2410 | Object* KeyedLoadStubCompiler::CompileLoadField(String* name, |
| 2411 | JSObject* receiver, |
| 2412 | JSObject* holder, |
| 2413 | int index) { |
| 2414 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2415 | // -- eax : key |
| 2416 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2417 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2418 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2419 | Label miss; |
| 2420 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2421 | __ IncrementCounter(&Counters::keyed_load_field, 1); |
| 2422 | |
| 2423 | // Check that the name has not changed. |
| 2424 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2425 | __ j(not_equal, &miss, not_taken); |
| 2426 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2427 | GenerateLoadField(receiver, holder, edx, ebx, ecx, edi, index, name, &miss); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2428 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2429 | __ bind(&miss); |
| 2430 | __ DecrementCounter(&Counters::keyed_load_field, 1); |
| 2431 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2432 | |
| 2433 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2434 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | |
| 2438 | Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name, |
| 2439 | JSObject* receiver, |
| 2440 | JSObject* holder, |
| 2441 | AccessorInfo* callback) { |
| 2442 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2443 | // -- eax : key |
| 2444 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2445 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2446 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2447 | Label miss; |
| 2448 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2449 | __ IncrementCounter(&Counters::keyed_load_callback, 1); |
| 2450 | |
| 2451 | // Check that the name has not changed. |
| 2452 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2453 | __ j(not_equal, &miss, not_taken); |
| 2454 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2455 | Failure* failure = Failure::InternalError(); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2456 | bool success = GenerateLoadCallback(receiver, holder, edx, eax, ebx, ecx, edi, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2457 | callback, name, &miss, &failure); |
| 2458 | if (!success) return failure; |
| 2459 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2460 | __ bind(&miss); |
| 2461 | __ DecrementCounter(&Counters::keyed_load_callback, 1); |
| 2462 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2463 | |
| 2464 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2465 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | |
| 2469 | Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name, |
| 2470 | JSObject* receiver, |
| 2471 | JSObject* holder, |
| 2472 | Object* value) { |
| 2473 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2474 | // -- eax : key |
| 2475 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2476 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2477 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2478 | Label miss; |
| 2479 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2480 | __ IncrementCounter(&Counters::keyed_load_constant_function, 1); |
| 2481 | |
| 2482 | // Check that the name has not changed. |
| 2483 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2484 | __ j(not_equal, &miss, not_taken); |
| 2485 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2486 | GenerateLoadConstant(receiver, holder, edx, ebx, ecx, edi, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2487 | value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2488 | __ bind(&miss); |
| 2489 | __ DecrementCounter(&Counters::keyed_load_constant_function, 1); |
| 2490 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2491 | |
| 2492 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2493 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | |
| 2497 | Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 2498 | JSObject* holder, |
| 2499 | String* name) { |
| 2500 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2501 | // -- eax : key |
| 2502 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2503 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2504 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2505 | Label miss; |
| 2506 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2507 | __ IncrementCounter(&Counters::keyed_load_interceptor, 1); |
| 2508 | |
| 2509 | // Check that the name has not changed. |
| 2510 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2511 | __ j(not_equal, &miss, not_taken); |
| 2512 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2513 | LookupResult lookup; |
| 2514 | LookupPostInterceptor(holder, name, &lookup); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2515 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2516 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2517 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2518 | edx, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2519 | eax, |
| 2520 | ecx, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2521 | ebx, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2522 | edi, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2523 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2524 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2525 | __ bind(&miss); |
| 2526 | __ DecrementCounter(&Counters::keyed_load_interceptor, 1); |
| 2527 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2528 | |
| 2529 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2530 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | |
| 2534 | |
| 2535 | |
| 2536 | Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) { |
| 2537 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2538 | // -- eax : key |
| 2539 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2540 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2541 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2542 | Label miss; |
| 2543 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2544 | __ IncrementCounter(&Counters::keyed_load_array_length, 1); |
| 2545 | |
| 2546 | // Check that the name has not changed. |
| 2547 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2548 | __ j(not_equal, &miss, not_taken); |
| 2549 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2550 | GenerateLoadArrayLength(masm(), edx, ecx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2551 | __ bind(&miss); |
| 2552 | __ DecrementCounter(&Counters::keyed_load_array_length, 1); |
| 2553 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2554 | |
| 2555 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2556 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2560 | Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2561 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2562 | // -- eax : key |
| 2563 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2564 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2565 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2566 | Label miss; |
| 2567 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2568 | __ IncrementCounter(&Counters::keyed_load_string_length, 1); |
| 2569 | |
| 2570 | // Check that the name has not changed. |
| 2571 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2572 | __ j(not_equal, &miss, not_taken); |
| 2573 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2574 | GenerateLoadStringLength(masm(), edx, ecx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2575 | __ bind(&miss); |
| 2576 | __ DecrementCounter(&Counters::keyed_load_string_length, 1); |
| 2577 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2578 | |
| 2579 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2580 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | |
| 2584 | Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) { |
| 2585 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2586 | // -- eax : key |
| 2587 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2588 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2589 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2590 | Label miss; |
| 2591 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2592 | __ IncrementCounter(&Counters::keyed_load_function_prototype, 1); |
| 2593 | |
| 2594 | // Check that the name has not changed. |
| 2595 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2596 | __ j(not_equal, &miss, not_taken); |
| 2597 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2598 | GenerateLoadFunctionPrototype(masm(), edx, ecx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2599 | __ bind(&miss); |
| 2600 | __ DecrementCounter(&Counters::keyed_load_function_prototype, 1); |
| 2601 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2602 | |
| 2603 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2604 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2608 | // Specialized stub for constructing objects from functions which only have only |
| 2609 | // simple assignments of the form this.x = ...; in their body. |
| 2610 | Object* ConstructStubCompiler::CompileConstructStub( |
| 2611 | SharedFunctionInfo* shared) { |
| 2612 | // ----------- S t a t e ------------- |
| 2613 | // -- eax : argc |
| 2614 | // -- edi : constructor |
| 2615 | // -- esp[0] : return address |
| 2616 | // -- esp[4] : last argument |
| 2617 | // ----------------------------------- |
| 2618 | Label generic_stub_call; |
| 2619 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 2620 | // Check to see whether there are any break points in the function code. If |
| 2621 | // there are jump to the generic constructor stub which calls the actual |
| 2622 | // code for the function thereby hitting the break points. |
| 2623 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2624 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kDebugInfoOffset)); |
| 2625 | __ cmp(ebx, Factory::undefined_value()); |
| 2626 | __ j(not_equal, &generic_stub_call, not_taken); |
| 2627 | #endif |
| 2628 | |
| 2629 | // Load the initial map and verify that it is in fact a map. |
| 2630 | __ mov(ebx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2631 | // Will both indicate a NULL and a Smi. |
| 2632 | __ test(ebx, Immediate(kSmiTagMask)); |
| 2633 | __ j(zero, &generic_stub_call); |
| 2634 | __ CmpObjectType(ebx, MAP_TYPE, ecx); |
| 2635 | __ j(not_equal, &generic_stub_call); |
| 2636 | |
| 2637 | #ifdef DEBUG |
| 2638 | // Cannot construct functions this way. |
| 2639 | // edi: constructor |
| 2640 | // ebx: initial map |
| 2641 | __ CmpInstanceType(ebx, JS_FUNCTION_TYPE); |
| 2642 | __ Assert(not_equal, "Function constructed by construct stub."); |
| 2643 | #endif |
| 2644 | |
| 2645 | // Now allocate the JSObject on the heap by moving the new space allocation |
| 2646 | // top forward. |
| 2647 | // edi: constructor |
| 2648 | // ebx: initial map |
| 2649 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceSizeOffset)); |
| 2650 | __ shl(ecx, kPointerSizeLog2); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2651 | __ AllocateInNewSpace(ecx, |
| 2652 | edx, |
| 2653 | ecx, |
| 2654 | no_reg, |
| 2655 | &generic_stub_call, |
| 2656 | NO_ALLOCATION_FLAGS); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2657 | |
| 2658 | // Allocated the JSObject, now initialize the fields and add the heap tag. |
| 2659 | // ebx: initial map |
| 2660 | // edx: JSObject (untagged) |
| 2661 | __ mov(Operand(edx, JSObject::kMapOffset), ebx); |
| 2662 | __ mov(ebx, Factory::empty_fixed_array()); |
| 2663 | __ mov(Operand(edx, JSObject::kPropertiesOffset), ebx); |
| 2664 | __ mov(Operand(edx, JSObject::kElementsOffset), ebx); |
| 2665 | |
| 2666 | // Push the allocated object to the stack. This is the object that will be |
| 2667 | // returned (after it is tagged). |
| 2668 | __ push(edx); |
| 2669 | |
| 2670 | // eax: argc |
| 2671 | // edx: JSObject (untagged) |
| 2672 | // Load the address of the first in-object property into edx. |
| 2673 | __ lea(edx, Operand(edx, JSObject::kHeaderSize)); |
| 2674 | // Calculate the location of the first argument. The stack contains the |
| 2675 | // allocated object and the return address on top of the argc arguments. |
| 2676 | __ lea(ecx, Operand(esp, eax, times_4, 1 * kPointerSize)); |
| 2677 | |
| 2678 | // Use edi for holding undefined which is used in several places below. |
| 2679 | __ mov(edi, Factory::undefined_value()); |
| 2680 | |
| 2681 | // eax: argc |
| 2682 | // ecx: first argument |
| 2683 | // edx: first in-object property of the JSObject |
| 2684 | // edi: undefined |
| 2685 | // Fill the initialized properties with a constant value or a passed argument |
| 2686 | // depending on the this.x = ...; assignment in the function. |
| 2687 | for (int i = 0; i < shared->this_property_assignments_count(); i++) { |
| 2688 | if (shared->IsThisPropertyAssignmentArgument(i)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2689 | // Check if the argument assigned to the property is actually passed. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2690 | // If argument is not passed the property is set to undefined, |
| 2691 | // otherwise find it on the stack. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2692 | int arg_number = shared->GetThisPropertyAssignmentArgument(i); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2693 | __ mov(ebx, edi); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2694 | __ cmp(eax, arg_number); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2695 | if (CpuFeatures::IsSupported(CMOV)) { |
| 2696 | CpuFeatures::Scope use_cmov(CMOV); |
| 2697 | __ cmov(above, ebx, Operand(ecx, arg_number * -kPointerSize)); |
| 2698 | } else { |
| 2699 | Label not_passed; |
| 2700 | __ j(below_equal, ¬_passed); |
| 2701 | __ mov(ebx, Operand(ecx, arg_number * -kPointerSize)); |
| 2702 | __ bind(¬_passed); |
| 2703 | } |
| 2704 | // Store value in the property. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2705 | __ mov(Operand(edx, i * kPointerSize), ebx); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2706 | } else { |
| 2707 | // Set the property to the constant value. |
| 2708 | Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i)); |
| 2709 | __ mov(Operand(edx, i * kPointerSize), Immediate(constant)); |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | // Fill the unused in-object property fields with undefined. |
| 2714 | for (int i = shared->this_property_assignments_count(); |
| 2715 | i < shared->CalculateInObjectProperties(); |
| 2716 | i++) { |
| 2717 | __ mov(Operand(edx, i * kPointerSize), edi); |
| 2718 | } |
| 2719 | |
| 2720 | // Move argc to ebx and retrieve and tag the JSObject to return. |
| 2721 | __ mov(ebx, eax); |
| 2722 | __ pop(eax); |
| 2723 | __ or_(Operand(eax), Immediate(kHeapObjectTag)); |
| 2724 | |
| 2725 | // Remove caller arguments and receiver from the stack and return. |
| 2726 | __ pop(ecx); |
| 2727 | __ lea(esp, Operand(esp, ebx, times_pointer_size, 1 * kPointerSize)); |
| 2728 | __ push(ecx); |
| 2729 | __ IncrementCounter(&Counters::constructed_objects, 1); |
| 2730 | __ IncrementCounter(&Counters::constructed_objects_stub, 1); |
| 2731 | __ ret(0); |
| 2732 | |
| 2733 | // Jump to the generic stub in case the specialized code cannot handle the |
| 2734 | // construction. |
| 2735 | __ bind(&generic_stub_call); |
| 2736 | Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); |
| 2737 | Handle<Code> generic_construct_stub(code); |
| 2738 | __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 2739 | |
| 2740 | // Return the generated code. |
| 2741 | return GetCode(); |
| 2742 | } |
| 2743 | |
| 2744 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2745 | #undef __ |
| 2746 | |
| 2747 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2748 | |
| 2749 | #endif // V8_TARGET_ARCH_IA32 |