blob: 5dae179f7cf233d4e3998ac0e59953ce3cb24d7d [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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 Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/messages.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011
12namespace v8 {
13namespace internal {
14
Ben Murdochb8a8cc12014-11-26 15:28:44 +000015//
16// IC is the base class for LoadIC, StoreIC, KeyedLoadIC, and KeyedStoreIC.
17//
18class IC {
19 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020 // 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 Murdoch4a90d5f2016-03-22 12:00:34 +000029 IC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030 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
Ben Murdochc5610432016-08-08 18:44:38 +010038 bool RecomputeHandlerForName(Handle<Object> name);
39 void MarkRecomputeHandler(Handle<Object> name) {
40 DCHECK(RecomputeHandlerForName(name));
Emily Bernierd0a1eb72015-03-24 16:35:39 -040041 old_state_ = state_;
Ben Murdochc5610432016-08-08 18:44:38 +010042 state_ = RECOMPUTE_HANDLER;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000043 }
44
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 // Clear the inline cache to initial state.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000046 static void Clear(Isolate* isolate, Address address, Address constant_pool);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047
48#ifdef DEBUG
49 bool IsLoadStub() const {
Ben Murdochc5610432016-08-08 18:44:38 +010050 return kind_ == Code::LOAD_IC || kind_ == Code::KEYED_LOAD_IC;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052 bool IsStoreStub() const {
Ben Murdochc5610432016-08-08 18:44:38 +010053 return kind_ == Code::STORE_IC || kind_ == Code::KEYED_STORE_IC;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000054 }
Ben Murdochc5610432016-08-08 18:44:38 +010055 bool IsCallStub() const { return kind_ == Code::CALL_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056#endif
57
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058 static inline Handle<Map> GetHandlerCacheHolder(Handle<Map> receiver_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059 bool receiver_is_holder,
60 Isolate* isolate,
61 CacheHolderFlag* flag);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000062 static inline Handle<Map> GetICCacheHolder(Handle<Map> receiver_map,
63 Isolate* isolate,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064 CacheHolderFlag* flag);
65
66 static bool IsCleared(Code* code) {
67 InlineCacheState state = code->ic_state();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000068 return !FLAG_use_ic || state == UNINITIALIZED || state == PREMONOMORPHIC;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000069 }
70
Emily Bernierd0a1eb72015-03-24 16:35:39 -040071 static bool IsCleared(FeedbackNexus* nexus) {
72 InlineCacheState state = nexus->StateFromFeedback();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000073 return !FLAG_use_ic || state == UNINITIALIZED || state == PREMONOMORPHIC;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040074 }
75
Emily Bernierd0a1eb72015-03-24 16:35:39 -040076 static bool ICUseVector(Code::Kind kind) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000077 return kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC ||
78 kind == Code::CALL_IC || kind == Code::STORE_IC ||
79 kind == Code::KEYED_STORE_IC;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040080 }
81
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000083 Address fp() const { return fp_; }
84 Address pc() const { return *pc_address_; }
85 Isolate* isolate() const { return isolate_; }
86
87 // Get the shared function info of the caller.
88 SharedFunctionInfo* GetSharedFunctionInfo() const;
89 // Get the code object of the caller.
90 Code* GetCode() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000091
92 bool AddressIsOptimizedCode() const;
93 inline bool AddressIsDeoptimizedCode() const;
94 inline static bool AddressIsDeoptimizedCode(Isolate* isolate,
95 Address address);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096
97 // Set the call-site target.
98 inline void set_target(Code* code);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000099 bool is_vector_set() { return vector_set_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000100
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400101 bool UseVector() const {
102 bool use = ICUseVector(kind());
103 // If we are supposed to use the nexus, verify the nexus is non-null.
Ben Murdochc5610432016-08-08 18:44:38 +0100104 DCHECK(!use || nexus_ != nullptr);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400105 return use;
106 }
107
108 // Configure for most states.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100109 void ConfigureVectorState(IC::State new_state, Handle<Object> key);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400110 // Configure the vector for MONOMORPHIC.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 void ConfigureVectorState(Handle<Name> name, Handle<Map> map,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400112 Handle<Code> handler);
113 // Configure the vector for POLYMORPHIC.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000114 void ConfigureVectorState(Handle<Name> name, MapHandleList* maps,
115 CodeHandleList* handlers);
116 // Configure the vector for POLYMORPHIC with transitions (only for element
117 // keyed stores).
118 void ConfigureVectorState(MapHandleList* maps,
119 MapHandleList* transitioned_maps,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400120 CodeHandleList* handlers);
121
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000122 char TransitionMarkFromState(IC::State state);
123 void TraceIC(const char* type, Handle<Object> name);
124 void TraceIC(const char* type, Handle<Object> name, State old_state,
125 State new_state);
126
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127 MaybeHandle<Object> TypeError(MessageTemplate::Template,
128 Handle<Object> object, Handle<Object> key);
129 MaybeHandle<Object> ReferenceError(Handle<Name> name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130
131 // Access the target code for the given IC address.
132 static inline Code* GetTargetAtAddress(Address address,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000133 Address constant_pool);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134 static inline void SetTargetAtAddress(Address address, Code* target,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000135 Address constant_pool);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400136 // As a vector-based IC, type feedback must be updated differently.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000137 static void OnTypeFeedbackChanged(Isolate* isolate, Code* host);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 static void PostPatching(Address address, Code* target, Code* old_target);
139
140 // Compute the handler either by compiling or by retrieving a cached version.
141 Handle<Code> ComputeHandler(LookupIterator* lookup,
142 Handle<Object> value = Handle<Code>::null());
Ben Murdochc5610432016-08-08 18:44:38 +0100143 virtual Handle<Code> GetMapIndependentHandler(LookupIterator* lookup) {
144 UNREACHABLE();
145 return Handle<Code>::null();
146 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000147 virtual Handle<Code> CompileHandler(LookupIterator* lookup,
148 Handle<Object> value,
149 CacheHolderFlag cache_holder) {
150 UNREACHABLE();
151 return Handle<Code>::null();
152 }
153
154 void UpdateMonomorphicIC(Handle<Code> handler, Handle<Name> name);
155 bool UpdatePolymorphicIC(Handle<Name> name, Handle<Code> code);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000156 void UpdateMegamorphicCache(Map* map, Name* name, Code* code);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157
158 void CopyICToMegamorphicCache(Handle<Name> name);
159 bool IsTransitionOfMonomorphicTarget(Map* source_map, Map* target_map);
160 void PatchCache(Handle<Name> name, Handle<Code> code);
161 Code::Kind kind() const { return kind_; }
Ben Murdochc5610432016-08-08 18:44:38 +0100162 bool is_keyed() const {
163 return kind_ == Code::KEYED_LOAD_IC || kind_ == Code::KEYED_STORE_IC;
164 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165 Code::Kind handler_kind() const {
166 if (kind_ == Code::KEYED_LOAD_IC) return Code::LOAD_IC;
167 DCHECK(kind_ == Code::LOAD_IC || kind_ == Code::STORE_IC ||
168 kind_ == Code::KEYED_STORE_IC);
169 return kind_;
170 }
Ben Murdochc5610432016-08-08 18:44:38 +0100171 bool ShouldRecomputeHandler(Handle<Object> receiver, Handle<String> name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000172
173 ExtraICState extra_ic_state() const { return extra_ic_state_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000174
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000175 Handle<Map> receiver_map() { return receiver_map_; }
176 void update_receiver_map(Handle<Object> receiver) {
177 if (receiver->IsSmi()) {
178 receiver_map_ = isolate_->factory()->heap_number_map();
179 } else {
180 receiver_map_ = handle(HeapObject::cast(*receiver)->map());
181 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000182 }
183
184 void TargetMaps(MapHandleList* list) {
185 FindTargetMaps();
186 for (int i = 0; i < target_maps_.length(); i++) {
187 list->Add(target_maps_.at(i));
188 }
189 }
190
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000191 Map* FirstTargetMap() {
192 FindTargetMaps();
193 return target_maps_.length() > 0 ? *target_maps_.at(0) : NULL;
194 }
195
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400196 Handle<TypeFeedbackVector> vector() const { return nexus()->vector_handle(); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000197 FeedbackVectorSlot slot() const { return nexus()->slot(); }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400198 State saved_state() const {
Ben Murdochc5610432016-08-08 18:44:38 +0100199 return state() == RECOMPUTE_HANDLER ? old_state_ : state();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400200 }
201
202 template <class NexusClass>
203 NexusClass* casted_nexus() {
204 return static_cast<NexusClass*>(nexus_);
205 }
206 FeedbackNexus* nexus() const { return nexus_; }
207
208 inline Code* get_host();
Ben Murdochc5610432016-08-08 18:44:38 +0100209 inline Code* target() const;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400210
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000211 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000212 inline Address constant_pool() const;
213 inline Address raw_constant_pool() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000214
215 void FindTargetMaps() {
216 if (target_maps_set_) return;
217 target_maps_set_ = true;
Ben Murdochc5610432016-08-08 18:44:38 +0100218 DCHECK(UseVector());
219 nexus()->ExtractMaps(&target_maps_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000220 }
221
222 // Frame pointer for the frame that uses (calls) the IC.
223 Address fp_;
224
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000225 // All access to the program counter and constant pool of an IC structure is
226 // indirect to make the code GC safe. This feature is crucial since
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000227 // GetProperty and SetProperty are called and they in turn might
228 // invoke the garbage collector.
229 Address* pc_address_;
230
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000231 // The constant pool of the code which originally called the IC (which might
232 // be for the breakpointed copy of the original code).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000233 Address* constant_pool_address_;
234
235 Isolate* isolate_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000236
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000237 bool vector_set_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400238 State old_state_; // For saving if we marked as prototype failure.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000239 State state_;
240 Code::Kind kind_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000241 Handle<Map> receiver_map_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 MaybeHandle<Code> maybe_handler_;
243
244 ExtraICState extra_ic_state_;
245 MapHandleList target_maps_;
246 bool target_maps_set_;
247
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400248 FeedbackNexus* nexus_;
249
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000250 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
251};
252
253
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000254class CallIC : public IC {
255 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400256 CallIC(Isolate* isolate, CallICNexus* nexus)
257 : IC(EXTRA_CALL_FRAME, isolate, nexus) {
258 DCHECK(nexus != NULL);
259 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000260
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000261 void HandleMiss(Handle<Object> function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000262
263 // Code generator routines.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000264 static Handle<Code> initialize_stub_in_optimized_code(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100265 Isolate* isolate, int argc, ConvertReceiverMode mode,
266 TailCallMode tail_call_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000267
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400268 static void Clear(Isolate* isolate, Code* host, CallICNexus* nexus);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000269};
270
271
272class LoadIC : public IC {
273 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000274 TypeofMode typeof_mode() const {
275 return LoadICState::GetTypeofMode(extra_ic_state());
276 }
277
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400278 LoadIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL)
279 : IC(depth, isolate, nexus) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000280 DCHECK(nexus != NULL);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400281 DCHECK(IsLoadStub());
282 }
283
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000284 bool ShouldThrowReferenceError(Handle<Object> receiver) {
285 return receiver->IsJSGlobalObject() && typeof_mode() == NOT_INSIDE_TYPEOF;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000286 }
287
288 // Code generator routines.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000289
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000290 static void GenerateMiss(MacroAssembler* masm);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100291 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
292 static void GenerateNormal(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000293
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400294 static Handle<Code> initialize_stub_in_optimized_code(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000295 Isolate* isolate, ExtraICState extra_state, State initialization_state);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000296
297 MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
298 Handle<Name> name);
299
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400300 static void Clear(Isolate* isolate, Code* host, LoadICNexus* nexus);
301
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000302 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000303 Handle<Code> slow_stub() const {
Ben Murdochc5610432016-08-08 18:44:38 +0100304 return isolate()->builtins()->LoadIC_Slow();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000305 }
306
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000307 // Update the inline cache and the global stub cache based on the
308 // lookup result.
309 void UpdateCaches(LookupIterator* lookup);
310
Ben Murdochc5610432016-08-08 18:44:38 +0100311 Handle<Code> GetMapIndependentHandler(LookupIterator* lookup) override;
312
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000313 Handle<Code> CompileHandler(LookupIterator* lookup, Handle<Object> unused,
314 CacheHolderFlag cache_holder) override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000315
316 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000317 Handle<Code> SimpleFieldLoad(FieldIndex index);
318
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000319 friend class IC;
320};
321
322
323class KeyedLoadIC : public LoadIC {
324 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400325 KeyedLoadIC(FrameDepth depth, Isolate* isolate,
326 KeyedLoadICNexus* nexus = NULL)
327 : LoadIC(depth, isolate, nexus) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000328 DCHECK(nexus != NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000329 }
330
331 MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
332 Handle<Object> key);
333
334 // Code generator routines.
335 static void GenerateMiss(MacroAssembler* masm);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100336 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100337 static void GenerateMegamorphic(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000338
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000339 static Handle<Code> initialize_stub_in_optimized_code(
340 Isolate* isolate, State initialization_state, ExtraICState extra_state);
341 static Handle<Code> ChooseMegamorphicStub(Isolate* isolate,
342 ExtraICState extra_state);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000343
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400344 static void Clear(Isolate* isolate, Code* host, KeyedLoadICNexus* nexus);
345
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000346 protected:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400347 // receiver is HeapObject because it could be a String or a JSObject
Ben Murdochc5610432016-08-08 18:44:38 +0100348 void UpdateLoadElement(Handle<HeapObject> receiver);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000349
350 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000351 friend class IC;
352};
353
354
355class StoreIC : public IC {
356 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000357 StoreIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL)
358 : IC(depth, isolate, nexus) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000359 DCHECK(IsStoreStub());
360 }
361
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000362 LanguageMode language_mode() const {
363 return StoreICState::GetLanguageMode(extra_ic_state());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000364 }
365
366 // Code generators for stub routines. Only called once at startup.
367 static void GenerateSlow(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000368 static void GenerateMiss(MacroAssembler* masm);
369 static void GenerateMegamorphic(MacroAssembler* masm);
370 static void GenerateNormal(MacroAssembler* masm);
371 static void GenerateRuntimeSetProperty(MacroAssembler* masm,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000372 LanguageMode language_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000373
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000374 static Handle<Code> initialize_stub_in_optimized_code(
375 Isolate* isolate, LanguageMode language_mode, State initialization_state);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000376
377 MUST_USE_RESULT MaybeHandle<Object> Store(
378 Handle<Object> object, Handle<Name> name, Handle<Object> value,
379 JSReceiver::StoreFromKeyed store_mode =
380 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED);
381
382 bool LookupForWrite(LookupIterator* it, Handle<Object> value,
383 JSReceiver::StoreFromKeyed store_mode);
384
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000385 static void Clear(Isolate* isolate, Code* host, StoreICNexus* nexus);
386
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000387 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000388 // Stub accessors.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000389 Handle<Code> slow_stub() const;
390
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000391 // Update the inline cache and the global stub cache based on the
392 // lookup result.
393 void UpdateCaches(LookupIterator* lookup, Handle<Object> value,
394 JSReceiver::StoreFromKeyed store_mode);
Ben Murdochc5610432016-08-08 18:44:38 +0100395 Handle<Code> GetMapIndependentHandler(LookupIterator* lookup) override;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000396 Handle<Code> CompileHandler(LookupIterator* lookup, Handle<Object> value,
397 CacheHolderFlag cache_holder) override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000398
399 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000400 friend class IC;
401};
402
403
404enum KeyedStoreCheckMap { kDontCheckMap, kCheckMap };
405
406
407enum KeyedStoreIncrementLength { kDontIncrementLength, kIncrementLength };
408
409
410class KeyedStoreIC : public StoreIC {
411 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412 KeyedAccessStoreMode GetKeyedAccessStoreMode() {
413 return casted_nexus<KeyedStoreICNexus>()->GetKeyedAccessStoreMode();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000414 }
415
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000416 KeyedStoreIC(FrameDepth depth, Isolate* isolate,
417 KeyedStoreICNexus* nexus = NULL)
Ben Murdochc5610432016-08-08 18:44:38 +0100418 : StoreIC(depth, isolate, nexus) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000419
420 MUST_USE_RESULT MaybeHandle<Object> Store(Handle<Object> object,
421 Handle<Object> name,
422 Handle<Object> value);
423
424 // Code generators for stub routines. Only called once at startup.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425 static void GenerateMiss(MacroAssembler* masm);
426 static void GenerateSlow(MacroAssembler* masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000427 static void GenerateMegamorphic(MacroAssembler* masm,
428 LanguageMode language_mode);
429
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000430 static Handle<Code> initialize_stub_in_optimized_code(
431 Isolate* isolate, LanguageMode language_mode, State initialization_state);
432 static Handle<Code> ChooseMegamorphicStub(Isolate* isolate,
433 ExtraICState extra_state);
434
435 static void Clear(Isolate* isolate, Code* host, KeyedStoreICNexus* nexus);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000436
437 protected:
Ben Murdochc5610432016-08-08 18:44:38 +0100438 void UpdateStoreElement(Handle<Map> receiver_map,
439 KeyedAccessStoreMode store_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000440
441 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000442 Handle<Map> ComputeTransitionedMap(Handle<Map> map,
443 KeyedAccessStoreMode store_mode);
444
445 friend class IC;
446};
447
448
449// Type Recording BinaryOpIC, that records the types of the inputs and outputs.
450class BinaryOpIC : public IC {
451 public:
452 explicit BinaryOpIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
453
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000454 MaybeHandle<Object> Transition(Handle<AllocationSite> allocation_site,
455 Handle<Object> left,
456 Handle<Object> right) WARN_UNUSED_RESULT;
457};
458
459
460class CompareIC : public IC {
461 public:
462 CompareIC(Isolate* isolate, Token::Value op)
463 : IC(EXTRA_CALL_FRAME, isolate), op_(op) {}
464
465 // Update the inline cache for the given operands.
466 Code* UpdateCaches(Handle<Object> x, Handle<Object> y);
467
468 // Helper function for computing the condition for a compare operation.
469 static Condition ComputeCondition(Token::Value op);
470
471 // Factory method for getting an uninitialized compare stub.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100472 static Handle<Code> GetUninitialized(Isolate* isolate, Token::Value op);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000473
474 private:
475 static bool HasInlinedSmiCode(Address address);
476
477 bool strict() const { return op_ == Token::EQ_STRICT; }
478 Condition GetCondition() const { return ComputeCondition(op_); }
479
Ben Murdoch097c5b22016-05-18 11:27:45 +0100480 static Code* GetRawUninitialized(Isolate* isolate, Token::Value op);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000481
482 static void Clear(Isolate* isolate, Address address, Code* target,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000483 Address constant_pool);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000484
485 Token::Value op_;
486
487 friend class IC;
488};
489
490
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000491class ToBooleanIC : public IC {
492 public:
493 explicit ToBooleanIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
494
495 Handle<Object> ToBoolean(Handle<Object> object);
496};
497
498
499// Helper for BinaryOpIC and CompareIC.
500enum InlinedSmiCheck { ENABLE_INLINED_SMI_CHECK, DISABLE_INLINED_SMI_CHECK };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000501void PatchInlinedSmiCode(Isolate* isolate, Address address,
502 InlinedSmiCheck check);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000503
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000504} // namespace internal
505} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000506
507#endif // V8_IC_H_