Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_TYPE_FEEDBACK_VECTOR_H_ |
| 6 | #define V8_TYPE_FEEDBACK_VECTOR_H_ |
| 7 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | #include "src/base/logging.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/elements-kind.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 12 | #include "src/objects.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/zone-containers.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 18 | |
| 19 | enum class FeedbackVectorSlotKind { |
| 20 | // This kind means that the slot points to the middle of other slot |
| 21 | // which occupies more than one feedback vector element. |
| 22 | // There must be no such slots in the system. |
| 23 | INVALID, |
| 24 | |
| 25 | CALL_IC, |
| 26 | LOAD_IC, |
| 27 | KEYED_LOAD_IC, |
| 28 | STORE_IC, |
| 29 | KEYED_STORE_IC, |
| 30 | |
| 31 | // This is a general purpose slot that occupies one feedback vector element. |
| 32 | GENERAL, |
| 33 | |
| 34 | KINDS_NUMBER // Last value indicating number of kinds. |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | std::ostream& operator<<(std::ostream& os, FeedbackVectorSlotKind kind); |
| 39 | |
| 40 | |
| 41 | template <typename Derived> |
| 42 | class FeedbackVectorSpecBase { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 43 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 44 | inline FeedbackVectorSlot AddSlot(FeedbackVectorSlotKind kind); |
| 45 | |
| 46 | FeedbackVectorSlot AddCallICSlot() { |
| 47 | return AddSlot(FeedbackVectorSlotKind::CALL_IC); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 48 | } |
| 49 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | FeedbackVectorSlot AddLoadICSlot() { |
| 51 | return AddSlot(FeedbackVectorSlotKind::LOAD_IC); |
| 52 | } |
| 53 | |
| 54 | FeedbackVectorSlot AddKeyedLoadICSlot() { |
| 55 | return AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC); |
| 56 | } |
| 57 | |
| 58 | FeedbackVectorSlot AddStoreICSlot() { |
| 59 | return AddSlot(FeedbackVectorSlotKind::STORE_IC); |
| 60 | } |
| 61 | |
| 62 | FeedbackVectorSlot AddKeyedStoreICSlot() { |
| 63 | return AddSlot(FeedbackVectorSlotKind::KEYED_STORE_IC); |
| 64 | } |
| 65 | |
| 66 | FeedbackVectorSlot AddGeneralSlot() { |
| 67 | return AddSlot(FeedbackVectorSlotKind::GENERAL); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | class StaticFeedbackVectorSpec |
| 73 | : public FeedbackVectorSpecBase<StaticFeedbackVectorSpec> { |
| 74 | public: |
| 75 | StaticFeedbackVectorSpec() : slots_(0) {} |
| 76 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 77 | int slots() const { return slots_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 78 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 79 | FeedbackVectorSlotKind GetKind(int slot) const { |
| 80 | DCHECK(slot >= 0 && slot < slots_); |
| 81 | return kinds_[slot]; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 85 | friend class FeedbackVectorSpecBase<StaticFeedbackVectorSpec>; |
| 86 | |
| 87 | void append(FeedbackVectorSlotKind kind) { |
| 88 | DCHECK(slots_ < kMaxLength); |
| 89 | kinds_[slots_++] = kind; |
| 90 | } |
| 91 | |
| 92 | static const int kMaxLength = 12; |
| 93 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 94 | int slots_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 95 | FeedbackVectorSlotKind kinds_[kMaxLength]; |
| 96 | }; |
| 97 | |
| 98 | |
| 99 | class FeedbackVectorSpec : public FeedbackVectorSpecBase<FeedbackVectorSpec> { |
| 100 | public: |
| 101 | explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone) { |
| 102 | slot_kinds_.reserve(16); |
| 103 | } |
| 104 | |
| 105 | int slots() const { return static_cast<int>(slot_kinds_.size()); } |
| 106 | |
| 107 | FeedbackVectorSlotKind GetKind(int slot) const { |
| 108 | return static_cast<FeedbackVectorSlotKind>(slot_kinds_.at(slot)); |
| 109 | } |
| 110 | |
| 111 | private: |
| 112 | friend class FeedbackVectorSpecBase<FeedbackVectorSpec>; |
| 113 | |
| 114 | void append(FeedbackVectorSlotKind kind) { |
| 115 | slot_kinds_.push_back(static_cast<unsigned char>(kind)); |
| 116 | } |
| 117 | |
| 118 | ZoneVector<unsigned char> slot_kinds_; |
| 119 | }; |
| 120 | |
| 121 | |
| 122 | // The shape of the TypeFeedbackMetadata is an array with: |
| 123 | // 0: slot_count |
| 124 | // 1..N: slot kinds packed into a bit vector |
| 125 | // |
| 126 | class TypeFeedbackMetadata : public FixedArray { |
| 127 | public: |
| 128 | // Casting. |
| 129 | static inline TypeFeedbackMetadata* cast(Object* obj); |
| 130 | |
| 131 | static const int kSlotsCountIndex = 0; |
| 132 | static const int kReservedIndexCount = 1; |
| 133 | |
| 134 | // Returns number of feedback vector elements used by given slot kind. |
| 135 | static inline int GetSlotSize(FeedbackVectorSlotKind kind); |
| 136 | |
| 137 | bool SpecDiffersFrom(const FeedbackVectorSpec* other_spec) const; |
| 138 | |
| 139 | // Returns number of slots in the vector. |
| 140 | inline int slot_count() const; |
| 141 | |
| 142 | // Returns slot kind for given slot. |
| 143 | FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; |
| 144 | |
| 145 | template <typename Spec> |
| 146 | static Handle<TypeFeedbackMetadata> New(Isolate* isolate, const Spec* spec); |
| 147 | |
| 148 | #ifdef OBJECT_PRINT |
| 149 | // For gdb debugging. |
| 150 | void Print(); |
| 151 | #endif // OBJECT_PRINT |
| 152 | |
| 153 | DECLARE_PRINTER(TypeFeedbackMetadata) |
| 154 | |
| 155 | static const char* Kind2String(FeedbackVectorSlotKind kind); |
| 156 | |
| 157 | private: |
| 158 | static const int kFeedbackVectorSlotKindBits = 3; |
| 159 | STATIC_ASSERT(static_cast<int>(FeedbackVectorSlotKind::KINDS_NUMBER) < |
| 160 | (1 << kFeedbackVectorSlotKindBits)); |
| 161 | |
| 162 | void SetKind(FeedbackVectorSlot slot, FeedbackVectorSlotKind kind); |
| 163 | |
| 164 | typedef BitSetComputer<FeedbackVectorSlotKind, kFeedbackVectorSlotKindBits, |
| 165 | kSmiValueSize, uint32_t> VectorICComputer; |
| 166 | |
| 167 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackMetadata); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | |
| 171 | // The shape of the TypeFeedbackVector is an array with: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 172 | // 0: feedback metadata |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 173 | // 1: ics_with_types |
| 174 | // 2: ics_with_generic_info |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 175 | // 3: feedback slot #0 (N >= 3) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 176 | // ... |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 177 | // N + slot_count - 1: feedback slot #(slot_count-1) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 178 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 179 | class TypeFeedbackVector : public FixedArray { |
| 180 | public: |
| 181 | // Casting. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 182 | static inline TypeFeedbackVector* cast(Object* obj); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 183 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 184 | static const int kMetadataIndex = 0; |
| 185 | static const int kReservedIndexCount = 1; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 186 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 187 | inline void ComputeCounts(int* with_type_info, int* generic); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 188 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 189 | inline bool is_empty() const; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 190 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 191 | // Returns number of slots in the vector. |
| 192 | inline int slot_count() const; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 193 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 194 | inline TypeFeedbackMetadata* metadata() const; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 195 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 196 | // Conversion from a slot to an integer index to the underlying array. |
| 197 | inline int GetIndex(FeedbackVectorSlot slot) const; |
| 198 | static int GetIndexFromSpec(const FeedbackVectorSpec* spec, |
| 199 | FeedbackVectorSlot slot); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 200 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 201 | // Conversion from an integer index to the underlying array to a slot. |
| 202 | inline FeedbackVectorSlot ToSlot(int index) const; |
| 203 | inline Object* Get(FeedbackVectorSlot slot) const; |
| 204 | inline void Set(FeedbackVectorSlot slot, Object* value, |
| 205 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 206 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 207 | // Returns slot kind for given slot. |
| 208 | inline FeedbackVectorSlotKind GetKind(FeedbackVectorSlot slot) const; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 209 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 210 | static Handle<TypeFeedbackVector> New(Isolate* isolate, |
| 211 | Handle<TypeFeedbackMetadata> metadata); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 212 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 213 | static Handle<TypeFeedbackVector> Copy(Isolate* isolate, |
| 214 | Handle<TypeFeedbackVector> vector); |
| 215 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 216 | #ifdef OBJECT_PRINT |
| 217 | // For gdb debugging. |
| 218 | void Print(); |
| 219 | #endif // OBJECT_PRINT |
| 220 | |
| 221 | DECLARE_PRINTER(TypeFeedbackVector) |
| 222 | |
| 223 | // Clears the vector slots. |
| 224 | void ClearSlots(SharedFunctionInfo* shared) { ClearSlotsImpl(shared, true); } |
| 225 | |
| 226 | void ClearSlotsAtGCTime(SharedFunctionInfo* shared) { |
| 227 | ClearSlotsImpl(shared, false); |
| 228 | } |
| 229 | |
| 230 | static void ClearAllKeyedStoreICs(Isolate* isolate); |
| 231 | void ClearKeyedStoreICs(SharedFunctionInfo* shared); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 232 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 233 | // The object that indicates an uninitialized cache. |
| 234 | static inline Handle<Object> UninitializedSentinel(Isolate* isolate); |
| 235 | |
| 236 | // The object that indicates a megamorphic state. |
| 237 | static inline Handle<Object> MegamorphicSentinel(Isolate* isolate); |
| 238 | |
| 239 | // The object that indicates a premonomorphic state. |
| 240 | static inline Handle<Object> PremonomorphicSentinel(Isolate* isolate); |
| 241 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 242 | // A raw version of the uninitialized sentinel that's safe to read during |
| 243 | // garbage collection (e.g., for patching the cache). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 244 | static inline Object* RawUninitializedSentinel(Isolate* isolate); |
| 245 | |
| 246 | static const int kDummyLoadICSlot = 0; |
| 247 | static const int kDummyKeyedLoadICSlot = 2; |
| 248 | static const int kDummyStoreICSlot = 4; |
| 249 | static const int kDummyKeyedStoreICSlot = 6; |
| 250 | |
| 251 | static Handle<TypeFeedbackVector> DummyVector(Isolate* isolate); |
| 252 | static FeedbackVectorSlot DummySlot(int dummyIndex) { |
| 253 | DCHECK(dummyIndex >= 0 && dummyIndex <= kDummyKeyedStoreICSlot); |
| 254 | return FeedbackVectorSlot(dummyIndex); |
| 255 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 256 | |
| 257 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 258 | void ClearSlotsImpl(SharedFunctionInfo* shared, bool force_clear); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 259 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 260 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackVector); |
| 261 | }; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 262 | |
| 263 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 264 | // The following asserts protect an optimization in type feedback vector |
| 265 | // code that looks into the contents of a slot assuming to find a String, |
| 266 | // a Symbol, an AllocationSite, a WeakCell, or a FixedArray. |
| 267 | STATIC_ASSERT(WeakCell::kSize >= 2 * kPointerSize); |
| 268 | STATIC_ASSERT(WeakCell::kValueOffset == AllocationSite::kTransitionInfoOffset); |
| 269 | STATIC_ASSERT(WeakCell::kValueOffset == FixedArray::kLengthOffset); |
| 270 | STATIC_ASSERT(WeakCell::kValueOffset == Name::kHashFieldSlot); |
| 271 | // Verify that an empty hash field looks like a tagged object, but can't |
| 272 | // possibly be confused with a pointer. |
| 273 | STATIC_ASSERT((Name::kEmptyHashField & kHeapObjectTag) == kHeapObjectTag); |
| 274 | STATIC_ASSERT(Name::kEmptyHashField == 0x3); |
| 275 | // Verify that a set hash field will not look like a tagged object. |
| 276 | STATIC_ASSERT(Name::kHashNotComputedMask == kHeapObjectTag); |
| 277 | |
| 278 | |
| 279 | class TypeFeedbackMetadataIterator { |
| 280 | public: |
| 281 | explicit TypeFeedbackMetadataIterator(Handle<TypeFeedbackMetadata> metadata) |
| 282 | : metadata_handle_(metadata), |
| 283 | slot_(FeedbackVectorSlot(0)), |
| 284 | slot_kind_(FeedbackVectorSlotKind::INVALID) {} |
| 285 | |
| 286 | explicit TypeFeedbackMetadataIterator(TypeFeedbackMetadata* metadata) |
| 287 | : metadata_(metadata), |
| 288 | slot_(FeedbackVectorSlot(0)), |
| 289 | slot_kind_(FeedbackVectorSlotKind::INVALID) {} |
| 290 | |
| 291 | bool HasNext() const { return slot_.ToInt() < metadata()->slot_count(); } |
| 292 | |
| 293 | FeedbackVectorSlot Next() { |
| 294 | DCHECK(HasNext()); |
| 295 | FeedbackVectorSlot slot = slot_; |
| 296 | slot_kind_ = metadata()->GetKind(slot); |
| 297 | slot_ = FeedbackVectorSlot(slot_.ToInt() + entry_size()); |
| 298 | return slot; |
| 299 | } |
| 300 | |
| 301 | // Returns slot kind of the last slot returned by Next(). |
| 302 | FeedbackVectorSlotKind kind() const { |
| 303 | DCHECK_NE(FeedbackVectorSlotKind::INVALID, slot_kind_); |
| 304 | DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, slot_kind_); |
| 305 | return slot_kind_; |
| 306 | } |
| 307 | |
| 308 | // Returns entry size of the last slot returned by Next(). |
| 309 | int entry_size() const { return TypeFeedbackMetadata::GetSlotSize(kind()); } |
| 310 | |
| 311 | private: |
| 312 | TypeFeedbackMetadata* metadata() const { |
| 313 | return !metadata_handle_.is_null() ? *metadata_handle_ : metadata_; |
| 314 | } |
| 315 | |
| 316 | // The reason for having a handle and a raw pointer to the meta data is |
| 317 | // to have a single iterator implementation for both "handlified" and raw |
| 318 | // pointer use cases. |
| 319 | Handle<TypeFeedbackMetadata> metadata_handle_; |
| 320 | TypeFeedbackMetadata* metadata_; |
| 321 | FeedbackVectorSlot slot_; |
| 322 | FeedbackVectorSlotKind slot_kind_; |
| 323 | }; |
| 324 | |
| 325 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 326 | // A FeedbackNexus is the combination of a TypeFeedbackVector and a slot. |
| 327 | // Derived classes customize the update and retrieval of feedback. |
| 328 | class FeedbackNexus { |
| 329 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 330 | FeedbackNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 331 | : vector_handle_(vector), vector_(NULL), slot_(slot) {} |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 332 | FeedbackNexus(TypeFeedbackVector* vector, FeedbackVectorSlot slot) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 333 | : vector_(vector), slot_(slot) {} |
| 334 | virtual ~FeedbackNexus() {} |
| 335 | |
| 336 | Handle<TypeFeedbackVector> vector_handle() const { |
| 337 | DCHECK(vector_ == NULL); |
| 338 | return vector_handle_; |
| 339 | } |
| 340 | TypeFeedbackVector* vector() const { |
| 341 | return vector_handle_.is_null() ? vector_ : *vector_handle_; |
| 342 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 343 | FeedbackVectorSlot slot() const { return slot_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 344 | |
| 345 | InlineCacheState ic_state() const { return StateFromFeedback(); } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 346 | bool IsUninitialized() const { return StateFromFeedback() == UNINITIALIZED; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 347 | Map* FindFirstMap() const { |
| 348 | MapHandleList maps; |
| 349 | ExtractMaps(&maps); |
| 350 | if (maps.length() > 0) return *maps.at(0); |
| 351 | return NULL; |
| 352 | } |
| 353 | |
| 354 | // TODO(mvstanton): remove FindAllMaps, it didn't survive a code review. |
| 355 | void FindAllMaps(MapHandleList* maps) const { ExtractMaps(maps); } |
| 356 | |
| 357 | virtual InlineCacheState StateFromFeedback() const = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 358 | virtual int ExtractMaps(MapHandleList* maps) const; |
| 359 | virtual MaybeHandle<Code> FindHandlerForMap(Handle<Map> map) const; |
| 360 | virtual bool FindHandlers(CodeHandleList* code_list, int length = -1) const; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 361 | virtual Name* FindFirstName() const { return NULL; } |
| 362 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 363 | virtual void ConfigureUninitialized(); |
| 364 | virtual void ConfigurePremonomorphic(); |
| 365 | virtual void ConfigureMegamorphic(); |
| 366 | |
| 367 | inline Object* GetFeedback() const; |
| 368 | inline Object* GetFeedbackExtra() const; |
| 369 | |
| 370 | inline Isolate* GetIsolate() const; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 371 | |
| 372 | protected: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 373 | inline void SetFeedback(Object* feedback, |
| 374 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 375 | inline void SetFeedbackExtra(Object* feedback_extra, |
| 376 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 377 | |
| 378 | Handle<FixedArray> EnsureArrayOfSize(int length); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 379 | Handle<FixedArray> EnsureExtraArrayOfSize(int length); |
| 380 | void InstallHandlers(Handle<FixedArray> array, MapHandleList* maps, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 381 | CodeHandleList* handlers); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 382 | |
| 383 | private: |
| 384 | // The reason for having a vector handle and a raw pointer is that we can and |
| 385 | // should use handles during IC miss, but not during GC when we clear ICs. If |
| 386 | // you have a handle to the vector that is better because more operations can |
| 387 | // be done, like allocation. |
| 388 | Handle<TypeFeedbackVector> vector_handle_; |
| 389 | TypeFeedbackVector* vector_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 390 | FeedbackVectorSlot slot_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 394 | class CallICNexus final : public FeedbackNexus { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 395 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 396 | // Monomorphic call ics store call counts. Platform code needs to increment |
| 397 | // the count appropriately (ie, by 2). |
| 398 | static const int kCallCountIncrement = 2; |
| 399 | |
| 400 | CallICNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 401 | : FeedbackNexus(vector, slot) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 402 | DCHECK_EQ(FeedbackVectorSlotKind::CALL_IC, vector->GetKind(slot)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 403 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 404 | CallICNexus(TypeFeedbackVector* vector, FeedbackVectorSlot slot) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 405 | : FeedbackNexus(vector, slot) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 406 | DCHECK_EQ(FeedbackVectorSlotKind::CALL_IC, vector->GetKind(slot)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void Clear(Code* host); |
| 410 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 411 | void ConfigureMonomorphicArray(); |
| 412 | void ConfigureMonomorphic(Handle<JSFunction> function); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 413 | void ConfigureMegamorphic() final; |
| 414 | void ConfigureMegamorphic(int call_count); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 415 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 416 | InlineCacheState StateFromFeedback() const final; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 417 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 418 | int ExtractMaps(MapHandleList* maps) const final { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 419 | // CallICs don't record map feedback. |
| 420 | return 0; |
| 421 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 422 | MaybeHandle<Code> FindHandlerForMap(Handle<Map> map) const final { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 423 | return MaybeHandle<Code>(); |
| 424 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 425 | bool FindHandlers(CodeHandleList* code_list, int length = -1) const final { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 426 | return length == 0; |
| 427 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 428 | |
| 429 | int ExtractCallCount(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | |
| 433 | class LoadICNexus : public FeedbackNexus { |
| 434 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 435 | LoadICNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 436 | : FeedbackNexus(vector, slot) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 437 | DCHECK_EQ(FeedbackVectorSlotKind::LOAD_IC, vector->GetKind(slot)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 438 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 439 | explicit LoadICNexus(Isolate* isolate) |
| 440 | : FeedbackNexus( |
| 441 | TypeFeedbackVector::DummyVector(isolate), |
| 442 | FeedbackVectorSlot(TypeFeedbackVector::kDummyLoadICSlot)) {} |
| 443 | LoadICNexus(TypeFeedbackVector* vector, FeedbackVectorSlot slot) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 444 | : FeedbackNexus(vector, slot) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 445 | DCHECK_EQ(FeedbackVectorSlotKind::LOAD_IC, vector->GetKind(slot)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | void Clear(Code* host); |
| 449 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 450 | void ConfigureMonomorphic(Handle<Map> receiver_map, Handle<Code> handler); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 451 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 452 | void ConfigurePolymorphic(MapHandleList* maps, CodeHandleList* handlers); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 453 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 454 | InlineCacheState StateFromFeedback() const override; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 455 | }; |
| 456 | |
| 457 | |
| 458 | class KeyedLoadICNexus : public FeedbackNexus { |
| 459 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 460 | KeyedLoadICNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 461 | : FeedbackNexus(vector, slot) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 462 | DCHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, vector->GetKind(slot)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 463 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 464 | KeyedLoadICNexus(TypeFeedbackVector* vector, FeedbackVectorSlot slot) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 465 | : FeedbackNexus(vector, slot) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 466 | DCHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, vector->GetKind(slot)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | void Clear(Code* host); |
| 470 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 471 | // name can be a null handle for element loads. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 472 | void ConfigureMonomorphic(Handle<Name> name, Handle<Map> receiver_map, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 473 | Handle<Code> handler); |
| 474 | // name can be null. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 475 | void ConfigurePolymorphic(Handle<Name> name, MapHandleList* maps, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 476 | CodeHandleList* handlers); |
| 477 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 478 | void ConfigureMegamorphicKeyed(IcCheckType property_type); |
| 479 | |
| 480 | IcCheckType GetKeyType() const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 481 | InlineCacheState StateFromFeedback() const override; |
| 482 | Name* FindFirstName() const override; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 483 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 484 | |
| 485 | |
| 486 | class StoreICNexus : public FeedbackNexus { |
| 487 | public: |
| 488 | StoreICNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) |
| 489 | : FeedbackNexus(vector, slot) { |
| 490 | DCHECK_EQ(FeedbackVectorSlotKind::STORE_IC, vector->GetKind(slot)); |
| 491 | } |
| 492 | explicit StoreICNexus(Isolate* isolate) |
| 493 | : FeedbackNexus( |
| 494 | TypeFeedbackVector::DummyVector(isolate), |
| 495 | FeedbackVectorSlot(TypeFeedbackVector::kDummyStoreICSlot)) {} |
| 496 | StoreICNexus(TypeFeedbackVector* vector, FeedbackVectorSlot slot) |
| 497 | : FeedbackNexus(vector, slot) { |
| 498 | DCHECK_EQ(FeedbackVectorSlotKind::STORE_IC, vector->GetKind(slot)); |
| 499 | } |
| 500 | |
| 501 | void Clear(Code* host); |
| 502 | |
| 503 | void ConfigureMonomorphic(Handle<Map> receiver_map, Handle<Code> handler); |
| 504 | |
| 505 | void ConfigurePolymorphic(MapHandleList* maps, CodeHandleList* handlers); |
| 506 | |
| 507 | InlineCacheState StateFromFeedback() const override; |
| 508 | }; |
| 509 | |
| 510 | |
| 511 | class KeyedStoreICNexus : public FeedbackNexus { |
| 512 | public: |
| 513 | KeyedStoreICNexus(Handle<TypeFeedbackVector> vector, FeedbackVectorSlot slot) |
| 514 | : FeedbackNexus(vector, slot) { |
| 515 | DCHECK_EQ(FeedbackVectorSlotKind::KEYED_STORE_IC, vector->GetKind(slot)); |
| 516 | } |
| 517 | explicit KeyedStoreICNexus(Isolate* isolate) |
| 518 | : FeedbackNexus( |
| 519 | TypeFeedbackVector::DummyVector(isolate), |
| 520 | FeedbackVectorSlot(TypeFeedbackVector::kDummyKeyedStoreICSlot)) {} |
| 521 | KeyedStoreICNexus(TypeFeedbackVector* vector, FeedbackVectorSlot slot) |
| 522 | : FeedbackNexus(vector, slot) { |
| 523 | DCHECK_EQ(FeedbackVectorSlotKind::KEYED_STORE_IC, vector->GetKind(slot)); |
| 524 | } |
| 525 | |
| 526 | void Clear(Code* host); |
| 527 | |
| 528 | // name can be a null handle for element loads. |
| 529 | void ConfigureMonomorphic(Handle<Name> name, Handle<Map> receiver_map, |
| 530 | Handle<Code> handler); |
| 531 | // name can be null. |
| 532 | void ConfigurePolymorphic(Handle<Name> name, MapHandleList* maps, |
| 533 | CodeHandleList* handlers); |
| 534 | void ConfigurePolymorphic(MapHandleList* maps, |
| 535 | MapHandleList* transitioned_maps, |
| 536 | CodeHandleList* handlers); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 537 | void ConfigureMegamorphicKeyed(IcCheckType property_type); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 538 | |
| 539 | KeyedAccessStoreMode GetKeyedAccessStoreMode() const; |
| 540 | IcCheckType GetKeyType() const; |
| 541 | |
| 542 | InlineCacheState StateFromFeedback() const override; |
| 543 | Name* FindFirstName() const override; |
| 544 | }; |
| 545 | } // namespace internal |
| 546 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 547 | |
| 548 | #endif // V8_TRANSITIONS_H_ |