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