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