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