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, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 196 | Code::ExtraICState extra_ic_state, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 197 | Handle<Object> object, |
| 198 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 199 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 200 | protected: |
| 201 | Code::Kind kind_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 202 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 203 | bool TryUpdateExtraICState(LookupResult* lookup, |
| 204 | Handle<Object> object, |
| 205 | Code::ExtraICState* extra_ic_state); |
| 206 | |
| 207 | MUST_USE_RESULT MaybeObject* ComputeMonomorphicStub( |
| 208 | LookupResult* lookup, |
| 209 | State state, |
| 210 | Code::ExtraICState extra_ic_state, |
| 211 | Handle<Object> object, |
| 212 | Handle<String> name); |
| 213 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 214 | // Update the inline cache and the global stub cache based on the |
| 215 | // lookup result. |
| 216 | void UpdateCaches(LookupResult* lookup, |
| 217 | State state, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 218 | Code::ExtraICState extra_ic_state, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 219 | Handle<Object> object, |
| 220 | Handle<String> name); |
| 221 | |
| 222 | // Returns a JSFunction if the object can be called as a function, |
| 223 | // and patches the stack to be ready for the call. |
| 224 | // Otherwise, it returns the undefined value. |
| 225 | Object* TryCallAsFunction(Object* object); |
| 226 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 227 | void ReceiverToObjectIfRequired(Handle<Object> callee, Handle<Object> object); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 228 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 229 | static void Clear(Address address, Code* target); |
| 230 | friend class IC; |
| 231 | }; |
| 232 | |
| 233 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 234 | class CallIC: public CallICBase { |
| 235 | public: |
| 236 | CallIC() : CallICBase(Code::CALL_IC) { ASSERT(target()->is_call_stub()); } |
| 237 | |
| 238 | // Code generator routines. |
| 239 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 240 | GenerateMiss(masm, argc); |
| 241 | } |
| 242 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 243 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 244 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 245 | }; |
| 246 | |
| 247 | |
| 248 | class KeyedCallIC: public CallICBase { |
| 249 | public: |
| 250 | KeyedCallIC() : CallICBase(Code::KEYED_CALL_IC) { |
| 251 | ASSERT(target()->is_keyed_call_stub()); |
| 252 | } |
| 253 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 254 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
| 255 | Handle<Object> object, |
| 256 | Handle<Object> key); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 257 | |
| 258 | // Code generator routines. |
| 259 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 260 | GenerateMiss(masm, argc); |
| 261 | } |
| 262 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 263 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 264 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 265 | }; |
| 266 | |
| 267 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | class LoadIC: public IC { |
| 269 | public: |
| 270 | LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); } |
| 271 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 272 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 273 | Handle<Object> object, |
| 274 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 275 | |
| 276 | // Code generator routines. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 277 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 278 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 279 | GenerateMiss(masm); |
| 280 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 281 | static void GenerateMiss(MacroAssembler* masm); |
| 282 | static void GenerateMegamorphic(MacroAssembler* masm); |
| 283 | static void GenerateNormal(MacroAssembler* masm); |
| 284 | |
| 285 | // Specialized code generator routines. |
| 286 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 287 | static void GenerateStringLength(MacroAssembler* masm, |
| 288 | bool support_wrappers); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 289 | static void GenerateFunctionPrototype(MacroAssembler* masm); |
| 290 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 291 | // Clear the use of the inlined version. |
| 292 | static void ClearInlinedVersion(Address address); |
| 293 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 294 | // The offset from the inlined patch site to the start of the |
| 295 | // inlined load instruction. It is architecture-dependent, and not |
| 296 | // used on ARM. |
| 297 | static const int kOffsetToLoadInstruction; |
| 298 | |
| 299 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 300 | // Update the inline cache and the global stub cache based on the |
| 301 | // lookup result. |
| 302 | void UpdateCaches(LookupResult* lookup, |
| 303 | State state, |
| 304 | Handle<Object> object, |
| 305 | Handle<String> name); |
| 306 | |
| 307 | // Stub accessors. |
| 308 | static Code* megamorphic_stub() { |
| 309 | return Builtins::builtin(Builtins::LoadIC_Megamorphic); |
| 310 | } |
| 311 | static Code* initialize_stub() { |
| 312 | return Builtins::builtin(Builtins::LoadIC_Initialize); |
| 313 | } |
| 314 | static Code* pre_monomorphic_stub() { |
| 315 | return Builtins::builtin(Builtins::LoadIC_PreMonomorphic); |
| 316 | } |
| 317 | |
| 318 | static void Clear(Address address, Code* target); |
| 319 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 320 | static bool PatchInlinedLoad(Address address, Object* map, int index); |
| 321 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 322 | static bool PatchInlinedContextualLoad(Address address, |
| 323 | Object* map, |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 324 | Object* cell, |
| 325 | bool is_dont_delete); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 326 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | friend class IC; |
| 328 | }; |
| 329 | |
| 330 | |
| 331 | class KeyedLoadIC: public IC { |
| 332 | public: |
| 333 | KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); } |
| 334 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 335 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 336 | Handle<Object> object, |
| 337 | Handle<Object> key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 338 | |
| 339 | // Code generator routines. |
| 340 | static void GenerateMiss(MacroAssembler* masm); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 341 | static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
| 342 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 343 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 344 | GenerateMiss(masm); |
| 345 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 346 | static void GenerateGeneric(MacroAssembler* masm); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 347 | static void GenerateString(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 348 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 349 | static void GenerateIndexedInterceptor(MacroAssembler* masm); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 350 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 351 | // Clear the use of the inlined version. |
| 352 | static void ClearInlinedVersion(Address address); |
| 353 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 354 | // Bit mask to be tested against bit field for the cases when |
| 355 | // generic stub should go into slow case. |
| 356 | // Access check is necessary explicitly since generic stub does not perform |
| 357 | // map checks. |
| 358 | static const int kSlowCaseBitFieldMask = |
| 359 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 360 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 361 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 362 | // Update the inline cache. |
| 363 | void UpdateCaches(LookupResult* lookup, |
| 364 | State state, |
| 365 | Handle<Object> object, |
| 366 | Handle<String> name); |
| 367 | |
| 368 | // Stub accessors. |
| 369 | static Code* initialize_stub() { |
| 370 | return Builtins::builtin(Builtins::KeyedLoadIC_Initialize); |
| 371 | } |
| 372 | static Code* megamorphic_stub() { |
| 373 | return Builtins::builtin(Builtins::KeyedLoadIC_Generic); |
| 374 | } |
| 375 | static Code* generic_stub() { |
| 376 | return Builtins::builtin(Builtins::KeyedLoadIC_Generic); |
| 377 | } |
| 378 | static Code* pre_monomorphic_stub() { |
| 379 | return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic); |
| 380 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 381 | static Code* string_stub() { |
| 382 | return Builtins::builtin(Builtins::KeyedLoadIC_String); |
| 383 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 384 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 385 | static Code* indexed_interceptor_stub() { |
| 386 | return Builtins::builtin(Builtins::KeyedLoadIC_IndexedInterceptor); |
| 387 | } |
| 388 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 389 | static void Clear(Address address, Code* target); |
| 390 | |
| 391 | // Support for patching the map that is checked in an inlined |
| 392 | // version of keyed load. |
| 393 | static bool PatchInlinedLoad(Address address, Object* map); |
| 394 | |
| 395 | friend class IC; |
| 396 | }; |
| 397 | |
| 398 | |
| 399 | class StoreIC: public IC { |
| 400 | public: |
| 401 | StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); } |
| 402 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 403 | MUST_USE_RESULT MaybeObject* Store(State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 404 | StrictModeFlag strict_mode, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 405 | Handle<Object> object, |
| 406 | Handle<String> name, |
| 407 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 408 | |
| 409 | // Code generators for stub routines. Only called once at startup. |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 410 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 411 | static void GenerateMiss(MacroAssembler* masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 412 | static void GenerateMegamorphic(MacroAssembler* masm, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 413 | StrictModeFlag strict_mode); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 414 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 415 | static void GenerateNormal(MacroAssembler* masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 416 | static void GenerateGlobalProxy(MacroAssembler* masm, |
| 417 | StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 418 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 419 | // Clear the use of an inlined version. |
| 420 | static void ClearInlinedVersion(Address address); |
| 421 | |
| 422 | // The offset from the inlined patch site to the start of the |
| 423 | // inlined store instruction. |
| 424 | static const int kOffsetToStoreInstruction; |
| 425 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 426 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 427 | // Update the inline cache and the global stub cache based on the |
| 428 | // lookup result. |
| 429 | void UpdateCaches(LookupResult* lookup, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 430 | State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 431 | StrictModeFlag strict_mode, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 432 | Handle<JSObject> receiver, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 433 | Handle<String> name, |
| 434 | Handle<Object> value); |
| 435 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 436 | void set_target(Code* code) { |
| 437 | // Strict mode must be preserved across IC patching. |
| 438 | ASSERT((code->extra_ic_state() & kStrictMode) == |
| 439 | (target()->extra_ic_state() & kStrictMode)); |
| 440 | IC::set_target(code); |
| 441 | } |
| 442 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | // Stub accessors. |
| 444 | static Code* megamorphic_stub() { |
| 445 | return Builtins::builtin(Builtins::StoreIC_Megamorphic); |
| 446 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 447 | static Code* megamorphic_stub_strict() { |
| 448 | return Builtins::builtin(Builtins::StoreIC_Megamorphic_Strict); |
| 449 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 450 | static Code* initialize_stub() { |
| 451 | return Builtins::builtin(Builtins::StoreIC_Initialize); |
| 452 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 453 | static Code* initialize_stub_strict() { |
| 454 | return Builtins::builtin(Builtins::StoreIC_Initialize_Strict); |
| 455 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 456 | static Code* global_proxy_stub() { |
| 457 | return Builtins::builtin(Builtins::StoreIC_GlobalProxy); |
| 458 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 459 | static Code* global_proxy_stub_strict() { |
| 460 | return Builtins::builtin(Builtins::StoreIC_GlobalProxy_Strict); |
| 461 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | |
| 463 | static void Clear(Address address, Code* target); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 464 | |
| 465 | // Support for patching the index and the map that is checked in an |
| 466 | // inlined version of the named store. |
| 467 | static bool PatchInlinedStore(Address address, Object* map, int index); |
| 468 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 469 | friend class IC; |
| 470 | }; |
| 471 | |
| 472 | |
| 473 | class KeyedStoreIC: public IC { |
| 474 | public: |
| 475 | KeyedStoreIC() : IC(NO_EXTRA_FRAME) { } |
| 476 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 477 | MUST_USE_RESULT MaybeObject* Store(State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 478 | StrictModeFlag strict_mode, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 479 | Handle<Object> object, |
| 480 | Handle<Object> name, |
| 481 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 482 | |
| 483 | // Code generators for stub routines. Only called once at startup. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 484 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 485 | static void GenerateMiss(MacroAssembler* masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 486 | static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 487 | StrictModeFlag strict_mode); |
| 488 | static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 489 | |
| 490 | // Clear the inlined version so the IC is always hit. |
| 491 | static void ClearInlinedVersion(Address address); |
| 492 | |
| 493 | // Restore the inlined version so the fast case can get hit. |
| 494 | static void RestoreInlinedVersion(Address address); |
| 495 | |
| 496 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | // Update the inline cache. |
| 498 | void UpdateCaches(LookupResult* lookup, |
| 499 | State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 500 | StrictModeFlag strict_mode, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 501 | Handle<JSObject> receiver, |
| 502 | Handle<String> name, |
| 503 | Handle<Object> value); |
| 504 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 505 | void set_target(Code* code) { |
| 506 | // Strict mode must be preserved across IC patching. |
| 507 | ASSERT((code->extra_ic_state() & kStrictMode) == |
| 508 | (target()->extra_ic_state() & kStrictMode)); |
| 509 | IC::set_target(code); |
| 510 | } |
| 511 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 512 | // Stub accessors. |
| 513 | static Code* initialize_stub() { |
| 514 | return Builtins::builtin(Builtins::KeyedStoreIC_Initialize); |
| 515 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 516 | static Code* initialize_stub_strict() { |
| 517 | return Builtins::builtin(Builtins::KeyedStoreIC_Initialize_Strict); |
| 518 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 519 | static Code* megamorphic_stub() { |
| 520 | return Builtins::builtin(Builtins::KeyedStoreIC_Generic); |
| 521 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 522 | static Code* megamorphic_stub_strict() { |
| 523 | return Builtins::builtin(Builtins::KeyedStoreIC_Generic_Strict); |
| 524 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 525 | static Code* generic_stub() { |
| 526 | return Builtins::builtin(Builtins::KeyedStoreIC_Generic); |
| 527 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame^] | 528 | static Code* generic_stub_strict() { |
| 529 | return Builtins::builtin(Builtins::KeyedStoreIC_Generic_Strict); |
| 530 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 531 | |
| 532 | static void Clear(Address address, Code* target); |
| 533 | |
| 534 | // Support for patching the map that is checked in an inlined |
| 535 | // version of keyed store. |
| 536 | // The address is the patch point for the IC call |
| 537 | // (Assembler::kCallTargetAddressOffset before the end of |
| 538 | // the call/return address). |
| 539 | // The map is the new map that the inlined code should check against. |
| 540 | static bool PatchInlinedStore(Address address, Object* map); |
| 541 | |
| 542 | friend class IC; |
| 543 | }; |
| 544 | |
| 545 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 546 | class BinaryOpIC: public IC { |
| 547 | public: |
| 548 | |
| 549 | enum TypeInfo { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 550 | UNINIT_OR_SMI, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 551 | DEFAULT, // Initial state. When first executed, patches to one |
| 552 | // of the following states depending on the operands types. |
| 553 | HEAP_NUMBERS, // Both arguments are HeapNumbers. |
| 554 | STRINGS, // At least one of the arguments is String. |
| 555 | GENERIC // Non-specialized case (processes any type combination). |
| 556 | }; |
| 557 | |
| 558 | BinaryOpIC() : IC(NO_EXTRA_FRAME) { } |
| 559 | |
| 560 | void patch(Code* code); |
| 561 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 562 | static const char* GetName(TypeInfo type_info); |
| 563 | |
| 564 | static State ToState(TypeInfo type_info); |
| 565 | |
| 566 | static TypeInfo GetTypeInfo(Object* left, Object* right); |
| 567 | }; |
| 568 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 569 | |
| 570 | // Type Recording BinaryOpIC, that records the types of the inputs and outputs. |
| 571 | class TRBinaryOpIC: public IC { |
| 572 | public: |
| 573 | |
| 574 | enum TypeInfo { |
| 575 | UNINITIALIZED, |
| 576 | SMI, |
| 577 | INT32, |
| 578 | HEAP_NUMBER, |
| 579 | STRING, // Only used for addition operation. At least one string operand. |
| 580 | GENERIC |
| 581 | }; |
| 582 | |
| 583 | TRBinaryOpIC() : IC(NO_EXTRA_FRAME) { } |
| 584 | |
| 585 | void patch(Code* code); |
| 586 | |
| 587 | static const char* GetName(TypeInfo type_info); |
| 588 | |
| 589 | static State ToState(TypeInfo type_info); |
| 590 | |
| 591 | static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right); |
| 592 | |
| 593 | static TypeInfo JoinTypes(TypeInfo x, TypeInfo y); |
| 594 | }; |
| 595 | |
| 596 | |
| 597 | class CompareIC: public IC { |
| 598 | public: |
| 599 | enum State { |
| 600 | UNINITIALIZED, |
| 601 | SMIS, |
| 602 | HEAP_NUMBERS, |
| 603 | OBJECTS, |
| 604 | GENERIC |
| 605 | }; |
| 606 | |
| 607 | explicit CompareIC(Token::Value op) : IC(EXTRA_CALL_FRAME), op_(op) { } |
| 608 | |
| 609 | // Update the inline cache for the given operands. |
| 610 | void UpdateCaches(Handle<Object> x, Handle<Object> y); |
| 611 | |
| 612 | // Factory method for getting an uninitialized compare stub. |
| 613 | static Handle<Code> GetUninitialized(Token::Value op); |
| 614 | |
| 615 | // Helper function for computing the condition for a compare operation. |
| 616 | static Condition ComputeCondition(Token::Value op); |
| 617 | |
| 618 | // Helper function for determining the state of a compare IC. |
| 619 | static State ComputeState(Code* target); |
| 620 | |
| 621 | static const char* GetStateName(State state); |
| 622 | |
| 623 | private: |
| 624 | State TargetState(State state, bool has_inlined_smi_code, |
| 625 | Handle<Object> x, Handle<Object> y); |
| 626 | |
| 627 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 628 | Condition GetCondition() const { return ComputeCondition(op_); } |
| 629 | State GetState() { return ComputeState(target()); } |
| 630 | |
| 631 | Token::Value op_; |
| 632 | }; |
| 633 | |
| 634 | // Helper for TRBinaryOpIC and CompareIC. |
| 635 | void PatchInlinedSmiCode(Address address); |
| 636 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 637 | } } // namespace v8::internal |
| 638 | |
| 639 | #endif // V8_IC_H_ |