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

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

Issue 2084913006: [ic] Let LoadGlobalIC load the variable name from TypeFeedbackMetadata. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@fix-load-ic-slow-stub
Patch Set: Created 4 years, 6 months 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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind); 43 inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind);
44 44
45 FeedbackVectorSlot AddCallICSlot() { 45 FeedbackVectorSlot AddCallICSlot() {
46 return AddSlot(FeedbackVectorSlotKind::CALL_IC); 46 return AddSlot(FeedbackVectorSlotKind::CALL_IC);
47 } 47 }
48 48
49 FeedbackVectorSlot AddLoadICSlot() { 49 FeedbackVectorSlot AddLoadICSlot() {
50 return AddSlot(FeedbackVectorSlotKind::LOAD_IC); 50 return AddSlot(FeedbackVectorSlotKind::LOAD_IC);
51 } 51 }
52 52
53 FeedbackVectorSlot AddLoadGlobalICSlot() { 53 FeedbackVectorSlot AddLoadGlobalICSlot(Handle<String> name) {
54 This()->append_name(name);
54 return AddSlot(FeedbackVectorSlotKind::LOAD_GLOBAL_IC); 55 return AddSlot(FeedbackVectorSlotKind::LOAD_GLOBAL_IC);
55 } 56 }
56 57
57 FeedbackVectorSlot AddKeyedLoadICSlot() { 58 FeedbackVectorSlot AddKeyedLoadICSlot() {
58 return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC); 59 return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC);
59 } 60 }
60 61
61 FeedbackVectorSlot AddStoreICSlot() { 62 FeedbackVectorSlot AddStoreICSlot() {
62 return AddSlot(FeedbackVectorSlotKind::STORE_IC); 63 return AddSlot(FeedbackVectorSlotKind::STORE_IC);
63 } 64 }
64 65
65 FeedbackVectorSlot AddKeyedStoreICSlot() { 66 FeedbackVectorSlot AddKeyedStoreICSlot() {
66 return AddSlot(FeedbackVectorSlotKind::KEYED_STORE_IC); 67 return AddSlot(FeedbackVectorSlotKind::KEYED_STORE_IC);
67 } 68 }
68 69
69 FeedbackVectorSlot AddGeneralSlot() { 70 FeedbackVectorSlot AddGeneralSlot() {
70 return AddSlot(FeedbackVectorSlotKind::GENERAL); 71 return AddSlot(FeedbackVectorSlotKind::GENERAL);
71 } 72 }
73
74 #ifdef OBJECT_PRINT
75 // For gdb debugging.
76 void Print();
77 #endif // OBJECT_PRINT
78
79 DECLARE_PRINTER(FeedbackVectorSpec)
80
81 private:
82 Derived* This() { return static_cast<Derived*>(this); }
72 }; 83 };
73 84
74 85
75 class StaticFeedbackVectorSpec 86 class StaticFeedbackVectorSpec
76 : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> { 87 : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> {
77 public: 88 public:
78 StaticFeedbackVectorSpec() : slots_(0) {} 89 StaticFeedbackVectorSpec() : slot_count_(0), name_count_(0) {}
79 90
80 int slots() const { return slots_; } 91 int slots() const { return slot_count_; }
81 92
82 FeedbackVectorSlotKind GetKind(int slot) const { 93 FeedbackVectorSlotKind GetKind(int slot) const {
83 DCHECK(slot >= 0 && slot < slots_); 94 DCHECK(slot >= 0 && slot < slot_count_);
84 return kinds_[slot]; 95 return kinds_[slot];
85 } 96 }
86 97
98 Handle<String> GetName(int index) const {
99 DCHECK(index >= 0 && index < name_count_);
100 return names_[index];
101 }
102
87 private: 103 private:
88 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; 104 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>;
89 105
90 void append(FeedbackVectorSlotKind kind) { 106 void append(FeedbackVectorSlotKind kind) {
91 DCHECK(slots_ < kMaxLength); 107 DCHECK(slot_count_ < kMaxLength);
92 kinds_[slots_++] = kind; 108 kinds_[slot_count_++] = kind;
109 }
110
111 void append_name(Handle<String> name) {
112 DCHECK(name_count_ < kMaxLength);
113 names_[name_count_++] = name;
93 } 114 }
94 115
95 static const int kMaxLength = 12; 116 static const int kMaxLength = 12;
96 117
97 int slots_; 118 int slot_count_;
98 FeedbackVectorSlotKind kinds_[kMaxLength]; 119 FeedbackVectorSlotKind kinds_[kMaxLength];
120 int name_count_;
121 Handle<String> names_[kMaxLength];
99 }; 122 };
100 123
101 124
102 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { 125 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> {
103 public: 126 public:
104 explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone) { 127 explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone), names_(zone) {
105 slot_kinds_.reserve(16); 128 slot_kinds_.reserve(16);
129 names_.reserve(8);
106 } 130 }
107 131
108 int slots() const { return static_cast<int>(slot_kinds_.size()); } 132 int slots() const { return static_cast<int>(slot_kinds_.size()); }
109 133
110 FeedbackVectorSlotKind GetKind(int slot) const { 134 FeedbackVectorSlotKind GetKind(int slot) const {
111 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); 135 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot));
112 } 136 }
113 137
138 Handle<String> GetName(int index) const { return names_.at(index); }
139
114 private: 140 private:
115 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; 141 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>;
116 142
117 void append(FeedbackVectorSlotKind kind) { 143 void append(FeedbackVectorSlotKind kind) {
118 slot_kinds_.push_back(static_cast<unsigned char>(kind)); 144 slot_kinds_.push_back(static_cast<unsigned char>(kind));
119 } 145 }
120 146
147 void append_name(Handle<String> name) { names_.push_back(name); }
148
121 ZoneVector<unsigned char> slot_kinds_; 149 ZoneVector<unsigned char> slot_kinds_;
150 ZoneVector<Handle<String>> names_;
122 }; 151 };
123 152
124 153
125 // The shape of the TypeFeedbackMetadata is an array with: 154 // The shape of the TypeFeedbackMetadata is an array with:
126 // 0: slot_count 155 // 0: slot_count
127 // 1..N: slot kinds packed into a bit vector 156 // 1: names table
157 // 2..N: slot kinds packed into a bit vector
128 // 158 //
129 class TypeFeedbackMetadata : public FixedArray { 159 class TypeFeedbackMetadata : public FixedArray {
130 public: 160 public:
131 // Casting. 161 // Casting.
132 static inline TypeFeedbackMetadata* cast(Object* obj); 162 static inline TypeFeedbackMetadata* cast(Object* obj);
133 163
134 static const int kSlotsCountIndex = 0; 164 static const int kSlotsCountIndex = 0;
135 static const int kReservedIndexCount = 1; 165 static const int kNamesTableIndex = 1;
166 static const int kReservedIndexCount = 2;
136 167
137 // Returns number of feedback vector elements used by given slot kind. 168 // Returns number of feedback vector elements used by given slot kind.
138 static inline int GetSlotSize(FeedbackVectorSlotKind kind); 169 static inline int GetSlotSize(FeedbackVectorSlotKind kind);
139 170
171 // Defines if slots of given kind require "name".
172 static inline bool SlotRequiresName(FeedbackVectorSlotKind kind);
173
140 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; 174 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const;
141 175
142 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const; 176 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const;
143 177
144 inline bool is_empty() const; 178 inline bool is_empty() const;
145 179
146 // Returns number of slots in the vector. 180 // Returns number of slots in the vector.
147 inline int slot_count() const; 181 inline int slot_count() const;
148 182
149 // Returns slot kind for given slot. 183 // Returns slot kind for given slot.
150 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; 184 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const;
151 185
186 // Returns name for given slot.
187 String* GetName(FeedbackVectorSlot slot) const;
188
152 template <typename Spec> 189 template <typename Spec>
153 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); 190 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec);
154 191
155 #ifdef OBJECT_PRINT 192 #ifdef OBJECT_PRINT
156 // For gdb debugging. 193 // For gdb debugging.
157 void Print(); 194 void Print();
158 #endif // OBJECT_PRINT 195 #endif // OBJECT_PRINT
159 196
160 DECLARE_PRINTER(TypeFeedbackMetadata) 197 DECLARE_PRINTER(TypeFeedbackMetadata)
161 198
(...skipping 10 matching lines...) Expand all
172 kSmiValueSize, uint32_t> VectorICComputer; 209 kSmiValueSize, uint32_t> VectorICComputer;
173 210
174 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackMetadata); 211 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackMetadata);
175 }; 212 };
176 213
177 214
178 // The shape of the TypeFeedbackVector is an array with: 215 // The shape of the TypeFeedbackVector is an array with:
179 // 0: feedback metadata 216 // 0: feedback metadata
180 // 1: ics_with_types 217 // 1: ics_with_types
181 // 2: ics_with_generic_info 218 // 2: ics_with_generic_info
182 // 3: feedback slot #0 (N >= 3) 219 // 3: feedback slot #0
183 // ... 220 // ...
184 // N + slot_count - 1: feedback slot #(slot_count-1) 221 // 3 + slot_count - 1: feedback slot #(slot_count-1)
185 // 222 //
186 class TypeFeedbackVector : public FixedArray { 223 class TypeFeedbackVector : public FixedArray {
187 public: 224 public:
188 // Casting. 225 // Casting.
189 static inline TypeFeedbackVector* cast(Object* obj); 226 static inline TypeFeedbackVector* cast(Object* obj);
190 227
191 static const int kMetadataIndex = 0; 228 static const int kMetadataIndex = 0;
192 static const int kReservedIndexCount = 1; 229 static const int kReservedIndexCount = 1;
193 230
194 inline void ComputeCounts(int* with_type_info, int* generic); 231 inline void ComputeCounts(int* with_type_info, int* generic);
(...skipping 13 matching lines...) Expand all
208 FeedbackVectorSlot slot); 245 FeedbackVectorSlot slot);
209 246
210 // Conversion from an integer index to the underlying array to a slot. 247 // Conversion from an integer index to the underlying array to a slot.
211 static inline FeedbackVectorSlot ToSlot(int index); 248 static inline FeedbackVectorSlot ToSlot(int index);
212 inline Object* Get(FeedbackVectorSlot slot) const; 249 inline Object* Get(FeedbackVectorSlot slot) const;
213 inline void Set(FeedbackVectorSlot slot, Object* value, 250 inline void Set(FeedbackVectorSlot slot, Object* value,
214 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 251 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
215 252
216 // Returns slot kind for given slot. 253 // Returns slot kind for given slot.
217 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; 254 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const;
255 // Returns name corresponding to given slot or an empty string.
256 String* GetName(FeedbackVectorSlot slot) const;
218 257
219 static Handle<TypeFeedbackVector> New(Isolate* isolate, 258 static Handle<TypeFeedbackVector> New(Isolate* isolate,
220 Handle<TypeFeedbackMetadata> metadata); 259 Handle<TypeFeedbackMetadata> metadata);
221 260
222 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, 261 static Handle<TypeFeedbackVector> Copy(Isolate* isolate,
223 Handle<TypeFeedbackVector> vector); 262 Handle<TypeFeedbackVector> vector);
224 263
225 #ifdef OBJECT_PRINT 264 #ifdef OBJECT_PRINT
226 // For gdb debugging. 265 // For gdb debugging.
227 void Print(); 266 void Print();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 STATIC_ASSERT((Name::kEmptyHashField & kHeapObjectTag) == kHeapObjectTag); 321 STATIC_ASSERT((Name::kEmptyHashField & kHeapObjectTag) == kHeapObjectTag);
283 STATIC_ASSERT(Name::kEmptyHashField == 0x3); 322 STATIC_ASSERT(Name::kEmptyHashField == 0x3);
284 // Verify that a set hash field will not look like a tagged object. 323 // Verify that a set hash field will not look like a tagged object.
285 STATIC_ASSERT(Name::kHashNotComputedMask == kHeapObjectTag); 324 STATIC_ASSERT(Name::kHashNotComputedMask == kHeapObjectTag);
286 325
287 326
288 class TypeFeedbackMetadataIterator { 327 class TypeFeedbackMetadataIterator {
289 public: 328 public:
290 explicit TypeFeedbackMetadataIterator(Handle<TypeFeedbackMetadata> metadata) 329 explicit TypeFeedbackMetadataIterator(Handle<TypeFeedbackMetadata> metadata)
291 : metadata_handle_(metadata), 330 : metadata_handle_(metadata),
292 slot_(FeedbackVectorSlot(0)), 331 next_slot_(FeedbackVectorSlot(0)),
293 slot_kind_(FeedbackVectorSlotKind::INVALID) {} 332 slot_kind_(FeedbackVectorSlotKind::INVALID) {}
294 333
295 explicit TypeFeedbackMetadataIterator(TypeFeedbackMetadata* metadata) 334 explicit TypeFeedbackMetadataIterator(TypeFeedbackMetadata* metadata)
296 : metadata_(metadata), 335 : metadata_(metadata),
297 slot_(FeedbackVectorSlot(0)), 336 next_slot_(FeedbackVectorSlot(0)),
298 slot_kind_(FeedbackVectorSlotKind::INVALID) {} 337 slot_kind_(FeedbackVectorSlotKind::INVALID) {}
299 338
300 inline bool HasNext() const; 339 inline bool HasNext() const;
301 340
302 inline FeedbackVectorSlot Next(); 341 inline FeedbackVectorSlot Next();
303 342
304 // Returns slot kind of the last slot returned by Next(). 343 // Returns slot kind of the last slot returned by Next().
305 FeedbackVectorSlotKind kind() const { 344 FeedbackVectorSlotKind kind() const {
306 DCHECK_NE(FeedbackVectorSlotKind::INVALID, slot_kind_); 345 DCHECK_NE(FeedbackVectorSlotKind::INVALID, slot_kind_);
307 DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, slot_kind_); 346 DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, slot_kind_);
308 return slot_kind_; 347 return slot_kind_;
309 } 348 }
310 349
311 // Returns entry size of the last slot returned by Next(). 350 // Returns entry size of the last slot returned by Next().
312 inline int entry_size() const; 351 inline int entry_size() const;
313 352
353 String* name() const {
354 DCHECK(TypeFeedbackMetadata::SlotRequiresName(kind()));
355 return metadata()->GetName(cur_slot_);
356 }
357
314 private: 358 private:
315 TypeFeedbackMetadata* metadata() const { 359 TypeFeedbackMetadata* metadata() const {
316 return !metadata_handle_.is_null() ? *metadata_handle_ : metadata_; 360 return !metadata_handle_.is_null() ? *metadata_handle_ : metadata_;
317 } 361 }
318 362
319 // The reason for having a handle and a raw pointer to the meta data is 363 // The reason for having a handle and a raw pointer to the meta data is
320 // to have a single iterator implementation for both "handlified" and raw 364 // to have a single iterator implementation for both "handlified" and raw
321 // pointer use cases. 365 // pointer use cases.
322 Handle<TypeFeedbackMetadata> metadata_handle_; 366 Handle<TypeFeedbackMetadata> metadata_handle_;
323 TypeFeedbackMetadata* metadata_; 367 TypeFeedbackMetadata* metadata_;
324 FeedbackVectorSlot slot_; 368 FeedbackVectorSlot cur_slot_;
369 FeedbackVectorSlot next_slot_;
325 FeedbackVectorSlotKind slot_kind_; 370 FeedbackVectorSlotKind slot_kind_;
326 }; 371 };
327 372
328 373
329 // A FeedbackNexus is the combination of a TypeFeedbackVector and a slot. 374 // A FeedbackNexus is the combination of a TypeFeedbackVector and a slot.
330 // Derived classes customize the update and retrieval of feedback. 375 // Derived classes customize the update and retrieval of feedback.
331 class FeedbackNexus { 376 class FeedbackNexus {
332 public: 377 public:
333 FeedbackNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) 378 FeedbackNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot)
334 : vector_handle_(vector), vector_(NULL), slot_(slot) {} 379 : vector_handle_(vector), vector_(NULL), slot_(slot) {}
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 KeyedAccessStoreMode GetKeyedAccessStoreMode() const; 614 KeyedAccessStoreMode GetKeyedAccessStoreMode() const;
570 IcCheckType GetKeyType() const; 615 IcCheckType GetKeyType() const;
571 616
572 InlineCacheState StateFromFeedback() const override; 617 InlineCacheState StateFromFeedback() const override;
573 Name* FindFirstName() const override; 618 Name* FindFirstName() const override;
574 }; 619 };
575 } // namespace internal 620 } // namespace internal
576 } // namespace v8 621 } // namespace v8
577 622
578 #endif // V8_TRANSITIONS_H_ 623 #endif // V8_TRANSITIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698