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. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 129 | __ mov(scratch, FieldOperand(name, String::kLengthOffset)); |
| 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. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 138 | __ mov(scratch, FieldOperand(name, String::kLengthOffset)); |
| 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 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 155 | template <typename Pushable> |
| 156 | static void PushInterceptorArguments(MacroAssembler* masm, |
| 157 | Register receiver, |
| 158 | Register holder, |
| 159 | Pushable name, |
| 160 | JSObject* holder_obj) { |
| 161 | __ push(receiver); |
| 162 | __ push(holder); |
| 163 | __ push(name); |
| 164 | InterceptorInfo* interceptor = holder_obj->GetNamedInterceptor(); |
| 165 | __ mov(receiver, Immediate(Handle<Object>(interceptor))); |
| 166 | __ push(receiver); |
| 167 | __ push(FieldOperand(receiver, InterceptorInfo::kDataOffset)); |
| 168 | } |
| 169 | |
| 170 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 171 | void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, |
| 172 | int index, |
| 173 | Register prototype) { |
| 174 | // Load the global or builtins object from the current context. |
| 175 | __ mov(prototype, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 176 | // Load the global context from the global or builtins object. |
| 177 | __ mov(prototype, |
| 178 | FieldOperand(prototype, GlobalObject::kGlobalContextOffset)); |
| 179 | // Load the function from the global context. |
| 180 | __ mov(prototype, Operand(prototype, Context::SlotOffset(index))); |
| 181 | // Load the initial map. The global functions all have initial maps. |
| 182 | __ mov(prototype, |
| 183 | FieldOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset)); |
| 184 | // Load the prototype from the initial map. |
| 185 | __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset)); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm, |
| 190 | Register receiver, |
| 191 | Register scratch, |
| 192 | Label* miss_label) { |
| 193 | // Check that the receiver isn't a smi. |
| 194 | __ test(receiver, Immediate(kSmiTagMask)); |
| 195 | __ j(zero, miss_label, not_taken); |
| 196 | |
| 197 | // Check that the object is a JS array. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 198 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | __ j(not_equal, miss_label, not_taken); |
| 200 | |
| 201 | // Load length directly from the JS array. |
| 202 | __ mov(eax, FieldOperand(receiver, JSArray::kLengthOffset)); |
| 203 | __ ret(0); |
| 204 | } |
| 205 | |
| 206 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 207 | // Generate code to check if an object is a string. If the object is |
| 208 | // a string, the map's instance type is left in the scratch register. |
| 209 | static void GenerateStringCheck(MacroAssembler* masm, |
| 210 | Register receiver, |
| 211 | Register scratch, |
| 212 | Label* smi, |
| 213 | Label* non_string_object) { |
| 214 | // Check that the object isn't a smi. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | __ test(receiver, Immediate(kSmiTagMask)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 216 | __ j(zero, smi, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 217 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 218 | // Check that the object is a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | __ mov(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 220 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 221 | ASSERT(kNotStringTag != 0); |
| 222 | __ test(scratch, Immediate(kNotStringTag)); |
| 223 | __ j(not_zero, non_string_object, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 227 | void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm, |
| 228 | Register receiver, |
| 229 | Register scratch, |
| 230 | Label* miss) { |
| 231 | Label load_length, check_wrapper; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 233 | // Check if the object is a string leaving the instance type in the |
| 234 | // scratch register. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 235 | GenerateStringCheck(masm, receiver, scratch, miss, &check_wrapper); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 236 | |
| 237 | // Load length directly from the string. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 238 | __ bind(&load_length); |
| 239 | __ and_(scratch, kStringSizeMask); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | __ mov(eax, FieldOperand(receiver, String::kLengthOffset)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 241 | // ecx is also the receiver. |
| 242 | __ lea(ecx, Operand(scratch, String::kLongLengthShift)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame^] | 243 | __ shr_cl(eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | __ shl(eax, kSmiTagSize); |
| 245 | __ ret(0); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 246 | |
| 247 | // Check if the object is a JSValue wrapper. |
| 248 | __ bind(&check_wrapper); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 249 | __ cmp(scratch, JS_VALUE_TYPE); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 250 | __ j(not_equal, miss, not_taken); |
| 251 | |
| 252 | // Check if the wrapped value is a string and load the length |
| 253 | // directly if it is. |
| 254 | __ mov(receiver, FieldOperand(receiver, JSValue::kValueOffset)); |
| 255 | GenerateStringCheck(masm, receiver, scratch, miss, miss); |
| 256 | __ jmp(&load_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | |
| 260 | void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm, |
| 261 | Register receiver, |
| 262 | Register scratch1, |
| 263 | Register scratch2, |
| 264 | Label* miss_label) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 265 | __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 266 | __ mov(eax, Operand(scratch1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | __ ret(0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 268 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 270 | |
| 271 | // Load a fast property out of a holder object (src). In-object properties |
| 272 | // are loaded directly otherwise the property is loaded from the properties |
| 273 | // fixed array. |
| 274 | void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 275 | Register dst, Register src, |
| 276 | JSObject* holder, int index) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 277 | // Adjust for the number of properties stored in the holder. |
| 278 | index -= holder->map()->inobject_properties(); |
| 279 | if (index < 0) { |
| 280 | // Get the property straight out of the holder. |
| 281 | int offset = holder->map()->instance_size() + (index * kPointerSize); |
| 282 | __ mov(dst, FieldOperand(src, offset)); |
| 283 | } else { |
| 284 | // Calculate the offset into the properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 285 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 286 | __ mov(dst, FieldOperand(src, JSObject::kPropertiesOffset)); |
| 287 | __ mov(dst, FieldOperand(dst, offset)); |
| 288 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 292 | template <class Pushable> |
| 293 | static void CompileCallLoadPropertyWithInterceptor(MacroAssembler* masm, |
| 294 | Register receiver, |
| 295 | Register holder, |
| 296 | Pushable name, |
| 297 | JSObject* holder_obj) { |
| 298 | PushInterceptorArguments(masm, receiver, holder, name, holder_obj); |
| 299 | |
| 300 | ExternalReference ref = |
| 301 | ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly)); |
| 302 | __ mov(eax, Immediate(5)); |
| 303 | __ mov(ebx, Immediate(ref)); |
| 304 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 305 | CEntryStub stub(1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 306 | __ CallStub(&stub); |
| 307 | } |
| 308 | |
| 309 | |
| 310 | template <class Compiler> |
| 311 | static void CompileLoadInterceptor(Compiler* compiler, |
| 312 | StubCompiler* stub_compiler, |
| 313 | MacroAssembler* masm, |
| 314 | JSObject* object, |
| 315 | JSObject* holder, |
| 316 | String* name, |
| 317 | LookupResult* lookup, |
| 318 | Register receiver, |
| 319 | Register scratch1, |
| 320 | Register scratch2, |
| 321 | Label* miss) { |
| 322 | ASSERT(holder->HasNamedInterceptor()); |
| 323 | ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 324 | |
| 325 | // Check that the receiver isn't a smi. |
| 326 | __ test(receiver, Immediate(kSmiTagMask)); |
| 327 | __ j(zero, miss, not_taken); |
| 328 | |
| 329 | // Check that the maps haven't changed. |
| 330 | Register reg = |
| 331 | stub_compiler->CheckPrototypes(object, receiver, holder, |
| 332 | scratch1, scratch2, name, miss); |
| 333 | |
| 334 | if (lookup->IsValid() && lookup->IsCacheable()) { |
| 335 | compiler->CompileCacheable(masm, |
| 336 | stub_compiler, |
| 337 | receiver, |
| 338 | reg, |
| 339 | scratch1, |
| 340 | scratch2, |
| 341 | holder, |
| 342 | lookup, |
| 343 | name, |
| 344 | miss); |
| 345 | } else { |
| 346 | compiler->CompileRegular(masm, |
| 347 | receiver, |
| 348 | reg, |
| 349 | scratch2, |
| 350 | holder, |
| 351 | miss); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | |
| 356 | static void LookupPostInterceptor(JSObject* holder, |
| 357 | String* name, |
| 358 | LookupResult* lookup) { |
| 359 | holder->LocalLookupRealNamedProperty(name, lookup); |
| 360 | if (lookup->IsNotFound()) { |
| 361 | Object* proto = holder->GetPrototype(); |
| 362 | if (proto != Heap::null_value()) { |
| 363 | proto->Lookup(name, lookup); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | |
| 369 | class LoadInterceptorCompiler BASE_EMBEDDED { |
| 370 | public: |
| 371 | explicit LoadInterceptorCompiler(Register name) : name_(name) {} |
| 372 | |
| 373 | void CompileCacheable(MacroAssembler* masm, |
| 374 | StubCompiler* stub_compiler, |
| 375 | Register receiver, |
| 376 | Register holder, |
| 377 | Register scratch1, |
| 378 | Register scratch2, |
| 379 | JSObject* holder_obj, |
| 380 | LookupResult* lookup, |
| 381 | String* name, |
| 382 | Label* miss_label) { |
| 383 | AccessorInfo* callback = 0; |
| 384 | bool optimize = false; |
| 385 | // So far the most popular follow ups for interceptor loads are FIELD |
| 386 | // and CALLBACKS, so inline only them, other cases may be added |
| 387 | // later. |
| 388 | if (lookup->type() == FIELD) { |
| 389 | optimize = true; |
| 390 | } else if (lookup->type() == CALLBACKS) { |
| 391 | Object* callback_object = lookup->GetCallbackObject(); |
| 392 | if (callback_object->IsAccessorInfo()) { |
| 393 | callback = AccessorInfo::cast(callback_object); |
| 394 | optimize = callback->getter() != NULL; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | if (!optimize) { |
| 399 | CompileRegular(masm, receiver, holder, scratch2, holder_obj, miss_label); |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | // Note: starting a frame here makes GC aware of pointers pushed below. |
| 404 | __ EnterInternalFrame(); |
| 405 | |
| 406 | if (lookup->type() == CALLBACKS) { |
| 407 | __ push(receiver); |
| 408 | } |
| 409 | __ push(holder); |
| 410 | __ push(name_); |
| 411 | |
| 412 | CompileCallLoadPropertyWithInterceptor(masm, |
| 413 | receiver, |
| 414 | holder, |
| 415 | name_, |
| 416 | holder_obj); |
| 417 | |
| 418 | Label interceptor_failed; |
| 419 | __ cmp(eax, Factory::no_interceptor_result_sentinel()); |
| 420 | __ j(equal, &interceptor_failed); |
| 421 | __ LeaveInternalFrame(); |
| 422 | __ ret(0); |
| 423 | |
| 424 | __ bind(&interceptor_failed); |
| 425 | __ pop(name_); |
| 426 | __ pop(holder); |
| 427 | if (lookup->type() == CALLBACKS) { |
| 428 | __ pop(receiver); |
| 429 | } |
| 430 | |
| 431 | __ LeaveInternalFrame(); |
| 432 | |
| 433 | if (lookup->type() == FIELD) { |
| 434 | holder = stub_compiler->CheckPrototypes(holder_obj, holder, |
| 435 | lookup->holder(), scratch1, |
| 436 | scratch2, |
| 437 | name, |
| 438 | miss_label); |
| 439 | stub_compiler->GenerateFastPropertyLoad(masm, eax, |
| 440 | holder, lookup->holder(), |
| 441 | lookup->GetFieldIndex()); |
| 442 | __ ret(0); |
| 443 | } else { |
| 444 | ASSERT(lookup->type() == CALLBACKS); |
| 445 | ASSERT(lookup->GetCallbackObject()->IsAccessorInfo()); |
| 446 | ASSERT(callback != NULL); |
| 447 | ASSERT(callback->getter() != NULL); |
| 448 | |
| 449 | Label cleanup; |
| 450 | __ pop(scratch2); |
| 451 | __ push(receiver); |
| 452 | __ push(scratch2); |
| 453 | |
| 454 | holder = stub_compiler->CheckPrototypes(holder_obj, holder, |
| 455 | lookup->holder(), scratch1, |
| 456 | scratch2, |
| 457 | name, |
| 458 | &cleanup); |
| 459 | |
| 460 | __ pop(scratch2); // save old return address |
| 461 | __ push(holder); |
| 462 | __ mov(holder, Immediate(Handle<AccessorInfo>(callback))); |
| 463 | __ push(holder); |
| 464 | __ push(FieldOperand(holder, AccessorInfo::kDataOffset)); |
| 465 | __ push(name_); |
| 466 | __ push(scratch2); // restore old return address |
| 467 | |
| 468 | ExternalReference ref = |
| 469 | ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 470 | __ TailCallRuntime(ref, 5, 1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 471 | |
| 472 | __ bind(&cleanup); |
| 473 | __ pop(scratch1); |
| 474 | __ pop(scratch2); |
| 475 | __ push(scratch1); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | |
| 480 | void CompileRegular(MacroAssembler* masm, |
| 481 | Register receiver, |
| 482 | Register holder, |
| 483 | Register scratch, |
| 484 | JSObject* holder_obj, |
| 485 | Label* miss_label) { |
| 486 | __ pop(scratch); // save old return address |
| 487 | PushInterceptorArguments(masm, receiver, holder, name_, holder_obj); |
| 488 | __ push(scratch); // restore old return address |
| 489 | |
| 490 | ExternalReference ref = ExternalReference( |
| 491 | IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 492 | __ TailCallRuntime(ref, 5, 1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | private: |
| 496 | Register name_; |
| 497 | }; |
| 498 | |
| 499 | |
| 500 | class CallInterceptorCompiler BASE_EMBEDDED { |
| 501 | public: |
| 502 | explicit CallInterceptorCompiler(const ParameterCount& arguments) |
| 503 | : arguments_(arguments), argc_(arguments.immediate()) {} |
| 504 | |
| 505 | void CompileCacheable(MacroAssembler* masm, |
| 506 | StubCompiler* stub_compiler, |
| 507 | Register receiver, |
| 508 | Register holder, |
| 509 | Register scratch1, |
| 510 | Register scratch2, |
| 511 | JSObject* holder_obj, |
| 512 | LookupResult* lookup, |
| 513 | String* name, |
| 514 | Label* miss_label) { |
| 515 | JSFunction* function = 0; |
| 516 | bool optimize = false; |
| 517 | // So far the most popular case for failed interceptor is |
| 518 | // CONSTANT_FUNCTION sitting below. |
| 519 | if (lookup->type() == CONSTANT_FUNCTION) { |
| 520 | function = lookup->GetConstantFunction(); |
| 521 | // JSArray holder is a special case for call constant function |
| 522 | // (see the corresponding code). |
| 523 | if (function->is_compiled() && !holder_obj->IsJSArray()) { |
| 524 | optimize = true; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | if (!optimize) { |
| 529 | CompileRegular(masm, receiver, holder, scratch2, holder_obj, miss_label); |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | __ EnterInternalFrame(); |
| 534 | __ push(holder); // save the holder |
| 535 | |
| 536 | CompileCallLoadPropertyWithInterceptor( |
| 537 | masm, |
| 538 | receiver, |
| 539 | holder, |
| 540 | // Under EnterInternalFrame this refers to name. |
| 541 | Operand(ebp, (argc_ + 3) * kPointerSize), |
| 542 | holder_obj); |
| 543 | |
| 544 | __ pop(receiver); // restore holder |
| 545 | __ LeaveInternalFrame(); |
| 546 | |
| 547 | __ cmp(eax, Factory::no_interceptor_result_sentinel()); |
| 548 | Label invoke; |
| 549 | __ j(not_equal, &invoke); |
| 550 | |
| 551 | stub_compiler->CheckPrototypes(holder_obj, receiver, |
| 552 | lookup->holder(), scratch1, |
| 553 | scratch2, |
| 554 | name, |
| 555 | miss_label); |
| 556 | if (lookup->holder()->IsGlobalObject()) { |
| 557 | __ mov(edx, Operand(esp, (argc_ + 1) * kPointerSize)); |
| 558 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 559 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edx); |
| 560 | } |
| 561 | |
| 562 | ASSERT(function->is_compiled()); |
| 563 | // Get the function and setup the context. |
| 564 | __ mov(edi, Immediate(Handle<JSFunction>(function))); |
| 565 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 566 | |
| 567 | // Jump to the cached code (tail call). |
| 568 | ASSERT(function->is_compiled()); |
| 569 | Handle<Code> code(function->code()); |
| 570 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 571 | __ InvokeCode(code, expected, arguments_, |
| 572 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
| 573 | |
| 574 | __ bind(&invoke); |
| 575 | } |
| 576 | |
| 577 | void CompileRegular(MacroAssembler* masm, |
| 578 | Register receiver, |
| 579 | Register holder, |
| 580 | Register scratch, |
| 581 | JSObject* holder_obj, |
| 582 | Label* miss_label) { |
| 583 | __ EnterInternalFrame(); |
| 584 | |
| 585 | PushInterceptorArguments(masm, |
| 586 | receiver, |
| 587 | holder, |
| 588 | Operand(ebp, (argc_ + 3) * kPointerSize), |
| 589 | holder_obj); |
| 590 | |
| 591 | ExternalReference ref = ExternalReference( |
| 592 | IC_Utility(IC::kLoadPropertyWithInterceptorForCall)); |
| 593 | __ mov(eax, Immediate(5)); |
| 594 | __ mov(ebx, Immediate(ref)); |
| 595 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 596 | CEntryStub stub(1); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 597 | __ CallStub(&stub); |
| 598 | |
| 599 | __ LeaveInternalFrame(); |
| 600 | } |
| 601 | |
| 602 | private: |
| 603 | const ParameterCount& arguments_; |
| 604 | int argc_; |
| 605 | }; |
| 606 | |
| 607 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 608 | void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) { |
| 609 | ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC); |
| 610 | Code* code = NULL; |
| 611 | if (kind == Code::LOAD_IC) { |
| 612 | code = Builtins::builtin(Builtins::LoadIC_Miss); |
| 613 | } else { |
| 614 | code = Builtins::builtin(Builtins::KeyedLoadIC_Miss); |
| 615 | } |
| 616 | |
| 617 | Handle<Code> ic(code); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 618 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | |
| 622 | void StubCompiler::GenerateStoreField(MacroAssembler* masm, |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 623 | Builtins::Name storage_extend, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 624 | JSObject* object, |
| 625 | int index, |
| 626 | Map* transition, |
| 627 | Register receiver_reg, |
| 628 | Register name_reg, |
| 629 | Register scratch, |
| 630 | Label* miss_label) { |
| 631 | // Check that the object isn't a smi. |
| 632 | __ test(receiver_reg, Immediate(kSmiTagMask)); |
| 633 | __ j(zero, miss_label, not_taken); |
| 634 | |
| 635 | // Check that the map of the object hasn't changed. |
| 636 | __ cmp(FieldOperand(receiver_reg, HeapObject::kMapOffset), |
| 637 | Immediate(Handle<Map>(object->map()))); |
| 638 | __ j(not_equal, miss_label, not_taken); |
| 639 | |
| 640 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 641 | if (object->IsJSGlobalProxy()) { |
| 642 | __ CheckAccessGlobalProxy(receiver_reg, scratch, miss_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | // Stub never generated for non-global objects that require access |
| 646 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 647 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 648 | |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 649 | // Perform map transition for the receiver if necessary. |
| 650 | if ((transition != NULL) && (object->map()->unused_property_fields() == 0)) { |
| 651 | // The properties must be extended before we can store the value. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 652 | // We jump to a runtime call that extends the properties array. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 653 | __ mov(ecx, Immediate(Handle<Map>(transition))); |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 654 | Handle<Code> ic(Builtins::builtin(storage_extend)); |
| 655 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 656 | return; |
| 657 | } |
| 658 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 659 | if (transition != NULL) { |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 660 | // Update the map of the object; no write barrier updating is |
| 661 | // needed because the map is never in new space. |
| 662 | __ mov(FieldOperand(receiver_reg, HeapObject::kMapOffset), |
| 663 | Immediate(Handle<Map>(transition))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 664 | } |
| 665 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 666 | // Adjust for the number of properties stored in the object. Even in the |
| 667 | // face of a transition we can use the old map here because the size of the |
| 668 | // object and the number of in-object properties is not going to change. |
| 669 | index -= object->map()->inobject_properties(); |
| 670 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 671 | if (index < 0) { |
| 672 | // Set the property straight into the object. |
| 673 | int offset = object->map()->instance_size() + (index * kPointerSize); |
| 674 | __ mov(FieldOperand(receiver_reg, offset), eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 675 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 676 | // Update the write barrier for the array address. |
| 677 | // Pass the value being stored in the now unused name_reg. |
| 678 | __ mov(name_reg, Operand(eax)); |
| 679 | __ RecordWrite(receiver_reg, offset, name_reg, scratch); |
| 680 | } else { |
| 681 | // Write to the properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 682 | int offset = index * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 683 | // Get the properties array (optimistically). |
| 684 | __ mov(scratch, FieldOperand(receiver_reg, JSObject::kPropertiesOffset)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 685 | __ mov(FieldOperand(scratch, offset), eax); |
| 686 | |
| 687 | // Update the write barrier for the array address. |
| 688 | // Pass the value being stored in the now unused name_reg. |
| 689 | __ mov(name_reg, Operand(eax)); |
| 690 | __ RecordWrite(scratch, offset, name_reg, receiver_reg); |
| 691 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 692 | |
| 693 | // Return the value (register eax). |
| 694 | __ ret(0); |
| 695 | } |
| 696 | |
| 697 | |
| 698 | #undef __ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 699 | #define __ ACCESS_MASM(masm()) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 700 | |
| 701 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 702 | Register StubCompiler::CheckPrototypes(JSObject* object, |
| 703 | Register object_reg, |
| 704 | JSObject* holder, |
| 705 | Register holder_reg, |
| 706 | Register scratch, |
| 707 | String* name, |
| 708 | Label* miss) { |
| 709 | // Check that the maps haven't changed. |
| 710 | Register result = |
| 711 | masm()->CheckMaps(object, object_reg, holder, holder_reg, scratch, miss); |
| 712 | |
| 713 | // If we've skipped any global objects, it's not enough to verify |
| 714 | // that their maps haven't changed. |
| 715 | while (object != holder) { |
| 716 | if (object->IsGlobalObject()) { |
| 717 | GlobalObject* global = GlobalObject::cast(object); |
| 718 | Object* probe = global->EnsurePropertyCell(name); |
| 719 | if (probe->IsFailure()) { |
| 720 | set_failure(Failure::cast(probe)); |
| 721 | return result; |
| 722 | } |
| 723 | JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(probe); |
| 724 | ASSERT(cell->value()->IsTheHole()); |
| 725 | __ mov(scratch, Immediate(Handle<Object>(cell))); |
| 726 | __ cmp(FieldOperand(scratch, JSGlobalPropertyCell::kValueOffset), |
| 727 | Immediate(Factory::the_hole_value())); |
| 728 | __ j(not_equal, miss, not_taken); |
| 729 | } |
| 730 | object = JSObject::cast(object->GetPrototype()); |
| 731 | } |
| 732 | |
| 733 | // Return the register containin the holder. |
| 734 | return result; |
| 735 | } |
| 736 | |
| 737 | |
| 738 | void StubCompiler::GenerateLoadField(JSObject* object, |
| 739 | JSObject* holder, |
| 740 | Register receiver, |
| 741 | Register scratch1, |
| 742 | Register scratch2, |
| 743 | int index, |
| 744 | String* name, |
| 745 | Label* miss) { |
| 746 | // Check that the receiver isn't a smi. |
| 747 | __ test(receiver, Immediate(kSmiTagMask)); |
| 748 | __ j(zero, miss, not_taken); |
| 749 | |
| 750 | // Check the prototype chain. |
| 751 | Register reg = |
| 752 | CheckPrototypes(object, receiver, holder, |
| 753 | scratch1, scratch2, name, miss); |
| 754 | |
| 755 | // Get the value from the properties. |
| 756 | GenerateFastPropertyLoad(masm(), eax, reg, holder, index); |
| 757 | __ ret(0); |
| 758 | } |
| 759 | |
| 760 | |
| 761 | void StubCompiler::GenerateLoadCallback(JSObject* object, |
| 762 | JSObject* holder, |
| 763 | Register receiver, |
| 764 | Register name_reg, |
| 765 | Register scratch1, |
| 766 | Register scratch2, |
| 767 | AccessorInfo* callback, |
| 768 | String* name, |
| 769 | Label* miss) { |
| 770 | // Check that the receiver isn't a smi. |
| 771 | __ test(receiver, Immediate(kSmiTagMask)); |
| 772 | __ j(zero, miss, not_taken); |
| 773 | |
| 774 | // Check that the maps haven't changed. |
| 775 | Register reg = |
| 776 | CheckPrototypes(object, receiver, holder, |
| 777 | scratch1, scratch2, name, miss); |
| 778 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame^] | 779 | Handle<AccessorInfo> callback_handle(callback); |
| 780 | |
| 781 | Register other = reg.is(scratch1) ? scratch2 : scratch1; |
| 782 | __ EnterInternalFrame(); |
| 783 | __ PushHandleScope(other); |
| 784 | // Push the stack address where the list of arguments ends |
| 785 | __ mov(other, esp); |
| 786 | __ sub(Operand(other), Immediate(2 * kPointerSize)); |
| 787 | __ push(other); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 788 | __ push(receiver); // receiver |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 789 | __ push(reg); // holder |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame^] | 790 | __ mov(other, Immediate(callback_handle)); |
| 791 | __ push(other); |
| 792 | __ push(FieldOperand(other, AccessorInfo::kDataOffset)); // data |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 793 | __ push(name_reg); // name |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame^] | 794 | // Save a pointer to where we pushed the arguments pointer. |
| 795 | // This will be passed as the const Arguments& to the C++ callback. |
| 796 | __ mov(eax, esp); |
| 797 | __ add(Operand(eax), Immediate(5 * kPointerSize)); |
| 798 | __ mov(ebx, esp); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 799 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame^] | 800 | // Do call through the api. |
| 801 | ASSERT_EQ(6, ApiGetterEntryStub::kStackSpace); |
| 802 | Address getter_address = v8::ToCData<Address>(callback->getter()); |
| 803 | ApiFunction fun(getter_address); |
| 804 | ApiGetterEntryStub stub(callback_handle, &fun); |
| 805 | __ CallStub(&stub); |
| 806 | |
| 807 | // We need to avoid using eax since that now holds the result. |
| 808 | Register tmp = other.is(eax) ? reg : other; |
| 809 | __ PopHandleScope(eax, tmp); |
| 810 | __ LeaveInternalFrame(); |
| 811 | |
| 812 | __ ret(0); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | |
| 816 | void StubCompiler::GenerateLoadConstant(JSObject* object, |
| 817 | JSObject* holder, |
| 818 | Register receiver, |
| 819 | Register scratch1, |
| 820 | Register scratch2, |
| 821 | Object* value, |
| 822 | String* name, |
| 823 | Label* miss) { |
| 824 | // Check that the receiver isn't a smi. |
| 825 | __ test(receiver, Immediate(kSmiTagMask)); |
| 826 | __ j(zero, miss, not_taken); |
| 827 | |
| 828 | // Check that the maps haven't changed. |
| 829 | Register reg = |
| 830 | CheckPrototypes(object, receiver, holder, |
| 831 | scratch1, scratch2, name, miss); |
| 832 | |
| 833 | // Return the constant value. |
| 834 | __ mov(eax, Handle<Object>(value)); |
| 835 | __ ret(0); |
| 836 | } |
| 837 | |
| 838 | |
| 839 | void StubCompiler::GenerateLoadInterceptor(JSObject* object, |
| 840 | JSObject* holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 841 | LookupResult* lookup, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 842 | Register receiver, |
| 843 | Register name_reg, |
| 844 | Register scratch1, |
| 845 | Register scratch2, |
| 846 | String* name, |
| 847 | Label* miss) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 848 | LoadInterceptorCompiler compiler(name_reg); |
| 849 | CompileLoadInterceptor(&compiler, |
| 850 | this, |
| 851 | masm(), |
| 852 | object, |
| 853 | holder, |
| 854 | name, |
| 855 | lookup, |
| 856 | receiver, |
| 857 | scratch1, |
| 858 | scratch2, |
| 859 | miss); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | // TODO(1241006): Avoid having lazy compile stubs specialized by the |
| 864 | // number of arguments. It is not needed anymore. |
| 865 | Object* StubCompiler::CompileLazyCompile(Code::Flags flags) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 866 | // Enter an internal frame. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 867 | __ EnterInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 868 | |
| 869 | // Push a copy of the function onto the stack. |
| 870 | __ push(edi); |
| 871 | |
| 872 | __ push(edi); // function is also the parameter to the runtime call |
| 873 | __ CallRuntime(Runtime::kLazyCompile, 1); |
| 874 | __ pop(edi); |
| 875 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 876 | // Tear down temporary frame. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 877 | __ LeaveInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 878 | |
| 879 | // Do a tail-call of the compiled function. |
| 880 | __ lea(ecx, FieldOperand(eax, Code::kHeaderSize)); |
| 881 | __ jmp(Operand(ecx)); |
| 882 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 883 | return GetCodeWithFlags(flags, "LazyCompileStub"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | |
| 887 | Object* CallStubCompiler::CompileCallField(Object* object, |
| 888 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 889 | int index, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 890 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 891 | // ----------- S t a t e ------------- |
| 892 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 893 | Label miss; |
| 894 | |
| 895 | // Get the receiver from the stack. |
| 896 | const int argc = arguments().immediate(); |
| 897 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 898 | |
| 899 | // Check that the receiver isn't a smi. |
| 900 | __ test(edx, Immediate(kSmiTagMask)); |
| 901 | __ j(zero, &miss, not_taken); |
| 902 | |
| 903 | // Do the right check and compute the holder register. |
| 904 | Register reg = |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 905 | CheckPrototypes(JSObject::cast(object), edx, holder, |
| 906 | ebx, ecx, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 907 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 908 | GenerateFastPropertyLoad(masm(), edi, reg, holder, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 909 | |
| 910 | // Check that the function really is a function. |
| 911 | __ test(edi, Immediate(kSmiTagMask)); |
| 912 | __ j(zero, &miss, not_taken); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 913 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 914 | __ j(not_equal, &miss, not_taken); |
| 915 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 916 | // Patch the receiver on the stack with the global proxy if |
| 917 | // necessary. |
| 918 | if (object->IsGlobalObject()) { |
| 919 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 920 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 921 | } |
| 922 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 923 | // Invoke the function. |
| 924 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION); |
| 925 | |
| 926 | // Handle call cache miss. |
| 927 | __ bind(&miss); |
| 928 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 929 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 930 | |
| 931 | // Return the generated code. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 932 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | |
| 936 | Object* CallStubCompiler::CompileCallConstant(Object* object, |
| 937 | JSObject* holder, |
| 938 | JSFunction* function, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 939 | String* name, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 940 | CheckType check) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 941 | // ----------- S t a t e ------------- |
| 942 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 943 | Label miss; |
| 944 | |
| 945 | // Get the receiver from the stack. |
| 946 | const int argc = arguments().immediate(); |
| 947 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 948 | |
| 949 | // Check that the receiver isn't a smi. |
| 950 | if (check != NUMBER_CHECK) { |
| 951 | __ test(edx, Immediate(kSmiTagMask)); |
| 952 | __ j(zero, &miss, not_taken); |
| 953 | } |
| 954 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 955 | // Make sure that it's okay not to patch the on stack receiver |
| 956 | // unless we're doing a receiver map check. |
| 957 | ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK); |
| 958 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 959 | switch (check) { |
| 960 | case RECEIVER_MAP_CHECK: |
| 961 | // Check that the maps haven't changed. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 962 | CheckPrototypes(JSObject::cast(object), edx, holder, |
| 963 | ebx, ecx, name, &miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 964 | |
| 965 | // Patch the receiver on the stack with the global proxy if |
| 966 | // necessary. |
| 967 | if (object->IsGlobalObject()) { |
| 968 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 969 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 970 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 971 | break; |
| 972 | |
| 973 | case STRING_CHECK: |
| 974 | // Check that the object is a two-byte string or a symbol. |
| 975 | __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 976 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 977 | __ cmp(ecx, FIRST_NONSTRING_TYPE); |
| 978 | __ j(above_equal, &miss, not_taken); |
| 979 | // Check that the maps starting from the prototype haven't changed. |
| 980 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 981 | Context::STRING_FUNCTION_INDEX, |
| 982 | ecx); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 983 | CheckPrototypes(JSObject::cast(object->GetPrototype()), ecx, holder, |
| 984 | ebx, edx, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 985 | break; |
| 986 | |
| 987 | case NUMBER_CHECK: { |
| 988 | Label fast; |
| 989 | // Check that the object is a smi or a heap number. |
| 990 | __ test(edx, Immediate(kSmiTagMask)); |
| 991 | __ j(zero, &fast, taken); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 992 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 993 | __ j(not_equal, &miss, not_taken); |
| 994 | __ bind(&fast); |
| 995 | // Check that the maps starting from the prototype haven't changed. |
| 996 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 997 | Context::NUMBER_FUNCTION_INDEX, |
| 998 | ecx); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 999 | CheckPrototypes(JSObject::cast(object->GetPrototype()), ecx, holder, |
| 1000 | ebx, edx, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1001 | break; |
| 1002 | } |
| 1003 | |
| 1004 | case BOOLEAN_CHECK: { |
| 1005 | Label fast; |
| 1006 | // Check that the object is a boolean. |
| 1007 | __ cmp(edx, Factory::true_value()); |
| 1008 | __ j(equal, &fast, taken); |
| 1009 | __ cmp(edx, Factory::false_value()); |
| 1010 | __ j(not_equal, &miss, not_taken); |
| 1011 | __ bind(&fast); |
| 1012 | // Check that the maps starting from the prototype haven't changed. |
| 1013 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 1014 | Context::BOOLEAN_FUNCTION_INDEX, |
| 1015 | ecx); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1016 | CheckPrototypes(JSObject::cast(object->GetPrototype()), ecx, holder, |
| 1017 | ebx, edx, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1018 | break; |
| 1019 | } |
| 1020 | |
| 1021 | case JSARRAY_HAS_FAST_ELEMENTS_CHECK: |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1022 | CheckPrototypes(JSObject::cast(object), edx, holder, |
| 1023 | ebx, ecx, name, &miss); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1024 | // Make sure object->HasFastElements(). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1025 | // Get the elements array of the object. |
| 1026 | __ mov(ebx, FieldOperand(edx, JSObject::kElementsOffset)); |
| 1027 | // Check that the object is in fast mode (not dictionary). |
| 1028 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1029 | Immediate(Factory::fixed_array_map())); |
| 1030 | __ j(not_equal, &miss, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1031 | break; |
| 1032 | |
| 1033 | default: |
| 1034 | UNREACHABLE(); |
| 1035 | } |
| 1036 | |
| 1037 | // Get the function and setup the context. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1038 | __ mov(edi, Immediate(Handle<JSFunction>(function))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1039 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1040 | |
| 1041 | // Jump to the cached code (tail call). |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1042 | ASSERT(function->is_compiled()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1043 | Handle<Code> code(function->code()); |
| 1044 | ParameterCount expected(function->shared()->formal_parameter_count()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1045 | __ InvokeCode(code, expected, arguments(), |
| 1046 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1047 | |
| 1048 | // Handle call cache miss. |
| 1049 | __ bind(&miss); |
| 1050 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1051 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1052 | |
| 1053 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1054 | String* function_name = NULL; |
| 1055 | if (function->shared()->name()->IsString()) { |
| 1056 | function_name = String::cast(function->shared()->name()); |
| 1057 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1058 | return GetCode(CONSTANT_FUNCTION, function_name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | Object* CallStubCompiler::CompileCallInterceptor(Object* object, |
| 1063 | JSObject* holder, |
| 1064 | String* name) { |
| 1065 | // ----------- S t a t e ------------- |
| 1066 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1067 | Label miss; |
| 1068 | |
| 1069 | // Get the number of arguments. |
| 1070 | const int argc = arguments().immediate(); |
| 1071 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1072 | LookupResult lookup; |
| 1073 | LookupPostInterceptor(holder, name, &lookup); |
| 1074 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1075 | // Get the receiver from the stack. |
| 1076 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1077 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1078 | CallInterceptorCompiler compiler(arguments()); |
| 1079 | CompileLoadInterceptor(&compiler, |
| 1080 | this, |
| 1081 | masm(), |
| 1082 | JSObject::cast(object), |
| 1083 | holder, |
| 1084 | name, |
| 1085 | &lookup, |
| 1086 | edx, |
| 1087 | ebx, |
| 1088 | ecx, |
| 1089 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1090 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1091 | // Restore receiver. |
| 1092 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1093 | |
| 1094 | // Check that the function really is a function. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1095 | __ test(eax, Immediate(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1096 | __ j(zero, &miss, not_taken); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1097 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1098 | __ j(not_equal, &miss, not_taken); |
| 1099 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1100 | // Patch the receiver on the stack with the global proxy if |
| 1101 | // necessary. |
| 1102 | if (object->IsGlobalObject()) { |
| 1103 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1104 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1105 | } |
| 1106 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1107 | // Invoke the function. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1108 | __ mov(edi, eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1109 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION); |
| 1110 | |
| 1111 | // Handle load cache miss. |
| 1112 | __ bind(&miss); |
| 1113 | Handle<Code> ic = ComputeCallMiss(argc); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1114 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1115 | |
| 1116 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1117 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1121 | Object* CallStubCompiler::CompileCallGlobal(JSObject* object, |
| 1122 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1123 | JSGlobalPropertyCell* cell, |
| 1124 | JSFunction* function, |
| 1125 | String* name) { |
| 1126 | // ----------- S t a t e ------------- |
| 1127 | // ----------------------------------- |
| 1128 | Label miss; |
| 1129 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1130 | // Get the number of arguments. |
| 1131 | const int argc = arguments().immediate(); |
| 1132 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1133 | // Get the receiver from the stack. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1134 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1135 | |
| 1136 | // If the object is the holder then we know that it's a global |
| 1137 | // object which can only happen for contextual calls. In this case, |
| 1138 | // the receiver cannot be a smi. |
| 1139 | if (object != holder) { |
| 1140 | __ test(edx, Immediate(kSmiTagMask)); |
| 1141 | __ j(zero, &miss, not_taken); |
| 1142 | } |
| 1143 | |
| 1144 | // Check that the maps haven't changed. |
| 1145 | CheckPrototypes(object, edx, holder, ebx, ecx, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1146 | |
| 1147 | // Get the value from the cell. |
| 1148 | __ mov(edi, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1149 | __ mov(edi, FieldOperand(edi, JSGlobalPropertyCell::kValueOffset)); |
| 1150 | |
| 1151 | // Check that the cell contains the same function. |
| 1152 | __ cmp(Operand(edi), Immediate(Handle<JSFunction>(function))); |
| 1153 | __ j(not_equal, &miss, not_taken); |
| 1154 | |
| 1155 | // Patch the receiver on the stack with the global proxy. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1156 | if (object->IsGlobalObject()) { |
| 1157 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1158 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1159 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1160 | |
| 1161 | // Setup the context (function already in edi). |
| 1162 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1163 | |
| 1164 | // Jump to the cached code (tail call). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1165 | __ IncrementCounter(&Counters::call_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1166 | ASSERT(function->is_compiled()); |
| 1167 | Handle<Code> code(function->code()); |
| 1168 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 1169 | __ InvokeCode(code, expected, arguments(), |
| 1170 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
| 1171 | |
| 1172 | // Handle call cache miss. |
| 1173 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1174 | __ IncrementCounter(&Counters::call_global_inline_miss, 1); |
| 1175 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
| 1176 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 1177 | |
| 1178 | // Return the generated code. |
| 1179 | return GetCode(NORMAL, name); |
| 1180 | } |
| 1181 | |
| 1182 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1183 | Object* StoreStubCompiler::CompileStoreField(JSObject* object, |
| 1184 | int index, |
| 1185 | Map* transition, |
| 1186 | String* name) { |
| 1187 | // ----------- S t a t e ------------- |
| 1188 | // -- eax : value |
| 1189 | // -- ecx : name |
| 1190 | // -- esp[0] : return address |
| 1191 | // -- esp[4] : receiver |
| 1192 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1193 | Label miss; |
| 1194 | |
| 1195 | // Get the object from the stack. |
| 1196 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1197 | |
| 1198 | // Generate store field code. Trashes the name register. |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1199 | GenerateStoreField(masm(), |
| 1200 | Builtins::StoreIC_ExtendStorage, |
| 1201 | object, |
| 1202 | index, |
| 1203 | transition, |
| 1204 | ebx, ecx, edx, |
| 1205 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1206 | |
| 1207 | // Handle store cache miss. |
| 1208 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1209 | __ mov(ecx, Immediate(Handle<String>(name))); // restore name |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1210 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1211 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1212 | |
| 1213 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1214 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | Object* StoreStubCompiler::CompileStoreCallback(JSObject* object, |
| 1219 | AccessorInfo* callback, |
| 1220 | String* name) { |
| 1221 | // ----------- S t a t e ------------- |
| 1222 | // -- eax : value |
| 1223 | // -- ecx : name |
| 1224 | // -- esp[0] : return address |
| 1225 | // -- esp[4] : receiver |
| 1226 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1227 | Label miss; |
| 1228 | |
| 1229 | // Get the object from the stack. |
| 1230 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1231 | |
| 1232 | // Check that the object isn't a smi. |
| 1233 | __ test(ebx, Immediate(kSmiTagMask)); |
| 1234 | __ j(zero, &miss, not_taken); |
| 1235 | |
| 1236 | // Check that the map of the object hasn't changed. |
| 1237 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1238 | Immediate(Handle<Map>(object->map()))); |
| 1239 | __ j(not_equal, &miss, not_taken); |
| 1240 | |
| 1241 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1242 | if (object->IsJSGlobalProxy()) { |
| 1243 | __ CheckAccessGlobalProxy(ebx, edx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | // Stub never generated for non-global objects that require access |
| 1247 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1248 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1249 | |
| 1250 | __ pop(ebx); // remove the return address |
| 1251 | __ push(Operand(esp, 0)); // receiver |
| 1252 | __ push(Immediate(Handle<AccessorInfo>(callback))); // callback info |
| 1253 | __ push(ecx); // name |
| 1254 | __ push(eax); // value |
| 1255 | __ push(ebx); // restore return address |
| 1256 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1257 | // Do tail-call to the runtime system. |
| 1258 | ExternalReference store_callback_property = |
| 1259 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1260 | __ TailCallRuntime(store_callback_property, 4, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1261 | |
| 1262 | // Handle store cache miss. |
| 1263 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1264 | __ mov(ecx, Immediate(Handle<String>(name))); // restore name |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1265 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1266 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1267 | |
| 1268 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1269 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | |
| 1273 | Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver, |
| 1274 | String* name) { |
| 1275 | // ----------- S t a t e ------------- |
| 1276 | // -- eax : value |
| 1277 | // -- ecx : name |
| 1278 | // -- esp[0] : return address |
| 1279 | // -- esp[4] : receiver |
| 1280 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1281 | Label miss; |
| 1282 | |
| 1283 | // Get the object from the stack. |
| 1284 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1285 | |
| 1286 | // Check that the object isn't a smi. |
| 1287 | __ test(ebx, Immediate(kSmiTagMask)); |
| 1288 | __ j(zero, &miss, not_taken); |
| 1289 | |
| 1290 | // Check that the map of the object hasn't changed. |
| 1291 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1292 | Immediate(Handle<Map>(receiver->map()))); |
| 1293 | __ j(not_equal, &miss, not_taken); |
| 1294 | |
| 1295 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1296 | if (receiver->IsJSGlobalProxy()) { |
| 1297 | __ CheckAccessGlobalProxy(ebx, edx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | // Stub never generated for non-global objects that require access |
| 1301 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1302 | ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1303 | |
| 1304 | __ pop(ebx); // remove the return address |
| 1305 | __ push(Operand(esp, 0)); // receiver |
| 1306 | __ push(ecx); // name |
| 1307 | __ push(eax); // value |
| 1308 | __ push(ebx); // restore return address |
| 1309 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1310 | // Do tail-call to the runtime system. |
| 1311 | ExternalReference store_ic_property = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1312 | ExternalReference(IC_Utility(IC::kStoreInterceptorProperty)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1313 | __ TailCallRuntime(store_ic_property, 3, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | |
| 1315 | // Handle store cache miss. |
| 1316 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1317 | __ mov(ecx, Immediate(Handle<String>(name))); // restore name |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1318 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1319 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1320 | |
| 1321 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1322 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1326 | Object* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object, |
| 1327 | JSGlobalPropertyCell* cell, |
| 1328 | String* name) { |
| 1329 | // ----------- S t a t e ------------- |
| 1330 | // -- eax : value |
| 1331 | // -- ecx : name |
| 1332 | // -- esp[0] : return address |
| 1333 | // -- esp[4] : receiver |
| 1334 | // ----------------------------------- |
| 1335 | Label miss; |
| 1336 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1337 | // Check that the map of the global has not changed. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1338 | __ mov(ebx, Operand(esp, kPointerSize)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1339 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1340 | Immediate(Handle<Map>(object->map()))); |
| 1341 | __ j(not_equal, &miss, not_taken); |
| 1342 | |
| 1343 | // Store the value in the cell. |
| 1344 | __ mov(ecx, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1345 | __ mov(FieldOperand(ecx, JSGlobalPropertyCell::kValueOffset), eax); |
| 1346 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1347 | // Return the value (register eax). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1348 | __ IncrementCounter(&Counters::named_store_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1349 | __ ret(0); |
| 1350 | |
| 1351 | // Handle store cache miss. |
| 1352 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1353 | __ IncrementCounter(&Counters::named_store_global_inline_miss, 1); |
| 1354 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
| 1355 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 1356 | |
| 1357 | // Return the generated code. |
| 1358 | return GetCode(NORMAL, name); |
| 1359 | } |
| 1360 | |
| 1361 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1362 | Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object, |
| 1363 | int index, |
| 1364 | Map* transition, |
| 1365 | String* name) { |
| 1366 | // ----------- S t a t e ------------- |
| 1367 | // -- eax : value |
| 1368 | // -- esp[0] : return address |
| 1369 | // -- esp[4] : key |
| 1370 | // -- esp[8] : receiver |
| 1371 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1372 | Label miss; |
| 1373 | |
| 1374 | __ IncrementCounter(&Counters::keyed_store_field, 1); |
| 1375 | |
| 1376 | // Get the name from the stack. |
| 1377 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 1378 | // Check that the name has not changed. |
| 1379 | __ cmp(Operand(ecx), Immediate(Handle<String>(name))); |
| 1380 | __ j(not_equal, &miss, not_taken); |
| 1381 | |
| 1382 | // Get the object from the stack. |
| 1383 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 1384 | |
| 1385 | // Generate store field code. Trashes the name register. |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1386 | GenerateStoreField(masm(), |
| 1387 | Builtins::KeyedStoreIC_ExtendStorage, |
| 1388 | object, |
| 1389 | index, |
| 1390 | transition, |
| 1391 | ebx, ecx, edx, |
| 1392 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1393 | |
| 1394 | // Handle store cache miss. |
| 1395 | __ bind(&miss); |
| 1396 | __ DecrementCounter(&Counters::keyed_store_field, 1); |
| 1397 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1398 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1399 | |
| 1400 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1401 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1405 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1406 | Object* LoadStubCompiler::CompileLoadField(JSObject* object, |
| 1407 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1408 | int index, |
| 1409 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1410 | // ----------- S t a t e ------------- |
| 1411 | // -- ecx : name |
| 1412 | // -- esp[0] : return address |
| 1413 | // -- esp[4] : receiver |
| 1414 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1415 | Label miss; |
| 1416 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1417 | __ mov(eax, Operand(esp, kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1418 | GenerateLoadField(object, holder, eax, ebx, edx, index, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1419 | __ bind(&miss); |
| 1420 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1421 | |
| 1422 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1423 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | |
| 1427 | Object* LoadStubCompiler::CompileLoadCallback(JSObject* object, |
| 1428 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1429 | AccessorInfo* callback, |
| 1430 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1431 | // ----------- S t a t e ------------- |
| 1432 | // -- ecx : name |
| 1433 | // -- esp[0] : return address |
| 1434 | // -- esp[4] : receiver |
| 1435 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1436 | Label miss; |
| 1437 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1438 | __ mov(eax, Operand(esp, kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1439 | GenerateLoadCallback(object, holder, eax, ecx, ebx, edx, |
| 1440 | callback, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1441 | __ bind(&miss); |
| 1442 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1443 | |
| 1444 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1445 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | |
| 1449 | Object* LoadStubCompiler::CompileLoadConstant(JSObject* object, |
| 1450 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1451 | Object* value, |
| 1452 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1453 | // ----------- S t a t e ------------- |
| 1454 | // -- ecx : name |
| 1455 | // -- esp[0] : return address |
| 1456 | // -- esp[4] : receiver |
| 1457 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1458 | Label miss; |
| 1459 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1460 | __ mov(eax, Operand(esp, kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1461 | GenerateLoadConstant(object, holder, eax, ebx, edx, value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1462 | __ bind(&miss); |
| 1463 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1464 | |
| 1465 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1466 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 1471 | JSObject* holder, |
| 1472 | String* name) { |
| 1473 | // ----------- S t a t e ------------- |
| 1474 | // -- ecx : name |
| 1475 | // -- esp[0] : return address |
| 1476 | // -- esp[4] : receiver |
| 1477 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1478 | Label miss; |
| 1479 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1480 | LookupResult lookup; |
| 1481 | LookupPostInterceptor(holder, name, &lookup); |
| 1482 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1483 | __ mov(eax, Operand(esp, kPointerSize)); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1484 | // TODO(368): Compile in the whole chain: all the interceptors in |
| 1485 | // prototypes and ultimate answer. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1486 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1487 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1488 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1489 | eax, |
| 1490 | ecx, |
| 1491 | edx, |
| 1492 | ebx, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1493 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1494 | &miss); |
| 1495 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1496 | __ bind(&miss); |
| 1497 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1498 | |
| 1499 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1500 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1504 | Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object, |
| 1505 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1506 | JSGlobalPropertyCell* cell, |
| 1507 | String* name, |
| 1508 | bool is_dont_delete) { |
| 1509 | // ----------- S t a t e ------------- |
| 1510 | // -- ecx : name |
| 1511 | // -- esp[0] : return address |
| 1512 | // -- esp[4] : receiver |
| 1513 | // ----------------------------------- |
| 1514 | Label miss; |
| 1515 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1516 | // Get the receiver from the stack. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1517 | __ mov(eax, Operand(esp, kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1518 | |
| 1519 | // If the object is the holder then we know that it's a global |
| 1520 | // object which can only happen for contextual loads. In this case, |
| 1521 | // the receiver cannot be a smi. |
| 1522 | if (object != holder) { |
| 1523 | __ test(eax, Immediate(kSmiTagMask)); |
| 1524 | __ j(zero, &miss, not_taken); |
| 1525 | } |
| 1526 | |
| 1527 | // Check that the maps haven't changed. |
| 1528 | CheckPrototypes(object, eax, holder, ebx, edx, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1529 | |
| 1530 | // Get the value from the cell. |
| 1531 | __ mov(eax, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1532 | __ mov(eax, FieldOperand(eax, JSGlobalPropertyCell::kValueOffset)); |
| 1533 | |
| 1534 | // Check for deleted property if property can actually be deleted. |
| 1535 | if (!is_dont_delete) { |
| 1536 | __ cmp(eax, Factory::the_hole_value()); |
| 1537 | __ j(equal, &miss, not_taken); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1538 | } else if (FLAG_debug_code) { |
| 1539 | __ cmp(eax, Factory::the_hole_value()); |
| 1540 | __ Check(not_equal, "DontDelete cells can't contain the hole"); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1543 | __ IncrementCounter(&Counters::named_load_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1544 | __ ret(0); |
| 1545 | |
| 1546 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1547 | __ IncrementCounter(&Counters::named_load_global_inline_miss, 1); |
| 1548 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1549 | |
| 1550 | // Return the generated code. |
| 1551 | return GetCode(NORMAL, name); |
| 1552 | } |
| 1553 | |
| 1554 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1555 | Object* KeyedLoadStubCompiler::CompileLoadField(String* name, |
| 1556 | JSObject* receiver, |
| 1557 | JSObject* holder, |
| 1558 | int index) { |
| 1559 | // ----------- S t a t e ------------- |
| 1560 | // -- esp[0] : return address |
| 1561 | // -- esp[4] : name |
| 1562 | // -- esp[8] : receiver |
| 1563 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1564 | Label miss; |
| 1565 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1566 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1567 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1568 | __ IncrementCounter(&Counters::keyed_load_field, 1); |
| 1569 | |
| 1570 | // Check that the name has not changed. |
| 1571 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1572 | __ j(not_equal, &miss, not_taken); |
| 1573 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1574 | GenerateLoadField(receiver, holder, ecx, ebx, edx, index, name, &miss); |
| 1575 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1576 | __ bind(&miss); |
| 1577 | __ DecrementCounter(&Counters::keyed_load_field, 1); |
| 1578 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1579 | |
| 1580 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1581 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | |
| 1585 | Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name, |
| 1586 | JSObject* receiver, |
| 1587 | JSObject* holder, |
| 1588 | AccessorInfo* callback) { |
| 1589 | // ----------- S t a t e ------------- |
| 1590 | // -- esp[0] : return address |
| 1591 | // -- esp[4] : name |
| 1592 | // -- esp[8] : receiver |
| 1593 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1594 | Label miss; |
| 1595 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1596 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1597 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1598 | __ IncrementCounter(&Counters::keyed_load_callback, 1); |
| 1599 | |
| 1600 | // Check that the name has not changed. |
| 1601 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1602 | __ j(not_equal, &miss, not_taken); |
| 1603 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1604 | GenerateLoadCallback(receiver, holder, ecx, eax, ebx, edx, |
| 1605 | callback, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | __ bind(&miss); |
| 1607 | __ DecrementCounter(&Counters::keyed_load_callback, 1); |
| 1608 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1609 | |
| 1610 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1611 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name, |
| 1616 | JSObject* receiver, |
| 1617 | JSObject* holder, |
| 1618 | Object* value) { |
| 1619 | // ----------- S t a t e ------------- |
| 1620 | // -- esp[0] : return address |
| 1621 | // -- esp[4] : name |
| 1622 | // -- esp[8] : receiver |
| 1623 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1624 | Label miss; |
| 1625 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1626 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1627 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1628 | __ IncrementCounter(&Counters::keyed_load_constant_function, 1); |
| 1629 | |
| 1630 | // Check that the name has not changed. |
| 1631 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1632 | __ j(not_equal, &miss, not_taken); |
| 1633 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1634 | GenerateLoadConstant(receiver, holder, ecx, ebx, edx, |
| 1635 | value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1636 | __ bind(&miss); |
| 1637 | __ DecrementCounter(&Counters::keyed_load_constant_function, 1); |
| 1638 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1639 | |
| 1640 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1641 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | |
| 1645 | Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 1646 | JSObject* holder, |
| 1647 | String* name) { |
| 1648 | // ----------- S t a t e ------------- |
| 1649 | // -- esp[0] : return address |
| 1650 | // -- esp[4] : name |
| 1651 | // -- esp[8] : receiver |
| 1652 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1653 | Label miss; |
| 1654 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1655 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1656 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1657 | __ IncrementCounter(&Counters::keyed_load_interceptor, 1); |
| 1658 | |
| 1659 | // Check that the name has not changed. |
| 1660 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1661 | __ j(not_equal, &miss, not_taken); |
| 1662 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1663 | LookupResult lookup; |
| 1664 | LookupPostInterceptor(holder, name, &lookup); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1665 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1666 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1667 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1668 | ecx, |
| 1669 | eax, |
| 1670 | edx, |
| 1671 | ebx, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1672 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1673 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1674 | __ bind(&miss); |
| 1675 | __ DecrementCounter(&Counters::keyed_load_interceptor, 1); |
| 1676 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1677 | |
| 1678 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1679 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) { |
| 1686 | // ----------- S t a t e ------------- |
| 1687 | // -- esp[0] : return address |
| 1688 | // -- esp[4] : name |
| 1689 | // -- esp[8] : receiver |
| 1690 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1691 | Label miss; |
| 1692 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1693 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1694 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1695 | __ IncrementCounter(&Counters::keyed_load_array_length, 1); |
| 1696 | |
| 1697 | // Check that the name has not changed. |
| 1698 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1699 | __ j(not_equal, &miss, not_taken); |
| 1700 | |
| 1701 | GenerateLoadArrayLength(masm(), ecx, edx, &miss); |
| 1702 | __ bind(&miss); |
| 1703 | __ DecrementCounter(&Counters::keyed_load_array_length, 1); |
| 1704 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1705 | |
| 1706 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1707 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1711 | Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1712 | // ----------- S t a t e ------------- |
| 1713 | // -- esp[0] : return address |
| 1714 | // -- esp[4] : name |
| 1715 | // -- esp[8] : receiver |
| 1716 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1717 | Label miss; |
| 1718 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1719 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1720 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1721 | __ IncrementCounter(&Counters::keyed_load_string_length, 1); |
| 1722 | |
| 1723 | // Check that the name has not changed. |
| 1724 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1725 | __ j(not_equal, &miss, not_taken); |
| 1726 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1727 | GenerateLoadStringLength(masm(), ecx, edx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1728 | __ bind(&miss); |
| 1729 | __ DecrementCounter(&Counters::keyed_load_string_length, 1); |
| 1730 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1731 | |
| 1732 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1733 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | |
| 1737 | Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) { |
| 1738 | // ----------- S t a t e ------------- |
| 1739 | // -- esp[0] : return address |
| 1740 | // -- esp[4] : name |
| 1741 | // -- esp[8] : receiver |
| 1742 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1743 | Label miss; |
| 1744 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1745 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1746 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1747 | __ IncrementCounter(&Counters::keyed_load_function_prototype, 1); |
| 1748 | |
| 1749 | // Check that the name has not changed. |
| 1750 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1751 | __ j(not_equal, &miss, not_taken); |
| 1752 | |
| 1753 | GenerateLoadFunctionPrototype(masm(), ecx, edx, ebx, &miss); |
| 1754 | __ bind(&miss); |
| 1755 | __ DecrementCounter(&Counters::keyed_load_function_prototype, 1); |
| 1756 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1757 | |
| 1758 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1759 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1763 | // Specialized stub for constructing objects from functions which only have only |
| 1764 | // simple assignments of the form this.x = ...; in their body. |
| 1765 | Object* ConstructStubCompiler::CompileConstructStub( |
| 1766 | SharedFunctionInfo* shared) { |
| 1767 | // ----------- S t a t e ------------- |
| 1768 | // -- eax : argc |
| 1769 | // -- edi : constructor |
| 1770 | // -- esp[0] : return address |
| 1771 | // -- esp[4] : last argument |
| 1772 | // ----------------------------------- |
| 1773 | Label generic_stub_call; |
| 1774 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1775 | // Check to see whether there are any break points in the function code. If |
| 1776 | // there are jump to the generic constructor stub which calls the actual |
| 1777 | // code for the function thereby hitting the break points. |
| 1778 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1779 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kDebugInfoOffset)); |
| 1780 | __ cmp(ebx, Factory::undefined_value()); |
| 1781 | __ j(not_equal, &generic_stub_call, not_taken); |
| 1782 | #endif |
| 1783 | |
| 1784 | // Load the initial map and verify that it is in fact a map. |
| 1785 | __ mov(ebx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1786 | // Will both indicate a NULL and a Smi. |
| 1787 | __ test(ebx, Immediate(kSmiTagMask)); |
| 1788 | __ j(zero, &generic_stub_call); |
| 1789 | __ CmpObjectType(ebx, MAP_TYPE, ecx); |
| 1790 | __ j(not_equal, &generic_stub_call); |
| 1791 | |
| 1792 | #ifdef DEBUG |
| 1793 | // Cannot construct functions this way. |
| 1794 | // edi: constructor |
| 1795 | // ebx: initial map |
| 1796 | __ CmpInstanceType(ebx, JS_FUNCTION_TYPE); |
| 1797 | __ Assert(not_equal, "Function constructed by construct stub."); |
| 1798 | #endif |
| 1799 | |
| 1800 | // Now allocate the JSObject on the heap by moving the new space allocation |
| 1801 | // top forward. |
| 1802 | // edi: constructor |
| 1803 | // ebx: initial map |
| 1804 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceSizeOffset)); |
| 1805 | __ shl(ecx, kPointerSizeLog2); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1806 | __ AllocateInNewSpace(ecx, |
| 1807 | edx, |
| 1808 | ecx, |
| 1809 | no_reg, |
| 1810 | &generic_stub_call, |
| 1811 | NO_ALLOCATION_FLAGS); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1812 | |
| 1813 | // Allocated the JSObject, now initialize the fields and add the heap tag. |
| 1814 | // ebx: initial map |
| 1815 | // edx: JSObject (untagged) |
| 1816 | __ mov(Operand(edx, JSObject::kMapOffset), ebx); |
| 1817 | __ mov(ebx, Factory::empty_fixed_array()); |
| 1818 | __ mov(Operand(edx, JSObject::kPropertiesOffset), ebx); |
| 1819 | __ mov(Operand(edx, JSObject::kElementsOffset), ebx); |
| 1820 | |
| 1821 | // Push the allocated object to the stack. This is the object that will be |
| 1822 | // returned (after it is tagged). |
| 1823 | __ push(edx); |
| 1824 | |
| 1825 | // eax: argc |
| 1826 | // edx: JSObject (untagged) |
| 1827 | // Load the address of the first in-object property into edx. |
| 1828 | __ lea(edx, Operand(edx, JSObject::kHeaderSize)); |
| 1829 | // Calculate the location of the first argument. The stack contains the |
| 1830 | // allocated object and the return address on top of the argc arguments. |
| 1831 | __ lea(ecx, Operand(esp, eax, times_4, 1 * kPointerSize)); |
| 1832 | |
| 1833 | // Use edi for holding undefined which is used in several places below. |
| 1834 | __ mov(edi, Factory::undefined_value()); |
| 1835 | |
| 1836 | // eax: argc |
| 1837 | // ecx: first argument |
| 1838 | // edx: first in-object property of the JSObject |
| 1839 | // edi: undefined |
| 1840 | // Fill the initialized properties with a constant value or a passed argument |
| 1841 | // depending on the this.x = ...; assignment in the function. |
| 1842 | for (int i = 0; i < shared->this_property_assignments_count(); i++) { |
| 1843 | if (shared->IsThisPropertyAssignmentArgument(i)) { |
| 1844 | Label not_passed; |
| 1845 | // Set the property to undefined. |
| 1846 | __ mov(Operand(edx, i * kPointerSize), edi); |
| 1847 | // Check if the argument assigned to the property is actually passed. |
| 1848 | int arg_number = shared->GetThisPropertyAssignmentArgument(i); |
| 1849 | __ cmp(eax, arg_number); |
| 1850 | __ j(below_equal, ¬_passed); |
| 1851 | // Argument passed - find it on the stack. |
| 1852 | __ mov(ebx, Operand(ecx, arg_number * -kPointerSize)); |
| 1853 | __ mov(Operand(edx, i * kPointerSize), ebx); |
| 1854 | __ bind(¬_passed); |
| 1855 | } else { |
| 1856 | // Set the property to the constant value. |
| 1857 | Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i)); |
| 1858 | __ mov(Operand(edx, i * kPointerSize), Immediate(constant)); |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | // Fill the unused in-object property fields with undefined. |
| 1863 | for (int i = shared->this_property_assignments_count(); |
| 1864 | i < shared->CalculateInObjectProperties(); |
| 1865 | i++) { |
| 1866 | __ mov(Operand(edx, i * kPointerSize), edi); |
| 1867 | } |
| 1868 | |
| 1869 | // Move argc to ebx and retrieve and tag the JSObject to return. |
| 1870 | __ mov(ebx, eax); |
| 1871 | __ pop(eax); |
| 1872 | __ or_(Operand(eax), Immediate(kHeapObjectTag)); |
| 1873 | |
| 1874 | // Remove caller arguments and receiver from the stack and return. |
| 1875 | __ pop(ecx); |
| 1876 | __ lea(esp, Operand(esp, ebx, times_pointer_size, 1 * kPointerSize)); |
| 1877 | __ push(ecx); |
| 1878 | __ IncrementCounter(&Counters::constructed_objects, 1); |
| 1879 | __ IncrementCounter(&Counters::constructed_objects_stub, 1); |
| 1880 | __ ret(0); |
| 1881 | |
| 1882 | // Jump to the generic stub in case the specialized code cannot handle the |
| 1883 | // construction. |
| 1884 | __ bind(&generic_stub_call); |
| 1885 | Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); |
| 1886 | Handle<Code> generic_construct_stub(code); |
| 1887 | __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 1888 | |
| 1889 | // Return the generated code. |
| 1890 | return GetCode(); |
| 1891 | } |
| 1892 | |
| 1893 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | #undef __ |
| 1895 | |
| 1896 | } } // namespace v8::internal |