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); |
| 126 | static inline Map* GetCodeCacheMap(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: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 194 | Object* LoadFunction(State state, Handle<Object> object, Handle<String> name); |
| 195 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 196 | protected: |
| 197 | Code::Kind kind_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 198 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 199 | // Update the inline cache and the global stub cache based on the |
| 200 | // lookup result. |
| 201 | void UpdateCaches(LookupResult* lookup, |
| 202 | State state, |
| 203 | Handle<Object> object, |
| 204 | Handle<String> name); |
| 205 | |
| 206 | // Returns a JSFunction if the object can be called as a function, |
| 207 | // and patches the stack to be ready for the call. |
| 208 | // Otherwise, it returns the undefined value. |
| 209 | Object* TryCallAsFunction(Object* object); |
| 210 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 211 | void ReceiverToObject(Handle<Object> object); |
| 212 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 213 | static void Clear(Address address, Code* target); |
| 214 | friend class IC; |
| 215 | }; |
| 216 | |
| 217 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 218 | class CallIC: public CallICBase { |
| 219 | public: |
| 220 | CallIC() : CallICBase(Code::CALL_IC) { ASSERT(target()->is_call_stub()); } |
| 221 | |
| 222 | // Code generator routines. |
| 223 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 224 | GenerateMiss(masm, argc); |
| 225 | } |
| 226 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 227 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 228 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 229 | }; |
| 230 | |
| 231 | |
| 232 | class KeyedCallIC: public CallICBase { |
| 233 | public: |
| 234 | KeyedCallIC() : CallICBase(Code::KEYED_CALL_IC) { |
| 235 | ASSERT(target()->is_keyed_call_stub()); |
| 236 | } |
| 237 | |
| 238 | Object* LoadFunction(State state, Handle<Object> object, Handle<Object> key); |
| 239 | |
| 240 | // Code generator routines. |
| 241 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 242 | GenerateMiss(masm, argc); |
| 243 | } |
| 244 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 245 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 246 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 247 | }; |
| 248 | |
| 249 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 250 | class LoadIC: public IC { |
| 251 | public: |
| 252 | LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); } |
| 253 | |
| 254 | Object* Load(State state, Handle<Object> object, Handle<String> name); |
| 255 | |
| 256 | // Code generator routines. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 257 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 258 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 259 | GenerateMiss(masm); |
| 260 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 261 | static void GenerateMiss(MacroAssembler* masm); |
| 262 | static void GenerateMegamorphic(MacroAssembler* masm); |
| 263 | static void GenerateNormal(MacroAssembler* masm); |
| 264 | |
| 265 | // Specialized code generator routines. |
| 266 | static void GenerateArrayLength(MacroAssembler* masm); |
| 267 | static void GenerateStringLength(MacroAssembler* masm); |
| 268 | static void GenerateFunctionPrototype(MacroAssembler* masm); |
| 269 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 270 | // Clear the use of the inlined version. |
| 271 | static void ClearInlinedVersion(Address address); |
| 272 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 273 | // The offset from the inlined patch site to the start of the |
| 274 | // inlined load instruction. It is architecture-dependent, and not |
| 275 | // used on ARM. |
| 276 | static const int kOffsetToLoadInstruction; |
| 277 | |
| 278 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 279 | // Update the inline cache and the global stub cache based on the |
| 280 | // lookup result. |
| 281 | void UpdateCaches(LookupResult* lookup, |
| 282 | State state, |
| 283 | Handle<Object> object, |
| 284 | Handle<String> name); |
| 285 | |
| 286 | // Stub accessors. |
| 287 | static Code* megamorphic_stub() { |
| 288 | return Builtins::builtin(Builtins::LoadIC_Megamorphic); |
| 289 | } |
| 290 | static Code* initialize_stub() { |
| 291 | return Builtins::builtin(Builtins::LoadIC_Initialize); |
| 292 | } |
| 293 | static Code* pre_monomorphic_stub() { |
| 294 | return Builtins::builtin(Builtins::LoadIC_PreMonomorphic); |
| 295 | } |
| 296 | |
| 297 | static void Clear(Address address, Code* target); |
| 298 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | static bool PatchInlinedLoad(Address address, Object* map, int index); |
| 300 | |
| 301 | friend class IC; |
| 302 | }; |
| 303 | |
| 304 | |
| 305 | class KeyedLoadIC: public IC { |
| 306 | public: |
| 307 | KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); } |
| 308 | |
| 309 | Object* Load(State state, Handle<Object> object, Handle<Object> key); |
| 310 | |
| 311 | // Code generator routines. |
| 312 | static void GenerateMiss(MacroAssembler* masm); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 313 | static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
| 314 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 315 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 316 | GenerateMiss(masm); |
| 317 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 318 | static void GenerateGeneric(MacroAssembler* masm); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 319 | static void GenerateString(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 320 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 321 | // Generators for external array types. See objects.h. |
| 322 | // These are similar to the generic IC; they optimize the case of |
| 323 | // operating upon external array types but fall back to the runtime |
| 324 | // for all other types. |
| 325 | static void GenerateExternalArray(MacroAssembler* masm, |
| 326 | ExternalArrayType array_type); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 327 | static void GenerateIndexedInterceptor(MacroAssembler* masm); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 328 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 329 | // Clear the use of the inlined version. |
| 330 | static void ClearInlinedVersion(Address address); |
| 331 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 332 | // Bit mask to be tested against bit field for the cases when |
| 333 | // generic stub should go into slow case. |
| 334 | // Access check is necessary explicitly since generic stub does not perform |
| 335 | // map checks. |
| 336 | static const int kSlowCaseBitFieldMask = |
| 337 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 338 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 339 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 340 | // Update the inline cache. |
| 341 | void UpdateCaches(LookupResult* lookup, |
| 342 | State state, |
| 343 | Handle<Object> object, |
| 344 | Handle<String> name); |
| 345 | |
| 346 | // Stub accessors. |
| 347 | static Code* initialize_stub() { |
| 348 | return Builtins::builtin(Builtins::KeyedLoadIC_Initialize); |
| 349 | } |
| 350 | static Code* megamorphic_stub() { |
| 351 | return Builtins::builtin(Builtins::KeyedLoadIC_Generic); |
| 352 | } |
| 353 | static Code* generic_stub() { |
| 354 | return Builtins::builtin(Builtins::KeyedLoadIC_Generic); |
| 355 | } |
| 356 | static Code* pre_monomorphic_stub() { |
| 357 | return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic); |
| 358 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 359 | static Code* string_stub() { |
| 360 | return Builtins::builtin(Builtins::KeyedLoadIC_String); |
| 361 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 362 | static Code* external_array_stub(JSObject::ElementsKind elements_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 363 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 364 | static Code* indexed_interceptor_stub() { |
| 365 | return Builtins::builtin(Builtins::KeyedLoadIC_IndexedInterceptor); |
| 366 | } |
| 367 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 368 | static void Clear(Address address, Code* target); |
| 369 | |
| 370 | // Support for patching the map that is checked in an inlined |
| 371 | // version of keyed load. |
| 372 | static bool PatchInlinedLoad(Address address, Object* map); |
| 373 | |
| 374 | friend class IC; |
| 375 | }; |
| 376 | |
| 377 | |
| 378 | class StoreIC: public IC { |
| 379 | public: |
| 380 | StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); } |
| 381 | |
| 382 | Object* Store(State state, |
| 383 | Handle<Object> object, |
| 384 | Handle<String> name, |
| 385 | Handle<Object> value); |
| 386 | |
| 387 | // Code generators for stub routines. Only called once at startup. |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 388 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 389 | static void GenerateMiss(MacroAssembler* masm); |
| 390 | static void GenerateMegamorphic(MacroAssembler* masm); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 391 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 392 | static void GenerateNormal(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 393 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame^] | 394 | // Clear the use of an inlined version. |
| 395 | static void ClearInlinedVersion(Address address); |
| 396 | |
| 397 | // The offset from the inlined patch site to the start of the |
| 398 | // inlined store instruction. |
| 399 | static const int kOffsetToStoreInstruction; |
| 400 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 401 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 402 | // Update the inline cache and the global stub cache based on the |
| 403 | // lookup result. |
| 404 | void UpdateCaches(LookupResult* lookup, |
| 405 | State state, Handle<JSObject> receiver, |
| 406 | Handle<String> name, |
| 407 | Handle<Object> value); |
| 408 | |
| 409 | // Stub accessors. |
| 410 | static Code* megamorphic_stub() { |
| 411 | return Builtins::builtin(Builtins::StoreIC_Megamorphic); |
| 412 | } |
| 413 | static Code* initialize_stub() { |
| 414 | return Builtins::builtin(Builtins::StoreIC_Initialize); |
| 415 | } |
| 416 | |
| 417 | static void Clear(Address address, Code* target); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame^] | 418 | |
| 419 | // Support for patching the index and the map that is checked in an |
| 420 | // inlined version of the named store. |
| 421 | static bool PatchInlinedStore(Address address, Object* map, int index); |
| 422 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 423 | friend class IC; |
| 424 | }; |
| 425 | |
| 426 | |
| 427 | class KeyedStoreIC: public IC { |
| 428 | public: |
| 429 | KeyedStoreIC() : IC(NO_EXTRA_FRAME) { } |
| 430 | |
| 431 | Object* Store(State state, |
| 432 | Handle<Object> object, |
| 433 | Handle<Object> name, |
| 434 | Handle<Object> value); |
| 435 | |
| 436 | // Code generators for stub routines. Only called once at startup. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 437 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 438 | static void GenerateMiss(MacroAssembler* masm); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 439 | static void GenerateRuntimeSetProperty(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 440 | static void GenerateGeneric(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 441 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 442 | // Generators for external array types. See objects.h. |
| 443 | // These are similar to the generic IC; they optimize the case of |
| 444 | // operating upon external array types but fall back to the runtime |
| 445 | // for all other types. |
| 446 | static void GenerateExternalArray(MacroAssembler* masm, |
| 447 | ExternalArrayType array_type); |
| 448 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 449 | // Clear the inlined version so the IC is always hit. |
| 450 | static void ClearInlinedVersion(Address address); |
| 451 | |
| 452 | // Restore the inlined version so the fast case can get hit. |
| 453 | static void RestoreInlinedVersion(Address address); |
| 454 | |
| 455 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 456 | // Update the inline cache. |
| 457 | void UpdateCaches(LookupResult* lookup, |
| 458 | State state, |
| 459 | Handle<JSObject> receiver, |
| 460 | Handle<String> name, |
| 461 | Handle<Object> value); |
| 462 | |
| 463 | // Stub accessors. |
| 464 | static Code* initialize_stub() { |
| 465 | return Builtins::builtin(Builtins::KeyedStoreIC_Initialize); |
| 466 | } |
| 467 | static Code* megamorphic_stub() { |
| 468 | return Builtins::builtin(Builtins::KeyedStoreIC_Generic); |
| 469 | } |
| 470 | static Code* generic_stub() { |
| 471 | return Builtins::builtin(Builtins::KeyedStoreIC_Generic); |
| 472 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 473 | static Code* external_array_stub(JSObject::ElementsKind elements_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 474 | |
| 475 | static void Clear(Address address, Code* target); |
| 476 | |
| 477 | // Support for patching the map that is checked in an inlined |
| 478 | // version of keyed store. |
| 479 | // The address is the patch point for the IC call |
| 480 | // (Assembler::kCallTargetAddressOffset before the end of |
| 481 | // the call/return address). |
| 482 | // The map is the new map that the inlined code should check against. |
| 483 | static bool PatchInlinedStore(Address address, Object* map); |
| 484 | |
| 485 | friend class IC; |
| 486 | }; |
| 487 | |
| 488 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 489 | class BinaryOpIC: public IC { |
| 490 | public: |
| 491 | |
| 492 | enum TypeInfo { |
| 493 | DEFAULT, // Initial state. When first executed, patches to one |
| 494 | // of the following states depending on the operands types. |
| 495 | HEAP_NUMBERS, // Both arguments are HeapNumbers. |
| 496 | STRINGS, // At least one of the arguments is String. |
| 497 | GENERIC // Non-specialized case (processes any type combination). |
| 498 | }; |
| 499 | |
| 500 | BinaryOpIC() : IC(NO_EXTRA_FRAME) { } |
| 501 | |
| 502 | void patch(Code* code); |
| 503 | |
| 504 | static void Clear(Address address, Code* target); |
| 505 | |
| 506 | static const char* GetName(TypeInfo type_info); |
| 507 | |
| 508 | static State ToState(TypeInfo type_info); |
| 509 | |
| 510 | static TypeInfo GetTypeInfo(Object* left, Object* right); |
| 511 | }; |
| 512 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 513 | } } // namespace v8::internal |
| 514 | |
| 515 | #endif // V8_IC_H_ |