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