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