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