| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 int name_count() const { return name_count_; } |
| 99 |
| 100 Handle<String> GetName(int index) const { |
| 101 DCHECK(index >= 0 && index < name_count_); |
| 102 return names_[index]; |
| 103 } |
| 104 |
| 87 private: | 105 private: |
| 88 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; | 106 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; |
| 89 | 107 |
| 90 void append(FeedbackVectorSlotKind kind) { | 108 void append(FeedbackVectorSlotKind kind) { |
| 91 DCHECK(slots_ < kMaxLength); | 109 DCHECK(slot_count_ < kMaxLength); |
| 92 kinds_[slots_++] = kind; | 110 kinds_[slot_count_++] = kind; |
| 111 } |
| 112 |
| 113 void append_name(Handle<String> name) { |
| 114 DCHECK(name_count_ < kMaxLength); |
| 115 names_[name_count_++] = name; |
| 93 } | 116 } |
| 94 | 117 |
| 95 static const int kMaxLength = 12; | 118 static const int kMaxLength = 12; |
| 96 | 119 |
| 97 int slots_; | 120 int slot_count_; |
| 98 FeedbackVectorSlotKind kinds_[kMaxLength]; | 121 FeedbackVectorSlotKind kinds_[kMaxLength]; |
| 122 int name_count_; |
| 123 Handle<String> names_[kMaxLength]; |
| 99 }; | 124 }; |
| 100 | 125 |
| 101 | 126 |
| 102 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { | 127 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { |
| 103 public: | 128 public: |
| 104 explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone) { | 129 explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone), names_(zone) { |
| 105 slot_kinds_.reserve(16); | 130 slot_kinds_.reserve(16); |
| 131 names_.reserve(8); |
| 106 } | 132 } |
| 107 | 133 |
| 108 int slots() const { return static_cast<int>(slot_kinds_.size()); } | 134 int slots() const { return static_cast<int>(slot_kinds_.size()); } |
| 109 | 135 |
| 110 FeedbackVectorSlotKind GetKind(int slot) const { | 136 FeedbackVectorSlotKind GetKind(int slot) const { |
| 111 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); | 137 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); |
| 112 } | 138 } |
| 113 | 139 |
| 140 int name_count() const { return static_cast<int>(names_.size()); } |
| 141 |
| 142 Handle<String> GetName(int index) const { return names_.at(index); } |
| 143 |
| 114 private: | 144 private: |
| 115 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; | 145 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; |
| 116 | 146 |
| 117 void append(FeedbackVectorSlotKind kind) { | 147 void append(FeedbackVectorSlotKind kind) { |
| 118 slot_kinds_.push_back(static_cast<unsigned char>(kind)); | 148 slot_kinds_.push_back(static_cast<unsigned char>(kind)); |
| 119 } | 149 } |
| 120 | 150 |
| 151 void append_name(Handle<String> name) { names_.push_back(name); } |
| 152 |
| 121 ZoneVector<unsigned char> slot_kinds_; | 153 ZoneVector<unsigned char> slot_kinds_; |
| 154 ZoneVector<Handle<String>> names_; |
| 122 }; | 155 }; |
| 123 | 156 |
| 124 | 157 |
| 125 // The shape of the TypeFeedbackMetadata is an array with: | 158 // The shape of the TypeFeedbackMetadata is an array with: |
| 126 // 0: slot_count | 159 // 0: slot_count |
| 127 // 1..N: slot kinds packed into a bit vector | 160 // 1: names table |
| 161 // 2..N: slot kinds packed into a bit vector |
| 128 // | 162 // |
| 129 class TypeFeedbackMetadata : public FixedArray { | 163 class TypeFeedbackMetadata : public FixedArray { |
| 130 public: | 164 public: |
| 131 // Casting. | 165 // Casting. |
| 132 static inline TypeFeedbackMetadata* cast(Object* obj); | 166 static inline TypeFeedbackMetadata* cast(Object* obj); |
| 133 | 167 |
| 134 static const int kSlotsCountIndex = 0; | 168 static const int kSlotsCountIndex = 0; |
| 135 static const int kReservedIndexCount = 1; | 169 static const int kNamesTableIndex = 1; |
| 170 static const int kReservedIndexCount = 2; |
| 171 |
| 172 static const int kNameTableEntrySize = 2; |
| 173 static const int kNameTableSlotIndex = 0; |
| 174 static const int kNameTableNameIndex = 1; |
| 136 | 175 |
| 137 // Returns number of feedback vector elements used by given slot kind. | 176 // Returns number of feedback vector elements used by given slot kind. |
| 138 static inline int GetSlotSize(FeedbackVectorSlotKind kind); | 177 static inline int GetSlotSize(FeedbackVectorSlotKind kind); |
| 139 | 178 |
| 179 // Defines if slots of given kind require "name". |
| 180 static inline bool SlotRequiresName(FeedbackVectorSlotKind kind); |
| 181 |
| 140 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; | 182 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; |
| 141 | 183 |
| 142 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const; | 184 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const; |
| 143 | 185 |
| 144 inline bool is_empty() const; | 186 inline bool is_empty() const; |
| 145 | 187 |
| 146 // Returns number of slots in the vector. | 188 // Returns number of slots in the vector. |
| 147 inline int slot_count() const; | 189 inline int slot_count() const; |
| 148 | 190 |
| 149 // Returns slot kind for given slot. | 191 // Returns slot kind for given slot. |
| 150 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; | 192 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; |
| 151 | 193 |
| 194 // Returns name for given slot. |
| 195 String* GetName(FeedbackVectorSlot slot) const; |
| 196 |
| 152 template <typename Spec> | 197 template <typename Spec> |
| 153 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); | 198 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); |
| 154 | 199 |
| 155 #ifdef OBJECT_PRINT | 200 #ifdef OBJECT_PRINT |
| 156 // For gdb debugging. | 201 // For gdb debugging. |
| 157 void Print(); | 202 void Print(); |
| 158 #endif // OBJECT_PRINT | 203 #endif // OBJECT_PRINT |
| 159 | 204 |
| 160 DECLARE_PRINTER(TypeFeedbackMetadata) | 205 DECLARE_PRINTER(TypeFeedbackMetadata) |
| 161 | 206 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 kSmiValueSize, uint32_t> VectorICComputer; | 217 kSmiValueSize, uint32_t> VectorICComputer; |
| 173 | 218 |
| 174 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackMetadata); | 219 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackMetadata); |
| 175 }; | 220 }; |
| 176 | 221 |
| 177 | 222 |
| 178 // The shape of the TypeFeedbackVector is an array with: | 223 // The shape of the TypeFeedbackVector is an array with: |
| 179 // 0: feedback metadata | 224 // 0: feedback metadata |
| 180 // 1: ics_with_types | 225 // 1: ics_with_types |
| 181 // 2: ics_with_generic_info | 226 // 2: ics_with_generic_info |
| 182 // 3: feedback slot #0 (N >= 3) | 227 // 3: feedback slot #0 |
| 183 // ... | 228 // ... |
| 184 // N + slot_count - 1: feedback slot #(slot_count-1) | 229 // 3 + slot_count - 1: feedback slot #(slot_count-1) |
| 185 // | 230 // |
| 186 class TypeFeedbackVector : public FixedArray { | 231 class TypeFeedbackVector : public FixedArray { |
| 187 public: | 232 public: |
| 188 // Casting. | 233 // Casting. |
| 189 static inline TypeFeedbackVector* cast(Object* obj); | 234 static inline TypeFeedbackVector* cast(Object* obj); |
| 190 | 235 |
| 191 static const int kMetadataIndex = 0; | 236 static const int kMetadataIndex = 0; |
| 192 static const int kReservedIndexCount = 1; | 237 static const int kReservedIndexCount = 1; |
| 193 | 238 |
| 194 inline void ComputeCounts(int* with_type_info, int* generic); | 239 inline void ComputeCounts(int* with_type_info, int* generic); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 208 FeedbackVectorSlot slot); | 253 FeedbackVectorSlot slot); |
| 209 | 254 |
| 210 // Conversion from an integer index to the underlying array to a slot. | 255 // Conversion from an integer index to the underlying array to a slot. |
| 211 static inline FeedbackVectorSlot ToSlot(int index); | 256 static inline FeedbackVectorSlot ToSlot(int index); |
| 212 inline Object* Get(FeedbackVectorSlot slot) const; | 257 inline Object* Get(FeedbackVectorSlot slot) const; |
| 213 inline void Set(FeedbackVectorSlot slot, Object* value, | 258 inline void Set(FeedbackVectorSlot slot, Object* value, |
| 214 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 259 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 215 | 260 |
| 216 // Returns slot kind for given slot. | 261 // Returns slot kind for given slot. |
| 217 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; | 262 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; |
| 263 // Returns name corresponding to given slot or an empty string. |
| 264 String* GetName(FeedbackVectorSlot slot) const; |
| 218 | 265 |
| 219 static Handle<TypeFeedbackVector> New(Isolate* isolate, | 266 static Handle<TypeFeedbackVector> New(Isolate* isolate, |
| 220 Handle<TypeFeedbackMetadata> metadata); | 267 Handle<TypeFeedbackMetadata> metadata); |
| 221 | 268 |
| 222 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, | 269 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, |
| 223 Handle<TypeFeedbackVector> vector); | 270 Handle<TypeFeedbackVector> vector); |
| 224 | 271 |
| 225 #ifdef OBJECT_PRINT | 272 #ifdef OBJECT_PRINT |
| 226 // For gdb debugging. | 273 // For gdb debugging. |
| 227 void Print(); | 274 void Print(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 STATIC_ASSERT((Name::kEmptyHashField & kHeapObjectTag) == kHeapObjectTag); | 329 STATIC_ASSERT((Name::kEmptyHashField & kHeapObjectTag) == kHeapObjectTag); |
| 283 STATIC_ASSERT(Name::kEmptyHashField == 0x3); | 330 STATIC_ASSERT(Name::kEmptyHashField == 0x3); |
| 284 // Verify that a set hash field will not look like a tagged object. | 331 // Verify that a set hash field will not look like a tagged object. |
| 285 STATIC_ASSERT(Name::kHashNotComputedMask == kHeapObjectTag); | 332 STATIC_ASSERT(Name::kHashNotComputedMask == kHeapObjectTag); |
| 286 | 333 |
| 287 | 334 |
| 288 class TypeFeedbackMetadataIterator { | 335 class TypeFeedbackMetadataIterator { |
| 289 public: | 336 public: |
| 290 explicit TypeFeedbackMetadataIterator(Handle<TypeFeedbackMetadata> metadata) | 337 explicit TypeFeedbackMetadataIterator(Handle<TypeFeedbackMetadata> metadata) |
| 291 : metadata_handle_(metadata), | 338 : metadata_handle_(metadata), |
| 292 slot_(FeedbackVectorSlot(0)), | 339 next_slot_(FeedbackVectorSlot(0)), |
| 293 slot_kind_(FeedbackVectorSlotKind::INVALID) {} | 340 slot_kind_(FeedbackVectorSlotKind::INVALID) {} |
| 294 | 341 |
| 295 explicit TypeFeedbackMetadataIterator(TypeFeedbackMetadata* metadata) | 342 explicit TypeFeedbackMetadataIterator(TypeFeedbackMetadata* metadata) |
| 296 : metadata_(metadata), | 343 : metadata_(metadata), |
| 297 slot_(FeedbackVectorSlot(0)), | 344 next_slot_(FeedbackVectorSlot(0)), |
| 298 slot_kind_(FeedbackVectorSlotKind::INVALID) {} | 345 slot_kind_(FeedbackVectorSlotKind::INVALID) {} |
| 299 | 346 |
| 300 inline bool HasNext() const; | 347 inline bool HasNext() const; |
| 301 | 348 |
| 302 inline FeedbackVectorSlot Next(); | 349 inline FeedbackVectorSlot Next(); |
| 303 | 350 |
| 304 // Returns slot kind of the last slot returned by Next(). | 351 // Returns slot kind of the last slot returned by Next(). |
| 305 FeedbackVectorSlotKind kind() const { | 352 FeedbackVectorSlotKind kind() const { |
| 306 DCHECK_NE(FeedbackVectorSlotKind::INVALID, slot_kind_); | 353 DCHECK_NE(FeedbackVectorSlotKind::INVALID, slot_kind_); |
| 307 DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, slot_kind_); | 354 DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, slot_kind_); |
| 308 return slot_kind_; | 355 return slot_kind_; |
| 309 } | 356 } |
| 310 | 357 |
| 311 // Returns entry size of the last slot returned by Next(). | 358 // Returns entry size of the last slot returned by Next(). |
| 312 inline int entry_size() const; | 359 inline int entry_size() const; |
| 313 | 360 |
| 361 String* name() const { |
| 362 DCHECK(TypeFeedbackMetadata::SlotRequiresName(kind())); |
| 363 return metadata()->GetName(cur_slot_); |
| 364 } |
| 365 |
| 314 private: | 366 private: |
| 315 TypeFeedbackMetadata* metadata() const { | 367 TypeFeedbackMetadata* metadata() const { |
| 316 return !metadata_handle_.is_null() ? *metadata_handle_ : metadata_; | 368 return !metadata_handle_.is_null() ? *metadata_handle_ : metadata_; |
| 317 } | 369 } |
| 318 | 370 |
| 319 // The reason for having a handle and a raw pointer to the meta data is | 371 // 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 | 372 // to have a single iterator implementation for both "handlified" and raw |
| 321 // pointer use cases. | 373 // pointer use cases. |
| 322 Handle<TypeFeedbackMetadata> metadata_handle_; | 374 Handle<TypeFeedbackMetadata> metadata_handle_; |
| 323 TypeFeedbackMetadata* metadata_; | 375 TypeFeedbackMetadata* metadata_; |
| 324 FeedbackVectorSlot slot_; | 376 FeedbackVectorSlot cur_slot_; |
| 377 FeedbackVectorSlot next_slot_; |
| 325 FeedbackVectorSlotKind slot_kind_; | 378 FeedbackVectorSlotKind slot_kind_; |
| 326 }; | 379 }; |
| 327 | 380 |
| 328 | 381 |
| 329 // A FeedbackNexus is the combination of a TypeFeedbackVector and a slot. | 382 // A FeedbackNexus is the combination of a TypeFeedbackVector and a slot. |
| 330 // Derived classes customize the update and retrieval of feedback. | 383 // Derived classes customize the update and retrieval of feedback. |
| 331 class FeedbackNexus { | 384 class FeedbackNexus { |
| 332 public: | 385 public: |
| 333 FeedbackNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) | 386 FeedbackNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) |
| 334 : vector_handle_(vector), vector_(NULL), slot_(slot) {} | 387 : vector_handle_(vector), vector_(NULL), slot_(slot) {} |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 KeyedAccessStoreMode GetKeyedAccessStoreMode() const; | 622 KeyedAccessStoreMode GetKeyedAccessStoreMode() const; |
| 570 IcCheckType GetKeyType() const; | 623 IcCheckType GetKeyType() const; |
| 571 | 624 |
| 572 InlineCacheState StateFromFeedback() const override; | 625 InlineCacheState StateFromFeedback() const override; |
| 573 Name* FindFirstName() const override; | 626 Name* FindFirstName() const override; |
| 574 }; | 627 }; |
| 575 } // namespace internal | 628 } // namespace internal |
| 576 } // namespace v8 | 629 } // namespace v8 |
| 577 | 630 |
| 578 #endif // V8_TRANSITIONS_H_ | 631 #endif // V8_TRANSITIONS_H_ |
| OLD | NEW |