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)); |
| 243 | __ shr(eax); // ecx is implicit shift register. |
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 | |
| 305 | CEntryStub stub; |
| 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)); |
| 470 | __ TailCallRuntime(ref, 5); |
| 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)); |
| 492 | __ TailCallRuntime(ref, 5); |
| 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 | |
| 596 | CEntryStub stub; |
| 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 | |
| 779 | // Push the arguments on the JS stack of the caller. |
| 780 | __ pop(scratch2); // remove return address |
| 781 | __ push(receiver); // receiver |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 782 | __ push(reg); // holder |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 783 | __ mov(reg, Immediate(Handle<AccessorInfo>(callback))); // callback data |
| 784 | __ push(reg); |
| 785 | __ push(FieldOperand(reg, AccessorInfo::kDataOffset)); |
| 786 | __ push(name_reg); // name |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 787 | __ push(scratch2); // restore return address |
| 788 | |
| 789 | // Do tail-call to the runtime system. |
| 790 | ExternalReference load_callback_property = |
| 791 | ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 792 | __ TailCallRuntime(load_callback_property, 5); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | |
| 796 | void StubCompiler::GenerateLoadConstant(JSObject* object, |
| 797 | JSObject* holder, |
| 798 | Register receiver, |
| 799 | Register scratch1, |
| 800 | Register scratch2, |
| 801 | Object* value, |
| 802 | String* name, |
| 803 | Label* miss) { |
| 804 | // Check that the receiver isn't a smi. |
| 805 | __ test(receiver, Immediate(kSmiTagMask)); |
| 806 | __ j(zero, miss, not_taken); |
| 807 | |
| 808 | // Check that the maps haven't changed. |
| 809 | Register reg = |
| 810 | CheckPrototypes(object, receiver, holder, |
| 811 | scratch1, scratch2, name, miss); |
| 812 | |
| 813 | // Return the constant value. |
| 814 | __ mov(eax, Handle<Object>(value)); |
| 815 | __ ret(0); |
| 816 | } |
| 817 | |
| 818 | |
| 819 | void StubCompiler::GenerateLoadInterceptor(JSObject* object, |
| 820 | JSObject* holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 821 | LookupResult* lookup, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 822 | Register receiver, |
| 823 | Register name_reg, |
| 824 | Register scratch1, |
| 825 | Register scratch2, |
| 826 | String* name, |
| 827 | Label* miss) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 828 | LoadInterceptorCompiler compiler(name_reg); |
| 829 | CompileLoadInterceptor(&compiler, |
| 830 | this, |
| 831 | masm(), |
| 832 | object, |
| 833 | holder, |
| 834 | name, |
| 835 | lookup, |
| 836 | receiver, |
| 837 | scratch1, |
| 838 | scratch2, |
| 839 | miss); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 843 | // TODO(1241006): Avoid having lazy compile stubs specialized by the |
| 844 | // number of arguments. It is not needed anymore. |
| 845 | Object* StubCompiler::CompileLazyCompile(Code::Flags flags) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 846 | // Enter an internal frame. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 847 | __ EnterInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 848 | |
| 849 | // Push a copy of the function onto the stack. |
| 850 | __ push(edi); |
| 851 | |
| 852 | __ push(edi); // function is also the parameter to the runtime call |
| 853 | __ CallRuntime(Runtime::kLazyCompile, 1); |
| 854 | __ pop(edi); |
| 855 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 856 | // Tear down temporary frame. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 857 | __ LeaveInternalFrame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | |
| 859 | // Do a tail-call of the compiled function. |
| 860 | __ lea(ecx, FieldOperand(eax, Code::kHeaderSize)); |
| 861 | __ jmp(Operand(ecx)); |
| 862 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 863 | return GetCodeWithFlags(flags, "LazyCompileStub"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | |
| 867 | Object* CallStubCompiler::CompileCallField(Object* object, |
| 868 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 869 | int index, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 870 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 871 | // ----------- S t a t e ------------- |
| 872 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 873 | Label miss; |
| 874 | |
| 875 | // Get the receiver from the stack. |
| 876 | const int argc = arguments().immediate(); |
| 877 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 878 | |
| 879 | // Check that the receiver isn't a smi. |
| 880 | __ test(edx, Immediate(kSmiTagMask)); |
| 881 | __ j(zero, &miss, not_taken); |
| 882 | |
| 883 | // Do the right check and compute the holder register. |
| 884 | Register reg = |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 885 | CheckPrototypes(JSObject::cast(object), edx, holder, |
| 886 | ebx, ecx, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 887 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 888 | GenerateFastPropertyLoad(masm(), edi, reg, holder, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | |
| 890 | // Check that the function really is a function. |
| 891 | __ test(edi, Immediate(kSmiTagMask)); |
| 892 | __ j(zero, &miss, not_taken); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 893 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 894 | __ j(not_equal, &miss, not_taken); |
| 895 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 896 | // Patch the receiver on the stack with the global proxy if |
| 897 | // necessary. |
| 898 | if (object->IsGlobalObject()) { |
| 899 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 900 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 901 | } |
| 902 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 903 | // Invoke the function. |
| 904 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION); |
| 905 | |
| 906 | // Handle call cache miss. |
| 907 | __ bind(&miss); |
| 908 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 909 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 910 | |
| 911 | // Return the generated code. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 912 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | |
| 916 | Object* CallStubCompiler::CompileCallConstant(Object* object, |
| 917 | JSObject* holder, |
| 918 | JSFunction* function, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 919 | String* name, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 920 | CheckType check) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | // ----------- S t a t e ------------- |
| 922 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 923 | Label miss; |
| 924 | |
| 925 | // Get the receiver from the stack. |
| 926 | const int argc = arguments().immediate(); |
| 927 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 928 | |
| 929 | // Check that the receiver isn't a smi. |
| 930 | if (check != NUMBER_CHECK) { |
| 931 | __ test(edx, Immediate(kSmiTagMask)); |
| 932 | __ j(zero, &miss, not_taken); |
| 933 | } |
| 934 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 935 | // Make sure that it's okay not to patch the on stack receiver |
| 936 | // unless we're doing a receiver map check. |
| 937 | ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK); |
| 938 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 939 | switch (check) { |
| 940 | case RECEIVER_MAP_CHECK: |
| 941 | // Check that the maps haven't changed. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 942 | CheckPrototypes(JSObject::cast(object), edx, holder, |
| 943 | ebx, ecx, name, &miss); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 944 | |
| 945 | // Patch the receiver on the stack with the global proxy if |
| 946 | // necessary. |
| 947 | if (object->IsGlobalObject()) { |
| 948 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 949 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 950 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 951 | break; |
| 952 | |
| 953 | case STRING_CHECK: |
| 954 | // Check that the object is a two-byte string or a symbol. |
| 955 | __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 956 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 957 | __ cmp(ecx, FIRST_NONSTRING_TYPE); |
| 958 | __ j(above_equal, &miss, not_taken); |
| 959 | // Check that the maps starting from the prototype haven't changed. |
| 960 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 961 | Context::STRING_FUNCTION_INDEX, |
| 962 | ecx); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 963 | CheckPrototypes(JSObject::cast(object->GetPrototype()), ecx, holder, |
| 964 | ebx, edx, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 965 | break; |
| 966 | |
| 967 | case NUMBER_CHECK: { |
| 968 | Label fast; |
| 969 | // Check that the object is a smi or a heap number. |
| 970 | __ test(edx, Immediate(kSmiTagMask)); |
| 971 | __ j(zero, &fast, taken); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 972 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 973 | __ j(not_equal, &miss, not_taken); |
| 974 | __ bind(&fast); |
| 975 | // Check that the maps starting from the prototype haven't changed. |
| 976 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 977 | Context::NUMBER_FUNCTION_INDEX, |
| 978 | ecx); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 979 | CheckPrototypes(JSObject::cast(object->GetPrototype()), ecx, holder, |
| 980 | ebx, edx, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 981 | break; |
| 982 | } |
| 983 | |
| 984 | case BOOLEAN_CHECK: { |
| 985 | Label fast; |
| 986 | // Check that the object is a boolean. |
| 987 | __ cmp(edx, Factory::true_value()); |
| 988 | __ j(equal, &fast, taken); |
| 989 | __ cmp(edx, Factory::false_value()); |
| 990 | __ j(not_equal, &miss, not_taken); |
| 991 | __ bind(&fast); |
| 992 | // Check that the maps starting from the prototype haven't changed. |
| 993 | GenerateLoadGlobalFunctionPrototype(masm(), |
| 994 | Context::BOOLEAN_FUNCTION_INDEX, |
| 995 | ecx); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 996 | CheckPrototypes(JSObject::cast(object->GetPrototype()), ecx, holder, |
| 997 | ebx, edx, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 998 | break; |
| 999 | } |
| 1000 | |
| 1001 | case JSARRAY_HAS_FAST_ELEMENTS_CHECK: |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1002 | CheckPrototypes(JSObject::cast(object), edx, holder, |
| 1003 | ebx, ecx, name, &miss); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1004 | // Make sure object->HasFastElements(). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1005 | // Get the elements array of the object. |
| 1006 | __ mov(ebx, FieldOperand(edx, JSObject::kElementsOffset)); |
| 1007 | // Check that the object is in fast mode (not dictionary). |
| 1008 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1009 | Immediate(Factory::fixed_array_map())); |
| 1010 | __ j(not_equal, &miss, not_taken); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1011 | break; |
| 1012 | |
| 1013 | default: |
| 1014 | UNREACHABLE(); |
| 1015 | } |
| 1016 | |
| 1017 | // Get the function and setup the context. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1018 | __ mov(edi, Immediate(Handle<JSFunction>(function))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1019 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1020 | |
| 1021 | // Jump to the cached code (tail call). |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1022 | ASSERT(function->is_compiled()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1023 | Handle<Code> code(function->code()); |
| 1024 | ParameterCount expected(function->shared()->formal_parameter_count()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1025 | __ InvokeCode(code, expected, arguments(), |
| 1026 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1027 | |
| 1028 | // Handle call cache miss. |
| 1029 | __ bind(&miss); |
| 1030 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1031 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1032 | |
| 1033 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1034 | String* function_name = NULL; |
| 1035 | if (function->shared()->name()->IsString()) { |
| 1036 | function_name = String::cast(function->shared()->name()); |
| 1037 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1038 | return GetCode(CONSTANT_FUNCTION, function_name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | Object* CallStubCompiler::CompileCallInterceptor(Object* object, |
| 1043 | JSObject* holder, |
| 1044 | String* name) { |
| 1045 | // ----------- S t a t e ------------- |
| 1046 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1047 | Label miss; |
| 1048 | |
| 1049 | // Get the number of arguments. |
| 1050 | const int argc = arguments().immediate(); |
| 1051 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1052 | LookupResult lookup; |
| 1053 | LookupPostInterceptor(holder, name, &lookup); |
| 1054 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1055 | // Get the receiver from the stack. |
| 1056 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1057 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1058 | CallInterceptorCompiler compiler(arguments()); |
| 1059 | CompileLoadInterceptor(&compiler, |
| 1060 | this, |
| 1061 | masm(), |
| 1062 | JSObject::cast(object), |
| 1063 | holder, |
| 1064 | name, |
| 1065 | &lookup, |
| 1066 | edx, |
| 1067 | ebx, |
| 1068 | ecx, |
| 1069 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1070 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1071 | // Restore receiver. |
| 1072 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1073 | |
| 1074 | // Check that the function really is a function. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1075 | __ test(eax, Immediate(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1076 | __ j(zero, &miss, not_taken); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1077 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1078 | __ j(not_equal, &miss, not_taken); |
| 1079 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1080 | // Patch the receiver on the stack with the global proxy if |
| 1081 | // necessary. |
| 1082 | if (object->IsGlobalObject()) { |
| 1083 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1084 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1085 | } |
| 1086 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1087 | // Invoke the function. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1088 | __ mov(edi, eax); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1089 | __ InvokeFunction(edi, arguments(), JUMP_FUNCTION); |
| 1090 | |
| 1091 | // Handle load cache miss. |
| 1092 | __ bind(&miss); |
| 1093 | Handle<Code> ic = ComputeCallMiss(argc); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1094 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1095 | |
| 1096 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1097 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1101 | Object* CallStubCompiler::CompileCallGlobal(JSObject* object, |
| 1102 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1103 | JSGlobalPropertyCell* cell, |
| 1104 | JSFunction* function, |
| 1105 | String* name) { |
| 1106 | // ----------- S t a t e ------------- |
| 1107 | // ----------------------------------- |
| 1108 | Label miss; |
| 1109 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1110 | // Get the number of arguments. |
| 1111 | const int argc = arguments().immediate(); |
| 1112 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1113 | // Get the receiver from the stack. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1114 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1115 | |
| 1116 | // If the object is the holder then we know that it's a global |
| 1117 | // object which can only happen for contextual calls. In this case, |
| 1118 | // the receiver cannot be a smi. |
| 1119 | if (object != holder) { |
| 1120 | __ test(edx, Immediate(kSmiTagMask)); |
| 1121 | __ j(zero, &miss, not_taken); |
| 1122 | } |
| 1123 | |
| 1124 | // Check that the maps haven't changed. |
| 1125 | CheckPrototypes(object, edx, holder, ebx, ecx, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1126 | |
| 1127 | // Get the value from the cell. |
| 1128 | __ mov(edi, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1129 | __ mov(edi, FieldOperand(edi, JSGlobalPropertyCell::kValueOffset)); |
| 1130 | |
| 1131 | // Check that the cell contains the same function. |
| 1132 | __ cmp(Operand(edi), Immediate(Handle<JSFunction>(function))); |
| 1133 | __ j(not_equal, &miss, not_taken); |
| 1134 | |
| 1135 | // Patch the receiver on the stack with the global proxy. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1136 | if (object->IsGlobalObject()) { |
| 1137 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); |
| 1138 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); |
| 1139 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1140 | |
| 1141 | // Setup the context (function already in edi). |
| 1142 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1143 | |
| 1144 | // Jump to the cached code (tail call). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1145 | __ IncrementCounter(&Counters::call_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1146 | ASSERT(function->is_compiled()); |
| 1147 | Handle<Code> code(function->code()); |
| 1148 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 1149 | __ InvokeCode(code, expected, arguments(), |
| 1150 | RelocInfo::CODE_TARGET, JUMP_FUNCTION); |
| 1151 | |
| 1152 | // Handle call cache miss. |
| 1153 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1154 | __ IncrementCounter(&Counters::call_global_inline_miss, 1); |
| 1155 | Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
| 1156 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 1157 | |
| 1158 | // Return the generated code. |
| 1159 | return GetCode(NORMAL, name); |
| 1160 | } |
| 1161 | |
| 1162 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1163 | Object* StoreStubCompiler::CompileStoreField(JSObject* object, |
| 1164 | int index, |
| 1165 | Map* transition, |
| 1166 | String* name) { |
| 1167 | // ----------- S t a t e ------------- |
| 1168 | // -- eax : value |
| 1169 | // -- ecx : name |
| 1170 | // -- esp[0] : return address |
| 1171 | // -- esp[4] : receiver |
| 1172 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1173 | Label miss; |
| 1174 | |
| 1175 | // Get the object from the stack. |
| 1176 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1177 | |
| 1178 | // Generate store field code. Trashes the name register. |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1179 | GenerateStoreField(masm(), |
| 1180 | Builtins::StoreIC_ExtendStorage, |
| 1181 | object, |
| 1182 | index, |
| 1183 | transition, |
| 1184 | ebx, ecx, edx, |
| 1185 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1186 | |
| 1187 | // Handle store cache miss. |
| 1188 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1189 | __ mov(ecx, Immediate(Handle<String>(name))); // restore name |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1190 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1191 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1192 | |
| 1193 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1194 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | Object* StoreStubCompiler::CompileStoreCallback(JSObject* object, |
| 1199 | AccessorInfo* callback, |
| 1200 | String* name) { |
| 1201 | // ----------- S t a t e ------------- |
| 1202 | // -- eax : value |
| 1203 | // -- ecx : name |
| 1204 | // -- esp[0] : return address |
| 1205 | // -- esp[4] : receiver |
| 1206 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1207 | Label miss; |
| 1208 | |
| 1209 | // Get the object from the stack. |
| 1210 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1211 | |
| 1212 | // Check that the object isn't a smi. |
| 1213 | __ test(ebx, Immediate(kSmiTagMask)); |
| 1214 | __ j(zero, &miss, not_taken); |
| 1215 | |
| 1216 | // Check that the map of the object hasn't changed. |
| 1217 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1218 | Immediate(Handle<Map>(object->map()))); |
| 1219 | __ j(not_equal, &miss, not_taken); |
| 1220 | |
| 1221 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1222 | if (object->IsJSGlobalProxy()) { |
| 1223 | __ CheckAccessGlobalProxy(ebx, edx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | // Stub never generated for non-global objects that require access |
| 1227 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1228 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1229 | |
| 1230 | __ pop(ebx); // remove the return address |
| 1231 | __ push(Operand(esp, 0)); // receiver |
| 1232 | __ push(Immediate(Handle<AccessorInfo>(callback))); // callback info |
| 1233 | __ push(ecx); // name |
| 1234 | __ push(eax); // value |
| 1235 | __ push(ebx); // restore return address |
| 1236 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1237 | // Do tail-call to the runtime system. |
| 1238 | ExternalReference store_callback_property = |
| 1239 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty)); |
| 1240 | __ TailCallRuntime(store_callback_property, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1241 | |
| 1242 | // Handle store cache miss. |
| 1243 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1244 | __ mov(ecx, Immediate(Handle<String>(name))); // restore name |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1245 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1246 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1247 | |
| 1248 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1249 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver, |
| 1254 | String* name) { |
| 1255 | // ----------- S t a t e ------------- |
| 1256 | // -- eax : value |
| 1257 | // -- ecx : name |
| 1258 | // -- esp[0] : return address |
| 1259 | // -- esp[4] : receiver |
| 1260 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1261 | Label miss; |
| 1262 | |
| 1263 | // Get the object from the stack. |
| 1264 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1265 | |
| 1266 | // Check that the object isn't a smi. |
| 1267 | __ test(ebx, Immediate(kSmiTagMask)); |
| 1268 | __ j(zero, &miss, not_taken); |
| 1269 | |
| 1270 | // Check that the map of the object hasn't changed. |
| 1271 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1272 | Immediate(Handle<Map>(receiver->map()))); |
| 1273 | __ j(not_equal, &miss, not_taken); |
| 1274 | |
| 1275 | // Perform global security token check if needed. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1276 | if (receiver->IsJSGlobalProxy()) { |
| 1277 | __ CheckAccessGlobalProxy(ebx, edx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | // Stub never generated for non-global objects that require access |
| 1281 | // checks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1282 | ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1283 | |
| 1284 | __ pop(ebx); // remove the return address |
| 1285 | __ push(Operand(esp, 0)); // receiver |
| 1286 | __ push(ecx); // name |
| 1287 | __ push(eax); // value |
| 1288 | __ push(ebx); // restore return address |
| 1289 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1290 | // Do tail-call to the runtime system. |
| 1291 | ExternalReference store_ic_property = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1292 | ExternalReference(IC_Utility(IC::kStoreInterceptorProperty)); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1293 | __ TailCallRuntime(store_ic_property, 3); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1294 | |
| 1295 | // Handle store cache miss. |
| 1296 | __ bind(&miss); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1297 | __ mov(ecx, Immediate(Handle<String>(name))); // restore name |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1298 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1299 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1300 | |
| 1301 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1302 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1306 | Object* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object, |
| 1307 | JSGlobalPropertyCell* cell, |
| 1308 | String* name) { |
| 1309 | // ----------- S t a t e ------------- |
| 1310 | // -- eax : value |
| 1311 | // -- ecx : name |
| 1312 | // -- esp[0] : return address |
| 1313 | // -- esp[4] : receiver |
| 1314 | // ----------------------------------- |
| 1315 | Label miss; |
| 1316 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1317 | // Check that the map of the global has not changed. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1318 | __ mov(ebx, Operand(esp, kPointerSize)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1319 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1320 | Immediate(Handle<Map>(object->map()))); |
| 1321 | __ j(not_equal, &miss, not_taken); |
| 1322 | |
| 1323 | // Store the value in the cell. |
| 1324 | __ mov(ecx, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1325 | __ mov(FieldOperand(ecx, JSGlobalPropertyCell::kValueOffset), eax); |
| 1326 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1327 | // Return the value (register eax). |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1328 | __ IncrementCounter(&Counters::named_store_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1329 | __ ret(0); |
| 1330 | |
| 1331 | // Handle store cache miss. |
| 1332 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1333 | __ IncrementCounter(&Counters::named_store_global_inline_miss, 1); |
| 1334 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss)); |
| 1335 | __ jmp(ic, RelocInfo::CODE_TARGET); |
| 1336 | |
| 1337 | // Return the generated code. |
| 1338 | return GetCode(NORMAL, name); |
| 1339 | } |
| 1340 | |
| 1341 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1342 | Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object, |
| 1343 | int index, |
| 1344 | Map* transition, |
| 1345 | String* name) { |
| 1346 | // ----------- S t a t e ------------- |
| 1347 | // -- eax : value |
| 1348 | // -- esp[0] : return address |
| 1349 | // -- esp[4] : key |
| 1350 | // -- esp[8] : receiver |
| 1351 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | Label miss; |
| 1353 | |
| 1354 | __ IncrementCounter(&Counters::keyed_store_field, 1); |
| 1355 | |
| 1356 | // Get the name from the stack. |
| 1357 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 1358 | // Check that the name has not changed. |
| 1359 | __ cmp(Operand(ecx), Immediate(Handle<String>(name))); |
| 1360 | __ j(not_equal, &miss, not_taken); |
| 1361 | |
| 1362 | // Get the object from the stack. |
| 1363 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 1364 | |
| 1365 | // Generate store field code. Trashes the name register. |
kasperl@chromium.org | 1accd57 | 2008-10-07 10:57:21 +0000 | [diff] [blame] | 1366 | GenerateStoreField(masm(), |
| 1367 | Builtins::KeyedStoreIC_ExtendStorage, |
| 1368 | object, |
| 1369 | index, |
| 1370 | transition, |
| 1371 | ebx, ecx, edx, |
| 1372 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1373 | |
| 1374 | // Handle store cache miss. |
| 1375 | __ bind(&miss); |
| 1376 | __ DecrementCounter(&Counters::keyed_store_field, 1); |
| 1377 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1378 | __ jmp(ic, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1379 | |
| 1380 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1381 | return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1385 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1386 | Object* LoadStubCompiler::CompileLoadField(JSObject* object, |
| 1387 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1388 | int index, |
| 1389 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1390 | // ----------- S t a t e ------------- |
| 1391 | // -- ecx : name |
| 1392 | // -- esp[0] : return address |
| 1393 | // -- esp[4] : receiver |
| 1394 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1395 | Label miss; |
| 1396 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1397 | __ mov(eax, Operand(esp, kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1398 | GenerateLoadField(object, holder, eax, ebx, edx, index, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1399 | __ bind(&miss); |
| 1400 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1401 | |
| 1402 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1403 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | |
| 1407 | Object* LoadStubCompiler::CompileLoadCallback(JSObject* object, |
| 1408 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1409 | AccessorInfo* callback, |
| 1410 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1411 | // ----------- S t a t e ------------- |
| 1412 | // -- ecx : name |
| 1413 | // -- esp[0] : return address |
| 1414 | // -- esp[4] : receiver |
| 1415 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1416 | Label miss; |
| 1417 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1418 | __ mov(eax, Operand(esp, kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1419 | GenerateLoadCallback(object, holder, eax, ecx, ebx, edx, |
| 1420 | callback, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1421 | __ bind(&miss); |
| 1422 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1423 | |
| 1424 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1425 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | |
| 1429 | Object* LoadStubCompiler::CompileLoadConstant(JSObject* object, |
| 1430 | JSObject* holder, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1431 | Object* value, |
| 1432 | String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1433 | // ----------- S t a t e ------------- |
| 1434 | // -- ecx : name |
| 1435 | // -- esp[0] : return address |
| 1436 | // -- esp[4] : receiver |
| 1437 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1438 | Label miss; |
| 1439 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1440 | __ mov(eax, Operand(esp, kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1441 | GenerateLoadConstant(object, holder, eax, ebx, edx, value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1442 | __ bind(&miss); |
| 1443 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1444 | |
| 1445 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1446 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 1451 | JSObject* holder, |
| 1452 | String* name) { |
| 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 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1460 | LookupResult lookup; |
| 1461 | LookupPostInterceptor(holder, name, &lookup); |
| 1462 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1463 | __ mov(eax, Operand(esp, kPointerSize)); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1464 | // TODO(368): Compile in the whole chain: all the interceptors in |
| 1465 | // prototypes and ultimate answer. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1466 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1467 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1468 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1469 | eax, |
| 1470 | ecx, |
| 1471 | edx, |
| 1472 | ebx, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1473 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1474 | &miss); |
| 1475 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1476 | __ bind(&miss); |
| 1477 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1478 | |
| 1479 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1480 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1484 | Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object, |
| 1485 | GlobalObject* holder, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1486 | JSGlobalPropertyCell* cell, |
| 1487 | String* name, |
| 1488 | bool is_dont_delete) { |
| 1489 | // ----------- S t a t e ------------- |
| 1490 | // -- ecx : name |
| 1491 | // -- esp[0] : return address |
| 1492 | // -- esp[4] : receiver |
| 1493 | // ----------------------------------- |
| 1494 | Label miss; |
| 1495 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1496 | // Get the receiver from the stack. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1497 | __ mov(eax, Operand(esp, kPointerSize)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1498 | |
| 1499 | // If the object is the holder then we know that it's a global |
| 1500 | // object which can only happen for contextual loads. In this case, |
| 1501 | // the receiver cannot be a smi. |
| 1502 | if (object != holder) { |
| 1503 | __ test(eax, Immediate(kSmiTagMask)); |
| 1504 | __ j(zero, &miss, not_taken); |
| 1505 | } |
| 1506 | |
| 1507 | // Check that the maps haven't changed. |
| 1508 | CheckPrototypes(object, eax, holder, ebx, edx, name, &miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1509 | |
| 1510 | // Get the value from the cell. |
| 1511 | __ mov(eax, Immediate(Handle<JSGlobalPropertyCell>(cell))); |
| 1512 | __ mov(eax, FieldOperand(eax, JSGlobalPropertyCell::kValueOffset)); |
| 1513 | |
| 1514 | // Check for deleted property if property can actually be deleted. |
| 1515 | if (!is_dont_delete) { |
| 1516 | __ cmp(eax, Factory::the_hole_value()); |
| 1517 | __ j(equal, &miss, not_taken); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1518 | } else if (FLAG_debug_code) { |
| 1519 | __ cmp(eax, Factory::the_hole_value()); |
| 1520 | __ Check(not_equal, "DontDelete cells can't contain the hole"); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1523 | __ IncrementCounter(&Counters::named_load_global_inline, 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1524 | __ ret(0); |
| 1525 | |
| 1526 | __ bind(&miss); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1527 | __ IncrementCounter(&Counters::named_load_global_inline_miss, 1); |
| 1528 | GenerateLoadMiss(masm(), Code::LOAD_IC); |
| 1529 | |
| 1530 | // Return the generated code. |
| 1531 | return GetCode(NORMAL, name); |
| 1532 | } |
| 1533 | |
| 1534 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1535 | Object* KeyedLoadStubCompiler::CompileLoadField(String* name, |
| 1536 | JSObject* receiver, |
| 1537 | JSObject* holder, |
| 1538 | int index) { |
| 1539 | // ----------- S t a t e ------------- |
| 1540 | // -- esp[0] : return address |
| 1541 | // -- esp[4] : name |
| 1542 | // -- esp[8] : receiver |
| 1543 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1544 | Label miss; |
| 1545 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1546 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1547 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1548 | __ IncrementCounter(&Counters::keyed_load_field, 1); |
| 1549 | |
| 1550 | // Check that the name has not changed. |
| 1551 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1552 | __ j(not_equal, &miss, not_taken); |
| 1553 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1554 | GenerateLoadField(receiver, holder, ecx, ebx, edx, index, name, &miss); |
| 1555 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1556 | __ bind(&miss); |
| 1557 | __ DecrementCounter(&Counters::keyed_load_field, 1); |
| 1558 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1559 | |
| 1560 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1561 | return GetCode(FIELD, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | |
| 1565 | Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name, |
| 1566 | JSObject* receiver, |
| 1567 | JSObject* holder, |
| 1568 | AccessorInfo* callback) { |
| 1569 | // ----------- S t a t e ------------- |
| 1570 | // -- esp[0] : return address |
| 1571 | // -- esp[4] : name |
| 1572 | // -- esp[8] : receiver |
| 1573 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1574 | Label miss; |
| 1575 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1576 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1577 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1578 | __ IncrementCounter(&Counters::keyed_load_callback, 1); |
| 1579 | |
| 1580 | // Check that the name has not changed. |
| 1581 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1582 | __ j(not_equal, &miss, not_taken); |
| 1583 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1584 | GenerateLoadCallback(receiver, holder, ecx, eax, ebx, edx, |
| 1585 | callback, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1586 | __ bind(&miss); |
| 1587 | __ DecrementCounter(&Counters::keyed_load_callback, 1); |
| 1588 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1589 | |
| 1590 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1591 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | |
| 1595 | Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name, |
| 1596 | JSObject* receiver, |
| 1597 | JSObject* holder, |
| 1598 | Object* value) { |
| 1599 | // ----------- S t a t e ------------- |
| 1600 | // -- esp[0] : return address |
| 1601 | // -- esp[4] : name |
| 1602 | // -- esp[8] : receiver |
| 1603 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1604 | Label miss; |
| 1605 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1606 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1607 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1608 | __ IncrementCounter(&Counters::keyed_load_constant_function, 1); |
| 1609 | |
| 1610 | // Check that the name has not changed. |
| 1611 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1612 | __ j(not_equal, &miss, not_taken); |
| 1613 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1614 | GenerateLoadConstant(receiver, holder, ecx, ebx, edx, |
| 1615 | value, name, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1616 | __ bind(&miss); |
| 1617 | __ DecrementCounter(&Counters::keyed_load_constant_function, 1); |
| 1618 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1619 | |
| 1620 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1621 | return GetCode(CONSTANT_FUNCTION, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | |
| 1625 | Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver, |
| 1626 | JSObject* holder, |
| 1627 | String* name) { |
| 1628 | // ----------- S t a t e ------------- |
| 1629 | // -- esp[0] : return address |
| 1630 | // -- esp[4] : name |
| 1631 | // -- esp[8] : receiver |
| 1632 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1633 | Label miss; |
| 1634 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1635 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1636 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1637 | __ IncrementCounter(&Counters::keyed_load_interceptor, 1); |
| 1638 | |
| 1639 | // Check that the name has not changed. |
| 1640 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1641 | __ j(not_equal, &miss, not_taken); |
| 1642 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1643 | LookupResult lookup; |
| 1644 | LookupPostInterceptor(holder, name, &lookup); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1645 | GenerateLoadInterceptor(receiver, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1646 | holder, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame^] | 1647 | &lookup, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1648 | ecx, |
| 1649 | eax, |
| 1650 | edx, |
| 1651 | ebx, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1652 | name, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1653 | &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1654 | __ bind(&miss); |
| 1655 | __ DecrementCounter(&Counters::keyed_load_interceptor, 1); |
| 1656 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1657 | |
| 1658 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1659 | return GetCode(INTERCEPTOR, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | |
| 1663 | |
| 1664 | |
| 1665 | Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) { |
| 1666 | // ----------- S t a t e ------------- |
| 1667 | // -- esp[0] : return address |
| 1668 | // -- esp[4] : name |
| 1669 | // -- esp[8] : receiver |
| 1670 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1671 | Label miss; |
| 1672 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1673 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1674 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1675 | __ IncrementCounter(&Counters::keyed_load_array_length, 1); |
| 1676 | |
| 1677 | // Check that the name has not changed. |
| 1678 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1679 | __ j(not_equal, &miss, not_taken); |
| 1680 | |
| 1681 | GenerateLoadArrayLength(masm(), ecx, edx, &miss); |
| 1682 | __ bind(&miss); |
| 1683 | __ DecrementCounter(&Counters::keyed_load_array_length, 1); |
| 1684 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1685 | |
| 1686 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1687 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1691 | Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1692 | // ----------- S t a t e ------------- |
| 1693 | // -- esp[0] : return address |
| 1694 | // -- esp[4] : name |
| 1695 | // -- esp[8] : receiver |
| 1696 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1697 | Label miss; |
| 1698 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1699 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1700 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1701 | __ IncrementCounter(&Counters::keyed_load_string_length, 1); |
| 1702 | |
| 1703 | // Check that the name has not changed. |
| 1704 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1705 | __ j(not_equal, &miss, not_taken); |
| 1706 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1707 | GenerateLoadStringLength(masm(), ecx, edx, &miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1708 | __ bind(&miss); |
| 1709 | __ DecrementCounter(&Counters::keyed_load_string_length, 1); |
| 1710 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1711 | |
| 1712 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1713 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | |
| 1717 | Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) { |
| 1718 | // ----------- S t a t e ------------- |
| 1719 | // -- esp[0] : return address |
| 1720 | // -- esp[4] : name |
| 1721 | // -- esp[8] : receiver |
| 1722 | // ----------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1723 | Label miss; |
| 1724 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1725 | __ mov(eax, Operand(esp, kPointerSize)); |
| 1726 | __ mov(ecx, Operand(esp, 2 * kPointerSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1727 | __ IncrementCounter(&Counters::keyed_load_function_prototype, 1); |
| 1728 | |
| 1729 | // Check that the name has not changed. |
| 1730 | __ cmp(Operand(eax), Immediate(Handle<String>(name))); |
| 1731 | __ j(not_equal, &miss, not_taken); |
| 1732 | |
| 1733 | GenerateLoadFunctionPrototype(masm(), ecx, edx, ebx, &miss); |
| 1734 | __ bind(&miss); |
| 1735 | __ DecrementCounter(&Counters::keyed_load_function_prototype, 1); |
| 1736 | GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| 1737 | |
| 1738 | // Return the generated code. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1739 | return GetCode(CALLBACKS, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | #undef __ |
| 1744 | |
| 1745 | } } // namespace v8::internal |