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