ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 31 | #include "macro-assembler.h" |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 32 | #include "type-info.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 34 | namespace v8 { |
| 35 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 37 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | // IC_UTIL_LIST defines all utility functions called from generated |
| 39 | // inline caching code. The argument for the macro, ICU, is the function name. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 40 | #define IC_UTIL_LIST(ICU) \ |
| 41 | ICU(LoadIC_Miss) \ |
| 42 | ICU(KeyedLoadIC_Miss) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 43 | ICU(KeyedLoadIC_MissForceGeneric) \ |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 44 | ICU(CallIC_Miss) \ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 45 | ICU(KeyedCallIC_Miss) \ |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 46 | ICU(StoreIC_Miss) \ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 47 | ICU(StoreIC_ArrayLength) \ |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 48 | ICU(SharedStoreIC_ExtendStorage) \ |
| 49 | ICU(KeyedStoreIC_Miss) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 50 | ICU(KeyedStoreIC_MissForceGeneric) \ |
| 51 | ICU(KeyedStoreIC_Slow) \ |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 52 | /* Utilities for IC stubs. */ \ |
| 53 | ICU(LoadCallbackProperty) \ |
| 54 | ICU(StoreCallbackProperty) \ |
| 55 | ICU(LoadPropertyWithInterceptorOnly) \ |
| 56 | ICU(LoadPropertyWithInterceptorForLoad) \ |
| 57 | ICU(LoadPropertyWithInterceptorForCall) \ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 58 | ICU(KeyedLoadPropertyWithInterceptor) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 59 | ICU(StoreInterceptorProperty) \ |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 60 | ICU(UnaryOp_Patch) \ |
| 61 | ICU(BinaryOp_Patch) \ |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 62 | ICU(CompareIC_Miss) \ |
| 63 | ICU(ToBoolean_Patch) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | // |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 65 | // IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC, |
| 66 | // and KeyedStoreIC. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 67 | // |
| 68 | class IC { |
| 69 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | // The ids for utility called from the generated code. |
| 71 | enum UtilityId { |
| 72 | #define CONST_NAME(name) k##name, |
| 73 | IC_UTIL_LIST(CONST_NAME) |
| 74 | #undef CONST_NAME |
| 75 | kUtilityCount |
| 76 | }; |
| 77 | |
| 78 | // Looks up the address of the named utility. |
| 79 | static Address AddressFromUtilityId(UtilityId id); |
| 80 | |
| 81 | // Alias the inline cache state type to make the IC code more readable. |
| 82 | typedef InlineCacheState State; |
| 83 | |
| 84 | // The IC code is either invoked with no extra frames on the stack |
| 85 | // or with a single extra frame for supporting calls. |
| 86 | enum FrameDepth { |
| 87 | NO_EXTRA_FRAME = 0, |
| 88 | EXTRA_CALL_FRAME = 1 |
| 89 | }; |
| 90 | |
| 91 | // Construct the IC structure with the given number of extra |
| 92 | // JavaScript frames on the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 93 | IC(FrameDepth depth, Isolate* isolate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 94 | virtual ~IC() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | |
| 96 | // Get the call-site target; used for determining the state. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 97 | Code* target() const { return GetTargetAtAddress(address()); } |
| 98 | inline Address address() const; |
| 99 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 100 | // Compute the current IC state based on the target stub, receiver and name. |
| 101 | static State StateFrom(Code* target, Object* receiver, Object* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 102 | |
| 103 | // Clear the inline cache to initial state. |
| 104 | static void Clear(Address address); |
| 105 | |
| 106 | // Computes the reloc info for this IC. This is a fairly expensive |
| 107 | // operation as it has to search through the heap to find the code |
| 108 | // object that contains this IC site. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 109 | RelocInfo::Mode ComputeMode(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | |
| 111 | // Returns if this IC is for contextual (no explicit receiver) |
| 112 | // access to properties. |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 113 | bool IsUndeclaredGlobal(Handle<Object> receiver) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 114 | if (receiver->IsGlobalObject()) { |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 115 | return SlowIsUndeclaredGlobal(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 116 | } else { |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 117 | ASSERT(!SlowIsUndeclaredGlobal()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 118 | return false; |
| 119 | } |
| 120 | } |
| 121 | |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 122 | bool SlowIsUndeclaredGlobal() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 123 | return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT; |
| 124 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 126 | // Determines which map must be used for keeping the code stub. |
| 127 | // These methods should not be called with undefined or null. |
| 128 | static inline InlineCacheHolderFlag GetCodeCacheForObject(Object* object, |
| 129 | JSObject* holder); |
| 130 | static inline InlineCacheHolderFlag GetCodeCacheForObject(JSObject* object, |
| 131 | JSObject* holder); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 132 | static inline JSObject* GetCodeCacheHolder(Object* object, |
| 133 | InlineCacheHolderFlag holder); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | |
| 135 | protected: |
| 136 | Address fp() const { return fp_; } |
| 137 | Address pc() const { return *pc_address_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 138 | Isolate* isolate() const { return isolate_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 140 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 141 | // Computes the address in the original code when the code running is |
| 142 | // containing break points (calls to DebugBreakXXX builtins). |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 143 | Address OriginalCodeAddress() const; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 144 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | |
| 146 | // Set the call-site target. |
| 147 | void set_target(Code* code) { SetTargetAtAddress(address(), code); } |
| 148 | |
| 149 | #ifdef DEBUG |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 150 | char TransitionMarkFromState(IC::State state); |
| 151 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 152 | void TraceIC(const char* type, |
| 153 | Handle<Object> name, |
| 154 | State old_state, |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 155 | Code* new_target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | #endif |
| 157 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 158 | Failure* TypeError(const char* type, |
| 159 | Handle<Object> object, |
| 160 | Handle<Object> key); |
| 161 | Failure* ReferenceError(const char* type, Handle<String> name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | |
| 163 | // Access the target code for the given IC address. |
| 164 | static inline Code* GetTargetAtAddress(Address address); |
| 165 | static inline void SetTargetAtAddress(Address address, Code* target); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 166 | static void PostPatching(Address address, Code* target, Code* old_target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 167 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 168 | void PatchCache(State state, |
| 169 | StrictModeFlag strict_mode, |
| 170 | Handle<JSObject> receiver, |
| 171 | Handle<String> name, |
| 172 | Handle<Code> code); |
| 173 | virtual void UpdateMegamorphicCache(Map* map, String* name, Code* code); |
| 174 | virtual Handle<Code> megamorphic_stub() { |
| 175 | UNREACHABLE(); |
| 176 | return Handle<Code>::null(); |
| 177 | } |
| 178 | virtual Handle<Code> megamorphic_stub_strict() { |
| 179 | UNREACHABLE(); |
| 180 | return Handle<Code>::null(); |
| 181 | } |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 182 | virtual Handle<Code> generic_stub() const { |
| 183 | UNREACHABLE(); |
| 184 | return Handle<Code>::null(); |
| 185 | } |
| 186 | virtual Handle<Code> generic_stub_strict() const { |
| 187 | UNREACHABLE(); |
| 188 | return Handle<Code>::null(); |
| 189 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 190 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 192 | // Frame pointer for the frame that uses (calls) the IC. |
| 193 | Address fp_; |
| 194 | |
| 195 | // All access to the program counter of an IC structure is indirect |
| 196 | // to make the code GC safe. This feature is crucial since |
| 197 | // GetProperty and SetProperty are called and they in turn might |
| 198 | // invoke the garbage collector. |
| 199 | Address* pc_address_; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 200 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 201 | Isolate* isolate_; |
| 202 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 203 | DISALLOW_IMPLICIT_CONSTRUCTORS(IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | |
| 207 | // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you |
| 208 | // cannot make forward declarations to an enum. |
| 209 | class IC_Utility { |
| 210 | public: |
| 211 | explicit IC_Utility(IC::UtilityId id) |
| 212 | : address_(IC::AddressFromUtilityId(id)), id_(id) {} |
| 213 | |
| 214 | Address address() const { return address_; } |
| 215 | |
| 216 | IC::UtilityId id() const { return id_; } |
| 217 | private: |
| 218 | Address address_; |
| 219 | IC::UtilityId id_; |
| 220 | }; |
| 221 | |
| 222 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 223 | class CallICBase: public IC { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 224 | public: |
| 225 | class Contextual: public BitField<bool, 0, 1> {}; |
| 226 | class StringStubState: public BitField<StringStubFeedback, 1, 1> {}; |
| 227 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 228 | // Returns a JSFunction or a Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 229 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 230 | Code::ExtraICState extra_ic_state, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 231 | Handle<Object> object, |
| 232 | Handle<String> name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 234 | protected: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 235 | CallICBase(Code::Kind kind, Isolate* isolate) |
| 236 | : IC(EXTRA_CALL_FRAME, isolate), kind_(kind) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 237 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 238 | bool TryUpdateExtraICState(LookupResult* lookup, |
| 239 | Handle<Object> object, |
| 240 | Code::ExtraICState* extra_ic_state); |
| 241 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 242 | // Compute a monomorphic stub if possible, otherwise return a null handle. |
| 243 | Handle<Code> ComputeMonomorphicStub(LookupResult* lookup, |
| 244 | State state, |
| 245 | Code::ExtraICState extra_state, |
| 246 | Handle<Object> object, |
| 247 | Handle<String> name); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 248 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 249 | // Update the inline cache and the global stub cache based on the lookup |
| 250 | // result. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | void UpdateCaches(LookupResult* lookup, |
| 252 | State state, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 253 | Code::ExtraICState extra_ic_state, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 254 | Handle<Object> object, |
| 255 | Handle<String> name); |
| 256 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 257 | // Returns a JSFunction if the object can be called as a function, and |
| 258 | // patches the stack to be ready for the call. Otherwise, it returns the |
| 259 | // undefined value. |
| 260 | Handle<Object> TryCallAsFunction(Handle<Object> object); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 261 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 262 | void ReceiverToObjectIfRequired(Handle<Object> callee, Handle<Object> object); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 263 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 264 | static void Clear(Address address, Code* target); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 265 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 266 | // Platform-specific code generation functions used by both call and |
| 267 | // keyed call. |
| 268 | static void GenerateMiss(MacroAssembler* masm, |
| 269 | int argc, |
| 270 | IC::UtilityId id, |
| 271 | Code::ExtraICState extra_state); |
| 272 | |
| 273 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 274 | |
| 275 | static void GenerateMonomorphicCacheProbe(MacroAssembler* masm, |
| 276 | int argc, |
| 277 | Code::Kind kind, |
| 278 | Code::ExtraICState extra_state); |
| 279 | |
| 280 | Code::Kind kind_; |
| 281 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 282 | friend class IC; |
| 283 | }; |
| 284 | |
| 285 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 286 | class CallIC: public CallICBase { |
| 287 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 288 | explicit CallIC(Isolate* isolate) : CallICBase(Code::CALL_IC, isolate) { |
| 289 | ASSERT(target()->is_call_stub()); |
| 290 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 291 | |
| 292 | // Code generator routines. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 293 | static void GenerateInitialize(MacroAssembler* masm, |
| 294 | int argc, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 295 | Code::ExtraICState extra_state) { |
| 296 | GenerateMiss(masm, argc, extra_state); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 297 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 298 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 299 | static void GenerateMiss(MacroAssembler* masm, |
| 300 | int argc, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 301 | Code::ExtraICState extra_state) { |
| 302 | CallICBase::GenerateMiss(masm, argc, IC::kCallIC_Miss, extra_state); |
| 303 | } |
| 304 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 305 | static void GenerateMegamorphic(MacroAssembler* masm, |
| 306 | int argc, |
| 307 | Code::ExtraICState extra_ic_state); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 308 | |
| 309 | static void GenerateNormal(MacroAssembler* masm, int argc) { |
| 310 | CallICBase::GenerateNormal(masm, argc); |
| 311 | GenerateMiss(masm, argc, Code::kNoExtraICState); |
| 312 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | |
| 316 | class KeyedCallIC: public CallICBase { |
| 317 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 318 | explicit KeyedCallIC(Isolate* isolate) |
| 319 | : CallICBase(Code::KEYED_CALL_IC, isolate) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 320 | ASSERT(target()->is_keyed_call_stub()); |
| 321 | } |
| 322 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 323 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
| 324 | Handle<Object> object, |
| 325 | Handle<Object> key); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 326 | |
| 327 | // Code generator routines. |
| 328 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 329 | GenerateMiss(masm, argc); |
| 330 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 331 | |
| 332 | static void GenerateMiss(MacroAssembler* masm, int argc) { |
| 333 | CallICBase::GenerateMiss(masm, argc, IC::kKeyedCallIC_Miss, |
| 334 | Code::kNoExtraICState); |
| 335 | } |
| 336 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 337 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 338 | static void GenerateNormal(MacroAssembler* masm, int argc); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 339 | static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 340 | }; |
| 341 | |
| 342 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 343 | class LoadIC: public IC { |
| 344 | public: |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 345 | explicit LoadIC(FrameDepth depth, Isolate* isolate) : IC(depth, isolate) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 346 | ASSERT(target()->is_load_stub() || target()->is_keyed_load_stub()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 347 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 348 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | // Code generator routines. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 350 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 351 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 352 | GenerateMiss(masm); |
| 353 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | static void GenerateMiss(MacroAssembler* masm); |
| 355 | static void GenerateMegamorphic(MacroAssembler* masm); |
| 356 | static void GenerateNormal(MacroAssembler* masm); |
| 357 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 358 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 359 | Handle<Object> object, |
| 360 | Handle<String> name); |
| 361 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 362 | protected: |
| 363 | virtual Code::Kind kind() const { return Code::LOAD_IC; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 364 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 365 | virtual Handle<Code> generic_stub() const { |
| 366 | UNREACHABLE(); |
| 367 | return Handle<Code>::null(); |
| 368 | } |
| 369 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 370 | virtual Handle<Code> megamorphic_stub() { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 371 | return isolate()->builtins()->LoadIC_Megamorphic(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 372 | } |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 373 | |
| 374 | // Update the inline cache and the global stub cache based on the |
| 375 | // lookup result. |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 376 | void UpdateCaches(LookupResult* lookup, |
| 377 | State state, |
| 378 | Handle<Object> object, |
| 379 | Handle<String> name); |
| 380 | virtual Handle<Code> ComputeLoadMonomorphic(LookupResult* lookup, |
| 381 | Handle<JSObject> receiver, |
| 382 | Handle<String> name); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 383 | |
| 384 | private: |
| 385 | // Stub accessors. |
| 386 | static Handle<Code> initialize_stub() { |
| 387 | return Isolate::Current()->builtins()->LoadIC_Initialize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 388 | } |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 389 | virtual Handle<Code> pre_monomorphic_stub() { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 390 | return isolate()->builtins()->LoadIC_PreMonomorphic(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | static void Clear(Address address, Code* target); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 394 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 395 | friend class IC; |
| 396 | }; |
| 397 | |
| 398 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 399 | enum ICMissMode { |
| 400 | MISS_FORCE_GENERIC, |
| 401 | MISS |
| 402 | }; |
| 403 | |
| 404 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 405 | class KeyedLoadIC: public LoadIC { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 406 | public: |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 407 | explicit KeyedLoadIC(FrameDepth depth, Isolate* isolate) |
| 408 | : LoadIC(depth, isolate) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 409 | ASSERT(target()->is_keyed_load_stub()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 410 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 411 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 412 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 413 | Handle<Object> object, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 414 | Handle<Object> key, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 415 | ICMissMode force_generic); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 416 | |
| 417 | // Code generator routines. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 418 | static void GenerateMiss(MacroAssembler* masm, ICMissMode force_generic); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 419 | static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 420 | static void GenerateInitialize(MacroAssembler* masm) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 421 | GenerateMiss(masm, MISS); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 422 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 423 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 424 | GenerateMiss(masm, MISS); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 425 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 426 | static void GenerateGeneric(MacroAssembler* masm); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 427 | static void GenerateString(MacroAssembler* masm); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 428 | static void GenerateIndexedInterceptor(MacroAssembler* masm); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 429 | static void GenerateNonStrictArguments(MacroAssembler* masm); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 430 | |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 431 | // Bit mask to be tested against bit field for the cases when |
| 432 | // generic stub should go into slow case. |
| 433 | // Access check is necessary explicitly since generic stub does not perform |
| 434 | // map checks. |
| 435 | static const int kSlowCaseBitFieldMask = |
| 436 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 437 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 438 | protected: |
| 439 | virtual Code::Kind kind() const { return Code::KEYED_LOAD_IC; } |
| 440 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 441 | Handle<Code> LoadElementStub(Handle<JSObject> receiver); |
| 442 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 443 | virtual Handle<Code> megamorphic_stub() { |
| 444 | return isolate()->builtins()->KeyedLoadIC_Generic(); |
| 445 | } |
| 446 | virtual Handle<Code> generic_stub() const { |
| 447 | return isolate()->builtins()->KeyedLoadIC_Generic(); |
| 448 | } |
| 449 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | // Update the inline cache. |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 451 | virtual Handle<Code> ComputeLoadMonomorphic(LookupResult* lookup, |
| 452 | Handle<JSObject> receiver, |
| 453 | Handle<String> name); |
| 454 | virtual void UpdateMegamorphicCache(Map* map, String* name, Code* code) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 456 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 457 | // Stub accessors. |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 458 | static Handle<Code> initialize_stub() { |
| 459 | return Isolate::Current()->builtins()->KeyedLoadIC_Initialize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | } |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 461 | virtual Handle<Code> pre_monomorphic_stub() { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 462 | return isolate()->builtins()->KeyedLoadIC_PreMonomorphic(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 463 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 464 | Handle<Code> indexed_interceptor_stub() { |
| 465 | return isolate()->builtins()->KeyedLoadIC_IndexedInterceptor(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 466 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 467 | Handle<Code> non_strict_arguments_stub() { |
| 468 | return isolate()->builtins()->KeyedLoadIC_NonStrictArguments(); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 469 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 470 | Handle<Code> string_stub() { |
| 471 | return isolate()->builtins()->KeyedLoadIC_String(); |
| 472 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 473 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 474 | static void Clear(Address address, Code* target); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 475 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 476 | friend class IC; |
| 477 | }; |
| 478 | |
| 479 | |
| 480 | class StoreIC: public IC { |
| 481 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 482 | explicit StoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 483 | ASSERT(target()->is_store_stub() || target()->is_keyed_store_stub()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 484 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 485 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 486 | // Code generators for stub routines. Only called once at startup. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 487 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 488 | static void GenerateMiss(MacroAssembler* masm); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 489 | static void GenerateMegamorphic(MacroAssembler* masm, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 490 | StrictModeFlag strict_mode); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 491 | static void GenerateNormal(MacroAssembler* masm); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 492 | static void GenerateGlobalProxy(MacroAssembler* masm, |
| 493 | StrictModeFlag strict_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 494 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 495 | MUST_USE_RESULT MaybeObject* Store( |
| 496 | State state, |
| 497 | StrictModeFlag strict_mode, |
| 498 | Handle<Object> object, |
| 499 | Handle<String> name, |
| 500 | Handle<Object> value, |
| 501 | JSReceiver::StoreFromKeyed store_mode = |
| 502 | JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); |
| 503 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 504 | protected: |
| 505 | virtual Code::Kind kind() const { return Code::STORE_IC; } |
| 506 | virtual Handle<Code> megamorphic_stub() { |
| 507 | return isolate()->builtins()->StoreIC_Megamorphic(); |
| 508 | } |
| 509 | // Stub accessors. |
| 510 | virtual Handle<Code> megamorphic_stub_strict() { |
| 511 | return isolate()->builtins()->StoreIC_Megamorphic_Strict(); |
| 512 | } |
| 513 | virtual Handle<Code> global_proxy_stub() { |
| 514 | return isolate()->builtins()->StoreIC_GlobalProxy(); |
| 515 | } |
| 516 | virtual Handle<Code> global_proxy_stub_strict() { |
| 517 | return isolate()->builtins()->StoreIC_GlobalProxy_Strict(); |
| 518 | } |
| 519 | |
| 520 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 521 | // Update the inline cache and the global stub cache based on the |
| 522 | // lookup result. |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 523 | void UpdateCaches(LookupResult* lookup, |
| 524 | State state, |
| 525 | StrictModeFlag strict_mode, |
| 526 | Handle<JSObject> receiver, |
| 527 | Handle<String> name, |
| 528 | Handle<Object> value); |
| 529 | // Compute the code stub for this store; used for rewriting to |
| 530 | // monomorphic state and making sure that the code stub is in the |
| 531 | // stub cache. |
| 532 | virtual Handle<Code> ComputeStoreMonomorphic(LookupResult* lookup, |
| 533 | StrictModeFlag strict_mode, |
| 534 | Handle<JSObject> receiver, |
| 535 | Handle<String> name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 537 | private: |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 538 | void set_target(Code* code) { |
| 539 | // Strict mode must be preserved across IC patching. |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 540 | ASSERT(Code::GetStrictMode(code->extra_ic_state()) == |
| 541 | Code::GetStrictMode(target()->extra_ic_state())); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 542 | IC::set_target(code); |
| 543 | } |
| 544 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 545 | static Handle<Code> initialize_stub() { |
| 546 | return Isolate::Current()->builtins()->StoreIC_Initialize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | } |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 548 | static Handle<Code> initialize_stub_strict() { |
| 549 | return Isolate::Current()->builtins()->StoreIC_Initialize_Strict(); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 550 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 551 | static void Clear(Address address, Code* target); |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 552 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 553 | friend class IC; |
| 554 | }; |
| 555 | |
| 556 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 557 | enum KeyedStoreCheckMap { |
| 558 | kDontCheckMap, |
| 559 | kCheckMap |
| 560 | }; |
| 561 | |
| 562 | |
| 563 | enum KeyedStoreIncrementLength { |
| 564 | kDontIncrementLength, |
| 565 | kIncrementLength |
| 566 | }; |
| 567 | |
| 568 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 569 | class KeyedStoreIC: public StoreIC { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 570 | public: |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 571 | enum StubKind { |
| 572 | STORE_NO_TRANSITION, |
| 573 | STORE_TRANSITION_SMI_TO_OBJECT, |
| 574 | STORE_TRANSITION_SMI_TO_DOUBLE, |
| 575 | STORE_TRANSITION_DOUBLE_TO_OBJECT, |
| 576 | STORE_TRANSITION_HOLEY_SMI_TO_OBJECT, |
| 577 | STORE_TRANSITION_HOLEY_SMI_TO_DOUBLE, |
| 578 | STORE_TRANSITION_HOLEY_DOUBLE_TO_OBJECT, |
| 579 | STORE_AND_GROW_NO_TRANSITION, |
| 580 | STORE_AND_GROW_TRANSITION_SMI_TO_OBJECT, |
| 581 | STORE_AND_GROW_TRANSITION_SMI_TO_DOUBLE, |
| 582 | STORE_AND_GROW_TRANSITION_DOUBLE_TO_OBJECT, |
| 583 | STORE_AND_GROW_TRANSITION_HOLEY_SMI_TO_OBJECT, |
| 584 | STORE_AND_GROW_TRANSITION_HOLEY_SMI_TO_DOUBLE, |
| 585 | STORE_AND_GROW_TRANSITION_HOLEY_DOUBLE_TO_OBJECT |
| 586 | }; |
| 587 | |
| 588 | static const int kGrowICDelta = STORE_AND_GROW_NO_TRANSITION - |
| 589 | STORE_NO_TRANSITION; |
| 590 | STATIC_ASSERT(kGrowICDelta == |
| 591 | STORE_AND_GROW_TRANSITION_SMI_TO_OBJECT - |
| 592 | STORE_TRANSITION_SMI_TO_OBJECT); |
| 593 | STATIC_ASSERT(kGrowICDelta == |
| 594 | STORE_AND_GROW_TRANSITION_SMI_TO_DOUBLE - |
| 595 | STORE_TRANSITION_SMI_TO_DOUBLE); |
| 596 | STATIC_ASSERT(kGrowICDelta == |
| 597 | STORE_AND_GROW_TRANSITION_DOUBLE_TO_OBJECT - |
| 598 | STORE_TRANSITION_DOUBLE_TO_OBJECT); |
| 599 | |
| 600 | static inline StubKind GetGrowStubKind(StubKind stub_kind) { |
| 601 | if (stub_kind < STORE_AND_GROW_NO_TRANSITION) { |
| 602 | stub_kind = static_cast<StubKind>(static_cast<int>(stub_kind) + |
| 603 | kGrowICDelta); |
| 604 | } |
| 605 | return stub_kind; |
| 606 | } |
| 607 | |
| 608 | explicit KeyedStoreIC(Isolate* isolate) : StoreIC(isolate) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 609 | ASSERT(target()->is_keyed_store_stub()); |
| 610 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 612 | MUST_USE_RESULT MaybeObject* Store(State state, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 613 | StrictModeFlag strict_mode, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 614 | Handle<Object> object, |
| 615 | Handle<Object> name, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 616 | Handle<Object> value, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 617 | ICMissMode force_generic); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 618 | |
| 619 | // Code generators for stub routines. Only called once at startup. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 620 | static void GenerateInitialize(MacroAssembler* masm) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 621 | GenerateMiss(masm, MISS); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 622 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 623 | static void GenerateMiss(MacroAssembler* masm, ICMissMode force_generic); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 624 | static void GenerateSlow(MacroAssembler* masm); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 625 | static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 626 | StrictModeFlag strict_mode); |
| 627 | static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 628 | static void GenerateNonStrictArguments(MacroAssembler* masm); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 629 | static void GenerateTransitionElementsSmiToDouble(MacroAssembler* masm); |
| 630 | static void GenerateTransitionElementsDoubleToObject(MacroAssembler* masm); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 631 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 632 | protected: |
| 633 | virtual Code::Kind kind() const { return Code::KEYED_STORE_IC; } |
| 634 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 635 | virtual Handle<Code> ComputeStoreMonomorphic(LookupResult* lookup, |
| 636 | StrictModeFlag strict_mode, |
| 637 | Handle<JSObject> receiver, |
| 638 | Handle<String> name); |
| 639 | virtual void UpdateMegamorphicCache(Map* map, String* name, Code* code) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 640 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 641 | virtual Handle<Code> megamorphic_stub() { |
| 642 | return isolate()->builtins()->KeyedStoreIC_Generic(); |
| 643 | } |
| 644 | virtual Handle<Code> megamorphic_stub_strict() { |
| 645 | return isolate()->builtins()->KeyedStoreIC_Generic_Strict(); |
| 646 | } |
| 647 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 648 | Handle<Code> StoreElementStub(Handle<JSObject> receiver, |
| 649 | StubKind stub_kind, |
| 650 | StrictModeFlag strict_mode); |
| 651 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 652 | private: |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 653 | void set_target(Code* code) { |
| 654 | // Strict mode must be preserved across IC patching. |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 655 | ASSERT(Code::GetStrictMode(code->extra_ic_state()) == |
| 656 | Code::GetStrictMode(target()->extra_ic_state())); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 657 | IC::set_target(code); |
| 658 | } |
| 659 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 660 | // Stub accessors. |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 661 | static Handle<Code> initialize_stub() { |
| 662 | return Isolate::Current()->builtins()->KeyedStoreIC_Initialize(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 663 | } |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 664 | static Handle<Code> initialize_stub_strict() { |
| 665 | return Isolate::Current()->builtins()->KeyedStoreIC_Initialize_Strict(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 666 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 667 | Handle<Code> generic_stub() const { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 668 | return isolate()->builtins()->KeyedStoreIC_Generic(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 669 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 670 | Handle<Code> generic_stub_strict() const { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 671 | return isolate()->builtins()->KeyedStoreIC_Generic_Strict(); |
| 672 | } |
| 673 | Handle<Code> non_strict_arguments_stub() { |
| 674 | return isolate()->builtins()->KeyedStoreIC_NonStrictArguments(); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 675 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 676 | |
| 677 | static void Clear(Address address, Code* target); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 678 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 679 | StubKind GetStubKind(Handle<JSObject> receiver, |
| 680 | Handle<Object> key, |
| 681 | Handle<Object> value); |
| 682 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 683 | static bool IsTransitionStubKind(StubKind stub_kind) { |
| 684 | return stub_kind > STORE_NO_TRANSITION && |
| 685 | stub_kind != STORE_AND_GROW_NO_TRANSITION; |
| 686 | } |
| 687 | |
| 688 | static bool IsGrowStubKind(StubKind stub_kind) { |
| 689 | return stub_kind >= STORE_AND_GROW_NO_TRANSITION; |
| 690 | } |
| 691 | |
| 692 | static StubKind GetNoTransitionStubKind(StubKind stub_kind) { |
| 693 | if (!IsTransitionStubKind(stub_kind)) return stub_kind; |
| 694 | if (IsGrowStubKind(stub_kind)) return STORE_AND_GROW_NO_TRANSITION; |
| 695 | return STORE_NO_TRANSITION; |
| 696 | } |
| 697 | |
| 698 | Handle<Map> ComputeTransitionedMap(Handle<JSObject> receiver, |
| 699 | StubKind stub_kind); |
| 700 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | friend class IC; |
| 702 | }; |
| 703 | |
| 704 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 705 | class UnaryOpIC: public IC { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 706 | public: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 707 | // sorted: increasingly more unspecific (ignoring UNINITIALIZED) |
| 708 | // TODO(svenpanne) Using enums+switch is an antipattern, use a class instead. |
| 709 | enum TypeInfo { |
| 710 | UNINITIALIZED, |
| 711 | SMI, |
| 712 | HEAP_NUMBER, |
| 713 | GENERIC |
| 714 | }; |
| 715 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 716 | explicit UnaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 717 | |
| 718 | void patch(Code* code); |
| 719 | |
| 720 | static const char* GetName(TypeInfo type_info); |
| 721 | |
| 722 | static State ToState(TypeInfo type_info); |
| 723 | |
| 724 | static TypeInfo GetTypeInfo(Handle<Object> operand); |
| 725 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 726 | static TypeInfo ComputeNewType(TypeInfo type, TypeInfo previous); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 727 | }; |
| 728 | |
| 729 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 730 | // Type Recording BinaryOpIC, that records the types of the inputs and outputs. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 731 | class BinaryOpIC: public IC { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 732 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 733 | enum TypeInfo { |
| 734 | UNINITIALIZED, |
| 735 | SMI, |
| 736 | INT32, |
| 737 | HEAP_NUMBER, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 738 | ODDBALL, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 739 | STRING, // Only used for addition operation. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 740 | GENERIC |
| 741 | }; |
| 742 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 743 | explicit BinaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 744 | |
| 745 | void patch(Code* code); |
| 746 | |
| 747 | static const char* GetName(TypeInfo type_info); |
| 748 | |
| 749 | static State ToState(TypeInfo type_info); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 750 | }; |
| 751 | |
| 752 | |
| 753 | class CompareIC: public IC { |
| 754 | public: |
| 755 | enum State { |
| 756 | UNINITIALIZED, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 757 | SMI, |
| 758 | HEAP_NUMBER, |
| 759 | SYMBOL, |
| 760 | STRING, |
| 761 | OBJECT, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 762 | KNOWN_OBJECTS, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 763 | GENERIC |
| 764 | }; |
| 765 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 766 | CompareIC(Isolate* isolate, Token::Value op) |
| 767 | : IC(EXTRA_CALL_FRAME, isolate), op_(op) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 768 | |
| 769 | // Update the inline cache for the given operands. |
| 770 | void UpdateCaches(Handle<Object> x, Handle<Object> y); |
| 771 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 772 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 773 | // Factory method for getting an uninitialized compare stub. |
| 774 | static Handle<Code> GetUninitialized(Token::Value op); |
| 775 | |
| 776 | // Helper function for computing the condition for a compare operation. |
| 777 | static Condition ComputeCondition(Token::Value op); |
| 778 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 779 | static const char* GetStateName(State state); |
| 780 | |
| 781 | private: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 782 | static bool HasInlinedSmiCode(Address address); |
| 783 | |
| 784 | State TargetState(State old_state, |
| 785 | State old_left, |
| 786 | State old_right, |
| 787 | bool has_inlined_smi_code, |
| 788 | Handle<Object> x, |
| 789 | Handle<Object> y); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 790 | |
| 791 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 792 | Condition GetCondition() const { return ComputeCondition(op_); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 793 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 794 | static Code* GetRawUninitialized(Token::Value op); |
| 795 | |
| 796 | static void Clear(Address address, Code* target); |
| 797 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 798 | Token::Value op_; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 799 | |
| 800 | friend class IC; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 801 | }; |
| 802 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 803 | |
| 804 | class ToBooleanIC: public IC { |
| 805 | public: |
| 806 | explicit ToBooleanIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
| 807 | |
| 808 | void patch(Code* code); |
| 809 | }; |
| 810 | |
| 811 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 812 | // Helper for BinaryOpIC and CompareIC. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 813 | enum InlinedSmiCheck { ENABLE_INLINED_SMI_CHECK, DISABLE_INLINED_SMI_CHECK }; |
| 814 | void PatchInlinedSmiCode(Address address, InlinedSmiCheck check); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 815 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 816 | DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadIC_Miss); |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 817 | DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadIC_MissFromStubFailure); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 818 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 819 | } } // namespace v8::internal |
| 820 | |
| 821 | #endif // V8_IC_H_ |