v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
ic.h
Go to the documentation of this file.
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_IC_H_
6#define V8_IC_IC_H_
7
8#include <vector>
9
12#include "src/heap/factory.h"
13#include "src/ic/stub-cache.h"
15#include "src/objects/map.h"
17#include "src/objects/smi.h"
18
19namespace v8 {
20namespace internal {
21
22enum class NamedPropertyType : bool { kNotOwn, kOwn };
23
24//
25// IC is the base class for LoadIC, StoreIC, KeyedLoadIC, and KeyedStoreIC.
26//
27class IC {
28 public:
29 // Alias the inline cache state type to make the IC code more readable.
31
32 // Construct the IC structure with the given number of extra
33 // JavaScript frames on the stack.
34 IC(Isolate* isolate, Handle<FeedbackVector> vector, FeedbackSlot slot,
36 virtual ~IC() = default;
37
38 State state() const { return state_; }
39
40 // Compute the current IC state based on the target stub, lookup_start_object
41 // and name.
42 void UpdateState(DirectHandle<Object> lookup_start_object,
44
51
52 bool IsAnyHas() const { return IsKeyedHasIC(); }
53 bool IsAnyLoad() const {
54 return IsLoadIC() || IsLoadGlobalIC() || IsKeyedLoadIC();
55 }
61 bool IsAnyDefineOwn() const {
63 }
64
65 static inline bool IsHandler(Tagged<MaybeObject> object);
66
67 // Notify the IC system that a feedback has changed.
68 static void OnFeedbackChanged(Isolate* isolate, Tagged<FeedbackVector> vector,
69 FeedbackSlot slot, const char* reason);
70
71 void OnFeedbackChanged(const char* reason);
72
73 protected:
74 void set_slow_stub_reason(const char* reason) { slow_stub_reason_ = reason; }
77
78 Isolate* isolate() const { return isolate_; }
79
80 bool is_vector_set() { return vector_set_; }
81 inline bool vector_needs_update();
82
83 // Configure for most states.
85 // Configure the vector for MONOMORPHIC.
87 DirectHandle<Object> handler);
89 const MaybeObjectDirectHandle& handler);
90 // Configure the vector for POLYMORPHIC.
92 MaybeObjectHandles* handlers);
94 MapsAndHandlers const& maps_and_handlers);
95
97 void TraceIC(const char* type, DirectHandle<Object> name);
98 void TraceIC(const char* type, DirectHandle<Object> name, State old_state,
99 State new_state);
100
104
106 DirectHandle<Name> name);
107 bool UpdateMegaDOMIC(const MaybeObjectDirectHandle& handler,
108 DirectHandle<Name> name);
110 const MaybeObjectDirectHandle& handler);
112 const MaybeObjectDirectHandle& handler);
113
115
118 Tagged<Map> target_map);
119 void SetCache(DirectHandle<Name> name, Handle<Object> handler);
120 void SetCache(DirectHandle<Name> name, const MaybeObjectHandle& handler);
121 FeedbackSlotKind kind() const { return kind_; }
122 bool IsGlobalIC() const { return IsLoadGlobalIC() || IsStoreGlobalIC(); }
123 bool IsLoadIC() const { return IsLoadICKind(kind_); }
124 bool IsLoadGlobalIC() const { return IsLoadGlobalICKind(kind_); }
125 bool IsKeyedLoadIC() const { return IsKeyedLoadICKind(kind_); }
126 bool IsStoreGlobalIC() const { return IsStoreGlobalICKind(kind_); }
127 bool IsSetNamedIC() const { return IsSetNamedICKind(kind_); }
132 bool IsKeyedStoreIC() const { return IsKeyedStoreICKind(kind_); }
133 bool IsKeyedHasIC() const { return IsKeyedHasICKind(kind_); }
135 bool is_keyed() const {
138 }
140
143
144 void TargetMaps(MapHandles* list) {
146 for (DirectHandle<Map> map : target_maps_) {
147 list->push_back(map);
148 }
149 }
150
155
156 const FeedbackNexus* nexus() const { return &nexus_; }
157 FeedbackNexus* nexus() { return &nexus_; }
158
159 private:
161 if (target_maps_set_) return;
162 target_maps_set_ = true;
163 nexus()->ExtractMaps(&target_maps_);
164 }
165
167
169 State old_state_; // For saving if we marked as prototype failure.
176
177 const char* slow_stub_reason_;
178
180
182};
183
184class LoadIC : public IC {
185 public:
188 : IC(isolate, vector, slot, kind) {
189 DCHECK(IsAnyLoad() || IsAnyHas());
190 }
191
195
198 }
199
200 // If receiver is empty, use object as the receiver.
202 Handle<JSAny> object, Handle<Name> name, bool update_feedback = true,
204
205 protected:
206 // Update the inline cache and the global stub cache based on the
207 // lookup result.
208 void UpdateCaches(LookupIterator* lookup);
209
210 private:
212
213 friend class IC;
215};
216
217class LoadGlobalIC : public LoadIC {
218 public:
221 : LoadIC(isolate, vector, slot, kind) {}
222
224 Handle<Name> name, bool update_feedback = true);
225};
226
227class KeyedLoadIC : public LoadIC {
228 public:
231 : LoadIC(isolate, vector, slot, kind) {}
232
235
236 protected:
239 bool* is_found = nullptr);
240
243
244 // receiver is HeapObject because it could be a String or a JSObject
246 KeyedAccessLoadMode new_load_mode);
247
248 private:
249 friend class IC;
250
252 KeyedAccessLoadMode new_load_mode);
253
254 void LoadElementPolymorphicHandlers(MapHandles* receiver_maps,
255 MaybeObjectHandles* handlers,
256 KeyedAccessLoadMode new_load_mode);
257
259 DirectHandle<Map> receiver_map) const;
260};
261
262class StoreIC : public IC {
263 public:
266 : IC(isolate, vector, slot, kind) {
268 }
269
272 StoreOrigin store_origin = StoreOrigin::kNamed);
273
275 StoreOrigin store_origin);
276
277 protected:
278 // Stub accessors.
279 // Update the inline cache and the global stub cache based on the
280 // lookup result.
282 StoreOrigin store_origin);
283
284 private:
286
287 friend class IC;
288};
289
290class StoreGlobalIC : public StoreIC {
291 public:
294 : StoreIC(isolate, vector, slot, kind) {}
295
298};
299
301
303
309
310class KeyedStoreIC : public StoreIC {
311 public:
313 return nexus()->GetKeyedAccessStoreMode();
314 }
315
318 : StoreIC(isolate, vector, slot, kind) {}
319
322
323 protected:
324 void UpdateStoreElement(Handle<Map> receiver_map,
325 KeyedAccessStoreMode store_mode,
326 Handle<Map> new_receiver_map);
327
328 private:
330 TransitionMode transition_mode);
331
333 KeyedAccessStoreMode store_mode,
335 prev_validity_cell = kNullMaybeHandle);
336
338 MapsAndHandlers* receiver_maps_and_handlers,
339 KeyedAccessStoreMode store_mode);
340
341 friend class IC;
342};
343
357
358} // namespace internal
359} // namespace v8
360
361#endif // V8_IC_IC_H_
void push_back(const_reference x)
Definition handles.h:1092
bool UpdatePolymorphicIC(DirectHandle< Name > name, const MaybeObjectDirectHandle &handler)
Definition ic.cc:620
State state_
Definition ic.h:170
void TraceIC(const char *type, DirectHandle< Object > name)
Definition ic.cc:108
void FindTargetMaps()
Definition ic.h:160
bool IsDefineNamedOwnIC() const
Definition ic.h:128
void set_slow_stub_reason(const char *reason)
Definition ic.h:74
bool IsSetNamedIC() const
Definition ic.h:127
bool IsStoreInArrayLiteralIC() const
Definition ic.h:129
FeedbackSlotKind kind_
Definition ic.h:171
bool is_vector_set()
Definition ic.h:80
bool IsDefineKeyedOwnIC() const
Definition ic.h:134
Handle< Map > lookup_start_object_map()
Definition ic.h:141
void update_lookup_start_object_map(DirectHandle< Object > object)
Definition ic-inl.h:20
State state() const
Definition ic.h:38
bool IsLoadIC() const
Definition ic.h:123
bool IsAnyHas() const
Definition ic.h:52
bool vector_needs_update()
Definition ic-inl.h:39
bool IsStoreGlobalIC() const
Definition ic.h:126
const char * slow_stub_reason_
Definition ic.h:177
static bool IsHandler(Tagged< MaybeObject > object)
Definition ic-inl.h:29
Handle< Map > lookup_start_object_map_
Definition ic.h:172
void set_accessor(Handle< Object > accessor)
Definition ic.h:75
bool IsAnyStore() const
Definition ic.h:56
StubCache * stub_cache()
Definition ic.cc:825
FeedbackNexus * nexus()
Definition ic.h:157
bool IsKeyedHasIC() const
Definition ic.h:133
MaybeDirectHandle< Object > ReferenceError(Handle< Name > name)
Definition ic.cc:298
bool ShouldRecomputeHandler(DirectHandle< String > name)
Definition ic.cc:236
void MarkRecomputeHandler(DirectHandle< Object > name)
Definition ic.h:46
bool IsLoadGlobalIC() const
Definition ic.h:124
bool IsTransitionOfMonomorphicTarget(Tagged< Map > source_map, Tagged< Map > target_map)
Definition ic.cc:720
DISALLOW_IMPLICIT_CONSTRUCTORS(IC)
Isolate * isolate() const
Definition ic.h:78
Tagged< Map > FirstTargetMap()
Definition ic.h:151
bool target_maps_set_
Definition ic.h:175
MaybeHandle< Object > accessor() const
Definition ic.h:76
FeedbackSlotKind kind() const
Definition ic.h:121
MaybeDirectHandle< Object > TypeError(MessageTemplate, Handle< Object > object, Handle< Object > key)
Definition ic.cc:291
bool is_keyed() const
Definition ic.h:135
void UpdateState(DirectHandle< Object > lookup_start_object, DirectHandle< Object > name)
Definition ic.cc:275
void TargetMaps(MapHandles *list)
Definition ic.h:144
bool ConfigureVectorState(IC::State new_state, DirectHandle< Object > key)
Definition ic.cc:335
FeedbackNexus nexus_
Definition ic.h:179
Isolate * isolate_
Definition ic.h:166
void CopyICToMegamorphicCache(DirectHandle< Name > name)
Definition ic.cc:712
MapHandles target_maps_
Definition ic.h:174
virtual ~IC()=default
bool IsKeyedLoadIC() const
Definition ic.h:125
bool IsAnyLoad() const
Definition ic.h:53
bool RecomputeHandlerForName(DirectHandle< Object > name)
Definition ic.cc:264
bool vector_set_
Definition ic.h:168
MaybeHandle< Object > accessor_
Definition ic.h:173
char TransitionMarkFromState(IC::State state)
Definition ic.cc:55
State old_state_
Definition ic.h:169
void UpdateMegamorphicCache(DirectHandle< Map > map, DirectHandle< Name > name, const MaybeObjectDirectHandle &handler)
Definition ic.cc:839
bool IsAnyDefineOwn() const
Definition ic.h:61
bool UpdateMegaDOMIC(const MaybeObjectDirectHandle &handler, DirectHandle< Name > name)
Definition ic.cc:561
void UpdateMonomorphicIC(const MaybeObjectDirectHandle &handler, DirectHandle< Name > name)
Definition ic.cc:706
IC(Isolate *isolate, Handle< FeedbackVector > vector, FeedbackSlot slot, FeedbackSlotKind kind)
Definition ic.cc:181
bool IsKeyedStoreIC() const
Definition ic.h:132
const FeedbackNexus * nexus() const
Definition ic.h:156
static void OnFeedbackChanged(Isolate *isolate, Tagged< FeedbackVector > vector, FeedbackSlot slot, const char *reason)
Definition ic.cc:312
void SetCache(DirectHandle< Name > name, Handle< Object > handler)
Definition ic.cc:737
bool IsGlobalIC() const
Definition ic.h:122
Handle< Object > LoadElementHandler(DirectHandle< Map > receiver_map, KeyedAccessLoadMode new_load_mode)
Definition ic.cc:1366
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > RuntimeLoad(DirectHandle< JSAny > object, DirectHandle< Object > key, bool *is_found=nullptr)
Definition ic.cc:1529
KeyedLoadIC(Isolate *isolate, Handle< FeedbackVector > vector, FeedbackSlot slot, FeedbackSlotKind kind)
Definition ic.h:229
void LoadElementPolymorphicHandlers(MapHandles *receiver_maps, MaybeObjectHandles *handlers, KeyedAccessLoadMode new_load_mode)
Definition ic.cc:1425
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Load(Handle< JSAny > object, Handle< Object > key)
Definition ic.cc:1563
KeyedAccessLoadMode GetKeyedAccessLoadModeFor(DirectHandle< Map > receiver_map) const
Definition ic.cc:1143
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > LoadName(Handle< JSAny > object, DirectHandle< Object > key, Handle< Name > name)
Definition ic.cc:1547
void UpdateLoadElement(DirectHandle< HeapObject > receiver, KeyedAccessLoadMode new_load_mode)
Definition ic.cc:1162
KeyedAccessStoreMode GetKeyedAccessStoreMode()
Definition ic.h:312
DirectHandle< Map > ComputeTransitionedMap(Handle< Map > map, TransitionMode transition_mode)
Handle< Object > StoreElementHandler(DirectHandle< Map > receiver_map, KeyedAccessStoreMode store_mode, MaybeDirectHandle< UnionOf< Smi, Cell > > prev_validity_cell=kNullMaybeHandle)
Definition ic.cc:2377
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Store(Handle< JSAny > object, Handle< Object > name, DirectHandle< Object > value)
Definition ic.cc:2554
void UpdateStoreElement(Handle< Map > receiver_map, KeyedAccessStoreMode store_mode, Handle< Map > new_receiver_map)
Definition ic.cc:2237
KeyedStoreIC(Isolate *isolate, Handle< FeedbackVector > vector, FeedbackSlot slot, FeedbackSlotKind kind)
Definition ic.h:316
void StoreElementPolymorphicHandlers(MapsAndHandlers *receiver_maps_and_handlers, KeyedAccessStoreMode store_mode)
Definition ic.cc:2453
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Load(Handle< Name > name, bool update_feedback=true)
Definition ic.cc:464
LoadGlobalIC(Isolate *isolate, Handle< FeedbackVector > vector, FeedbackSlot slot, FeedbackSlotKind kind)
Definition ic.h:219
static bool ShouldThrowReferenceError(FeedbackSlotKind kind)
Definition ic.h:192
void UpdateCaches(LookupIterator *lookup)
Definition ic.cc:778
MaybeObjectHandle ComputeHandler(LookupIterator *lookup)
Definition ic.cc:846
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Load(Handle< JSAny > object, Handle< Name > name, bool update_feedback=true, DirectHandle< JSAny > receiver=DirectHandle< JSAny >())
Definition ic.cc:386
friend class NamedLoadHandlerCompiler
Definition ic.h:214
bool ShouldThrowReferenceError() const
Definition ic.h:196
LoadIC(Isolate *isolate, Handle< FeedbackVector > vector, FeedbackSlot slot, FeedbackSlotKind kind)
Definition ic.h:186
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Store(Handle< Name > name, DirectHandle< Object > value)
Definition ic.cc:1695
StoreGlobalIC(Isolate *isolate, Handle< FeedbackVector > vector, FeedbackSlot slot, FeedbackSlotKind kind)
Definition ic.h:292
bool LookupForWrite(LookupIterator *it, DirectHandle< Object > value, StoreOrigin store_origin)
Definition ic.cc:1598
MaybeObjectHandle ComputeHandler(LookupIterator *lookup)
Definition ic.cc:1969
void UpdateCaches(LookupIterator *lookup, DirectHandle< Object > value, StoreOrigin store_origin)
Definition ic.cc:1943
StoreIC(Isolate *isolate, Handle< FeedbackVector > vector, FeedbackSlot slot, FeedbackSlotKind kind)
Definition ic.h:264
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Store(Handle< JSAny > object, Handle< Name > name, DirectHandle< Object > value, StoreOrigin store_origin=StoreOrigin::kNamed)
Definition ic.cc:1827
MaybeDirectHandle< Object > Store(DirectHandle< JSArray > array, Handle< Object > index, DirectHandle< Object > value)
Definition ic.cc:2708
StoreInArrayLiteralIC(Isolate *isolate, Handle< FeedbackVector > vector, FeedbackSlot slot)
Definition ic.h:346
TNode< Object > receiver
bool IsStoreGlobalICKind(FeedbackSlotKind kind)
bool IsKeyedHasICKind(FeedbackSlotKind kind)
constexpr NullMaybeHandleType kNullMaybeHandle
bool IsDefineNamedOwnICKind(FeedbackSlotKind kind)
bool IsSetNamedICKind(FeedbackSlotKind kind)
bool IsLoadICKind(FeedbackSlotKind kind)
NamedPropertyType
Definition ic.h:22
bool IsStoreInArrayLiteralICKind(FeedbackSlotKind kind)
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123
TransitionMode
Definition ic.h:304
bool IsKeyedLoadICKind(FeedbackSlotKind kind)
bool IsDefineKeyedOwnICKind(FeedbackSlotKind kind)
bool IsLoadGlobalICKind(FeedbackSlotKind kind)
KeyedStoreCheckMap
Definition ic.h:300
@ kDontCheckMap
Definition ic.h:300
@ kCheckMap
Definition ic.h:300
std::vector< MaybeObjectHandle > MaybeObjectHandles
bool IsKeyedStoreICKind(FeedbackSlotKind kind)
KeyedStoreIncrementLength
Definition ic.h:302
@ kDontIncrementLength
Definition ic.h:302
@ kIncrementLength
Definition ic.h:302
#define DCHECK(condition)
Definition logging.h:482
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671