| 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 | 33 |
| 34 // This kind of slot has an integer parameter associated with it. | |
| 35 CREATE_CLOSURE, | |
| 36 // This is a general purpose slot that occupies one feedback vector element. | 34 // This is a general purpose slot that occupies one feedback vector element. |
| 37 GENERAL, | 35 GENERAL, |
| 38 | 36 |
| 39 KINDS_NUMBER // Last value indicating number of kinds. | 37 KINDS_NUMBER // Last value indicating number of kinds. |
| 40 }; | 38 }; |
| 41 | 39 |
| 42 std::ostream& operator<<(std::ostream& os, FeedbackVectorSlotKind kind); | 40 std::ostream& operator<<(std::ostream& os, FeedbackVectorSlotKind kind); |
| 43 | 41 |
| 44 | 42 |
| 45 template <typename Derived> | 43 template <typename Derived> |
| 46 class FeedbackVectorSpecBase { | 44 class FeedbackVectorSpecBase { |
| 47 public: | 45 public: |
| 48 inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind); | 46 inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind); |
| 49 | 47 |
| 50 FeedbackVectorSlot AddCallICSlot() { | 48 FeedbackVectorSlot AddCallICSlot() { |
| 51 return AddSlot(FeedbackVectorSlotKind::CALL_IC); | 49 return AddSlot(FeedbackVectorSlotKind::CALL_IC); |
| 52 } | 50 } |
| 53 | 51 |
| 54 FeedbackVectorSlot AddLoadICSlot() { | 52 FeedbackVectorSlot AddLoadICSlot() { |
| 55 return AddSlot(FeedbackVectorSlotKind::LOAD_IC); | 53 return AddSlot(FeedbackVectorSlotKind::LOAD_IC); |
| 56 } | 54 } |
| 57 | 55 |
| 58 FeedbackVectorSlot AddLoadGlobalICSlot() { | 56 FeedbackVectorSlot AddLoadGlobalICSlot() { |
| 59 return AddSlot(FeedbackVectorSlotKind::LOAD_GLOBAL_IC); | 57 return AddSlot(FeedbackVectorSlotKind::LOAD_GLOBAL_IC); |
| 60 } | 58 } |
| 61 | 59 |
| 62 FeedbackVectorSlot AddCreateClosureSlot(int size) { | |
| 63 This()->append_parameter(size); | |
| 64 return AddSlot(FeedbackVectorSlotKind::CREATE_CLOSURE); | |
| 65 } | |
| 66 | |
| 67 FeedbackVectorSlot AddKeyedLoadICSlot() { | 60 FeedbackVectorSlot AddKeyedLoadICSlot() { |
| 68 return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC); | 61 return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC); |
| 69 } | 62 } |
| 70 | 63 |
| 71 FeedbackVectorSlot AddStoreICSlot() { | 64 FeedbackVectorSlot AddStoreICSlot() { |
| 72 return AddSlot(FeedbackVectorSlotKind::STORE_IC); | 65 return AddSlot(FeedbackVectorSlotKind::STORE_IC); |
| 73 } | 66 } |
| 74 | 67 |
| 75 FeedbackVectorSlot AddKeyedStoreICSlot() { | 68 FeedbackVectorSlot AddKeyedStoreICSlot() { |
| 76 return AddSlot(FeedbackVectorSlotKind::KEYED_STORE_IC); | 69 return AddSlot(FeedbackVectorSlotKind::KEYED_STORE_IC); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 96 DECLARE_PRINTER(FeedbackVectorSpec) | 89 DECLARE_PRINTER(FeedbackVectorSpec) |
| 97 | 90 |
| 98 private: | 91 private: |
| 99 Derived* This() { return static_cast<Derived*>(this); } | 92 Derived* This() { return static_cast<Derived*>(this); } |
| 100 }; | 93 }; |
| 101 | 94 |
| 102 | 95 |
| 103 class StaticFeedbackVectorSpec | 96 class StaticFeedbackVectorSpec |
| 104 : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> { | 97 : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> { |
| 105 public: | 98 public: |
| 106 StaticFeedbackVectorSpec() : slot_count_(0), parameters_count_(0) {} | 99 StaticFeedbackVectorSpec() : slot_count_(0) {} |
| 107 | 100 |
| 108 int slots() const { return slot_count_; } | 101 int slots() const { return slot_count_; } |
| 109 | 102 |
| 110 FeedbackVectorSlotKind GetKind(int slot) const { | 103 FeedbackVectorSlotKind GetKind(int slot) const { |
| 111 DCHECK(slot >= 0 && slot < slot_count_); | 104 DCHECK(slot >= 0 && slot < slot_count_); |
| 112 return kinds_[slot]; | 105 return kinds_[slot]; |
| 113 } | 106 } |
| 114 | 107 |
| 115 int parameters_count() const { return parameters_count_; } | |
| 116 | |
| 117 int GetParameter(int index) const { | |
| 118 DCHECK(index >= 0 && index < parameters_count_); | |
| 119 return parameters_[index]; | |
| 120 } | |
| 121 | |
| 122 private: | 108 private: |
| 123 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; | 109 friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; |
| 124 | 110 |
| 125 void append(FeedbackVectorSlotKind kind) { | 111 void append(FeedbackVectorSlotKind kind) { |
| 126 DCHECK(slot_count_ < kMaxLength); | 112 DCHECK(slot_count_ < kMaxLength); |
| 127 kinds_[slot_count_++] = kind; | 113 kinds_[slot_count_++] = kind; |
| 128 } | 114 } |
| 129 | 115 |
| 130 void append_parameter(int parameter) { | |
| 131 DCHECK(parameters_count_ < kMaxLength); | |
| 132 parameters_[parameters_count_++] = parameter; | |
| 133 } | |
| 134 | |
| 135 static const int kMaxLength = 12; | 116 static const int kMaxLength = 12; |
| 136 | 117 |
| 137 int slot_count_; | 118 int slot_count_; |
| 138 FeedbackVectorSlotKind kinds_[kMaxLength]; | 119 FeedbackVectorSlotKind kinds_[kMaxLength]; |
| 139 int parameters_count_; | |
| 140 int parameters_[kMaxLength]; | |
| 141 }; | 120 }; |
| 142 | 121 |
| 143 | 122 |
| 144 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { | 123 class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { |
| 145 public: | 124 public: |
| 146 explicit FeedbackVectorSpec(Zone* zone) | 125 explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone) { |
| 147 : slot_kinds_(zone), parameters_(zone) { | |
| 148 slot_kinds_.reserve(16); | 126 slot_kinds_.reserve(16); |
| 149 parameters_.reserve(8); | |
| 150 } | 127 } |
| 151 | 128 |
| 152 int slots() const { return static_cast<int>(slot_kinds_.size()); } | 129 int slots() const { return static_cast<int>(slot_kinds_.size()); } |
| 153 | 130 |
| 154 FeedbackVectorSlotKind GetKind(int slot) const { | 131 FeedbackVectorSlotKind GetKind(int slot) const { |
| 155 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); | 132 return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); |
| 156 } | 133 } |
| 157 | 134 |
| 158 int parameters_count() const { return static_cast<int>(parameters_.size()); } | |
| 159 | |
| 160 int GetParameter(int index) const { return parameters_.at(index); } | |
| 161 | |
| 162 private: | 135 private: |
| 163 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; | 136 friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; |
| 164 | 137 |
| 165 void append(FeedbackVectorSlotKind kind) { | 138 void append(FeedbackVectorSlotKind kind) { |
| 166 slot_kinds_.push_back(static_cast<unsigned char>(kind)); | 139 slot_kinds_.push_back(static_cast<unsigned char>(kind)); |
| 167 } | 140 } |
| 168 | 141 |
| 169 void append_parameter(int parameter) { parameters_.push_back(parameter); } | |
| 170 | |
| 171 ZoneVector<unsigned char> slot_kinds_; | 142 ZoneVector<unsigned char> slot_kinds_; |
| 172 ZoneVector<int> parameters_; | |
| 173 }; | 143 }; |
| 174 | 144 |
| 175 | 145 |
| 176 // The shape of the TypeFeedbackMetadata is an array with: | 146 // The shape of the TypeFeedbackMetadata is an array with: |
| 177 // 0: slot_count | 147 // 0: slot_count |
| 178 // 1: names table | 148 // 1: names table |
| 179 // 2: parameters table | 149 // 2..N: slot kinds packed into a bit vector |
| 180 // 3..N: slot kinds packed into a bit vector | |
| 181 // | 150 // |
| 182 class TypeFeedbackMetadata : public FixedArray { | 151 class TypeFeedbackMetadata : public FixedArray { |
| 183 public: | 152 public: |
| 184 // Casting. | 153 // Casting. |
| 185 static inline TypeFeedbackMetadata* cast(Object* obj); | 154 static inline TypeFeedbackMetadata* cast(Object* obj); |
| 186 | 155 |
| 187 static const int kSlotsCountIndex = 0; | 156 static const int kSlotsCountIndex = 0; |
| 188 static const int kParametersTableIndex = 1; | 157 static const int kReservedIndexCount = 1; |
| 189 static const int kReservedIndexCount = 2; | |
| 190 | 158 |
| 191 // Returns number of feedback vector elements used by given slot kind. | 159 // Returns number of feedback vector elements used by given slot kind. |
| 192 static inline int GetSlotSize(FeedbackVectorSlotKind kind); | 160 static inline int GetSlotSize(FeedbackVectorSlotKind kind); |
| 193 | 161 |
| 194 // Defines if slots of given kind require "parameter". | |
| 195 static inline bool SlotRequiresParameter(FeedbackVectorSlotKind kind); | |
| 196 | |
| 197 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; | 162 bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; |
| 198 | 163 |
| 199 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const; | 164 bool DiffersFrom(const TypeFeedbackMetadata* other_metadata) const; |
| 200 | 165 |
| 201 inline bool is_empty() const; | 166 inline bool is_empty() const; |
| 202 | 167 |
| 203 // Returns number of slots in the vector. | 168 // Returns number of slots in the vector. |
| 204 inline int slot_count() const; | 169 inline int slot_count() const; |
| 205 | 170 |
| 206 // Returns slot kind for given slot. | 171 // Returns slot kind for given slot. |
| 207 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; | 172 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; |
| 208 | 173 |
| 209 // Returns parameter for given index (note: this is not the slot) | |
| 210 int GetParameter(int parameter_index) const; | |
| 211 | |
| 212 template <typename Spec> | 174 template <typename Spec> |
| 213 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); | 175 static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); |
| 214 | 176 |
| 215 #ifdef OBJECT_PRINT | 177 #ifdef OBJECT_PRINT |
| 216 // For gdb debugging. | 178 // For gdb debugging. |
| 217 void Print(); | 179 void Print(); |
| 218 #endif // OBJECT_PRINT | 180 #endif // OBJECT_PRINT |
| 219 | 181 |
| 220 DECLARE_PRINTER(TypeFeedbackMetadata) | 182 DECLARE_PRINTER(TypeFeedbackMetadata) |
| 221 | 183 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 FeedbackVectorSlot slot); | 232 FeedbackVectorSlot slot); |
| 271 | 233 |
| 272 // Conversion from an integer index to the underlying array to a slot. | 234 // Conversion from an integer index to the underlying array to a slot. |
| 273 static inline FeedbackVectorSlot ToSlot(int index); | 235 static inline FeedbackVectorSlot ToSlot(int index); |
| 274 inline Object* Get(FeedbackVectorSlot slot) const; | 236 inline Object* Get(FeedbackVectorSlot slot) const; |
| 275 inline void Set(FeedbackVectorSlot slot, Object* value, | 237 inline void Set(FeedbackVectorSlot slot, Object* value, |
| 276 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 238 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 277 | 239 |
| 278 // Returns slot kind for given slot. | 240 // Returns slot kind for given slot. |
| 279 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; | 241 FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; |
| 280 // Returns parameter corresponding to given slot or -1. | |
| 281 int GetParameter(FeedbackVectorSlot slot) const; | |
| 282 | 242 |
| 283 static Handle<TypeFeedbackVector> New(Isolate* isolate, | 243 static Handle<TypeFeedbackVector> New(Isolate* isolate, |
| 284 Handle<TypeFeedbackMetadata> metadata); | 244 Handle<TypeFeedbackMetadata> metadata); |
| 285 | 245 |
| 286 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, | 246 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, |
| 287 Handle<TypeFeedbackVector> vector); | 247 Handle<TypeFeedbackVector> vector); |
| 288 | 248 |
| 289 #ifdef OBJECT_PRINT | 249 #ifdef OBJECT_PRINT |
| 290 // For gdb debugging. | 250 // For gdb debugging. |
| 291 void Print(); | 251 void Print(); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 } | 667 } |
| 708 }; | 668 }; |
| 709 | 669 |
| 710 inline BinaryOperationHint BinaryOperationHintFromFeedback(int type_feedback); | 670 inline BinaryOperationHint BinaryOperationHintFromFeedback(int type_feedback); |
| 711 inline CompareOperationHint CompareOperationHintFromFeedback(int type_feedback); | 671 inline CompareOperationHint CompareOperationHintFromFeedback(int type_feedback); |
| 712 | 672 |
| 713 } // namespace internal | 673 } // namespace internal |
| 714 } // namespace v8 | 674 } // namespace v8 |
| 715 | 675 |
| 716 #endif // V8_TRANSITIONS_H_ | 676 #endif // V8_TRANSITIONS_H_ |
| OLD | NEW |