Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_IC_H_ |
| 6 | #define V8_IC_H_ |
| 7 | |
| 8 | #include "src/ic/ic-state.h" |
| 9 | #include "src/macro-assembler.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 10 | #include "src/messages.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 15 | // |
| 16 | // IC is the base class for LoadIC, StoreIC, KeyedLoadIC, and KeyedStoreIC. |
| 17 | // |
| 18 | class IC { |
| 19 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 20 | // Alias the inline cache state type to make the IC code more readable. |
| 21 | typedef InlineCacheState State; |
| 22 | |
| 23 | // The IC code is either invoked with no extra frames on the stack |
| 24 | // or with a single extra frame for supporting calls. |
| 25 | enum FrameDepth { NO_EXTRA_FRAME = 0, EXTRA_CALL_FRAME = 1 }; |
| 26 | |
| 27 | // Construct the IC structure with the given number of extra |
| 28 | // JavaScript frames on the stack. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 29 | IC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 30 | virtual ~IC() {} |
| 31 | |
| 32 | State state() const { return state_; } |
| 33 | inline Address address() const; |
| 34 | |
| 35 | // Compute the current IC state based on the target stub, receiver and name. |
| 36 | void UpdateState(Handle<Object> receiver, Handle<Object> name); |
| 37 | |
| 38 | bool IsNameCompatibleWithPrototypeFailure(Handle<Object> name); |
| 39 | void MarkPrototypeFailure(Handle<Object> name) { |
| 40 | DCHECK(IsNameCompatibleWithPrototypeFailure(name)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 41 | old_state_ = state_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 42 | state_ = PROTOTYPE_FAILURE; |
| 43 | } |
| 44 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | // Clear the inline cache to initial state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 46 | static void Clear(Isolate* isolate, Address address, Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 47 | |
| 48 | #ifdef DEBUG |
| 49 | bool IsLoadStub() const { |
| 50 | return target()->is_load_stub() || target()->is_keyed_load_stub(); |
| 51 | } |
| 52 | |
| 53 | bool IsStoreStub() const { |
| 54 | return target()->is_store_stub() || target()->is_keyed_store_stub(); |
| 55 | } |
| 56 | |
| 57 | bool IsCallStub() const { return target()->is_call_stub(); } |
| 58 | #endif |
| 59 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 60 | static inline Handle<Map> GetHandlerCacheHolder(Handle<Map> receiver_map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | bool receiver_is_holder, |
| 62 | Isolate* isolate, |
| 63 | CacheHolderFlag* flag); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 64 | static inline Handle<Map> GetICCacheHolder(Handle<Map> receiver_map, |
| 65 | Isolate* isolate, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 66 | CacheHolderFlag* flag); |
| 67 | |
| 68 | static bool IsCleared(Code* code) { |
| 69 | InlineCacheState state = code->ic_state(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 70 | return !FLAG_use_ic || state == UNINITIALIZED || state == PREMONOMORPHIC; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 73 | static bool IsCleared(FeedbackNexus* nexus) { |
| 74 | InlineCacheState state = nexus->StateFromFeedback(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 75 | return !FLAG_use_ic || state == UNINITIALIZED || state == PREMONOMORPHIC; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 76 | } |
| 77 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 78 | static bool ICUseVector(Code::Kind kind) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 79 | return kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC || |
| 80 | kind == Code::CALL_IC || kind == Code::STORE_IC || |
| 81 | kind == Code::KEYED_STORE_IC; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 84 | protected: |
| 85 | // Get the call-site target; used for determining the state. |
| 86 | Handle<Code> target() const { return target_; } |
| 87 | |
| 88 | Address fp() const { return fp_; } |
| 89 | Address pc() const { return *pc_address_; } |
| 90 | Isolate* isolate() const { return isolate_; } |
| 91 | |
| 92 | // Get the shared function info of the caller. |
| 93 | SharedFunctionInfo* GetSharedFunctionInfo() const; |
| 94 | // Get the code object of the caller. |
| 95 | Code* GetCode() const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 96 | |
| 97 | bool AddressIsOptimizedCode() const; |
| 98 | inline bool AddressIsDeoptimizedCode() const; |
| 99 | inline static bool AddressIsDeoptimizedCode(Isolate* isolate, |
| 100 | Address address); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 101 | |
| 102 | // Set the call-site target. |
| 103 | inline void set_target(Code* code); |
| 104 | bool is_target_set() { return target_set_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 105 | bool is_vector_set() { return vector_set_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 106 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 107 | bool UseVector() const { |
| 108 | bool use = ICUseVector(kind()); |
| 109 | // If we are supposed to use the nexus, verify the nexus is non-null. |
| 110 | DCHECK(!use || nexus_ != NULL); |
| 111 | return use; |
| 112 | } |
| 113 | |
| 114 | // Configure for most states. |
| 115 | void ConfigureVectorState(IC::State new_state); |
| 116 | // Configure the vector for MONOMORPHIC. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 117 | void ConfigureVectorState(Handle<Name> name, Handle<Map> map, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 118 | Handle<Code> handler); |
| 119 | // Configure the vector for POLYMORPHIC. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 120 | void ConfigureVectorState(Handle<Name> name, MapHandleList* maps, |
| 121 | CodeHandleList* handlers); |
| 122 | // Configure the vector for POLYMORPHIC with transitions (only for element |
| 123 | // keyed stores). |
| 124 | void ConfigureVectorState(MapHandleList* maps, |
| 125 | MapHandleList* transitioned_maps, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 126 | CodeHandleList* handlers); |
| 127 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 128 | char TransitionMarkFromState(IC::State state); |
| 129 | void TraceIC(const char* type, Handle<Object> name); |
| 130 | void TraceIC(const char* type, Handle<Object> name, State old_state, |
| 131 | State new_state); |
| 132 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 133 | MaybeHandle<Object> TypeError(MessageTemplate::Template, |
| 134 | Handle<Object> object, Handle<Object> key); |
| 135 | MaybeHandle<Object> ReferenceError(Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 136 | |
| 137 | // Access the target code for the given IC address. |
| 138 | static inline Code* GetTargetAtAddress(Address address, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 139 | Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 140 | static inline void SetTargetAtAddress(Address address, Code* target, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 141 | Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 142 | static void OnTypeFeedbackChanged(Isolate* isolate, Address address, |
| 143 | State old_state, State new_state, |
| 144 | bool target_remains_ic_stub); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 145 | // As a vector-based IC, type feedback must be updated differently. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 146 | static void OnTypeFeedbackChanged(Isolate* isolate, Code* host); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 147 | static void PostPatching(Address address, Code* target, Code* old_target); |
| 148 | |
| 149 | // Compute the handler either by compiling or by retrieving a cached version. |
| 150 | Handle<Code> ComputeHandler(LookupIterator* lookup, |
| 151 | Handle<Object> value = Handle<Code>::null()); |
| 152 | virtual Handle<Code> CompileHandler(LookupIterator* lookup, |
| 153 | Handle<Object> value, |
| 154 | CacheHolderFlag cache_holder) { |
| 155 | UNREACHABLE(); |
| 156 | return Handle<Code>::null(); |
| 157 | } |
| 158 | |
| 159 | void UpdateMonomorphicIC(Handle<Code> handler, Handle<Name> name); |
| 160 | bool UpdatePolymorphicIC(Handle<Name> name, Handle<Code> code); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 161 | void UpdateMegamorphicCache(Map* map, Name* name, Code* code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | |
| 163 | void CopyICToMegamorphicCache(Handle<Name> name); |
| 164 | bool IsTransitionOfMonomorphicTarget(Map* source_map, Map* target_map); |
| 165 | void PatchCache(Handle<Name> name, Handle<Code> code); |
| 166 | Code::Kind kind() const { return kind_; } |
| 167 | Code::Kind handler_kind() const { |
| 168 | if (kind_ == Code::KEYED_LOAD_IC) return Code::LOAD_IC; |
| 169 | DCHECK(kind_ == Code::LOAD_IC || kind_ == Code::STORE_IC || |
| 170 | kind_ == Code::KEYED_STORE_IC); |
| 171 | return kind_; |
| 172 | } |
| 173 | virtual Handle<Code> megamorphic_stub() { |
| 174 | UNREACHABLE(); |
| 175 | return Handle<Code>::null(); |
| 176 | } |
| 177 | |
| 178 | bool TryRemoveInvalidPrototypeDependentStub(Handle<Object> receiver, |
| 179 | Handle<String> name); |
| 180 | |
| 181 | ExtraICState extra_ic_state() const { return extra_ic_state_; } |
| 182 | void set_extra_ic_state(ExtraICState state) { extra_ic_state_ = state; } |
| 183 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 184 | Handle<Map> receiver_map() { return receiver_map_; } |
| 185 | void update_receiver_map(Handle<Object> receiver) { |
| 186 | if (receiver->IsSmi()) { |
| 187 | receiver_map_ = isolate_->factory()->heap_number_map(); |
| 188 | } else { |
| 189 | receiver_map_ = handle(HeapObject::cast(*receiver)->map()); |
| 190 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void TargetMaps(MapHandleList* list) { |
| 194 | FindTargetMaps(); |
| 195 | for (int i = 0; i < target_maps_.length(); i++) { |
| 196 | list->Add(target_maps_.at(i)); |
| 197 | } |
| 198 | } |
| 199 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 200 | Map* FirstTargetMap() { |
| 201 | FindTargetMaps(); |
| 202 | return target_maps_.length() > 0 ? *target_maps_.at(0) : NULL; |
| 203 | } |
| 204 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 205 | inline void UpdateTarget(); |
| 206 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 207 | Handle<TypeFeedbackVector> vector() const { return nexus()->vector_handle(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 208 | FeedbackVectorSlot slot() const { return nexus()->slot(); } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 209 | State saved_state() const { |
| 210 | return state() == PROTOTYPE_FAILURE ? old_state_ : state(); |
| 211 | } |
| 212 | |
| 213 | template <class NexusClass> |
| 214 | NexusClass* casted_nexus() { |
| 215 | return static_cast<NexusClass*>(nexus_); |
| 216 | } |
| 217 | FeedbackNexus* nexus() const { return nexus_; } |
| 218 | |
| 219 | inline Code* get_host(); |
| 220 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 221 | private: |
| 222 | inline Code* raw_target() const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 223 | inline Address constant_pool() const; |
| 224 | inline Address raw_constant_pool() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 225 | |
| 226 | void FindTargetMaps() { |
| 227 | if (target_maps_set_) return; |
| 228 | target_maps_set_ = true; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 229 | if (UseVector()) { |
| 230 | nexus()->ExtractMaps(&target_maps_); |
| 231 | } else { |
| 232 | if (state_ == MONOMORPHIC) { |
| 233 | Map* map = target_->FindFirstMap(); |
| 234 | if (map != NULL) target_maps_.Add(handle(map)); |
| 235 | } else if (state_ != UNINITIALIZED && state_ != PREMONOMORPHIC) { |
| 236 | target_->FindAllMaps(&target_maps_); |
| 237 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
| 241 | // Frame pointer for the frame that uses (calls) the IC. |
| 242 | Address fp_; |
| 243 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 244 | // All access to the program counter and constant pool of an IC structure is |
| 245 | // indirect to make the code GC safe. This feature is crucial since |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 246 | // GetProperty and SetProperty are called and they in turn might |
| 247 | // invoke the garbage collector. |
| 248 | Address* pc_address_; |
| 249 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 250 | // The constant pool of the code which originally called the IC (which might |
| 251 | // be for the breakpointed copy of the original code). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 252 | Address* constant_pool_address_; |
| 253 | |
| 254 | Isolate* isolate_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 255 | |
| 256 | // The original code target that missed. |
| 257 | Handle<Code> target_; |
| 258 | bool target_set_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 259 | bool vector_set_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 260 | State old_state_; // For saving if we marked as prototype failure. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 261 | State state_; |
| 262 | Code::Kind kind_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 263 | Handle<Map> receiver_map_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 264 | MaybeHandle<Code> maybe_handler_; |
| 265 | |
| 266 | ExtraICState extra_ic_state_; |
| 267 | MapHandleList target_maps_; |
| 268 | bool target_maps_set_; |
| 269 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 270 | FeedbackNexus* nexus_; |
| 271 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 272 | DISALLOW_IMPLICIT_CONSTRUCTORS(IC); |
| 273 | }; |
| 274 | |
| 275 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 276 | class CallIC : public IC { |
| 277 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 278 | CallIC(Isolate* isolate, CallICNexus* nexus) |
| 279 | : IC(EXTRA_CALL_FRAME, isolate, nexus) { |
| 280 | DCHECK(nexus != NULL); |
| 281 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 282 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 283 | void HandleMiss(Handle<Object> function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 284 | |
| 285 | // Code generator routines. |
| 286 | static Handle<Code> initialize_stub(Isolate* isolate, int argc, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 287 | ConvertReceiverMode mode); |
| 288 | static Handle<Code> initialize_stub_in_optimized_code( |
| 289 | Isolate* isolate, int argc, ConvertReceiverMode mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 290 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 291 | static void Clear(Isolate* isolate, Code* host, CallICNexus* nexus); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | |
| 295 | class LoadIC : public IC { |
| 296 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 297 | static ExtraICState ComputeExtraICState(TypeofMode typeof_mode, |
| 298 | LanguageMode language_mode) { |
| 299 | return LoadICState(typeof_mode, language_mode).GetExtraICState(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 302 | TypeofMode typeof_mode() const { |
| 303 | return LoadICState::GetTypeofMode(extra_ic_state()); |
| 304 | } |
| 305 | |
| 306 | LanguageMode language_mode() const { |
| 307 | return LoadICState::GetLanguageMode(extra_ic_state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 310 | LoadIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL) |
| 311 | : IC(depth, isolate, nexus) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 312 | DCHECK(nexus != NULL); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 313 | DCHECK(IsLoadStub()); |
| 314 | } |
| 315 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 316 | bool ShouldThrowReferenceError(Handle<Object> receiver) { |
| 317 | return receiver->IsJSGlobalObject() && typeof_mode() == NOT_INSIDE_TYPEOF; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | // Code generator routines. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 321 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 322 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 323 | static void GenerateMiss(MacroAssembler* masm); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 324 | static void GenerateRuntimeGetProperty(MacroAssembler* masm, |
| 325 | LanguageMode language_mode); |
| 326 | static void GenerateNormal(MacroAssembler* masm, LanguageMode language_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 327 | |
| 328 | static Handle<Code> initialize_stub(Isolate* isolate, |
| 329 | ExtraICState extra_state); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 330 | static Handle<Code> initialize_stub_in_optimized_code( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 331 | Isolate* isolate, ExtraICState extra_state, State initialization_state); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | |
| 333 | MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object, |
| 334 | Handle<Name> name); |
| 335 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 336 | static void Clear(Isolate* isolate, Code* host, LoadICNexus* nexus); |
| 337 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 338 | protected: |
| 339 | inline void set_target(Code* code); |
| 340 | |
| 341 | Handle<Code> slow_stub() const { |
| 342 | if (kind() == Code::LOAD_IC) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 343 | return is_strong(language_mode()) |
| 344 | ? isolate()->builtins()->LoadIC_Slow_Strong() |
| 345 | : isolate()->builtins()->LoadIC_Slow(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 346 | } else { |
| 347 | DCHECK_EQ(Code::KEYED_LOAD_IC, kind()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 348 | return is_strong(language_mode()) |
| 349 | ? isolate()->builtins()->KeyedLoadIC_Slow_Strong() |
| 350 | : isolate()->builtins()->KeyedLoadIC_Slow(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 354 | Handle<Code> megamorphic_stub() override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 355 | |
| 356 | // Update the inline cache and the global stub cache based on the |
| 357 | // lookup result. |
| 358 | void UpdateCaches(LookupIterator* lookup); |
| 359 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 360 | Handle<Code> CompileHandler(LookupIterator* lookup, Handle<Object> unused, |
| 361 | CacheHolderFlag cache_holder) override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 362 | |
| 363 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 364 | Handle<Code> SimpleFieldLoad(FieldIndex index); |
| 365 | |
| 366 | static void Clear(Isolate* isolate, Address address, Code* target, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 367 | Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 368 | |
| 369 | friend class IC; |
| 370 | }; |
| 371 | |
| 372 | |
| 373 | class KeyedLoadIC : public LoadIC { |
| 374 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 375 | // ExtraICState bits (building on IC) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 376 | class IcCheckTypeField |
| 377 | : public BitField<IcCheckType, LoadICState::kNextBitFieldOffset, 1> {}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 378 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 379 | static ExtraICState ComputeExtraICState(TypeofMode typeof_mode, |
| 380 | LanguageMode language_mode, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 381 | IcCheckType key_type) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 382 | return LoadICState(typeof_mode, language_mode).GetExtraICState() | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 383 | IcCheckTypeField::encode(key_type); |
| 384 | } |
| 385 | |
| 386 | static IcCheckType GetKeyType(ExtraICState extra_state) { |
| 387 | return IcCheckTypeField::decode(extra_state); |
| 388 | } |
| 389 | |
| 390 | KeyedLoadIC(FrameDepth depth, Isolate* isolate, |
| 391 | KeyedLoadICNexus* nexus = NULL) |
| 392 | : LoadIC(depth, isolate, nexus) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 393 | DCHECK(nexus != NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | DCHECK(target()->is_keyed_load_stub()); |
| 395 | } |
| 396 | |
| 397 | MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object, |
| 398 | Handle<Object> key); |
| 399 | |
| 400 | // Code generator routines. |
| 401 | static void GenerateMiss(MacroAssembler* masm); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 402 | static void GenerateRuntimeGetProperty(MacroAssembler* masm, |
| 403 | LanguageMode language_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 404 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 405 | static void GenerateMegamorphic(MacroAssembler* masm, |
| 406 | LanguageMode language_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 407 | |
| 408 | // Bit mask to be tested against bit field for the cases when |
| 409 | // generic stub should go into slow case. |
| 410 | // Access check is necessary explicitly since generic stub does not perform |
| 411 | // map checks. |
| 412 | static const int kSlowCaseBitFieldMask = |
| 413 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 414 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 415 | static Handle<Code> initialize_stub(Isolate* isolate, |
| 416 | ExtraICState extra_state); |
| 417 | static Handle<Code> initialize_stub_in_optimized_code( |
| 418 | Isolate* isolate, State initialization_state, ExtraICState extra_state); |
| 419 | static Handle<Code> ChooseMegamorphicStub(Isolate* isolate, |
| 420 | ExtraICState extra_state); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 421 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 422 | static void Clear(Isolate* isolate, Code* host, KeyedLoadICNexus* nexus); |
| 423 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 424 | protected: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 425 | // receiver is HeapObject because it could be a String or a JSObject |
| 426 | Handle<Code> LoadElementStub(Handle<HeapObject> receiver); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | |
| 428 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 429 | static void Clear(Isolate* isolate, Address address, Code* target, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 430 | Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 431 | |
| 432 | friend class IC; |
| 433 | }; |
| 434 | |
| 435 | |
| 436 | class StoreIC : public IC { |
| 437 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 438 | static ExtraICState ComputeExtraICState(LanguageMode flag) { |
| 439 | return StoreICState(flag).GetExtraICState(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 442 | StoreIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL) |
| 443 | : IC(depth, isolate, nexus) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 444 | DCHECK(IsStoreStub()); |
| 445 | } |
| 446 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 447 | LanguageMode language_mode() const { |
| 448 | return StoreICState::GetLanguageMode(extra_ic_state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | // Code generators for stub routines. Only called once at startup. |
| 452 | static void GenerateSlow(MacroAssembler* masm); |
| 453 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 454 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 455 | GenerateMiss(masm); |
| 456 | } |
| 457 | static void GenerateMiss(MacroAssembler* masm); |
| 458 | static void GenerateMegamorphic(MacroAssembler* masm); |
| 459 | static void GenerateNormal(MacroAssembler* masm); |
| 460 | static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 461 | LanguageMode language_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 462 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 463 | static Handle<Code> initialize_stub(Isolate* isolate, |
| 464 | LanguageMode language_mode, |
| 465 | State initialization_state); |
| 466 | static Handle<Code> initialize_stub_in_optimized_code( |
| 467 | Isolate* isolate, LanguageMode language_mode, State initialization_state); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 468 | |
| 469 | MUST_USE_RESULT MaybeHandle<Object> Store( |
| 470 | Handle<Object> object, Handle<Name> name, Handle<Object> value, |
| 471 | JSReceiver::StoreFromKeyed store_mode = |
| 472 | JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); |
| 473 | |
| 474 | bool LookupForWrite(LookupIterator* it, Handle<Object> value, |
| 475 | JSReceiver::StoreFromKeyed store_mode); |
| 476 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 477 | static void Clear(Isolate* isolate, Code* host, StoreICNexus* nexus); |
| 478 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 479 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 480 | // Stub accessors. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 481 | Handle<Code> megamorphic_stub() override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 482 | Handle<Code> slow_stub() const; |
| 483 | |
| 484 | virtual Handle<Code> pre_monomorphic_stub() const { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 485 | return pre_monomorphic_stub(isolate(), language_mode()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static Handle<Code> pre_monomorphic_stub(Isolate* isolate, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 489 | LanguageMode language_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 490 | |
| 491 | // Update the inline cache and the global stub cache based on the |
| 492 | // lookup result. |
| 493 | void UpdateCaches(LookupIterator* lookup, Handle<Object> value, |
| 494 | JSReceiver::StoreFromKeyed store_mode); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 495 | Handle<Code> CompileHandler(LookupIterator* lookup, Handle<Object> value, |
| 496 | CacheHolderFlag cache_holder) override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 497 | |
| 498 | private: |
| 499 | inline void set_target(Code* code); |
| 500 | |
| 501 | static void Clear(Isolate* isolate, Address address, Code* target, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 502 | Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 503 | |
| 504 | friend class IC; |
| 505 | }; |
| 506 | |
| 507 | |
| 508 | enum KeyedStoreCheckMap { kDontCheckMap, kCheckMap }; |
| 509 | |
| 510 | |
| 511 | enum KeyedStoreIncrementLength { kDontIncrementLength, kIncrementLength }; |
| 512 | |
| 513 | |
| 514 | class KeyedStoreIC : public StoreIC { |
| 515 | public: |
| 516 | // ExtraICState bits (building on IC) |
| 517 | // ExtraICState bits |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 518 | // When more language modes are added, these BitFields need to move too. |
| 519 | STATIC_ASSERT(i::LANGUAGE_END == 3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 520 | class ExtraICStateKeyedAccessStoreMode |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 521 | : public BitField<KeyedAccessStoreMode, 3, 3> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 522 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 523 | class IcCheckTypeField : public BitField<IcCheckType, 6, 1> {}; |
| 524 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 525 | static ExtraICState ComputeExtraICState(LanguageMode flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 526 | KeyedAccessStoreMode mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 527 | return StoreICState(flag).GetExtraICState() | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 528 | ExtraICStateKeyedAccessStoreMode::encode(mode) | |
| 529 | IcCheckTypeField::encode(ELEMENT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 532 | KeyedAccessStoreMode GetKeyedAccessStoreMode() { |
| 533 | return casted_nexus<KeyedStoreICNexus>()->GetKeyedAccessStoreMode(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 536 | KeyedStoreIC(FrameDepth depth, Isolate* isolate, |
| 537 | KeyedStoreICNexus* nexus = NULL) |
| 538 | : StoreIC(depth, isolate, nexus) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 539 | DCHECK(target()->is_keyed_store_stub()); |
| 540 | } |
| 541 | |
| 542 | MUST_USE_RESULT MaybeHandle<Object> Store(Handle<Object> object, |
| 543 | Handle<Object> name, |
| 544 | Handle<Object> value); |
| 545 | |
| 546 | // Code generators for stub routines. Only called once at startup. |
| 547 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 548 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 549 | GenerateMiss(masm); |
| 550 | } |
| 551 | static void GenerateMiss(MacroAssembler* masm); |
| 552 | static void GenerateSlow(MacroAssembler* masm); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 553 | static void GenerateMegamorphic(MacroAssembler* masm, |
| 554 | LanguageMode language_mode); |
| 555 | |
| 556 | static Handle<Code> initialize_stub(Isolate* isolate, |
| 557 | LanguageMode language_mode, |
| 558 | State initialization_state); |
| 559 | |
| 560 | static Handle<Code> initialize_stub_in_optimized_code( |
| 561 | Isolate* isolate, LanguageMode language_mode, State initialization_state); |
| 562 | static Handle<Code> ChooseMegamorphicStub(Isolate* isolate, |
| 563 | ExtraICState extra_state); |
| 564 | |
| 565 | static void Clear(Isolate* isolate, Code* host, KeyedStoreICNexus* nexus); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 566 | |
| 567 | protected: |
| 568 | virtual Handle<Code> pre_monomorphic_stub() const { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 569 | return pre_monomorphic_stub(isolate(), language_mode()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 570 | } |
| 571 | static Handle<Code> pre_monomorphic_stub(Isolate* isolate, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 572 | LanguageMode language_mode) { |
| 573 | if (is_strict(language_mode)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 574 | return isolate->builtins()->KeyedStoreIC_PreMonomorphic_Strict(); |
| 575 | } else { |
| 576 | return isolate->builtins()->KeyedStoreIC_PreMonomorphic(); |
| 577 | } |
| 578 | } |
| 579 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 580 | Handle<Code> StoreElementStub(Handle<Map> receiver_map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 581 | KeyedAccessStoreMode store_mode); |
| 582 | |
| 583 | private: |
| 584 | inline void set_target(Code* code); |
| 585 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 586 | static void Clear(Isolate* isolate, Address address, Code* target, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 587 | Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 588 | |
| 589 | Handle<Map> ComputeTransitionedMap(Handle<Map> map, |
| 590 | KeyedAccessStoreMode store_mode); |
| 591 | |
| 592 | friend class IC; |
| 593 | }; |
| 594 | |
| 595 | |
| 596 | // Type Recording BinaryOpIC, that records the types of the inputs and outputs. |
| 597 | class BinaryOpIC : public IC { |
| 598 | public: |
| 599 | explicit BinaryOpIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {} |
| 600 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 601 | MaybeHandle<Object> Transition(Handle<AllocationSite> allocation_site, |
| 602 | Handle<Object> left, |
| 603 | Handle<Object> right) WARN_UNUSED_RESULT; |
| 604 | }; |
| 605 | |
| 606 | |
| 607 | class CompareIC : public IC { |
| 608 | public: |
| 609 | CompareIC(Isolate* isolate, Token::Value op) |
| 610 | : IC(EXTRA_CALL_FRAME, isolate), op_(op) {} |
| 611 | |
| 612 | // Update the inline cache for the given operands. |
| 613 | Code* UpdateCaches(Handle<Object> x, Handle<Object> y); |
| 614 | |
| 615 | // Helper function for computing the condition for a compare operation. |
| 616 | static Condition ComputeCondition(Token::Value op); |
| 617 | |
| 618 | // Factory method for getting an uninitialized compare stub. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 619 | static Handle<Code> GetUninitialized(Isolate* isolate, Token::Value op, |
| 620 | Strength strength); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 621 | |
| 622 | private: |
| 623 | static bool HasInlinedSmiCode(Address address); |
| 624 | |
| 625 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 626 | Condition GetCondition() const { return ComputeCondition(op_); } |
| 627 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 628 | static Code* GetRawUninitialized(Isolate* isolate, Token::Value op, |
| 629 | Strength strength); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 630 | |
| 631 | static void Clear(Isolate* isolate, Address address, Code* target, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 632 | Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 633 | |
| 634 | Token::Value op_; |
| 635 | |
| 636 | friend class IC; |
| 637 | }; |
| 638 | |
| 639 | |
| 640 | class CompareNilIC : public IC { |
| 641 | public: |
| 642 | explicit CompareNilIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {} |
| 643 | |
| 644 | Handle<Object> CompareNil(Handle<Object> object); |
| 645 | |
| 646 | static Handle<Code> GetUninitialized(); |
| 647 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 648 | static void Clear(Address address, Code* target, Address constant_pool); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 649 | |
| 650 | static Handle<Object> DoCompareNilSlow(Isolate* isolate, NilValue nil, |
| 651 | Handle<Object> object); |
| 652 | }; |
| 653 | |
| 654 | |
| 655 | class ToBooleanIC : public IC { |
| 656 | public: |
| 657 | explicit ToBooleanIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {} |
| 658 | |
| 659 | Handle<Object> ToBoolean(Handle<Object> object); |
| 660 | }; |
| 661 | |
| 662 | |
| 663 | // Helper for BinaryOpIC and CompareIC. |
| 664 | enum InlinedSmiCheck { ENABLE_INLINED_SMI_CHECK, DISABLE_INLINED_SMI_CHECK }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 665 | void PatchInlinedSmiCode(Isolate* isolate, Address address, |
| 666 | InlinedSmiCheck check); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 667 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 668 | } // namespace internal |
| 669 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 670 | |
| 671 | #endif // V8_IC_H_ |