| 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/code-stubs.h" | 7 #include "src/code-stubs.h" |
| 8 #include "src/ic/ic.h" | 8 #include "src/ic/ic.h" |
| 9 #include "src/ic/ic-state.h" | 9 #include "src/ic/ic-state.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 void TypeFeedbackVector::SetKind(FeedbackVectorICSlot slot, Code::Kind kind) { | 72 void TypeFeedbackVector::SetKind(FeedbackVectorICSlot slot, Code::Kind kind) { |
| 73 VectorICKind b = FromCodeKind(kind); | 73 VectorICKind b = FromCodeKind(kind); |
| 74 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); | 74 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 75 int data = Smi::cast(get(index))->value(); | 75 int data = Smi::cast(get(index))->value(); |
| 76 int new_data = VectorICComputer::encode(data, slot.ToInt(), b); | 76 int new_data = VectorICComputer::encode(data, slot.ToInt(), b); |
| 77 set(index, Smi::FromInt(new_data)); | 77 set(index, Smi::FromInt(new_data)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 template Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate( | 81 template int TypeFeedbackVector::SizeFor(const FeedbackVectorSpec* spec); |
| 82 Isolate* isolate, const FeedbackVectorSpec* spec); | 82 template int TypeFeedbackVector::SizeFor(const ZoneFeedbackVectorSpec* spec); |
| 83 template Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate( | 83 template void TypeFeedbackVector::Init(Isolate* isolate, |
| 84 Isolate* isolate, const ZoneFeedbackVectorSpec* spec); | 84 const FeedbackVectorSpec* spec); |
| 85 template void TypeFeedbackVector::Init(Isolate* isolate, |
| 86 const ZoneFeedbackVectorSpec* spec); |
| 85 | 87 |
| 86 | 88 |
| 87 // static | 89 // static |
| 88 template <typename Spec> | 90 template <typename Spec> |
| 89 Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate(Isolate* isolate, | 91 int TypeFeedbackVector::SizeFor(const Spec* spec) { |
| 90 const Spec* spec) { | 92 const int slot_count = spec->slots(); |
| 93 const int ic_slot_count = spec->ic_slots(); |
| 94 // In this case, we'll use a sentinel, heap()->empty_feedback_vector(). |
| 95 if (slot_count == 0 && ic_slot_count == 0) { |
| 96 return TypeFeedbackVector::kHeaderSize; |
| 97 } |
| 98 const int index_count = VectorICComputer::word_count(ic_slot_count); |
| 99 const int length = slot_count + (ic_slot_count * elements_per_ic_slot()) + |
| 100 index_count + kReservedIndexCount; |
| 101 return length * kPointerSize + TypeFeedbackVector::kHeaderSize; |
| 102 } |
| 103 |
| 104 |
| 105 template <typename Spec> |
| 106 void TypeFeedbackVector::Init(Isolate* isolate, const Spec* spec) { |
| 91 const int slot_count = spec->slots(); | 107 const int slot_count = spec->slots(); |
| 92 const int ic_slot_count = spec->ic_slots(); | 108 const int ic_slot_count = spec->ic_slots(); |
| 93 const int index_count = VectorICComputer::word_count(ic_slot_count); | 109 const int index_count = VectorICComputer::word_count(ic_slot_count); |
| 94 const int length = slot_count + (ic_slot_count * elements_per_ic_slot()) + | 110 const int length = slot_count + (ic_slot_count * elements_per_ic_slot()) + |
| 95 index_count + kReservedIndexCount; | 111 index_count + kReservedIndexCount; |
| 96 if (length == kReservedIndexCount) { | 112 |
| 97 return Handle<TypeFeedbackVector>::cast( | 113 set_length(length); |
| 98 isolate->factory()->empty_fixed_array()); | 114 |
| 115 // We shouldn't create one of these if we don't have useful information to |
| 116 // store. |
| 117 DCHECK(slot_count > 0 || ic_slot_count > 0); |
| 118 |
| 119 if (ic_slot_count > 0) { |
| 120 set(kFirstICSlotIndex, |
| 121 Smi::FromInt(slot_count + index_count + kReservedIndexCount)); |
| 122 } else { |
| 123 set(kFirstICSlotIndex, Smi::FromInt(length)); |
| 99 } | 124 } |
| 100 | 125 set(kWithTypesIndex, Smi::FromInt(0)); |
| 101 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length, TENURED); | 126 set(kGenericCountIndex, Smi::FromInt(0)); |
| 102 if (ic_slot_count > 0) { | |
| 103 array->set(kFirstICSlotIndex, | |
| 104 Smi::FromInt(slot_count + index_count + kReservedIndexCount)); | |
| 105 } else { | |
| 106 array->set(kFirstICSlotIndex, Smi::FromInt(length)); | |
| 107 } | |
| 108 array->set(kWithTypesIndex, Smi::FromInt(0)); | |
| 109 array->set(kGenericCountIndex, Smi::FromInt(0)); | |
| 110 // Fill the indexes with zeros. | 127 // Fill the indexes with zeros. |
| 111 for (int i = 0; i < index_count; i++) { | 128 for (int i = 0; i < index_count; i++) { |
| 112 array->set(kReservedIndexCount + i, Smi::FromInt(0)); | 129 set(kReservedIndexCount + i, Smi::FromInt(0)); |
| 113 } | 130 } |
| 114 | 131 |
| 115 // Ensure we can skip the write barrier | 132 // Ensure we can skip the write barrier |
| 116 Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); | 133 Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); |
| 117 DCHECK_EQ(isolate->heap()->uninitialized_symbol(), *uninitialized_sentinel); | 134 DCHECK_EQ(isolate->heap()->uninitialized_symbol(), *uninitialized_sentinel); |
| 118 for (int i = kReservedIndexCount + index_count; i < length; i++) { | 135 for (int i = kReservedIndexCount + index_count; i < length; i++) { |
| 119 array->set(i, *uninitialized_sentinel, SKIP_WRITE_BARRIER); | 136 set(i, *uninitialized_sentinel, SKIP_WRITE_BARRIER); |
| 120 } | 137 } |
| 121 | 138 |
| 122 Handle<TypeFeedbackVector> vector = Handle<TypeFeedbackVector>::cast(array); | |
| 123 for (int i = 0; i < ic_slot_count; i++) { | 139 for (int i = 0; i < ic_slot_count; i++) { |
| 124 vector->SetKind(FeedbackVectorICSlot(i), spec->GetKind(i)); | 140 SetKind(FeedbackVectorICSlot(i), spec->GetKind(i)); |
| 125 } | 141 } |
| 126 return vector; | |
| 127 } | 142 } |
| 128 | 143 |
| 129 | 144 |
| 130 // static | 145 // static |
| 131 Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( | 146 Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( |
| 132 Isolate* isolate, Handle<TypeFeedbackVector> vector) { | 147 Isolate* isolate, Handle<TypeFeedbackVector> vector) { |
| 133 Handle<TypeFeedbackVector> result; | 148 Handle<TypeFeedbackVector> result = |
| 134 result = Handle<TypeFeedbackVector>::cast( | 149 isolate->factory()->CopyTypeFeedbackVector(vector); |
| 135 isolate->factory()->CopyFixedArray(Handle<FixedArray>::cast(vector))); | |
| 136 return result; | 150 return result; |
| 137 } | 151 } |
| 138 | 152 |
| 139 | 153 |
| 140 bool TypeFeedbackVector::SpecDiffersFrom( | 154 bool TypeFeedbackVector::SpecDiffersFrom( |
| 141 const ZoneFeedbackVectorSpec* other_spec) const { | 155 const ZoneFeedbackVectorSpec* other_spec) const { |
| 142 if (other_spec->slots() != Slots() || other_spec->ic_slots() != ICSlots()) { | 156 if (other_spec->slots() != Slots() || other_spec->ic_slots() != ICSlots()) { |
| 143 return true; | 157 return true; |
| 144 } | 158 } |
| 145 | 159 |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 void StoreICNexus::Clear(Code* host) { | 693 void StoreICNexus::Clear(Code* host) { |
| 680 StoreIC::Clear(GetIsolate(), host, this); | 694 StoreIC::Clear(GetIsolate(), host, this); |
| 681 } | 695 } |
| 682 | 696 |
| 683 | 697 |
| 684 void KeyedStoreICNexus::Clear(Code* host) { | 698 void KeyedStoreICNexus::Clear(Code* host) { |
| 685 KeyedStoreIC::Clear(GetIsolate(), host, this); | 699 KeyedStoreIC::Clear(GetIsolate(), host, this); |
| 686 } | 700 } |
| 687 } // namespace internal | 701 } // namespace internal |
| 688 } // namespace v8 | 702 } // namespace v8 |
| OLD | NEW |