karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1 | // Copyright 2011 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 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 32 | #include "codegen.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | #include "ic-inl.h" |
| 34 | #include "runtime.h" |
| 35 | #include "stub-cache.h" |
| 36 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 37 | namespace v8 { |
| 38 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | // ---------------------------------------------------------------------------- |
| 41 | // Static IC stub generators. |
| 42 | // |
| 43 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 44 | #define __ ACCESS_MASM(masm) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
| 46 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 47 | static void GenerateGlobalInstanceTypeCheck(MacroAssembler* masm, |
| 48 | Register type, |
| 49 | Label* global_object) { |
| 50 | // Register usage: |
| 51 | // type: holds the receiver instance type on entry. |
| 52 | __ cmp(type, JS_GLOBAL_OBJECT_TYPE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 53 | __ j(equal, global_object); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 54 | __ cmp(type, JS_BUILTINS_OBJECT_TYPE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 55 | __ j(equal, global_object); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 56 | __ cmp(type, JS_GLOBAL_PROXY_TYPE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 57 | __ j(equal, global_object); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | |
| 61 | // Generated code falls through if the receiver is a regular non-global |
| 62 | // JS object with slow properties and no interceptors. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 63 | static void GenerateStringDictionaryReceiverCheck(MacroAssembler* masm, |
| 64 | Register receiver, |
| 65 | Register r0, |
| 66 | Register r1, |
| 67 | Label* miss) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 68 | // Register usage: |
| 69 | // receiver: holds the receiver on entry and is unchanged. |
| 70 | // r0: used to hold receiver instance type. |
| 71 | // Holds the property dictionary on fall through. |
| 72 | // r1: used to hold receivers map. |
| 73 | |
| 74 | // Check that the receiver isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 75 | __ JumpIfSmi(receiver, miss); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 76 | |
| 77 | // Check that the receiver is a valid JS object. |
| 78 | __ mov(r1, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 79 | __ movzx_b(r0, FieldOperand(r1, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 80 | __ cmp(r0, FIRST_SPEC_OBJECT_TYPE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 81 | __ j(below, miss); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 82 | |
| 83 | // If this assert fails, we have to check upper bound too. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 84 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 85 | |
| 86 | GenerateGlobalInstanceTypeCheck(masm, r0, miss); |
| 87 | |
| 88 | // Check for non-global object that requires access check. |
| 89 | __ test_b(FieldOperand(r1, Map::kBitFieldOffset), |
| 90 | (1 << Map::kIsAccessCheckNeeded) | |
| 91 | (1 << Map::kHasNamedInterceptor)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 92 | __ j(not_zero, miss); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 93 | |
| 94 | __ mov(r0, FieldOperand(receiver, JSObject::kPropertiesOffset)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 95 | __ CheckMap(r0, FACTORY->hash_table_map(), miss, DONT_DO_SMI_CHECK); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 99 | // Helper function used to load a property from a dictionary backing |
| 100 | // storage. This function may fail to load a property even though it is |
| 101 | // in the dictionary, so code at miss_label must always call a backup |
| 102 | // property load that is complete. This function is safe to call if |
| 103 | // name is not a symbol, and will jump to the miss_label in that |
| 104 | // case. The generated code assumes that the receiver has slow |
| 105 | // properties, is not a global object and does not have interceptors. |
| 106 | static void GenerateDictionaryLoad(MacroAssembler* masm, |
| 107 | Label* miss_label, |
| 108 | Register elements, |
| 109 | Register name, |
| 110 | Register r0, |
| 111 | Register r1, |
| 112 | Register result) { |
| 113 | // Register use: |
| 114 | // |
| 115 | // elements - holds the property dictionary on entry and is unchanged. |
| 116 | // |
| 117 | // name - holds the name of the property on entry and is unchanged. |
| 118 | // |
| 119 | // Scratch registers: |
| 120 | // |
| 121 | // r0 - used for the index into the property dictionary |
| 122 | // |
| 123 | // r1 - used to hold the capacity of the property dictionary. |
| 124 | // |
| 125 | // result - holds the result on exit. |
| 126 | |
| 127 | Label done; |
| 128 | |
| 129 | // Probe the dictionary. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 130 | StringDictionaryLookupStub::GeneratePositiveLookup(masm, |
| 131 | miss_label, |
| 132 | &done, |
| 133 | elements, |
| 134 | name, |
| 135 | r0, |
| 136 | r1); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 137 | |
| 138 | // If probing finds an entry in the dictionary, r0 contains the |
| 139 | // index into the dictionary. Check that the value is a normal |
| 140 | // property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 141 | __ bind(&done); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 142 | const int kElementsStartOffset = |
| 143 | StringDictionary::kHeaderSize + |
| 144 | StringDictionary::kElementsStartIndex * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | const int kDetailsOffset = kElementsStartOffset + 2 * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 146 | __ test(Operand(elements, r0, times_4, kDetailsOffset - kHeapObjectTag), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 147 | Immediate(PropertyDetails::TypeField::mask() << kSmiTagSize)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 148 | __ j(not_zero, miss_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | |
| 150 | // Get the value at the masked, scaled index. |
| 151 | const int kValueOffset = kElementsStartOffset + kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 152 | __ mov(result, Operand(elements, r0, times_4, kValueOffset - kHeapObjectTag)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 156 | // Helper function used to store a property to a dictionary backing |
| 157 | // storage. This function may fail to store a property eventhough it |
| 158 | // is in the dictionary, so code at miss_label must always call a |
| 159 | // backup property store that is complete. This function is safe to |
| 160 | // call if name is not a symbol, and will jump to the miss_label in |
| 161 | // that case. The generated code assumes that the receiver has slow |
| 162 | // properties, is not a global object and does not have interceptors. |
| 163 | static void GenerateDictionaryStore(MacroAssembler* masm, |
| 164 | Label* miss_label, |
| 165 | Register elements, |
| 166 | Register name, |
| 167 | Register value, |
| 168 | Register r0, |
| 169 | Register r1) { |
| 170 | // Register use: |
| 171 | // |
| 172 | // elements - holds the property dictionary on entry and is clobbered. |
| 173 | // |
| 174 | // name - holds the name of the property on entry and is unchanged. |
| 175 | // |
| 176 | // value - holds the value to store and is unchanged. |
| 177 | // |
| 178 | // r0 - used for index into the property dictionary and is clobbered. |
| 179 | // |
| 180 | // r1 - used to hold the capacity of the property dictionary and is clobbered. |
| 181 | Label done; |
| 182 | |
| 183 | |
| 184 | // Probe the dictionary. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 185 | StringDictionaryLookupStub::GeneratePositiveLookup(masm, |
| 186 | miss_label, |
| 187 | &done, |
| 188 | elements, |
| 189 | name, |
| 190 | r0, |
| 191 | r1); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 192 | |
| 193 | // If probing finds an entry in the dictionary, r0 contains the |
| 194 | // index into the dictionary. Check that the value is a normal |
| 195 | // property that is not read only. |
| 196 | __ bind(&done); |
| 197 | const int kElementsStartOffset = |
| 198 | StringDictionary::kHeaderSize + |
| 199 | StringDictionary::kElementsStartIndex * kPointerSize; |
| 200 | const int kDetailsOffset = kElementsStartOffset + 2 * kPointerSize; |
| 201 | const int kTypeAndReadOnlyMask |
| 202 | = (PropertyDetails::TypeField::mask() | |
| 203 | PropertyDetails::AttributesField::encode(READ_ONLY)) << kSmiTagSize; |
| 204 | __ test(Operand(elements, r0, times_4, kDetailsOffset - kHeapObjectTag), |
| 205 | Immediate(kTypeAndReadOnlyMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 206 | __ j(not_zero, miss_label); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 207 | |
| 208 | // Store the value at the masked, scaled index. |
| 209 | const int kValueOffset = kElementsStartOffset + kPointerSize; |
| 210 | __ lea(r0, Operand(elements, r0, times_4, kValueOffset - kHeapObjectTag)); |
| 211 | __ mov(Operand(r0, 0), value); |
| 212 | |
| 213 | // Update write barrier. Make sure not to clobber the value. |
| 214 | __ mov(r1, value); |
| 215 | __ RecordWrite(elements, r0, r1); |
| 216 | } |
| 217 | |
| 218 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | void LoadIC::GenerateArrayLength(MacroAssembler* masm) { |
| 220 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 221 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | // -- ecx : name |
| 223 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | Label miss; |
| 226 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | StubCompiler::GenerateLoadArrayLength(masm, eax, edx, &miss); |
| 228 | __ bind(&miss); |
| 229 | StubCompiler::GenerateLoadMiss(masm, Code::LOAD_IC); |
| 230 | } |
| 231 | |
| 232 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 233 | void LoadIC::GenerateStringLength(MacroAssembler* masm, |
| 234 | bool support_wrappers) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 236 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 237 | // -- ecx : name |
| 238 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | Label miss; |
| 241 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 242 | StubCompiler::GenerateLoadStringLength(masm, eax, edx, ebx, &miss, |
| 243 | support_wrappers); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | __ bind(&miss); |
| 245 | StubCompiler::GenerateLoadMiss(masm, Code::LOAD_IC); |
| 246 | } |
| 247 | |
| 248 | |
| 249 | void LoadIC::GenerateFunctionPrototype(MacroAssembler* masm) { |
| 250 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 251 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 252 | // -- ecx : name |
| 253 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 254 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | Label miss; |
| 256 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | StubCompiler::GenerateLoadFunctionPrototype(masm, eax, edx, ebx, &miss); |
| 258 | __ bind(&miss); |
| 259 | StubCompiler::GenerateLoadMiss(masm, Code::LOAD_IC); |
| 260 | } |
| 261 | |
| 262 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 263 | // Checks the receiver for special cases (value type, slow case bits). |
| 264 | // Falls through for regular JS object. |
| 265 | static void GenerateKeyedLoadReceiverCheck(MacroAssembler* masm, |
| 266 | Register receiver, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 267 | Register map, |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 268 | int interceptor_bit, |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 269 | Label* slow) { |
| 270 | // Register use: |
| 271 | // receiver - holds the receiver and is unchanged. |
| 272 | // Scratch registers: |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 273 | // map - used to hold the map of the receiver. |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 274 | |
| 275 | // Check that the object isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 276 | __ JumpIfSmi(receiver, slow); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 277 | |
| 278 | // Get the map of the receiver. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 279 | __ mov(map, FieldOperand(receiver, HeapObject::kMapOffset)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 280 | |
| 281 | // Check bit field. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 282 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 283 | (1 << Map::kIsAccessCheckNeeded) | (1 << interceptor_bit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 284 | __ j(not_zero, slow); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 285 | // Check that the object is some kind of JS object EXCEPT JS Value type. |
| 286 | // In the case that the object is a value-wrapper object, |
| 287 | // we enter the runtime system to make sure that indexing |
| 288 | // into string objects works as intended. |
| 289 | ASSERT(JS_OBJECT_TYPE > JS_VALUE_TYPE); |
| 290 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 291 | __ CmpInstanceType(map, JS_OBJECT_TYPE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 292 | __ j(below, slow); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
| 296 | // Loads an indexed element from a fast case array. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 297 | // If not_fast_array is NULL, doesn't perform the elements map check. |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 298 | static void GenerateFastArrayLoad(MacroAssembler* masm, |
| 299 | Register receiver, |
| 300 | Register key, |
| 301 | Register scratch, |
| 302 | Register result, |
| 303 | Label* not_fast_array, |
| 304 | Label* out_of_range) { |
| 305 | // Register use: |
| 306 | // receiver - holds the receiver and is unchanged. |
| 307 | // key - holds the key and is unchanged (must be a smi). |
| 308 | // Scratch registers: |
| 309 | // scratch - used to hold elements of the receiver and the loaded value. |
| 310 | // result - holds the result on exit if the load succeeds and |
| 311 | // we fall through. |
| 312 | |
| 313 | __ mov(scratch, FieldOperand(receiver, JSObject::kElementsOffset)); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 314 | if (not_fast_array != NULL) { |
| 315 | // Check that the object is in fast mode and writable. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 316 | __ CheckMap(scratch, |
| 317 | FACTORY->fixed_array_map(), |
| 318 | not_fast_array, |
| 319 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 320 | } else { |
| 321 | __ AssertFastElements(scratch); |
| 322 | } |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 323 | // Check that the key (index) is within bounds. |
| 324 | __ cmp(key, FieldOperand(scratch, FixedArray::kLengthOffset)); |
| 325 | __ j(above_equal, out_of_range); |
| 326 | // Fast case: Do the load. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame^] | 327 | STATIC_ASSERT((kPointerSize == 4) && (kSmiTagSize == 1) && (kSmiTag == 0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 328 | __ mov(scratch, FieldOperand(scratch, key, times_2, FixedArray::kHeaderSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 329 | __ cmp(Operand(scratch), Immediate(FACTORY->the_hole_value())); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 330 | // In case the loaded value is the_hole we have to consult GetProperty |
| 331 | // to ensure the prototype chain is searched. |
| 332 | __ j(equal, out_of_range); |
| 333 | if (!result.is(scratch)) { |
| 334 | __ mov(result, scratch); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | |
| 339 | // Checks whether a key is an array index string or a symbol string. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 340 | // Falls through if the key is a symbol. |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 341 | static void GenerateKeyStringCheck(MacroAssembler* masm, |
| 342 | Register key, |
| 343 | Register map, |
| 344 | Register hash, |
| 345 | Label* index_string, |
| 346 | Label* not_symbol) { |
| 347 | // Register use: |
| 348 | // key - holds the key and is unchanged. Assumed to be non-smi. |
| 349 | // Scratch registers: |
| 350 | // map - used to hold the map of the key. |
| 351 | // hash - used to hold the hash of the key. |
| 352 | __ CmpObjectType(key, FIRST_NONSTRING_TYPE, map); |
| 353 | __ j(above_equal, not_symbol); |
| 354 | |
| 355 | // Is the string an array index, with cached numeric value? |
| 356 | __ mov(hash, FieldOperand(key, String::kHashFieldOffset)); |
| 357 | __ test(hash, Immediate(String::kContainsCachedArrayIndexMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 358 | __ j(zero, index_string); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 359 | |
| 360 | // Is the string a symbol? |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame^] | 361 | STATIC_ASSERT(kSymbolTag != 0); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 362 | __ test_b(FieldOperand(map, Map::kInstanceTypeOffset), kIsSymbolMask); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 363 | __ j(zero, not_symbol); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 367 | static Operand GenerateMappedArgumentsLookup(MacroAssembler* masm, |
| 368 | Register object, |
| 369 | Register key, |
| 370 | Register scratch1, |
| 371 | Register scratch2, |
| 372 | Label* unmapped_case, |
| 373 | Label* slow_case) { |
| 374 | Heap* heap = masm->isolate()->heap(); |
| 375 | Factory* factory = masm->isolate()->factory(); |
| 376 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 377 | // Check that the receiver is a JSObject. Because of the elements |
| 378 | // map check later, we do not need to check for interceptors or |
| 379 | // whether it requires access checks. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 380 | __ JumpIfSmi(object, slow_case); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 381 | // Check that the object is some kind of JSObject. |
| 382 | __ CmpObjectType(object, FIRST_JS_RECEIVER_TYPE, scratch1); |
| 383 | __ j(below, slow_case); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 384 | |
| 385 | // Check that the key is a positive smi. |
| 386 | __ test(key, Immediate(0x8000001)); |
| 387 | __ j(not_zero, slow_case); |
| 388 | |
| 389 | // Load the elements into scratch1 and check its map. |
| 390 | Handle<Map> arguments_map(heap->non_strict_arguments_elements_map()); |
| 391 | __ mov(scratch1, FieldOperand(object, JSObject::kElementsOffset)); |
| 392 | __ CheckMap(scratch1, arguments_map, slow_case, DONT_DO_SMI_CHECK); |
| 393 | |
| 394 | // Check if element is in the range of mapped arguments. If not, jump |
| 395 | // to the unmapped lookup with the parameter map in scratch1. |
| 396 | __ mov(scratch2, FieldOperand(scratch1, FixedArray::kLengthOffset)); |
| 397 | __ sub(Operand(scratch2), Immediate(Smi::FromInt(2))); |
| 398 | __ cmp(key, Operand(scratch2)); |
| 399 | __ j(greater_equal, unmapped_case); |
| 400 | |
| 401 | // Load element index and check whether it is the hole. |
| 402 | const int kHeaderSize = FixedArray::kHeaderSize + 2 * kPointerSize; |
| 403 | __ mov(scratch2, FieldOperand(scratch1, |
| 404 | key, |
| 405 | times_half_pointer_size, |
| 406 | kHeaderSize)); |
| 407 | __ cmp(scratch2, factory->the_hole_value()); |
| 408 | __ j(equal, unmapped_case); |
| 409 | |
| 410 | // Load value from context and return it. We can reuse scratch1 because |
| 411 | // we do not jump to the unmapped lookup (which requires the parameter |
| 412 | // map in scratch1). |
| 413 | const int kContextOffset = FixedArray::kHeaderSize; |
| 414 | __ mov(scratch1, FieldOperand(scratch1, kContextOffset)); |
| 415 | return FieldOperand(scratch1, |
| 416 | scratch2, |
| 417 | times_half_pointer_size, |
| 418 | Context::kHeaderSize); |
| 419 | } |
| 420 | |
| 421 | |
| 422 | static Operand GenerateUnmappedArgumentsLookup(MacroAssembler* masm, |
| 423 | Register key, |
| 424 | Register parameter_map, |
| 425 | Register scratch, |
| 426 | Label* slow_case) { |
| 427 | // Element is in arguments backing store, which is referenced by the |
| 428 | // second element of the parameter_map. |
| 429 | const int kBackingStoreOffset = FixedArray::kHeaderSize + kPointerSize; |
| 430 | Register backing_store = parameter_map; |
| 431 | __ mov(backing_store, FieldOperand(parameter_map, kBackingStoreOffset)); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 432 | Handle<Map> fixed_array_map(masm->isolate()->heap()->fixed_array_map()); |
| 433 | __ CheckMap(backing_store, fixed_array_map, slow_case, DONT_DO_SMI_CHECK); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 434 | __ mov(scratch, FieldOperand(backing_store, FixedArray::kLengthOffset)); |
| 435 | __ cmp(key, Operand(scratch)); |
| 436 | __ j(greater_equal, slow_case); |
| 437 | return FieldOperand(backing_store, |
| 438 | key, |
| 439 | times_half_pointer_size, |
| 440 | FixedArray::kHeaderSize); |
| 441 | } |
| 442 | |
| 443 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 444 | void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) { |
| 445 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 446 | // -- eax : key |
| 447 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 448 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 449 | // ----------------------------------- |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 450 | Label slow, check_string, index_smi, index_string, property_array_property; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 451 | Label probe_dictionary, check_number_dictionary; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 452 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 453 | // Check that the key is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 454 | __ JumpIfNotSmi(eax, &check_string); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 455 | __ bind(&index_smi); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 456 | // Now the key is known to be a smi. This place is also jumped to from |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 457 | // where a numeric string is converted to a smi. |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 458 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 459 | GenerateKeyedLoadReceiverCheck( |
| 460 | masm, edx, ecx, Map::kHasIndexedInterceptor, &slow); |
| 461 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 462 | // Check the receiver's map to see if it has fast elements. |
| 463 | __ CheckFastElements(ecx, &check_number_dictionary); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 464 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 465 | GenerateFastArrayLoad(masm, |
| 466 | edx, |
| 467 | eax, |
| 468 | ecx, |
| 469 | eax, |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 470 | NULL, |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 471 | &slow); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 472 | Isolate* isolate = masm->isolate(); |
| 473 | Counters* counters = isolate->counters(); |
| 474 | __ IncrementCounter(counters->keyed_load_generic_smi(), 1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 475 | __ ret(0); |
| 476 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 477 | __ bind(&check_number_dictionary); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 478 | __ mov(ebx, eax); |
| 479 | __ SmiUntag(ebx); |
| 480 | __ mov(ecx, FieldOperand(edx, JSObject::kElementsOffset)); |
| 481 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 482 | // Check whether the elements is a number dictionary. |
| 483 | // edx: receiver |
| 484 | // ebx: untagged index |
| 485 | // eax: key |
| 486 | // ecx: elements |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 487 | __ CheckMap(ecx, |
| 488 | isolate->factory()->hash_table_map(), |
| 489 | &slow, |
| 490 | DONT_DO_SMI_CHECK); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 491 | Label slow_pop_receiver; |
| 492 | // Push receiver on the stack to free up a register for the dictionary |
| 493 | // probing. |
| 494 | __ push(edx); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 495 | __ LoadFromNumberDictionary(&slow_pop_receiver, |
| 496 | ecx, |
| 497 | eax, |
| 498 | ebx, |
| 499 | edx, |
| 500 | edi, |
| 501 | eax); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 502 | // Pop receiver before returning. |
| 503 | __ pop(edx); |
| 504 | __ ret(0); |
| 505 | |
| 506 | __ bind(&slow_pop_receiver); |
| 507 | // Pop the receiver from the stack and jump to runtime. |
| 508 | __ pop(edx); |
| 509 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | __ bind(&slow); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 511 | // Slow case: jump to runtime. |
| 512 | // edx: receiver |
| 513 | // eax: key |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 514 | __ IncrementCounter(counters->keyed_load_generic_slow(), 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 515 | GenerateRuntimeGetProperty(masm); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 516 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 517 | __ bind(&check_string); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 518 | GenerateKeyStringCheck(masm, eax, ecx, ebx, &index_string, &slow); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 519 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 520 | GenerateKeyedLoadReceiverCheck( |
| 521 | masm, edx, ecx, Map::kHasNamedInterceptor, &slow); |
| 522 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 523 | // If the receiver is a fast-case object, check the keyed lookup |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 524 | // cache. Otherwise probe the dictionary. |
| 525 | __ mov(ebx, FieldOperand(edx, JSObject::kPropertiesOffset)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 526 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 527 | Immediate(isolate->factory()->hash_table_map())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 528 | __ j(equal, &probe_dictionary); |
| 529 | |
| 530 | // Load the map of the receiver, compute the keyed lookup cache hash |
| 531 | // based on 32 bits of the map pointer and the string hash. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 532 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 533 | __ mov(ecx, ebx); |
| 534 | __ shr(ecx, KeyedLookupCache::kMapHashShift); |
| 535 | __ mov(edi, FieldOperand(eax, String::kHashFieldOffset)); |
| 536 | __ shr(edi, String::kHashShift); |
| 537 | __ xor_(ecx, Operand(edi)); |
| 538 | __ and_(ecx, KeyedLookupCache::kCapacityMask); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 539 | |
| 540 | // Load the key (consisting of map and symbol) from the cache and |
| 541 | // check for match. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 542 | ExternalReference cache_keys = |
| 543 | ExternalReference::keyed_lookup_cache_keys(masm->isolate()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 544 | __ mov(edi, ecx); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 545 | __ shl(edi, kPointerSizeLog2 + 1); |
| 546 | __ cmp(ebx, Operand::StaticArray(edi, times_1, cache_keys)); |
| 547 | __ j(not_equal, &slow); |
| 548 | __ add(Operand(edi), Immediate(kPointerSize)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 549 | __ cmp(eax, Operand::StaticArray(edi, times_1, cache_keys)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 550 | __ j(not_equal, &slow); |
| 551 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 552 | // Get field offset. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 553 | // edx : receiver |
| 554 | // ebx : receiver's map |
| 555 | // eax : key |
| 556 | // ecx : lookup cache index |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 557 | ExternalReference cache_field_offsets = |
| 558 | ExternalReference::keyed_lookup_cache_field_offsets(masm->isolate()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 559 | __ mov(edi, |
| 560 | Operand::StaticArray(ecx, times_pointer_size, cache_field_offsets)); |
| 561 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInObjectPropertiesOffset)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 562 | __ sub(edi, Operand(ecx)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 563 | __ j(above_equal, &property_array_property); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 564 | |
| 565 | // Load in-object property. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 566 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceSizeOffset)); |
| 567 | __ add(ecx, Operand(edi)); |
| 568 | __ mov(eax, FieldOperand(edx, ecx, times_pointer_size, 0)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 569 | __ IncrementCounter(counters->keyed_load_generic_lookup_cache(), 1); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 570 | __ ret(0); |
| 571 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 572 | // Load property array property. |
| 573 | __ bind(&property_array_property); |
| 574 | __ mov(eax, FieldOperand(edx, JSObject::kPropertiesOffset)); |
| 575 | __ mov(eax, FieldOperand(eax, edi, times_pointer_size, |
| 576 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 577 | __ IncrementCounter(counters->keyed_load_generic_lookup_cache(), 1); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 578 | __ ret(0); |
| 579 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 580 | // Do a quick inline probe of the receiver's dictionary, if it |
| 581 | // exists. |
| 582 | __ bind(&probe_dictionary); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 583 | |
| 584 | __ mov(ecx, FieldOperand(edx, JSObject::kMapOffset)); |
| 585 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 586 | GenerateGlobalInstanceTypeCheck(masm, ecx, &slow); |
| 587 | |
| 588 | GenerateDictionaryLoad(masm, &slow, ebx, eax, ecx, edi, eax); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 589 | __ IncrementCounter(counters->keyed_load_generic_symbol(), 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | __ ret(0); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 591 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 592 | __ bind(&index_string); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 593 | __ IndexFromHash(ebx, eax); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 594 | // Now jump to the place where smi keys are handled. |
| 595 | __ jmp(&index_smi); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 599 | void KeyedLoadIC::GenerateString(MacroAssembler* masm) { |
| 600 | // ----------- S t a t e ------------- |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 601 | // -- eax : key (index) |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 602 | // -- edx : receiver |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 603 | // -- esp[0] : return address |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 604 | // ----------------------------------- |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 605 | Label miss; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 606 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 607 | Register receiver = edx; |
| 608 | Register index = eax; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 609 | Register scratch1 = ebx; |
| 610 | Register scratch2 = ecx; |
| 611 | Register result = eax; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 612 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 613 | StringCharAtGenerator char_at_generator(receiver, |
| 614 | index, |
| 615 | scratch1, |
| 616 | scratch2, |
| 617 | result, |
| 618 | &miss, // When not a string. |
| 619 | &miss, // When not a number. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 620 | &miss, // When index out of range. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 621 | STRING_INDEX_IS_ARRAY_INDEX); |
| 622 | char_at_generator.GenerateFast(masm); |
| 623 | __ ret(0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 624 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 625 | StubRuntimeCallHelper call_helper; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 626 | char_at_generator.GenerateSlow(masm, call_helper); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 627 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 628 | __ bind(&miss); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 629 | GenerateMiss(masm, false); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 633 | void KeyedLoadIC::GenerateIndexedInterceptor(MacroAssembler* masm) { |
| 634 | // ----------- S t a t e ------------- |
| 635 | // -- eax : key |
| 636 | // -- edx : receiver |
| 637 | // -- esp[0] : return address |
| 638 | // ----------------------------------- |
| 639 | Label slow; |
| 640 | |
| 641 | // Check that the receiver isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 642 | __ JumpIfSmi(edx, &slow); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 643 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 644 | // Check that the key is an array index, that is Uint32. |
| 645 | __ test(eax, Immediate(kSmiTagMask | kSmiSignMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 646 | __ j(not_zero, &slow); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 647 | |
| 648 | // Get the map of the receiver. |
| 649 | __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 650 | |
| 651 | // Check that it has indexed interceptor and access checks |
| 652 | // are not enabled for this object. |
| 653 | __ movzx_b(ecx, FieldOperand(ecx, Map::kBitFieldOffset)); |
| 654 | __ and_(Operand(ecx), Immediate(kSlowCaseBitFieldMask)); |
| 655 | __ cmp(Operand(ecx), Immediate(1 << Map::kHasIndexedInterceptor)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 656 | __ j(not_zero, &slow); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 657 | |
| 658 | // Everything is fine, call runtime. |
| 659 | __ pop(ecx); |
| 660 | __ push(edx); // receiver |
| 661 | __ push(eax); // key |
| 662 | __ push(ecx); // return address |
| 663 | |
| 664 | // Perform tail call to the entry. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 665 | ExternalReference ref = |
| 666 | ExternalReference(IC_Utility(kKeyedLoadPropertyWithInterceptor), |
| 667 | masm->isolate()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 668 | __ TailCallExternalReference(ref, 2, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 669 | |
| 670 | __ bind(&slow); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 671 | GenerateMiss(masm, false); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 675 | void KeyedLoadIC::GenerateNonStrictArguments(MacroAssembler* masm) { |
| 676 | // ----------- S t a t e ------------- |
| 677 | // -- eax : key |
| 678 | // -- edx : receiver |
| 679 | // -- esp[0] : return address |
| 680 | // ----------------------------------- |
| 681 | Label slow, notin; |
| 682 | Factory* factory = masm->isolate()->factory(); |
| 683 | Operand mapped_location = |
| 684 | GenerateMappedArgumentsLookup(masm, edx, eax, ebx, ecx, ¬in, &slow); |
| 685 | __ mov(eax, mapped_location); |
| 686 | __ Ret(); |
| 687 | __ bind(¬in); |
| 688 | // The unmapped lookup expects that the parameter map is in ebx. |
| 689 | Operand unmapped_location = |
| 690 | GenerateUnmappedArgumentsLookup(masm, eax, ebx, ecx, &slow); |
| 691 | __ cmp(unmapped_location, factory->the_hole_value()); |
| 692 | __ j(equal, &slow); |
| 693 | __ mov(eax, unmapped_location); |
| 694 | __ Ret(); |
| 695 | __ bind(&slow); |
| 696 | GenerateMiss(masm, false); |
| 697 | } |
| 698 | |
| 699 | |
| 700 | void KeyedStoreIC::GenerateNonStrictArguments(MacroAssembler* masm) { |
| 701 | // ----------- S t a t e ------------- |
| 702 | // -- eax : value |
| 703 | // -- ecx : key |
| 704 | // -- edx : receiver |
| 705 | // -- esp[0] : return address |
| 706 | // ----------------------------------- |
| 707 | Label slow, notin; |
| 708 | Operand mapped_location = |
| 709 | GenerateMappedArgumentsLookup(masm, edx, ecx, ebx, edi, ¬in, &slow); |
| 710 | __ mov(mapped_location, eax); |
fschneider@chromium.org | 59c1426 | 2011-06-23 10:27:56 +0000 | [diff] [blame] | 711 | __ lea(ecx, mapped_location); |
| 712 | __ mov(edx, eax); |
| 713 | __ RecordWrite(ebx, ecx, edx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 714 | __ Ret(); |
| 715 | __ bind(¬in); |
| 716 | // The unmapped lookup expects that the parameter map is in ebx. |
| 717 | Operand unmapped_location = |
| 718 | GenerateUnmappedArgumentsLookup(masm, ecx, ebx, edi, &slow); |
| 719 | __ mov(unmapped_location, eax); |
fschneider@chromium.org | 59c1426 | 2011-06-23 10:27:56 +0000 | [diff] [blame] | 720 | __ lea(edi, unmapped_location); |
| 721 | __ mov(edx, eax); |
| 722 | __ RecordWrite(ebx, edi, edx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 723 | __ Ret(); |
| 724 | __ bind(&slow); |
| 725 | GenerateMiss(masm, false); |
| 726 | } |
| 727 | |
| 728 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 729 | void KeyedStoreIC::GenerateGeneric(MacroAssembler* masm, |
| 730 | StrictModeFlag strict_mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 731 | // ----------- S t a t e ------------- |
| 732 | // -- eax : value |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 733 | // -- ecx : key |
| 734 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 735 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 736 | // ----------------------------------- |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 737 | Label slow, fast, array, extra; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 738 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 739 | // Check that the object isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 740 | __ JumpIfSmi(edx, &slow); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 741 | // Get the map from the receiver. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 742 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 743 | // Check that the receiver does not require access checks. We need |
| 744 | // to do this because this generic stub does not perform map checks. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 745 | __ test_b(FieldOperand(edi, Map::kBitFieldOffset), |
| 746 | 1 << Map::kIsAccessCheckNeeded); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 747 | __ j(not_zero, &slow); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 748 | // Check that the key is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 749 | __ JumpIfNotSmi(ecx, &slow); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 750 | __ CmpInstanceType(edi, JS_ARRAY_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 751 | __ j(equal, &array); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 752 | // Check that the object is some kind of JSObject. |
| 753 | __ CmpInstanceType(edi, FIRST_JS_RECEIVER_TYPE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 754 | __ j(below, &slow); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 755 | __ CmpInstanceType(edi, JS_PROXY_TYPE); |
| 756 | __ j(equal, &slow); |
| 757 | __ CmpInstanceType(edi, JS_FUNCTION_PROXY_TYPE); |
| 758 | __ j(equal, &slow); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 759 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 760 | // Object case: Check key against length in the elements array. |
| 761 | // eax: value |
| 762 | // edx: JSObject |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 763 | // ecx: key (a smi) |
| 764 | __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 765 | // Check that the object is in fast mode and writable. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 766 | __ CheckMap(edi, FACTORY->fixed_array_map(), &slow, DONT_DO_SMI_CHECK); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 767 | __ cmp(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 768 | __ j(below, &fast); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 769 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 770 | // Slow case: call runtime. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 771 | __ bind(&slow); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 772 | GenerateRuntimeSetProperty(masm, strict_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 773 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 774 | // Extra capacity case: Check if there is extra capacity to |
| 775 | // perform the store and update the length. Used for adding one |
| 776 | // element to the array by writing to array[array.length]. |
| 777 | __ bind(&extra); |
| 778 | // eax: value |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 779 | // edx: receiver, a JSArray |
| 780 | // ecx: key, a smi. |
| 781 | // edi: receiver->elements, a FixedArray |
| 782 | // flags: compare (ecx, edx.length()) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 783 | // do not leave holes in the array: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 784 | __ j(not_equal, &slow); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 785 | __ cmp(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 786 | __ j(above_equal, &slow); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 787 | // Add 1 to receiver->length, and go to fast array write. |
| 788 | __ add(FieldOperand(edx, JSArray::kLengthOffset), |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 789 | Immediate(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 790 | __ jmp(&fast); |
| 791 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 792 | // Array case: Get the length and the elements array from the JS |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 793 | // array. Check that the array is in fast mode (and writable); if it |
| 794 | // is the length is always a smi. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 795 | __ bind(&array); |
| 796 | // eax: value |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 797 | // edx: receiver, a JSArray |
| 798 | // ecx: key, a smi. |
| 799 | __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 800 | __ CheckMap(edi, FACTORY->fixed_array_map(), &slow, DONT_DO_SMI_CHECK); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 801 | |
| 802 | // Check the key against the length in the array, compute the |
| 803 | // address to store into and fall through to fast case. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 804 | __ cmp(ecx, FieldOperand(edx, JSArray::kLengthOffset)); // Compare smis. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 805 | __ j(above_equal, &extra); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 806 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 807 | // Fast case: Do the store. |
| 808 | __ bind(&fast); |
| 809 | // eax: value |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 810 | // ecx: key (a smi) |
| 811 | // edx: receiver |
| 812 | // edi: FixedArray receiver->elements |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 813 | __ mov(CodeGenerator::FixedArrayElementOperand(edi, ecx), eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 814 | // Update write barrier for the elements array address. |
| 815 | __ mov(edx, Operand(eax)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 816 | __ RecordWrite(edi, 0, edx, ecx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 817 | __ ret(0); |
| 818 | } |
| 819 | |
| 820 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 821 | // The generated code does not accept smi keys. |
| 822 | // The generated code falls through if both probes miss. |
| 823 | static void GenerateMonomorphicCacheProbe(MacroAssembler* masm, |
| 824 | int argc, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 825 | Code::Kind kind, |
| 826 | Code::ExtraICState extra_ic_state) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 827 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 828 | // -- ecx : name |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 829 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | // ----------------------------------- |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 831 | Label number, non_number, non_string, boolean, probe, miss; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 832 | |
| 833 | // Probe the stub cache. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 834 | Code::Flags flags = Code::ComputeFlags(kind, |
| 835 | NOT_IN_LOOP, |
| 836 | MONOMORPHIC, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 837 | extra_ic_state, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 838 | NORMAL, |
| 839 | argc); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 840 | Isolate::Current()->stub_cache()->GenerateProbe(masm, flags, edx, ecx, ebx, |
| 841 | eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 842 | |
| 843 | // If the stub cache probing failed, the receiver might be a value. |
| 844 | // For value objects, we use the map of the prototype objects for |
| 845 | // the corresponding JSValue for the cache and that is what we need |
| 846 | // to probe. |
| 847 | // |
| 848 | // Check for number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 849 | __ JumpIfSmi(edx, &number); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 850 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 851 | __ j(not_equal, &non_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 852 | __ bind(&number); |
| 853 | StubCompiler::GenerateLoadGlobalFunctionPrototype( |
| 854 | masm, Context::NUMBER_FUNCTION_INDEX, edx); |
| 855 | __ jmp(&probe); |
| 856 | |
| 857 | // Check for string. |
| 858 | __ bind(&non_number); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 859 | __ CmpInstanceType(ebx, FIRST_NONSTRING_TYPE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 860 | __ j(above_equal, &non_string); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 861 | StubCompiler::GenerateLoadGlobalFunctionPrototype( |
| 862 | masm, Context::STRING_FUNCTION_INDEX, edx); |
| 863 | __ jmp(&probe); |
| 864 | |
| 865 | // Check for boolean. |
| 866 | __ bind(&non_string); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 867 | __ cmp(edx, FACTORY->true_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 868 | __ j(equal, &boolean); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 869 | __ cmp(edx, FACTORY->false_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 870 | __ j(not_equal, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 871 | __ bind(&boolean); |
| 872 | StubCompiler::GenerateLoadGlobalFunctionPrototype( |
| 873 | masm, Context::BOOLEAN_FUNCTION_INDEX, edx); |
| 874 | |
| 875 | // Probe the stub cache for the value object. |
| 876 | __ bind(&probe); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 877 | Isolate::Current()->stub_cache()->GenerateProbe(masm, flags, edx, ecx, ebx, |
| 878 | no_reg); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 879 | __ bind(&miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 883 | static void GenerateFunctionTailCall(MacroAssembler* masm, |
| 884 | int argc, |
| 885 | Label* miss) { |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 886 | // ----------- S t a t e ------------- |
| 887 | // -- ecx : name |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 888 | // -- edi : function |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 889 | // -- esp[0] : return address |
| 890 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 891 | // -- ... |
| 892 | // -- esp[(argc + 1) * 4] : receiver |
| 893 | // ----------------------------------- |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 894 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 895 | // Check that the result is not a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 896 | __ JumpIfSmi(edi, miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 897 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 898 | // Check that the value is a JavaScript function, fetching its map into eax. |
| 899 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, eax); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 900 | __ j(not_equal, miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 901 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 902 | // Invoke the function. |
| 903 | ParameterCount actual(argc); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 904 | __ InvokeFunction(edi, actual, JUMP_FUNCTION, |
| 905 | NullCallWrapper(), CALL_AS_METHOD); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 906 | } |
| 907 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 908 | // The generated code falls through if the call should be handled by runtime. |
| 909 | static void GenerateCallNormal(MacroAssembler* masm, int argc) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 910 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 911 | // -- ecx : name |
| 912 | // -- esp[0] : return address |
| 913 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 914 | // -- ... |
| 915 | // -- esp[(argc + 1) * 4] : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 916 | // ----------------------------------- |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 917 | Label miss; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 918 | |
| 919 | // Get the receiver of the function from the stack; 1 ~ return address. |
| 920 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 922 | GenerateStringDictionaryReceiverCheck(masm, edx, eax, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 923 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 924 | // eax: elements |
| 925 | // Search the dictionary placing the result in edi. |
| 926 | GenerateDictionaryLoad(masm, &miss, eax, ecx, edi, ebx, edi); |
| 927 | GenerateFunctionTailCall(masm, argc, &miss); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 928 | |
| 929 | __ bind(&miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 933 | static void GenerateCallMiss(MacroAssembler* masm, |
| 934 | int argc, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 935 | IC::UtilityId id, |
| 936 | Code::ExtraICState extra_ic_state) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 937 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 938 | // -- ecx : name |
| 939 | // -- esp[0] : return address |
| 940 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 941 | // -- ... |
| 942 | // -- esp[(argc + 1) * 4] : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 943 | // ----------------------------------- |
| 944 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 945 | Counters* counters = masm->isolate()->counters(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 946 | if (id == IC::kCallIC_Miss) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 947 | __ IncrementCounter(counters->call_miss(), 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 948 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 949 | __ IncrementCounter(counters->keyed_call_miss(), 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 950 | } |
| 951 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 952 | // Get the receiver of the function from the stack; 1 ~ return address. |
| 953 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 954 | |
| 955 | // Enter an internal frame. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 956 | __ EnterInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 957 | |
| 958 | // Push the receiver and the name of the function. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 959 | __ push(edx); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 960 | __ push(ecx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 961 | |
| 962 | // Call the entry. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 963 | CEntryStub stub(1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 964 | __ mov(eax, Immediate(2)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 965 | __ mov(ebx, Immediate(ExternalReference(IC_Utility(id), masm->isolate()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 966 | __ CallStub(&stub); |
| 967 | |
| 968 | // Move result to edi and exit the internal frame. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 969 | __ mov(edi, eax); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 970 | __ LeaveInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 971 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 972 | // Check if the receiver is a global object of some sort. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 973 | // This can happen only for regular CallIC but not KeyedCallIC. |
| 974 | if (id == IC::kCallIC_Miss) { |
| 975 | Label invoke, global; |
| 976 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); // receiver |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 977 | __ JumpIfSmi(edx, &invoke, Label::kNear); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 978 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 979 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 980 | __ cmp(ebx, JS_GLOBAL_OBJECT_TYPE); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 981 | __ j(equal, &global, Label::kNear); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 982 | __ cmp(ebx, JS_BUILTINS_OBJECT_TYPE); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 983 | __ j(not_equal, &invoke, Label::kNear); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 984 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 985 | // Patch the receiver on the stack. |
| 986 | __ bind(&global); |
| 987 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 988 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 989 | __ bind(&invoke); |
| 990 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 991 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 992 | // Invoke the function. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 993 | CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state) |
| 994 | ? CALL_AS_FUNCTION |
| 995 | : CALL_AS_METHOD; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 996 | ParameterCount actual(argc); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 997 | __ InvokeFunction(edi, |
| 998 | actual, |
| 999 | JUMP_FUNCTION, |
| 1000 | NullCallWrapper(), |
| 1001 | call_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1005 | void CallIC::GenerateMegamorphic(MacroAssembler* masm, |
| 1006 | int argc, |
| 1007 | Code::ExtraICState extra_ic_state) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1008 | // ----------- S t a t e ------------- |
| 1009 | // -- ecx : name |
| 1010 | // -- esp[0] : return address |
| 1011 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1012 | // -- ... |
| 1013 | // -- esp[(argc + 1) * 4] : receiver |
| 1014 | // ----------------------------------- |
| 1015 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1016 | // Get the receiver of the function from the stack; 1 ~ return address. |
| 1017 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1018 | GenerateMonomorphicCacheProbe(masm, argc, Code::CALL_IC, extra_ic_state); |
| 1019 | |
| 1020 | GenerateMiss(masm, argc, extra_ic_state); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | void CallIC::GenerateNormal(MacroAssembler* masm, int argc) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1025 | // ----------- S t a t e ------------- |
| 1026 | // -- ecx : name |
| 1027 | // -- esp[0] : return address |
| 1028 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1029 | // -- ... |
| 1030 | // -- esp[(argc + 1) * 4] : receiver |
| 1031 | // ----------------------------------- |
| 1032 | |
| 1033 | GenerateCallNormal(masm, argc); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1034 | GenerateMiss(masm, argc, Code::kNoExtraICState); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1038 | void CallIC::GenerateMiss(MacroAssembler* masm, |
| 1039 | int argc, |
| 1040 | Code::ExtraICState extra_ic_state) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1041 | // ----------- S t a t e ------------- |
| 1042 | // -- ecx : name |
| 1043 | // -- esp[0] : return address |
| 1044 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1045 | // -- ... |
| 1046 | // -- esp[(argc + 1) * 4] : receiver |
| 1047 | // ----------------------------------- |
| 1048 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1049 | GenerateCallMiss(masm, argc, IC::kCallIC_Miss, extra_ic_state); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | void KeyedCallIC::GenerateMegamorphic(MacroAssembler* masm, int argc) { |
| 1054 | // ----------- S t a t e ------------- |
| 1055 | // -- ecx : name |
| 1056 | // -- esp[0] : return address |
| 1057 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1058 | // -- ... |
| 1059 | // -- esp[(argc + 1) * 4] : receiver |
| 1060 | // ----------------------------------- |
| 1061 | |
| 1062 | // Get the receiver of the function from the stack; 1 ~ return address. |
| 1063 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1064 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1065 | Label do_call, slow_call, slow_load, slow_reload_receiver; |
| 1066 | Label check_number_dictionary, check_string, lookup_monomorphic_cache; |
| 1067 | Label index_smi, index_string; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1068 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1069 | // Check that the key is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1070 | __ JumpIfNotSmi(ecx, &check_string); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1071 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1072 | __ bind(&index_smi); |
| 1073 | // Now the key is known to be a smi. This place is also jumped to from |
| 1074 | // where a numeric string is converted to a smi. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1075 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1076 | GenerateKeyedLoadReceiverCheck( |
| 1077 | masm, edx, eax, Map::kHasIndexedInterceptor, &slow_call); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1078 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1079 | GenerateFastArrayLoad( |
| 1080 | masm, edx, ecx, eax, edi, &check_number_dictionary, &slow_load); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1081 | Isolate* isolate = masm->isolate(); |
| 1082 | Counters* counters = isolate->counters(); |
| 1083 | __ IncrementCounter(counters->keyed_call_generic_smi_fast(), 1); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1084 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1085 | __ bind(&do_call); |
| 1086 | // receiver in edx is not used after this point. |
| 1087 | // ecx: key |
| 1088 | // edi: function |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1089 | GenerateFunctionTailCall(masm, argc, &slow_call); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1090 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1091 | __ bind(&check_number_dictionary); |
| 1092 | // eax: elements |
| 1093 | // ecx: smi key |
| 1094 | // Check whether the elements is a number dictionary. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1095 | __ CheckMap(eax, |
| 1096 | isolate->factory()->hash_table_map(), |
| 1097 | &slow_load, |
| 1098 | DONT_DO_SMI_CHECK); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1099 | __ mov(ebx, ecx); |
| 1100 | __ SmiUntag(ebx); |
| 1101 | // ebx: untagged index |
| 1102 | // Receiver in edx will be clobbered, need to reload it on miss. |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1103 | __ LoadFromNumberDictionary( |
| 1104 | &slow_reload_receiver, eax, ecx, ebx, edx, edi, edi); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1105 | __ IncrementCounter(counters->keyed_call_generic_smi_dict(), 1); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1106 | __ jmp(&do_call); |
| 1107 | |
| 1108 | __ bind(&slow_reload_receiver); |
| 1109 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1110 | |
| 1111 | __ bind(&slow_load); |
| 1112 | // This branch is taken when calling KeyedCallIC_Miss is neither required |
| 1113 | // nor beneficial. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1114 | __ IncrementCounter(counters->keyed_call_generic_slow_load(), 1); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1115 | __ EnterInternalFrame(); |
| 1116 | __ push(ecx); // save the key |
| 1117 | __ push(edx); // pass the receiver |
| 1118 | __ push(ecx); // pass the key |
| 1119 | __ CallRuntime(Runtime::kKeyedGetProperty, 2); |
| 1120 | __ pop(ecx); // restore the key |
| 1121 | __ LeaveInternalFrame(); |
| 1122 | __ mov(edi, eax); |
| 1123 | __ jmp(&do_call); |
| 1124 | |
| 1125 | __ bind(&check_string); |
| 1126 | GenerateKeyStringCheck(masm, ecx, eax, ebx, &index_string, &slow_call); |
| 1127 | |
| 1128 | // The key is known to be a symbol. |
| 1129 | // If the receiver is a regular JS object with slow properties then do |
| 1130 | // a quick inline probe of the receiver's dictionary. |
| 1131 | // Otherwise do the monomorphic cache probe. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1132 | GenerateKeyedLoadReceiverCheck( |
| 1133 | masm, edx, eax, Map::kHasNamedInterceptor, &lookup_monomorphic_cache); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1134 | |
| 1135 | __ mov(ebx, FieldOperand(edx, JSObject::kPropertiesOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1136 | __ CheckMap(ebx, |
| 1137 | isolate->factory()->hash_table_map(), |
| 1138 | &lookup_monomorphic_cache, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1139 | DONT_DO_SMI_CHECK); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1140 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1141 | GenerateDictionaryLoad(masm, &slow_load, ebx, ecx, eax, edi, edi); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1142 | __ IncrementCounter(counters->keyed_call_generic_lookup_dict(), 1); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1143 | __ jmp(&do_call); |
| 1144 | |
| 1145 | __ bind(&lookup_monomorphic_cache); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1146 | __ IncrementCounter(counters->keyed_call_generic_lookup_cache(), 1); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1147 | GenerateMonomorphicCacheProbe(masm, |
| 1148 | argc, |
| 1149 | Code::KEYED_CALL_IC, |
| 1150 | Code::kNoExtraICState); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1151 | // Fall through on miss. |
| 1152 | |
| 1153 | __ bind(&slow_call); |
| 1154 | // This branch is taken if: |
| 1155 | // - the receiver requires boxing or access check, |
| 1156 | // - the key is neither smi nor symbol, |
| 1157 | // - the value loaded is not a function, |
| 1158 | // - there is hope that the runtime will create a monomorphic call stub |
| 1159 | // that will get fetched next time. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1160 | __ IncrementCounter(counters->keyed_call_generic_slow(), 1); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1161 | GenerateMiss(masm, argc); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1162 | |
| 1163 | __ bind(&index_string); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1164 | __ IndexFromHash(ebx, ecx); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1165 | // Now jump to the place where smi keys are handled. |
| 1166 | __ jmp(&index_smi); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1170 | void KeyedCallIC::GenerateNonStrictArguments(MacroAssembler* masm, |
| 1171 | int argc) { |
| 1172 | // ----------- S t a t e ------------- |
| 1173 | // -- ecx : name |
| 1174 | // -- esp[0] : return address |
| 1175 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1176 | // -- ... |
| 1177 | // -- esp[(argc + 1) * 4] : receiver |
| 1178 | // ----------------------------------- |
| 1179 | Label slow, notin; |
| 1180 | Factory* factory = masm->isolate()->factory(); |
| 1181 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1182 | Operand mapped_location = |
| 1183 | GenerateMappedArgumentsLookup(masm, edx, ecx, ebx, eax, ¬in, &slow); |
| 1184 | __ mov(edi, mapped_location); |
| 1185 | GenerateFunctionTailCall(masm, argc, &slow); |
| 1186 | __ bind(¬in); |
| 1187 | // The unmapped lookup expects that the parameter map is in ebx. |
| 1188 | Operand unmapped_location = |
| 1189 | GenerateUnmappedArgumentsLookup(masm, ecx, ebx, eax, &slow); |
| 1190 | __ cmp(unmapped_location, factory->the_hole_value()); |
| 1191 | __ j(equal, &slow); |
| 1192 | __ mov(edi, unmapped_location); |
| 1193 | GenerateFunctionTailCall(masm, argc, &slow); |
| 1194 | __ bind(&slow); |
| 1195 | GenerateMiss(masm, argc); |
| 1196 | } |
| 1197 | |
| 1198 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1199 | void KeyedCallIC::GenerateNormal(MacroAssembler* masm, int argc) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1200 | // ----------- S t a t e ------------- |
| 1201 | // -- ecx : name |
| 1202 | // -- esp[0] : return address |
| 1203 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1204 | // -- ... |
| 1205 | // -- esp[(argc + 1) * 4] : receiver |
| 1206 | // ----------------------------------- |
| 1207 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1208 | // Check if the name is a string. |
| 1209 | Label miss; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1210 | __ JumpIfSmi(ecx, &miss); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1211 | Condition cond = masm->IsObjectStringType(ecx, eax, eax); |
| 1212 | __ j(NegateCondition(cond), &miss); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1213 | GenerateCallNormal(masm, argc); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1214 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1215 | GenerateMiss(masm, argc); |
| 1216 | } |
| 1217 | |
| 1218 | |
| 1219 | void KeyedCallIC::GenerateMiss(MacroAssembler* masm, int argc) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1220 | // ----------- S t a t e ------------- |
| 1221 | // -- ecx : name |
| 1222 | // -- esp[0] : return address |
| 1223 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1224 | // -- ... |
| 1225 | // -- esp[(argc + 1) * 4] : receiver |
| 1226 | // ----------------------------------- |
| 1227 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1228 | GenerateCallMiss(masm, argc, IC::kKeyedCallIC_Miss, Code::kNoExtraICState); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1232 | void LoadIC::GenerateMegamorphic(MacroAssembler* masm) { |
| 1233 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1234 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1235 | // -- ecx : name |
| 1236 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1237 | // ----------------------------------- |
| 1238 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1239 | // Probe the stub cache. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1240 | Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, |
| 1241 | NOT_IN_LOOP, |
| 1242 | MONOMORPHIC); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1243 | Isolate::Current()->stub_cache()->GenerateProbe(masm, flags, eax, ecx, ebx, |
| 1244 | edx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1245 | |
| 1246 | // Cache miss: Jump to runtime. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1247 | GenerateMiss(masm); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | void LoadIC::GenerateNormal(MacroAssembler* masm) { |
| 1252 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1253 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1254 | // -- ecx : name |
| 1255 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1256 | // ----------------------------------- |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1257 | Label miss; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1258 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1259 | GenerateStringDictionaryReceiverCheck(masm, eax, edx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1260 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1261 | // edx: elements |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1262 | // Search the dictionary placing the result in eax. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1263 | GenerateDictionaryLoad(masm, &miss, edx, ecx, edi, ebx, eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | __ ret(0); |
| 1265 | |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 1266 | // Cache miss: Jump to runtime. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1267 | __ bind(&miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1268 | GenerateMiss(masm); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | |
| 1272 | void LoadIC::GenerateMiss(MacroAssembler* masm) { |
| 1273 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1274 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1275 | // -- ecx : name |
| 1276 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1277 | // ----------------------------------- |
| 1278 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1279 | __ IncrementCounter(masm->isolate()->counters()->load_miss(), 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1280 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1281 | __ pop(ebx); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1282 | __ push(eax); // receiver |
| 1283 | __ push(ecx); // name |
| 1284 | __ push(ebx); // return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1285 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1286 | // Perform tail call to the entry. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1287 | ExternalReference ref = |
| 1288 | ExternalReference(IC_Utility(kLoadIC_Miss), masm->isolate()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1289 | __ TailCallExternalReference(ref, 2, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1293 | void KeyedLoadIC::GenerateMiss(MacroAssembler* masm, bool force_generic) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1294 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1295 | // -- eax : key |
| 1296 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1297 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1298 | // ----------------------------------- |
| 1299 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1300 | __ IncrementCounter(masm->isolate()->counters()->keyed_load_miss(), 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1301 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1302 | __ pop(ebx); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1303 | __ push(edx); // receiver |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1304 | __ push(eax); // name |
| 1305 | __ push(ebx); // return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1306 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1307 | // Perform tail call to the entry. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1308 | ExternalReference ref = force_generic |
| 1309 | ? ExternalReference(IC_Utility(kKeyedLoadIC_MissForceGeneric), |
| 1310 | masm->isolate()) |
| 1311 | : ExternalReference(IC_Utility(kKeyedLoadIC_Miss), masm->isolate()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1312 | __ TailCallExternalReference(ref, 2, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { |
| 1317 | // ----------- S t a t e ------------- |
| 1318 | // -- eax : key |
| 1319 | // -- edx : receiver |
| 1320 | // -- esp[0] : return address |
| 1321 | // ----------------------------------- |
| 1322 | |
| 1323 | __ pop(ebx); |
| 1324 | __ push(edx); // receiver |
| 1325 | __ push(eax); // name |
| 1326 | __ push(ebx); // return address |
| 1327 | |
| 1328 | // Perform tail call to the entry. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1329 | __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1333 | void StoreIC::GenerateMegamorphic(MacroAssembler* masm, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1334 | StrictModeFlag strict_mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1335 | // ----------- S t a t e ------------- |
| 1336 | // -- eax : value |
| 1337 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1338 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1339 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1340 | // ----------------------------------- |
| 1341 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1342 | Code::Flags flags = Code::ComputeFlags(Code::STORE_IC, |
| 1343 | NOT_IN_LOOP, |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1344 | MONOMORPHIC, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1345 | strict_mode); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1346 | Isolate::Current()->stub_cache()->GenerateProbe(masm, flags, edx, ecx, ebx, |
| 1347 | no_reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1348 | |
| 1349 | // Cache miss: Jump to runtime. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1350 | GenerateMiss(masm); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1354 | void StoreIC::GenerateMiss(MacroAssembler* masm) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1355 | // ----------- S t a t e ------------- |
| 1356 | // -- eax : value |
| 1357 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1358 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1359 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1360 | // ----------------------------------- |
| 1361 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1362 | __ pop(ebx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1363 | __ push(edx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1364 | __ push(ecx); |
| 1365 | __ push(eax); |
| 1366 | __ push(ebx); |
| 1367 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1368 | // Perform tail call to the entry. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1369 | ExternalReference ref = |
| 1370 | ExternalReference(IC_Utility(kStoreIC_Miss), masm->isolate()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1371 | __ TailCallExternalReference(ref, 3, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1375 | void StoreIC::GenerateArrayLength(MacroAssembler* masm) { |
| 1376 | // ----------- S t a t e ------------- |
| 1377 | // -- eax : value |
| 1378 | // -- ecx : name |
| 1379 | // -- edx : receiver |
| 1380 | // -- esp[0] : return address |
| 1381 | // ----------------------------------- |
| 1382 | // |
| 1383 | // This accepts as a receiver anything JSObject::SetElementsLength accepts |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1384 | // (currently anything except for external arrays which means anything with |
| 1385 | // elements of FixedArray type.), but currently is restricted to JSArray. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1386 | // Value must be a number, but only smis are accepted as the most common case. |
| 1387 | |
| 1388 | Label miss; |
| 1389 | |
| 1390 | Register receiver = edx; |
| 1391 | Register value = eax; |
| 1392 | Register scratch = ebx; |
| 1393 | |
| 1394 | // Check that the receiver isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1395 | __ JumpIfSmi(receiver, &miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1396 | |
| 1397 | // Check that the object is a JS array. |
| 1398 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1399 | __ j(not_equal, &miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1400 | |
| 1401 | // Check that elements are FixedArray. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1402 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 1403 | // fast elements (including COW). |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1404 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 1405 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1406 | __ j(not_equal, &miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1407 | |
| 1408 | // Check that value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1409 | __ JumpIfNotSmi(value, &miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1410 | |
| 1411 | // Prepare tail call to StoreIC_ArrayLength. |
| 1412 | __ pop(scratch); |
| 1413 | __ push(receiver); |
| 1414 | __ push(value); |
| 1415 | __ push(scratch); // return address |
| 1416 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1417 | ExternalReference ref = |
| 1418 | ExternalReference(IC_Utility(kStoreIC_ArrayLength), masm->isolate()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1419 | __ TailCallExternalReference(ref, 2, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1420 | |
| 1421 | __ bind(&miss); |
| 1422 | |
| 1423 | GenerateMiss(masm); |
| 1424 | } |
| 1425 | |
| 1426 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1427 | void StoreIC::GenerateNormal(MacroAssembler* masm) { |
| 1428 | // ----------- S t a t e ------------- |
| 1429 | // -- eax : value |
| 1430 | // -- ecx : name |
| 1431 | // -- edx : receiver |
| 1432 | // -- esp[0] : return address |
| 1433 | // ----------------------------------- |
| 1434 | |
| 1435 | Label miss, restore_miss; |
| 1436 | |
| 1437 | GenerateStringDictionaryReceiverCheck(masm, edx, ebx, edi, &miss); |
| 1438 | |
| 1439 | // A lot of registers are needed for storing to slow case |
| 1440 | // objects. Push and restore receiver but rely on |
| 1441 | // GenerateDictionaryStore preserving the value and name. |
| 1442 | __ push(edx); |
| 1443 | GenerateDictionaryStore(masm, &restore_miss, ebx, ecx, eax, edx, edi); |
| 1444 | __ Drop(1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1445 | Counters* counters = masm->isolate()->counters(); |
| 1446 | __ IncrementCounter(counters->store_normal_hit(), 1); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1447 | __ ret(0); |
| 1448 | |
| 1449 | __ bind(&restore_miss); |
| 1450 | __ pop(edx); |
| 1451 | |
| 1452 | __ bind(&miss); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1453 | __ IncrementCounter(counters->store_normal_miss(), 1); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1454 | GenerateMiss(masm); |
| 1455 | } |
| 1456 | |
| 1457 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1458 | void StoreIC::GenerateGlobalProxy(MacroAssembler* masm, |
| 1459 | StrictModeFlag strict_mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1460 | // ----------- S t a t e ------------- |
| 1461 | // -- eax : value |
| 1462 | // -- ecx : name |
| 1463 | // -- edx : receiver |
| 1464 | // -- esp[0] : return address |
| 1465 | // ----------------------------------- |
| 1466 | __ pop(ebx); |
| 1467 | __ push(edx); |
| 1468 | __ push(ecx); |
| 1469 | __ push(eax); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1470 | __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
| 1471 | __ push(Immediate(Smi::FromInt(strict_mode))); |
| 1472 | __ push(ebx); // return address |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1473 | |
| 1474 | // Do tail-call to runtime routine. |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1475 | __ TailCallRuntime(Runtime::kSetProperty, 5, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1479 | void KeyedStoreIC::GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 1480 | StrictModeFlag strict_mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1481 | // ----------- S t a t e ------------- |
| 1482 | // -- eax : value |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1483 | // -- ecx : key |
| 1484 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1485 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1486 | // ----------------------------------- |
| 1487 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1488 | __ pop(ebx); |
| 1489 | __ push(edx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1490 | __ push(ecx); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1491 | __ push(eax); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1492 | __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
| 1493 | __ push(Immediate(Smi::FromInt(strict_mode))); // Strict mode. |
| 1494 | __ push(ebx); // return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1495 | |
| 1496 | // Do tail-call to runtime routine. |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1497 | __ TailCallRuntime(Runtime::kSetProperty, 5, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1501 | void KeyedStoreIC::GenerateMiss(MacroAssembler* masm, bool force_generic) { |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1502 | // ----------- S t a t e ------------- |
| 1503 | // -- eax : value |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1504 | // -- ecx : key |
| 1505 | // -- edx : receiver |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1506 | // -- esp[0] : return address |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1507 | // ----------------------------------- |
| 1508 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1509 | __ pop(ebx); |
| 1510 | __ push(edx); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1511 | __ push(ecx); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1512 | __ push(eax); |
| 1513 | __ push(ebx); |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1514 | |
| 1515 | // Do tail-call to runtime routine. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1516 | ExternalReference ref = force_generic |
| 1517 | ? ExternalReference(IC_Utility(kKeyedStoreIC_MissForceGeneric), |
| 1518 | masm->isolate()) |
| 1519 | : ExternalReference(IC_Utility(kKeyedStoreIC_Miss), masm->isolate()); |
| 1520 | __ TailCallExternalReference(ref, 3, 1); |
| 1521 | } |
| 1522 | |
| 1523 | |
| 1524 | void KeyedStoreIC::GenerateSlow(MacroAssembler* masm) { |
| 1525 | // ----------- S t a t e ------------- |
| 1526 | // -- eax : value |
| 1527 | // -- ecx : key |
| 1528 | // -- edx : receiver |
| 1529 | // -- esp[0] : return address |
| 1530 | // ----------------------------------- |
| 1531 | |
| 1532 | __ pop(ebx); |
| 1533 | __ push(edx); |
| 1534 | __ push(ecx); |
| 1535 | __ push(eax); |
| 1536 | __ push(ebx); // return address |
| 1537 | |
| 1538 | // Do tail-call to runtime routine. |
| 1539 | ExternalReference ref(IC_Utility(kKeyedStoreIC_Slow), masm->isolate()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1540 | __ TailCallExternalReference(ref, 3, 1); |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1543 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1544 | #undef __ |
| 1545 | |
| 1546 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1547 | Condition CompareIC::ComputeCondition(Token::Value op) { |
| 1548 | switch (op) { |
| 1549 | case Token::EQ_STRICT: |
| 1550 | case Token::EQ: |
| 1551 | return equal; |
| 1552 | case Token::LT: |
| 1553 | return less; |
| 1554 | case Token::GT: |
| 1555 | // Reverse left and right operands to obtain ECMA-262 conversion order. |
| 1556 | return less; |
| 1557 | case Token::LTE: |
| 1558 | // Reverse left and right operands to obtain ECMA-262 conversion order. |
| 1559 | return greater_equal; |
| 1560 | case Token::GTE: |
| 1561 | return greater_equal; |
| 1562 | default: |
| 1563 | UNREACHABLE(); |
| 1564 | return no_condition; |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1569 | static bool HasInlinedSmiCode(Address address) { |
| 1570 | // The address of the instruction following the call. |
| 1571 | Address test_instruction_address = |
| 1572 | address + Assembler::kCallTargetAddressOffset; |
| 1573 | |
| 1574 | // If the instruction following the call is not a test al, nothing |
| 1575 | // was inlined. |
| 1576 | return *test_instruction_address == Assembler::kTestAlByte; |
| 1577 | } |
| 1578 | |
| 1579 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1580 | void CompareIC::UpdateCaches(Handle<Object> x, Handle<Object> y) { |
| 1581 | HandleScope scope; |
| 1582 | Handle<Code> rewritten; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1583 | State previous_state = GetState(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1584 | |
| 1585 | State state = TargetState(previous_state, HasInlinedSmiCode(address()), x, y); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1586 | if (state == GENERIC) { |
| 1587 | CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS); |
| 1588 | rewritten = stub.GetCode(); |
| 1589 | } else { |
| 1590 | ICCompareStub stub(op_, state); |
| 1591 | rewritten = stub.GetCode(); |
| 1592 | } |
| 1593 | set_target(*rewritten); |
| 1594 | |
| 1595 | #ifdef DEBUG |
| 1596 | if (FLAG_trace_ic) { |
| 1597 | PrintF("[CompareIC (%s->%s)#%s]\n", |
| 1598 | GetStateName(previous_state), |
| 1599 | GetStateName(state), |
| 1600 | Token::Name(op_)); |
| 1601 | } |
| 1602 | #endif |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1603 | |
| 1604 | // Activate inlined smi code. |
| 1605 | if (previous_state == UNINITIALIZED) { |
| 1606 | PatchInlinedSmiCode(address()); |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | |
| 1611 | void PatchInlinedSmiCode(Address address) { |
| 1612 | // The address of the instruction following the call. |
| 1613 | Address test_instruction_address = |
| 1614 | address + Assembler::kCallTargetAddressOffset; |
| 1615 | |
| 1616 | // If the instruction following the call is not a test al, nothing |
| 1617 | // was inlined. |
| 1618 | if (*test_instruction_address != Assembler::kTestAlByte) { |
| 1619 | ASSERT(*test_instruction_address == Assembler::kNopByte); |
| 1620 | return; |
| 1621 | } |
| 1622 | |
| 1623 | Address delta_address = test_instruction_address + 1; |
| 1624 | // The delta to the start of the map check instruction and the |
| 1625 | // condition code uses at the patched jump. |
| 1626 | int8_t delta = *reinterpret_cast<int8_t*>(delta_address); |
| 1627 | if (FLAG_trace_ic) { |
| 1628 | PrintF("[ patching ic at %p, test=%p, delta=%d\n", |
| 1629 | address, test_instruction_address, delta); |
| 1630 | } |
| 1631 | |
| 1632 | // Patch with a short conditional jump. There must be a |
| 1633 | // short jump-if-carry/not-carry at this position. |
| 1634 | Address jmp_address = test_instruction_address - delta; |
| 1635 | ASSERT(*jmp_address == Assembler::kJncShortOpcode || |
| 1636 | *jmp_address == Assembler::kJcShortOpcode); |
| 1637 | Condition cc = *jmp_address == Assembler::kJncShortOpcode |
| 1638 | ? not_zero |
| 1639 | : zero; |
| 1640 | *jmp_address = static_cast<byte>(Assembler::kJccShortPrefix | cc); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1644 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1645 | |
| 1646 | #endif // V8_TARGET_ARCH_IA32 |