Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 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 | #ifndef V8_STUB_CACHE_H_ |
| 29 | #define V8_STUB_CACHE_H_ |
| 30 | |
| 31 | #include "macro-assembler.h" |
| 32 | |
| 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
| 36 | |
| 37 | // The stub cache is used for megamorphic calls and property accesses. |
| 38 | // It maps (map, name, type)->Code* |
| 39 | |
| 40 | // The design of the table uses the inline cache stubs used for |
| 41 | // mono-morphic calls. The beauty of this, we do not have to |
| 42 | // invalidate the cache whenever a prototype map is changed. The stub |
| 43 | // validates the map chain as in the mono-morphic case. |
| 44 | |
| 45 | class SCTableReference; |
| 46 | |
| 47 | class StubCache : public AllStatic { |
| 48 | public: |
| 49 | struct Entry { |
| 50 | String* key; |
| 51 | Code* value; |
| 52 | }; |
| 53 | |
| 54 | |
| 55 | static void Initialize(bool create_heap_objects); |
| 56 | |
| 57 | // Computes the right stub matching. Inserts the result in the |
| 58 | // cache before returning. This might compile a stub if needed. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 59 | static Object* ComputeLoadNonexistent(String* name, JSObject* receiver); |
| 60 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 61 | static Object* ComputeLoadField(String* name, |
| 62 | JSObject* receiver, |
| 63 | JSObject* holder, |
| 64 | int field_index); |
| 65 | |
| 66 | static Object* ComputeLoadCallback(String* name, |
| 67 | JSObject* receiver, |
| 68 | JSObject* holder, |
| 69 | AccessorInfo* callback); |
| 70 | |
| 71 | static Object* ComputeLoadConstant(String* name, |
| 72 | JSObject* receiver, |
| 73 | JSObject* holder, |
| 74 | Object* value); |
| 75 | |
| 76 | static Object* ComputeLoadInterceptor(String* name, |
| 77 | JSObject* receiver, |
| 78 | JSObject* holder); |
| 79 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 80 | static Object* ComputeLoadNormal(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 81 | |
| 82 | |
| 83 | static Object* ComputeLoadGlobal(String* name, |
| 84 | JSObject* receiver, |
| 85 | GlobalObject* holder, |
| 86 | JSGlobalPropertyCell* cell, |
| 87 | bool is_dont_delete); |
| 88 | |
| 89 | |
| 90 | // --- |
| 91 | |
| 92 | static Object* ComputeKeyedLoadField(String* name, |
| 93 | JSObject* receiver, |
| 94 | JSObject* holder, |
| 95 | int field_index); |
| 96 | |
| 97 | static Object* ComputeKeyedLoadCallback(String* name, |
| 98 | JSObject* receiver, |
| 99 | JSObject* holder, |
| 100 | AccessorInfo* callback); |
| 101 | |
| 102 | static Object* ComputeKeyedLoadConstant(String* name, JSObject* receiver, |
| 103 | JSObject* holder, Object* value); |
| 104 | |
| 105 | static Object* ComputeKeyedLoadInterceptor(String* name, |
| 106 | JSObject* receiver, |
| 107 | JSObject* holder); |
| 108 | |
| 109 | static Object* ComputeKeyedLoadArrayLength(String* name, JSArray* receiver); |
| 110 | |
| 111 | static Object* ComputeKeyedLoadStringLength(String* name, |
| 112 | String* receiver); |
| 113 | |
| 114 | static Object* ComputeKeyedLoadFunctionPrototype(String* name, |
| 115 | JSFunction* receiver); |
| 116 | |
| 117 | // --- |
| 118 | |
| 119 | static Object* ComputeStoreField(String* name, |
| 120 | JSObject* receiver, |
| 121 | int field_index, |
| 122 | Map* transition = NULL); |
| 123 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 124 | static Object* ComputeStoreNormal(); |
| 125 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 126 | static Object* ComputeStoreGlobal(String* name, |
| 127 | GlobalObject* receiver, |
| 128 | JSGlobalPropertyCell* cell); |
| 129 | |
| 130 | static Object* ComputeStoreCallback(String* name, |
| 131 | JSObject* receiver, |
| 132 | AccessorInfo* callback); |
| 133 | |
| 134 | static Object* ComputeStoreInterceptor(String* name, JSObject* receiver); |
| 135 | |
| 136 | // --- |
| 137 | |
| 138 | static Object* ComputeKeyedStoreField(String* name, |
| 139 | JSObject* receiver, |
| 140 | int field_index, |
| 141 | Map* transition = NULL); |
| 142 | |
| 143 | // --- |
| 144 | |
| 145 | static Object* ComputeCallField(int argc, |
| 146 | InLoopFlag in_loop, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 147 | Code::Kind, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 148 | String* name, |
| 149 | Object* object, |
| 150 | JSObject* holder, |
| 151 | int index); |
| 152 | |
| 153 | static Object* ComputeCallConstant(int argc, |
| 154 | InLoopFlag in_loop, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 155 | Code::Kind, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 156 | String* name, |
| 157 | Object* object, |
| 158 | JSObject* holder, |
| 159 | JSFunction* function); |
| 160 | |
| 161 | static Object* ComputeCallNormal(int argc, |
| 162 | InLoopFlag in_loop, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 163 | Code::Kind, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 164 | String* name, |
| 165 | JSObject* receiver); |
| 166 | |
| 167 | static Object* ComputeCallInterceptor(int argc, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 168 | Code::Kind, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 169 | String* name, |
| 170 | Object* object, |
| 171 | JSObject* holder); |
| 172 | |
| 173 | static Object* ComputeCallGlobal(int argc, |
| 174 | InLoopFlag in_loop, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 175 | Code::Kind, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 176 | String* name, |
| 177 | JSObject* receiver, |
| 178 | GlobalObject* holder, |
| 179 | JSGlobalPropertyCell* cell, |
| 180 | JSFunction* function); |
| 181 | |
| 182 | // --- |
| 183 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 184 | static Object* ComputeCallInitialize(int argc, |
| 185 | InLoopFlag in_loop, |
| 186 | Code::Kind kind); |
| 187 | |
| 188 | static Object* ComputeCallPreMonomorphic(int argc, |
| 189 | InLoopFlag in_loop, |
| 190 | Code::Kind kind); |
| 191 | |
| 192 | static Object* ComputeCallNormal(int argc, |
| 193 | InLoopFlag in_loop, |
| 194 | Code::Kind kind); |
| 195 | |
| 196 | static Object* ComputeCallMegamorphic(int argc, |
| 197 | InLoopFlag in_loop, |
| 198 | Code::Kind kind); |
| 199 | |
| 200 | static Object* ComputeCallMiss(int argc, Code::Kind kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 201 | |
| 202 | // Finds the Code object stored in the Heap::non_monomorphic_cache(). |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 203 | static Code* FindCallInitialize(int argc, |
| 204 | InLoopFlag in_loop, |
| 205 | Code::Kind kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 206 | |
| 207 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 208 | static Object* ComputeCallDebugBreak(int argc, Code::Kind kind); |
| 209 | |
| 210 | static Object* ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | #endif |
| 212 | |
| 213 | static Object* ComputeLazyCompile(int argc); |
| 214 | |
| 215 | |
| 216 | // Update cache for entry hash(name, map). |
| 217 | static Code* Set(String* name, Map* map, Code* code); |
| 218 | |
| 219 | // Clear the lookup table (@ mark compact collection). |
| 220 | static void Clear(); |
| 221 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 222 | // Generate code for probing the stub cache table. |
| 223 | // If extra != no_reg it might be used as am extra scratch register. |
| 224 | static void GenerateProbe(MacroAssembler* masm, |
| 225 | Code::Flags flags, |
| 226 | Register receiver, |
| 227 | Register name, |
| 228 | Register scratch, |
| 229 | Register extra); |
| 230 | |
| 231 | enum Table { |
| 232 | kPrimary, |
| 233 | kSecondary |
| 234 | }; |
| 235 | |
| 236 | private: |
| 237 | friend class SCTableReference; |
| 238 | static const int kPrimaryTableSize = 2048; |
| 239 | static const int kSecondaryTableSize = 512; |
| 240 | static Entry primary_[]; |
| 241 | static Entry secondary_[]; |
| 242 | |
| 243 | // Computes the hashed offsets for primary and secondary caches. |
| 244 | static int PrimaryOffset(String* name, Code::Flags flags, Map* map) { |
| 245 | // This works well because the heap object tag size and the hash |
| 246 | // shift are equal. Shifting down the length field to get the |
| 247 | // hash code would effectively throw away two bits of the hash |
| 248 | // code. |
| 249 | ASSERT(kHeapObjectTagSize == String::kHashShift); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 250 | // Compute the hash of the name (use entire hash field). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 251 | ASSERT(name->HasHashCode()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 252 | uint32_t field = name->hash_field(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 253 | // Using only the low bits in 64-bit mode is unlikely to increase the |
| 254 | // risk of collision even if the heap is spread over an area larger than |
| 255 | // 4Gb (and not at all if it isn't). |
| 256 | uint32_t map_low32bits = |
| 257 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(map)); |
| 258 | // We always set the in_loop bit to zero when generating the lookup code |
| 259 | // so do it here too so the hash codes match. |
| 260 | uint32_t iflags = |
| 261 | (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup); |
| 262 | // Base the offset on a simple combination of name, flags, and map. |
| 263 | uint32_t key = (map_low32bits + field) ^ iflags; |
| 264 | return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); |
| 265 | } |
| 266 | |
| 267 | static int SecondaryOffset(String* name, Code::Flags flags, int seed) { |
| 268 | // Use the seed from the primary cache in the secondary cache. |
| 269 | uint32_t string_low32bits = |
| 270 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)); |
| 271 | // We always set the in_loop bit to zero when generating the lookup code |
| 272 | // so do it here too so the hash codes match. |
| 273 | uint32_t iflags = |
| 274 | (static_cast<uint32_t>(flags) & ~Code::kFlagsICInLoopMask); |
| 275 | uint32_t key = seed - string_low32bits + iflags; |
| 276 | return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); |
| 277 | } |
| 278 | |
| 279 | // Compute the entry for a given offset in exactly the same way as |
| 280 | // we do in generated code. We generate an hash code that already |
| 281 | // ends in String::kHashShift 0s. Then we shift it so it is a multiple |
| 282 | // of sizeof(Entry). This makes it easier to avoid making mistakes |
| 283 | // in the hashed offset computations. |
| 284 | static Entry* entry(Entry* table, int offset) { |
| 285 | const int shift_amount = kPointerSizeLog2 + 1 - String::kHashShift; |
| 286 | return reinterpret_cast<Entry*>( |
| 287 | reinterpret_cast<Address>(table) + (offset << shift_amount)); |
| 288 | } |
| 289 | }; |
| 290 | |
| 291 | |
| 292 | class SCTableReference { |
| 293 | public: |
| 294 | static SCTableReference keyReference(StubCache::Table table) { |
| 295 | return SCTableReference( |
| 296 | reinterpret_cast<Address>(&first_entry(table)->key)); |
| 297 | } |
| 298 | |
| 299 | |
| 300 | static SCTableReference valueReference(StubCache::Table table) { |
| 301 | return SCTableReference( |
| 302 | reinterpret_cast<Address>(&first_entry(table)->value)); |
| 303 | } |
| 304 | |
| 305 | Address address() const { return address_; } |
| 306 | |
| 307 | private: |
| 308 | explicit SCTableReference(Address address) : address_(address) {} |
| 309 | |
| 310 | static StubCache::Entry* first_entry(StubCache::Table table) { |
| 311 | switch (table) { |
| 312 | case StubCache::kPrimary: return StubCache::primary_; |
| 313 | case StubCache::kSecondary: return StubCache::secondary_; |
| 314 | } |
| 315 | UNREACHABLE(); |
| 316 | return NULL; |
| 317 | } |
| 318 | |
| 319 | Address address_; |
| 320 | }; |
| 321 | |
| 322 | // ------------------------------------------------------------------------ |
| 323 | |
| 324 | |
| 325 | // Support functions for IC stubs for callbacks. |
| 326 | Object* LoadCallbackProperty(Arguments args); |
| 327 | Object* StoreCallbackProperty(Arguments args); |
| 328 | |
| 329 | |
| 330 | // Support functions for IC stubs for interceptors. |
| 331 | Object* LoadPropertyWithInterceptorOnly(Arguments args); |
| 332 | Object* LoadPropertyWithInterceptorForLoad(Arguments args); |
| 333 | Object* LoadPropertyWithInterceptorForCall(Arguments args); |
| 334 | Object* StoreInterceptorProperty(Arguments args); |
| 335 | Object* CallInterceptorProperty(Arguments args); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 336 | Object* KeyedLoadPropertyWithInterceptor(Arguments args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 337 | |
| 338 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 339 | // The stub compiler compiles stubs for the stub cache. |
| 340 | class StubCompiler BASE_EMBEDDED { |
| 341 | public: |
| 342 | enum CheckType { |
| 343 | RECEIVER_MAP_CHECK, |
| 344 | STRING_CHECK, |
| 345 | NUMBER_CHECK, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 346 | BOOLEAN_CHECK |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | StubCompiler() : scope_(), masm_(NULL, 256), failure_(NULL) { } |
| 350 | |
| 351 | Object* CompileCallInitialize(Code::Flags flags); |
| 352 | Object* CompileCallPreMonomorphic(Code::Flags flags); |
| 353 | Object* CompileCallNormal(Code::Flags flags); |
| 354 | Object* CompileCallMegamorphic(Code::Flags flags); |
| 355 | Object* CompileCallMiss(Code::Flags flags); |
| 356 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 357 | Object* CompileCallDebugBreak(Code::Flags flags); |
| 358 | Object* CompileCallDebugPrepareStepIn(Code::Flags flags); |
| 359 | #endif |
| 360 | Object* CompileLazyCompile(Code::Flags flags); |
| 361 | |
| 362 | // Static functions for generating parts of stubs. |
| 363 | static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, |
| 364 | int index, |
| 365 | Register prototype); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 366 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 367 | // Generates prototype loading code that uses the objects from the |
| 368 | // context we were in when this function was called. This ties the |
| 369 | // generated code to a particular context and so must not be used in |
| 370 | // cases where the generated code is not allowed to have references |
| 371 | // to objects from a context. |
| 372 | static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, |
| 373 | int index, |
| 374 | Register prototype); |
| 375 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 376 | static void GenerateFastPropertyLoad(MacroAssembler* masm, |
| 377 | Register dst, Register src, |
| 378 | JSObject* holder, int index); |
| 379 | |
| 380 | static void GenerateLoadArrayLength(MacroAssembler* masm, |
| 381 | Register receiver, |
| 382 | Register scratch, |
| 383 | Label* miss_label); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 384 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 385 | static void GenerateLoadStringLength(MacroAssembler* masm, |
| 386 | Register receiver, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 387 | Register scratch1, |
| 388 | Register scratch2, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 389 | Label* miss_label); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 390 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 391 | static void GenerateLoadFunctionPrototype(MacroAssembler* masm, |
| 392 | Register receiver, |
| 393 | Register scratch1, |
| 394 | Register scratch2, |
| 395 | Label* miss_label); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 396 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 397 | static void GenerateStoreField(MacroAssembler* masm, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 398 | JSObject* object, |
| 399 | int index, |
| 400 | Map* transition, |
| 401 | Register receiver_reg, |
| 402 | Register name_reg, |
| 403 | Register scratch, |
| 404 | Label* miss_label); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 405 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 406 | static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); |
| 407 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 408 | // Generates code that verifies that the property holder has not changed |
| 409 | // (checking maps of objects in the prototype chain for fast and global |
| 410 | // objects or doing negative lookup for slow objects, ensures that the |
| 411 | // property cells for global objects are still empty) and checks that the map |
| 412 | // of the holder has not changed. If necessary the function also generates |
| 413 | // code for security check in case of global object holders. Helps to make |
| 414 | // sure that the current IC is still valid. |
| 415 | // |
| 416 | // The scratch and holder registers are always clobbered, but the object |
| 417 | // register is only clobbered if it the same as the holder register. The |
| 418 | // function returns a register containing the holder - either object_reg or |
| 419 | // holder_reg. |
| 420 | // The function can optionally (when save_at_depth != |
| 421 | // kInvalidProtoDepth) save the object at the given depth by moving |
| 422 | // it to [esp + kPointerSize]. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 423 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 424 | Register CheckPrototypes(JSObject* object, |
| 425 | Register object_reg, |
| 426 | JSObject* holder, |
| 427 | Register holder_reg, |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 428 | Register scratch1, |
| 429 | Register scratch2, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 430 | String* name, |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 431 | Label* miss) { |
| 432 | return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, |
| 433 | scratch2, name, kInvalidProtoDepth, miss); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | Register CheckPrototypes(JSObject* object, |
| 437 | Register object_reg, |
| 438 | JSObject* holder, |
| 439 | Register holder_reg, |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 440 | Register scratch1, |
| 441 | Register scratch2, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 442 | String* name, |
| 443 | int save_at_depth, |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 444 | Label* miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 445 | |
| 446 | protected: |
| 447 | Object* GetCodeWithFlags(Code::Flags flags, const char* name); |
| 448 | Object* GetCodeWithFlags(Code::Flags flags, String* name); |
| 449 | |
| 450 | MacroAssembler* masm() { return &masm_; } |
| 451 | void set_failure(Failure* failure) { failure_ = failure; } |
| 452 | |
| 453 | void GenerateLoadField(JSObject* object, |
| 454 | JSObject* holder, |
| 455 | Register receiver, |
| 456 | Register scratch1, |
| 457 | Register scratch2, |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 458 | Register scratch3, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 459 | int index, |
| 460 | String* name, |
| 461 | Label* miss); |
| 462 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 463 | bool GenerateLoadCallback(JSObject* object, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 464 | JSObject* holder, |
| 465 | Register receiver, |
| 466 | Register name_reg, |
| 467 | Register scratch1, |
| 468 | Register scratch2, |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 469 | Register scratch3, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 470 | AccessorInfo* callback, |
| 471 | String* name, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 472 | Label* miss, |
| 473 | Failure** failure); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 474 | |
| 475 | void GenerateLoadConstant(JSObject* object, |
| 476 | JSObject* holder, |
| 477 | Register receiver, |
| 478 | Register scratch1, |
| 479 | Register scratch2, |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 480 | Register scratch3, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 481 | Object* value, |
| 482 | String* name, |
| 483 | Label* miss); |
| 484 | |
| 485 | void GenerateLoadInterceptor(JSObject* object, |
| 486 | JSObject* holder, |
| 487 | LookupResult* lookup, |
| 488 | Register receiver, |
| 489 | Register name_reg, |
| 490 | Register scratch1, |
| 491 | Register scratch2, |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 492 | Register scratch3, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 493 | String* name, |
| 494 | Label* miss); |
| 495 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 496 | static void LookupPostInterceptor(JSObject* holder, |
| 497 | String* name, |
| 498 | LookupResult* lookup); |
| 499 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 500 | private: |
| 501 | HandleScope scope_; |
| 502 | MacroAssembler masm_; |
| 503 | Failure* failure_; |
| 504 | }; |
| 505 | |
| 506 | |
| 507 | class LoadStubCompiler: public StubCompiler { |
| 508 | public: |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 509 | Object* CompileLoadNonexistent(String* name, |
| 510 | JSObject* object, |
| 511 | JSObject* last); |
| 512 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 513 | Object* CompileLoadField(JSObject* object, |
| 514 | JSObject* holder, |
| 515 | int index, |
| 516 | String* name); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 517 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 518 | Object* CompileLoadCallback(String* name, |
| 519 | JSObject* object, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 520 | JSObject* holder, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 521 | AccessorInfo* callback); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 522 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 523 | Object* CompileLoadConstant(JSObject* object, |
| 524 | JSObject* holder, |
| 525 | Object* value, |
| 526 | String* name); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 527 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 528 | Object* CompileLoadInterceptor(JSObject* object, |
| 529 | JSObject* holder, |
| 530 | String* name); |
| 531 | |
| 532 | Object* CompileLoadGlobal(JSObject* object, |
| 533 | GlobalObject* holder, |
| 534 | JSGlobalPropertyCell* cell, |
| 535 | String* name, |
| 536 | bool is_dont_delete); |
| 537 | |
| 538 | private: |
| 539 | Object* GetCode(PropertyType type, String* name); |
| 540 | }; |
| 541 | |
| 542 | |
| 543 | class KeyedLoadStubCompiler: public StubCompiler { |
| 544 | public: |
| 545 | Object* CompileLoadField(String* name, |
| 546 | JSObject* object, |
| 547 | JSObject* holder, |
| 548 | int index); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 549 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | Object* CompileLoadCallback(String* name, |
| 551 | JSObject* object, |
| 552 | JSObject* holder, |
| 553 | AccessorInfo* callback); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 554 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 555 | Object* CompileLoadConstant(String* name, |
| 556 | JSObject* object, |
| 557 | JSObject* holder, |
| 558 | Object* value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 559 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 560 | Object* CompileLoadInterceptor(JSObject* object, |
| 561 | JSObject* holder, |
| 562 | String* name); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 563 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 564 | Object* CompileLoadArrayLength(String* name); |
| 565 | Object* CompileLoadStringLength(String* name); |
| 566 | Object* CompileLoadFunctionPrototype(String* name); |
| 567 | |
| 568 | private: |
| 569 | Object* GetCode(PropertyType type, String* name); |
| 570 | }; |
| 571 | |
| 572 | |
| 573 | class StoreStubCompiler: public StubCompiler { |
| 574 | public: |
| 575 | Object* CompileStoreField(JSObject* object, |
| 576 | int index, |
| 577 | Map* transition, |
| 578 | String* name); |
| 579 | Object* CompileStoreCallback(JSObject* object, |
| 580 | AccessorInfo* callbacks, |
| 581 | String* name); |
| 582 | Object* CompileStoreInterceptor(JSObject* object, String* name); |
| 583 | Object* CompileStoreGlobal(GlobalObject* object, |
| 584 | JSGlobalPropertyCell* holder, |
| 585 | String* name); |
| 586 | |
| 587 | |
| 588 | private: |
| 589 | Object* GetCode(PropertyType type, String* name); |
| 590 | }; |
| 591 | |
| 592 | |
| 593 | class KeyedStoreStubCompiler: public StubCompiler { |
| 594 | public: |
| 595 | Object* CompileStoreField(JSObject* object, |
| 596 | int index, |
| 597 | Map* transition, |
| 598 | String* name); |
| 599 | |
| 600 | private: |
| 601 | Object* GetCode(PropertyType type, String* name); |
| 602 | }; |
| 603 | |
| 604 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 605 | // List of functions with custom constant call IC stubs. |
| 606 | // |
| 607 | // Installation of custom call generators for the selected builtins is |
| 608 | // handled by the bootstrapper. |
| 609 | // |
| 610 | // Each entry has a name of a global function (lowercased), a name of |
| 611 | // a builtin function on its instance prototype (the one the generator |
| 612 | // is set for), and a name of a generator itself (used to build ids |
| 613 | // and generator function names). |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 614 | #define CUSTOM_CALL_IC_GENERATORS(V) \ |
| 615 | V(array, push, ArrayPush) \ |
| 616 | V(array, pop, ArrayPop) \ |
| 617 | V(string, charCodeAt, StringCharCodeAt) \ |
| 618 | V(string, charAt, StringCharAt) |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 619 | |
| 620 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 621 | class CallStubCompiler: public StubCompiler { |
| 622 | public: |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 623 | enum { |
| 624 | #define DECLARE_CALL_GENERATOR_ID(ignored1, ignored2, name) \ |
| 625 | k##name##CallGenerator, |
| 626 | CUSTOM_CALL_IC_GENERATORS(DECLARE_CALL_GENERATOR_ID) |
| 627 | #undef DECLARE_CALL_GENERATOR_ID |
| 628 | kNumCallGenerators |
| 629 | }; |
| 630 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 631 | CallStubCompiler(int argc, |
| 632 | InLoopFlag in_loop, |
| 633 | Code::Kind kind, |
| 634 | InlineCacheHolderFlag cache_holder); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 635 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 636 | Object* CompileCallField(JSObject* object, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 637 | JSObject* holder, |
| 638 | int index, |
| 639 | String* name); |
| 640 | Object* CompileCallConstant(Object* object, |
| 641 | JSObject* holder, |
| 642 | JSFunction* function, |
| 643 | String* name, |
| 644 | CheckType check); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 645 | Object* CompileCallInterceptor(JSObject* object, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 646 | JSObject* holder, |
| 647 | String* name); |
| 648 | Object* CompileCallGlobal(JSObject* object, |
| 649 | GlobalObject* holder, |
| 650 | JSGlobalPropertyCell* cell, |
| 651 | JSFunction* function, |
| 652 | String* name); |
| 653 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 654 | // Compiles a custom call constant IC using the generator with given id. |
| 655 | Object* CompileCustomCall(int generator_id, |
| 656 | Object* object, |
| 657 | JSObject* holder, |
| 658 | JSFunction* function, |
| 659 | String* name, |
| 660 | CheckType check); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 661 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 662 | #define DECLARE_CALL_GENERATOR(ignored1, ignored2, name) \ |
| 663 | Object* Compile##name##Call(Object* object, \ |
| 664 | JSObject* holder, \ |
| 665 | JSFunction* function, \ |
| 666 | String* fname, \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 667 | CheckType check); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 668 | CUSTOM_CALL_IC_GENERATORS(DECLARE_CALL_GENERATOR) |
| 669 | #undef DECLARE_CALL_GENERATOR |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 670 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 671 | private: |
| 672 | const ParameterCount arguments_; |
| 673 | const InLoopFlag in_loop_; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 674 | const Code::Kind kind_; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 675 | const InlineCacheHolderFlag cache_holder_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 676 | |
| 677 | const ParameterCount& arguments() { return arguments_; } |
| 678 | |
| 679 | Object* GetCode(PropertyType type, String* name); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 680 | |
| 681 | // Convenience function. Calls GetCode above passing |
| 682 | // CONSTANT_FUNCTION type and the name of the given function. |
| 683 | Object* GetCode(JSFunction* function); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 684 | |
| 685 | void GenerateNameCheck(String* name, Label* miss); |
| 686 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame^] | 687 | // Generates a jump to CallIC miss stub. Returns Failure if the jump cannot |
| 688 | // be generated. |
| 689 | Object* GenerateMissBranch(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 690 | }; |
| 691 | |
| 692 | |
| 693 | class ConstructStubCompiler: public StubCompiler { |
| 694 | public: |
| 695 | explicit ConstructStubCompiler() {} |
| 696 | |
| 697 | Object* CompileConstructStub(SharedFunctionInfo* shared); |
| 698 | |
| 699 | private: |
| 700 | Object* GetCode(); |
| 701 | }; |
| 702 | |
| 703 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 704 | // Holds information about possible function call optimizations. |
| 705 | class CallOptimization BASE_EMBEDDED { |
| 706 | public: |
| 707 | explicit CallOptimization(LookupResult* lookup); |
| 708 | |
| 709 | explicit CallOptimization(JSFunction* function); |
| 710 | |
| 711 | bool is_constant_call() const { |
| 712 | return constant_function_ != NULL; |
| 713 | } |
| 714 | |
| 715 | JSFunction* constant_function() const { |
| 716 | ASSERT(constant_function_ != NULL); |
| 717 | return constant_function_; |
| 718 | } |
| 719 | |
| 720 | bool is_simple_api_call() const { |
| 721 | return is_simple_api_call_; |
| 722 | } |
| 723 | |
| 724 | FunctionTemplateInfo* expected_receiver_type() const { |
| 725 | ASSERT(is_simple_api_call_); |
| 726 | return expected_receiver_type_; |
| 727 | } |
| 728 | |
| 729 | CallHandlerInfo* api_call_info() const { |
| 730 | ASSERT(is_simple_api_call_); |
| 731 | return api_call_info_; |
| 732 | } |
| 733 | |
| 734 | // Returns the depth of the object having the expected type in the |
| 735 | // prototype chain between the two arguments. |
| 736 | int GetPrototypeDepthOfExpectedType(JSObject* object, |
| 737 | JSObject* holder) const; |
| 738 | |
| 739 | private: |
| 740 | void Initialize(JSFunction* function); |
| 741 | |
| 742 | // Determines whether the given function can be called using the |
| 743 | // fast api call builtin. |
| 744 | void AnalyzePossibleApiFunction(JSFunction* function); |
| 745 | |
| 746 | JSFunction* constant_function_; |
| 747 | bool is_simple_api_call_; |
| 748 | FunctionTemplateInfo* expected_receiver_type_; |
| 749 | CallHandlerInfo* api_call_info_; |
| 750 | }; |
| 751 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 752 | } } // namespace v8::internal |
| 753 | |
| 754 | #endif // V8_STUB_CACHE_H_ |