| 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/type-feedback-vector.h" | 5 #include "src/type-feedback-vector.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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 FeedbackVectorSlotKind TypeFeedbackMetadata::GetKind( | 33 FeedbackVectorSlotKind TypeFeedbackMetadata::GetKind( |
| 34 FeedbackVectorSlot slot) const { | 34 FeedbackVectorSlot slot) const { |
| 35 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); | 35 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 36 int data = Smi::cast(get(index))->value(); | 36 int data = Smi::cast(get(index))->value(); |
| 37 return VectorICComputer::decode(data, slot.ToInt()); | 37 return VectorICComputer::decode(data, slot.ToInt()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 String* TypeFeedbackMetadata::GetName(FeedbackVectorSlot slot) const { | 40 String* TypeFeedbackMetadata::GetName(FeedbackVectorSlot slot) const { |
| 41 DCHECK(SlotRequiresName(GetKind(slot))); | 41 DCHECK(SlotRequiresName(GetKind(slot))); |
| 42 FixedArray* names = FixedArray::cast(get(kNamesTableIndex)); | 42 UnseededNumberDictionary* names = |
| 43 // TODO(ishell): consider using binary search here or even Dictionary when we | 43 UnseededNumberDictionary::cast(get(kNamesTableIndex)); |
| 44 // have more ICs with names. | 44 int entry = names->FindEntry(GetIsolate(), slot.ToInt()); |
| 45 Smi* key = Smi::FromInt(slot.ToInt()); | 45 CHECK_NE(UnseededNumberDictionary::kNotFound, entry); |
| 46 for (int entry = 0; entry < names->length(); entry += kNameTableEntrySize) { | 46 Object* name = names->ValueAt(entry); |
| 47 Object* current_key = names->get(entry + kNameTableSlotIndex); | 47 DCHECK(name->IsString()); |
| 48 if (current_key == key) { | 48 return String::cast(name); |
| 49 Object* name = names->get(entry + kNameTableNameIndex); | |
| 50 DCHECK(name->IsString()); | |
| 51 return String::cast(name); | |
| 52 } | |
| 53 } | |
| 54 UNREACHABLE(); | |
| 55 return nullptr; | |
| 56 } | 49 } |
| 57 | 50 |
| 58 void TypeFeedbackMetadata::SetKind(FeedbackVectorSlot slot, | 51 void TypeFeedbackMetadata::SetKind(FeedbackVectorSlot slot, |
| 59 FeedbackVectorSlotKind kind) { | 52 FeedbackVectorSlotKind kind) { |
| 60 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); | 53 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 61 int data = Smi::cast(get(index))->value(); | 54 int data = Smi::cast(get(index))->value(); |
| 62 int new_data = VectorICComputer::encode(data, slot.ToInt(), kind); | 55 int new_data = VectorICComputer::encode(data, slot.ToInt(), kind); |
| 63 set(index, Smi::FromInt(new_data)); | 56 set(index, Smi::FromInt(new_data)); |
| 64 } | 57 } |
| 65 | 58 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 for (int i = 0; i < slot_kinds_length; i++) { | 93 for (int i = 0; i < slot_kinds_length; i++) { |
| 101 array->set(kReservedIndexCount + i, Smi::FromInt(0)); | 94 array->set(kReservedIndexCount + i, Smi::FromInt(0)); |
| 102 } | 95 } |
| 103 | 96 |
| 104 Handle<TypeFeedbackMetadata> metadata = | 97 Handle<TypeFeedbackMetadata> metadata = |
| 105 Handle<TypeFeedbackMetadata>::cast(array); | 98 Handle<TypeFeedbackMetadata>::cast(array); |
| 106 | 99 |
| 107 // Add names to NamesTable. | 100 // Add names to NamesTable. |
| 108 const int name_count = spec->name_count(); | 101 const int name_count = spec->name_count(); |
| 109 | 102 |
| 110 Handle<FixedArray> names = | 103 Handle<UnseededNumberDictionary> names = |
| 111 name_count == 0 | 104 UnseededNumberDictionary::New(isolate, name_count); |
| 112 ? factory->empty_fixed_array() | 105 |
| 113 : factory->NewFixedArray(name_count * kNameTableEntrySize); | |
| 114 int name_index = 0; | 106 int name_index = 0; |
| 115 for (int i = 0; i < slot_count; i++) { | 107 for (int i = 0; i < slot_count; i++) { |
| 116 FeedbackVectorSlotKind kind = spec->GetKind(i); | 108 FeedbackVectorSlotKind kind = spec->GetKind(i); |
| 117 metadata->SetKind(FeedbackVectorSlot(i), kind); | 109 metadata->SetKind(FeedbackVectorSlot(i), kind); |
| 118 if (SlotRequiresName(kind)) { | 110 if (SlotRequiresName(kind)) { |
| 119 Handle<String> name = spec->GetName(name_index); | 111 Handle<String> name = spec->GetName(name_index); |
| 120 DCHECK(!name.is_null()); | 112 DCHECK(!name.is_null()); |
| 121 int entry = name_index * kNameTableEntrySize; | 113 names = UnseededNumberDictionary::AtNumberPut(names, i, name); |
| 122 names->set(entry + kNameTableSlotIndex, Smi::FromInt(i)); | |
| 123 names->set(entry + kNameTableNameIndex, *name); | |
| 124 name_index++; | 114 name_index++; |
| 125 } | 115 } |
| 126 } | 116 } |
| 127 DCHECK_EQ(name_count, name_index); | 117 DCHECK_EQ(name_count, name_index); |
| 128 metadata->set(kNamesTableIndex, *names); | 118 metadata->set(kNamesTableIndex, *names); |
| 129 | 119 |
| 130 // It's important that the TypeFeedbackMetadata have a COW map, since it's | 120 // It's important that the TypeFeedbackMetadata have a COW map, since it's |
| 131 // pointed to by both a SharedFunctionInfo and indirectly by closures through | 121 // pointed to by both a SharedFunctionInfo and indirectly by closures through |
| 132 // the TypeFeedbackVector. The serializer uses the COW map type to decide | 122 // the TypeFeedbackVector. The serializer uses the COW map type to decide |
| 133 // this object belongs in the startup snapshot and not the partial | 123 // this object belongs in the startup snapshot and not the partial |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 | 1009 |
| 1020 IcCheckType KeyedStoreICNexus::GetKeyType() const { | 1010 IcCheckType KeyedStoreICNexus::GetKeyType() const { |
| 1021 Object* feedback = GetFeedback(); | 1011 Object* feedback = GetFeedback(); |
| 1022 if (feedback == *TypeFeedbackVector::MegamorphicSentinel(GetIsolate())) { | 1012 if (feedback == *TypeFeedbackVector::MegamorphicSentinel(GetIsolate())) { |
| 1023 return static_cast<IcCheckType>(Smi::cast(GetFeedbackExtra())->value()); | 1013 return static_cast<IcCheckType>(Smi::cast(GetFeedbackExtra())->value()); |
| 1024 } | 1014 } |
| 1025 return IsPropertyNameFeedback(feedback) ? PROPERTY : ELEMENT; | 1015 return IsPropertyNameFeedback(feedback) ? PROPERTY : ELEMENT; |
| 1026 } | 1016 } |
| 1027 } // namespace internal | 1017 } // namespace internal |
| 1028 } // namespace v8 | 1018 } // namespace v8 |
| OLD | NEW |