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