erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 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 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_IA32 |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 31 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "ic-inl.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "stub-cache.h" |
| 35 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 36 | namespace v8 { |
| 37 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 39 | #define __ ACCESS_MASM(masm) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
| 41 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 42 | static void ProbeTable(Isolate* isolate, |
| 43 | MacroAssembler* masm, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | Code::Flags flags, |
| 45 | StubCache::Table table, |
| 46 | Register name, |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 47 | Register receiver, |
| 48 | // Number of the cache entry pointer-size scaled. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 49 | Register offset, |
| 50 | Register extra) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 51 | ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); |
| 52 | ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 53 | ExternalReference map_offset(isolate->stub_cache()->map_reference(table)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 54 | |
| 55 | Label miss; |
| 56 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 57 | // Multiply by 3 because there are 3 fields per entry (name, code, map). |
| 58 | __ lea(offset, Operand(offset, offset, times_2, 0)); |
| 59 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 60 | if (extra.is_valid()) { |
| 61 | // Get the code entry from the cache. |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 62 | __ mov(extra, Operand::StaticArray(offset, times_1, value_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 64 | // Check that the key in the entry matches the name. |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 65 | __ cmp(name, Operand::StaticArray(offset, times_1, key_offset)); |
| 66 | __ j(not_equal, &miss); |
| 67 | |
| 68 | // Check the map matches. |
| 69 | __ mov(offset, Operand::StaticArray(offset, times_1, map_offset)); |
| 70 | __ cmp(offset, FieldOperand(receiver, HeapObject::kMapOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 71 | __ j(not_equal, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 72 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 73 | // Check that the flags match what we're looking for. |
| 74 | __ mov(offset, FieldOperand(extra, Code::kFlagsOffset)); |
| 75 | __ and_(offset, ~Code::kFlagsNotUsedInLookup); |
| 76 | __ cmp(offset, flags); |
| 77 | __ j(not_equal, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 79 | #ifdef DEBUG |
| 80 | if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
| 81 | __ jmp(&miss); |
| 82 | } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
| 83 | __ jmp(&miss); |
| 84 | } |
| 85 | #endif |
| 86 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 87 | // Jump to the first instruction in the code stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 88 | __ add(extra, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 89 | __ jmp(extra); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 90 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 91 | __ bind(&miss); |
| 92 | } else { |
| 93 | // Save the offset on the stack. |
| 94 | __ push(offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 96 | // Check that the key in the entry matches the name. |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 97 | __ cmp(name, Operand::StaticArray(offset, times_1, key_offset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 98 | __ j(not_equal, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 99 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 100 | // Check the map matches. |
| 101 | __ mov(offset, Operand::StaticArray(offset, times_1, map_offset)); |
| 102 | __ cmp(offset, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 103 | __ j(not_equal, &miss); |
| 104 | |
| 105 | // Restore offset register. |
| 106 | __ mov(offset, Operand(esp, 0)); |
| 107 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 108 | // Get the code entry from the cache. |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 109 | __ mov(offset, Operand::StaticArray(offset, times_1, value_offset)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 110 | |
| 111 | // Check that the flags match what we're looking for. |
| 112 | __ mov(offset, FieldOperand(offset, Code::kFlagsOffset)); |
| 113 | __ and_(offset, ~Code::kFlagsNotUsedInLookup); |
| 114 | __ cmp(offset, flags); |
| 115 | __ j(not_equal, &miss); |
| 116 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 117 | #ifdef DEBUG |
| 118 | if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
| 119 | __ jmp(&miss); |
| 120 | } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
| 121 | __ jmp(&miss); |
| 122 | } |
| 123 | #endif |
| 124 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 125 | // Restore offset and re-load code entry from cache. |
| 126 | __ pop(offset); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 127 | __ mov(offset, Operand::StaticArray(offset, times_1, value_offset)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 128 | |
| 129 | // Jump to the first instruction in the code stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 130 | __ add(offset, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 131 | __ jmp(offset); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 132 | |
| 133 | // Pop at miss. |
| 134 | __ bind(&miss); |
| 135 | __ pop(offset); |
| 136 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 140 | void StubCompiler::GenerateDictionaryNegativeLookup(MacroAssembler* masm, |
| 141 | Label* miss_label, |
| 142 | Register receiver, |
| 143 | Handle<Name> name, |
| 144 | Register scratch0, |
| 145 | Register scratch1) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 146 | ASSERT(name->IsUniqueName()); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 147 | ASSERT(!receiver.is(scratch0)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 148 | Counters* counters = masm->isolate()->counters(); |
| 149 | __ IncrementCounter(counters->negative_lookups(), 1); |
| 150 | __ IncrementCounter(counters->negative_lookups_miss(), 1); |
| 151 | |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 152 | __ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 153 | |
| 154 | const int kInterceptorOrAccessCheckNeededMask = |
| 155 | (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded); |
| 156 | |
| 157 | // Bail out if the receiver has a named interceptor or requires access checks. |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 158 | __ test_b(FieldOperand(scratch0, Map::kBitFieldOffset), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 159 | kInterceptorOrAccessCheckNeededMask); |
| 160 | __ j(not_zero, miss_label); |
| 161 | |
| 162 | // Check that receiver is a JSObject. |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 163 | __ CmpInstanceType(scratch0, FIRST_SPEC_OBJECT_TYPE); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 164 | __ j(below, miss_label); |
| 165 | |
| 166 | // Load properties array. |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 167 | Register properties = scratch0; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 168 | __ mov(properties, FieldOperand(receiver, JSObject::kPropertiesOffset)); |
| 169 | |
| 170 | // Check that the properties array is a dictionary. |
| 171 | __ cmp(FieldOperand(properties, HeapObject::kMapOffset), |
| 172 | Immediate(masm->isolate()->factory()->hash_table_map())); |
| 173 | __ j(not_equal, miss_label); |
| 174 | |
| 175 | Label done; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 176 | NameDictionaryLookupStub::GenerateNegativeLookup(masm, |
| 177 | miss_label, |
| 178 | &done, |
| 179 | properties, |
| 180 | name, |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 181 | scratch1); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 182 | __ bind(&done); |
| 183 | __ DecrementCounter(counters->negative_lookups_miss(), 1); |
| 184 | } |
| 185 | |
| 186 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | void StubCache::GenerateProbe(MacroAssembler* masm, |
| 188 | Code::Flags flags, |
| 189 | Register receiver, |
| 190 | Register name, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 191 | Register scratch, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 192 | Register extra, |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 193 | Register extra2, |
| 194 | Register extra3) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 195 | Label miss; |
| 196 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 197 | // Assert that code is valid. The multiplying code relies on the entry size |
| 198 | // being 12. |
| 199 | ASSERT(sizeof(Entry) == 12); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 200 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 201 | // Assert the flags do not name a specific type. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 202 | ASSERT(Code::ExtractTypeFromFlags(flags) == 0); |
| 203 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 204 | // Assert that there are no register conflicts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | ASSERT(!scratch.is(receiver)); |
| 206 | ASSERT(!scratch.is(name)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 207 | ASSERT(!extra.is(receiver)); |
| 208 | ASSERT(!extra.is(name)); |
| 209 | ASSERT(!extra.is(scratch)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 210 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 211 | // Assert scratch and extra registers are valid, and extra2/3 are unused. |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 212 | ASSERT(!scratch.is(no_reg)); |
| 213 | ASSERT(extra2.is(no_reg)); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 214 | ASSERT(extra3.is(no_reg)); |
| 215 | |
| 216 | Register offset = scratch; |
| 217 | scratch = no_reg; |
| 218 | |
| 219 | Counters* counters = masm->isolate()->counters(); |
| 220 | __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 221 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | // Check that the receiver isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 223 | __ JumpIfSmi(receiver, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | |
| 225 | // Get the map of the receiver and compute the hash. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 226 | __ mov(offset, FieldOperand(name, Name::kHashFieldOffset)); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 227 | __ add(offset, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 228 | __ xor_(offset, flags); |
| 229 | // We mask out the last two bits because they are not part of the hash and |
| 230 | // they are always 01 for maps. Also in the two 'and' instructions below. |
| 231 | __ and_(offset, (kPrimaryTableSize - 1) << kHeapObjectTagSize); |
| 232 | // ProbeTable expects the offset to be pointer scaled, which it is, because |
| 233 | // the heap object tag size is 2 and the pointer size log 2 is also 2. |
| 234 | ASSERT(kHeapObjectTagSize == kPointerSizeLog2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | |
| 236 | // Probe the primary table. |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 237 | ProbeTable(isolate(), masm, flags, kPrimary, name, receiver, offset, extra); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 238 | |
| 239 | // Primary miss: Compute hash for secondary probe. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 240 | __ mov(offset, FieldOperand(name, Name::kHashFieldOffset)); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 241 | __ add(offset, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 242 | __ xor_(offset, flags); |
| 243 | __ and_(offset, (kPrimaryTableSize - 1) << kHeapObjectTagSize); |
| 244 | __ sub(offset, name); |
| 245 | __ add(offset, Immediate(flags)); |
| 246 | __ and_(offset, (kSecondaryTableSize - 1) << kHeapObjectTagSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | |
| 248 | // Probe the secondary table. |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 249 | ProbeTable( |
| 250 | isolate(), masm, flags, kSecondary, name, receiver, offset, extra); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | |
| 252 | // Cache miss: Fall-through and let caller handle the miss by |
| 253 | // entering the runtime system. |
| 254 | __ bind(&miss); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 255 | __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | |
| 259 | void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, |
| 260 | int index, |
| 261 | Register prototype) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 262 | __ LoadGlobalFunction(index, prototype); |
| 263 | __ LoadGlobalFunctionInitialMap(prototype, prototype); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 264 | // Load the prototype from the initial map. |
| 265 | __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset)); |
| 266 | } |
| 267 | |
| 268 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 269 | void StubCompiler::GenerateDirectLoadGlobalFunctionPrototype( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 270 | MacroAssembler* masm, |
| 271 | int index, |
| 272 | Register prototype, |
| 273 | Label* miss) { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 274 | // Check we're still in the same context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 275 | __ cmp(Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), |
| 276 | masm->isolate()->global_object()); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 277 | __ j(not_equal, miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 278 | // Get the global function with the given index. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 279 | Handle<JSFunction> function( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 280 | JSFunction::cast(masm->isolate()->native_context()->get(index))); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 281 | // Load its initial map. The global functions all have initial maps. |
| 282 | __ Set(prototype, Immediate(Handle<Map>(function->initial_map()))); |
| 283 | // Load the prototype from the initial map. |
| 284 | __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset)); |
| 285 | } |
| 286 | |
| 287 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 288 | void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm, |
| 289 | Register receiver, |
| 290 | Register scratch, |
| 291 | Label* miss_label) { |
| 292 | // Check that the receiver isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 293 | __ JumpIfSmi(receiver, miss_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | |
| 295 | // Check that the object is a JS array. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 296 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 297 | __ j(not_equal, miss_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 298 | |
| 299 | // Load length directly from the JS array. |
| 300 | __ mov(eax, FieldOperand(receiver, JSArray::kLengthOffset)); |
| 301 | __ ret(0); |
| 302 | } |
| 303 | |
| 304 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 305 | // Generate code to check if an object is a string. If the object is |
| 306 | // a string, the map's instance type is left in the scratch register. |
| 307 | static void GenerateStringCheck(MacroAssembler* masm, |
| 308 | Register receiver, |
| 309 | Register scratch, |
| 310 | Label* smi, |
| 311 | Label* non_string_object) { |
| 312 | // Check that the object isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 313 | __ JumpIfSmi(receiver, smi); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 315 | // Check that the object is a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | __ mov(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 317 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 318 | STATIC_ASSERT(kNotStringTag != 0); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 319 | __ test(scratch, Immediate(kNotStringTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 320 | __ j(not_zero, non_string_object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 324 | void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm, |
| 325 | Register receiver, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 326 | Register scratch1, |
| 327 | Register scratch2, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 328 | Label* miss) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 329 | Label check_wrapper; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 331 | // Check if the object is a string leaving the instance type in the |
| 332 | // scratch register. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 333 | GenerateStringCheck(masm, receiver, scratch1, miss, &check_wrapper); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 334 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 335 | // Load length from the string and convert to a smi. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 336 | __ mov(eax, FieldOperand(receiver, String::kLengthOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | __ ret(0); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 338 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 339 | // Check if the object is a JSValue wrapper. |
| 340 | __ bind(&check_wrapper); |
| 341 | __ cmp(scratch1, JS_VALUE_TYPE); |
| 342 | __ j(not_equal, miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 343 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 344 | // Check if the wrapped value is a string and load the length |
| 345 | // directly if it is. |
| 346 | __ mov(scratch2, FieldOperand(receiver, JSValue::kValueOffset)); |
| 347 | GenerateStringCheck(masm, scratch2, scratch1, miss, miss); |
| 348 | __ mov(eax, FieldOperand(scratch2, String::kLengthOffset)); |
| 349 | __ ret(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | |
| 353 | void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm, |
| 354 | Register receiver, |
| 355 | Register scratch1, |
| 356 | Register scratch2, |
| 357 | Label* miss_label) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 358 | __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 359 | __ mov(eax, scratch1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | __ ret(0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 361 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 362 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 363 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 364 | void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm, |
| 365 | Register dst, |
| 366 | Register src, |
| 367 | bool inobject, |
| 368 | int index, |
| 369 | Representation representation) { |
| 370 | ASSERT(!FLAG_track_double_fields || !representation.IsDouble()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 371 | int offset = index * kPointerSize; |
| 372 | if (!inobject) { |
| 373 | // Calculate the offset into the properties array. |
| 374 | offset = offset + FixedArray::kHeaderSize; |
| 375 | __ mov(dst, FieldOperand(src, JSObject::kPropertiesOffset)); |
| 376 | src = dst; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 377 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 378 | __ mov(dst, FieldOperand(src, offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 382 | static void PushInterceptorArguments(MacroAssembler* masm, |
| 383 | Register receiver, |
| 384 | Register holder, |
| 385 | Register name, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 386 | Handle<JSObject> holder_obj) { |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 387 | STATIC_ASSERT(StubCache::kInterceptorArgsNameIndex == 0); |
| 388 | STATIC_ASSERT(StubCache::kInterceptorArgsInfoIndex == 1); |
| 389 | STATIC_ASSERT(StubCache::kInterceptorArgsThisIndex == 2); |
| 390 | STATIC_ASSERT(StubCache::kInterceptorArgsHolderIndex == 3); |
| 391 | STATIC_ASSERT(StubCache::kInterceptorArgsLength == 4); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 392 | __ push(name); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 393 | Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor()); |
| 394 | ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor)); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 395 | Register scratch = name; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 396 | __ mov(scratch, Immediate(interceptor)); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 397 | __ push(scratch); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 398 | __ push(receiver); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 399 | __ push(holder); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 403 | static void CompileCallLoadPropertyWithInterceptor( |
| 404 | MacroAssembler* masm, |
| 405 | Register receiver, |
| 406 | Register holder, |
| 407 | Register name, |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 408 | Handle<JSObject> holder_obj, |
| 409 | IC::UtilityId id) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 410 | PushInterceptorArguments(masm, receiver, holder, name, holder_obj); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 411 | __ CallExternalReference( |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 412 | ExternalReference(IC_Utility(id), masm->isolate()), |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 413 | StubCache::kInterceptorArgsLength); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 417 | // Number of pointers to be reserved on stack for fast API call. |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 418 | static const int kFastApiCallArguments = FunctionCallbackArguments::kArgsLength; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 419 | |
| 420 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 421 | // Reserves space for the extra arguments to API function in the |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 422 | // caller's frame. |
| 423 | // |
| 424 | // These arguments are set by CheckPrototypes and GenerateFastApiCall. |
| 425 | static void ReserveSpaceForFastApiCall(MacroAssembler* masm, Register scratch) { |
| 426 | // ----------- S t a t e ------------- |
| 427 | // -- esp[0] : return address |
| 428 | // -- esp[4] : last argument in the internal frame of the caller |
| 429 | // ----------------------------------- |
| 430 | __ pop(scratch); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 431 | for (int i = 0; i < kFastApiCallArguments; i++) { |
| 432 | __ push(Immediate(Smi::FromInt(0))); |
| 433 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 434 | __ push(scratch); |
| 435 | } |
| 436 | |
| 437 | |
| 438 | // Undoes the effects of ReserveSpaceForFastApiCall. |
| 439 | static void FreeSpaceForFastApiCall(MacroAssembler* masm, Register scratch) { |
| 440 | // ----------- S t a t e ------------- |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 441 | // -- esp[0] : return address. |
| 442 | // -- esp[4] : last fast api call extra argument. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 443 | // -- ... |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 444 | // -- esp[kFastApiCallArguments * 4] : first fast api call extra argument. |
| 445 | // -- esp[kFastApiCallArguments * 4 + 4] : last argument in the internal |
| 446 | // frame. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 447 | // ----------------------------------- |
| 448 | __ pop(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 449 | __ add(esp, Immediate(kPointerSize * kFastApiCallArguments)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 450 | __ push(scratch); |
| 451 | } |
| 452 | |
| 453 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 454 | static void GenerateFastApiCallBody(MacroAssembler* masm, |
| 455 | const CallOptimization& optimization, |
| 456 | int argc, |
| 457 | bool restore_context); |
| 458 | |
| 459 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 460 | // Generates call to API function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 461 | static void GenerateFastApiCall(MacroAssembler* masm, |
| 462 | const CallOptimization& optimization, |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 463 | int argc) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 464 | typedef FunctionCallbackArguments FCA; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 465 | // Save calling context. |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 466 | __ mov(Operand(esp, (1 + FCA::kContextSaveIndex) * kPointerSize), esi); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 467 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 468 | // Get the function and setup the context. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 469 | Handle<JSFunction> function = optimization.constant_function(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 470 | __ LoadHeapObject(edi, function); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 471 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 472 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 473 | // Construct the FunctionCallbackInfo. |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 474 | __ mov(Operand(esp, (1 + FCA::kCalleeIndex) * kPointerSize), edi); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 475 | Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 476 | Handle<Object> call_data(api_call_info->data(), masm->isolate()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 477 | if (masm->isolate()->heap()->InNewSpace(*call_data)) { |
| 478 | __ mov(ecx, api_call_info); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 479 | __ mov(ebx, FieldOperand(ecx, CallHandlerInfo::kDataOffset)); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 480 | __ mov(Operand(esp, (1 + FCA::kDataIndex) * kPointerSize), ebx); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 481 | } else { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 482 | __ mov(Operand(esp, (1 + FCA::kDataIndex) * kPointerSize), |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 483 | Immediate(call_data)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 484 | } |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 485 | __ mov(Operand(esp, (1 + FCA::kIsolateIndex) * kPointerSize), |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 486 | Immediate(reinterpret_cast<int>(masm->isolate()))); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 487 | __ mov(Operand(esp, (1 + FCA::kReturnValueOffset) * kPointerSize), |
hpayer@chromium.org | 4f626d1 | 2013-09-18 07:47:45 +0000 | [diff] [blame] | 488 | masm->isolate()->factory()->undefined_value()); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 489 | __ mov(Operand(esp, (1 + FCA::kReturnValueDefaultValueIndex) * kPointerSize), |
| 490 | masm->isolate()->factory()->undefined_value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 491 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 492 | // Prepare arguments. |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 493 | STATIC_ASSERT(kFastApiCallArguments == 7); |
| 494 | __ lea(eax, Operand(esp, 1 * kPointerSize)); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 495 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 496 | GenerateFastApiCallBody(masm, optimization, argc, false); |
| 497 | } |
| 498 | |
| 499 | |
| 500 | // Generate call to api function. |
| 501 | // This function uses push() to generate smaller, faster code than |
| 502 | // the version above. It is an optimization that should will be removed |
| 503 | // when api call ICs are generated in hydrogen. |
| 504 | static void GenerateFastApiCall(MacroAssembler* masm, |
| 505 | const CallOptimization& optimization, |
| 506 | Register receiver, |
| 507 | Register scratch1, |
| 508 | Register scratch2, |
| 509 | Register scratch3, |
| 510 | int argc, |
| 511 | Register* values) { |
| 512 | ASSERT(optimization.is_simple_api_call()); |
| 513 | |
| 514 | // Copy return value. |
| 515 | __ pop(scratch1); |
| 516 | |
| 517 | // receiver |
| 518 | __ push(receiver); |
| 519 | |
| 520 | // Write the arguments to stack frame. |
| 521 | for (int i = 0; i < argc; i++) { |
| 522 | Register arg = values[argc-1-i]; |
| 523 | ASSERT(!receiver.is(arg)); |
| 524 | ASSERT(!scratch1.is(arg)); |
| 525 | ASSERT(!scratch2.is(arg)); |
| 526 | ASSERT(!scratch3.is(arg)); |
| 527 | __ push(arg); |
| 528 | } |
| 529 | |
| 530 | typedef FunctionCallbackArguments FCA; |
| 531 | |
| 532 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 533 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 534 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 535 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 536 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 537 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 538 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 539 | STATIC_ASSERT(FCA::kArgsLength == 7); |
| 540 | |
| 541 | // context save |
| 542 | __ push(esi); |
| 543 | |
| 544 | // Get the function and setup the context. |
| 545 | Handle<JSFunction> function = optimization.constant_function(); |
| 546 | __ LoadHeapObject(scratch2, function); |
| 547 | __ mov(esi, FieldOperand(scratch2, JSFunction::kContextOffset)); |
| 548 | // callee |
| 549 | __ push(scratch2); |
| 550 | |
| 551 | Isolate* isolate = masm->isolate(); |
| 552 | Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 553 | Handle<Object> call_data(api_call_info->data(), isolate); |
| 554 | // Push data from ExecutableAccessorInfo. |
| 555 | if (isolate->heap()->InNewSpace(*call_data)) { |
| 556 | __ mov(scratch2, api_call_info); |
| 557 | __ mov(scratch3, FieldOperand(scratch2, CallHandlerInfo::kDataOffset)); |
| 558 | __ push(scratch3); |
| 559 | } else { |
| 560 | __ push(Immediate(call_data)); |
| 561 | } |
| 562 | // return value |
| 563 | __ push(Immediate(isolate->factory()->undefined_value())); |
| 564 | // return value default |
| 565 | __ push(Immediate(isolate->factory()->undefined_value())); |
| 566 | // isolate |
| 567 | __ push(Immediate(reinterpret_cast<int>(isolate))); |
| 568 | // holder |
| 569 | __ push(receiver); |
| 570 | |
| 571 | // store receiver address for GenerateFastApiCallBody |
| 572 | ASSERT(!scratch1.is(eax)); |
| 573 | __ mov(eax, esp); |
| 574 | |
| 575 | // return address |
| 576 | __ push(scratch1); |
| 577 | |
| 578 | GenerateFastApiCallBody(masm, optimization, argc, true); |
| 579 | } |
| 580 | |
| 581 | |
| 582 | static void GenerateFastApiCallBody(MacroAssembler* masm, |
| 583 | const CallOptimization& optimization, |
| 584 | int argc, |
| 585 | bool restore_context) { |
| 586 | // ----------- S t a t e ------------- |
| 587 | // -- esp[0] : return address |
| 588 | // -- esp[4] - esp[28] : FunctionCallbackInfo, incl. |
| 589 | // : object passing the type check |
| 590 | // (set by CheckPrototypes) |
| 591 | // -- esp[32] : last argument |
| 592 | // -- ... |
| 593 | // -- esp[(argc + 7) * 4] : first argument |
| 594 | // -- esp[(argc + 8) * 4] : receiver |
| 595 | // |
| 596 | // -- eax : receiver address |
| 597 | // ----------------------------------- |
| 598 | typedef FunctionCallbackArguments FCA; |
| 599 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 600 | // API function gets reference to the v8::Arguments. If CPU profiler |
| 601 | // is enabled wrapper function will be called and we need to pass |
| 602 | // address of the callback as additional parameter, always allocate |
| 603 | // space for it. |
| 604 | const int kApiArgc = 1 + 1; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 605 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 606 | // Allocate the v8::Arguments structure in the arguments' space since |
| 607 | // it's not controlled by GC. |
| 608 | const int kApiStackSpace = 4; |
| 609 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 610 | Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 611 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 612 | // Function address is a foreign pointer outside V8's heap. |
| 613 | Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 614 | __ PrepareCallApiFunction(kApiArgc + kApiStackSpace); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 615 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 616 | // FunctionCallbackInfo::implicit_args_. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 617 | __ mov(ApiParameterOperand(2), eax); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 618 | __ add(eax, Immediate((argc + kFastApiCallArguments - 1) * kPointerSize)); |
| 619 | // FunctionCallbackInfo::values_. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 620 | __ mov(ApiParameterOperand(3), eax); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 621 | // FunctionCallbackInfo::length_. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 622 | __ Set(ApiParameterOperand(4), Immediate(argc)); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 623 | // FunctionCallbackInfo::is_construct_call_. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 624 | __ Set(ApiParameterOperand(5), Immediate(0)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 625 | |
| 626 | // v8::InvocationCallback's argument. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 627 | __ lea(eax, ApiParameterOperand(2)); |
| 628 | __ mov(ApiParameterOperand(0), eax); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 629 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 630 | Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 631 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 632 | Operand context_restore_operand(ebp, |
| 633 | (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 634 | Operand return_value_operand(ebp, |
| 635 | (2 + FCA::kReturnValueOffset) * kPointerSize); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 636 | __ CallApiFunctionAndReturn(function_address, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 637 | thunk_address, |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 638 | ApiParameterOperand(1), |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 639 | argc + kFastApiCallArguments + 1, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 640 | return_value_operand, |
| 641 | restore_context ? |
| 642 | &context_restore_operand : NULL); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 646 | class CallInterceptorCompiler BASE_EMBEDDED { |
| 647 | public: |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 648 | CallInterceptorCompiler(CallStubCompiler* stub_compiler, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 649 | const ParameterCount& arguments, |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 650 | Register name) |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 651 | : stub_compiler_(stub_compiler), |
| 652 | arguments_(arguments), |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 653 | name_(name) {} |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 654 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 655 | void Compile(MacroAssembler* masm, |
| 656 | Handle<JSObject> object, |
| 657 | Handle<JSObject> holder, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 658 | Handle<Name> name, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 659 | LookupResult* lookup, |
| 660 | Register receiver, |
| 661 | Register scratch1, |
| 662 | Register scratch2, |
| 663 | Register scratch3, |
| 664 | Label* miss) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 665 | ASSERT(holder->HasNamedInterceptor()); |
| 666 | ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 667 | |
| 668 | // Check that the receiver isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 669 | __ JumpIfSmi(receiver, miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 670 | |
| 671 | CallOptimization optimization(lookup); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 672 | if (optimization.is_constant_call()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 673 | CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3, |
| 674 | holder, lookup, name, optimization, miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 675 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 676 | CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3, |
| 677 | name, holder, miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
| 681 | private: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 682 | void CompileCacheable(MacroAssembler* masm, |
| 683 | Handle<JSObject> object, |
| 684 | Register receiver, |
| 685 | Register scratch1, |
| 686 | Register scratch2, |
| 687 | Register scratch3, |
| 688 | Handle<JSObject> interceptor_holder, |
| 689 | LookupResult* lookup, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 690 | Handle<Name> name, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 691 | const CallOptimization& optimization, |
| 692 | Label* miss_label) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 693 | ASSERT(optimization.is_constant_call()); |
| 694 | ASSERT(!lookup->holder()->IsGlobalObject()); |
| 695 | |
| 696 | int depth1 = kInvalidProtoDepth; |
| 697 | int depth2 = kInvalidProtoDepth; |
| 698 | bool can_do_fast_api_call = false; |
| 699 | if (optimization.is_simple_api_call() && |
| 700 | !lookup->holder()->IsGlobalObject()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 701 | depth1 = optimization.GetPrototypeDepthOfExpectedType( |
| 702 | object, interceptor_holder); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 703 | if (depth1 == kInvalidProtoDepth) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 704 | depth2 = optimization.GetPrototypeDepthOfExpectedType( |
| 705 | interceptor_holder, Handle<JSObject>(lookup->holder())); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 706 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 707 | can_do_fast_api_call = |
| 708 | depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 709 | } |
| 710 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 711 | Counters* counters = masm->isolate()->counters(); |
| 712 | __ IncrementCounter(counters->call_const_interceptor(), 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 713 | |
| 714 | if (can_do_fast_api_call) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 715 | __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 716 | ReserveSpaceForFastApiCall(masm, scratch1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 717 | } |
| 718 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 719 | // Check that the maps from receiver to interceptor's holder |
| 720 | // haven't changed and thus we can invoke interceptor. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 721 | Label miss_cleanup; |
| 722 | Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label; |
| 723 | Register holder = |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 724 | stub_compiler_->CheckPrototypes( |
| 725 | IC::CurrentTypeOf(object, masm->isolate()), receiver, |
| 726 | interceptor_holder, scratch1, scratch2, scratch3, |
| 727 | name, depth1, miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 728 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 729 | // Invoke an interceptor and if it provides a value, |
| 730 | // branch to |regular_invoke|. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 731 | Label regular_invoke; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 732 | LoadWithInterceptor(masm, receiver, holder, interceptor_holder, |
| 733 | ®ular_invoke); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 734 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 735 | // Interceptor returned nothing for this property. Try to use cached |
| 736 | // constant function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 737 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 738 | // Check that the maps from interceptor's holder to constant function's |
| 739 | // holder haven't changed and thus we can use cached constant function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 740 | if (*interceptor_holder != lookup->holder()) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 741 | stub_compiler_->CheckPrototypes( |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 742 | IC::CurrentTypeOf(interceptor_holder, masm->isolate()), holder, |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 743 | handle(lookup->holder()), scratch1, scratch2, scratch3, |
| 744 | name, depth2, miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 745 | } else { |
| 746 | // CheckPrototypes has a side effect of fetching a 'holder' |
| 747 | // for API (object which is instanceof for the signature). It's |
| 748 | // safe to omit it here, as if present, it should be fetched |
| 749 | // by the previous CheckPrototypes. |
| 750 | ASSERT(depth2 == kInvalidProtoDepth); |
| 751 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 752 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 753 | // Invoke function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 754 | if (can_do_fast_api_call) { |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 755 | GenerateFastApiCall(masm, optimization, arguments_.immediate()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 756 | } else { |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 757 | Handle<JSFunction> fun = optimization.constant_function(); |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 758 | stub_compiler_->GenerateJumpFunction(object, fun); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 759 | } |
| 760 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 761 | // Deferred code for fast API call case---clean preallocated space. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 762 | if (can_do_fast_api_call) { |
| 763 | __ bind(&miss_cleanup); |
| 764 | FreeSpaceForFastApiCall(masm, scratch1); |
| 765 | __ jmp(miss_label); |
| 766 | } |
| 767 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 768 | // Invoke a regular function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 769 | __ bind(®ular_invoke); |
| 770 | if (can_do_fast_api_call) { |
| 771 | FreeSpaceForFastApiCall(masm, scratch1); |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | void CompileRegular(MacroAssembler* masm, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 776 | Handle<JSObject> object, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 777 | Register receiver, |
| 778 | Register scratch1, |
| 779 | Register scratch2, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 780 | Register scratch3, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 781 | Handle<Name> name, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 782 | Handle<JSObject> interceptor_holder, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 783 | Label* miss_label) { |
| 784 | Register holder = |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 785 | stub_compiler_->CheckPrototypes( |
| 786 | IC::CurrentTypeOf(object, masm->isolate()), receiver, |
| 787 | interceptor_holder, scratch1, scratch2, scratch3, name, miss_label); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 788 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 789 | FrameScope scope(masm, StackFrame::INTERNAL); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 790 | // Save the name_ register across the call. |
| 791 | __ push(name_); |
| 792 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 793 | CompileCallLoadPropertyWithInterceptor( |
| 794 | masm, receiver, holder, name_, interceptor_holder, |
| 795 | IC::kLoadPropertyWithInterceptorForCall); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 796 | |
| 797 | // Restore the name_ register. |
| 798 | __ pop(name_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 799 | |
| 800 | // Leave the internal frame. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | void LoadWithInterceptor(MacroAssembler* masm, |
| 804 | Register receiver, |
| 805 | Register holder, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 806 | Handle<JSObject> holder_obj, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 807 | Label* interceptor_succeeded) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 808 | { |
| 809 | FrameScope scope(masm, StackFrame::INTERNAL); |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 810 | __ push(receiver); |
| 811 | __ push(holder); |
| 812 | __ push(name_); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 813 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 814 | CompileCallLoadPropertyWithInterceptor( |
| 815 | masm, receiver, holder, name_, holder_obj, |
| 816 | IC::kLoadPropertyWithInterceptorOnly); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 817 | |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 818 | __ pop(name_); |
| 819 | __ pop(holder); |
| 820 | __ pop(receiver); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 821 | // Leave the internal frame. |
| 822 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 823 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 824 | __ cmp(eax, masm->isolate()->factory()->no_interceptor_result_sentinel()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 825 | __ j(not_equal, interceptor_succeeded); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 826 | } |
| 827 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 828 | CallStubCompiler* stub_compiler_; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 829 | const ParameterCount& arguments_; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 830 | Register name_; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 831 | }; |
| 832 | |
| 833 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 834 | void StoreStubCompiler::GenerateRestoreName(MacroAssembler* masm, |
| 835 | Label* label, |
| 836 | Handle<Name> name) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 837 | if (!label->is_unused()) { |
| 838 | __ bind(label); |
| 839 | __ mov(this->name(), Immediate(name)); |
| 840 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 844 | // Generate code to check that a global property cell is empty. Create |
| 845 | // the property cell at compilation time if no cell exists for the |
| 846 | // property. |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 847 | void StubCompiler::GenerateCheckPropertyCell(MacroAssembler* masm, |
| 848 | Handle<JSGlobalObject> global, |
| 849 | Handle<Name> name, |
| 850 | Register scratch, |
| 851 | Label* miss) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 852 | Handle<PropertyCell> cell = |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 853 | JSGlobalObject::EnsurePropertyCell(global, name); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 854 | ASSERT(cell->value()->IsTheHole()); |
| 855 | Handle<Oddball> the_hole = masm->isolate()->factory()->the_hole_value(); |
| 856 | if (Serializer::enabled()) { |
| 857 | __ mov(scratch, Immediate(cell)); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 858 | __ cmp(FieldOperand(scratch, PropertyCell::kValueOffset), |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 859 | Immediate(the_hole)); |
| 860 | } else { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 861 | __ cmp(Operand::ForCell(cell), Immediate(the_hole)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 862 | } |
| 863 | __ j(not_equal, miss); |
| 864 | } |
| 865 | |
| 866 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 867 | void StoreStubCompiler::GenerateNegativeHolderLookup( |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 868 | MacroAssembler* masm, |
| 869 | Handle<JSObject> holder, |
| 870 | Register holder_reg, |
| 871 | Handle<Name> name, |
| 872 | Label* miss) { |
| 873 | if (holder->IsJSGlobalObject()) { |
| 874 | GenerateCheckPropertyCell( |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 875 | masm, Handle<JSGlobalObject>::cast(holder), name, scratch1(), miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 876 | } else if (!holder->HasFastProperties() && !holder->IsJSGlobalProxy()) { |
| 877 | GenerateDictionaryNegativeLookup( |
| 878 | masm, miss, holder_reg, name, scratch1(), scratch2()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 879 | } |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 880 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 881 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 882 | |
| 883 | // Receiver_reg is preserved on jumps to miss_label, but may be destroyed if |
| 884 | // store is successful. |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 885 | void StoreStubCompiler::GenerateStoreTransition(MacroAssembler* masm, |
| 886 | Handle<JSObject> object, |
| 887 | LookupResult* lookup, |
| 888 | Handle<Map> transition, |
| 889 | Handle<Name> name, |
| 890 | Register receiver_reg, |
| 891 | Register storage_reg, |
| 892 | Register value_reg, |
| 893 | Register scratch1, |
| 894 | Register scratch2, |
| 895 | Register unused, |
| 896 | Label* miss_label, |
| 897 | Label* slow) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 898 | int descriptor = transition->LastAdded(); |
| 899 | DescriptorArray* descriptors = transition->instance_descriptors(); |
| 900 | PropertyDetails details = descriptors->GetDetails(descriptor); |
| 901 | Representation representation = details.representation(); |
| 902 | ASSERT(!representation.IsNone()); |
| 903 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 904 | if (details.type() == CONSTANT) { |
| 905 | Handle<Object> constant(descriptors->GetValue(descriptor), masm->isolate()); |
| 906 | __ CmpObject(value_reg, constant); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 907 | __ j(not_equal, miss_label); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 908 | } else if (FLAG_track_fields && representation.IsSmi()) { |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 909 | __ JumpIfNotSmi(value_reg, miss_label); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 910 | } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) { |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 911 | __ JumpIfSmi(value_reg, miss_label); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 912 | } else if (FLAG_track_double_fields && representation.IsDouble()) { |
| 913 | Label do_store, heap_number; |
| 914 | __ AllocateHeapNumber(storage_reg, scratch1, scratch2, slow); |
| 915 | |
| 916 | __ JumpIfNotSmi(value_reg, &heap_number); |
| 917 | __ SmiUntag(value_reg); |
| 918 | if (CpuFeatures::IsSupported(SSE2)) { |
| 919 | CpuFeatureScope use_sse2(masm, SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 920 | __ Cvtsi2sd(xmm0, value_reg); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 921 | } else { |
| 922 | __ push(value_reg); |
| 923 | __ fild_s(Operand(esp, 0)); |
| 924 | __ pop(value_reg); |
| 925 | } |
| 926 | __ SmiTag(value_reg); |
| 927 | __ jmp(&do_store); |
| 928 | |
| 929 | __ bind(&heap_number); |
| 930 | __ CheckMap(value_reg, masm->isolate()->factory()->heap_number_map(), |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 931 | miss_label, DONT_DO_SMI_CHECK); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 932 | if (CpuFeatures::IsSupported(SSE2)) { |
| 933 | CpuFeatureScope use_sse2(masm, SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 934 | __ movsd(xmm0, FieldOperand(value_reg, HeapNumber::kValueOffset)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 935 | } else { |
| 936 | __ fld_d(FieldOperand(value_reg, HeapNumber::kValueOffset)); |
| 937 | } |
| 938 | |
| 939 | __ bind(&do_store); |
| 940 | if (CpuFeatures::IsSupported(SSE2)) { |
| 941 | CpuFeatureScope use_sse2(masm, SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 942 | __ movsd(FieldOperand(storage_reg, HeapNumber::kValueOffset), xmm0); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 943 | } else { |
| 944 | __ fstp_d(FieldOperand(storage_reg, HeapNumber::kValueOffset)); |
| 945 | } |
| 946 | } |
| 947 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 948 | // Stub never generated for non-global objects that require access |
| 949 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 950 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 951 | |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 952 | // Perform map transition for the receiver if necessary. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 953 | if (details.type() == FIELD && |
| 954 | object->map()->unused_property_fields() == 0) { |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 955 | // The properties must be extended before we can store the value. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 956 | // We jump to a runtime call that extends the properties array. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 957 | __ pop(scratch1); // Return address. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 958 | __ push(receiver_reg); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 959 | __ push(Immediate(transition)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 960 | __ push(value_reg); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 961 | __ push(scratch1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 962 | __ TailCallExternalReference( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 963 | ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage), |
| 964 | masm->isolate()), |
| 965 | 3, |
| 966 | 1); |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 967 | return; |
| 968 | } |
| 969 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 970 | // Update the map of the object. |
| 971 | __ mov(scratch1, Immediate(transition)); |
| 972 | __ mov(FieldOperand(receiver_reg, HeapObject::kMapOffset), scratch1); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 973 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 974 | // Update the write barrier for the map field. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 975 | __ RecordWriteField(receiver_reg, |
| 976 | HeapObject::kMapOffset, |
| 977 | scratch1, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 978 | scratch2, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 979 | kDontSaveFPRegs, |
| 980 | OMIT_REMEMBERED_SET, |
| 981 | OMIT_SMI_CHECK); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 982 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 983 | if (details.type() == CONSTANT) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 984 | ASSERT(value_reg.is(eax)); |
| 985 | __ ret(0); |
| 986 | return; |
| 987 | } |
| 988 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 989 | int index = transition->instance_descriptors()->GetFieldIndex( |
| 990 | transition->LastAdded()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 991 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 992 | // Adjust for the number of properties stored in the object. Even in the |
| 993 | // face of a transition we can use the old map here because the size of the |
| 994 | // object and the number of in-object properties is not going to change. |
| 995 | index -= object->map()->inobject_properties(); |
| 996 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 997 | SmiCheck smi_check = representation.IsTagged() |
| 998 | ? INLINE_SMI_CHECK : OMIT_SMI_CHECK; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 999 | // TODO(verwaest): Share this code as a code stub. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1000 | if (index < 0) { |
| 1001 | // Set the property straight into the object. |
| 1002 | int offset = object->map()->instance_size() + (index * kPointerSize); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1003 | if (FLAG_track_double_fields && representation.IsDouble()) { |
| 1004 | __ mov(FieldOperand(receiver_reg, offset), storage_reg); |
| 1005 | } else { |
| 1006 | __ mov(FieldOperand(receiver_reg, offset), value_reg); |
| 1007 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1008 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1009 | if (!FLAG_track_fields || !representation.IsSmi()) { |
| 1010 | // Update the write barrier for the array address. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1011 | if (!FLAG_track_double_fields || !representation.IsDouble()) { |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1012 | __ mov(storage_reg, value_reg); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1013 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1014 | __ RecordWriteField(receiver_reg, |
| 1015 | offset, |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1016 | storage_reg, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1017 | scratch1, |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1018 | kDontSaveFPRegs, |
| 1019 | EMIT_REMEMBERED_SET, |
| 1020 | smi_check); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1021 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1022 | } else { |
| 1023 | // Write to the properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1024 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1025 | // Get the properties array (optimistically). |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1026 | __ mov(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1027 | if (FLAG_track_double_fields && representation.IsDouble()) { |
| 1028 | __ mov(FieldOperand(scratch1, offset), storage_reg); |
| 1029 | } else { |
| 1030 | __ mov(FieldOperand(scratch1, offset), value_reg); |
| 1031 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1032 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1033 | if (!FLAG_track_fields || !representation.IsSmi()) { |
| 1034 | // Update the write barrier for the array address. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1035 | if (!FLAG_track_double_fields || !representation.IsDouble()) { |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1036 | __ mov(storage_reg, value_reg); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1037 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1038 | __ RecordWriteField(scratch1, |
| 1039 | offset, |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1040 | storage_reg, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1041 | receiver_reg, |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1042 | kDontSaveFPRegs, |
| 1043 | EMIT_REMEMBERED_SET, |
| 1044 | smi_check); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1045 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1046 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1047 | |
| 1048 | // Return the value (register eax). |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1049 | ASSERT(value_reg.is(eax)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1050 | __ ret(0); |
| 1051 | } |
| 1052 | |
| 1053 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1054 | // Both name_reg and receiver_reg are preserved on jumps to miss_label, |
| 1055 | // but may be destroyed if store is successful. |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 1056 | void StoreStubCompiler::GenerateStoreField(MacroAssembler* masm, |
| 1057 | Handle<JSObject> object, |
| 1058 | LookupResult* lookup, |
| 1059 | Register receiver_reg, |
| 1060 | Register name_reg, |
| 1061 | Register value_reg, |
| 1062 | Register scratch1, |
| 1063 | Register scratch2, |
| 1064 | Label* miss_label) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1065 | // Stub never generated for non-global objects that require access |
| 1066 | // checks. |
| 1067 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
| 1068 | |
| 1069 | int index = lookup->GetFieldIndex().field_index(); |
| 1070 | |
| 1071 | // Adjust for the number of properties stored in the object. Even in the |
| 1072 | // face of a transition we can use the old map here because the size of the |
| 1073 | // object and the number of in-object properties is not going to change. |
| 1074 | index -= object->map()->inobject_properties(); |
| 1075 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1076 | Representation representation = lookup->representation(); |
| 1077 | ASSERT(!representation.IsNone()); |
| 1078 | if (FLAG_track_fields && representation.IsSmi()) { |
| 1079 | __ JumpIfNotSmi(value_reg, miss_label); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1080 | } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) { |
| 1081 | __ JumpIfSmi(value_reg, miss_label); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1082 | } else if (FLAG_track_double_fields && representation.IsDouble()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1083 | // Load the double storage. |
| 1084 | if (index < 0) { |
| 1085 | int offset = object->map()->instance_size() + (index * kPointerSize); |
| 1086 | __ mov(scratch1, FieldOperand(receiver_reg, offset)); |
| 1087 | } else { |
| 1088 | __ mov(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset)); |
| 1089 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
| 1090 | __ mov(scratch1, FieldOperand(scratch1, offset)); |
| 1091 | } |
| 1092 | |
| 1093 | // Store the value into the storage. |
| 1094 | Label do_store, heap_number; |
| 1095 | __ JumpIfNotSmi(value_reg, &heap_number); |
| 1096 | __ SmiUntag(value_reg); |
| 1097 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1098 | CpuFeatureScope use_sse2(masm, SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1099 | __ Cvtsi2sd(xmm0, value_reg); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1100 | } else { |
| 1101 | __ push(value_reg); |
| 1102 | __ fild_s(Operand(esp, 0)); |
| 1103 | __ pop(value_reg); |
| 1104 | } |
| 1105 | __ SmiTag(value_reg); |
| 1106 | __ jmp(&do_store); |
| 1107 | __ bind(&heap_number); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1108 | __ CheckMap(value_reg, masm->isolate()->factory()->heap_number_map(), |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1109 | miss_label, DONT_DO_SMI_CHECK); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1110 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1111 | CpuFeatureScope use_sse2(masm, SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1112 | __ movsd(xmm0, FieldOperand(value_reg, HeapNumber::kValueOffset)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1113 | } else { |
| 1114 | __ fld_d(FieldOperand(value_reg, HeapNumber::kValueOffset)); |
| 1115 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1116 | __ bind(&do_store); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1117 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1118 | CpuFeatureScope use_sse2(masm, SSE2); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1119 | __ movsd(FieldOperand(scratch1, HeapNumber::kValueOffset), xmm0); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1120 | } else { |
| 1121 | __ fstp_d(FieldOperand(scratch1, HeapNumber::kValueOffset)); |
| 1122 | } |
| 1123 | // Return the value (register eax). |
| 1124 | ASSERT(value_reg.is(eax)); |
| 1125 | __ ret(0); |
| 1126 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1129 | ASSERT(!FLAG_track_double_fields || !representation.IsDouble()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1130 | // TODO(verwaest): Share this code as a code stub. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1131 | SmiCheck smi_check = representation.IsTagged() |
| 1132 | ? INLINE_SMI_CHECK : OMIT_SMI_CHECK; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1133 | if (index < 0) { |
| 1134 | // Set the property straight into the object. |
| 1135 | int offset = object->map()->instance_size() + (index * kPointerSize); |
| 1136 | __ mov(FieldOperand(receiver_reg, offset), value_reg); |
| 1137 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1138 | if (!FLAG_track_fields || !representation.IsSmi()) { |
| 1139 | // Update the write barrier for the array address. |
| 1140 | // Pass the value being stored in the now unused name_reg. |
| 1141 | __ mov(name_reg, value_reg); |
| 1142 | __ RecordWriteField(receiver_reg, |
| 1143 | offset, |
| 1144 | name_reg, |
| 1145 | scratch1, |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1146 | kDontSaveFPRegs, |
| 1147 | EMIT_REMEMBERED_SET, |
| 1148 | smi_check); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1149 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1150 | } else { |
| 1151 | // Write to the properties array. |
| 1152 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
| 1153 | // Get the properties array (optimistically). |
| 1154 | __ mov(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1155 | __ mov(FieldOperand(scratch1, offset), value_reg); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1156 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1157 | if (!FLAG_track_fields || !representation.IsSmi()) { |
| 1158 | // Update the write barrier for the array address. |
| 1159 | // Pass the value being stored in the now unused name_reg. |
| 1160 | __ mov(name_reg, value_reg); |
| 1161 | __ RecordWriteField(scratch1, |
| 1162 | offset, |
| 1163 | name_reg, |
| 1164 | receiver_reg, |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1165 | kDontSaveFPRegs, |
| 1166 | EMIT_REMEMBERED_SET, |
| 1167 | smi_check); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1168 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | // Return the value (register eax). |
| 1172 | ASSERT(value_reg.is(eax)); |
| 1173 | __ ret(0); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1177 | void StubCompiler::GenerateTailCall(MacroAssembler* masm, Handle<Code> code) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1178 | __ jmp(code, RelocInfo::CODE_TARGET); |
| 1179 | } |
| 1180 | |
| 1181 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1182 | #undef __ |
| 1183 | #define __ ACCESS_MASM(masm()) |
| 1184 | |
| 1185 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1186 | Register StubCompiler::CheckPrototypes(Handle<Type> type, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1187 | Register object_reg, |
| 1188 | Handle<JSObject> holder, |
| 1189 | Register holder_reg, |
| 1190 | Register scratch1, |
| 1191 | Register scratch2, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1192 | Handle<Name> name, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1193 | int save_at_depth, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1194 | Label* miss, |
| 1195 | PrototypeCheckType check) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1196 | Handle<Map> receiver_map(IC::TypeToMap(*type, isolate())); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1197 | // Make sure that the type feedback oracle harvests the receiver map. |
| 1198 | // TODO(svenpanne) Remove this hack when all ICs are reworked. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1199 | __ mov(scratch1, receiver_map); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1200 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1201 | // Make sure there's no overlap between holder and object registers. |
| 1202 | ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg)); |
| 1203 | ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg) |
| 1204 | && !scratch2.is(scratch1)); |
| 1205 | |
| 1206 | // Keep track of the current object in register reg. |
| 1207 | Register reg = object_reg; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1208 | int depth = 0; |
| 1209 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1210 | const int kHolderIndex = FunctionCallbackArguments::kHolderIndex + 1; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1211 | if (save_at_depth == depth) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1212 | __ mov(Operand(esp, kHolderIndex * kPointerSize), reg); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1215 | Handle<JSObject> current = Handle<JSObject>::null(); |
| 1216 | if (type->IsConstant()) current = Handle<JSObject>::cast(type->AsConstant()); |
| 1217 | Handle<JSObject> prototype = Handle<JSObject>::null(); |
| 1218 | Handle<Map> current_map = receiver_map; |
| 1219 | Handle<Map> holder_map(holder->map()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1220 | // Traverse the prototype chain and check the maps in the prototype chain for |
| 1221 | // fast and global objects or do negative lookup for normal objects. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1222 | while (!current_map.is_identical_to(holder_map)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1223 | ++depth; |
| 1224 | |
| 1225 | // Only global objects and objects that do not require access |
| 1226 | // checks are allowed in stubs. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1227 | ASSERT(current_map->IsJSGlobalProxyMap() || |
| 1228 | !current_map->is_access_check_needed()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1229 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1230 | prototype = handle(JSObject::cast(current_map->prototype())); |
| 1231 | if (current_map->is_dictionary_map() && |
| 1232 | !current_map->IsJSGlobalObjectMap() && |
| 1233 | !current_map->IsJSGlobalProxyMap()) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1234 | if (!name->IsUniqueName()) { |
| 1235 | ASSERT(name->IsString()); |
| 1236 | name = factory()->InternalizeString(Handle<String>::cast(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1237 | } |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1238 | ASSERT(current.is_null() || |
| 1239 | current->property_dictionary()->FindEntry(*name) == |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1240 | NameDictionary::kNotFound); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1241 | |
| 1242 | GenerateDictionaryNegativeLookup(masm(), miss, reg, name, |
| 1243 | scratch1, scratch2); |
| 1244 | |
| 1245 | __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); |
| 1246 | reg = holder_reg; // From now on the object will be in holder_reg. |
| 1247 | __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset)); |
| 1248 | } else { |
| 1249 | bool in_new_space = heap()->InNewSpace(*prototype); |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1250 | if (depth != 1 || check == CHECK_ALL_MAPS) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1251 | __ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1252 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1253 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1254 | // Check access rights to the global object. This has to happen after |
| 1255 | // the map check so that we know that the object is actually a global |
| 1256 | // object. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1257 | if (current_map->IsJSGlobalProxyMap()) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1258 | __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss); |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1259 | } else if (current_map->IsJSGlobalObjectMap()) { |
| 1260 | GenerateCheckPropertyCell( |
| 1261 | masm(), Handle<JSGlobalObject>::cast(current), name, |
| 1262 | scratch2, miss); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1263 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1264 | |
| 1265 | if (in_new_space) { |
| 1266 | // Save the map in scratch1 for later. |
| 1267 | __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); |
| 1268 | } |
| 1269 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1270 | reg = holder_reg; // From now on the object will be in holder_reg. |
| 1271 | |
| 1272 | if (in_new_space) { |
| 1273 | // The prototype is in new space; we cannot store a reference to it |
| 1274 | // in the code. Load it from the map. |
| 1275 | __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset)); |
| 1276 | } else { |
| 1277 | // The prototype is in old space; load it directly. |
| 1278 | __ mov(reg, prototype); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | if (save_at_depth == depth) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1283 | __ mov(Operand(esp, kHolderIndex * kPointerSize), reg); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | // Go to the next object in the prototype chain. |
| 1287 | current = prototype; |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1288 | current_map = handle(current->map()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1289 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1290 | |
| 1291 | // Log the check depth. |
| 1292 | LOG(isolate(), IntEvent("check-maps-depth", depth + 1)); |
| 1293 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1294 | if (depth != 0 || check == CHECK_ALL_MAPS) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1295 | // Check the holder map. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1296 | __ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1297 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1298 | |
| 1299 | // Perform security check for access to the global object. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1300 | ASSERT(current_map->IsJSGlobalProxyMap() || |
| 1301 | !current_map->is_access_check_needed()); |
| 1302 | if (current_map->IsJSGlobalProxyMap()) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1303 | __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1306 | // Return the register containing the holder. |
| 1307 | return reg; |
| 1308 | } |
| 1309 | |
| 1310 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1311 | void LoadStubCompiler::HandlerFrontendFooter(Handle<Name> name, Label* miss) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1312 | if (!miss->is_unused()) { |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1313 | Label success; |
| 1314 | __ jmp(&success); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1315 | __ bind(miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1316 | TailCallBuiltin(masm(), MissBuiltin(kind())); |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1317 | __ bind(&success); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1318 | } |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1319 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1320 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1321 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1322 | void StoreStubCompiler::HandlerFrontendFooter(Handle<Name> name, Label* miss) { |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1323 | if (!miss->is_unused()) { |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1324 | Label success; |
| 1325 | __ jmp(&success); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1326 | GenerateRestoreName(masm(), miss, name); |
| 1327 | TailCallBuiltin(masm(), MissBuiltin(kind())); |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1328 | __ bind(&success); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 1333 | Register LoadStubCompiler::CallbackHandlerFrontend( |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1334 | Handle<Type> type, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1335 | Register object_reg, |
| 1336 | Handle<JSObject> holder, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1337 | Handle<Name> name, |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 1338 | Handle<Object> callback) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1339 | Label miss; |
| 1340 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 1341 | Register reg = HandlerFrontendHeader(type, object_reg, holder, name, &miss); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1342 | |
| 1343 | if (!holder->HasFastProperties() && !holder->IsJSGlobalObject()) { |
| 1344 | ASSERT(!reg.is(scratch2())); |
| 1345 | ASSERT(!reg.is(scratch3())); |
| 1346 | Register dictionary = scratch1(); |
| 1347 | bool must_preserve_dictionary_reg = reg.is(dictionary); |
| 1348 | |
| 1349 | // Load the properties dictionary. |
| 1350 | if (must_preserve_dictionary_reg) { |
| 1351 | __ push(dictionary); |
| 1352 | } |
| 1353 | __ mov(dictionary, FieldOperand(reg, JSObject::kPropertiesOffset)); |
| 1354 | |
| 1355 | // Probe the dictionary. |
| 1356 | Label probe_done, pop_and_miss; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1357 | NameDictionaryLookupStub::GeneratePositiveLookup(masm(), |
| 1358 | &pop_and_miss, |
| 1359 | &probe_done, |
| 1360 | dictionary, |
| 1361 | this->name(), |
| 1362 | scratch2(), |
| 1363 | scratch3()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1364 | __ bind(&pop_and_miss); |
| 1365 | if (must_preserve_dictionary_reg) { |
| 1366 | __ pop(dictionary); |
| 1367 | } |
| 1368 | __ jmp(&miss); |
| 1369 | __ bind(&probe_done); |
| 1370 | |
| 1371 | // If probing finds an entry in the dictionary, scratch2 contains the |
| 1372 | // index into the dictionary. Check that the value is the callback. |
| 1373 | Register index = scratch2(); |
| 1374 | const int kElementsStartOffset = |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1375 | NameDictionary::kHeaderSize + |
| 1376 | NameDictionary::kElementsStartIndex * kPointerSize; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1377 | const int kValueOffset = kElementsStartOffset + kPointerSize; |
| 1378 | __ mov(scratch3(), |
| 1379 | Operand(dictionary, index, times_4, kValueOffset - kHeapObjectTag)); |
| 1380 | if (must_preserve_dictionary_reg) { |
| 1381 | __ pop(dictionary); |
| 1382 | } |
| 1383 | __ cmp(scratch3(), callback); |
| 1384 | __ j(not_equal, &miss); |
| 1385 | } |
| 1386 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1387 | HandlerFrontendFooter(name, &miss); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1388 | return reg; |
| 1389 | } |
| 1390 | |
| 1391 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 1392 | void LoadStubCompiler::GenerateLoadField(Register reg, |
| 1393 | Handle<JSObject> holder, |
| 1394 | PropertyIndex field, |
| 1395 | Representation representation) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1396 | if (!reg.is(receiver())) __ mov(receiver(), reg); |
| 1397 | if (kind() == Code::LOAD_IC) { |
| 1398 | LoadFieldStub stub(field.is_inobject(holder), |
| 1399 | field.translate(holder), |
| 1400 | representation); |
| 1401 | GenerateTailCall(masm(), stub.GetCode(isolate())); |
| 1402 | } else { |
| 1403 | KeyedLoadFieldStub stub(field.is_inobject(holder), |
| 1404 | field.translate(holder), |
| 1405 | representation); |
| 1406 | GenerateTailCall(masm(), stub.GetCode(isolate())); |
| 1407 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 1411 | void LoadStubCompiler::GenerateLoadCallback( |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 1412 | const CallOptimization& call_optimization) { |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1413 | GenerateFastApiCall( |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1414 | masm(), call_optimization, receiver(), scratch1(), |
| 1415 | scratch2(), name(), 0, NULL); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 1419 | void LoadStubCompiler::GenerateLoadCallback( |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1420 | Register reg, |
| 1421 | Handle<ExecutableAccessorInfo> callback) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1422 | // Insert additional parameters into the stack frame above return address. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1423 | ASSERT(!scratch3().is(reg)); |
| 1424 | __ pop(scratch3()); // Get return address to place it below. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1425 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1426 | STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0); |
| 1427 | STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1); |
| 1428 | STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2); |
| 1429 | STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3); |
| 1430 | STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4); |
| 1431 | STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1432 | __ push(receiver()); // receiver |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1433 | // Push data from ExecutableAccessorInfo. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1434 | if (isolate()->heap()->InNewSpace(callback->data())) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1435 | ASSERT(!scratch2().is(reg)); |
| 1436 | __ mov(scratch2(), Immediate(callback)); |
| 1437 | __ push(FieldOperand(scratch2(), ExecutableAccessorInfo::kDataOffset)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1438 | } else { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1439 | __ push(Immediate(Handle<Object>(callback->data(), isolate()))); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1440 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1441 | __ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1442 | // ReturnValue default value |
| 1443 | __ push(Immediate(isolate()->factory()->undefined_value())); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 1444 | __ push(Immediate(reinterpret_cast<int>(isolate()))); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 1445 | __ push(reg); // holder |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1446 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1447 | // Save a pointer to where we pushed the arguments. This will be |
| 1448 | // passed as the const PropertyAccessorInfo& to the C++ callback. |
| 1449 | __ push(esp); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1450 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1451 | __ push(name()); // name |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1452 | __ mov(ebx, esp); // esp points to reference to name (handler). |
| 1453 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1454 | __ push(scratch3()); // Restore return address. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1455 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1456 | // array for v8::Arguments::values_, handler for name and pointer |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1457 | // to the values (it considered as smi in GC). |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1458 | const int kStackSpace = PropertyCallbackArguments::kArgsLength + 2; |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1459 | // Allocate space for opional callback address parameter in case |
| 1460 | // CPU profiler is active. |
| 1461 | const int kApiArgc = 2 + 1; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1462 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1463 | Address getter_address = v8::ToCData<Address>(callback->getter()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1464 | __ PrepareCallApiFunction(kApiArgc); |
| 1465 | __ mov(ApiParameterOperand(0), ebx); // name. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1466 | __ add(ebx, Immediate(kPointerSize)); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1467 | __ mov(ApiParameterOperand(1), ebx); // arguments pointer. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1468 | |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1469 | // Emitting a stub call may try to allocate (if the code is not |
| 1470 | // already generated). Do not allow the assembler to perform a |
| 1471 | // garbage collection but instead return the allocation failure |
| 1472 | // object. |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1473 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1474 | Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1475 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1476 | __ CallApiFunctionAndReturn(getter_address, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1477 | thunk_address, |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1478 | ApiParameterOperand(2), |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1479 | kStackSpace, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1480 | Operand(ebp, 7 * kPointerSize), |
| 1481 | NULL); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 1485 | void LoadStubCompiler::GenerateLoadConstant(Handle<Object> value) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1486 | // Return the constant value. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1487 | __ LoadObject(eax, value); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1488 | __ ret(0); |
| 1489 | } |
| 1490 | |
| 1491 | |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 1492 | void LoadStubCompiler::GenerateLoadInterceptor( |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1493 | Register holder_reg, |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1494 | Handle<Object> object, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1495 | Handle<JSObject> interceptor_holder, |
| 1496 | LookupResult* lookup, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1497 | Handle<Name> name) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1498 | ASSERT(interceptor_holder->HasNamedInterceptor()); |
| 1499 | ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 1500 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1501 | // So far the most popular follow ups for interceptor loads are FIELD |
| 1502 | // and CALLBACKS, so inline only them, other cases may be added |
| 1503 | // later. |
| 1504 | bool compile_followup_inline = false; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1505 | if (lookup->IsFound() && lookup->IsCacheable()) { |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 1506 | if (lookup->IsField()) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1507 | compile_followup_inline = true; |
| 1508 | } else if (lookup->type() == CALLBACKS && |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1509 | lookup->GetCallbackObject()->IsExecutableAccessorInfo()) { |
| 1510 | ExecutableAccessorInfo* callback = |
| 1511 | ExecutableAccessorInfo::cast(lookup->GetCallbackObject()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1512 | compile_followup_inline = callback->getter() != NULL && |
| 1513 | callback->IsCompatibleReceiver(*object); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | if (compile_followup_inline) { |
| 1518 | // Compile the interceptor call, followed by inline code to load the |
| 1519 | // property from further up the prototype chain if the call fails. |
| 1520 | // Check that the maps haven't changed. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1521 | ASSERT(holder_reg.is(receiver()) || holder_reg.is(scratch1())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1522 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1523 | // Preserve the receiver register explicitly whenever it is different from |
| 1524 | // the holder and it is needed should the interceptor return without any |
| 1525 | // result. The CALLBACKS case needs the receiver to be passed into C++ code, |
| 1526 | // the FIELD case might cause a miss during the prototype check. |
| 1527 | bool must_perfrom_prototype_check = *interceptor_holder != lookup->holder(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1528 | bool must_preserve_receiver_reg = !receiver().is(holder_reg) && |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1529 | (lookup->type() == CALLBACKS || must_perfrom_prototype_check); |
| 1530 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1531 | // Save necessary data before invoking an interceptor. |
| 1532 | // Requires a frame to make GC aware of pushed pointers. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1533 | { |
| 1534 | FrameScope frame_scope(masm(), StackFrame::INTERNAL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1535 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1536 | if (must_preserve_receiver_reg) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1537 | __ push(receiver()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1538 | } |
| 1539 | __ push(holder_reg); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1540 | __ push(this->name()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1541 | |
| 1542 | // Invoke an interceptor. Note: map checks from receiver to |
| 1543 | // interceptor's holder has been compiled before (see a caller |
| 1544 | // of this method.) |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1545 | CompileCallLoadPropertyWithInterceptor( |
| 1546 | masm(), receiver(), holder_reg, this->name(), interceptor_holder, |
| 1547 | IC::kLoadPropertyWithInterceptorOnly); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1548 | |
| 1549 | // Check if interceptor provided a value for property. If it's |
| 1550 | // the case, return immediately. |
| 1551 | Label interceptor_failed; |
| 1552 | __ cmp(eax, factory()->no_interceptor_result_sentinel()); |
| 1553 | __ j(equal, &interceptor_failed); |
| 1554 | frame_scope.GenerateLeaveFrame(); |
| 1555 | __ ret(0); |
| 1556 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1557 | // Clobber registers when generating debug-code to provoke errors. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1558 | __ bind(&interceptor_failed); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1559 | if (FLAG_debug_code) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1560 | __ mov(receiver(), Immediate(BitCast<int32_t>(kZapValue))); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1561 | __ mov(holder_reg, Immediate(BitCast<int32_t>(kZapValue))); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1562 | __ mov(this->name(), Immediate(BitCast<int32_t>(kZapValue))); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1565 | __ pop(this->name()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1566 | __ pop(holder_reg); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1567 | if (must_preserve_receiver_reg) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1568 | __ pop(receiver()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | // Leave the internal frame. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1572 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1573 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1574 | GenerateLoadPostInterceptor(holder_reg, interceptor_holder, name, lookup); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1575 | } else { // !compile_followup_inline |
| 1576 | // Call the runtime system to load the interceptor. |
| 1577 | // Check that the maps haven't changed. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1578 | __ pop(scratch2()); // save old return address |
| 1579 | PushInterceptorArguments(masm(), receiver(), holder_reg, |
| 1580 | this->name(), interceptor_holder); |
| 1581 | __ push(scratch2()); // restore old return address |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1582 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1583 | ExternalReference ref = |
| 1584 | ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1585 | isolate()); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 1586 | __ TailCallExternalReference(ref, StubCache::kInterceptorArgsLength, 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1587 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1591 | void CallStubCompiler::GenerateNameCheck(Handle<Name> name, Label* miss) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1592 | if (kind_ == Code::KEYED_CALL_IC) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1593 | __ cmp(ecx, Immediate(name)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1594 | __ j(not_equal, miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 1599 | void CallStubCompiler::GenerateFunctionCheck(Register function, |
| 1600 | Register scratch, |
| 1601 | Label* miss) { |
| 1602 | __ JumpIfSmi(function, miss); |
| 1603 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
| 1604 | __ j(not_equal, miss); |
| 1605 | } |
| 1606 | |
| 1607 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1608 | void CallStubCompiler::GenerateLoadFunctionFromCell( |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1609 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1610 | Handle<JSFunction> function, |
| 1611 | Label* miss) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1612 | // Get the value from the cell. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1613 | if (Serializer::enabled()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1614 | __ mov(edi, Immediate(cell)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1615 | __ mov(edi, FieldOperand(edi, Cell::kValueOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1616 | } else { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1617 | __ mov(edi, Operand::ForCell(cell)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1618 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1619 | |
| 1620 | // Check that the cell contains the same function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1621 | if (isolate()->heap()->InNewSpace(*function)) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1622 | // We can't embed a pointer to a function in new space so we have |
| 1623 | // to verify that the shared function info is unchanged. This has |
| 1624 | // the nice side effect that multiple closures based on the same |
| 1625 | // function can all use this call IC. Before we load through the |
| 1626 | // function, we have to verify that it still is a function. |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 1627 | GenerateFunctionCheck(edi, ebx, miss); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1628 | |
| 1629 | // Check the shared function info. Make sure it hasn't changed. |
| 1630 | __ cmp(FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset), |
| 1631 | Immediate(Handle<SharedFunctionInfo>(function->shared()))); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1632 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1633 | __ cmp(edi, Immediate(function)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1634 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1635 | __ j(not_equal, miss); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1639 | void CallStubCompiler::GenerateMissBranch() { |
| 1640 | Handle<Code> code = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1641 | isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1642 | kind_, |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 1643 | extra_state()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1644 | __ jmp(code, RelocInfo::CODE_TARGET); |
| 1645 | } |
| 1646 | |
| 1647 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1648 | Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object, |
| 1649 | Handle<JSObject> holder, |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1650 | PropertyIndex index, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1651 | Handle<Name> name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1652 | Label miss; |
| 1653 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1654 | Register reg = HandlerFrontendHeader( |
| 1655 | object, holder, name, RECEIVER_MAP_CHECK, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1656 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1657 | GenerateFastPropertyLoad( |
| 1658 | masm(), edi, reg, index.is_inobject(holder), |
| 1659 | index.translate(holder), Representation::Tagged()); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 1660 | GenerateJumpFunction(object, edi, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1661 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1662 | HandlerFrontendFooter(&miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1663 | |
| 1664 | // Return the generated code. |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 1665 | return GetCode(Code::FAST, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1669 | Handle<Code> CallStubCompiler::CompileArrayCodeCall( |
| 1670 | Handle<Object> object, |
| 1671 | Handle<JSObject> holder, |
| 1672 | Handle<Cell> cell, |
| 1673 | Handle<JSFunction> function, |
| 1674 | Handle<String> name, |
| 1675 | Code::StubType type) { |
| 1676 | Label miss; |
| 1677 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1678 | HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); |
| 1679 | if (!cell.is_null()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1680 | ASSERT(cell->value() == *function); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1681 | GenerateLoadFunctionFromCell(cell, function, &miss); |
| 1682 | } |
| 1683 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1684 | Handle<AllocationSite> site = isolate()->factory()->NewAllocationSite(); |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1685 | site->SetElementsKind(GetInitialFastElementsKind()); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1686 | Handle<Cell> site_feedback_cell = isolate()->factory()->NewCell(site); |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1687 | const int argc = arguments().immediate(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1688 | __ mov(eax, Immediate(argc)); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1689 | __ mov(ebx, site_feedback_cell); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1690 | __ mov(edi, function); |
| 1691 | |
| 1692 | ArrayConstructorStub stub(isolate()); |
| 1693 | __ TailCallStub(&stub); |
| 1694 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1695 | HandlerFrontendFooter(&miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1696 | |
| 1697 | // Return the generated code. |
| 1698 | return GetCode(type, name); |
| 1699 | } |
| 1700 | |
| 1701 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1702 | Handle<Code> CallStubCompiler::CompileArrayPushCall( |
| 1703 | Handle<Object> object, |
| 1704 | Handle<JSObject> holder, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1705 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1706 | Handle<JSFunction> function, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1707 | Handle<String> name, |
| 1708 | Code::StubType type) { |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 1709 | // If object is not an array or is observed or sealed, bail out to regular |
| 1710 | // call. |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1711 | if (!object->IsJSArray() || |
| 1712 | !cell.is_null() || |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 1713 | Handle<JSArray>::cast(object)->map()->is_observed() || |
| 1714 | !Handle<JSArray>::cast(object)->map()->is_extensible()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1715 | return Handle<Code>::null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1716 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1717 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1718 | Label miss; |
| 1719 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1720 | HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1721 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1722 | const int argc = arguments().immediate(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1723 | if (argc == 0) { |
| 1724 | // Noop, return the length. |
| 1725 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1726 | __ ret((argc + 1) * kPointerSize); |
| 1727 | } else { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1728 | Label call_builtin; |
| 1729 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1730 | if (argc == 1) { // Otherwise fall through to call builtin. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1731 | Label attempt_to_grow_elements, with_write_barrier, check_double; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1732 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1733 | // Get the elements array of the object. |
| 1734 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1735 | |
| 1736 | // Check that the elements are in fast mode and writable. |
| 1737 | __ cmp(FieldOperand(edi, HeapObject::kMapOffset), |
| 1738 | Immediate(factory()->fixed_array_map())); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1739 | __ j(not_equal, &check_double); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1740 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1741 | // Get the array's length into eax and calculate new length. |
| 1742 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1743 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1744 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1745 | __ add(eax, Immediate(Smi::FromInt(argc))); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1746 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1747 | // Get the elements' length into ecx. |
| 1748 | __ mov(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1749 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1750 | // Check if we could survive without allocation. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1751 | __ cmp(eax, ecx); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1752 | __ j(greater, &attempt_to_grow_elements); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1753 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1754 | // Check if value is a smi. |
| 1755 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 1756 | __ JumpIfNotSmi(ecx, &with_write_barrier); |
| 1757 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1758 | // Save new length. |
| 1759 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1760 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1761 | // Store the value. |
| 1762 | __ mov(FieldOperand(edi, |
| 1763 | eax, |
| 1764 | times_half_pointer_size, |
| 1765 | FixedArray::kHeaderSize - argc * kPointerSize), |
| 1766 | ecx); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1767 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1768 | __ ret((argc + 1) * kPointerSize); |
| 1769 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1770 | __ bind(&check_double); |
| 1771 | |
| 1772 | |
| 1773 | // Check that the elements are in double mode. |
| 1774 | __ cmp(FieldOperand(edi, HeapObject::kMapOffset), |
| 1775 | Immediate(factory()->fixed_double_array_map())); |
| 1776 | __ j(not_equal, &call_builtin); |
| 1777 | |
| 1778 | // Get the array's length into eax and calculate new length. |
| 1779 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1780 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1781 | STATIC_ASSERT(kSmiTag == 0); |
| 1782 | __ add(eax, Immediate(Smi::FromInt(argc))); |
| 1783 | |
| 1784 | // Get the elements' length into ecx. |
| 1785 | __ mov(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); |
| 1786 | |
| 1787 | // Check if we could survive without allocation. |
| 1788 | __ cmp(eax, ecx); |
| 1789 | __ j(greater, &call_builtin); |
| 1790 | |
| 1791 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 1792 | __ StoreNumberToDoubleElements( |
| 1793 | ecx, edi, eax, ecx, xmm0, &call_builtin, true, argc * kDoubleSize); |
| 1794 | |
| 1795 | // Save new length. |
| 1796 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1797 | __ ret((argc + 1) * kPointerSize); |
| 1798 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1799 | __ bind(&with_write_barrier); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1800 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1801 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 1802 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1803 | if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) { |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1804 | Label fast_object, not_fast_object; |
| 1805 | __ CheckFastObjectElements(ebx, ¬_fast_object, Label::kNear); |
| 1806 | __ jmp(&fast_object); |
| 1807 | // In case of fast smi-only, convert to fast object, otherwise bail out. |
| 1808 | __ bind(¬_fast_object); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1809 | __ CheckFastSmiElements(ebx, &call_builtin); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1810 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 1811 | Immediate(factory()->heap_number_map())); |
| 1812 | __ j(equal, &call_builtin); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1813 | // edi: elements array |
| 1814 | // edx: receiver |
| 1815 | // ebx: map |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1816 | Label try_holey_map; |
| 1817 | __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1818 | FAST_ELEMENTS, |
| 1819 | ebx, |
| 1820 | edi, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1821 | &try_holey_map); |
| 1822 | |
| 1823 | ElementsTransitionGenerator:: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1824 | GenerateMapChangeElementsTransition(masm(), |
| 1825 | DONT_TRACK_ALLOCATION_SITE, |
| 1826 | NULL); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1827 | // Restore edi. |
| 1828 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1829 | __ jmp(&fast_object); |
| 1830 | |
| 1831 | __ bind(&try_holey_map); |
| 1832 | __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS, |
| 1833 | FAST_HOLEY_ELEMENTS, |
| 1834 | ebx, |
| 1835 | edi, |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1836 | &call_builtin); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1837 | ElementsTransitionGenerator:: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1838 | GenerateMapChangeElementsTransition(masm(), |
| 1839 | DONT_TRACK_ALLOCATION_SITE, |
| 1840 | NULL); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1841 | // Restore edi. |
| 1842 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1843 | __ bind(&fast_object); |
| 1844 | } else { |
| 1845 | __ CheckFastObjectElements(ebx, &call_builtin); |
| 1846 | } |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1847 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1848 | // Save new length. |
| 1849 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1850 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1851 | // Store the value. |
| 1852 | __ lea(edx, FieldOperand(edi, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1853 | eax, times_half_pointer_size, |
| 1854 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 1855 | __ mov(Operand(edx, 0), ecx); |
| 1856 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1857 | __ RecordWrite(edi, edx, ecx, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1858 | OMIT_SMI_CHECK); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1859 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1860 | __ ret((argc + 1) * kPointerSize); |
| 1861 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1862 | __ bind(&attempt_to_grow_elements); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1863 | if (!FLAG_inline_new) { |
| 1864 | __ jmp(&call_builtin); |
| 1865 | } |
| 1866 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1867 | __ mov(ebx, Operand(esp, argc * kPointerSize)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1868 | // Growing elements that are SMI-only requires special handling in case |
| 1869 | // the new element is non-Smi. For now, delegate to the builtin. |
| 1870 | Label no_fast_elements_check; |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1871 | __ JumpIfSmi(ebx, &no_fast_elements_check); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1872 | __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 1873 | __ CheckFastObjectElements(ecx, &call_builtin, Label::kFar); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1874 | __ bind(&no_fast_elements_check); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1875 | |
| 1876 | // We could be lucky and the elements array could be at the top of |
| 1877 | // new-space. In this case we can just grow it in place by moving the |
| 1878 | // allocation pointer up. |
| 1879 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1880 | ExternalReference new_space_allocation_top = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1881 | ExternalReference::new_space_allocation_top_address(isolate()); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1882 | ExternalReference new_space_allocation_limit = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1883 | ExternalReference::new_space_allocation_limit_address(isolate()); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1884 | |
| 1885 | const int kAllocationDelta = 4; |
| 1886 | // Load top. |
| 1887 | __ mov(ecx, Operand::StaticVariable(new_space_allocation_top)); |
| 1888 | |
| 1889 | // Check if it's the end of elements. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1890 | __ lea(edx, FieldOperand(edi, |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1891 | eax, times_half_pointer_size, |
| 1892 | FixedArray::kHeaderSize - argc * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1893 | __ cmp(edx, ecx); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1894 | __ j(not_equal, &call_builtin); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1895 | __ add(ecx, Immediate(kAllocationDelta * kPointerSize)); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1896 | __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1897 | __ j(above, &call_builtin); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1898 | |
| 1899 | // We fit and could grow elements. |
| 1900 | __ mov(Operand::StaticVariable(new_space_allocation_top), ecx); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1901 | |
| 1902 | // Push the argument... |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1903 | __ mov(Operand(edx, 0), ebx); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1904 | // ... and fill the rest with holes. |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1905 | for (int i = 1; i < kAllocationDelta; i++) { |
| 1906 | __ mov(Operand(edx, i * kPointerSize), |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1907 | Immediate(factory()->the_hole_value())); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1910 | // We know the elements array is in new space so we don't need the |
| 1911 | // remembered set, but we just pushed a value onto it so we may have to |
| 1912 | // tell the incremental marker to rescan the object that we just grew. We |
| 1913 | // don't need to worry about the holes because they are in old space and |
| 1914 | // already marked black. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1915 | __ RecordWrite(edi, edx, ebx, kDontSaveFPRegs, OMIT_REMEMBERED_SET); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1916 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1917 | // Restore receiver to edx as finish sequence assumes it's here. |
| 1918 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1919 | |
| 1920 | // Increment element's and array's sizes. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1921 | __ add(FieldOperand(edi, FixedArray::kLengthOffset), |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1922 | Immediate(Smi::FromInt(kAllocationDelta))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1923 | |
| 1924 | // NOTE: This only happen in new-space, where we don't |
| 1925 | // care about the black-byte-count on pages. Otherwise we should |
| 1926 | // update that too if the object is black. |
| 1927 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1928 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1929 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1930 | __ ret((argc + 1) * kPointerSize); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1933 | __ bind(&call_builtin); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1934 | __ TailCallExternalReference( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1935 | ExternalReference(Builtins::c_ArrayPush, isolate()), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1936 | argc + 1, |
| 1937 | 1); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1940 | HandlerFrontendFooter(&miss); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1941 | |
| 1942 | // Return the generated code. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1943 | return GetCode(type, name); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1947 | Handle<Code> CallStubCompiler::CompileArrayPopCall( |
| 1948 | Handle<Object> object, |
| 1949 | Handle<JSObject> holder, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1950 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1951 | Handle<JSFunction> function, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1952 | Handle<String> name, |
| 1953 | Code::StubType type) { |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 1954 | // If object is not an array or is observed or sealed, bail out to regular |
| 1955 | // call. |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 1956 | if (!object->IsJSArray() || |
| 1957 | !cell.is_null() || |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 1958 | Handle<JSArray>::cast(object)->map()->is_observed() || |
| 1959 | !Handle<JSArray>::cast(object)->map()->is_extensible()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1960 | return Handle<Code>::null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1961 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1962 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1963 | Label miss, return_undefined, call_builtin; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1964 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1965 | HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1966 | |
| 1967 | // Get the elements array of the object. |
| 1968 | __ mov(ebx, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1969 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1970 | // Check that the elements are in fast mode and writable. |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1971 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1972 | Immediate(factory()->fixed_array_map())); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1973 | __ j(not_equal, &call_builtin); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1974 | |
| 1975 | // Get the array's length into ecx and calculate new length. |
| 1976 | __ mov(ecx, FieldOperand(edx, JSArray::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1977 | __ sub(ecx, Immediate(Smi::FromInt(1))); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1978 | __ j(negative, &return_undefined); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1979 | |
| 1980 | // Get the last element. |
| 1981 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1982 | STATIC_ASSERT(kSmiTag == 0); |
| 1983 | __ mov(eax, FieldOperand(ebx, |
| 1984 | ecx, times_half_pointer_size, |
| 1985 | FixedArray::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1986 | __ cmp(eax, Immediate(factory()->the_hole_value())); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1987 | __ j(equal, &call_builtin); |
| 1988 | |
| 1989 | // Set the array's length. |
| 1990 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), ecx); |
| 1991 | |
| 1992 | // Fill with the hole. |
| 1993 | __ mov(FieldOperand(ebx, |
| 1994 | ecx, times_half_pointer_size, |
| 1995 | FixedArray::kHeaderSize), |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1996 | Immediate(factory()->the_hole_value())); |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 1997 | const int argc = arguments().immediate(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1998 | __ ret((argc + 1) * kPointerSize); |
| 1999 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2000 | __ bind(&return_undefined); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2001 | __ mov(eax, Immediate(factory()->undefined_value())); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2002 | __ ret((argc + 1) * kPointerSize); |
| 2003 | |
| 2004 | __ bind(&call_builtin); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2005 | __ TailCallExternalReference( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2006 | ExternalReference(Builtins::c_ArrayPop, isolate()), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2007 | argc + 1, |
| 2008 | 1); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2009 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2010 | HandlerFrontendFooter(&miss); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2011 | |
| 2012 | // Return the generated code. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2013 | return GetCode(type, name); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2017 | Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall( |
| 2018 | Handle<Object> object, |
| 2019 | Handle<JSObject> holder, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2020 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2021 | Handle<JSFunction> function, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2022 | Handle<String> name, |
| 2023 | Code::StubType type) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2024 | // If object is not a string, bail out to regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2025 | if (!object->IsString() || !cell.is_null()) { |
| 2026 | return Handle<Code>::null(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2027 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2028 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2029 | const int argc = arguments().immediate(); |
| 2030 | |
| 2031 | Label miss; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2032 | Label name_miss; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2033 | Label index_out_of_range; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2034 | Label* index_out_of_range_label = &index_out_of_range; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2035 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2036 | if (kind_ == Code::CALL_IC && |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2037 | (CallICBase::StringStubState::decode(extra_state()) == |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2038 | DEFAULT_STRING_STUB)) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2039 | index_out_of_range_label = &miss; |
| 2040 | } |
| 2041 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2042 | HandlerFrontendHeader(object, holder, name, STRING_CHECK, &name_miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2043 | |
| 2044 | Register receiver = ebx; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2045 | Register index = edi; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2046 | Register result = eax; |
| 2047 | __ mov(receiver, Operand(esp, (argc + 1) * kPointerSize)); |
| 2048 | if (argc > 0) { |
| 2049 | __ mov(index, Operand(esp, (argc - 0) * kPointerSize)); |
| 2050 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2051 | __ Set(index, Immediate(factory()->undefined_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2054 | StringCharCodeAtGenerator generator(receiver, |
| 2055 | index, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2056 | result, |
| 2057 | &miss, // When not a string. |
| 2058 | &miss, // When not a number. |
| 2059 | index_out_of_range_label, |
| 2060 | STRING_INDEX_IS_NUMBER); |
| 2061 | generator.GenerateFast(masm()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2062 | __ ret((argc + 1) * kPointerSize); |
| 2063 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2064 | StubRuntimeCallHelper call_helper; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2065 | generator.GenerateSlow(masm(), call_helper); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2066 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2067 | if (index_out_of_range.is_linked()) { |
| 2068 | __ bind(&index_out_of_range); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2069 | __ Set(eax, Immediate(factory()->nan_value())); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2070 | __ ret((argc + 1) * kPointerSize); |
| 2071 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2072 | |
| 2073 | __ bind(&miss); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2074 | // Restore function name in ecx. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2075 | __ Set(ecx, Immediate(name)); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2076 | HandlerFrontendFooter(&name_miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2077 | |
| 2078 | // Return the generated code. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2079 | return GetCode(type, name); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2083 | Handle<Code> CallStubCompiler::CompileStringCharAtCall( |
| 2084 | Handle<Object> object, |
| 2085 | Handle<JSObject> holder, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2086 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2087 | Handle<JSFunction> function, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2088 | Handle<String> name, |
| 2089 | Code::StubType type) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2090 | // If object is not a string, bail out to regular call. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2091 | if (!object->IsString() || !cell.is_null()) { |
| 2092 | return Handle<Code>::null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2093 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2094 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2095 | const int argc = arguments().immediate(); |
| 2096 | |
| 2097 | Label miss; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2098 | Label name_miss; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2099 | Label index_out_of_range; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2100 | Label* index_out_of_range_label = &index_out_of_range; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2101 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2102 | if (kind_ == Code::CALL_IC && |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2103 | (CallICBase::StringStubState::decode(extra_state()) == |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2104 | DEFAULT_STRING_STUB)) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2105 | index_out_of_range_label = &miss; |
| 2106 | } |
| 2107 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2108 | HandlerFrontendHeader(object, holder, name, STRING_CHECK, &name_miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2109 | |
| 2110 | Register receiver = eax; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2111 | Register index = edi; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2112 | Register scratch = edx; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2113 | Register result = eax; |
| 2114 | __ mov(receiver, Operand(esp, (argc + 1) * kPointerSize)); |
| 2115 | if (argc > 0) { |
| 2116 | __ mov(index, Operand(esp, (argc - 0) * kPointerSize)); |
| 2117 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2118 | __ Set(index, Immediate(factory()->undefined_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2121 | StringCharAtGenerator generator(receiver, |
| 2122 | index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2123 | scratch, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2124 | result, |
| 2125 | &miss, // When not a string. |
| 2126 | &miss, // When not a number. |
| 2127 | index_out_of_range_label, |
| 2128 | STRING_INDEX_IS_NUMBER); |
| 2129 | generator.GenerateFast(masm()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2130 | __ ret((argc + 1) * kPointerSize); |
| 2131 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2132 | StubRuntimeCallHelper call_helper; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2133 | generator.GenerateSlow(masm(), call_helper); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2134 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2135 | if (index_out_of_range.is_linked()) { |
| 2136 | __ bind(&index_out_of_range); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2137 | __ Set(eax, Immediate(factory()->empty_string())); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2138 | __ ret((argc + 1) * kPointerSize); |
| 2139 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2140 | |
| 2141 | __ bind(&miss); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2142 | // Restore function name in ecx. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2143 | __ Set(ecx, Immediate(name)); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2144 | HandlerFrontendFooter(&name_miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2145 | |
| 2146 | // Return the generated code. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2147 | return GetCode(type, name); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2151 | Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall( |
| 2152 | Handle<Object> object, |
| 2153 | Handle<JSObject> holder, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2154 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2155 | Handle<JSFunction> function, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2156 | Handle<String> name, |
| 2157 | Code::StubType type) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2158 | const int argc = arguments().immediate(); |
| 2159 | |
| 2160 | // If the object is not a JSObject or we got an unexpected number of |
| 2161 | // arguments, bail out to the regular call. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2162 | if (!object->IsJSObject() || argc != 1) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2163 | return Handle<Code>::null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2164 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2165 | |
| 2166 | Label miss; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2167 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2168 | HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); |
| 2169 | if (!cell.is_null()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2170 | ASSERT(cell->value() == *function); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2171 | GenerateLoadFunctionFromCell(cell, function, &miss); |
| 2172 | } |
| 2173 | |
| 2174 | // Load the char code argument. |
| 2175 | Register code = ebx; |
| 2176 | __ mov(code, Operand(esp, 1 * kPointerSize)); |
| 2177 | |
| 2178 | // Check the code is a smi. |
| 2179 | Label slow; |
| 2180 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2181 | __ JumpIfNotSmi(code, &slow); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2182 | |
| 2183 | // Convert the smi code to uint16. |
| 2184 | __ and_(code, Immediate(Smi::FromInt(0xffff))); |
| 2185 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2186 | StringCharFromCodeGenerator generator(code, eax); |
| 2187 | generator.GenerateFast(masm()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2188 | __ ret(2 * kPointerSize); |
| 2189 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2190 | StubRuntimeCallHelper call_helper; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2191 | generator.GenerateSlow(masm(), call_helper); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2192 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2193 | __ bind(&slow); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2194 | // We do not have to patch the receiver because the function makes no use of |
| 2195 | // it. |
| 2196 | GenerateJumpFunctionIgnoreReceiver(function); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2197 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2198 | HandlerFrontendFooter(&miss); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2199 | |
| 2200 | // Return the generated code. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2201 | return GetCode(type, name); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2205 | Handle<Code> CallStubCompiler::CompileMathFloorCall( |
| 2206 | Handle<Object> object, |
| 2207 | Handle<JSObject> holder, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2208 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2209 | Handle<JSFunction> function, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2210 | Handle<String> name, |
| 2211 | Code::StubType type) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2212 | if (!CpuFeatures::IsSupported(SSE2)) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2213 | return Handle<Code>::null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2214 | } |
| 2215 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2216 | CpuFeatureScope use_sse2(masm(), SSE2); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2217 | |
| 2218 | const int argc = arguments().immediate(); |
| 2219 | |
| 2220 | // If the object is not a JSObject or we got an unexpected number of |
| 2221 | // arguments, bail out to the regular call. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2222 | if (!object->IsJSObject() || argc != 1) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2223 | return Handle<Code>::null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2224 | } |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2225 | |
| 2226 | Label miss; |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2227 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2228 | HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); |
| 2229 | if (!cell.is_null()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2230 | ASSERT(cell->value() == *function); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2231 | GenerateLoadFunctionFromCell(cell, function, &miss); |
| 2232 | } |
| 2233 | |
| 2234 | // Load the (only) argument into eax. |
| 2235 | __ mov(eax, Operand(esp, 1 * kPointerSize)); |
| 2236 | |
| 2237 | // Check if the argument is a smi. |
| 2238 | Label smi; |
| 2239 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2240 | __ JumpIfSmi(eax, &smi); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2241 | |
| 2242 | // Check if the argument is a heap number and load its value into xmm0. |
| 2243 | Label slow; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2244 | __ CheckMap(eax, factory()->heap_number_map(), &slow, DONT_DO_SMI_CHECK); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 2245 | __ movsd(xmm0, FieldOperand(eax, HeapNumber::kValueOffset)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2246 | |
| 2247 | // Check if the argument is strictly positive. Note this also |
| 2248 | // discards NaN. |
| 2249 | __ xorpd(xmm1, xmm1); |
| 2250 | __ ucomisd(xmm0, xmm1); |
| 2251 | __ j(below_equal, &slow); |
| 2252 | |
| 2253 | // Do a truncating conversion. |
| 2254 | __ cvttsd2si(eax, Operand(xmm0)); |
| 2255 | |
| 2256 | // Check if the result fits into a smi. Note this also checks for |
| 2257 | // 0x80000000 which signals a failed conversion. |
| 2258 | Label wont_fit_into_smi; |
| 2259 | __ test(eax, Immediate(0xc0000000)); |
| 2260 | __ j(not_zero, &wont_fit_into_smi); |
| 2261 | |
| 2262 | // Smi tag and return. |
| 2263 | __ SmiTag(eax); |
| 2264 | __ bind(&smi); |
| 2265 | __ ret(2 * kPointerSize); |
| 2266 | |
| 2267 | // Check if the argument is < 2^kMantissaBits. |
| 2268 | Label already_round; |
| 2269 | __ bind(&wont_fit_into_smi); |
| 2270 | __ LoadPowerOf2(xmm1, ebx, HeapNumber::kMantissaBits); |
| 2271 | __ ucomisd(xmm0, xmm1); |
| 2272 | __ j(above_equal, &already_round); |
| 2273 | |
| 2274 | // Save a copy of the argument. |
| 2275 | __ movaps(xmm2, xmm0); |
| 2276 | |
| 2277 | // Compute (argument + 2^kMantissaBits) - 2^kMantissaBits. |
| 2278 | __ addsd(xmm0, xmm1); |
| 2279 | __ subsd(xmm0, xmm1); |
| 2280 | |
| 2281 | // Compare the argument and the tentative result to get the right mask: |
| 2282 | // if xmm2 < xmm0: |
| 2283 | // xmm2 = 1...1 |
| 2284 | // else: |
| 2285 | // xmm2 = 0...0 |
| 2286 | __ cmpltsd(xmm2, xmm0); |
| 2287 | |
| 2288 | // Subtract 1 if the argument was less than the tentative result. |
| 2289 | __ LoadPowerOf2(xmm1, ebx, 0); |
| 2290 | __ andpd(xmm1, xmm2); |
| 2291 | __ subsd(xmm0, xmm1); |
| 2292 | |
| 2293 | // Return a new heap number. |
| 2294 | __ AllocateHeapNumber(eax, ebx, edx, &slow); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 2295 | __ movsd(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2296 | __ ret(2 * kPointerSize); |
| 2297 | |
| 2298 | // Return the argument (when it's an already round heap number). |
| 2299 | __ bind(&already_round); |
| 2300 | __ mov(eax, Operand(esp, 1 * kPointerSize)); |
| 2301 | __ ret(2 * kPointerSize); |
| 2302 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2303 | __ bind(&slow); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2304 | // We do not have to patch the receiver because the function makes no use of |
| 2305 | // it. |
| 2306 | GenerateJumpFunctionIgnoreReceiver(function); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2307 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2308 | HandlerFrontendFooter(&miss); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2309 | |
| 2310 | // Return the generated code. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2311 | return GetCode(type, name); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2315 | Handle<Code> CallStubCompiler::CompileMathAbsCall( |
| 2316 | Handle<Object> object, |
| 2317 | Handle<JSObject> holder, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2318 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2319 | Handle<JSFunction> function, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2320 | Handle<String> name, |
| 2321 | Code::StubType type) { |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2322 | const int argc = arguments().immediate(); |
| 2323 | |
| 2324 | // If the object is not a JSObject or we got an unexpected number of |
| 2325 | // arguments, bail out to the regular call. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2326 | if (!object->IsJSObject() || argc != 1) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2327 | return Handle<Code>::null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2328 | } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2329 | |
| 2330 | Label miss; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2331 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2332 | HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); |
| 2333 | if (!cell.is_null()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2334 | ASSERT(cell->value() == *function); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2335 | GenerateLoadFunctionFromCell(cell, function, &miss); |
| 2336 | } |
| 2337 | |
| 2338 | // Load the (only) argument into eax. |
| 2339 | __ mov(eax, Operand(esp, 1 * kPointerSize)); |
| 2340 | |
| 2341 | // Check if the argument is a smi. |
| 2342 | Label not_smi; |
| 2343 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2344 | __ JumpIfNotSmi(eax, ¬_smi); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2345 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2346 | // Branchless abs implementation, refer to below: |
| 2347 | // http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2348 | // Set ebx to 1...1 (== -1) if the argument is negative, or to 0...0 |
| 2349 | // otherwise. |
| 2350 | __ mov(ebx, eax); |
| 2351 | __ sar(ebx, kBitsPerInt - 1); |
| 2352 | |
| 2353 | // Do bitwise not or do nothing depending on ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2354 | __ xor_(eax, ebx); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2355 | |
| 2356 | // Add 1 or do nothing depending on ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2357 | __ sub(eax, ebx); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2358 | |
| 2359 | // If the result is still negative, go to the slow case. |
| 2360 | // This only happens for the most negative smi. |
| 2361 | Label slow; |
| 2362 | __ j(negative, &slow); |
| 2363 | |
| 2364 | // Smi case done. |
| 2365 | __ ret(2 * kPointerSize); |
| 2366 | |
| 2367 | // Check if the argument is a heap number and load its exponent and |
| 2368 | // sign into ebx. |
| 2369 | __ bind(¬_smi); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2370 | __ CheckMap(eax, factory()->heap_number_map(), &slow, DONT_DO_SMI_CHECK); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2371 | __ mov(ebx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2372 | |
| 2373 | // Check the sign of the argument. If the argument is positive, |
| 2374 | // just return it. |
| 2375 | Label negative_sign; |
| 2376 | __ test(ebx, Immediate(HeapNumber::kSignMask)); |
| 2377 | __ j(not_zero, &negative_sign); |
| 2378 | __ ret(2 * kPointerSize); |
| 2379 | |
| 2380 | // If the argument is negative, clear the sign, and return a new |
| 2381 | // number. |
| 2382 | __ bind(&negative_sign); |
| 2383 | __ and_(ebx, ~HeapNumber::kSignMask); |
| 2384 | __ mov(ecx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
| 2385 | __ AllocateHeapNumber(eax, edi, edx, &slow); |
| 2386 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ebx); |
| 2387 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 2388 | __ ret(2 * kPointerSize); |
| 2389 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2390 | __ bind(&slow); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2391 | // We do not have to patch the receiver because the function makes no use of |
| 2392 | // it. |
| 2393 | GenerateJumpFunctionIgnoreReceiver(function); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2394 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2395 | HandlerFrontendFooter(&miss); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2396 | |
| 2397 | // Return the generated code. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2398 | return GetCode(type, name); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2402 | Handle<Code> CallStubCompiler::CompileFastApiCall( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2403 | const CallOptimization& optimization, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2404 | Handle<Object> object, |
| 2405 | Handle<JSObject> holder, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2406 | Handle<Cell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2407 | Handle<JSFunction> function, |
| 2408 | Handle<String> name) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2409 | ASSERT(optimization.is_simple_api_call()); |
| 2410 | // Bail out if object is a global object as we don't want to |
| 2411 | // repatch it to global receiver. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2412 | if (object->IsGlobalObject()) return Handle<Code>::null(); |
| 2413 | if (!cell.is_null()) return Handle<Code>::null(); |
| 2414 | if (!object->IsJSObject()) return Handle<Code>::null(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2415 | int depth = optimization.GetPrototypeDepthOfExpectedType( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2416 | Handle<JSObject>::cast(object), holder); |
| 2417 | if (depth == kInvalidProtoDepth) return Handle<Code>::null(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2418 | |
| 2419 | Label miss, miss_before_stack_reserved; |
| 2420 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2421 | GenerateNameCheck(name, &miss_before_stack_reserved); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2422 | |
| 2423 | // Get the receiver from the stack. |
| 2424 | const int argc = arguments().immediate(); |
| 2425 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 2426 | |
| 2427 | // Check that the receiver isn't a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2428 | __ JumpIfSmi(edx, &miss_before_stack_reserved); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2429 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2430 | Counters* counters = isolate()->counters(); |
| 2431 | __ IncrementCounter(counters->call_const(), 1); |
| 2432 | __ IncrementCounter(counters->call_const_fast_api(), 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2433 | |
| 2434 | // Allocate space for v8::Arguments implicit values. Must be initialized |
| 2435 | // before calling any runtime function. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2436 | __ sub(esp, Immediate(kFastApiCallArguments * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2437 | |
| 2438 | // Check that the maps haven't changed and find a Holder as a side effect. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2439 | CheckPrototypes(IC::CurrentTypeOf(object, isolate()), edx, holder, |
| 2440 | ebx, eax, edi, name, depth, &miss); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2441 | |
| 2442 | // Move the return address on top of the stack. |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2443 | __ mov(eax, Operand(esp, kFastApiCallArguments * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2444 | __ mov(Operand(esp, 0 * kPointerSize), eax); |
| 2445 | |
| 2446 | // esp[2 * kPointerSize] is uninitialized, esp[3 * kPointerSize] contains |
| 2447 | // duplicate of return address and will be overwritten. |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 2448 | GenerateFastApiCall(masm(), optimization, argc); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2449 | |
| 2450 | __ bind(&miss); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2451 | __ add(esp, Immediate(kFastApiCallArguments * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2452 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2453 | HandlerFrontendFooter(&miss_before_stack_reserved); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2454 | |
| 2455 | // Return the generated code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2456 | return GetCode(function); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 2460 | void StubCompiler::GenerateBooleanCheck(Register object, Label* miss) { |
| 2461 | Label success; |
| 2462 | // Check that the object is a boolean. |
| 2463 | __ cmp(object, factory()->true_value()); |
| 2464 | __ j(equal, &success); |
| 2465 | __ cmp(object, factory()->false_value()); |
| 2466 | __ j(not_equal, miss); |
| 2467 | __ bind(&success); |
| 2468 | } |
| 2469 | |
| 2470 | |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame^] | 2471 | void CallStubCompiler::PatchGlobalProxy(Handle<Object> object, |
| 2472 | Handle<JSFunction> function) { |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2473 | if (object->IsGlobalObject()) { |
| 2474 | const int argc = arguments().immediate(); |
| 2475 | const int receiver_offset = (argc + 1) * kPointerSize; |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame^] | 2476 | __ LoadHeapObject(edx, handle(function->context()->global_proxy())); |
| 2477 | __ mov(Operand(esp, receiver_offset), edx); |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | |
| 2482 | void CallStubCompiler::PatchGlobalProxy(Handle<Object> object, |
| 2483 | Register function) { |
| 2484 | if (object->IsGlobalObject()) { |
| 2485 | FetchGlobalProxy(masm(), edx, function); |
| 2486 | const int argc = arguments().immediate(); |
| 2487 | const int receiver_offset = (argc + 1) * kPointerSize; |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2488 | __ mov(Operand(esp, receiver_offset), edx); |
| 2489 | } |
| 2490 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2491 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2492 | |
| 2493 | Register CallStubCompiler::HandlerFrontendHeader(Handle<Object> object, |
| 2494 | Handle<JSObject> holder, |
| 2495 | Handle<Name> name, |
| 2496 | CheckType check, |
| 2497 | Label* miss) { |
| 2498 | GenerateNameCheck(name, miss); |
| 2499 | |
| 2500 | Register reg = edx; |
| 2501 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2502 | const int argc = arguments().immediate(); |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2503 | const int receiver_offset = (argc + 1) * kPointerSize; |
| 2504 | __ mov(reg, Operand(esp, receiver_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2505 | |
| 2506 | // Check that the receiver isn't a smi. |
| 2507 | if (check != NUMBER_CHECK) { |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2508 | __ JumpIfSmi(reg, miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2509 | } |
| 2510 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2511 | // Make sure that it's okay not to patch the on stack receiver |
| 2512 | // unless we're doing a receiver map check. |
| 2513 | ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2514 | switch (check) { |
| 2515 | case RECEIVER_MAP_CHECK: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2516 | __ IncrementCounter(isolate()->counters()->call_const(), 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2517 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2518 | // Check that the maps haven't changed. |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2519 | reg = CheckPrototypes(IC::CurrentTypeOf(object, isolate()), reg, holder, |
| 2520 | ebx, eax, edi, name, miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2521 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2522 | break; |
| 2523 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2524 | case STRING_CHECK: { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2525 | // Check that the object is a string. |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2526 | __ CmpObjectType(reg, FIRST_NONSTRING_TYPE, eax); |
| 2527 | __ j(above_equal, miss); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2528 | // Check that the maps starting from the prototype haven't changed. |
| 2529 | GenerateDirectLoadGlobalFunctionPrototype( |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2530 | masm(), Context::STRING_FUNCTION_INDEX, eax, miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2531 | break; |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2532 | } |
| 2533 | case SYMBOL_CHECK: { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2534 | // Check that the object is a symbol. |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2535 | __ CmpObjectType(reg, SYMBOL_TYPE, eax); |
| 2536 | __ j(not_equal, miss); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2537 | // Check that the maps starting from the prototype haven't changed. |
| 2538 | GenerateDirectLoadGlobalFunctionPrototype( |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2539 | masm(), Context::SYMBOL_FUNCTION_INDEX, eax, miss); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2540 | break; |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2541 | } |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2542 | case NUMBER_CHECK: { |
| 2543 | Label fast; |
| 2544 | // Check that the object is a smi or a heap number. |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2545 | __ JumpIfSmi(reg, &fast); |
| 2546 | __ CmpObjectType(reg, HEAP_NUMBER_TYPE, eax); |
| 2547 | __ j(not_equal, miss); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2548 | __ bind(&fast); |
| 2549 | // Check that the maps starting from the prototype haven't changed. |
| 2550 | GenerateDirectLoadGlobalFunctionPrototype( |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2551 | masm(), Context::NUMBER_FUNCTION_INDEX, eax, miss); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2552 | break; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2553 | } |
| 2554 | case BOOLEAN_CHECK: { |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2555 | GenerateBooleanCheck(reg, miss); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2556 | // Check that the maps starting from the prototype haven't changed. |
| 2557 | GenerateDirectLoadGlobalFunctionPrototype( |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2558 | masm(), Context::BOOLEAN_FUNCTION_INDEX, eax, miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2559 | break; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2560 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2563 | if (check != RECEIVER_MAP_CHECK) { |
| 2564 | Handle<Object> prototype(object->GetPrototype(isolate()), isolate()); |
| 2565 | reg = CheckPrototypes( |
| 2566 | IC::CurrentTypeOf(prototype, isolate()), |
| 2567 | eax, holder, ebx, edx, edi, name, miss); |
| 2568 | } |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2569 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2570 | return reg; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2574 | void CallStubCompiler::GenerateJumpFunction(Handle<Object> object, |
| 2575 | Register function, |
| 2576 | Label* miss) { |
| 2577 | // Check that the function really is a function. |
| 2578 | GenerateFunctionCheck(function, ebx, miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2579 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2580 | if (!function.is(edi)) __ mov(edi, function); |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame^] | 2581 | PatchGlobalProxy(object, function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2582 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2583 | // Invoke the function. |
| 2584 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION, |
| 2585 | NullCallWrapper(), call_kind()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2589 | Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object, |
| 2590 | Handle<JSObject> holder, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2591 | Handle<Name> name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2592 | Label miss; |
| 2593 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2594 | GenerateNameCheck(name, &miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2595 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2596 | // Get the number of arguments. |
| 2597 | const int argc = arguments().immediate(); |
| 2598 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2599 | LookupResult lookup(isolate()); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2600 | LookupPostInterceptor(holder, name, &lookup); |
| 2601 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2602 | // Get the receiver from the stack. |
| 2603 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2604 | |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 2605 | CallInterceptorCompiler compiler(this, arguments(), ecx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2606 | compiler.Compile(masm(), object, holder, name, &lookup, edx, ebx, edi, eax, |
| 2607 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2608 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2609 | // Restore receiver. |
| 2610 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2611 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2612 | GenerateJumpFunction(object, eax, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2613 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2614 | HandlerFrontendFooter(&miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2615 | |
| 2616 | // Return the generated code. |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 2617 | return GetCode(Code::FAST, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2621 | Handle<Code> CallStubCompiler::CompileCallGlobal( |
| 2622 | Handle<JSObject> object, |
| 2623 | Handle<GlobalObject> holder, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2624 | Handle<PropertyCell> cell, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2625 | Handle<JSFunction> function, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2626 | Handle<Name> name) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2627 | if (HasCustomCallGenerator(function)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2628 | Handle<Code> code = CompileCustomCall( |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2629 | object, holder, cell, function, Handle<String>::cast(name), |
| 2630 | Code::NORMAL); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2631 | // A null handle means bail out to the regular compiler code below. |
| 2632 | if (!code.is_null()) return code; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2633 | } |
| 2634 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2635 | Label miss; |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2636 | HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2637 | // Potentially loads a closure that matches the shared function info of the |
| 2638 | // function, rather than function. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2639 | GenerateLoadFunctionFromCell(cell, function, &miss); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2640 | GenerateJumpFunction(object, edi, function); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2641 | |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2642 | HandlerFrontendFooter(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2643 | |
| 2644 | // Return the generated code. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2645 | return GetCode(Code::NORMAL, name); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2649 | Handle<Code> StoreStubCompiler::CompileStoreCallback( |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2650 | Handle<JSObject> object, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 2651 | Handle<JSObject> holder, |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2652 | Handle<Name> name, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2653 | Handle<ExecutableAccessorInfo> callback) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2654 | HandlerFrontend(IC::CurrentTypeOf(object, isolate()), |
| 2655 | receiver(), holder, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2656 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2657 | __ pop(scratch1()); // remove the return address |
| 2658 | __ push(receiver()); |
| 2659 | __ Push(callback); |
| 2660 | __ Push(name); |
| 2661 | __ push(value()); |
| 2662 | __ push(scratch1()); // restore return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2663 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2664 | // Do tail-call to the runtime system. |
| 2665 | ExternalReference store_callback_property = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2666 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2667 | __ TailCallExternalReference(store_callback_property, 4, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2668 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2669 | // Return the generated code. |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 2670 | return GetCode(kind(), Code::FAST, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 2674 | Handle<Code> StoreStubCompiler::CompileStoreCallback( |
| 2675 | Handle<JSObject> object, |
| 2676 | Handle<JSObject> holder, |
| 2677 | Handle<Name> name, |
| 2678 | const CallOptimization& call_optimization) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2679 | HandlerFrontend(IC::CurrentTypeOf(object, isolate()), |
| 2680 | receiver(), holder, name); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 2681 | |
| 2682 | Register values[] = { value() }; |
| 2683 | GenerateFastApiCall( |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 2684 | masm(), call_optimization, receiver(), scratch1(), |
| 2685 | scratch2(), this->name(), 1, values); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 2686 | |
| 2687 | // Return the generated code. |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 2688 | return GetCode(kind(), Code::FAST, name); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2692 | #undef __ |
| 2693 | #define __ ACCESS_MASM(masm) |
| 2694 | |
| 2695 | |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame^] | 2696 | void CallStubCompiler::FetchGlobalProxy(MacroAssembler* masm, |
| 2697 | Register target, |
| 2698 | Register function) { |
| 2699 | __ mov(target, FieldOperand(function, JSFunction::kContextOffset)); |
| 2700 | __ mov(target, ContextOperand(target, Context::GLOBAL_OBJECT_INDEX)); |
| 2701 | __ mov(target, FieldOperand(target, GlobalObject::kGlobalReceiverOffset)); |
| 2702 | } |
| 2703 | |
| 2704 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2705 | void StoreStubCompiler::GenerateStoreViaSetter( |
| 2706 | MacroAssembler* masm, |
| 2707 | Handle<JSFunction> setter) { |
| 2708 | // ----------- S t a t e ------------- |
| 2709 | // -- eax : value |
| 2710 | // -- ecx : name |
| 2711 | // -- edx : receiver |
| 2712 | // -- esp[0] : return address |
| 2713 | // ----------------------------------- |
| 2714 | { |
| 2715 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2716 | |
| 2717 | // Save value register, so we can restore it later. |
| 2718 | __ push(eax); |
| 2719 | |
| 2720 | if (!setter.is_null()) { |
| 2721 | // Call the JavaScript setter with receiver and value on the stack. |
| 2722 | __ push(edx); |
| 2723 | __ push(eax); |
| 2724 | ParameterCount actual(1); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2725 | ParameterCount expected(setter); |
| 2726 | __ InvokeFunction(setter, expected, actual, |
| 2727 | CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2728 | } else { |
| 2729 | // If we generate a global code snippet for deoptimization only, remember |
| 2730 | // the place to continue after deoptimization. |
| 2731 | masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset()); |
| 2732 | } |
| 2733 | |
| 2734 | // We have to return the passed value, not the return value of the setter. |
| 2735 | __ pop(eax); |
| 2736 | |
| 2737 | // Restore context register. |
| 2738 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2739 | } |
| 2740 | __ ret(0); |
| 2741 | } |
| 2742 | |
| 2743 | |
| 2744 | #undef __ |
| 2745 | #define __ ACCESS_MASM(masm()) |
| 2746 | |
| 2747 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2748 | Handle<Code> StoreStubCompiler::CompileStoreInterceptor( |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2749 | Handle<JSObject> object, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2750 | Handle<Name> name) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2751 | __ pop(scratch1()); // remove the return address |
| 2752 | __ push(receiver()); |
| 2753 | __ push(this->name()); |
| 2754 | __ push(value()); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2755 | __ push(scratch1()); // restore return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2756 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2757 | // Do tail-call to the runtime system. |
| 2758 | ExternalReference store_ic_property = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2759 | ExternalReference(IC_Utility(IC::kStoreInterceptorProperty), isolate()); |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 2760 | __ TailCallExternalReference(store_ic_property, 3, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2761 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2762 | // Return the generated code. |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 2763 | return GetCode(kind(), Code::FAST, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2767 | Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic( |
| 2768 | MapHandleList* receiver_maps, |
| 2769 | CodeHandleList* handler_stubs, |
| 2770 | MapHandleList* transitioned_maps) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2771 | Label miss; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2772 | __ JumpIfSmi(receiver(), &miss, Label::kNear); |
| 2773 | __ mov(scratch1(), FieldOperand(receiver(), HeapObject::kMapOffset)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2774 | for (int i = 0; i < receiver_maps->length(); ++i) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2775 | __ cmp(scratch1(), receiver_maps->at(i)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2776 | if (transitioned_maps->at(i).is_null()) { |
| 2777 | __ j(equal, handler_stubs->at(i)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2778 | } else { |
| 2779 | Label next_map; |
| 2780 | __ j(not_equal, &next_map, Label::kNear); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2781 | __ mov(transition_map(), Immediate(transitioned_maps->at(i))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2782 | __ jmp(handler_stubs->at(i), RelocInfo::CODE_TARGET); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2783 | __ bind(&next_map); |
| 2784 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2785 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2786 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2787 | TailCallBuiltin(masm(), MissBuiltin(kind())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2788 | |
| 2789 | // Return the generated code. |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2790 | return GetICCode( |
| 2791 | kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2795 | Handle<Code> LoadStubCompiler::CompileLoadNonexistent(Handle<Type> type, |
| 2796 | Handle<JSObject> last, |
| 2797 | Handle<Name> name) { |
| 2798 | NonexistentHandlerFrontend(type, last, name); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2799 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2800 | // Return undefined if maps of the full prototype chain are still the |
| 2801 | // same and no global property with this name contains a value. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2802 | __ mov(eax, isolate()->factory()->undefined_value()); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2803 | __ ret(0); |
| 2804 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2805 | // Return the generated code. |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 2806 | return GetCode(kind(), Code::FAST, name); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2807 | } |
| 2808 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2809 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2810 | Register* LoadStubCompiler::registers() { |
| 2811 | // receiver, name, scratch1, scratch2, scratch3, scratch4. |
| 2812 | static Register registers[] = { edx, ecx, ebx, eax, edi, no_reg }; |
| 2813 | return registers; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2817 | Register* KeyedLoadStubCompiler::registers() { |
| 2818 | // receiver, name, scratch1, scratch2, scratch3, scratch4. |
| 2819 | static Register registers[] = { edx, ecx, ebx, eax, edi, no_reg }; |
| 2820 | return registers; |
| 2821 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2822 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2823 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2824 | Register* StoreStubCompiler::registers() { |
| 2825 | // receiver, name, value, scratch1, scratch2, scratch3. |
| 2826 | static Register registers[] = { edx, ecx, eax, ebx, edi, no_reg }; |
| 2827 | return registers; |
| 2828 | } |
| 2829 | |
| 2830 | |
| 2831 | Register* KeyedStoreStubCompiler::registers() { |
| 2832 | // receiver, name, value, scratch1, scratch2, scratch3. |
| 2833 | static Register registers[] = { edx, ecx, eax, ebx, edi, no_reg }; |
| 2834 | return registers; |
| 2835 | } |
| 2836 | |
| 2837 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2838 | void KeyedLoadStubCompiler::GenerateNameCheck(Handle<Name> name, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2839 | Register name_reg, |
| 2840 | Label* miss) { |
| 2841 | __ cmp(name_reg, Immediate(name)); |
| 2842 | __ j(not_equal, miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2846 | void KeyedStoreStubCompiler::GenerateNameCheck(Handle<Name> name, |
| 2847 | Register name_reg, |
| 2848 | Label* miss) { |
| 2849 | __ cmp(name_reg, Immediate(name)); |
| 2850 | __ j(not_equal, miss); |
| 2851 | } |
| 2852 | |
| 2853 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2854 | #undef __ |
| 2855 | #define __ ACCESS_MASM(masm) |
| 2856 | |
| 2857 | |
| 2858 | void LoadStubCompiler::GenerateLoadViaGetter(MacroAssembler* masm, |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 2859 | Register receiver, |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2860 | Handle<JSFunction> getter) { |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2861 | { |
| 2862 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2863 | |
| 2864 | if (!getter.is_null()) { |
| 2865 | // Call the JavaScript getter with the receiver on the stack. |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 2866 | __ push(receiver); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2867 | ParameterCount actual(0); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2868 | ParameterCount expected(getter); |
| 2869 | __ InvokeFunction(getter, expected, actual, |
| 2870 | CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2871 | } else { |
| 2872 | // If we generate a global code snippet for deoptimization only, remember |
| 2873 | // the place to continue after deoptimization. |
| 2874 | masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset()); |
| 2875 | } |
| 2876 | |
| 2877 | // Restore context register. |
| 2878 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2879 | } |
| 2880 | __ ret(0); |
| 2881 | } |
| 2882 | |
| 2883 | |
| 2884 | #undef __ |
| 2885 | #define __ ACCESS_MASM(masm()) |
| 2886 | |
| 2887 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2888 | Handle<Code> LoadStubCompiler::CompileLoadGlobal( |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2889 | Handle<Type> type, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2890 | Handle<GlobalObject> global, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2891 | Handle<PropertyCell> cell, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2892 | Handle<Name> name, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2893 | bool is_dont_delete) { |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 2894 | Label miss; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2895 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2896 | HandlerFrontendHeader(type, receiver(), global, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2897 | // Get the value from the cell. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2898 | if (Serializer::enabled()) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2899 | __ mov(eax, Immediate(cell)); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2900 | __ mov(eax, FieldOperand(eax, PropertyCell::kValueOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2901 | } else { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2902 | __ mov(eax, Operand::ForCell(cell)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2903 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2904 | |
| 2905 | // Check for deleted property if property can actually be deleted. |
| 2906 | if (!is_dont_delete) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2907 | __ cmp(eax, factory()->the_hole_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2908 | __ j(equal, &miss); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2909 | } else if (FLAG_debug_code) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2910 | __ cmp(eax, factory()->the_hole_value()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2911 | __ Check(not_equal, kDontDeleteCellsCannotContainTheHole); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2912 | } |
| 2913 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 2914 | HandlerFrontendFooter(name, &miss); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2915 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2916 | Counters* counters = isolate()->counters(); |
| 2917 | __ IncrementCounter(counters->named_load_global_stub(), 1); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2918 | // The code above already loads the result into the return register. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2919 | __ ret(0); |
| 2920 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2921 | // Return the generated code. |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 2922 | return GetCode(kind(), Code::NORMAL, name); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2926 | Handle<Code> BaseLoadStoreStubCompiler::CompilePolymorphicIC( |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 2927 | TypeHandleList* types, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2928 | CodeHandleList* handlers, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2929 | Handle<Name> name, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2930 | Code::StubType type, |
| 2931 | IcCheckType check) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2932 | Label miss; |
| 2933 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2934 | if (check == PROPERTY) { |
| 2935 | GenerateNameCheck(name, this->name(), &miss); |
| 2936 | } |
| 2937 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 2938 | Label number_case; |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 2939 | Label* smi_target = IncludesNumberType(types) ? &number_case : &miss; |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 2940 | __ JumpIfSmi(receiver(), smi_target); |
| 2941 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2942 | Register map_reg = scratch1(); |
| 2943 | __ mov(map_reg, FieldOperand(receiver(), HeapObject::kMapOffset)); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 2944 | int receiver_count = types->length(); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2945 | int number_of_handled_maps = 0; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2946 | for (int current = 0; current < receiver_count; ++current) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 2947 | Handle<Type> type = types->at(current); |
| 2948 | Handle<Map> map = IC::TypeToMap(*type, isolate()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2949 | if (!map->is_deprecated()) { |
| 2950 | number_of_handled_maps++; |
| 2951 | __ cmp(map_reg, map); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 2952 | if (type->Is(Type::Number())) { |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 2953 | ASSERT(!number_case.is_unused()); |
| 2954 | __ bind(&number_case); |
| 2955 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2956 | __ j(equal, handlers->at(current)); |
| 2957 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2958 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2959 | ASSERT(number_of_handled_maps != 0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2960 | |
| 2961 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2962 | TailCallBuiltin(masm(), MissBuiltin(kind())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2963 | |
| 2964 | // Return the generated code. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2965 | InlineCacheState state = |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2966 | number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2967 | return GetICCode(kind(), type, name, state); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2971 | #undef __ |
| 2972 | #define __ ACCESS_MASM(masm) |
| 2973 | |
| 2974 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2975 | void KeyedLoadStubCompiler::GenerateLoadDictionaryElement( |
| 2976 | MacroAssembler* masm) { |
| 2977 | // ----------- S t a t e ------------- |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2978 | // -- ecx : key |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2979 | // -- edx : receiver |
| 2980 | // -- esp[0] : return address |
| 2981 | // ----------------------------------- |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 2982 | Label slow, miss; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2983 | |
| 2984 | // This stub is meant to be tail-jumped to, the receiver must already |
| 2985 | // have been verified by the caller to not be a smi. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 2986 | __ JumpIfNotSmi(ecx, &miss); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2987 | __ mov(ebx, ecx); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2988 | __ SmiUntag(ebx); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2989 | __ mov(eax, FieldOperand(edx, JSObject::kElementsOffset)); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2990 | |
| 2991 | // Push receiver on the stack to free up a register for the dictionary |
| 2992 | // probing. |
| 2993 | __ push(edx); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2994 | __ LoadFromNumberDictionary(&slow, eax, ecx, ebx, edx, edi, eax); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2995 | // Pop receiver before returning. |
| 2996 | __ pop(edx); |
| 2997 | __ ret(0); |
| 2998 | |
| 2999 | __ bind(&slow); |
| 3000 | __ pop(edx); |
| 3001 | |
| 3002 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3003 | // -- ecx : key |
| 3004 | // -- edx : receiver |
| 3005 | // -- esp[0] : return address |
| 3006 | // ----------------------------------- |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3007 | TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3008 | |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 3009 | __ bind(&miss); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3010 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3011 | // -- ecx : key |
| 3012 | // -- edx : receiver |
| 3013 | // -- esp[0] : return address |
| 3014 | // ----------------------------------- |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 3015 | TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3019 | #undef __ |
| 3020 | |
| 3021 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3022 | |
| 3023 | #endif // V8_TARGET_ARCH_IA32 |