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 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
| 13 // static |
| 14 TypeFeedbackVector* TypeFeedbackVector::cast(Object* obj) { |
| 15 DCHECK(obj->IsTypeFeedbackVector()); |
| 16 return reinterpret_cast<TypeFeedbackVector*>(obj); |
| 17 } |
| 18 |
| 19 |
| 20 int TypeFeedbackVector::first_ic_slot_index() const { |
| 21 DCHECK(length() >= kReservedIndexCount); |
| 22 return Smi::cast(get(kFirstICSlotIndex))->value(); |
| 23 } |
| 24 |
| 25 |
| 26 int TypeFeedbackVector::ic_with_type_info_count() { |
| 27 return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0; |
| 28 } |
| 29 |
| 30 |
| 31 void TypeFeedbackVector::change_ic_with_type_info_count(int delta) { |
| 32 if (delta == 0) return; |
| 33 int value = ic_with_type_info_count() + delta; |
| 34 // Could go negative because of the debugger. |
| 35 if (value >= 0) { |
| 36 set(kWithTypesIndex, Smi::FromInt(value)); |
| 37 } |
| 38 } |
| 39 |
| 40 |
| 41 int TypeFeedbackVector::ic_generic_count() { |
| 42 return length() > 0 ? Smi::cast(get(kGenericCountIndex))->value() : 0; |
| 43 } |
| 44 |
| 45 |
| 46 void TypeFeedbackVector::change_ic_generic_count(int delta) { |
| 47 if (delta == 0) return; |
| 48 int value = ic_generic_count() + delta; |
| 49 if (value >= 0) { |
| 50 set(kGenericCountIndex, Smi::FromInt(value)); |
| 51 } |
| 52 } |
| 53 |
| 54 |
| 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 |
13 int TypeFeedbackVector::ic_metadata_length() const { | 68 int TypeFeedbackVector::ic_metadata_length() const { |
14 return VectorICComputer::word_count(ICSlots()); | 69 return VectorICComputer::word_count(ICSlots()); |
15 } | 70 } |
16 | 71 |
17 | 72 |
| 73 // Conversion from a slot or ic slot to an integer index to the underlying |
| 74 // array. |
| 75 int TypeFeedbackVector::GetIndex(FeedbackVectorSlot slot) const { |
| 76 DCHECK(slot.ToInt() < first_ic_slot_index()); |
| 77 return kReservedIndexCount + ic_metadata_length() + slot.ToInt(); |
| 78 } |
| 79 |
| 80 |
| 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 |
| 89 // should know what kind she expects. |
| 90 FeedbackVectorSlot TypeFeedbackVector::ToSlot(int index) const { |
| 91 DCHECK(index >= kReservedIndexCount && index < first_ic_slot_index()); |
| 92 return FeedbackVectorSlot(index - ic_metadata_length() - kReservedIndexCount); |
| 93 } |
| 94 |
| 95 |
| 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 { |
| 104 return get(GetIndex(slot)); |
| 105 } |
| 106 |
| 107 |
| 108 void TypeFeedbackVector::Set(FeedbackVectorSlot slot, Object* value, |
| 109 WriteBarrierMode mode) { |
| 110 set(GetIndex(slot), value, mode); |
| 111 } |
| 112 |
| 113 |
| 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 |
18 Handle<Object> TypeFeedbackVector::UninitializedSentinel(Isolate* isolate) { | 125 Handle<Object> TypeFeedbackVector::UninitializedSentinel(Isolate* isolate) { |
19 return isolate->factory()->uninitialized_symbol(); | 126 return isolate->factory()->uninitialized_symbol(); |
20 } | 127 } |
21 | 128 |
22 | 129 |
23 Handle<Object> TypeFeedbackVector::MegamorphicSentinel(Isolate* isolate) { | 130 Handle<Object> TypeFeedbackVector::MegamorphicSentinel(Isolate* isolate) { |
24 return isolate->factory()->megamorphic_symbol(); | 131 return isolate->factory()->megamorphic_symbol(); |
25 } | 132 } |
26 | 133 |
27 | 134 |
28 Handle<Object> TypeFeedbackVector::PremonomorphicSentinel(Isolate* isolate) { | 135 Handle<Object> TypeFeedbackVector::PremonomorphicSentinel(Isolate* isolate) { |
29 return isolate->factory()->premonomorphic_symbol(); | 136 return isolate->factory()->premonomorphic_symbol(); |
30 } | 137 } |
31 | 138 |
32 | 139 |
33 Object* TypeFeedbackVector::RawUninitializedSentinel(Heap* heap) { | 140 Object* TypeFeedbackVector::RawUninitializedSentinel(Heap* heap) { |
34 return heap->uninitialized_symbol(); | 141 return heap->uninitialized_symbol(); |
35 } | 142 } |
| 143 |
| 144 |
| 145 Object* FeedbackNexus::GetFeedback() const { return vector()->Get(slot()); } |
| 146 |
| 147 |
| 148 Object* FeedbackNexus::GetFeedbackExtra() const { |
| 149 DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1); |
| 150 int extra_index = vector()->GetIndex(slot()) + 1; |
| 151 return vector()->get(extra_index); |
| 152 } |
| 153 |
| 154 |
| 155 void FeedbackNexus::SetFeedback(Object* feedback, WriteBarrierMode mode) { |
| 156 vector()->Set(slot(), feedback, mode); |
| 157 } |
| 158 |
| 159 |
| 160 void FeedbackNexus::SetFeedbackExtra(Object* feedback_extra, |
| 161 WriteBarrierMode mode) { |
| 162 DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1); |
| 163 int index = vector()->GetIndex(slot()) + 1; |
| 164 vector()->set(index, feedback_extra, mode); |
| 165 } |
| 166 |
| 167 |
| 168 Isolate* FeedbackNexus::GetIsolate() const { return vector()->GetIsolate(); } |
36 } | 169 } |
37 } // namespace v8::internal | 170 } // namespace v8::internal |
38 | 171 |
39 #endif // V8_TYPE_FEEDBACK_VECTOR_INL_H_ | 172 #endif // V8_TYPE_FEEDBACK_VECTOR_INL_H_ |
OLD | NEW |