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