| OLD | NEW |
| 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 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/ic/ic-state.h" | 7 #include "src/ic/ic-state.h" |
| 8 #include "src/objects.h" | 8 #include "src/objects.h" |
| 9 #include "src/type-feedback-vector-inl.h" | 9 #include "src/type-feedback-vector-inl.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 TypeFeedbackVector::VectorICKind TypeFeedbackVector::FromCodeKind( |
| 16 Code::Kind kind) { |
| 17 switch (kind) { |
| 18 case Code::CALL_IC: |
| 19 return KindCallIC; |
| 20 case Code::LOAD_IC: |
| 21 return KindLoadIC; |
| 22 case Code::KEYED_LOAD_IC: |
| 23 return KindKeyedLoadIC; |
| 24 default: |
| 25 // Shouldn't get here. |
| 26 UNREACHABLE(); |
| 27 } |
| 28 |
| 29 return KindUnused; |
| 30 } |
| 31 |
| 32 |
| 33 // static |
| 34 Code::Kind TypeFeedbackVector::FromVectorICKind(VectorICKind kind) { |
| 35 switch (kind) { |
| 36 case KindCallIC: |
| 37 return Code::CALL_IC; |
| 38 case KindLoadIC: |
| 39 return Code::LOAD_IC; |
| 40 case KindKeyedLoadIC: |
| 41 return Code::KEYED_LOAD_IC; |
| 42 case KindUnused: |
| 43 break; |
| 44 } |
| 45 // Sentinel for no information. |
| 46 return Code::NUMBER_OF_KINDS; |
| 47 } |
| 48 |
| 49 |
| 50 Code::Kind TypeFeedbackVector::GetKind(FeedbackVectorICSlot slot) const { |
| 51 if (!FLAG_vector_ics) { |
| 52 // We only have CALL_ICs |
| 53 return Code::CALL_IC; |
| 54 } |
| 55 |
| 56 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 57 int data = Smi::cast(get(index))->value(); |
| 58 VectorICKind b = VectorICComputer::decode(data, slot.ToInt()); |
| 59 return FromVectorICKind(b); |
| 60 } |
| 61 |
| 62 |
| 63 void TypeFeedbackVector::SetKind(FeedbackVectorICSlot slot, Code::Kind kind) { |
| 64 if (!FLAG_vector_ics) { |
| 65 // Nothing to do if we only have CALL_ICs |
| 66 return; |
| 67 } |
| 68 |
| 69 VectorICKind b = FromCodeKind(kind); |
| 70 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 71 int data = Smi::cast(get(index))->value(); |
| 72 int new_data = VectorICComputer::encode(data, slot.ToInt(), b); |
| 73 set(index, Smi::FromInt(new_data)); |
| 74 } |
| 75 |
| 76 |
| 77 // static |
| 15 Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate(Isolate* isolate, | 78 Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate(Isolate* isolate, |
| 16 int slot_count, | 79 int slot_count, |
| 17 int ic_slot_count) { | 80 int ic_slot_count) { |
| 18 int length = slot_count + ic_slot_count + kReservedIndexCount; | 81 int index_count = |
| 82 FLAG_vector_ics ? VectorICComputer::word_count(ic_slot_count) : 0; |
| 83 int length = slot_count + ic_slot_count + index_count + kReservedIndexCount; |
| 19 if (length == kReservedIndexCount) { | 84 if (length == kReservedIndexCount) { |
| 20 return Handle<TypeFeedbackVector>::cast( | 85 return Handle<TypeFeedbackVector>::cast( |
| 21 isolate->factory()->empty_fixed_array()); | 86 isolate->factory()->empty_fixed_array()); |
| 22 } | 87 } |
| 23 | 88 |
| 24 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length, TENURED); | 89 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length, TENURED); |
| 25 if (ic_slot_count > 0) { | 90 if (ic_slot_count > 0) { |
| 26 array->set(kFirstICSlotIndex, | 91 array->set(kFirstICSlotIndex, |
| 27 Smi::FromInt(slot_count + kReservedIndexCount)); | 92 Smi::FromInt(slot_count + index_count + kReservedIndexCount)); |
| 28 } else { | 93 } else { |
| 29 array->set(kFirstICSlotIndex, Smi::FromInt(length)); | 94 array->set(kFirstICSlotIndex, Smi::FromInt(length)); |
| 30 } | 95 } |
| 31 array->set(kWithTypesIndex, Smi::FromInt(0)); | 96 array->set(kWithTypesIndex, Smi::FromInt(0)); |
| 32 array->set(kGenericCountIndex, Smi::FromInt(0)); | 97 array->set(kGenericCountIndex, Smi::FromInt(0)); |
| 98 // Fill the indexes with zeros. |
| 99 for (int i = 0; i < index_count; i++) { |
| 100 array->set(kReservedIndexCount + i, Smi::FromInt(0)); |
| 101 } |
| 33 | 102 |
| 34 // Ensure we can skip the write barrier | 103 // Ensure we can skip the write barrier |
| 35 Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); | 104 Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); |
| 36 DCHECK_EQ(isolate->heap()->uninitialized_symbol(), *uninitialized_sentinel); | 105 DCHECK_EQ(isolate->heap()->uninitialized_symbol(), *uninitialized_sentinel); |
| 37 for (int i = kReservedIndexCount; i < length; i++) { | 106 for (int i = kReservedIndexCount + index_count; i < length; i++) { |
| 38 array->set(i, *uninitialized_sentinel, SKIP_WRITE_BARRIER); | 107 array->set(i, *uninitialized_sentinel, SKIP_WRITE_BARRIER); |
| 39 } | 108 } |
| 40 return Handle<TypeFeedbackVector>::cast(array); | 109 return Handle<TypeFeedbackVector>::cast(array); |
| 41 } | 110 } |
| 42 | 111 |
| 43 | 112 |
| 44 // static | 113 // static |
| 45 Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( | 114 Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( |
| 46 Isolate* isolate, Handle<TypeFeedbackVector> vector) { | 115 Isolate* isolate, Handle<TypeFeedbackVector> vector) { |
| 47 Handle<TypeFeedbackVector> result; | 116 Handle<TypeFeedbackVector> result; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 for (int i = 0; i < slots; i++) { | 150 for (int i = 0; i < slots; i++) { |
| 82 FeedbackVectorICSlot slot(i); | 151 FeedbackVectorICSlot slot(i); |
| 83 Object* obj = Get(slot); | 152 Object* obj = Get(slot); |
| 84 if (obj != uninitialized_sentinel) { | 153 if (obj != uninitialized_sentinel) { |
| 85 ICUtility::Clear(isolate, Code::CALL_IC, host, this, slot); | 154 ICUtility::Clear(isolate, Code::CALL_IC, host, this, slot); |
| 86 } | 155 } |
| 87 } | 156 } |
| 88 } | 157 } |
| 89 } | 158 } |
| 90 } // namespace v8::internal | 159 } // namespace v8::internal |
| OLD | NEW |