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 |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 819 | __ mov(other, Immediate(callback_handle)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 820 | __ push(FieldOperand(other, AccessorInfo::kDataOffset)); // data |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 821 | __ push(name_reg); // name |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 822 | // Save a pointer to where we pushed the arguments pointer. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 823 | // 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] | 824 | __ mov(eax, esp); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 825 | __ add(Operand(eax), Immediate(4 * kPointerSize)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 826 | __ mov(ebx, esp); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 827 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 828 | // Do call through the api. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 829 | ASSERT_EQ(5, ApiGetterEntryStub::kStackSpace); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 830 | Address getter_address = v8::ToCData<Address>(callback->getter()); |
| 831 | ApiFunction fun(getter_address); |
| 832 | ApiGetterEntryStub stub(callback_handle, &fun); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 833 | // Emitting a stub call may try to allocate (if the code is not |
| 834 | // already generated). Do not allow the assembler to perform a |
| 835 | // garbage collection but instead return the allocation failure |
| 836 | // object. |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 837 | Object* result = masm()->TryCallStub(&stub); |
| 838 | if (result->IsFailure()) { |
| 839 | *failure = Failure::cast(result); |
| 840 | return false; |
| 841 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 842 | |
| 843 | // We need to avoid using eax since that now holds the result. |
| 844 | Register tmp = other.is(eax) ? reg : other; |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 845 | // Emitting PopHandleScope may try to allocate. Do not allow the |
| 846 | // assembler to perform a garbage collection but instead return a |
| 847 | // failure object. |
| 848 | result = masm()->TryPopHandleScope(eax, tmp); |
| 849 | if (result->IsFailure()) { |
| 850 | *failure = Failure::cast(result); |
| 851 | return false; |
| 852 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 853 | __ LeaveInternalFrame(); |
| 854 | |
| 855 | __ ret(0); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 856 | return true; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | |
| 860 | void StubCompiler::GenerateLoadConstant(JSObject* object, |
| 861 | JSObject* holder, |
| 862 | Register receiver, |
| 863 | Register scratch1, |
| 864 | Register scratch2, |
| 865 | Object* value, |
| 866 | String* name, |
| 867 | Label* miss) { |
| 868 | // Check that the receiver isn't a smi. |
| 869 | __ test(receiver, Immediate(kSmiTagMask)); |
| 870 | __ j(zero, miss, not_taken); |
| 871 | |
| 872 | // Check that the maps haven't changed. |
| 873 | Register reg = |
| 874 | CheckPrototypes(object, receiver, holder, |
| 875 | scratch1, scratch2, name, miss); |
| 876 | |
| 877 | // Return the constant value. |
| 878 | __ mov(eax, Handle<Object>(value)); |
| 879 | __ ret(0); |
| 880 | } |
| 881 | |
| 882 | |
| 883 | void StubCompiler::GenerateLoadInterceptor(JSObject* object, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 884 | JSObject* interceptor_holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 885 | LookupResult* lookup, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 886 | Register receiver, |
| 887 | Register name_reg, |
| 888 | Register scratch1, |
| 889 | Register scratch2, |
| 890 | String* name, |
| 891 | Label* miss) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 892 | ASSERT(interceptor_holder->HasNamedInterceptor()); |
| 893 | ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 894 | |
| 895 | // Check that the receiver isn't a smi. |
| 896 | __ test(receiver, Immediate(kSmiTagMask)); |
| 897 | __ j(zero, miss, not_taken); |
| 898 | |
| 899 | // So far the most popular follow ups for interceptor loads are FIELD |
| 900 | // and CALLBACKS, so inline only them, other cases may be added |
| 901 | // later. |
| 902 | bool compile_followup_inline = false; |
| 903 | if (lookup->IsProperty() && lookup->IsCacheable()) { |
| 904 | if (lookup->type() == FIELD) { |
| 905 | compile_followup_inline = true; |
| 906 | } else if (lookup->type() == CALLBACKS && |
| 907 | lookup->GetCallbackObject()->IsAccessorInfo() && |
| 908 | AccessorInfo::cast(lookup->GetCallbackObject())->getter() != NULL) { |
| 909 | compile_followup_inline = true; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | if (compile_followup_inline) { |
| 914 | // Compile the interceptor call, followed by inline code to load the |
| 915 | // property from further up the prototype chain if the call fails. |
| 916 | // Check that the maps haven't changed. |
| 917 | Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder, |
| 918 | scratch1, scratch2, name, miss); |
| 919 | ASSERT(holder_reg.is(receiver) || holder_reg.is(scratch1)); |
| 920 | |
| 921 | // Save necessary data before invoking an interceptor. |
| 922 | // Requires a frame to make GC aware of pushed pointers. |
| 923 | __ EnterInternalFrame(); |
| 924 | |
| 925 | if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) { |
| 926 | // CALLBACKS case needs a receiver to be passed into C++ callback. |
| 927 | __ push(receiver); |
| 928 | } |
| 929 | __ push(holder_reg); |
| 930 | __ push(name_reg); |
| 931 | |
| 932 | // Invoke an interceptor. Note: map checks from receiver to |
| 933 | // interceptor's holder has been compiled before (see a caller |
| 934 | // of this method.) |
| 935 | CompileCallLoadPropertyWithInterceptor(masm(), |
| 936 | receiver, |
| 937 | holder_reg, |
| 938 | name_reg, |
| 939 | interceptor_holder); |
| 940 | |
| 941 | // Check if interceptor provided a value for property. If it's |
| 942 | // the case, return immediately. |
| 943 | Label interceptor_failed; |
| 944 | __ cmp(eax, Factory::no_interceptor_result_sentinel()); |
| 945 | __ j(equal, &interceptor_failed); |
| 946 | __ LeaveInternalFrame(); |
| 947 | __ ret(0); |
| 948 | |
| 949 | __ bind(&interceptor_failed); |
| 950 | __ pop(name_reg); |
| 951 | __ pop(holder_reg); |
| 952 | if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) { |
| 953 | __ pop(receiver); |
| 954 | } |
| 955 | |
| 956 | __ LeaveInternalFrame(); |
| 957 | |
| 958 | // Check that the maps from interceptor's holder to lookup's holder |
| 959 | // haven't changed. And load lookup's holder into holder_reg. |
| 960 | if (interceptor_holder != lookup->holder()) { |
| 961 | holder_reg = CheckPrototypes(interceptor_holder, |
| 962 | holder_reg, |
| 963 | lookup->holder(), |
| 964 | scratch1, |
| 965 | scratch2, |
| 966 | name, |
| 967 | miss); |
| 968 | } |
| 969 | |
| 970 | if (lookup->type() == FIELD) { |
| 971 | // We found FIELD property in prototype chain of interceptor's holder. |
| 972 | // Retrieve a field from field's holder. |
| 973 | GenerateFastPropertyLoad(masm(), eax, holder_reg, |
| 974 | lookup->holder(), lookup->GetFieldIndex()); |
| 975 | __ ret(0); |
| 976 | } else { |
| 977 | // We found CALLBACKS property in prototype chain of interceptor's |
| 978 | // holder. |
| 979 | ASSERT(lookup->type() == CALLBACKS); |
| 980 | ASSERT(lookup->GetCallbackObject()->IsAccessorInfo()); |
| 981 | AccessorInfo* callback = AccessorInfo::cast(lookup->GetCallbackObject()); |
| 982 | ASSERT(callback != NULL); |
| 983 | ASSERT(callback->getter() != NULL); |
| 984 | |
| 985 | // Tail call to runtime. |
| 986 | // Important invariant in CALLBACKS case: the code above must be |
| 987 | // structured to never clobber |receiver| register. |
| 988 | __ pop(scratch2); // return address |
| 989 | __ push(receiver); |
| 990 | __ push(holder_reg); |
| 991 | __ mov(holder_reg, Immediate(Handle<AccessorInfo>(callback))); |
| 992 | __ push(holder_reg); |
| 993 | __ push(FieldOperand(holder_reg, AccessorInfo::kDataOffset)); |
| 994 | __ push(name_reg); |
| 995 | __ push(scratch2); // restore return address |
| 996 | |
| 997 | ExternalReference ref = |
| 998 | ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); |
| 999 | __ TailCallExternalReference(ref, 5, 1); |
| 1000 | } |
| 1001 | } else { // !compile_followup_inline |
| 1002 | // Call the runtime system to load the interceptor. |
| 1003 | // Check that the maps haven't changed. |
| 1004 | Register holder_reg = |
| 1005 | CheckPrototypes(object, receiver, interceptor_holder, |
| 1006 | scratch1, scratch2, name, miss); |
| 1007 | __ pop(scratch2); // save old return address |
| 1008 | PushInterceptorArguments(masm(), receiver, holder_reg, |
| 1009 | name_reg, interceptor_holder); |
| 1010 | __ push(scratch2); // restore old return address |
| 1011 | |
| 1012 | ExternalReference ref = ExternalReference( |
| 1013 | IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); |
| 1014 | __ TailCallExternalReference(ref, 5, 1); |
| 1015 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1019 | // TODO(1241006): Avoid having lazy compile stubs specialized by the |
| 1020 | // number of arguments. It is not needed anymore. |
| 1021 | Object* StubCompiler::CompileLazyCompile(Code::Flags flags) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1022 | // Enter an internal frame. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1023 | __ EnterInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1024 | |
| 1025 | // Push a copy of the function onto the stack. |
| 1026 | __ push(edi); |
| 1027 | |
| 1028 | __ push(edi); // function is also the parameter to the runtime call |
| 1029 | __ CallRuntime(Runtime::kLazyCompile, 1); |
| 1030 | __ pop(edi); |
| 1031 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1032 | // Tear down temporary frame. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1033 | __ LeaveInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1034 | |
| 1035 | // Do a tail-call of the compiled function. |
| 1036 | __ lea(ecx, FieldOperand(eax, Code::kHeaderSize)); |
| 1037 | __ jmp(Operand(ecx)); |
| 1038 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1039 | return GetCodeWithFlags(flags, "LazyCompileStub"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1043 | void CallStubCompiler::GenerateNameCheck(String* name, Label* miss) { |
| 1044 | if (kind_ == Code::KEYED_CALL_IC) { |
| 1045 | __ cmp(Operand(ecx), Immediate(Handle<String>(name))); |
| 1046 | __ j(not_equal, miss, not_taken); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | void CallStubCompiler::GenerateMissBranch() { |
| 1052 | Handle<Code> ic = ComputeCallMiss(arguments().immediate(), kind_); |
| 1053 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 1054 | } |
| 1055 | |
| 1056 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1057 | Object* CallStubCompiler::CompileCallField(JSObject* object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1058 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1059 | int index, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1060 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1061 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1062 | // -- ecx : name |
| 1063 | // -- esp[0] : return address |
| 1064 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1065 | // -- ... |
| 1066 | // -- esp[(argc + 1) * 4] : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1067 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1068 | Label miss; |
| 1069 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1070 | GenerateNameCheck(name, &miss); |
| 1071 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1072 | // Get the receiver from the stack. |
| 1073 | const int argc = arguments().immediate(); |
| 1074 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1075 | |
| 1076 | // Check that the receiver isn't a smi. |
| 1077 | __ test(edx, Immediate(kSmiTagMask)); |
| 1078 | __ j(zero, &miss, not_taken); |
| 1079 | |
| 1080 | // Do the right check and compute the holder register. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1081 | Register reg = CheckPrototypes(object, edx, holder, ebx, eax, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1082 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1083 | GenerateFastPropertyLoad(masm(), edi, reg, holder, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Check that the function really is a function. |
| 1086 | __ test(edi, Immediate(kSmiTagMask)); |
| 1087 | __ j(zero, &miss, not_taken); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1088 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1089 | __ j(not_equal, &miss, not_taken); |
| 1090 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1091 | // Patch the receiver on the stack with the global proxy if |
| 1092 | // necessary. |
| 1093 | if (object->IsGlobalObject()) { |
| 1094 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1095 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1096 | } |
| 1097 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1098 | // Invoke the function. |
| 1099 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION); |
| 1100 | |
| 1101 | // Handle call cache miss. |
| 1102 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1103 | GenerateMissBranch(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1104 | |
| 1105 | // Return the generated code. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1106 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1110 | Object* CallStubCompiler::CompileArrayPushCall(Object* object, |
| 1111 | JSObject* holder, |
| 1112 | JSFunction* function, |
| 1113 | String* name, |
| 1114 | CheckType check) { |
| 1115 | // ----------- S t a t e ------------- |
| 1116 | // -- ecx : name |
| 1117 | // -- esp[0] : return address |
| 1118 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1119 | // -- ... |
| 1120 | // -- esp[(argc + 1) * 4] : receiver |
| 1121 | // ----------------------------------- |
| 1122 | ASSERT(check == RECEIVER_MAP_CHECK); |
| 1123 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1124 | // If object is not an array, bail out to regular call. |
| 1125 | if (!object->IsJSArray()) { |
| 1126 | return Heap::undefined_value(); |
| 1127 | } |
| 1128 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1129 | Label miss; |
| 1130 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1131 | GenerateNameCheck(name, &miss); |
| 1132 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1133 | // Get the receiver from the stack. |
| 1134 | const int argc = arguments().immediate(); |
| 1135 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1136 | |
| 1137 | // Check that the receiver isn't a smi. |
| 1138 | __ test(edx, Immediate(kSmiTagMask)); |
| 1139 | __ j(zero, &miss); |
| 1140 | |
| 1141 | CheckPrototypes(JSObject::cast(object), edx, |
| 1142 | holder, ebx, |
| 1143 | eax, name, &miss); |
| 1144 | |
| 1145 | if (argc == 0) { |
| 1146 | // Noop, return the length. |
| 1147 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1148 | __ ret((argc + 1) * kPointerSize); |
| 1149 | } else { |
| 1150 | // Get the elements array of the object. |
| 1151 | __ mov(ebx, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1152 | |
| 1153 | // Check that the elements are in fast mode (not dictionary). |
| 1154 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1155 | Immediate(Factory::fixed_array_map())); |
| 1156 | __ j(not_equal, &miss); |
| 1157 | |
| 1158 | if (argc == 1) { // Otherwise fall through to call builtin. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1159 | Label call_builtin, exit, with_write_barrier, attempt_to_grow_elements; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1160 | |
| 1161 | // Get the array's length into eax and calculate new length. |
| 1162 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1163 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1164 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1165 | __ add(Operand(eax), Immediate(Smi::FromInt(argc))); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1166 | |
| 1167 | // Get the element's length into ecx. |
| 1168 | __ mov(ecx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1169 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1170 | // Check if we could survive without allocation. |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1171 | __ cmp(eax, Operand(ecx)); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1172 | __ j(greater, &attempt_to_grow_elements); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1173 | |
| 1174 | // Save new length. |
| 1175 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1176 | |
| 1177 | // Push the element. |
| 1178 | __ lea(edx, FieldOperand(ebx, |
| 1179 | eax, times_half_pointer_size, |
| 1180 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 1181 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 1182 | __ mov(Operand(edx, 0), ecx); |
| 1183 | |
| 1184 | // Check if value is a smi. |
| 1185 | __ test(ecx, Immediate(kSmiTagMask)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1186 | __ j(not_zero, &with_write_barrier); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1187 | |
| 1188 | __ bind(&exit); |
| 1189 | __ ret((argc + 1) * kPointerSize); |
| 1190 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1191 | __ bind(&with_write_barrier); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1192 | |
| 1193 | __ InNewSpace(ebx, ecx, equal, &exit); |
| 1194 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1195 | __ RecordWriteHelper(ebx, edx, ecx); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1196 | __ ret((argc + 1) * kPointerSize); |
| 1197 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1198 | __ bind(&attempt_to_grow_elements); |
| 1199 | ExternalReference new_space_allocation_top = |
| 1200 | ExternalReference::new_space_allocation_top_address(); |
| 1201 | ExternalReference new_space_allocation_limit = |
| 1202 | ExternalReference::new_space_allocation_limit_address(); |
| 1203 | |
| 1204 | const int kAllocationDelta = 4; |
| 1205 | // Load top. |
| 1206 | __ mov(ecx, Operand::StaticVariable(new_space_allocation_top)); |
| 1207 | |
| 1208 | // Check if it's the end of elements. |
| 1209 | __ lea(edx, FieldOperand(ebx, |
| 1210 | eax, times_half_pointer_size, |
| 1211 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 1212 | __ cmp(edx, Operand(ecx)); |
| 1213 | __ j(not_equal, &call_builtin); |
| 1214 | __ add(Operand(ecx), Immediate(kAllocationDelta * kPointerSize)); |
| 1215 | __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1216 | __ j(above, &call_builtin); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1217 | |
| 1218 | // We fit and could grow elements. |
| 1219 | __ mov(Operand::StaticVariable(new_space_allocation_top), ecx); |
| 1220 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1221 | |
| 1222 | // Push the argument... |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1223 | __ mov(Operand(edx, 0), ecx); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1224 | // ... and fill the rest with holes. |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1225 | for (int i = 1; i < kAllocationDelta; i++) { |
| 1226 | __ mov(Operand(edx, i * kPointerSize), |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1227 | Immediate(Factory::the_hole_value())); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | // Restore receiver to edx as finish sequence assumes it's here. |
| 1231 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1232 | |
| 1233 | // Increment element's and array's sizes. |
| 1234 | __ add(FieldOperand(ebx, FixedArray::kLengthOffset), |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1235 | Immediate(Smi::FromInt(kAllocationDelta))); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1236 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1237 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1238 | // Elements are in new space, so write barrier is not required. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1239 | __ ret((argc + 1) * kPointerSize); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1240 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1241 | __ bind(&call_builtin); |
| 1242 | } |
| 1243 | |
| 1244 | __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush), |
| 1245 | argc + 1, |
| 1246 | 1); |
| 1247 | } |
| 1248 | |
| 1249 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1250 | GenerateMissBranch(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1251 | |
| 1252 | // Return the generated code. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1253 | return GetCode(function); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | Object* CallStubCompiler::CompileArrayPopCall(Object* object, |
| 1258 | JSObject* holder, |
| 1259 | JSFunction* function, |
| 1260 | String* name, |
| 1261 | CheckType check) { |
| 1262 | // ----------- S t a t e ------------- |
| 1263 | // -- ecx : name |
| 1264 | // -- esp[0] : return address |
| 1265 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1266 | // -- ... |
| 1267 | // -- esp[(argc + 1) * 4] : receiver |
| 1268 | // ----------------------------------- |
| 1269 | ASSERT(check == RECEIVER_MAP_CHECK); |
| 1270 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1271 | // If object is not an array, bail out to regular call. |
| 1272 | if (!object->IsJSArray()) { |
| 1273 | return Heap::undefined_value(); |
| 1274 | } |
| 1275 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1276 | Label miss, return_undefined, call_builtin; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1277 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1278 | GenerateNameCheck(name, &miss); |
| 1279 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1280 | // Get the receiver from the stack. |
| 1281 | const int argc = arguments().immediate(); |
| 1282 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1283 | |
| 1284 | // Check that the receiver isn't a smi. |
| 1285 | __ test(edx, Immediate(kSmiTagMask)); |
| 1286 | __ j(zero, &miss); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1287 | CheckPrototypes(JSObject::cast(object), edx, |
| 1288 | holder, ebx, |
| 1289 | eax, name, &miss); |
| 1290 | |
| 1291 | // Get the elements array of the object. |
| 1292 | __ mov(ebx, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1293 | |
| 1294 | // Check that the elements are in fast mode (not dictionary). |
| 1295 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1296 | Immediate(Factory::fixed_array_map())); |
| 1297 | __ j(not_equal, &miss); |
| 1298 | |
| 1299 | // Get the array's length into ecx and calculate new length. |
| 1300 | __ mov(ecx, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1301 | __ sub(Operand(ecx), Immediate(Smi::FromInt(1))); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1302 | __ j(negative, &return_undefined); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1303 | |
| 1304 | // Get the last element. |
| 1305 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1306 | STATIC_ASSERT(kSmiTag == 0); |
| 1307 | __ mov(eax, FieldOperand(ebx, |
| 1308 | ecx, times_half_pointer_size, |
| 1309 | FixedArray::kHeaderSize)); |
| 1310 | __ cmp(Operand(eax), Immediate(Factory::the_hole_value())); |
| 1311 | __ j(equal, &call_builtin); |
| 1312 | |
| 1313 | // Set the array's length. |
| 1314 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), ecx); |
| 1315 | |
| 1316 | // Fill with the hole. |
| 1317 | __ mov(FieldOperand(ebx, |
| 1318 | ecx, times_half_pointer_size, |
| 1319 | FixedArray::kHeaderSize), |
| 1320 | Immediate(Factory::the_hole_value())); |
| 1321 | __ ret((argc + 1) * kPointerSize); |
| 1322 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1323 | __ bind(&return_undefined); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1324 | __ mov(eax, Immediate(Factory::undefined_value())); |
| 1325 | __ ret((argc + 1) * kPointerSize); |
| 1326 | |
| 1327 | __ bind(&call_builtin); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1328 | __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop), |
| 1329 | argc + 1, |
| 1330 | 1); |
| 1331 | |
| 1332 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1333 | GenerateMissBranch(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1334 | |
| 1335 | // Return the generated code. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1336 | return GetCode(function); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1340 | Object* CallStubCompiler::CompileStringCharCodeAtCall(Object* object, |
| 1341 | JSObject* holder, |
| 1342 | JSFunction* function, |
| 1343 | String* name, |
| 1344 | CheckType check) { |
| 1345 | // ----------- S t a t e ------------- |
| 1346 | // -- ecx : function name |
| 1347 | // -- esp[0] : return address |
| 1348 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1349 | // -- ... |
| 1350 | // -- esp[(argc + 1) * 4] : receiver |
| 1351 | // ----------------------------------- |
| 1352 | |
| 1353 | const int argc = arguments().immediate(); |
| 1354 | |
| 1355 | Label miss; |
| 1356 | Label index_out_of_range; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1357 | GenerateNameCheck(name, &miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1358 | |
| 1359 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1360 | GenerateDirectLoadGlobalFunctionPrototype(masm(), |
| 1361 | Context::STRING_FUNCTION_INDEX, |
| 1362 | eax); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1363 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
| 1364 | ebx, edx, name, &miss); |
| 1365 | |
| 1366 | Register receiver = ebx; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1367 | Register index = edi; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1368 | Register scratch = edx; |
| 1369 | Register result = eax; |
| 1370 | __ mov(receiver, Operand(esp, (argc + 1) * kPointerSize)); |
| 1371 | if (argc > 0) { |
| 1372 | __ mov(index, Operand(esp, (argc - 0) * kPointerSize)); |
| 1373 | } else { |
| 1374 | __ Set(index, Immediate(Factory::undefined_value())); |
| 1375 | } |
| 1376 | |
| 1377 | StringCharCodeAtGenerator char_code_at_generator(receiver, |
| 1378 | index, |
| 1379 | scratch, |
| 1380 | result, |
| 1381 | &miss, // When not a string. |
| 1382 | &miss, // When not a number. |
| 1383 | &index_out_of_range, |
| 1384 | STRING_INDEX_IS_NUMBER); |
| 1385 | char_code_at_generator.GenerateFast(masm()); |
| 1386 | __ ret((argc + 1) * kPointerSize); |
| 1387 | |
| 1388 | ICRuntimeCallHelper call_helper; |
| 1389 | char_code_at_generator.GenerateSlow(masm(), call_helper); |
| 1390 | |
| 1391 | __ bind(&index_out_of_range); |
| 1392 | __ Set(eax, Immediate(Factory::nan_value())); |
| 1393 | __ ret((argc + 1) * kPointerSize); |
| 1394 | |
| 1395 | __ bind(&miss); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1396 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1397 | GenerateMissBranch(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1398 | |
| 1399 | // Return the generated code. |
| 1400 | return GetCode(function); |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | Object* CallStubCompiler::CompileStringCharAtCall(Object* object, |
| 1405 | JSObject* holder, |
| 1406 | JSFunction* function, |
| 1407 | String* name, |
| 1408 | CheckType check) { |
| 1409 | // ----------- S t a t e ------------- |
| 1410 | // -- ecx : function name |
| 1411 | // -- esp[0] : return address |
| 1412 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1413 | // -- ... |
| 1414 | // -- esp[(argc + 1) * 4] : receiver |
| 1415 | // ----------------------------------- |
| 1416 | |
| 1417 | const int argc = arguments().immediate(); |
| 1418 | |
| 1419 | Label miss; |
| 1420 | Label index_out_of_range; |
| 1421 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1422 | GenerateNameCheck(name, &miss); |
| 1423 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1424 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1425 | GenerateDirectLoadGlobalFunctionPrototype(masm(), |
| 1426 | Context::STRING_FUNCTION_INDEX, |
| 1427 | eax); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1428 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
| 1429 | ebx, edx, name, &miss); |
| 1430 | |
| 1431 | Register receiver = eax; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1432 | Register index = edi; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1433 | Register scratch1 = ebx; |
| 1434 | Register scratch2 = edx; |
| 1435 | Register result = eax; |
| 1436 | __ mov(receiver, Operand(esp, (argc + 1) * kPointerSize)); |
| 1437 | if (argc > 0) { |
| 1438 | __ mov(index, Operand(esp, (argc - 0) * kPointerSize)); |
| 1439 | } else { |
| 1440 | __ Set(index, Immediate(Factory::undefined_value())); |
| 1441 | } |
| 1442 | |
| 1443 | StringCharAtGenerator char_at_generator(receiver, |
| 1444 | index, |
| 1445 | scratch1, |
| 1446 | scratch2, |
| 1447 | result, |
| 1448 | &miss, // When not a string. |
| 1449 | &miss, // When not a number. |
| 1450 | &index_out_of_range, |
| 1451 | STRING_INDEX_IS_NUMBER); |
| 1452 | char_at_generator.GenerateFast(masm()); |
| 1453 | __ ret((argc + 1) * kPointerSize); |
| 1454 | |
| 1455 | ICRuntimeCallHelper call_helper; |
| 1456 | char_at_generator.GenerateSlow(masm(), call_helper); |
| 1457 | |
| 1458 | __ bind(&index_out_of_range); |
| 1459 | __ Set(eax, Immediate(Factory::empty_string())); |
| 1460 | __ ret((argc + 1) * kPointerSize); |
| 1461 | |
| 1462 | __ bind(&miss); |
| 1463 | // Restore function name in ecx. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1464 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1465 | GenerateMissBranch(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1466 | |
| 1467 | // Return the generated code. |
| 1468 | return GetCode(function); |
| 1469 | } |
| 1470 | |
| 1471 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1472 | Object* CallStubCompiler::CompileCallConstant(Object* object, |
| 1473 | JSObject* holder, |
| 1474 | JSFunction* function, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1475 | String* name, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1476 | CheckType check) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1477 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1478 | // -- ecx : name |
| 1479 | // -- esp[0] : return address |
| 1480 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1481 | // -- ... |
| 1482 | // -- esp[(argc + 1) * 4] : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1483 | // ----------------------------------- |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1484 | |
| 1485 | SharedFunctionInfo* function_info = function->shared(); |
| 1486 | if (function_info->HasCustomCallGenerator()) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1487 | const int id = function_info->custom_call_generator_id(); |
| 1488 | Object* result = |
| 1489 | CompileCustomCall(id, object, holder, function, name, check); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1490 | // undefined means bail out to regular compiler. |
| 1491 | if (!result->IsUndefined()) { |
| 1492 | return result; |
| 1493 | } |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
sgjesse@chromium.org | 534ae57 | 2010-02-24 22:09:39 +0000 | [diff] [blame] | 1496 | Label miss_in_smi_check; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1497 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1498 | GenerateNameCheck(name, &miss_in_smi_check); |
| 1499 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1500 | // Get the receiver from the stack. |
| 1501 | const int argc = arguments().immediate(); |
| 1502 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1503 | |
| 1504 | // Check that the receiver isn't a smi. |
| 1505 | if (check != NUMBER_CHECK) { |
| 1506 | __ test(edx, Immediate(kSmiTagMask)); |
sgjesse@chromium.org | 534ae57 | 2010-02-24 22:09:39 +0000 | [diff] [blame] | 1507 | __ j(zero, &miss_in_smi_check, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1510 | // Make sure that it's okay not to patch the on stack receiver |
| 1511 | // unless we're doing a receiver map check. |
| 1512 | ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK); |
| 1513 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1514 | CallOptimization optimization(function); |
| 1515 | int depth = kInvalidProtoDepth; |
sgjesse@chromium.org | 534ae57 | 2010-02-24 22:09:39 +0000 | [diff] [blame] | 1516 | Label miss; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1517 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1518 | switch (check) { |
| 1519 | case RECEIVER_MAP_CHECK: |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1520 | __ IncrementCounter(&Counters::call_const, 1); |
| 1521 | |
| 1522 | if (optimization.is_simple_api_call() && !object->IsGlobalObject()) { |
| 1523 | depth = optimization.GetPrototypeDepthOfExpectedType( |
| 1524 | JSObject::cast(object), holder); |
| 1525 | } |
| 1526 | |
| 1527 | if (depth != kInvalidProtoDepth) { |
| 1528 | __ IncrementCounter(&Counters::call_const_fast_api, 1); |
| 1529 | ReserveSpaceForFastApiCall(masm(), eax); |
| 1530 | } |
| 1531 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1532 | // Check that the maps haven't changed. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1533 | CheckPrototypes(JSObject::cast(object), edx, holder, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1534 | ebx, eax, name, depth, &miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1535 | |
| 1536 | // Patch the receiver on the stack with the global proxy if |
| 1537 | // necessary. |
| 1538 | if (object->IsGlobalObject()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1539 | ASSERT(depth == kInvalidProtoDepth); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1540 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1541 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1542 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1543 | break; |
| 1544 | |
| 1545 | case STRING_CHECK: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1546 | if (!function->IsBuiltin()) { |
| 1547 | // Calling non-builtins with a value as receiver requires boxing. |
| 1548 | __ jmp(&miss); |
| 1549 | } else { |
| 1550 | // Check that the object is a string or a symbol. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1551 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1552 | __ j(above_equal, &miss, not_taken); |
| 1553 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1554 | GenerateDirectLoadGlobalFunctionPrototype( |
| 1555 | masm(), Context::STRING_FUNCTION_INDEX, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1556 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
| 1557 | ebx, edx, name, &miss); |
| 1558 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1559 | break; |
| 1560 | |
| 1561 | case NUMBER_CHECK: { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1562 | if (!function->IsBuiltin()) { |
| 1563 | // Calling non-builtins with a value as receiver requires boxing. |
| 1564 | __ jmp(&miss); |
| 1565 | } else { |
| 1566 | Label fast; |
| 1567 | // Check that the object is a smi or a heap number. |
| 1568 | __ test(edx, Immediate(kSmiTagMask)); |
| 1569 | __ j(zero, &fast, taken); |
| 1570 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, eax); |
| 1571 | __ j(not_equal, &miss, not_taken); |
| 1572 | __ bind(&fast); |
| 1573 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1574 | GenerateDirectLoadGlobalFunctionPrototype( |
| 1575 | masm(), Context::NUMBER_FUNCTION_INDEX, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1576 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
| 1577 | ebx, edx, name, &miss); |
| 1578 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1579 | break; |
| 1580 | } |
| 1581 | |
| 1582 | case BOOLEAN_CHECK: { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1583 | if (!function->IsBuiltin()) { |
| 1584 | // Calling non-builtins with a value as receiver requires boxing. |
| 1585 | __ jmp(&miss); |
| 1586 | } else { |
| 1587 | Label fast; |
| 1588 | // Check that the object is a boolean. |
| 1589 | __ cmp(edx, Factory::true_value()); |
| 1590 | __ j(equal, &fast, taken); |
| 1591 | __ cmp(edx, Factory::false_value()); |
| 1592 | __ j(not_equal, &miss, not_taken); |
| 1593 | __ bind(&fast); |
| 1594 | // Check that the maps starting from the prototype haven't changed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1595 | GenerateDirectLoadGlobalFunctionPrototype( |
| 1596 | masm(), Context::BOOLEAN_FUNCTION_INDEX, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1597 | CheckPrototypes(JSObject::cast(object->GetPrototype()), eax, holder, |
| 1598 | ebx, edx, name, &miss); |
| 1599 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1600 | break; |
| 1601 | } |
| 1602 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1603 | default: |
| 1604 | UNREACHABLE(); |
| 1605 | } |
| 1606 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1607 | if (depth != kInvalidProtoDepth) { |
| 1608 | GenerateFastApiCall(masm(), optimization, argc); |
| 1609 | } else { |
| 1610 | __ InvokeFunction(function, arguments(), JUMP_FUNCTION); |
| 1611 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1612 | |
| 1613 | // Handle call cache miss. |
| 1614 | __ bind(&miss); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1615 | if (depth != kInvalidProtoDepth) { |
| 1616 | FreeSpaceForFastApiCall(masm(), eax); |
| 1617 | } |
sgjesse@chromium.org | 534ae57 | 2010-02-24 22:09:39 +0000 | [diff] [blame] | 1618 | __ bind(&miss_in_smi_check); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1619 | GenerateMissBranch(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1620 | |
| 1621 | // Return the generated code. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1622 | return GetCode(function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1626 | Object* CallStubCompiler::CompileCallInterceptor(JSObject* object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1627 | JSObject* holder, |
| 1628 | String* name) { |
| 1629 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1630 | // -- ecx : name |
| 1631 | // -- esp[0] : return address |
| 1632 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1633 | // -- ... |
| 1634 | // -- esp[(argc + 1) * 4] : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1635 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1636 | Label miss; |
| 1637 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1638 | GenerateNameCheck(name, &miss); |
| 1639 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1640 | // Get the number of arguments. |
| 1641 | const int argc = arguments().immediate(); |
| 1642 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1643 | LookupResult lookup; |
| 1644 | LookupPostInterceptor(holder, name, &lookup); |
| 1645 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1646 | // Get the receiver from the stack. |
| 1647 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1648 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1649 | CallInterceptorCompiler compiler(this, arguments(), ecx); |
| 1650 | compiler.Compile(masm(), |
| 1651 | object, |
| 1652 | holder, |
| 1653 | name, |
| 1654 | &lookup, |
| 1655 | edx, |
| 1656 | ebx, |
| 1657 | edi, |
| 1658 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1659 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1660 | // Restore receiver. |
| 1661 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1662 | |
| 1663 | // Check that the function really is a function. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1664 | __ test(eax, Immediate(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1665 | __ j(zero, &miss, not_taken); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1666 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1667 | __ j(not_equal, &miss, not_taken); |
| 1668 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1669 | // Patch the receiver on the stack with the global proxy if |
| 1670 | // necessary. |
| 1671 | if (object->IsGlobalObject()) { |
| 1672 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1673 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1674 | } |
| 1675 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1676 | // Invoke the function. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1677 | __ mov(edi, eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1678 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION); |
| 1679 | |
| 1680 | // Handle load cache miss. |
| 1681 | __ bind(&miss); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1682 | GenerateMissBranch(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1683 | |
| 1684 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1685 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1689 | Object* CallStubCompiler::CompileCallGlobal(JSObject* object, |
| 1690 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1691 | JSGlobalPropertyCell* cell, |
| 1692 | JSFunction* function, |
| 1693 | String* name) { |
| 1694 | // ----------- S t a t e ------------- |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1695 | // -- ecx : name |
| 1696 | // -- esp[0] : return address |
| 1697 | // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1698 | // -- ... |
| 1699 | // -- esp[(argc + 1) * 4] : receiver |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1700 | // ----------------------------------- |
| 1701 | Label miss; |
| 1702 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1703 | GenerateNameCheck(name, &miss); |
| 1704 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1705 | // Get the number of arguments. |
| 1706 | const int argc = arguments().immediate(); |
| 1707 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1708 | // Get the receiver from the stack. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1709 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1710 | |
| 1711 | // If the object is the holder then we know that it's a global |
| 1712 | // object which can only happen for contextual calls. In this case, |
| 1713 | // the receiver cannot be a smi. |
| 1714 | if (object != holder) { |
| 1715 | __ test(edx, Immediate(kSmiTagMask)); |
| 1716 | __ j(zero, &miss, not_taken); |
| 1717 | } |
| 1718 | |
| 1719 | // Check that the maps haven't changed. |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1720 | CheckPrototypes(object, edx, holder, ebx, eax, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1721 | |
| 1722 | // Get the value from the cell. |
| 1723 | __ mov(edi, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1724 | __ mov(edi, FieldOperand(edi, JSGlobalPropertyCell::kValueOffset)); |
| 1725 | |
| 1726 | // Check that the cell contains the same function. |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1727 | if (Heap::InNewSpace(function)) { |
| 1728 | // We can't embed a pointer to a function in new space so we have |
| 1729 | // to verify that the shared function info is unchanged. This has |
| 1730 | // the nice side effect that multiple closures based on the same |
| 1731 | // function can all use this call IC. Before we load through the |
| 1732 | // function, we have to verify that it still is a function. |
| 1733 | __ test(edi, Immediate(kSmiTagMask)); |
| 1734 | __ j(zero, &miss, not_taken); |
| 1735 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ebx); |
| 1736 | __ j(not_equal, &miss, not_taken); |
| 1737 | |
| 1738 | // Check the shared function info. Make sure it hasn't changed. |
| 1739 | __ cmp(FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset), |
| 1740 | Immediate(Handle<SharedFunctionInfo>(function->shared()))); |
| 1741 | __ j(not_equal, &miss, not_taken); |
| 1742 | } else { |
| 1743 | __ cmp(Operand(edi), Immediate(Handle<JSFunction>(function))); |
| 1744 | __ j(not_equal, &miss, not_taken); |
| 1745 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1746 | |
| 1747 | // Patch the receiver on the stack with the global proxy. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1748 | if (object->IsGlobalObject()) { |
| 1749 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1750 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1751 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1752 | |
| 1753 | // Setup the context (function already in edi). |
| 1754 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1755 | |
| 1756 | // Jump to the cached code (tail call). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1757 | __ IncrementCounter(&Counters::call_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1758 | ASSERT(function->is_compiled()); |
| 1759 | Handle<Code> code(function->code()); |
| 1760 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 1761 | __ InvokeCode(code, expected, arguments(), |
| 1762 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
| 1763 | |
| 1764 | // Handle call cache miss. |
| 1765 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1766 | __ IncrementCounter(&Counters::call_global_inline_miss, 1); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame^] | 1767 | GenerateMissBranch(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1768 | |
| 1769 | // Return the generated code. |
| 1770 | return GetCode(NORMAL, name); |
| 1771 | } |
| 1772 | |
| 1773 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1774 | Object* StoreStubCompiler::CompileStoreField(JSObject* object, |
| 1775 | int index, |
| 1776 | Map* transition, |
| 1777 | String* name) { |
| 1778 | // ----------- S t a t e ------------- |
| 1779 | // -- eax : value |
| 1780 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1781 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1782 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1783 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1784 | Label miss; |
| 1785 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1786 | // Generate store field code. Trashes the name register. |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1787 | GenerateStoreField(masm(), |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1788 | object, |
| 1789 | index, |
| 1790 | transition, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1791 | edx, ecx, ebx, |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1792 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1793 | |
| 1794 | // Handle store cache miss. |
| 1795 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1796 | __ mov(ecx, Immediate(Handle<String>(name))); // restore name |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1797 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1798 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1799 | |
| 1800 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1801 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | |
| 1805 | Object* StoreStubCompiler::CompileStoreCallback(JSObject* object, |
| 1806 | AccessorInfo* callback, |
| 1807 | String* name) { |
| 1808 | // ----------- S t a t e ------------- |
| 1809 | // -- eax : value |
| 1810 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1811 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1812 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1813 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1814 | Label miss; |
| 1815 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1816 | // Check that the object isn't a smi. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1817 | __ test(edx, Immediate(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1818 | __ j(zero, &miss, not_taken); |
| 1819 | |
| 1820 | // Check that the map of the object hasn't changed. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1821 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1822 | Immediate(Handle<Map>(object->map()))); |
| 1823 | __ j(not_equal, &miss, not_taken); |
| 1824 | |
| 1825 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1826 | if (object->IsJSGlobalProxy()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1827 | __ CheckAccessGlobalProxy(edx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | // Stub never generated for non-global objects that require access |
| 1831 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1832 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1833 | |
| 1834 | __ pop(ebx); // remove the return address |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1835 | __ push(edx); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1836 | __ push(Immediate(Handle<AccessorInfo>(callback))); // callback info |
| 1837 | __ push(ecx); // name |
| 1838 | __ push(eax); // value |
| 1839 | __ push(ebx); // restore return address |
| 1840 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1841 | // Do tail-call to the runtime system. |
| 1842 | ExternalReference store_callback_property = |
| 1843 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1844 | __ TailCallExternalReference(store_callback_property, 4, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1845 | |
| 1846 | // Handle store cache miss. |
| 1847 | __ bind(&miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1848 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1849 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1850 | |
| 1851 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1852 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | |
| 1856 | Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver, |
| 1857 | String* name) { |
| 1858 | // ----------- S t a t e ------------- |
| 1859 | // -- eax : value |
| 1860 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1861 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1862 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1863 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1864 | Label miss; |
| 1865 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1866 | // Check that the object isn't a smi. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1867 | __ test(edx, Immediate(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1868 | __ j(zero, &miss, not_taken); |
| 1869 | |
| 1870 | // Check that the map of the object hasn't changed. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1871 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1872 | Immediate(Handle<Map>(receiver->map()))); |
| 1873 | __ j(not_equal, &miss, not_taken); |
| 1874 | |
| 1875 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1876 | if (receiver->IsJSGlobalProxy()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1877 | __ CheckAccessGlobalProxy(edx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | // Stub never generated for non-global objects that require access |
| 1881 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1882 | ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1883 | |
| 1884 | __ pop(ebx); // remove the return address |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1885 | __ push(edx); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1886 | __ push(ecx); // name |
| 1887 | __ push(eax); // value |
| 1888 | __ push(ebx); // restore return address |
| 1889 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1890 | // Do tail-call to the runtime system. |
| 1891 | ExternalReference store_ic_property = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1892 | ExternalReference(IC_Utility(IC::kStoreInterceptorProperty)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1893 | __ TailCallExternalReference(store_ic_property, 3, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | |
| 1895 | // Handle store cache miss. |
| 1896 | __ bind(&miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1897 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1898 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1899 | |
| 1900 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1901 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1905 | Object* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object, |
| 1906 | JSGlobalPropertyCell* cell, |
| 1907 | String* name) { |
| 1908 | // ----------- S t a t e ------------- |
| 1909 | // -- eax : value |
| 1910 | // -- ecx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1911 | // -- edx : receiver |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1912 | // -- esp[0] : return address |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1913 | // ----------------------------------- |
| 1914 | Label miss; |
| 1915 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1916 | // Check that the map of the global has not changed. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1917 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1918 | Immediate(Handle<Map>(object->map()))); |
| 1919 | __ j(not_equal, &miss, not_taken); |
| 1920 | |
| 1921 | // Store the value in the cell. |
| 1922 | __ mov(ecx, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1923 | __ mov(FieldOperand(ecx, JSGlobalPropertyCell::kValueOffset), eax); |
| 1924 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1925 | // Return the value (register eax). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1926 | __ IncrementCounter(&Counters::named_store_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1927 | __ ret(0); |
| 1928 | |
| 1929 | // Handle store cache miss. |
| 1930 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1931 | __ IncrementCounter(&Counters::named_store_global_inline_miss, 1); |
| 1932 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
| 1933 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 1934 | |
| 1935 | // Return the generated code. |
| 1936 | return GetCode(NORMAL, name); |
| 1937 | } |
| 1938 | |
| 1939 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1940 | Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object, |
| 1941 | int index, |
| 1942 | Map* transition, |
| 1943 | String* name) { |
| 1944 | // ----------- S t a t e ------------- |
| 1945 | // -- eax : value |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1946 | // -- ecx : key |
| 1947 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1949 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1950 | Label miss; |
| 1951 | |
| 1952 | __ IncrementCounter(&Counters::keyed_store_field, 1); |
| 1953 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1954 | // Check that the name has not changed. |
| 1955 | __ cmp(Operand(ecx), Immediate(Handle<String>(name))); |
| 1956 | __ j(not_equal, &miss, not_taken); |
| 1957 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1958 | // Generate store field code. Trashes the name register. |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1959 | GenerateStoreField(masm(), |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1960 | object, |
| 1961 | index, |
| 1962 | transition, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1963 | edx, ecx, ebx, |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1964 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1965 | |
| 1966 | // Handle store cache miss. |
| 1967 | __ bind(&miss); |
| 1968 | __ DecrementCounter(&Counters::keyed_store_field, 1); |
| 1969 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1970 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1971 | |
| 1972 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1973 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1977 | Object* LoadStubCompiler::CompileLoadNonexistent(String* name, |
| 1978 | JSObject* object, |
| 1979 | JSObject* last) { |
| 1980 | // ----------- S t a t e ------------- |
| 1981 | // -- eax : receiver |
| 1982 | // -- ecx : name |
| 1983 | // -- esp[0] : return address |
| 1984 | // ----------------------------------- |
| 1985 | Label miss; |
| 1986 | |
| 1987 | // Check that the receiver isn't a smi. |
| 1988 | __ test(eax, Immediate(kSmiTagMask)); |
| 1989 | __ j(zero, &miss, not_taken); |
| 1990 | |
| 1991 | // Check the maps of the full prototype chain. Also check that |
| 1992 | // global property cells up to (but not including) the last object |
| 1993 | // in the prototype chain are empty. |
| 1994 | CheckPrototypes(object, eax, last, ebx, edx, name, &miss); |
| 1995 | |
| 1996 | // If the last object in the prototype chain is a global object, |
| 1997 | // check that the global property cell is empty. |
| 1998 | if (last->IsGlobalObject()) { |
| 1999 | Object* cell = GenerateCheckPropertyCell(masm(), |
| 2000 | GlobalObject::cast(last), |
| 2001 | name, |
| 2002 | edx, |
| 2003 | &miss); |
| 2004 | if (cell->IsFailure()) return cell; |
| 2005 | } |
| 2006 | |
| 2007 | // Return undefined if maps of the full prototype chain are still the |
| 2008 | // same and no global property with this name contains a value. |
| 2009 | __ mov(eax, Factory::undefined_value()); |
| 2010 | __ ret(0); |
| 2011 | |
| 2012 | __ bind(&miss); |
| 2013 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2014 | |
| 2015 | // Return the generated code. |
| 2016 | return GetCode(NONEXISTENT, Heap::empty_string()); |
| 2017 | } |
| 2018 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2019 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2020 | Object* LoadStubCompiler::CompileLoadField(JSObject* object, |
| 2021 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2022 | int index, |
| 2023 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2024 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2025 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2026 | // -- ecx : name |
| 2027 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2028 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2029 | Label miss; |
| 2030 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2031 | GenerateLoadField(object, holder, eax, ebx, edx, index, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2032 | __ bind(&miss); |
| 2033 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2034 | |
| 2035 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2036 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2040 | Object* LoadStubCompiler::CompileLoadCallback(String* name, |
| 2041 | JSObject* object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2042 | JSObject* holder, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2043 | AccessorInfo* callback) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2044 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2045 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2046 | // -- ecx : name |
| 2047 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2048 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2049 | Label miss; |
| 2050 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2051 | Failure* failure = Failure::InternalError(); |
| 2052 | bool success = GenerateLoadCallback(object, holder, eax, ecx, ebx, edx, |
| 2053 | callback, name, &miss, &failure); |
| 2054 | if (!success) return failure; |
| 2055 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2056 | __ bind(&miss); |
| 2057 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2058 | |
| 2059 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2060 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | |
| 2064 | Object* LoadStubCompiler::CompileLoadConstant(JSObject* object, |
| 2065 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2066 | Object* value, |
| 2067 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2068 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2069 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2070 | // -- ecx : name |
| 2071 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2072 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2073 | Label miss; |
| 2074 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2075 | GenerateLoadConstant(object, holder, eax, ebx, edx, value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2076 | __ bind(&miss); |
| 2077 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2078 | |
| 2079 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2080 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | |
| 2084 | Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 2085 | JSObject* holder, |
| 2086 | String* name) { |
| 2087 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2088 | // -- eax : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2089 | // -- ecx : name |
| 2090 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2091 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2092 | Label miss; |
| 2093 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2094 | LookupResult lookup; |
| 2095 | LookupPostInterceptor(holder, name, &lookup); |
| 2096 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2097 | // TODO(368): Compile in the whole chain: all the interceptors in |
| 2098 | // prototypes and ultimate answer. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2099 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2100 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2101 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2102 | eax, |
| 2103 | ecx, |
| 2104 | edx, |
| 2105 | ebx, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2106 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2107 | &miss); |
| 2108 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2109 | __ bind(&miss); |
| 2110 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2111 | |
| 2112 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2113 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2117 | Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object, |
| 2118 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2119 | JSGlobalPropertyCell* cell, |
| 2120 | String* name, |
| 2121 | bool is_dont_delete) { |
| 2122 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2123 | // -- eax : receiver |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2124 | // -- ecx : name |
| 2125 | // -- esp[0] : return address |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2126 | // ----------------------------------- |
| 2127 | Label miss; |
| 2128 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2129 | // If the object is the holder then we know that it's a global |
| 2130 | // object which can only happen for contextual loads. In this case, |
| 2131 | // the receiver cannot be a smi. |
| 2132 | if (object != holder) { |
| 2133 | __ test(eax, Immediate(kSmiTagMask)); |
| 2134 | __ j(zero, &miss, not_taken); |
| 2135 | } |
| 2136 | |
| 2137 | // Check that the maps haven't changed. |
| 2138 | CheckPrototypes(object, eax, holder, ebx, edx, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2139 | |
| 2140 | // Get the value from the cell. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2141 | __ mov(ebx, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 2142 | __ mov(ebx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2143 | |
| 2144 | // Check for deleted property if property can actually be deleted. |
| 2145 | if (!is_dont_delete) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2146 | __ cmp(ebx, Factory::the_hole_value()); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2147 | __ j(equal, &miss, not_taken); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2148 | } else if (FLAG_debug_code) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2149 | __ cmp(ebx, Factory::the_hole_value()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2150 | __ Check(not_equal, "DontDelete cells can't contain the hole"); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2153 | __ IncrementCounter(&Counters::named_load_global_inline, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2154 | __ mov(eax, ebx); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2155 | __ ret(0); |
| 2156 | |
| 2157 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2158 | __ IncrementCounter(&Counters::named_load_global_inline_miss, 1); |
| 2159 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 2160 | |
| 2161 | // Return the generated code. |
| 2162 | return GetCode(NORMAL, name); |
| 2163 | } |
| 2164 | |
| 2165 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2166 | Object* KeyedLoadStubCompiler::CompileLoadField(String* name, |
| 2167 | JSObject* receiver, |
| 2168 | JSObject* holder, |
| 2169 | int index) { |
| 2170 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2171 | // -- eax : key |
| 2172 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2173 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2174 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2175 | Label miss; |
| 2176 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2177 | __ IncrementCounter(&Counters::keyed_load_field, 1); |
| 2178 | |
| 2179 | // Check that the name has not changed. |
| 2180 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2181 | __ j(not_equal, &miss, not_taken); |
| 2182 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2183 | GenerateLoadField(receiver, holder, edx, ebx, ecx, index, name, &miss); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2184 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2185 | __ bind(&miss); |
| 2186 | __ DecrementCounter(&Counters::keyed_load_field, 1); |
| 2187 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2188 | |
| 2189 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2190 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | |
| 2194 | Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name, |
| 2195 | JSObject* receiver, |
| 2196 | JSObject* holder, |
| 2197 | AccessorInfo* callback) { |
| 2198 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2199 | // -- eax : key |
| 2200 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2201 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2202 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2203 | Label miss; |
| 2204 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2205 | __ IncrementCounter(&Counters::keyed_load_callback, 1); |
| 2206 | |
| 2207 | // Check that the name has not changed. |
| 2208 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2209 | __ j(not_equal, &miss, not_taken); |
| 2210 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2211 | Failure* failure = Failure::InternalError(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2212 | bool success = GenerateLoadCallback(receiver, holder, edx, eax, ebx, ecx, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2213 | callback, name, &miss, &failure); |
| 2214 | if (!success) return failure; |
| 2215 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2216 | __ bind(&miss); |
| 2217 | __ DecrementCounter(&Counters::keyed_load_callback, 1); |
| 2218 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2219 | |
| 2220 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2221 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | |
| 2225 | Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name, |
| 2226 | JSObject* receiver, |
| 2227 | JSObject* holder, |
| 2228 | Object* value) { |
| 2229 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2230 | // -- eax : key |
| 2231 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2232 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2233 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2234 | Label miss; |
| 2235 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2236 | __ IncrementCounter(&Counters::keyed_load_constant_function, 1); |
| 2237 | |
| 2238 | // Check that the name has not changed. |
| 2239 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2240 | __ j(not_equal, &miss, not_taken); |
| 2241 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2242 | GenerateLoadConstant(receiver, holder, edx, ebx, ecx, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2243 | value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2244 | __ bind(&miss); |
| 2245 | __ DecrementCounter(&Counters::keyed_load_constant_function, 1); |
| 2246 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2247 | |
| 2248 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2249 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | |
| 2253 | Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 2254 | JSObject* holder, |
| 2255 | String* name) { |
| 2256 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2257 | // -- eax : key |
| 2258 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2259 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2260 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2261 | Label miss; |
| 2262 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2263 | __ IncrementCounter(&Counters::keyed_load_interceptor, 1); |
| 2264 | |
| 2265 | // Check that the name has not changed. |
| 2266 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2267 | __ j(not_equal, &miss, not_taken); |
| 2268 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2269 | LookupResult lookup; |
| 2270 | LookupPostInterceptor(holder, name, &lookup); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2271 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2272 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2273 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2274 | edx, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2275 | eax, |
| 2276 | ecx, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2277 | ebx, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2278 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2279 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2280 | __ bind(&miss); |
| 2281 | __ DecrementCounter(&Counters::keyed_load_interceptor, 1); |
| 2282 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2283 | |
| 2284 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2285 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) { |
| 2292 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2293 | // -- eax : key |
| 2294 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2295 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2296 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2297 | Label miss; |
| 2298 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2299 | __ IncrementCounter(&Counters::keyed_load_array_length, 1); |
| 2300 | |
| 2301 | // Check that the name has not changed. |
| 2302 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2303 | __ j(not_equal, &miss, not_taken); |
| 2304 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2305 | GenerateLoadArrayLength(masm(), edx, ecx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2306 | __ bind(&miss); |
| 2307 | __ DecrementCounter(&Counters::keyed_load_array_length, 1); |
| 2308 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2309 | |
| 2310 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2311 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2315 | Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2316 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2317 | // -- eax : key |
| 2318 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2319 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2320 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2321 | Label miss; |
| 2322 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2323 | __ IncrementCounter(&Counters::keyed_load_string_length, 1); |
| 2324 | |
| 2325 | // Check that the name has not changed. |
| 2326 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2327 | __ j(not_equal, &miss, not_taken); |
| 2328 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2329 | GenerateLoadStringLength(masm(), edx, ecx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2330 | __ bind(&miss); |
| 2331 | __ DecrementCounter(&Counters::keyed_load_string_length, 1); |
| 2332 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2333 | |
| 2334 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2335 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | |
| 2339 | Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) { |
| 2340 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2341 | // -- eax : key |
| 2342 | // -- edx : receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2343 | // -- esp[0] : return address |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2344 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2345 | Label miss; |
| 2346 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2347 | __ IncrementCounter(&Counters::keyed_load_function_prototype, 1); |
| 2348 | |
| 2349 | // Check that the name has not changed. |
| 2350 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 2351 | __ j(not_equal, &miss, not_taken); |
| 2352 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2353 | GenerateLoadFunctionPrototype(masm(), edx, ecx, ebx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2354 | __ bind(&miss); |
| 2355 | __ DecrementCounter(&Counters::keyed_load_function_prototype, 1); |
| 2356 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 2357 | |
| 2358 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2359 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2363 | // Specialized stub for constructing objects from functions which only have only |
| 2364 | // simple assignments of the form this.x = ...; in their body. |
| 2365 | Object* ConstructStubCompiler::CompileConstructStub( |
| 2366 | SharedFunctionInfo* shared) { |
| 2367 | // ----------- S t a t e ------------- |
| 2368 | // -- eax : argc |
| 2369 | // -- edi : constructor |
| 2370 | // -- esp[0] : return address |
| 2371 | // -- esp[4] : last argument |
| 2372 | // ----------------------------------- |
| 2373 | Label generic_stub_call; |
| 2374 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 2375 | // Check to see whether there are any break points in the function code. If |
| 2376 | // there are jump to the generic constructor stub which calls the actual |
| 2377 | // code for the function thereby hitting the break points. |
| 2378 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2379 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kDebugInfoOffset)); |
| 2380 | __ cmp(ebx, Factory::undefined_value()); |
| 2381 | __ j(not_equal, &generic_stub_call, not_taken); |
| 2382 | #endif |
| 2383 | |
| 2384 | // Load the initial map and verify that it is in fact a map. |
| 2385 | __ mov(ebx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2386 | // Will both indicate a NULL and a Smi. |
| 2387 | __ test(ebx, Immediate(kSmiTagMask)); |
| 2388 | __ j(zero, &generic_stub_call); |
| 2389 | __ CmpObjectType(ebx, MAP_TYPE, ecx); |
| 2390 | __ j(not_equal, &generic_stub_call); |
| 2391 | |
| 2392 | #ifdef DEBUG |
| 2393 | // Cannot construct functions this way. |
| 2394 | // edi: constructor |
| 2395 | // ebx: initial map |
| 2396 | __ CmpInstanceType(ebx, JS_FUNCTION_TYPE); |
| 2397 | __ Assert(not_equal, "Function constructed by construct stub."); |
| 2398 | #endif |
| 2399 | |
| 2400 | // Now allocate the JSObject on the heap by moving the new space allocation |
| 2401 | // top forward. |
| 2402 | // edi: constructor |
| 2403 | // ebx: initial map |
| 2404 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceSizeOffset)); |
| 2405 | __ shl(ecx, kPointerSizeLog2); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2406 | __ AllocateInNewSpace(ecx, |
| 2407 | edx, |
| 2408 | ecx, |
| 2409 | no_reg, |
| 2410 | &generic_stub_call, |
| 2411 | NO_ALLOCATION_FLAGS); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2412 | |
| 2413 | // Allocated the JSObject, now initialize the fields and add the heap tag. |
| 2414 | // ebx: initial map |
| 2415 | // edx: JSObject (untagged) |
| 2416 | __ mov(Operand(edx, JSObject::kMapOffset), ebx); |
| 2417 | __ mov(ebx, Factory::empty_fixed_array()); |
| 2418 | __ mov(Operand(edx, JSObject::kPropertiesOffset), ebx); |
| 2419 | __ mov(Operand(edx, JSObject::kElementsOffset), ebx); |
| 2420 | |
| 2421 | // Push the allocated object to the stack. This is the object that will be |
| 2422 | // returned (after it is tagged). |
| 2423 | __ push(edx); |
| 2424 | |
| 2425 | // eax: argc |
| 2426 | // edx: JSObject (untagged) |
| 2427 | // Load the address of the first in-object property into edx. |
| 2428 | __ lea(edx, Operand(edx, JSObject::kHeaderSize)); |
| 2429 | // Calculate the location of the first argument. The stack contains the |
| 2430 | // allocated object and the return address on top of the argc arguments. |
| 2431 | __ lea(ecx, Operand(esp, eax, times_4, 1 * kPointerSize)); |
| 2432 | |
| 2433 | // Use edi for holding undefined which is used in several places below. |
| 2434 | __ mov(edi, Factory::undefined_value()); |
| 2435 | |
| 2436 | // eax: argc |
| 2437 | // ecx: first argument |
| 2438 | // edx: first in-object property of the JSObject |
| 2439 | // edi: undefined |
| 2440 | // Fill the initialized properties with a constant value or a passed argument |
| 2441 | // depending on the this.x = ...; assignment in the function. |
| 2442 | for (int i = 0; i < shared->this_property_assignments_count(); i++) { |
| 2443 | if (shared->IsThisPropertyAssignmentArgument(i)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2444 | // Check if the argument assigned to the property is actually passed. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2445 | // If argument is not passed the property is set to undefined, |
| 2446 | // otherwise find it on the stack. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2447 | int arg_number = shared->GetThisPropertyAssignmentArgument(i); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2448 | __ mov(ebx, edi); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2449 | __ cmp(eax, arg_number); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2450 | if (CpuFeatures::IsSupported(CMOV)) { |
| 2451 | CpuFeatures::Scope use_cmov(CMOV); |
| 2452 | __ cmov(above, ebx, Operand(ecx, arg_number * -kPointerSize)); |
| 2453 | } else { |
| 2454 | Label not_passed; |
| 2455 | __ j(below_equal, ¬_passed); |
| 2456 | __ mov(ebx, Operand(ecx, arg_number * -kPointerSize)); |
| 2457 | __ bind(¬_passed); |
| 2458 | } |
| 2459 | // Store value in the property. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2460 | __ mov(Operand(edx, i * kPointerSize), ebx); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2461 | } else { |
| 2462 | // Set the property to the constant value. |
| 2463 | Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i)); |
| 2464 | __ mov(Operand(edx, i * kPointerSize), Immediate(constant)); |
| 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | // Fill the unused in-object property fields with undefined. |
| 2469 | for (int i = shared->this_property_assignments_count(); |
| 2470 | i < shared->CalculateInObjectProperties(); |
| 2471 | i++) { |
| 2472 | __ mov(Operand(edx, i * kPointerSize), edi); |
| 2473 | } |
| 2474 | |
| 2475 | // Move argc to ebx and retrieve and tag the JSObject to return. |
| 2476 | __ mov(ebx, eax); |
| 2477 | __ pop(eax); |
| 2478 | __ or_(Operand(eax), Immediate(kHeapObjectTag)); |
| 2479 | |
| 2480 | // Remove caller arguments and receiver from the stack and return. |
| 2481 | __ pop(ecx); |
| 2482 | __ lea(esp, Operand(esp, ebx, times_pointer_size, 1 * kPointerSize)); |
| 2483 | __ push(ecx); |
| 2484 | __ IncrementCounter(&Counters::constructed_objects, 1); |
| 2485 | __ IncrementCounter(&Counters::constructed_objects_stub, 1); |
| 2486 | __ ret(0); |
| 2487 | |
| 2488 | // Jump to the generic stub in case the specialized code cannot handle the |
| 2489 | // construction. |
| 2490 | __ bind(&generic_stub_call); |
| 2491 | Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); |
| 2492 | Handle<Code> generic_construct_stub(code); |
| 2493 | __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 2494 | |
| 2495 | // Return the generated code. |
| 2496 | return GetCode(); |
| 2497 | } |
| 2498 | |
| 2499 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2500 | #undef __ |
| 2501 | |
| 2502 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2503 | |
| 2504 | #endif // V8_TARGET_ARCH_IA32 |