blob: 8d45eab4b2c6301e2304dfd4686d45ae73d5d559 [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 Murdoch61f157c2016-09-16 13:49:30 +010050 return kind_ == Code::LOAD_IC || kind_ == Code::LOAD_GLOBAL_IC ||
51 kind_ == Code::KEYED_LOAD_IC;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000053 bool IsStoreStub() const {
Ben Murdochc5610432016-08-08 18:44:38 +010054 return kind_ == Code::STORE_IC || kind_ == Code::KEYED_STORE_IC;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055 }
Ben Murdochc5610432016-08-08 18:44:38 +010056 bool IsCallStub() const { return kind_ == Code::CALL_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057#endif
58
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000059 static inline Handle<Map> GetHandlerCacheHolder(Handle<Map> receiver_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000060 bool receiver_is_holder,
61 Isolate* isolate,
62 CacheHolderFlag* flag);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000063 static inline Handle<Map> GetICCacheHolder(Handle<Map> receiver_map,
64 Isolate* isolate,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065 CacheHolderFlag* flag);
66
Emily Bernierd0a1eb72015-03-24 16:35:39 -040067 static bool IsCleared(FeedbackNexus* nexus) {
68 InlineCacheState state = nexus->StateFromFeedback();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000069 return !FLAG_use_ic || state == UNINITIALIZED || state == PREMONOMORPHIC;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040070 }
71
Emily Bernierd0a1eb72015-03-24 16:35:39 -040072 static bool ICUseVector(Code::Kind kind) {
Ben Murdoch61f157c2016-09-16 13:49:30 +010073 return kind == Code::LOAD_IC || kind == Code::LOAD_GLOBAL_IC ||
74 kind == Code::KEYED_LOAD_IC || kind == Code::CALL_IC ||
75 kind == Code::STORE_IC || kind == Code::KEYED_STORE_IC;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040076 }
77
Ben Murdoch61f157c2016-09-16 13:49:30 +010078 static InlineCacheState StateFromCode(Code* code);
79
Ben Murdochb8a8cc12014-11-26 15:28:44 +000080 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081 Address fp() const { return fp_; }
82 Address pc() const { return *pc_address_; }
83 Isolate* isolate() const { return isolate_; }
84
85 // Get the shared function info of the caller.
86 SharedFunctionInfo* GetSharedFunctionInfo() const;
87 // Get the code object of the caller.
88 Code* GetCode() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089
90 bool AddressIsOptimizedCode() const;
91 inline bool AddressIsDeoptimizedCode() const;
92 inline static bool AddressIsDeoptimizedCode(Isolate* isolate,
93 Address address);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000094
95 // Set the call-site target.
96 inline void set_target(Code* code);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000097 bool is_vector_set() { return vector_set_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000098
Emily Bernierd0a1eb72015-03-24 16:35:39 -040099 bool UseVector() const {
100 bool use = ICUseVector(kind());
101 // If we are supposed to use the nexus, verify the nexus is non-null.
Ben Murdochc5610432016-08-08 18:44:38 +0100102 DCHECK(!use || nexus_ != nullptr);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400103 return use;
104 }
105
106 // Configure for most states.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100107 void ConfigureVectorState(IC::State new_state, Handle<Object> key);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400108 // Configure the vector for MONOMORPHIC.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000109 void ConfigureVectorState(Handle<Name> name, Handle<Map> map,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400110 Handle<Code> handler);
111 // Configure the vector for POLYMORPHIC.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000112 void ConfigureVectorState(Handle<Name> name, MapHandleList* maps,
113 CodeHandleList* handlers);
114 // Configure the vector for POLYMORPHIC with transitions (only for element
115 // keyed stores).
116 void ConfigureVectorState(MapHandleList* maps,
117 MapHandleList* transitioned_maps,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400118 CodeHandleList* handlers);
119
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000120 char TransitionMarkFromState(IC::State state);
121 void TraceIC(const char* type, Handle<Object> name);
122 void TraceIC(const char* type, Handle<Object> name, State old_state,
123 State new_state);
124
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000125 MaybeHandle<Object> TypeError(MessageTemplate::Template,
126 Handle<Object> object, Handle<Object> key);
127 MaybeHandle<Object> ReferenceError(Handle<Name> name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128
129 // Access the target code for the given IC address.
130 static inline Code* GetTargetAtAddress(Address address,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131 Address constant_pool);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132 static inline void SetTargetAtAddress(Address address, Code* target,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000133 Address constant_pool);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400134 // As a vector-based IC, type feedback must be updated differently.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000135 static void OnTypeFeedbackChanged(Isolate* isolate, Code* host);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000136 static void PostPatching(Address address, Code* target, Code* old_target);
137
138 // Compute the handler either by compiling or by retrieving a cached version.
139 Handle<Code> ComputeHandler(LookupIterator* lookup,
140 Handle<Object> value = Handle<Code>::null());
Ben Murdochc5610432016-08-08 18:44:38 +0100141 virtual Handle<Code> GetMapIndependentHandler(LookupIterator* lookup) {
142 UNREACHABLE();
143 return Handle<Code>::null();
144 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000145 virtual Handle<Code> CompileHandler(LookupIterator* lookup,
146 Handle<Object> value,
147 CacheHolderFlag cache_holder) {
148 UNREACHABLE();
149 return Handle<Code>::null();
150 }
151
152 void UpdateMonomorphicIC(Handle<Code> handler, Handle<Name> name);
153 bool UpdatePolymorphicIC(Handle<Name> name, Handle<Code> code);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000154 void UpdateMegamorphicCache(Map* map, Name* name, Code* code);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000155
156 void CopyICToMegamorphicCache(Handle<Name> name);
157 bool IsTransitionOfMonomorphicTarget(Map* source_map, Map* target_map);
158 void PatchCache(Handle<Name> name, Handle<Code> code);
159 Code::Kind kind() const { return kind_; }
Ben Murdochc5610432016-08-08 18:44:38 +0100160 bool is_keyed() const {
161 return kind_ == Code::KEYED_LOAD_IC || kind_ == Code::KEYED_STORE_IC;
162 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000163 Code::Kind handler_kind() const {
164 if (kind_ == Code::KEYED_LOAD_IC) return Code::LOAD_IC;
165 DCHECK(kind_ == Code::LOAD_IC || kind_ == Code::STORE_IC ||
166 kind_ == Code::KEYED_STORE_IC);
167 return kind_;
168 }
Ben Murdochc5610432016-08-08 18:44:38 +0100169 bool ShouldRecomputeHandler(Handle<Object> receiver, Handle<String> name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000170
171 ExtraICState extra_ic_state() const { return extra_ic_state_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000172
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000173 Handle<Map> receiver_map() { return receiver_map_; }
174 void update_receiver_map(Handle<Object> receiver) {
175 if (receiver->IsSmi()) {
176 receiver_map_ = isolate_->factory()->heap_number_map();
177 } else {
178 receiver_map_ = handle(HeapObject::cast(*receiver)->map());
179 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000180 }
181
182 void TargetMaps(MapHandleList* list) {
183 FindTargetMaps();
184 for (int i = 0; i < target_maps_.length(); i++) {
185 list->Add(target_maps_.at(i));
186 }
187 }
188
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000189 Map* FirstTargetMap() {
190 FindTargetMaps();
191 return target_maps_.length() > 0 ? *target_maps_.at(0) : NULL;
192 }
193
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400194 Handle<TypeFeedbackVector> vector() const { return nexus()->vector_handle(); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000195 FeedbackVectorSlot slot() const { return nexus()->slot(); }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400196 State saved_state() const {
Ben Murdochc5610432016-08-08 18:44:38 +0100197 return state() == RECOMPUTE_HANDLER ? old_state_ : state();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400198 }
199
200 template <class NexusClass>
201 NexusClass* casted_nexus() {
202 return static_cast<NexusClass*>(nexus_);
203 }
204 FeedbackNexus* nexus() const { return nexus_; }
205
206 inline Code* get_host();
Ben Murdochc5610432016-08-08 18:44:38 +0100207 inline Code* target() const;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400208
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000209 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000210 inline Address constant_pool() const;
211 inline Address raw_constant_pool() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000212
213 void FindTargetMaps() {
214 if (target_maps_set_) return;
215 target_maps_set_ = true;
Ben Murdochc5610432016-08-08 18:44:38 +0100216 DCHECK(UseVector());
217 nexus()->ExtractMaps(&target_maps_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218 }
219
220 // Frame pointer for the frame that uses (calls) the IC.
221 Address fp_;
222
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000223 // All access to the program counter and constant pool of an IC structure is
224 // indirect to make the code GC safe. This feature is crucial since
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000225 // GetProperty and SetProperty are called and they in turn might
226 // invoke the garbage collector.
227 Address* pc_address_;
228
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000229 // The constant pool of the code which originally called the IC (which might
230 // be for the breakpointed copy of the original code).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000231 Address* constant_pool_address_;
232
233 Isolate* isolate_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000234
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000235 bool vector_set_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400236 State old_state_; // For saving if we marked as prototype failure.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237 State state_;
238 Code::Kind kind_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000239 Handle<Map> receiver_map_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000240 MaybeHandle<Code> maybe_handler_;
241
242 ExtraICState extra_ic_state_;
243 MapHandleList target_maps_;
244 bool target_maps_set_;
245
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400246 FeedbackNexus* nexus_;
247
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000248 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
249};
250
251
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000252class CallIC : public IC {
253 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400254 CallIC(Isolate* isolate, CallICNexus* nexus)
255 : IC(EXTRA_CALL_FRAME, isolate, nexus) {
256 DCHECK(nexus != NULL);
257 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000258
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000259 void HandleMiss(Handle<Object> function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000260
261 // Code generator routines.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000262 static Handle<Code> initialize_stub_in_optimized_code(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100263 Isolate* isolate, int argc, ConvertReceiverMode mode,
264 TailCallMode tail_call_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000265
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400266 static void Clear(Isolate* isolate, Code* host, CallICNexus* nexus);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000267};
268
269
270class LoadIC : public IC {
271 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400272 LoadIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL)
273 : IC(depth, isolate, nexus) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000274 DCHECK(nexus != NULL);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400275 DCHECK(IsLoadStub());
276 }
277
Ben Murdoch61f157c2016-09-16 13:49:30 +0100278 bool ShouldThrowReferenceError() const {
279 return kind() == Code::LOAD_GLOBAL_IC &&
280 LoadGlobalICState::GetTypeofMode(extra_ic_state()) ==
281 NOT_INSIDE_TYPEOF;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000282 }
283
284 // Code generator routines.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000285
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000286 static void GenerateMiss(MacroAssembler* masm);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100287 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
288 static void GenerateNormal(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289
Ben Murdoch61f157c2016-09-16 13:49:30 +0100290 static Handle<Code> initialize_stub_in_optimized_code(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000291
292 MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
293 Handle<Name> name);
294
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400295 static void Clear(Isolate* isolate, Code* host, LoadICNexus* nexus);
296
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000297 protected:
Ben Murdoch61f157c2016-09-16 13:49:30 +0100298 virtual Handle<Code> slow_stub() const {
Ben Murdochc5610432016-08-08 18:44:38 +0100299 return isolate()->builtins()->LoadIC_Slow();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000300 }
301
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000302 // Update the inline cache and the global stub cache based on the
303 // lookup result.
304 void UpdateCaches(LookupIterator* lookup);
305
Ben Murdochc5610432016-08-08 18:44:38 +0100306 Handle<Code> GetMapIndependentHandler(LookupIterator* lookup) override;
307
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000308 Handle<Code> CompileHandler(LookupIterator* lookup, Handle<Object> unused,
309 CacheHolderFlag cache_holder) override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000310
311 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000312 Handle<Code> SimpleFieldLoad(FieldIndex index);
313
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000314 friend class IC;
315};
316
Ben Murdoch61f157c2016-09-16 13:49:30 +0100317class LoadGlobalIC : public LoadIC {
318 public:
319 LoadGlobalIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL)
320 : LoadIC(depth, isolate, nexus) {}
321
322 static Handle<Code> initialize_stub_in_optimized_code(
323 Isolate* isolate, ExtraICState extra_state);
324
325 MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Name> name);
326
327 static void Clear(Isolate* isolate, Code* host, LoadGlobalICNexus* nexus);
328
329 protected:
330 Handle<Code> slow_stub() const override {
331 return isolate()->builtins()->LoadGlobalIC_Slow();
332 }
333};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000334
335class KeyedLoadIC : public LoadIC {
336 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400337 KeyedLoadIC(FrameDepth depth, Isolate* isolate,
338 KeyedLoadICNexus* nexus = NULL)
339 : LoadIC(depth, isolate, nexus) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000340 DCHECK(nexus != NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000341 }
342
343 MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
344 Handle<Object> key);
345
346 // Code generator routines.
347 static void GenerateMiss(MacroAssembler* masm);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100348 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100349 static void GenerateMegamorphic(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000350
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000351 static Handle<Code> initialize_stub_in_optimized_code(
Ben Murdoch61f157c2016-09-16 13:49:30 +0100352 Isolate* isolate, ExtraICState extra_state);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000353 static Handle<Code> ChooseMegamorphicStub(Isolate* isolate,
354 ExtraICState extra_state);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000355
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400356 static void Clear(Isolate* isolate, Code* host, KeyedLoadICNexus* nexus);
357
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000358 protected:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400359 // receiver is HeapObject because it could be a String or a JSObject
Ben Murdochc5610432016-08-08 18:44:38 +0100360 void UpdateLoadElement(Handle<HeapObject> receiver);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000361
362 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000363 friend class IC;
364};
365
366
367class StoreIC : public IC {
368 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000369 StoreIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL)
370 : IC(depth, isolate, nexus) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000371 DCHECK(IsStoreStub());
372 }
373
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000374 LanguageMode language_mode() const {
375 return StoreICState::GetLanguageMode(extra_ic_state());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000376 }
377
378 // Code generators for stub routines. Only called once at startup.
379 static void GenerateSlow(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000380 static void GenerateMiss(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000381 static void GenerateNormal(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000382
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000383 static Handle<Code> initialize_stub_in_optimized_code(
Ben Murdoch61f157c2016-09-16 13:49:30 +0100384 Isolate* isolate, LanguageMode language_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000385
386 MUST_USE_RESULT MaybeHandle<Object> Store(
387 Handle<Object> object, Handle<Name> name, Handle<Object> value,
388 JSReceiver::StoreFromKeyed store_mode =
389 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED);
390
391 bool LookupForWrite(LookupIterator* it, Handle<Object> value,
392 JSReceiver::StoreFromKeyed store_mode);
393
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000394 static void Clear(Isolate* isolate, Code* host, StoreICNexus* nexus);
395
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000396 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000397 // Stub accessors.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100398 Handle<Code> slow_stub() const {
399 return isolate()->builtins()->StoreIC_Slow();
400 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000401
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000402 // Update the inline cache and the global stub cache based on the
403 // lookup result.
404 void UpdateCaches(LookupIterator* lookup, Handle<Object> value,
405 JSReceiver::StoreFromKeyed store_mode);
Ben Murdochc5610432016-08-08 18:44:38 +0100406 Handle<Code> GetMapIndependentHandler(LookupIterator* lookup) override;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000407 Handle<Code> CompileHandler(LookupIterator* lookup, Handle<Object> value,
408 CacheHolderFlag cache_holder) override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000409
410 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000411 friend class IC;
412};
413
414
415enum KeyedStoreCheckMap { kDontCheckMap, kCheckMap };
416
417
418enum KeyedStoreIncrementLength { kDontIncrementLength, kIncrementLength };
419
420
421class KeyedStoreIC : public StoreIC {
422 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000423 KeyedAccessStoreMode GetKeyedAccessStoreMode() {
424 return casted_nexus<KeyedStoreICNexus>()->GetKeyedAccessStoreMode();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425 }
426
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000427 KeyedStoreIC(FrameDepth depth, Isolate* isolate,
428 KeyedStoreICNexus* nexus = NULL)
Ben Murdochc5610432016-08-08 18:44:38 +0100429 : StoreIC(depth, isolate, nexus) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000430
431 MUST_USE_RESULT MaybeHandle<Object> Store(Handle<Object> object,
432 Handle<Object> name,
433 Handle<Object> value);
434
435 // Code generators for stub routines. Only called once at startup.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000436 static void GenerateMiss(MacroAssembler* masm);
437 static void GenerateSlow(MacroAssembler* masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000438 static void GenerateMegamorphic(MacroAssembler* masm,
439 LanguageMode language_mode);
440
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000441 static Handle<Code> initialize_stub_in_optimized_code(
Ben Murdoch61f157c2016-09-16 13:49:30 +0100442 Isolate* isolate, LanguageMode language_mode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000443 static Handle<Code> ChooseMegamorphicStub(Isolate* isolate,
444 ExtraICState extra_state);
445
446 static void Clear(Isolate* isolate, Code* host, KeyedStoreICNexus* nexus);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000447
448 protected:
Ben Murdochc5610432016-08-08 18:44:38 +0100449 void UpdateStoreElement(Handle<Map> receiver_map,
450 KeyedAccessStoreMode store_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000451
452 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000453 Handle<Map> ComputeTransitionedMap(Handle<Map> map,
454 KeyedAccessStoreMode store_mode);
455
456 friend class IC;
457};
458
459
460// Type Recording BinaryOpIC, that records the types of the inputs and outputs.
461class BinaryOpIC : public IC {
462 public:
463 explicit BinaryOpIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
464
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000465 MaybeHandle<Object> Transition(Handle<AllocationSite> allocation_site,
466 Handle<Object> left,
467 Handle<Object> right) WARN_UNUSED_RESULT;
468};
469
470
471class CompareIC : public IC {
472 public:
473 CompareIC(Isolate* isolate, Token::Value op)
474 : IC(EXTRA_CALL_FRAME, isolate), op_(op) {}
475
476 // Update the inline cache for the given operands.
477 Code* UpdateCaches(Handle<Object> x, Handle<Object> y);
478
479 // Helper function for computing the condition for a compare operation.
480 static Condition ComputeCondition(Token::Value op);
481
482 // Factory method for getting an uninitialized compare stub.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100483 static Handle<Code> GetUninitialized(Isolate* isolate, Token::Value op);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000484
485 private:
486 static bool HasInlinedSmiCode(Address address);
487
488 bool strict() const { return op_ == Token::EQ_STRICT; }
489 Condition GetCondition() const { return ComputeCondition(op_); }
490
Ben Murdoch097c5b22016-05-18 11:27:45 +0100491 static Code* GetRawUninitialized(Isolate* isolate, Token::Value op);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000492
493 static void Clear(Isolate* isolate, Address address, Code* target,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000494 Address constant_pool);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000495
496 Token::Value op_;
497
498 friend class IC;
499};
500
501
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000502class ToBooleanIC : public IC {
503 public:
504 explicit ToBooleanIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
505
506 Handle<Object> ToBoolean(Handle<Object> object);
507};
508
509
510// Helper for BinaryOpIC and CompareIC.
511enum InlinedSmiCheck { ENABLE_INLINED_SMI_CHECK, DISABLE_INLINED_SMI_CHECK };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000512void PatchInlinedSmiCode(Isolate* isolate, Address address,
513 InlinedSmiCheck check);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000514
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000515} // namespace internal
516} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000517
518#endif // V8_IC_H_