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