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

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

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

Powered by Google App Engine
This is Rietveld 408576698