| 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" |
| 11 #include "src/type-feedback-vector-inl.h" | 11 #include "src/type-feedback-vector-inl.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 // static | 16 std::ostream& operator<<(std::ostream& os, FeedbackVectorSlotKind kind) { |
| 17 TypeFeedbackVector::VectorICKind TypeFeedbackVector::FromCodeKind( | 17 return os << TypeFeedbackVector::Kind2String(kind); |
| 18 Code::Kind kind) { | |
| 19 switch (kind) { | |
| 20 case Code::CALL_IC: | |
| 21 return KindCallIC; | |
| 22 case Code::LOAD_IC: | |
| 23 return KindLoadIC; | |
| 24 case Code::KEYED_LOAD_IC: | |
| 25 return KindKeyedLoadIC; | |
| 26 case Code::STORE_IC: | |
| 27 return KindStoreIC; | |
| 28 case Code::KEYED_STORE_IC: | |
| 29 return KindKeyedStoreIC; | |
| 30 default: | |
| 31 // Shouldn't get here. | |
| 32 UNREACHABLE(); | |
| 33 } | |
| 34 | |
| 35 return KindUnused; | |
| 36 } | 18 } |
| 37 | 19 |
| 38 | 20 |
| 39 // static | 21 FeedbackVectorSlotKind TypeFeedbackVector::GetKind( |
| 40 Code::Kind TypeFeedbackVector::FromVectorICKind(VectorICKind kind) { | 22 FeedbackVectorICSlot slot) const { |
| 41 switch (kind) { | 23 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 42 case KindCallIC: | 24 int data = Smi::cast(get(index))->value(); |
| 43 return Code::CALL_IC; | 25 return VectorICComputer::decode(data, slot.ToInt()); |
| 44 case KindLoadIC: | |
| 45 return Code::LOAD_IC; | |
| 46 case KindKeyedLoadIC: | |
| 47 return Code::KEYED_LOAD_IC; | |
| 48 case KindStoreIC: | |
| 49 DCHECK(FLAG_vector_stores); | |
| 50 return Code::STORE_IC; | |
| 51 case KindKeyedStoreIC: | |
| 52 DCHECK(FLAG_vector_stores); | |
| 53 return Code::KEYED_STORE_IC; | |
| 54 case KindUnused: | |
| 55 break; | |
| 56 } | |
| 57 // Sentinel for no information. | |
| 58 return Code::NUMBER_OF_KINDS; | |
| 59 } | 26 } |
| 60 | 27 |
| 61 | 28 |
| 62 Code::Kind TypeFeedbackVector::GetKind(FeedbackVectorICSlot slot) const { | 29 void TypeFeedbackVector::SetKind(FeedbackVectorICSlot slot, |
| 30 FeedbackVectorSlotKind kind) { |
| 63 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); | 31 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 64 int data = Smi::cast(get(index))->value(); | 32 int data = Smi::cast(get(index))->value(); |
| 65 VectorICKind b = VectorICComputer::decode(data, slot.ToInt()); | 33 int new_data = VectorICComputer::encode(data, slot.ToInt(), kind); |
| 66 return FromVectorICKind(b); | |
| 67 } | |
| 68 | |
| 69 | |
| 70 void TypeFeedbackVector::SetKind(FeedbackVectorICSlot slot, Code::Kind kind) { | |
| 71 VectorICKind b = FromCodeKind(kind); | |
| 72 int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); | |
| 73 int data = Smi::cast(get(index))->value(); | |
| 74 int new_data = VectorICComputer::encode(data, slot.ToInt(), b); | |
| 75 set(index, Smi::FromInt(new_data)); | 34 set(index, Smi::FromInt(new_data)); |
| 76 } | 35 } |
| 77 | 36 |
| 78 | 37 |
| 79 template Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate( | 38 template Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate( |
| 80 Isolate* isolate, const FeedbackVectorSpec* spec); | 39 Isolate* isolate, const FeedbackVectorSpec* spec); |
| 81 template Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate( | 40 template Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate( |
| 82 Isolate* isolate, const ZoneFeedbackVectorSpec* spec); | 41 Isolate* isolate, const ZoneFeedbackVectorSpec* spec); |
| 83 | 42 |
| 84 | 43 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // static | 87 // static |
| 129 int TypeFeedbackVector::PushAppliedArgumentsIndex() { | 88 int TypeFeedbackVector::PushAppliedArgumentsIndex() { |
| 130 const int index_count = VectorICComputer::word_count(1); | 89 const int index_count = VectorICComputer::word_count(1); |
| 131 return kReservedIndexCount + index_count; | 90 return kReservedIndexCount + index_count; |
| 132 } | 91 } |
| 133 | 92 |
| 134 | 93 |
| 135 // static | 94 // static |
| 136 Handle<TypeFeedbackVector> TypeFeedbackVector::CreatePushAppliedArgumentsVector( | 95 Handle<TypeFeedbackVector> TypeFeedbackVector::CreatePushAppliedArgumentsVector( |
| 137 Isolate* isolate) { | 96 Isolate* isolate) { |
| 138 Code::Kind kinds[] = {Code::KEYED_LOAD_IC}; | 97 FeedbackVectorSlotKind kinds[] = {FeedbackVectorSlotKind::KEYED_LOAD_IC}; |
| 139 FeedbackVectorSpec spec(0, 1, kinds); | 98 FeedbackVectorSpec spec(0, 1, kinds); |
| 140 Handle<TypeFeedbackVector> feedback_vector = | 99 Handle<TypeFeedbackVector> feedback_vector = |
| 141 isolate->factory()->NewTypeFeedbackVector(&spec); | 100 isolate->factory()->NewTypeFeedbackVector(&spec); |
| 142 DCHECK(PushAppliedArgumentsIndex() == | 101 DCHECK(PushAppliedArgumentsIndex() == |
| 143 feedback_vector->GetIndex(FeedbackVectorICSlot(0))); | 102 feedback_vector->GetIndex(FeedbackVectorICSlot(0))); |
| 144 return feedback_vector; | 103 return feedback_vector; |
| 145 } | 104 } |
| 146 | 105 |
| 147 | 106 |
| 148 // static | 107 // static |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if (!force_clear && !ClearLogic(heap)) return; | 171 if (!force_clear && !ClearLogic(heap)) return; |
| 213 | 172 |
| 214 int slots = ICSlots(); | 173 int slots = ICSlots(); |
| 215 Code* host = shared->code(); | 174 Code* host = shared->code(); |
| 216 Object* uninitialized_sentinel = | 175 Object* uninitialized_sentinel = |
| 217 TypeFeedbackVector::RawUninitializedSentinel(heap); | 176 TypeFeedbackVector::RawUninitializedSentinel(heap); |
| 218 for (int i = 0; i < slots; i++) { | 177 for (int i = 0; i < slots; i++) { |
| 219 FeedbackVectorICSlot slot(i); | 178 FeedbackVectorICSlot slot(i); |
| 220 Object* obj = Get(slot); | 179 Object* obj = Get(slot); |
| 221 if (obj != uninitialized_sentinel) { | 180 if (obj != uninitialized_sentinel) { |
| 222 Code::Kind kind = GetKind(slot); | 181 FeedbackVectorSlotKind kind = GetKind(slot); |
| 223 if (kind == Code::CALL_IC) { | 182 switch (kind) { |
| 224 CallICNexus nexus(this, slot); | 183 case FeedbackVectorSlotKind::CALL_IC: { |
| 225 nexus.Clear(host); | 184 CallICNexus nexus(this, slot); |
| 226 } else if (kind == Code::LOAD_IC) { | 185 nexus.Clear(host); |
| 227 LoadICNexus nexus(this, slot); | 186 break; |
| 228 nexus.Clear(host); | 187 } |
| 229 } else if (kind == Code::KEYED_LOAD_IC) { | 188 case FeedbackVectorSlotKind::LOAD_IC: { |
| 230 KeyedLoadICNexus nexus(this, slot); | 189 LoadICNexus nexus(this, slot); |
| 231 nexus.Clear(host); | 190 nexus.Clear(host); |
| 232 } else if (kind == Code::STORE_IC) { | 191 break; |
| 233 DCHECK(FLAG_vector_stores); | 192 } |
| 234 StoreICNexus nexus(this, slot); | 193 case FeedbackVectorSlotKind::KEYED_LOAD_IC: { |
| 235 nexus.Clear(host); | 194 KeyedLoadICNexus nexus(this, slot); |
| 236 } else if (kind == Code::KEYED_STORE_IC) { | 195 nexus.Clear(host); |
| 237 DCHECK(FLAG_vector_stores); | 196 break; |
| 238 KeyedStoreICNexus nexus(this, slot); | 197 } |
| 239 nexus.Clear(host); | 198 case FeedbackVectorSlotKind::STORE_IC: { |
| 199 DCHECK(FLAG_vector_stores); |
| 200 StoreICNexus nexus(this, slot); |
| 201 nexus.Clear(host); |
| 202 break; |
| 203 } |
| 204 case FeedbackVectorSlotKind::KEYED_STORE_IC: { |
| 205 DCHECK(FLAG_vector_stores); |
| 206 KeyedStoreICNexus nexus(this, slot); |
| 207 nexus.Clear(host); |
| 208 break; |
| 209 } |
| 210 case FeedbackVectorSlotKind::UNUSED: |
| 211 case FeedbackVectorSlotKind::KINDS_NUMBER: |
| 212 UNREACHABLE(); |
| 213 break; |
| 240 } | 214 } |
| 241 } | 215 } |
| 242 } | 216 } |
| 243 } | 217 } |
| 244 | 218 |
| 245 | 219 |
| 246 // static | 220 // static |
| 247 void TypeFeedbackVector::ClearAllKeyedStoreICs(Isolate* isolate) { | 221 void TypeFeedbackVector::ClearAllKeyedStoreICs(Isolate* isolate) { |
| 248 DCHECK(FLAG_vector_stores); | 222 DCHECK(FLAG_vector_stores); |
| 249 SharedFunctionInfo::Iterator iterator(isolate); | 223 SharedFunctionInfo::Iterator iterator(isolate); |
| 250 SharedFunctionInfo* shared; | 224 SharedFunctionInfo* shared; |
| 251 while ((shared = iterator.Next())) { | 225 while ((shared = iterator.Next())) { |
| 252 TypeFeedbackVector* vector = shared->feedback_vector(); | 226 TypeFeedbackVector* vector = shared->feedback_vector(); |
| 253 vector->ClearKeyedStoreICs(shared); | 227 vector->ClearKeyedStoreICs(shared); |
| 254 } | 228 } |
| 255 } | 229 } |
| 256 | 230 |
| 257 | 231 |
| 258 void TypeFeedbackVector::ClearKeyedStoreICs(SharedFunctionInfo* shared) { | 232 void TypeFeedbackVector::ClearKeyedStoreICs(SharedFunctionInfo* shared) { |
| 259 Heap* heap = GetIsolate()->heap(); | 233 Heap* heap = GetIsolate()->heap(); |
| 260 | 234 |
| 261 int slots = ICSlots(); | 235 int slots = ICSlots(); |
| 262 Code* host = shared->code(); | 236 Code* host = shared->code(); |
| 263 Object* uninitialized_sentinel = | 237 Object* uninitialized_sentinel = |
| 264 TypeFeedbackVector::RawUninitializedSentinel(heap); | 238 TypeFeedbackVector::RawUninitializedSentinel(heap); |
| 265 for (int i = 0; i < slots; i++) { | 239 for (int i = 0; i < slots; i++) { |
| 266 FeedbackVectorICSlot slot(i); | 240 FeedbackVectorICSlot slot(i); |
| 267 Object* obj = Get(slot); | 241 Object* obj = Get(slot); |
| 268 if (obj != uninitialized_sentinel) { | 242 if (obj != uninitialized_sentinel) { |
| 269 Code::Kind kind = GetKind(slot); | 243 FeedbackVectorSlotKind kind = GetKind(slot); |
| 270 if (kind == Code::KEYED_STORE_IC) { | 244 if (kind == FeedbackVectorSlotKind::KEYED_STORE_IC) { |
| 271 DCHECK(FLAG_vector_stores); | 245 DCHECK(FLAG_vector_stores); |
| 272 KeyedStoreICNexus nexus(this, slot); | 246 KeyedStoreICNexus nexus(this, slot); |
| 273 nexus.Clear(host); | 247 nexus.Clear(host); |
| 274 } | 248 } |
| 275 } | 249 } |
| 276 } | 250 } |
| 277 } | 251 } |
| 278 | 252 |
| 279 | 253 |
| 280 // static | 254 // static |
| 281 Handle<TypeFeedbackVector> TypeFeedbackVector::DummyVector(Isolate* isolate) { | 255 Handle<TypeFeedbackVector> TypeFeedbackVector::DummyVector(Isolate* isolate) { |
| 282 return Handle<TypeFeedbackVector>::cast(isolate->factory()->dummy_vector()); | 256 return Handle<TypeFeedbackVector>::cast(isolate->factory()->dummy_vector()); |
| 283 } | 257 } |
| 284 | 258 |
| 285 | 259 |
| 260 const char* TypeFeedbackVector::Kind2String(FeedbackVectorSlotKind kind) { |
| 261 switch (kind) { |
| 262 case FeedbackVectorSlotKind::UNUSED: |
| 263 return "UNUSED"; |
| 264 case FeedbackVectorSlotKind::CALL_IC: |
| 265 return "CALL_IC"; |
| 266 case FeedbackVectorSlotKind::LOAD_IC: |
| 267 return "LOAD_IC"; |
| 268 case FeedbackVectorSlotKind::KEYED_LOAD_IC: |
| 269 return "KEYED_LOAD_IC"; |
| 270 case FeedbackVectorSlotKind::STORE_IC: |
| 271 return "STORE_IC"; |
| 272 case FeedbackVectorSlotKind::KEYED_STORE_IC: |
| 273 return "KEYED_STORE_IC"; |
| 274 case FeedbackVectorSlotKind::KINDS_NUMBER: |
| 275 break; |
| 276 } |
| 277 UNREACHABLE(); |
| 278 return "?"; |
| 279 } |
| 280 |
| 281 |
| 286 Handle<FixedArray> FeedbackNexus::EnsureArrayOfSize(int length) { | 282 Handle<FixedArray> FeedbackNexus::EnsureArrayOfSize(int length) { |
| 287 Isolate* isolate = GetIsolate(); | 283 Isolate* isolate = GetIsolate(); |
| 288 Handle<Object> feedback = handle(GetFeedback(), isolate); | 284 Handle<Object> feedback = handle(GetFeedback(), isolate); |
| 289 if (!feedback->IsFixedArray() || | 285 if (!feedback->IsFixedArray() || |
| 290 FixedArray::cast(*feedback)->length() != length) { | 286 FixedArray::cast(*feedback)->length() != length) { |
| 291 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); | 287 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); |
| 292 SetFeedback(*array); | 288 SetFeedback(*array); |
| 293 return array; | 289 return array; |
| 294 } | 290 } |
| 295 return Handle<FixedArray>::cast(feedback); | 291 return Handle<FixedArray>::cast(feedback); |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 return mode; | 803 return mode; |
| 808 } | 804 } |
| 809 | 805 |
| 810 | 806 |
| 811 IcCheckType KeyedStoreICNexus::GetKeyType() const { | 807 IcCheckType KeyedStoreICNexus::GetKeyType() const { |
| 812 // The structure of the vector slots tells us the type. | 808 // The structure of the vector slots tells us the type. |
| 813 return GetFeedback()->IsName() ? PROPERTY : ELEMENT; | 809 return GetFeedback()->IsName() ? PROPERTY : ELEMENT; |
| 814 } | 810 } |
| 815 } // namespace internal | 811 } // namespace internal |
| 816 } // namespace v8 | 812 } // namespace v8 |
| OLD | NEW |