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