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