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