OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_TYPE_FEEDBACK_VECTOR_H_ | 5 #ifndef V8_TYPE_FEEDBACK_VECTOR_H_ |
6 #define V8_TYPE_FEEDBACK_VECTOR_H_ | 6 #define V8_TYPE_FEEDBACK_VECTOR_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "src/checks.h" | 10 #include "src/checks.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 static TypeFeedbackVector* cast(Object* obj) { | 67 static TypeFeedbackVector* cast(Object* obj) { |
68 DCHECK(obj->IsTypeFeedbackVector()); | 68 DCHECK(obj->IsTypeFeedbackVector()); |
69 return reinterpret_cast<TypeFeedbackVector*>(obj); | 69 return reinterpret_cast<TypeFeedbackVector*>(obj); |
70 } | 70 } |
71 | 71 |
72 static const int kReservedIndexCount = 3; | 72 static const int kReservedIndexCount = 3; |
73 static const int kFirstICSlotIndex = 0; | 73 static const int kFirstICSlotIndex = 0; |
74 static const int kWithTypesIndex = 1; | 74 static const int kWithTypesIndex = 1; |
75 static const int kGenericCountIndex = 2; | 75 static const int kGenericCountIndex = 2; |
76 | 76 |
77 static int elements_per_ic_slot() { return FLAG_vector_ics ? 2 : 1; } | |
78 | |
77 int first_ic_slot_index() const { | 79 int first_ic_slot_index() const { |
78 DCHECK(length() >= kReservedIndexCount); | 80 DCHECK(length() >= kReservedIndexCount); |
79 return Smi::cast(get(kFirstICSlotIndex))->value(); | 81 return Smi::cast(get(kFirstICSlotIndex))->value(); |
80 } | 82 } |
81 | 83 |
82 int ic_with_type_info_count() { | 84 int ic_with_type_info_count() { |
83 return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0; | 85 return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0; |
84 } | 86 } |
85 | 87 |
86 void change_ic_with_type_info_count(int delta) { | 88 void change_ic_with_type_info_count(int delta) { |
(...skipping 20 matching lines...) Expand all Loading... | |
107 inline int ic_metadata_length() const; | 109 inline int ic_metadata_length() const; |
108 | 110 |
109 int Slots() const { | 111 int Slots() const { |
110 if (length() == 0) return 0; | 112 if (length() == 0) return 0; |
111 return Max( | 113 return Max( |
112 0, first_ic_slot_index() - ic_metadata_length() - kReservedIndexCount); | 114 0, first_ic_slot_index() - ic_metadata_length() - kReservedIndexCount); |
113 } | 115 } |
114 | 116 |
115 int ICSlots() const { | 117 int ICSlots() const { |
116 if (length() == 0) return 0; | 118 if (length() == 0) return 0; |
117 return length() - first_ic_slot_index(); | 119 return (length() - first_ic_slot_index()) / elements_per_ic_slot(); |
118 } | 120 } |
119 | 121 |
120 // Conversion from a slot or ic slot to an integer index to the underlying | 122 // Conversion from a slot or ic slot to an integer index to the underlying |
121 // array. | 123 // array. |
122 int GetIndex(FeedbackVectorSlot slot) const { | 124 int GetIndex(FeedbackVectorSlot slot) const { |
123 DCHECK(slot.ToInt() < first_ic_slot_index()); | 125 DCHECK(slot.ToInt() < first_ic_slot_index()); |
124 return kReservedIndexCount + ic_metadata_length() + slot.ToInt(); | 126 return kReservedIndexCount + ic_metadata_length() + slot.ToInt(); |
125 } | 127 } |
126 | 128 |
127 int GetIndex(FeedbackVectorICSlot slot) const { | 129 int GetIndex(FeedbackVectorICSlot slot) const { |
128 int first_ic_slot = first_ic_slot_index(); | 130 int first_ic_slot = first_ic_slot_index(); |
129 DCHECK(slot.ToInt() < ICSlots()); | 131 DCHECK(slot.ToInt() < ICSlots()); |
130 return first_ic_slot + slot.ToInt(); | 132 return first_ic_slot + slot.ToInt() * elements_per_ic_slot(); |
131 } | 133 } |
132 | 134 |
133 // Conversion from an integer index to either a slot or an ic slot. The caller | 135 // Conversion from an integer index to either a slot or an ic slot. The caller |
134 // should know what kind she expects. | 136 // should know what kind she expects. |
135 FeedbackVectorSlot ToSlot(int index) const { | 137 FeedbackVectorSlot ToSlot(int index) const { |
136 DCHECK(index >= kReservedIndexCount && index < first_ic_slot_index()); | 138 DCHECK(index >= kReservedIndexCount && index < first_ic_slot_index()); |
137 return FeedbackVectorSlot(index - ic_metadata_length() - | 139 return FeedbackVectorSlot(index - ic_metadata_length() - |
138 kReservedIndexCount); | 140 kReservedIndexCount); |
139 } | 141 } |
140 | 142 |
141 FeedbackVectorICSlot ToICSlot(int index) const { | 143 FeedbackVectorICSlot ToICSlot(int index) const { |
142 DCHECK(index >= first_ic_slot_index() && index < length()); | 144 DCHECK(index >= first_ic_slot_index() && index < length()); |
143 return FeedbackVectorICSlot(index - first_ic_slot_index()); | 145 int ic_slot = (index - first_ic_slot_index()) / elements_per_ic_slot(); |
146 return FeedbackVectorICSlot(ic_slot); | |
144 } | 147 } |
145 | 148 |
146 Object* Get(FeedbackVectorSlot slot) const { return get(GetIndex(slot)); } | 149 Object* Get(FeedbackVectorSlot slot) const { return get(GetIndex(slot)); } |
147 void Set(FeedbackVectorSlot slot, Object* value, | 150 void Set(FeedbackVectorSlot slot, Object* value, |
148 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) { | 151 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) { |
149 set(GetIndex(slot), value, mode); | 152 set(GetIndex(slot), value, mode); |
150 } | 153 } |
151 | 154 |
152 Object* Get(FeedbackVectorICSlot slot) const { return get(GetIndex(slot)); } | 155 Object* Get(FeedbackVectorICSlot slot) const { return get(GetIndex(slot)); } |
153 void Set(FeedbackVectorICSlot slot, Object* value, | 156 void Set(FeedbackVectorICSlot slot, Object* value, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 | 248 |
246 virtual InlineCacheState StateFromFeedback() const = 0; | 249 virtual InlineCacheState StateFromFeedback() const = 0; |
247 virtual int ExtractMaps(MapHandleList* maps) const = 0; | 250 virtual int ExtractMaps(MapHandleList* maps) const = 0; |
248 virtual MaybeHandle<Code> FindHandlerForMap(Handle<Map> map) const = 0; | 251 virtual MaybeHandle<Code> FindHandlerForMap(Handle<Map> map) const = 0; |
249 virtual bool FindHandlers(CodeHandleList* code_list, int length = -1) const { | 252 virtual bool FindHandlers(CodeHandleList* code_list, int length = -1) const { |
250 return length == 0; | 253 return length == 0; |
251 } | 254 } |
252 virtual Name* FindFirstName() const { return NULL; } | 255 virtual Name* FindFirstName() const { return NULL; } |
253 | 256 |
254 Object* GetFeedback() const { return vector()->Get(slot()); } | 257 Object* GetFeedback() const { return vector()->Get(slot()); } |
258 Object* GetFeedbackExtra() const { | |
259 DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1); | |
260 int extra_index = vector()->GetIndex(slot()) + 1; | |
261 return vector()->get(extra_index); | |
262 } | |
255 | 263 |
256 protected: | 264 protected: |
257 Isolate* GetIsolate() const { return vector()->GetIsolate(); } | 265 Isolate* GetIsolate() const { return vector()->GetIsolate(); } |
258 | 266 |
259 void SetFeedback(Object* feedback, | 267 void SetFeedback(Object* feedback, |
260 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) { | 268 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) { |
261 vector()->Set(slot(), feedback, mode); | 269 vector()->Set(slot(), feedback, mode); |
262 } | 270 } |
263 | 271 |
272 void SetFeedbackExtra(Object* feedback_extra, | |
273 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) { | |
274 DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1); | |
275 int index = vector()->GetIndex(slot()) + 1; | |
276 vector()->set(index, feedback_extra, mode); | |
277 } | |
278 | |
264 Handle<FixedArray> EnsureArrayOfSize(int length); | 279 Handle<FixedArray> EnsureArrayOfSize(int length); |
265 void InstallHandlers(int start_index, MapHandleList* maps, | 280 Handle<FixedArray> EnsureExtraArrayOfSize(int length); |
281 void InstallHandlers(Handle<FixedArray> array, MapHandleList* maps, | |
266 CodeHandleList* handlers); | 282 CodeHandleList* handlers); |
267 int ExtractMaps(int start_index, MapHandleList* maps) const; | 283 |
268 MaybeHandle<Code> FindHandlerForMap(int start_index, Handle<Map> map) const; | 284 int ExtractMapsImpl(MapHandleList* maps) const; |
Toon Verwaest
2015/03/11 17:55:02
Impl?
mvstanton
2015/03/12 17:05:34
I'll reorganize this, providing a base implementat
| |
269 bool FindHandlers(int start_index, CodeHandleList* code_list, | 285 MaybeHandle<Code> FindHandlerForMapImpl(Handle<Map> map) const; |
270 int length) const; | 286 bool FindHandlersImpl(CodeHandleList* code_list, int length) const; |
271 | 287 |
272 private: | 288 private: |
273 // The reason for having a vector handle and a raw pointer is that we can and | 289 // The reason for having a vector handle and a raw pointer is that we can and |
274 // should use handles during IC miss, but not during GC when we clear ICs. If | 290 // should use handles during IC miss, but not during GC when we clear ICs. If |
275 // you have a handle to the vector that is better because more operations can | 291 // you have a handle to the vector that is better because more operations can |
276 // be done, like allocation. | 292 // be done, like allocation. |
277 Handle<TypeFeedbackVector> vector_handle_; | 293 Handle<TypeFeedbackVector> vector_handle_; |
278 TypeFeedbackVector* vector_; | 294 TypeFeedbackVector* vector_; |
279 FeedbackVectorICSlot slot_; | 295 FeedbackVectorICSlot slot_; |
280 }; | 296 }; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 int ExtractMaps(MapHandleList* maps) const OVERRIDE; | 383 int ExtractMaps(MapHandleList* maps) const OVERRIDE; |
368 MaybeHandle<Code> FindHandlerForMap(Handle<Map> map) const OVERRIDE; | 384 MaybeHandle<Code> FindHandlerForMap(Handle<Map> map) const OVERRIDE; |
369 virtual bool FindHandlers(CodeHandleList* code_list, | 385 virtual bool FindHandlers(CodeHandleList* code_list, |
370 int length = -1) const OVERRIDE; | 386 int length = -1) const OVERRIDE; |
371 Name* FindFirstName() const OVERRIDE; | 387 Name* FindFirstName() const OVERRIDE; |
372 }; | 388 }; |
373 } | 389 } |
374 } // namespace v8::internal | 390 } // namespace v8::internal |
375 | 391 |
376 #endif // V8_TRANSITIONS_H_ | 392 #endif // V8_TRANSITIONS_H_ |
OLD | NEW |