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/base/logging.h" | 10 #include "src/base/logging.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 CALL_IC, | 25 CALL_IC, |
26 LOAD_IC, | 26 LOAD_IC, |
27 LOAD_GLOBAL_IC, | 27 LOAD_GLOBAL_IC, |
28 KEYED_LOAD_IC, | 28 KEYED_LOAD_IC, |
29 STORE_IC, | 29 STORE_IC, |
30 KEYED_STORE_IC, | 30 KEYED_STORE_IC, |
31 INTERPRETER_BINARYOP_IC, | 31 INTERPRETER_BINARYOP_IC, |
32 INTERPRETER_COMPARE_IC, | 32 INTERPRETER_COMPARE_IC, |
33 STORE_DATA_PROPERTY_IN_LITERAL_IC, | 33 STORE_DATA_PROPERTY_IN_LITERAL_IC, |
34 | |
35 // This kind of slot has an integer parameter associated with it. | |
36 CREATE_CLOSURE, | 34 CREATE_CLOSURE, |
37 // This is a general purpose slot that occupies one feedback vector element. | 35 // This is a general purpose slot that occupies one feedback vector element. |
38 GENERAL, | 36 GENERAL, |
39 | 37 |
40 KINDS_NUMBER // Last value indicating number of kinds. | 38 KINDS_NUMBER // Last value indicating number of kinds. |
41 }; | 39 }; |
42 | 40 |
43 std::ostream& operator<<(std::ostream& os, FeedbackVectorSlotKind kind); | 41 std::ostream& operator<<(std::ostream& os, FeedbackVectorSlotKind kind); |
44 | 42 |
45 | 43 |
46 template <typename Derived> | 44 template <typename Derived> |
47 class FeedbackVectorSpecBase { | 45 class FeedbackVectorSpecBase { |
48 public: | 46 public: |
49 inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind); | 47 inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind); |
50 | 48 |
51 FeedbackVectorSlot AddCallICSlot() { | 49 FeedbackVectorSlot AddCallICSlot() { |
52 return AddSlot(FeedbackVectorSlotKind::CALL_IC); | 50 return AddSlot(FeedbackVectorSlotKind::CALL_IC); |
53 } | 51 } |
54 | 52 |
55 FeedbackVectorSlot AddLoadICSlot() { | 53 FeedbackVectorSlot AddLoadICSlot() { |
56 return AddSlot(FeedbackVectorSlotKind::LOAD_IC); | 54 return AddSlot(FeedbackVectorSlotKind::LOAD_IC); |
57 } | 55 } |
58 | 56 |
59 FeedbackVectorSlot AddLoadGlobalICSlot() { | 57 FeedbackVectorSlot AddLoadGlobalICSlot() { |
60 return AddSlot(FeedbackVectorSlotKind::LOAD_GLOBAL_IC); | 58 return AddSlot(FeedbackVectorSlotKind::LOAD_GLOBAL_IC); |
61 } | 59 } |
62 | 60 |
63 FeedbackVectorSlot AddCreateClosureSlot(int size) { | 61 FeedbackVectorSlot AddCreateClosureSlot() { |
64 This()->append_parameter(size); | |
65 return AddSlot(FeedbackVectorSlotKind::CREATE_CLOSURE); | 62 return AddSlot(FeedbackVectorSlotKind::CREATE_CLOSURE); |
66 } | 63 } |
67 | 64 |
68 FeedbackVectorSlot AddKeyedLoadICSlot() { | 65 FeedbackVectorSlot AddKeyedLoadICSlot() { |
69 return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC); | 66 return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC); |
70 } | 67 } |
71 | 68 |
72 FeedbackVectorSlot AddStoreICSlot() { | 69 FeedbackVectorSlot AddStoreICSlot() { |
73 return AddSlot(FeedbackVectorSlotKind::STORE_IC); | 70 return AddSlot(FeedbackVectorSlotKind::STORE_IC); |
74 } | 71 } |
(...skipping 26 matching lines...) Expand all Loading... |
101 DECLARE_PRINTER(FeedbackVectorSpec) | 98 DECLARE_PRINTER(FeedbackVectorSpec) |
102 | 99 |
103 private: | 100 private: |
104 Derived* This() { return static_cast<Derived*>(this); } | 101 Derived* This() { return static_cast<Derived*>(this); } |
105 }; | 102 }; |
106 | 103 |
107 | 104 |
108 class StaticFeedbackVectorSpec | 105 class StaticFeedbackVectorSpec |
109 : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> { | 106 : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> { |
110 public: | 107 public: |
111 StaticFeedbackVectorSpec() : slot_count_(0), parameters_count_(0) {} | 108 StaticFeedbackVectorSpec() : slot_count_(0) {} |
112 | 109 |
113 int slots() const { return slot_count_; } | 110 int slots() const { return slot_count_; } |
114 | 111 |
115 FeedbackVectorSlotKind GetKind(int slot) const { | 112 FeedbackVectorSlotKind GetKind(int slot) const { |
116 DCHECK(slot >= 0 && slot < slot_count_); | 113 DCHECK(slot >= 0 && slot < slot_count_); |
117 return kinds_[slot]; | 114 return kinds_[slot]; |
118 } | 115 } |
119 | 116 |
120 int parameters_count() const { return parameters_count_; } | |
121 | |
122 int GetParameter(int index) const { | |
123 DCHECK(index >= 0 && index < parameters_count_); | |
124 return parameters_[index]; | |
125 } | |
126 | |
127 private: | 117 private: |
128 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; | 118 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; |
129 | 119 |
130 void append(FeedbackVectorSlotKind kind) { | 120 void append(FeedbackVectorSlotKind kind) { |
131 DCHECK(slot_count_ < kMaxLength); | 121 DCHECK(slot_count_ < kMaxLength); |
132 kinds_[slot_count_++] = kind; | 122 kinds_[slot_count_++] = kind; |
133 } | 123 } |
134 | 124 |
135 void append_parameter(int parameter) { | |
136 DCHECK(parameters_count_ < kMaxLength); | |
137 parameters_[parameters_count_++] = parameter; | |
138 } | |
139 | |
140 static const int kMaxLength = 12; | 125 static const int kMaxLength = 12; |
141 | 126 |
142 int slot_count_; | 127 int slot_count_; |
143 FeedbackVectorSlotKind kinds_[kMaxLength]; | 128 FeedbackVectorSlotKind kinds_[kMaxLength]; |
144 int parameters_count_; | |
145 int parameters_[kMaxLength]; | |
146 }; | 129 }; |
147 | 130 |
148 | 131 |
149 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { | 132 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { |
150 public: | 133 public: |
151 explicit FeedbackVectorSpec(Zone* zone) | 134 explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone) { |
152 : slot_kinds_(zone), parameters_(zone) { | |
153 slot_kinds_.reserve(16); | 135 slot_kinds_.reserve(16); |
154 parameters_.reserve(8); | |
155 } | 136 } |
156 | 137 |
157 int slots() const { return static_cast<int>(slot_kinds_.size()); } | 138 int slots() const { return static_cast<int>(slot_kinds_.size()); } |
158 | 139 |
159 FeedbackVectorSlotKind GetKind(int slot) const { | 140 FeedbackVectorSlotKind GetKind(int slot) const { |
160 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); | 141 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); |
161 } | 142 } |
162 | 143 |
163 int parameters_count() const { return static_cast<int>(parameters_.size()); } | |
164 | |
165 int GetParameter(int index) const { return parameters_.at(index); } | |
166 | |
167 private: | 144 private: |
168 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; | 145 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; |
169 | 146 |
170 void append(FeedbackVectorSlotKind kind) { | 147 void append(FeedbackVectorSlotKind kind) { |
171 slot_kinds_.push_back(static_cast<unsigned char>(kind)); | 148 slot_kinds_.push_back(static_cast<unsigned char>(kind)); |
172 } | 149 } |
173 | 150 |
174 void append_parameter(int parameter) { parameters_.push_back(parameter); } | |
175 | |
176 ZoneVector<unsigned char> slot_kinds_; | 151 ZoneVector<unsigned char> slot_kinds_; |
177 ZoneVector<int> parameters_; | |
178 }; | 152 }; |
179 | 153 |
180 | 154 |
181 // The shape of the TypeFeedbackMetadata is an array with: | 155 // The shape of the TypeFeedbackMetadata is an array with: |
182 // 0: slot_count | 156 // 0: slot_count |
183 // 1: names table | 157 // 1: names table |
184 // 2: parameters table | 158 // 2: parameters table |
185 // 3..N: slot kinds packed into a bit vector | 159 // 3..N: slot kinds packed into a bit vector |
186 // | 160 // |
187 class TypeFeedbackMetadata : public FixedArray { | 161 class TypeFeedbackMetadata : public FixedArray { |
188 public: | 162 public: |
189 // Casting. | 163 // Casting. |
190 static inline TypeFeedbackMetadata* cast(Object* obj); | 164 static inline TypeFeedbackMetadata* cast(Object* obj); |
191 | 165 |
192 static const int kSlotsCountIndex = 0; | 166 static const int kSlotsCountIndex = 0; |
193 static const int kParametersTableIndex = 1; | 167 static const int kReservedIndexCount = 1; |
194 static const int kReservedIndexCount = 2; | |
195 | 168 |
196 // Returns number of feedback vector elements used by given slot kind. | 169 // Returns number of feedback vector elements used by given slot kind. |
197 static inline int GetSlotSize(FeedbackVectorSlotKind kind); | 170 static inline int GetSlotSize(FeedbackVectorSlotKind kind); |
198 | 171 |
199 // Defines if slots of given kind require "parameter". | |
200 static inline bool SlotRequiresParameter(FeedbackVectorSlotKind kind); | |
201 | |
202 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; | 172 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; |
203 | 173 |
204 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const; | 174 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const; |
205 | 175 |
206 inline bool is_empty() const; | 176 inline bool is_empty() const; |
207 | 177 |
208 // Returns number of slots in the vector. | 178 // Returns number of slots in the vector. |
209 inline int slot_count() const; | 179 inline int slot_count() const; |
210 | 180 |
211 // Returns slot kind for given slot. | 181 // Returns slot kind for given slot. |
212 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; | 182 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; |
213 | 183 |
214 // Returns parameter for given index (note: this is not the slot) | |
215 int GetParameter(int parameter_index) const; | |
216 | |
217 template <typename Spec> | 184 template <typename Spec> |
218 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); | 185 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); |
219 | 186 |
220 #ifdef OBJECT_PRINT | 187 #ifdef OBJECT_PRINT |
221 // For gdb debugging. | 188 // For gdb debugging. |
222 void Print(); | 189 void Print(); |
223 #endif // OBJECT_PRINT | 190 #endif // OBJECT_PRINT |
224 | 191 |
225 DECLARE_PRINTER(TypeFeedbackMetadata) | 192 DECLARE_PRINTER(TypeFeedbackMetadata) |
226 | 193 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 FeedbackVectorSlot slot); | 242 FeedbackVectorSlot slot); |
276 | 243 |
277 // Conversion from an integer index to the underlying array to a slot. | 244 // Conversion from an integer index to the underlying array to a slot. |
278 static inline FeedbackVectorSlot ToSlot(int index); | 245 static inline FeedbackVectorSlot ToSlot(int index); |
279 inline Object* Get(FeedbackVectorSlot slot) const; | 246 inline Object* Get(FeedbackVectorSlot slot) const; |
280 inline void Set(FeedbackVectorSlot slot, Object* value, | 247 inline void Set(FeedbackVectorSlot slot, Object* value, |
281 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 248 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
282 | 249 |
283 // Returns slot kind for given slot. | 250 // Returns slot kind for given slot. |
284 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; | 251 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; |
285 // Returns parameter corresponding to given slot or -1. | |
286 int GetParameter(FeedbackVectorSlot slot) const; | |
287 | 252 |
288 static Handle<TypeFeedbackVector> New(Isolate* isolate, | 253 static Handle<TypeFeedbackVector> New(Isolate* isolate, |
289 Handle<TypeFeedbackMetadata> metadata); | 254 Handle<TypeFeedbackMetadata> metadata); |
290 | 255 |
291 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, | 256 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, |
292 Handle<TypeFeedbackVector> vector); | 257 Handle<TypeFeedbackVector> vector); |
293 | 258 |
294 #ifdef OBJECT_PRINT | 259 #ifdef OBJECT_PRINT |
295 // For gdb debugging. | 260 // For gdb debugging. |
296 void Print(); | 261 void Print(); |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 InlineCacheState StateFromFeedback() const override; | 699 InlineCacheState StateFromFeedback() const override; |
735 }; | 700 }; |
736 | 701 |
737 inline BinaryOperationHint BinaryOperationHintFromFeedback(int type_feedback); | 702 inline BinaryOperationHint BinaryOperationHintFromFeedback(int type_feedback); |
738 inline CompareOperationHint CompareOperationHintFromFeedback(int type_feedback); | 703 inline CompareOperationHint CompareOperationHintFromFeedback(int type_feedback); |
739 | 704 |
740 } // namespace internal | 705 } // namespace internal |
741 } // namespace v8 | 706 } // namespace v8 |
742 | 707 |
743 #endif // V8_TRANSITIONS_H_ | 708 #endif // V8_TRANSITIONS_H_ |
OLD | NEW |