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