Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Side by Side Diff: src/type-feedback-vector.h

Issue 1309303008: Make type-feedback-vector.h usable without objects-inl.h header (and others). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comment. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/type-feedback-vector-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/checks.h" 10 #include "src/checks.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // 3: type information for ic slots, if any 80 // 3: type information for ic slots, if any
81 // ... 81 // ...
82 // N: first feedback slot (N >= 3) 82 // N: first feedback slot (N >= 3)
83 // ... 83 // ...
84 // [<first_ic_slot_index>: feedback slot] 84 // [<first_ic_slot_index>: feedback slot]
85 // ...to length() - 1 85 // ...to length() - 1
86 // 86 //
87 class TypeFeedbackVector : public FixedArray { 87 class TypeFeedbackVector : public FixedArray {
88 public: 88 public:
89 // Casting. 89 // Casting.
90 static TypeFeedbackVector* cast(Object* obj) { 90 static inline TypeFeedbackVector* cast(Object* obj);
91 DCHECK(obj->IsTypeFeedbackVector());
92 return reinterpret_cast<TypeFeedbackVector*>(obj);
93 }
94 91
95 static const int kReservedIndexCount = 3; 92 static const int kReservedIndexCount = 3;
96 static const int kFirstICSlotIndex = 0; 93 static const int kFirstICSlotIndex = 0;
97 static const int kWithTypesIndex = 1; 94 static const int kWithTypesIndex = 1;
98 static const int kGenericCountIndex = 2; 95 static const int kGenericCountIndex = 2;
99 96
100 static int elements_per_ic_slot() { return 2; } 97 static int elements_per_ic_slot() { return 2; }
101 98
102 int first_ic_slot_index() const { 99 inline int first_ic_slot_index() const;
103 DCHECK(length() >= kReservedIndexCount); 100 inline int ic_with_type_info_count();
104 return Smi::cast(get(kFirstICSlotIndex))->value(); 101 inline void change_ic_with_type_info_count(int delta);
105 } 102 inline int ic_generic_count();
106 103 inline void change_ic_generic_count(int delta);
107 int ic_with_type_info_count() {
108 return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0;
109 }
110
111 void change_ic_with_type_info_count(int delta) {
112 if (delta == 0) return;
113 int value = ic_with_type_info_count() + delta;
114 // Could go negative because of the debugger.
115 if (value >= 0) {
116 set(kWithTypesIndex, Smi::FromInt(value));
117 }
118 }
119
120 int ic_generic_count() {
121 return length() > 0 ? Smi::cast(get(kGenericCountIndex))->value() : 0;
122 }
123
124 void change_ic_generic_count(int delta) {
125 if (delta == 0) return;
126 int value = ic_generic_count() + delta;
127 if (value >= 0) {
128 set(kGenericCountIndex, Smi::FromInt(value));
129 }
130 }
131
132 inline int ic_metadata_length() const; 104 inline int ic_metadata_length() const;
133 105
134 bool SpecDiffersFrom(const ZoneFeedbackVectorSpec* other_spec) const; 106 bool SpecDiffersFrom(const ZoneFeedbackVectorSpec* other_spec) const;
135 107
136 int Slots() const { 108 inline int Slots() const;
137 if (length() == 0) return 0; 109 inline int ICSlots() const;
138 return Max(
139 0, first_ic_slot_index() - ic_metadata_length() - kReservedIndexCount);
140 }
141
142 int ICSlots() const {
143 if (length() == 0) return 0;
144 return (length() - first_ic_slot_index()) / elements_per_ic_slot();
145 }
146 110
147 // Conversion from a slot or ic slot to an integer index to the underlying 111 // Conversion from a slot or ic slot to an integer index to the underlying
148 // array. 112 // array.
149 int GetIndex(FeedbackVectorSlot slot) const { 113 inline int GetIndex(FeedbackVectorSlot slot) const;
150 DCHECK(slot.ToInt() < first_ic_slot_index()); 114 inline int GetIndex(FeedbackVectorICSlot slot) const;
151 return kReservedIndexCount + ic_metadata_length() + slot.ToInt();
152 }
153
154 int GetIndex(FeedbackVectorICSlot slot) const {
155 int first_ic_slot = first_ic_slot_index();
156 DCHECK(slot.ToInt() < ICSlots());
157 return first_ic_slot + slot.ToInt() * elements_per_ic_slot();
158 }
159 115
160 // Conversion from an integer index to either a slot or an ic slot. The caller 116 // Conversion from an integer index to either a slot or an ic slot. The caller
161 // should know what kind she expects. 117 // should know what kind she expects.
162 FeedbackVectorSlot ToSlot(int index) const { 118 inline FeedbackVectorSlot ToSlot(int index) const;
163 DCHECK(index >= kReservedIndexCount && index < first_ic_slot_index()); 119 inline FeedbackVectorICSlot ToICSlot(int index) const;
164 return FeedbackVectorSlot(index - ic_metadata_length() - 120 inline Object* Get(FeedbackVectorSlot slot) const;
165 kReservedIndexCount); 121 inline void Set(FeedbackVectorSlot slot, Object* value,
166 } 122 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
167 123 inline Object* Get(FeedbackVectorICSlot slot) const;
168 FeedbackVectorICSlot ToICSlot(int index) const { 124 inline void Set(FeedbackVectorICSlot slot, Object* value,
169 DCHECK(index >= first_ic_slot_index() && index < length()); 125 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
170 int ic_slot = (index - first_ic_slot_index()) / elements_per_ic_slot();
171 return FeedbackVectorICSlot(ic_slot);
172 }
173
174 Object* Get(FeedbackVectorSlot slot) const { return get(GetIndex(slot)); }
175 void Set(FeedbackVectorSlot slot, Object* value,
176 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) {
177 set(GetIndex(slot), value, mode);
178 }
179
180 Object* Get(FeedbackVectorICSlot slot) const { return get(GetIndex(slot)); }
181 void Set(FeedbackVectorICSlot slot, Object* value,
182 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) {
183 set(GetIndex(slot), value, mode);
184 }
185 126
186 // IC slots need metadata to recognize the type of IC. 127 // IC slots need metadata to recognize the type of IC.
187 Code::Kind GetKind(FeedbackVectorICSlot slot) const; 128 Code::Kind GetKind(FeedbackVectorICSlot slot) const;
188 129
189 template <typename Spec> 130 template <typename Spec>
190 static Handle<TypeFeedbackVector> Allocate(Isolate* isolate, 131 static Handle<TypeFeedbackVector> Allocate(Isolate* isolate,
191 const Spec* spec); 132 const Spec* spec);
192 133
193 static Handle<TypeFeedbackVector> Copy(Isolate* isolate, 134 static Handle<TypeFeedbackVector> Copy(Isolate* isolate,
194 Handle<TypeFeedbackVector> vector); 135 Handle<TypeFeedbackVector> vector);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 virtual InlineCacheState StateFromFeedback() const = 0; 254 virtual InlineCacheState StateFromFeedback() const = 0;
314 virtual int ExtractMaps(MapHandleList* maps) const; 255 virtual int ExtractMaps(MapHandleList* maps) const;
315 virtual MaybeHandle<Code> FindHandlerForMap(Handle<Map> map) const; 256 virtual MaybeHandle<Code> FindHandlerForMap(Handle<Map> map) const;
316 virtual bool FindHandlers(CodeHandleList* code_list, int length = -1) const; 257 virtual bool FindHandlers(CodeHandleList* code_list, int length = -1) const;
317 virtual Name* FindFirstName() const { return NULL; } 258 virtual Name* FindFirstName() const { return NULL; }
318 259
319 virtual void ConfigureUninitialized(); 260 virtual void ConfigureUninitialized();
320 virtual void ConfigurePremonomorphic(); 261 virtual void ConfigurePremonomorphic();
321 virtual void ConfigureMegamorphic(); 262 virtual void ConfigureMegamorphic();
322 263
323 Object* GetFeedback() const { return vector()->Get(slot()); } 264 inline Object* GetFeedback() const;
324 Object* GetFeedbackExtra() const { 265 inline Object* GetFeedbackExtra() const;
325 DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1);
326 int extra_index = vector()->GetIndex(slot()) + 1;
327 return vector()->get(extra_index);
328 }
329 266
330 protected: 267 protected:
331 Isolate* GetIsolate() const { return vector()->GetIsolate(); } 268 inline Isolate* GetIsolate() const;
332 269
333 void SetFeedback(Object* feedback, 270 inline void SetFeedback(Object* feedback,
334 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) { 271 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
335 vector()->Set(slot(), feedback, mode); 272 inline void SetFeedbackExtra(Object* feedback_extra,
336 } 273 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
337
338 void SetFeedbackExtra(Object* feedback_extra,
339 WriteBarrierMode mode = UPDATE_WRITE_BARRIER) {
340 DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1);
341 int index = vector()->GetIndex(slot()) + 1;
342 vector()->set(index, feedback_extra, mode);
343 }
344 274
345 Handle<FixedArray> EnsureArrayOfSize(int length); 275 Handle<FixedArray> EnsureArrayOfSize(int length);
346 Handle<FixedArray> EnsureExtraArrayOfSize(int length); 276 Handle<FixedArray> EnsureExtraArrayOfSize(int length);
347 void InstallHandlers(Handle<FixedArray> array, MapHandleList* maps, 277 void InstallHandlers(Handle<FixedArray> array, MapHandleList* maps,
348 CodeHandleList* handlers); 278 CodeHandleList* handlers);
349 279
350 private: 280 private:
351 // The reason for having a vector handle and a raw pointer is that we can and 281 // The reason for having a vector handle and a raw pointer is that we can and
352 // should use handles during IC miss, but not during GC when we clear ICs. If 282 // should use handles during IC miss, but not during GC when we clear ICs. If
353 // you have a handle to the vector that is better because more operations can 283 // you have a handle to the vector that is better because more operations can
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 KeyedAccessStoreMode GetKeyedAccessStoreMode() const; 427 KeyedAccessStoreMode GetKeyedAccessStoreMode() const;
498 IcCheckType GetKeyType() const; 428 IcCheckType GetKeyType() const;
499 429
500 InlineCacheState StateFromFeedback() const override; 430 InlineCacheState StateFromFeedback() const override;
501 Name* FindFirstName() const override; 431 Name* FindFirstName() const override;
502 }; 432 };
503 } 433 }
504 } // namespace v8::internal 434 } // namespace v8::internal
505 435
506 #endif // V8_TRANSITIONS_H_ 436 #endif // V8_TRANSITIONS_H_
OLDNEW
« no previous file with comments | « no previous file | src/type-feedback-vector-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698