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

Side by Side Diff: src/type-feedback-vector.h

Issue 2515233002: [ic] Remove names table from type feedback metadata. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « src/objects-printer.cc ('k') | src/type-feedback-vector.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 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind); 46 inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind);
47 47
48 FeedbackVectorSlot AddCallICSlot() { 48 FeedbackVectorSlot AddCallICSlot() {
49 return AddSlot(FeedbackVectorSlotKind::CALL_IC); 49 return AddSlot(FeedbackVectorSlotKind::CALL_IC);
50 } 50 }
51 51
52 FeedbackVectorSlot AddLoadICSlot() { 52 FeedbackVectorSlot AddLoadICSlot() {
53 return AddSlot(FeedbackVectorSlotKind::LOAD_IC); 53 return AddSlot(FeedbackVectorSlotKind::LOAD_IC);
54 } 54 }
55 55
56 FeedbackVectorSlot AddLoadGlobalICSlot(Handle<String> name) { 56 FeedbackVectorSlot AddLoadGlobalICSlot() {
57 This()->append_name(name);
58 return AddSlot(FeedbackVectorSlotKind::LOAD_GLOBAL_IC); 57 return AddSlot(FeedbackVectorSlotKind::LOAD_GLOBAL_IC);
59 } 58 }
60 59
61 FeedbackVectorSlot AddKeyedLoadICSlot() { 60 FeedbackVectorSlot AddKeyedLoadICSlot() {
62 return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC); 61 return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC);
63 } 62 }
64 63
65 FeedbackVectorSlot AddStoreICSlot() { 64 FeedbackVectorSlot AddStoreICSlot() {
66 return AddSlot(FeedbackVectorSlotKind::STORE_IC); 65 return AddSlot(FeedbackVectorSlotKind::STORE_IC);
67 } 66 }
(...skipping 22 matching lines...) Expand all
90 DECLARE_PRINTER(FeedbackVectorSpec) 89 DECLARE_PRINTER(FeedbackVectorSpec)
91 90
92 private: 91 private:
93 Derived* This() { return static_cast<Derived*>(this); } 92 Derived* This() { return static_cast<Derived*>(this); }
94 }; 93 };
95 94
96 95
97 class StaticFeedbackVectorSpec 96 class StaticFeedbackVectorSpec
98 : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> { 97 : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> {
99 public: 98 public:
100 StaticFeedbackVectorSpec() : slot_count_(0), name_count_(0) {} 99 StaticFeedbackVectorSpec() : slot_count_(0) {}
101 100
102 int slots() const { return slot_count_; } 101 int slots() const { return slot_count_; }
103 102
104 FeedbackVectorSlotKind GetKind(int slot) const { 103 FeedbackVectorSlotKind GetKind(int slot) const {
105 DCHECK(slot >= 0 && slot < slot_count_); 104 DCHECK(slot >= 0 && slot < slot_count_);
106 return kinds_[slot]; 105 return kinds_[slot];
107 } 106 }
108 107
109 int name_count() const { return name_count_; }
110
111 Handle<String> GetName(int index) const {
112 DCHECK(index >= 0 && index < name_count_);
113 return names_[index];
114 }
115
116 private: 108 private:
117 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; 109 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>;
118 110
119 void append(FeedbackVectorSlotKind kind) { 111 void append(FeedbackVectorSlotKind kind) {
120 DCHECK(slot_count_ < kMaxLength); 112 DCHECK(slot_count_ < kMaxLength);
121 kinds_[slot_count_++] = kind; 113 kinds_[slot_count_++] = kind;
122 } 114 }
123 115
124 void append_name(Handle<String> name) {
125 DCHECK(name_count_ < kMaxLength);
126 names_[name_count_++] = name;
127 }
128
129 static const int kMaxLength = 12; 116 static const int kMaxLength = 12;
130 117
131 int slot_count_; 118 int slot_count_;
132 FeedbackVectorSlotKind kinds_[kMaxLength]; 119 FeedbackVectorSlotKind kinds_[kMaxLength];
133 int name_count_;
134 Handle<String> names_[kMaxLength];
135 }; 120 };
136 121
137 122
138 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { 123 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> {
139 public: 124 public:
140 explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone), names_(zone) { 125 explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone) {
141 slot_kinds_.reserve(16); 126 slot_kinds_.reserve(16);
142 names_.reserve(8);
143 } 127 }
144 128
145 int slots() const { return static_cast<int>(slot_kinds_.size()); } 129 int slots() const { return static_cast<int>(slot_kinds_.size()); }
146 130
147 FeedbackVectorSlotKind GetKind(int slot) const { 131 FeedbackVectorSlotKind GetKind(int slot) const {
148 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); 132 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot));
149 } 133 }
150 134
151 int name_count() const { return static_cast<int>(names_.size()); }
152
153 Handle<String> GetName(int index) const { return names_.at(index); }
154
155 private: 135 private:
156 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; 136 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>;
157 137
158 void append(FeedbackVectorSlotKind kind) { 138 void append(FeedbackVectorSlotKind kind) {
159 slot_kinds_.push_back(static_cast<unsigned char>(kind)); 139 slot_kinds_.push_back(static_cast<unsigned char>(kind));
160 } 140 }
161 141
162 void append_name(Handle<String> name) { names_.push_back(name); }
163
164 ZoneVector<unsigned char> slot_kinds_; 142 ZoneVector<unsigned char> slot_kinds_;
165 ZoneVector<Handle<String>> names_;
166 }; 143 };
167 144
168 145
169 // The shape of the TypeFeedbackMetadata is an array with: 146 // The shape of the TypeFeedbackMetadata is an array with:
170 // 0: slot_count 147 // 0: slot_count
171 // 1: names table 148 // 1: names table
172 // 2..N: slot kinds packed into a bit vector 149 // 2..N: slot kinds packed into a bit vector
173 // 150 //
174 class TypeFeedbackMetadata : public FixedArray { 151 class TypeFeedbackMetadata : public FixedArray {
175 public: 152 public:
176 // Casting. 153 // Casting.
177 static inline TypeFeedbackMetadata* cast(Object* obj); 154 static inline TypeFeedbackMetadata* cast(Object* obj);
178 155
179 static const int kSlotsCountIndex = 0; 156 static const int kSlotsCountIndex = 0;
180 static const int kNamesTableIndex = 1; 157 static const int kReservedIndexCount = 1;
181 static const int kReservedIndexCount = 2;
182 158
183 static const int kNameTableEntrySize = 2; 159 static const int kNameTableEntrySize = 2;
184 static const int kNameTableSlotIndex = 0; 160 static const int kNameTableSlotIndex = 0;
185 static const int kNameTableNameIndex = 1; 161 static const int kNameTableNameIndex = 1;
186 162
187 // Returns number of feedback vector elements used by given slot kind. 163 // Returns number of feedback vector elements used by given slot kind.
188 static inline int GetSlotSize(FeedbackVectorSlotKind kind); 164 static inline int GetSlotSize(FeedbackVectorSlotKind kind);
189 165
190 // Defines if slots of given kind require "name".
191 static inline bool SlotRequiresName(FeedbackVectorSlotKind kind);
192
193 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; 166 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const;
194 167
195 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const; 168 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const;
196 169
197 inline bool is_empty() const; 170 inline bool is_empty() const;
198 171
199 // Returns number of slots in the vector. 172 // Returns number of slots in the vector.
200 inline int slot_count() const; 173 inline int slot_count() const;
201 174
202 // Returns slot kind for given slot. 175 // Returns slot kind for given slot.
203 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; 176 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const;
204 177
205 // Returns name for given slot.
206 String* GetName(FeedbackVectorSlot slot) const;
207
208 template <typename Spec> 178 template <typename Spec>
209 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); 179 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec);
210 180
211 #ifdef OBJECT_PRINT 181 #ifdef OBJECT_PRINT
212 // For gdb debugging. 182 // For gdb debugging.
213 void Print(); 183 void Print();
214 #endif // OBJECT_PRINT 184 #endif // OBJECT_PRINT
215 185
216 DECLARE_PRINTER(TypeFeedbackMetadata) 186 DECLARE_PRINTER(TypeFeedbackMetadata)
217 187
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 FeedbackVectorSlot slot); 236 FeedbackVectorSlot slot);
267 237
268 // Conversion from an integer index to the underlying array to a slot. 238 // Conversion from an integer index to the underlying array to a slot.
269 static inline FeedbackVectorSlot ToSlot(int index); 239 static inline FeedbackVectorSlot ToSlot(int index);
270 inline Object* Get(FeedbackVectorSlot slot) const; 240 inline Object* Get(FeedbackVectorSlot slot) const;
271 inline void Set(FeedbackVectorSlot slot, Object* value, 241 inline void Set(FeedbackVectorSlot slot, Object* value,
272 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 242 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
273 243
274 // Returns slot kind for given slot. 244 // Returns slot kind for given slot.
275 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; 245 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const;
276 // Returns name corresponding to given slot or an empty string.
277 String* GetName(FeedbackVectorSlot slot) const;
278 246
279 static Handle<TypeFeedbackVector> New(Isolate* isolate, 247 static Handle<TypeFeedbackVector> New(Isolate* isolate,
280 Handle<TypeFeedbackMetadata> metadata); 248 Handle<TypeFeedbackMetadata> metadata);
281 249
282 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, 250 static Handle<TypeFeedbackVector> Copy(Isolate* isolate,
283 Handle<TypeFeedbackVector> vector); 251 Handle<TypeFeedbackVector> vector);
284 252
285 #ifdef OBJECT_PRINT 253 #ifdef OBJECT_PRINT
286 // For gdb debugging. 254 // For gdb debugging.
287 void Print(); 255 void Print();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // Returns slot kind of the last slot returned by Next(). 332 // Returns slot kind of the last slot returned by Next().
365 FeedbackVectorSlotKind kind() const { 333 FeedbackVectorSlotKind kind() const {
366 DCHECK_NE(FeedbackVectorSlotKind::INVALID, slot_kind_); 334 DCHECK_NE(FeedbackVectorSlotKind::INVALID, slot_kind_);
367 DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, slot_kind_); 335 DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, slot_kind_);
368 return slot_kind_; 336 return slot_kind_;
369 } 337 }
370 338
371 // Returns entry size of the last slot returned by Next(). 339 // Returns entry size of the last slot returned by Next().
372 inline int entry_size() const; 340 inline int entry_size() const;
373 341
374 String* name() const {
375 DCHECK(TypeFeedbackMetadata::SlotRequiresName(kind()));
376 return metadata()->GetName(cur_slot_);
377 }
378
379 private: 342 private:
380 TypeFeedbackMetadata* metadata() const { 343 TypeFeedbackMetadata* metadata() const {
381 return !metadata_handle_.is_null() ? *metadata_handle_ : metadata_; 344 return !metadata_handle_.is_null() ? *metadata_handle_ : metadata_;
382 } 345 }
383 346
384 // The reason for having a handle and a raw pointer to the meta data is 347 // The reason for having a handle and a raw pointer to the meta data is
385 // to have a single iterator implementation for both "handlified" and raw 348 // to have a single iterator implementation for both "handlified" and raw
386 // pointer use cases. 349 // pointer use cases.
387 Handle<TypeFeedbackMetadata> metadata_handle_; 350 Handle<TypeFeedbackMetadata> metadata_handle_;
388 TypeFeedbackMetadata* metadata_; 351 TypeFeedbackMetadata* metadata_;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 } 678 }
716 }; 679 };
717 680
718 inline BinaryOperationHint BinaryOperationHintFromFeedback(int type_feedback); 681 inline BinaryOperationHint BinaryOperationHintFromFeedback(int type_feedback);
719 inline CompareOperationHint CompareOperationHintFromFeedback(int type_feedback); 682 inline CompareOperationHint CompareOperationHintFromFeedback(int type_feedback);
720 683
721 } // namespace internal 684 } // namespace internal
722 } // namespace v8 685 } // namespace v8
723 686
724 #endif // V8_TRANSITIONS_H_ 687 #endif // V8_TRANSITIONS_H_
OLDNEW
« no previous file with comments | « src/objects-printer.cc ('k') | src/type-feedback-vector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698