Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Side by Side Diff: src/ic/ic.h

Issue 683933002: Introduce FeedbackNexus for vector-based ics. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ic/ic.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_IC_H_ 5 #ifndef V8_IC_H_
6 #define V8_IC_H_ 6 #define V8_IC_H_
7 7
8 #include "src/ic/ic-state.h" 8 #include "src/ic/ic-state.h"
9 #include "src/macro-assembler.h" 9 #include "src/macro-assembler.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 // Alias the inline cache state type to make the IC code more readable. 53 // Alias the inline cache state type to make the IC code more readable.
54 typedef InlineCacheState State; 54 typedef InlineCacheState State;
55 55
56 // The IC code is either invoked with no extra frames on the stack 56 // The IC code is either invoked with no extra frames on the stack
57 // or with a single extra frame for supporting calls. 57 // or with a single extra frame for supporting calls.
58 enum FrameDepth { NO_EXTRA_FRAME = 0, EXTRA_CALL_FRAME = 1 }; 58 enum FrameDepth { NO_EXTRA_FRAME = 0, EXTRA_CALL_FRAME = 1 };
59 59
60 // Construct the IC structure with the given number of extra 60 // Construct the IC structure with the given number of extra
61 // JavaScript frames on the stack. 61 // JavaScript frames on the stack.
62 IC(FrameDepth depth, Isolate* isolate); 62 IC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL,
63 bool for_queries_only = false);
63 virtual ~IC() {} 64 virtual ~IC() {}
64 65
65 State state() const { return state_; } 66 State state() const { return state_; }
66 inline Address address() const; 67 inline Address address() const;
67 68
68 // Compute the current IC state based on the target stub, receiver and name. 69 // Compute the current IC state based on the target stub, receiver and name.
69 void UpdateState(Handle<Object> receiver, Handle<Object> name); 70 void UpdateState(Handle<Object> receiver, Handle<Object> name);
70 71
71 bool IsNameCompatibleWithPrototypeFailure(Handle<Object> name); 72 bool IsNameCompatibleWithPrototypeFailure(Handle<Object> name);
72 void MarkPrototypeFailure(Handle<Object> name) { 73 void MarkPrototypeFailure(Handle<Object> name) {
73 DCHECK(IsNameCompatibleWithPrototypeFailure(name)); 74 DCHECK(IsNameCompatibleWithPrototypeFailure(name));
75 old_state_ = state_;
74 state_ = PROTOTYPE_FAILURE; 76 state_ = PROTOTYPE_FAILURE;
75 } 77 }
76 78
77 // If the stub contains weak maps then this function adds the stub to 79 // If the stub contains weak maps then this function adds the stub to
78 // the dependent code array of each weak map. 80 // the dependent code array of each weak map.
79 static void RegisterWeakMapDependency(Handle<Code> stub); 81 static void RegisterWeakMapDependency(Handle<Code> stub);
80 82
81 // This function is called when a weak map in the stub is dying, 83 // This function is called when a weak map in the stub is dying,
82 // invalidates the stub by setting maps in it to undefined. 84 // invalidates the stub by setting maps in it to undefined.
83 static void InvalidateMaps(Code* stub); 85 static void InvalidateMaps(Code* stub);
84 86
85 // Clear the inline cache to initial state. 87 // Clear the inline cache to initial state.
86 static void Clear(Isolate* isolate, Address address, 88 static void Clear(Isolate* isolate, Address address,
87 ConstantPoolArray* constant_pool); 89 ConstantPoolArray* constant_pool);
88 90
89 // Clear the vector-based inline cache to initial state. 91 // Clear the vector-based inline cache to initial state.
92 template <class Nexus>
90 static void Clear(Isolate* isolate, Code::Kind kind, Code* host, 93 static void Clear(Isolate* isolate, Code::Kind kind, Code* host,
91 TypeFeedbackVector* vector, FeedbackVectorICSlot slot); 94 Nexus* nexus);
92 95
93 #ifdef DEBUG 96 #ifdef DEBUG
94 bool IsLoadStub() const { 97 bool IsLoadStub() const {
95 return target()->is_load_stub() || target()->is_keyed_load_stub(); 98 return target()->is_load_stub() || target()->is_keyed_load_stub();
96 } 99 }
97 100
98 bool IsStoreStub() const { 101 bool IsStoreStub() const {
99 return target()->is_store_stub() || target()->is_keyed_store_stub(); 102 return target()->is_store_stub() || target()->is_keyed_store_stub();
100 } 103 }
101 104
102 bool IsCallStub() const { return target()->is_call_stub(); } 105 bool IsCallStub() const { return target()->is_call_stub(); }
103 #endif 106 #endif
104 107
105 template <class TypeClass> 108 template <class TypeClass>
106 static JSFunction* GetRootConstructor(TypeClass* type, 109 static JSFunction* GetRootConstructor(TypeClass* type,
107 Context* native_context); 110 Context* native_context);
108 static inline Handle<Map> GetHandlerCacheHolder(HeapType* type, 111 static inline Handle<Map> GetHandlerCacheHolder(HeapType* type,
109 bool receiver_is_holder, 112 bool receiver_is_holder,
110 Isolate* isolate, 113 Isolate* isolate,
111 CacheHolderFlag* flag); 114 CacheHolderFlag* flag);
112 static inline Handle<Map> GetICCacheHolder(HeapType* type, Isolate* isolate, 115 static inline Handle<Map> GetICCacheHolder(HeapType* type, Isolate* isolate,
113 CacheHolderFlag* flag); 116 CacheHolderFlag* flag);
114 117
115 static bool IsCleared(Code* code) { 118 static bool IsCleared(Code* code) {
116 InlineCacheState state = code->ic_state(); 119 InlineCacheState state = code->ic_state();
117 return state == UNINITIALIZED || state == PREMONOMORPHIC; 120 return state == UNINITIALIZED || state == PREMONOMORPHIC;
118 } 121 }
119 122
123 static bool IsCleared(FeedbackNexus* nexus) {
124 InlineCacheState state = nexus->StateFromFeedback();
125 return state == UNINITIALIZED || state == PREMONOMORPHIC;
126 }
127
120 // Utility functions to convert maps to types and back. There are two special 128 // Utility functions to convert maps to types and back. There are two special
121 // cases: 129 // cases:
122 // - The heap_number_map is used as a marker which includes heap numbers as 130 // - The heap_number_map is used as a marker which includes heap numbers as
123 // well as smis. 131 // well as smis.
124 // - The oddball map is only used for booleans. 132 // - The oddball map is only used for booleans.
125 static Handle<Map> TypeToMap(HeapType* type, Isolate* isolate); 133 static Handle<Map> TypeToMap(HeapType* type, Isolate* isolate);
126 template <class T> 134 template <class T>
127 static typename T::TypeHandle MapToType(Handle<Map> map, 135 static typename T::TypeHandle MapToType(Handle<Map> map,
128 typename T::Region* region); 136 typename T::Region* region);
129 137
(...skipping 12 matching lines...) Expand all
142 SharedFunctionInfo* GetSharedFunctionInfo() const; 150 SharedFunctionInfo* GetSharedFunctionInfo() const;
143 // Get the code object of the caller. 151 // Get the code object of the caller.
144 Code* GetCode() const; 152 Code* GetCode() const;
145 // Get the original (non-breakpointed) code object of the caller. 153 // Get the original (non-breakpointed) code object of the caller.
146 Code* GetOriginalCode() const; 154 Code* GetOriginalCode() const;
147 155
148 // Set the call-site target. 156 // Set the call-site target.
149 inline void set_target(Code* code); 157 inline void set_target(Code* code);
150 bool is_target_set() { return target_set_; } 158 bool is_target_set() { return target_set_; }
151 159
160 bool UseVector() const {
161 bool use = (FLAG_vector_ics &&
162 (kind() == Code::LOAD_IC || kind() == Code::KEYED_LOAD_IC)) ||
163 kind() == Code::CALL_IC;
164 // If we are supposed to use the nexus, verify the nexus is non-null.
165 DCHECK(!use || nexus_ != NULL);
166 return use;
167 }
168
152 char TransitionMarkFromState(IC::State state); 169 char TransitionMarkFromState(IC::State state);
153 void TraceIC(const char* type, Handle<Object> name); 170 void TraceIC(const char* type, Handle<Object> name);
154 void TraceIC(const char* type, Handle<Object> name, State old_state, 171 void TraceIC(const char* type, Handle<Object> name, State old_state,
155 State new_state); 172 State new_state);
156 173
157 MaybeHandle<Object> TypeError(const char* type, Handle<Object> object, 174 MaybeHandle<Object> TypeError(const char* type, Handle<Object> object,
158 Handle<Object> key); 175 Handle<Object> key);
159 MaybeHandle<Object> ReferenceError(const char* type, Handle<Name> name); 176 MaybeHandle<Object> ReferenceError(const char* type, Handle<Name> name);
160 177
161 // Access the target code for the given IC address. 178 // Access the target code for the given IC address.
162 static inline Code* GetTargetAtAddress(Address address, 179 static inline Code* GetTargetAtAddress(Address address,
163 ConstantPoolArray* constant_pool); 180 ConstantPoolArray* constant_pool);
164 static inline void SetTargetAtAddress(Address address, Code* target, 181 static inline void SetTargetAtAddress(Address address, Code* target,
165 ConstantPoolArray* constant_pool); 182 ConstantPoolArray* constant_pool);
166 static void OnTypeFeedbackChanged(Isolate* isolate, Address address, 183 static void OnTypeFeedbackChanged(Isolate* isolate, Address address,
167 State old_state, State new_state, 184 State old_state, State new_state,
168 bool target_remains_ic_stub); 185 bool target_remains_ic_stub);
186 // As a vector-based IC, type feedback must be updated differently.
187 static void OnTypeFeedbackChanged(Isolate* isolate, Code* host,
188 TypeFeedbackVector* vector, State old_state,
189 State new_state);
169 static void PostPatching(Address address, Code* target, Code* old_target); 190 static void PostPatching(Address address, Code* target, Code* old_target);
170 191
171 // Compute the handler either by compiling or by retrieving a cached version. 192 // Compute the handler either by compiling or by retrieving a cached version.
172 Handle<Code> ComputeHandler(LookupIterator* lookup, 193 Handle<Code> ComputeHandler(LookupIterator* lookup,
173 Handle<Object> value = Handle<Code>::null()); 194 Handle<Object> value = Handle<Code>::null());
174 virtual Handle<Code> CompileHandler(LookupIterator* lookup, 195 virtual Handle<Code> CompileHandler(LookupIterator* lookup,
175 Handle<Object> value, 196 Handle<Object> value,
176 CacheHolderFlag cache_holder) { 197 CacheHolderFlag cache_holder) {
177 UNREACHABLE(); 198 UNREACHABLE();
178 return Handle<Code>::null(); 199 return Handle<Code>::null();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 243 }
223 } 244 }
224 245
225 Map* FirstTargetMap() { 246 Map* FirstTargetMap() {
226 FindTargetMaps(); 247 FindTargetMaps();
227 return target_maps_.length() > 0 ? *target_maps_.at(0) : NULL; 248 return target_maps_.length() > 0 ? *target_maps_.at(0) : NULL;
228 } 249 }
229 250
230 inline void UpdateTarget(); 251 inline void UpdateTarget();
231 252
253 Handle<TypeFeedbackVector> vector() const { return nexus()->vector_handle(); }
254 FeedbackVectorICSlot slot() const { return nexus()->slot(); }
255 State saved_state() const {
256 return state() == PROTOTYPE_FAILURE ? old_state_ : state();
257 }
258
259 template <class NexusClass>
260 NexusClass* casted_nexus() {
261 return static_cast<NexusClass*>(nexus_);
262 }
263 FeedbackNexus* nexus() const { return nexus_; }
264
265 inline Code* get_host();
266
232 private: 267 private:
233 inline Code* raw_target() const; 268 inline Code* raw_target() const;
234 inline ConstantPoolArray* constant_pool() const; 269 inline ConstantPoolArray* constant_pool() const;
235 inline ConstantPoolArray* raw_constant_pool() const; 270 inline ConstantPoolArray* raw_constant_pool() const;
236 271
237 void FindTargetMaps() { 272 void FindTargetMaps() {
238 if (target_maps_set_) return; 273 if (target_maps_set_) return;
239 target_maps_set_ = true; 274 target_maps_set_ = true;
240 if (state_ == MONOMORPHIC) { 275 if (state_ == MONOMORPHIC) {
241 Map* map = target_->FindFirstMap(); 276 Map* map = target_->FindFirstMap();
(...skipping 14 matching lines...) Expand all
256 291
257 Isolate* isolate_; 292 Isolate* isolate_;
258 293
259 // The constant pool of the code which originally called the IC (which might 294 // The constant pool of the code which originally called the IC (which might
260 // be for the breakpointed copy of the original code). 295 // be for the breakpointed copy of the original code).
261 Handle<ConstantPoolArray> raw_constant_pool_; 296 Handle<ConstantPoolArray> raw_constant_pool_;
262 297
263 // The original code target that missed. 298 // The original code target that missed.
264 Handle<Code> target_; 299 Handle<Code> target_;
265 bool target_set_; 300 bool target_set_;
301 State old_state_; // For saving if we marked as prototype failure.
266 State state_; 302 State state_;
267 Code::Kind kind_; 303 Code::Kind kind_;
268 Handle<HeapType> receiver_type_; 304 Handle<HeapType> receiver_type_;
269 MaybeHandle<Code> maybe_handler_; 305 MaybeHandle<Code> maybe_handler_;
270 306
271 ExtraICState extra_ic_state_; 307 ExtraICState extra_ic_state_;
272 MapHandleList target_maps_; 308 MapHandleList target_maps_;
273 bool target_maps_set_; 309 bool target_maps_set_;
274 310
311 FeedbackNexus* nexus_;
312
275 DISALLOW_IMPLICIT_CONSTRUCTORS(IC); 313 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
276 }; 314 };
277 315
278 316
279 // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you 317 // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you
280 // cannot make forward declarations to an enum. 318 // cannot make forward declarations to an enum.
281 class IC_Utility { 319 class IC_Utility {
282 public: 320 public:
283 explicit IC_Utility(IC::UtilityId id) 321 explicit IC_Utility(IC::UtilityId id)
284 : address_(IC::AddressFromUtilityId(id)), id_(id) {} 322 : address_(IC::AddressFromUtilityId(id)), id_(id) {}
285 323
286 Address address() const { return address_; } 324 Address address() const { return address_; }
287 325
288 IC::UtilityId id() const { return id_; } 326 IC::UtilityId id() const { return id_; }
289 327
290 private: 328 private:
291 Address address_; 329 Address address_;
292 IC::UtilityId id_; 330 IC::UtilityId id_;
293 }; 331 };
294 332
295 333
296 class CallIC : public IC { 334 class CallIC : public IC {
297 public: 335 public:
298 explicit CallIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {} 336 CallIC(Isolate* isolate, CallICNexus* nexus)
337 : IC(EXTRA_CALL_FRAME, isolate, nexus) {
338 DCHECK(nexus != NULL);
339 }
299 340
300 void PatchMegamorphic(Handle<Object> function, 341 void PatchMegamorphic(Handle<Object> function);
301 Handle<TypeFeedbackVector> vector,
302 FeedbackVectorICSlot slot);
303 342
304 void HandleMiss(Handle<Object> receiver, Handle<Object> function, 343 void HandleMiss(Handle<Object> receiver, Handle<Object> function);
305 Handle<TypeFeedbackVector> vector, FeedbackVectorICSlot slot);
306 344
307 // Returns true if a custom handler was installed. 345 // Returns true if a custom handler was installed.
308 bool DoCustomHandler(Handle<Object> receiver, Handle<Object> function, 346 bool DoCustomHandler(Handle<Object> receiver, Handle<Object> function,
309 Handle<TypeFeedbackVector> vector, 347 const CallICState& callic_state);
310 FeedbackVectorICSlot slot, const CallICState& state);
311 348
312 // Code generator routines. 349 // Code generator routines.
313 static Handle<Code> initialize_stub(Isolate* isolate, int argc, 350 static Handle<Code> initialize_stub(Isolate* isolate, int argc,
314 CallICState::CallType call_type); 351 CallICState::CallType call_type);
315 352
316 static void Clear(Isolate* isolate, Code* host, TypeFeedbackVector* vector, 353 static void Clear(Isolate* isolate, Code* host, CallICNexus* nexus);
317 FeedbackVectorICSlot slot);
318
319 private:
320 static inline IC::State FeedbackToState(Isolate* isolate,
321 TypeFeedbackVector* vector,
322 FeedbackVectorICSlot slot);
323
324 inline Code* get_host();
325
326 // As a vector-based IC, type feedback must be updated differently.
327 static void OnTypeFeedbackChanged(Isolate* isolate, Code* host,
328 TypeFeedbackVector* vector, State old_state,
329 State new_state);
330 }; 354 };
331 355
332 356
333 class LoadIC : public IC { 357 class LoadIC : public IC {
334 public: 358 public:
335 static ExtraICState ComputeExtraICState(ContextualMode contextual_mode) { 359 static ExtraICState ComputeExtraICState(ContextualMode contextual_mode) {
336 return LoadICState(contextual_mode).GetExtraICState(); 360 return LoadICState(contextual_mode).GetExtraICState();
337 } 361 }
338 362
339 ContextualMode contextual_mode() const { 363 ContextualMode contextual_mode() const {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 732
709 // Support functions for interceptor handlers. 733 // Support functions for interceptor handlers.
710 DECLARE_RUNTIME_FUNCTION(LoadPropertyWithInterceptorOnly); 734 DECLARE_RUNTIME_FUNCTION(LoadPropertyWithInterceptorOnly);
711 DECLARE_RUNTIME_FUNCTION(LoadPropertyWithInterceptor); 735 DECLARE_RUNTIME_FUNCTION(LoadPropertyWithInterceptor);
712 DECLARE_RUNTIME_FUNCTION(LoadElementWithInterceptor); 736 DECLARE_RUNTIME_FUNCTION(LoadElementWithInterceptor);
713 DECLARE_RUNTIME_FUNCTION(StorePropertyWithInterceptor); 737 DECLARE_RUNTIME_FUNCTION(StorePropertyWithInterceptor);
714 } 738 }
715 } // namespace v8::internal 739 } // namespace v8::internal
716 740
717 #endif // V8_IC_H_ 741 #endif // V8_IC_H_
OLDNEW
« no previous file with comments | « no previous file | src/ic/ic.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698