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