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