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

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

Issue 1384673002: The metadata part of TypeFeedbackVector is extracted to TypeFeedbackMetadata array. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Cleanup Created 5 years, 2 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 | « src/type-feedback-vector.cc ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('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 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 {
11 namespace internal { 11 namespace internal {
12 12
13 13
14 template <typename Derived> 14 template <typename Derived>
15 FeedbackVectorSlot FeedbackVectorSpecBase<Derived>::AddSlot( 15 FeedbackVectorSlot FeedbackVectorSpecBase<Derived>::AddSlot(
16 FeedbackVectorSlotKind kind) { 16 FeedbackVectorSlotKind kind) {
17 Derived* derived = static_cast<Derived*>(this); 17 Derived* derived = static_cast<Derived*>(this);
18 18
19 int slot = derived->slots(); 19 int slot = derived->slots();
20 int entries_per_slot = TypeFeedbackVector::GetSlotSize(kind); 20 int entries_per_slot = TypeFeedbackMetadata::GetSlotSize(kind);
21 derived->append(kind); 21 derived->append(kind);
22 for (int i = 1; i < entries_per_slot; i++) { 22 for (int i = 1; i < entries_per_slot; i++) {
23 derived->append(FeedbackVectorSlotKind::INVALID); 23 derived->append(FeedbackVectorSlotKind::INVALID);
24 } 24 }
25 return FeedbackVectorSlot(slot); 25 return FeedbackVectorSlot(slot);
26 } 26 }
27 27
28 28
29 // static 29 // static
30 TypeFeedbackMetadata* TypeFeedbackMetadata::cast(Object* obj) {
31 DCHECK(obj->IsTypeFeedbackVector());
32 return reinterpret_cast<TypeFeedbackMetadata*>(obj);
33 }
34
35
36 int TypeFeedbackMetadata::slot_count() const {
37 if (length() == 0) return 0;
38 DCHECK(length() > kReservedIndexCount);
39 return Smi::cast(get(kSlotsCountIndex))->value();
40 }
41
42
43 // static
30 TypeFeedbackVector* TypeFeedbackVector::cast(Object* obj) { 44 TypeFeedbackVector* TypeFeedbackVector::cast(Object* obj) {
31 DCHECK(obj->IsTypeFeedbackVector()); 45 DCHECK(obj->IsTypeFeedbackVector());
32 return reinterpret_cast<TypeFeedbackVector*>(obj); 46 return reinterpret_cast<TypeFeedbackVector*>(obj);
33 } 47 }
34 48
35 49
36 int TypeFeedbackVector::GetSlotSize(FeedbackVectorSlotKind kind) { 50 int TypeFeedbackMetadata::GetSlotSize(FeedbackVectorSlotKind kind) {
37 DCHECK_NE(FeedbackVectorSlotKind::INVALID, kind); 51 DCHECK_NE(FeedbackVectorSlotKind::INVALID, kind);
38 DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, kind); 52 DCHECK_NE(FeedbackVectorSlotKind::KINDS_NUMBER, kind);
39 return kind == FeedbackVectorSlotKind::GENERAL ? 1 : 2; 53 return kind == FeedbackVectorSlotKind::GENERAL ? 1 : 2;
40 } 54 }
41 55
42 56
43 bool TypeFeedbackVector::is_empty() const { 57 bool TypeFeedbackVector::is_empty() const {
44 if (length() == 0) return true; 58 if (length() == 0) return true;
45 DCHECK(length() >= kReservedIndexCount); 59 DCHECK(length() > kReservedIndexCount);
46 return false; 60 return false;
47 } 61 }
48 62
49 63
50 int TypeFeedbackVector::Slots() const { 64 int TypeFeedbackVector::slot_count() const {
51 if (length() == 0) return 0; 65 if (length() == 0) return 0;
52 DCHECK(length() >= kReservedIndexCount); 66 DCHECK(length() > kReservedIndexCount);
53 return Smi::cast(get(kSlotsCountIndex))->value(); 67 return length() - kReservedIndexCount;
54 } 68 }
55 69
56 70
71 TypeFeedbackMetadata* TypeFeedbackVector::metadata() const {
72 return is_empty() ? TypeFeedbackMetadata::cast(GetHeap()->empty_fixed_array())
73 : TypeFeedbackMetadata::cast(get(kMetadataIndex));
74 }
75
76
77 FeedbackVectorSlotKind TypeFeedbackVector::GetKind(
78 FeedbackVectorSlot slot) const {
79 DCHECK(!is_empty());
80 return metadata()->GetKind(slot);
81 }
82
83
57 int TypeFeedbackVector::ic_with_type_info_count() { 84 int TypeFeedbackVector::ic_with_type_info_count() {
58 return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0; 85 return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0;
59 } 86 }
60 87
61 88
62 void TypeFeedbackVector::change_ic_with_type_info_count(int delta) { 89 void TypeFeedbackVector::change_ic_with_type_info_count(int delta) {
63 if (delta == 0) return; 90 if (delta == 0) return;
64 int value = ic_with_type_info_count() + delta; 91 int value = ic_with_type_info_count() + delta;
65 // Could go negative because of the debugger. 92 // Could go negative because of the debugger.
66 if (value >= 0) { 93 if (value >= 0) {
67 set(kWithTypesIndex, Smi::FromInt(value)); 94 set(kWithTypesIndex, Smi::FromInt(value));
68 } 95 }
69 } 96 }
70 97
71 98
72 int TypeFeedbackVector::ic_generic_count() { 99 int TypeFeedbackVector::ic_generic_count() {
73 return length() > 0 ? Smi::cast(get(kGenericCountIndex))->value() : 0; 100 return length() > 0 ? Smi::cast(get(kGenericCountIndex))->value() : 0;
74 } 101 }
75 102
76 103
77 void TypeFeedbackVector::change_ic_generic_count(int delta) { 104 void TypeFeedbackVector::change_ic_generic_count(int delta) {
78 if (delta == 0) return; 105 if (delta == 0) return;
79 int value = ic_generic_count() + delta; 106 int value = ic_generic_count() + delta;
80 if (value >= 0) { 107 if (value >= 0) {
81 set(kGenericCountIndex, Smi::FromInt(value)); 108 set(kGenericCountIndex, Smi::FromInt(value));
82 } 109 }
83 } 110 }
84 111
85 112
86 int TypeFeedbackVector::ic_metadata_length() const {
87 return VectorICComputer::word_count(Slots());
88 }
89
90
91 int TypeFeedbackVector::GetIndex(FeedbackVectorSlot slot) const { 113 int TypeFeedbackVector::GetIndex(FeedbackVectorSlot slot) const {
92 DCHECK(slot.ToInt() < Slots()); 114 DCHECK(slot.ToInt() < slot_count());
93 return kReservedIndexCount + ic_metadata_length() + slot.ToInt(); 115 return kReservedIndexCount + slot.ToInt();
94 } 116 }
95 117
96 118
97 // Conversion from an integer index to either a slot or an ic slot. The caller 119 // Conversion from an integer index to either a slot or an ic slot. The caller
98 // should know what kind she expects. 120 // should know what kind she expects.
99 FeedbackVectorSlot TypeFeedbackVector::ToSlot(int index) const { 121 FeedbackVectorSlot TypeFeedbackVector::ToSlot(int index) const {
100 DCHECK(index >= kReservedIndexCount + ic_metadata_length() && 122 DCHECK(index >= kReservedIndexCount && index < length());
101 index < length()); 123 return FeedbackVectorSlot(index - kReservedIndexCount);
102 return FeedbackVectorSlot(index - ic_metadata_length() - kReservedIndexCount);
103 } 124 }
104 125
105 126
106 Object* TypeFeedbackVector::Get(FeedbackVectorSlot slot) const { 127 Object* TypeFeedbackVector::Get(FeedbackVectorSlot slot) const {
107 return get(GetIndex(slot)); 128 return get(GetIndex(slot));
108 } 129 }
109 130
110 131
111 void TypeFeedbackVector::Set(FeedbackVectorSlot slot, Object* value, 132 void TypeFeedbackVector::Set(FeedbackVectorSlot slot, Object* value,
112 WriteBarrierMode mode) { 133 WriteBarrierMode mode) {
(...skipping 20 matching lines...) Expand all
133 return isolate->heap()->uninitialized_symbol(); 154 return isolate->heap()->uninitialized_symbol();
134 } 155 }
135 156
136 157
137 Object* FeedbackNexus::GetFeedback() const { return vector()->Get(slot()); } 158 Object* FeedbackNexus::GetFeedback() const { return vector()->Get(slot()); }
138 159
139 160
140 Object* FeedbackNexus::GetFeedbackExtra() const { 161 Object* FeedbackNexus::GetFeedbackExtra() const {
141 #ifdef DEBUG 162 #ifdef DEBUG
142 FeedbackVectorSlotKind kind = vector()->GetKind(slot()); 163 FeedbackVectorSlotKind kind = vector()->GetKind(slot());
143 DCHECK_LT(1, TypeFeedbackVector::GetSlotSize(kind)); 164 DCHECK_LT(1, TypeFeedbackMetadata::GetSlotSize(kind));
144 #endif 165 #endif
145 int extra_index = vector()->GetIndex(slot()) + 1; 166 int extra_index = vector()->GetIndex(slot()) + 1;
146 return vector()->get(extra_index); 167 return vector()->get(extra_index);
147 } 168 }
148 169
149 170
150 void FeedbackNexus::SetFeedback(Object* feedback, WriteBarrierMode mode) { 171 void FeedbackNexus::SetFeedback(Object* feedback, WriteBarrierMode mode) {
151 vector()->Set(slot(), feedback, mode); 172 vector()->Set(slot(), feedback, mode);
152 } 173 }
153 174
154 175
155 void FeedbackNexus::SetFeedbackExtra(Object* feedback_extra, 176 void FeedbackNexus::SetFeedbackExtra(Object* feedback_extra,
156 WriteBarrierMode mode) { 177 WriteBarrierMode mode) {
157 #ifdef DEBUG 178 #ifdef DEBUG
158 FeedbackVectorSlotKind kind = vector()->GetKind(slot()); 179 FeedbackVectorSlotKind kind = vector()->GetKind(slot());
159 DCHECK_LT(1, TypeFeedbackVector::GetSlotSize(kind)); 180 DCHECK_LT(1, TypeFeedbackMetadata::GetSlotSize(kind));
160 #endif 181 #endif
161 int index = vector()->GetIndex(slot()) + 1; 182 int index = vector()->GetIndex(slot()) + 1;
162 vector()->set(index, feedback_extra, mode); 183 vector()->set(index, feedback_extra, mode);
163 } 184 }
164 185
165 186
166 Isolate* FeedbackNexus::GetIsolate() const { return vector()->GetIsolate(); } 187 Isolate* FeedbackNexus::GetIsolate() const { return vector()->GetIsolate(); }
167 } // namespace internal 188 } // namespace internal
168 } // namespace v8 189 } // namespace v8
169 190
170 #endif // V8_TYPE_FEEDBACK_VECTOR_INL_H_ 191 #endif // V8_TYPE_FEEDBACK_VECTOR_INL_H_
OLDNEW
« no previous file with comments | « src/type-feedback-vector.cc ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698