OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_INL_H_ | 5 #ifndef V8_TYPE_FEEDBACK_VECTOR_INL_H_ |
6 #define V8_TYPE_FEEDBACK_VECTOR_INL_H_ | 6 #define V8_TYPE_FEEDBACK_VECTOR_INL_H_ |
7 | 7 |
8 #include "src/type-feedback-vector.h" | 8 #include "src/type-feedback-vector.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 FeedbackVectorSlotKind TypeFeedbackVector::GetKind( | 77 FeedbackVectorSlotKind TypeFeedbackVector::GetKind( |
78 FeedbackVectorSlot slot) const { | 78 FeedbackVectorSlot slot) const { |
79 DCHECK(!is_empty()); | 79 DCHECK(!is_empty()); |
80 return metadata()->GetKind(slot); | 80 return metadata()->GetKind(slot); |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 int TypeFeedbackVector::ic_with_type_info_count() { | |
85 return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0; | |
86 } | |
87 | |
88 | |
89 void TypeFeedbackVector::change_ic_with_type_info_count(int delta) { | |
90 if (delta == 0) return; | |
91 int value = ic_with_type_info_count() + delta; | |
92 // Could go negative because of the debugger. | |
93 if (value >= 0) { | |
94 set(kWithTypesIndex, Smi::FromInt(value)); | |
95 } | |
96 } | |
97 | |
98 | |
99 int TypeFeedbackVector::ic_generic_count() { | |
100 return length() > 0 ? Smi::cast(get(kGenericCountIndex))->value() : 0; | |
101 } | |
102 | |
103 | |
104 void TypeFeedbackVector::change_ic_generic_count(int delta) { | |
105 if (delta == 0) return; | |
106 int value = ic_generic_count() + delta; | |
107 if (value >= 0) { | |
108 set(kGenericCountIndex, Smi::FromInt(value)); | |
109 } | |
110 } | |
111 | |
112 | |
113 int TypeFeedbackVector::GetIndex(FeedbackVectorSlot slot) const { | 84 int TypeFeedbackVector::GetIndex(FeedbackVectorSlot slot) const { |
114 DCHECK(slot.ToInt() < slot_count()); | 85 DCHECK(slot.ToInt() < slot_count()); |
115 return kReservedIndexCount + slot.ToInt(); | 86 return kReservedIndexCount + slot.ToInt(); |
116 } | 87 } |
117 | 88 |
118 | 89 |
119 // Conversion from an integer index to either a slot or an ic slot. The caller | 90 // Conversion from an integer index to either a slot or an ic slot. The caller |
120 // should know what kind she expects. | 91 // should know what kind she expects. |
121 FeedbackVectorSlot TypeFeedbackVector::ToSlot(int index) const { | 92 FeedbackVectorSlot TypeFeedbackVector::ToSlot(int index) const { |
122 DCHECK(index >= kReservedIndexCount && index < length()); | 93 DCHECK(index >= kReservedIndexCount && index < length()); |
123 return FeedbackVectorSlot(index - kReservedIndexCount); | 94 return FeedbackVectorSlot(index - kReservedIndexCount); |
124 } | 95 } |
125 | 96 |
126 | 97 |
127 Object* TypeFeedbackVector::Get(FeedbackVectorSlot slot) const { | 98 Object* TypeFeedbackVector::Get(FeedbackVectorSlot slot) const { |
128 return get(GetIndex(slot)); | 99 return get(GetIndex(slot)); |
129 } | 100 } |
130 | 101 |
131 | 102 |
132 void TypeFeedbackVector::Set(FeedbackVectorSlot slot, Object* value, | 103 void TypeFeedbackVector::Set(FeedbackVectorSlot slot, Object* value, |
133 WriteBarrierMode mode) { | 104 WriteBarrierMode mode) { |
134 set(GetIndex(slot), value, mode); | 105 set(GetIndex(slot), value, mode); |
135 } | 106 } |
136 | 107 |
137 | 108 |
| 109 void TypeFeedbackVector::ComputeCounts(int* with_type_info, int* generic) { |
| 110 Object* uninitialized_sentinel = |
| 111 TypeFeedbackVector::RawUninitializedSentinel(GetIsolate()); |
| 112 Object* megamorphic_sentinel = |
| 113 *TypeFeedbackVector::MegamorphicSentinel(GetIsolate()); |
| 114 int with = 0; |
| 115 int gen = 0; |
| 116 TypeFeedbackMetadataIterator iter(metadata()); |
| 117 while (iter.HasNext()) { |
| 118 FeedbackVectorSlot slot = iter.Next(); |
| 119 FeedbackVectorSlotKind kind = iter.kind(); |
| 120 |
| 121 Object* obj = Get(slot); |
| 122 if (obj != uninitialized_sentinel && |
| 123 kind != FeedbackVectorSlotKind::GENERAL) { |
| 124 if (obj->IsWeakCell() || obj->IsFixedArray() || obj->IsString()) { |
| 125 with++; |
| 126 } else if (obj == megamorphic_sentinel) { |
| 127 gen++; |
| 128 } |
| 129 } |
| 130 } |
| 131 |
| 132 *with_type_info = with; |
| 133 *generic = gen; |
| 134 } |
| 135 |
| 136 |
138 Handle<Object> TypeFeedbackVector::UninitializedSentinel(Isolate* isolate) { | 137 Handle<Object> TypeFeedbackVector::UninitializedSentinel(Isolate* isolate) { |
139 return isolate->factory()->uninitialized_symbol(); | 138 return isolate->factory()->uninitialized_symbol(); |
140 } | 139 } |
141 | 140 |
142 | 141 |
143 Handle<Object> TypeFeedbackVector::MegamorphicSentinel(Isolate* isolate) { | 142 Handle<Object> TypeFeedbackVector::MegamorphicSentinel(Isolate* isolate) { |
144 return isolate->factory()->megamorphic_symbol(); | 143 return isolate->factory()->megamorphic_symbol(); |
145 } | 144 } |
146 | 145 |
147 | 146 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 int index = vector()->GetIndex(slot()) + 1; | 181 int index = vector()->GetIndex(slot()) + 1; |
183 vector()->set(index, feedback_extra, mode); | 182 vector()->set(index, feedback_extra, mode); |
184 } | 183 } |
185 | 184 |
186 | 185 |
187 Isolate* FeedbackNexus::GetIsolate() const { return vector()->GetIsolate(); } | 186 Isolate* FeedbackNexus::GetIsolate() const { return vector()->GetIsolate(); } |
188 } // namespace internal | 187 } // namespace internal |
189 } // namespace v8 | 188 } // namespace v8 |
190 | 189 |
191 #endif // V8_TYPE_FEEDBACK_VECTOR_INL_H_ | 190 #endif // V8_TYPE_FEEDBACK_VECTOR_INL_H_ |
OLD | NEW |