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