Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 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_IC_H_ |
| 29 | #define V8_IC_H_ |
| 30 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 31 | #include "macro-assembler.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | |
| 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 36 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 37 | // IC_UTIL_LIST defines all utility functions called from generated |
| 38 | // inline caching code. The argument for the macro, ICU, is the function name. |
| 39 | #define IC_UTIL_LIST(ICU) \ |
| 40 | ICU(LoadIC_Miss) \ |
| 41 | ICU(KeyedLoadIC_Miss) \ |
| 42 | ICU(CallIC_Miss) \ |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 43 | ICU(KeyedCallIC_Miss) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | ICU(StoreIC_Miss) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 45 | ICU(StoreIC_ArrayLength) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | ICU(SharedStoreIC_ExtendStorage) \ |
| 47 | ICU(KeyedStoreIC_Miss) \ |
| 48 | /* Utilities for IC stubs. */ \ |
| 49 | ICU(LoadCallbackProperty) \ |
| 50 | ICU(StoreCallbackProperty) \ |
| 51 | ICU(LoadPropertyWithInterceptorOnly) \ |
| 52 | ICU(LoadPropertyWithInterceptorForLoad) \ |
| 53 | ICU(LoadPropertyWithInterceptorForCall) \ |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 54 | ICU(KeyedLoadPropertyWithInterceptor) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 55 | ICU(StoreInterceptorProperty) \ |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 56 | ICU(BinaryOp_Patch) \ |
| 57 | ICU(TypeRecordingBinaryOp_Patch) \ |
| 58 | ICU(CompareIC_Miss) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 59 | // |
| 60 | // IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC, |
| 61 | // and KeyedStoreIC. |
| 62 | // |
| 63 | class IC { |
| 64 | public: |
| 65 | |
| 66 | // The ids for utility called from the generated code. |
| 67 | enum UtilityId { |
| 68 | #define CONST_NAME(name) k##name, |
| 69 | IC_UTIL_LIST(CONST_NAME) |
| 70 | #undef CONST_NAME |
| 71 | kUtilityCount |
| 72 | }; |
| 73 | |
| 74 | // Looks up the address of the named utility. |
| 75 | static Address AddressFromUtilityId(UtilityId id); |
| 76 | |
| 77 | // Alias the inline cache state type to make the IC code more readable. |
| 78 | typedef InlineCacheState State; |
| 79 | |
| 80 | // The IC code is either invoked with no extra frames on the stack |
| 81 | // or with a single extra frame for supporting calls. |
| 82 | enum FrameDepth { |
| 83 | NO_EXTRA_FRAME = 0, |
| 84 | EXTRA_CALL_FRAME = 1 |
| 85 | }; |
| 86 | |
| 87 | // Construct the IC structure with the given number of extra |
| 88 | // JavaScript frames on the stack. |
| 89 | explicit IC(FrameDepth depth); |
| 90 | |
| 91 | // Get the call-site target; used for determining the state. |
| 92 | Code* target() { return GetTargetAtAddress(address()); } |
| 93 | inline Address address(); |
| 94 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 95 | // Compute the current IC state based on the target stub, receiver and name. |
| 96 | static State StateFrom(Code* target, Object* receiver, Object* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 97 | |
| 98 | // Clear the inline cache to initial state. |
| 99 | static void Clear(Address address); |
| 100 | |
| 101 | // Computes the reloc info for this IC. This is a fairly expensive |
| 102 | // operation as it has to search through the heap to find the code |
| 103 | // object that contains this IC site. |
| 104 | RelocInfo::Mode ComputeMode(); |
| 105 | |
| 106 | // Returns if this IC is for contextual (no explicit receiver) |
| 107 | // access to properties. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 108 | bool IsContextual(Handle<Object> receiver) { |
| 109 | if (receiver->IsGlobalObject()) { |
| 110 | return SlowIsContextual(); |
| 111 | } else { |
| 112 | ASSERT(!SlowIsContextual()); |
| 113 | return false; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | bool SlowIsContextual() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 118 | return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT; |
| 119 | } |
| 120 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 121 | // Determines which map must be used for keeping the code stub. |
| 122 | // These methods should not be called with undefined or null. |
| 123 | static inline InlineCacheHolderFlag GetCodeCacheForObject(Object* object, |
| 124 | JSObject* holder); |
| 125 | static inline InlineCacheHolderFlag GetCodeCacheForObject(JSObject* object, |
| 126 | JSObject* holder); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 127 | static inline JSObject* GetCodeCacheHolder(Object* object, |
| 128 | InlineCacheHolderFlag holder); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 129 | |
| 130 | protected: |
| 131 | Address fp() const { return fp_; } |
| 132 | Address pc() const { return *pc_address_; } |
| 133 | |
| 134 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 135 | // Computes the address in the original code when the code running is |
| 136 | // containing break points (calls to DebugBreakXXX builtins). |
| 137 | Address OriginalCodeAddress(); |
| 138 | #endif |
| 139 | |
| 140 | // Set the call-site target. |
| 141 | void set_target(Code* code) { SetTargetAtAddress(address(), code); } |
| 142 | |
| 143 | #ifdef DEBUG |
| 144 | static void TraceIC(const char* type, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 145 | Handle<Object> name, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 146 | State old_state, |
| 147 | Code* new_target, |
| 148 | const char* extra_info = ""); |
| 149 | #endif |
| 150 | |
| 151 | static Failure* TypeError(const char* type, |
| 152 | Handle<Object> object, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 153 | Handle<Object> key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 154 | static Failure* ReferenceError(const char* type, Handle<String> name); |
| 155 | |
| 156 | // Access the target code for the given IC address. |
| 157 | static inline Code* GetTargetAtAddress(Address address); |
| 158 | static inline void SetTargetAtAddress(Address address, Code* target); |
| 159 | |
| 160 | private: |
| 161 | // Frame pointer for the frame that uses (calls) the IC. |
| 162 | Address fp_; |
| 163 | |
| 164 | // All access to the program counter of an IC structure is indirect |
| 165 | // to make the code GC safe. This feature is crucial since |
| 166 | // GetProperty and SetProperty are called and they in turn might |
| 167 | // invoke the garbage collector. |
| 168 | Address* pc_address_; |
| 169 | |
| 170 | DISALLOW_IMPLICIT_CONSTRUCTORS(IC); |
| 171 | }; |
| 172 | |
| 173 | |
| 174 | // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you |
| 175 | // cannot make forward declarations to an enum. |
| 176 | class IC_Utility { |
| 177 | public: |
| 178 | explicit IC_Utility(IC::UtilityId id) |
| 179 | : address_(IC::AddressFromUtilityId(id)), id_(id) {} |
| 180 | |
| 181 | Address address() const { return address_; } |
| 182 | |
| 183 | IC::UtilityId id() const { return id_; } |
| 184 | private: |
| 185 | Address address_; |
| 186 | IC::UtilityId id_; |
| 187 | }; |
| 188 | |
| 189 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 190 | class CallICBase: public IC { |
| 191 | protected: |
| 192 | explicit CallICBase(Code::Kind kind) : IC(EXTRA_CALL_FRAME), kind_(kind) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 193 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 194 | public: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 195 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
| 196 | Handle<Object> object, |
| 197 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 198 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 199 | protected: |
| 200 | Code::Kind kind_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 201 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 202 | // Update the inline cache and the global stub cache based on the |
| 203 | // lookup result. |
| 204 | void UpdateCaches(LookupResult* lookup, |
| 205 | State state, |
| 206 | Handle<Object> object, |
| 207 | Handle<String> name); |
| 208 | |
| 209 | // Returns a JSFunction if the object can be called as a function, |
| 210 | // and patches the stack to be ready for the call. |
| 211 | // Otherwise, it returns the undefined value. |
| 212 | Object* TryCallAsFunction(Object* object); |
| 213 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 214 | void ReceiverToObject(Handle<Object> object); |
| 215 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 216 | static void Clear(Address address, Code* target); |
| 217 | friend class IC; |
| 218 | }; |
| 219 | |
| 220 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 221 | class CallIC: public CallICBase { |
| 222 | public: |
| 223 | CallIC() : CallICBase(Code::CALL_IC) { ASSERT(target()->is_call_stub()); } |
| 224 | |
| 225 | // Code generator routines. |
| 226 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 227 | GenerateMiss(masm, argc); |
| 228 | } |
| 229 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 230 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 231 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 232 | }; |
| 233 | |
| 234 | |
| 235 | class KeyedCallIC: public CallICBase { |
| 236 | public: |
| 237 | KeyedCallIC() : CallICBase(Code::KEYED_CALL_IC) { |
| 238 | ASSERT(target()->is_keyed_call_stub()); |
| 239 | } |
| 240 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 241 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
| 242 | Handle<Object> object, |
| 243 | Handle<Object> key); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 244 | |
| 245 | // Code generator routines. |
| 246 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 247 | GenerateMiss(masm, argc); |
| 248 | } |
| 249 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 250 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 251 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 252 | }; |
| 253 | |
| 254 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 255 | class LoadIC: public IC { |
| 256 | public: |
| 257 | LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); } |
| 258 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 259 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 260 | Handle<Object> object, |
| 261 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 262 | |
| 263 | // Code generator routines. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 264 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 265 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 266 | GenerateMiss(masm); |
| 267 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | static void GenerateMiss(MacroAssembler* masm); |
| 269 | static void GenerateMegamorphic(MacroAssembler* masm); |
| 270 | static void GenerateNormal(MacroAssembler* masm); |
| 271 | |
| 272 | // Specialized code generator routines. |
| 273 | static void GenerateArrayLength(MacroAssembler* masm); |
| 274 | static void GenerateStringLength(MacroAssembler* masm); |
| 275 | static void GenerateFunctionPrototype(MacroAssembler* masm); |
| 276 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 277 | // Clear the use of the inlined version. |
| 278 | static void ClearInlinedVersion(Address address); |
| 279 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 280 | // The offset from the inlined patch site to the start of the |
| 281 | // inlined load instruction. It is architecture-dependent, and not |
| 282 | // used on ARM. |
| 283 | static const int kOffsetToLoadInstruction; |
| 284 | |
| 285 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 286 | // Update the inline cache and the global stub cache based on the |
| 287 | // lookup result. |
| 288 | void UpdateCaches(LookupResult* lookup, |
| 289 | State state, |
| 290 | Handle<Object> object, |
| 291 | Handle<String> name); |
| 292 | |
| 293 | // Stub accessors. |
| 294 | static Code* megamorphic_stub() { |
| 295 | return Builtins::builtin(Builtins::LoadIC_Megamorphic); |
| 296 | } |
| 297 | static Code* initialize_stub() { |
| 298 | return Builtins::builtin(Builtins::LoadIC_Initialize); |
| 299 | } |
| 300 | static Code* pre_monomorphic_stub() { |
| 301 | return Builtins::builtin(Builtins::LoadIC_PreMonomorphic); |
| 302 | } |
| 303 | |
| 304 | static void Clear(Address address, Code* target); |
| 305 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 306 | static bool PatchInlinedLoad(Address address, Object* map, int index); |
| 307 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 308 | static bool PatchInlinedContextualLoad(Address address, |
| 309 | Object* map, |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 310 | Object* cell, |
| 311 | bool is_dont_delete); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 312 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | friend class IC; |
| 314 | }; |
| 315 | |
| 316 | |
| 317 | class KeyedLoadIC: public IC { |
| 318 | public: |
| 319 | KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); } |
| 320 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 321 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 322 | Handle<Object> object, |
| 323 | Handle<Object> key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 324 | |
| 325 | // Code generator routines. |
| 326 | static void GenerateMiss(MacroAssembler* masm); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 327 | static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
| 328 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 329 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 330 | GenerateMiss(masm); |
| 331 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 332 | static void GenerateGeneric(MacroAssembler* masm); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 333 | static void GenerateString(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 334 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 335 | // Generators for external array types. See objects.h. |
| 336 | // These are similar to the generic IC; they optimize the case of |
| 337 | // operating upon external array types but fall back to the runtime |
| 338 | // for all other types. |
| 339 | static void GenerateExternalArray(MacroAssembler* masm, |
| 340 | ExternalArrayType array_type); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 341 | static void GenerateIndexedInterceptor(MacroAssembler* masm); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 342 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 343 | // Clear the use of the inlined version. |
| 344 | static void ClearInlinedVersion(Address address); |
| 345 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 346 | // Bit mask to be tested against bit field for the cases when |
| 347 | // generic stub should go into slow case. |
| 348 | // Access check is necessary explicitly since generic stub does not perform |
| 349 | // map checks. |
| 350 | static const int kSlowCaseBitFieldMask = |
| 351 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 352 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 353 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 354 | // Update the inline cache. |
| 355 | void UpdateCaches(LookupResult* lookup, |
| 356 | State state, |
| 357 | Handle<Object> object, |
| 358 | Handle<String> name); |
| 359 | |
| 360 | // Stub accessors. |
| 361 | static Code* initialize_stub() { |
| 362 | return Builtins::builtin(Builtins::KeyedLoadIC_Initialize); |
| 363 | } |
| 364 | static Code* megamorphic_stub() { |
| 365 | return Builtins::builtin(Builtins::KeyedLoadIC_Generic); |
| 366 | } |
| 367 | static Code* generic_stub() { |
| 368 | return Builtins::builtin(Builtins::KeyedLoadIC_Generic); |
| 369 | } |
| 370 | static Code* pre_monomorphic_stub() { |
| 371 | return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic); |
| 372 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 373 | static Code* string_stub() { |
| 374 | return Builtins::builtin(Builtins::KeyedLoadIC_String); |
| 375 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 376 | static Code* external_array_stub(JSObject::ElementsKind elements_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 377 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 378 | static Code* indexed_interceptor_stub() { |
| 379 | return Builtins::builtin(Builtins::KeyedLoadIC_IndexedInterceptor); |
| 380 | } |
| 381 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 382 | static void Clear(Address address, Code* target); |
| 383 | |
| 384 | // Support for patching the map that is checked in an inlined |
| 385 | // version of keyed load. |
| 386 | static bool PatchInlinedLoad(Address address, Object* map); |
| 387 | |
| 388 | friend class IC; |
| 389 | }; |
| 390 | |
| 391 | |
| 392 | class StoreIC: public IC { |
| 393 | public: |
| 394 | StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); } |
| 395 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 396 | MUST_USE_RESULT MaybeObject* Store(State state, |
| 397 | Handle<Object> object, |
| 398 | Handle<String> name, |
| 399 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 400 | |
| 401 | // Code generators for stub routines. Only called once at startup. |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 402 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 403 | static void GenerateMiss(MacroAssembler* masm); |
| 404 | static void GenerateMegamorphic(MacroAssembler* masm); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 405 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 406 | static void GenerateNormal(MacroAssembler* masm); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 407 | static void GenerateGlobalProxy(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 408 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 409 | // Clear the use of an inlined version. |
| 410 | static void ClearInlinedVersion(Address address); |
| 411 | |
| 412 | // The offset from the inlined patch site to the start of the |
| 413 | // inlined store instruction. |
| 414 | static const int kOffsetToStoreInstruction; |
| 415 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 416 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 417 | // Update the inline cache and the global stub cache based on the |
| 418 | // lookup result. |
| 419 | void UpdateCaches(LookupResult* lookup, |
| 420 | State state, Handle<JSObject> receiver, |
| 421 | Handle<String> name, |
| 422 | Handle<Object> value); |
| 423 | |
| 424 | // Stub accessors. |
| 425 | static Code* megamorphic_stub() { |
| 426 | return Builtins::builtin(Builtins::StoreIC_Megamorphic); |
| 427 | } |
| 428 | static Code* initialize_stub() { |
| 429 | return Builtins::builtin(Builtins::StoreIC_Initialize); |
| 430 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 431 | static Code* global_proxy_stub() { |
| 432 | return Builtins::builtin(Builtins::StoreIC_GlobalProxy); |
| 433 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 434 | |
| 435 | static void Clear(Address address, Code* target); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 436 | |
| 437 | // Support for patching the index and the map that is checked in an |
| 438 | // inlined version of the named store. |
| 439 | static bool PatchInlinedStore(Address address, Object* map, int index); |
| 440 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 441 | friend class IC; |
| 442 | }; |
| 443 | |
| 444 | |
| 445 | class KeyedStoreIC: public IC { |
| 446 | public: |
| 447 | KeyedStoreIC() : IC(NO_EXTRA_FRAME) { } |
| 448 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 449 | MUST_USE_RESULT MaybeObject* Store(State state, |
| 450 | Handle<Object> object, |
| 451 | Handle<Object> name, |
| 452 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | |
| 454 | // Code generators for stub routines. Only called once at startup. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 455 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 456 | static void GenerateMiss(MacroAssembler* masm); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 457 | static void GenerateRuntimeSetProperty(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 458 | static void GenerateGeneric(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 459 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 460 | // Generators for external array types. See objects.h. |
| 461 | // These are similar to the generic IC; they optimize the case of |
| 462 | // operating upon external array types but fall back to the runtime |
| 463 | // for all other types. |
| 464 | static void GenerateExternalArray(MacroAssembler* masm, |
| 465 | ExternalArrayType array_type); |
| 466 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 467 | // Clear the inlined version so the IC is always hit. |
| 468 | static void ClearInlinedVersion(Address address); |
| 469 | |
| 470 | // Restore the inlined version so the fast case can get hit. |
| 471 | static void RestoreInlinedVersion(Address address); |
| 472 | |
| 473 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 474 | // Update the inline cache. |
| 475 | void UpdateCaches(LookupResult* lookup, |
| 476 | State state, |
| 477 | Handle<JSObject> receiver, |
| 478 | Handle<String> name, |
| 479 | Handle<Object> value); |
| 480 | |
| 481 | // Stub accessors. |
| 482 | static Code* initialize_stub() { |
| 483 | return Builtins::builtin(Builtins::KeyedStoreIC_Initialize); |
| 484 | } |
| 485 | static Code* megamorphic_stub() { |
| 486 | return Builtins::builtin(Builtins::KeyedStoreIC_Generic); |
| 487 | } |
| 488 | static Code* generic_stub() { |
| 489 | return Builtins::builtin(Builtins::KeyedStoreIC_Generic); |
| 490 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 491 | static Code* external_array_stub(JSObject::ElementsKind elements_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 492 | |
| 493 | static void Clear(Address address, Code* target); |
| 494 | |
| 495 | // Support for patching the map that is checked in an inlined |
| 496 | // version of keyed store. |
| 497 | // The address is the patch point for the IC call |
| 498 | // (Assembler::kCallTargetAddressOffset before the end of |
| 499 | // the call/return address). |
| 500 | // The map is the new map that the inlined code should check against. |
| 501 | static bool PatchInlinedStore(Address address, Object* map); |
| 502 | |
| 503 | friend class IC; |
| 504 | }; |
| 505 | |
| 506 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 507 | class BinaryOpIC: public IC { |
| 508 | public: |
| 509 | |
| 510 | enum TypeInfo { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 511 | UNINIT_OR_SMI, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 512 | DEFAULT, // Initial state. When first executed, patches to one |
| 513 | // of the following states depending on the operands types. |
| 514 | HEAP_NUMBERS, // Both arguments are HeapNumbers. |
| 515 | STRINGS, // At least one of the arguments is String. |
| 516 | GENERIC // Non-specialized case (processes any type combination). |
| 517 | }; |
| 518 | |
| 519 | BinaryOpIC() : IC(NO_EXTRA_FRAME) { } |
| 520 | |
| 521 | void patch(Code* code); |
| 522 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 523 | static const char* GetName(TypeInfo type_info); |
| 524 | |
| 525 | static State ToState(TypeInfo type_info); |
| 526 | |
| 527 | static TypeInfo GetTypeInfo(Object* left, Object* right); |
| 528 | }; |
| 529 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 530 | |
| 531 | // Type Recording BinaryOpIC, that records the types of the inputs and outputs. |
| 532 | class TRBinaryOpIC: public IC { |
| 533 | public: |
| 534 | |
| 535 | enum TypeInfo { |
| 536 | UNINITIALIZED, |
| 537 | SMI, |
| 538 | INT32, |
| 539 | HEAP_NUMBER, |
| 540 | STRING, // Only used for addition operation. At least one string operand. |
| 541 | GENERIC |
| 542 | }; |
| 543 | |
| 544 | TRBinaryOpIC() : IC(NO_EXTRA_FRAME) { } |
| 545 | |
| 546 | void patch(Code* code); |
| 547 | |
| 548 | static const char* GetName(TypeInfo type_info); |
| 549 | |
| 550 | static State ToState(TypeInfo type_info); |
| 551 | |
| 552 | static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right); |
| 553 | |
| 554 | static TypeInfo JoinTypes(TypeInfo x, TypeInfo y); |
| 555 | }; |
| 556 | |
| 557 | |
| 558 | class CompareIC: public IC { |
| 559 | public: |
| 560 | enum State { |
| 561 | UNINITIALIZED, |
| 562 | SMIS, |
| 563 | HEAP_NUMBERS, |
| 564 | OBJECTS, |
| 565 | GENERIC |
| 566 | }; |
| 567 | |
| 568 | explicit CompareIC(Token::Value op) : IC(EXTRA_CALL_FRAME), op_(op) { } |
| 569 | |
| 570 | // Update the inline cache for the given operands. |
| 571 | void UpdateCaches(Handle<Object> x, Handle<Object> y); |
| 572 | |
| 573 | // Factory method for getting an uninitialized compare stub. |
| 574 | static Handle<Code> GetUninitialized(Token::Value op); |
| 575 | |
| 576 | // Helper function for computing the condition for a compare operation. |
| 577 | static Condition ComputeCondition(Token::Value op); |
| 578 | |
| 579 | // Helper function for determining the state of a compare IC. |
| 580 | static State ComputeState(Code* target); |
| 581 | |
| 582 | static const char* GetStateName(State state); |
| 583 | |
| 584 | private: |
| 585 | State TargetState(State state, bool has_inlined_smi_code, |
| 586 | Handle<Object> x, Handle<Object> y); |
| 587 | |
| 588 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 589 | Condition GetCondition() const { return ComputeCondition(op_); } |
| 590 | State GetState() { return ComputeState(target()); } |
| 591 | |
| 592 | Token::Value op_; |
| 593 | }; |
| 594 | |
| 595 | // Helper for TRBinaryOpIC and CompareIC. |
| 596 | void PatchInlinedSmiCode(Address address); |
| 597 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 598 | } } // namespace v8::internal |
| 599 | |
| 600 | #endif // V8_IC_H_ |