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/feedback-vector.h" | 5 #include "src/feedback-vector.h" |
6 #include "src/code-stubs.h" | 6 #include "src/code-stubs.h" |
7 #include "src/feedback-vector-inl.h" | 7 #include "src/feedback-vector-inl.h" |
8 #include "src/ic/ic-inl.h" | 8 #include "src/ic/ic-inl.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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 case FeedbackSlotKind::kCompareOp: | 142 case FeedbackSlotKind::kCompareOp: |
143 return "INTERPRETER_COMPARE_IC"; | 143 return "INTERPRETER_COMPARE_IC"; |
144 case FeedbackSlotKind::kToBoolean: | 144 case FeedbackSlotKind::kToBoolean: |
145 return "TO_BOOLEAN_IC"; | 145 return "TO_BOOLEAN_IC"; |
146 case FeedbackSlotKind::kStoreDataPropertyInLiteral: | 146 case FeedbackSlotKind::kStoreDataPropertyInLiteral: |
147 return "STORE_DATA_PROPERTY_IN_LITERAL_IC"; | 147 return "STORE_DATA_PROPERTY_IN_LITERAL_IC"; |
148 case FeedbackSlotKind::kCreateClosure: | 148 case FeedbackSlotKind::kCreateClosure: |
149 return "kCreateClosure"; | 149 return "kCreateClosure"; |
150 case FeedbackSlotKind::kLiteral: | 150 case FeedbackSlotKind::kLiteral: |
151 return "LITERAL"; | 151 return "LITERAL"; |
| 152 case FeedbackSlotKind::kTypeProfile: |
| 153 return "TYPE_PROFILE"; |
152 case FeedbackSlotKind::kGeneral: | 154 case FeedbackSlotKind::kGeneral: |
153 return "STUB"; | 155 return "STUB"; |
154 case FeedbackSlotKind::kKindsNumber: | 156 case FeedbackSlotKind::kKindsNumber: |
155 break; | 157 break; |
156 } | 158 } |
157 UNREACHABLE(); | 159 UNREACHABLE(); |
158 return "?"; | 160 return "?"; |
159 } | 161 } |
160 | 162 |
| 163 bool FeedbackMetadata::HasTypeProfileSlot() { |
| 164 FeedbackMetadataIterator iter(this); |
| 165 while (iter.HasNext()) { |
| 166 iter.Next(); |
| 167 FeedbackSlotKind kind = iter.kind(); |
| 168 if (kind == FeedbackSlotKind::kTypeProfile) { |
| 169 return true; |
| 170 } |
| 171 } |
| 172 return false; |
| 173 } |
| 174 |
161 FeedbackSlotKind FeedbackVector::GetKind(FeedbackSlot slot) const { | 175 FeedbackSlotKind FeedbackVector::GetKind(FeedbackSlot slot) const { |
162 DCHECK(!is_empty()); | 176 DCHECK(!is_empty()); |
163 return metadata()->GetKind(slot); | 177 return metadata()->GetKind(slot); |
164 } | 178 } |
165 | 179 |
166 // static | 180 // static |
167 Handle<FeedbackVector> FeedbackVector::New(Isolate* isolate, | 181 Handle<FeedbackVector> FeedbackVector::New(Isolate* isolate, |
168 Handle<SharedFunctionInfo> shared) { | 182 Handle<SharedFunctionInfo> shared) { |
169 Factory* factory = isolate->factory(); | 183 Factory* factory = isolate->factory(); |
170 | 184 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 break; | 226 break; |
213 case FeedbackSlotKind::kLoadProperty: | 227 case FeedbackSlotKind::kLoadProperty: |
214 case FeedbackSlotKind::kLoadKeyed: | 228 case FeedbackSlotKind::kLoadKeyed: |
215 case FeedbackSlotKind::kStoreNamedSloppy: | 229 case FeedbackSlotKind::kStoreNamedSloppy: |
216 case FeedbackSlotKind::kStoreNamedStrict: | 230 case FeedbackSlotKind::kStoreNamedStrict: |
217 case FeedbackSlotKind::kStoreOwnNamed: | 231 case FeedbackSlotKind::kStoreOwnNamed: |
218 case FeedbackSlotKind::kStoreKeyedSloppy: | 232 case FeedbackSlotKind::kStoreKeyedSloppy: |
219 case FeedbackSlotKind::kStoreKeyedStrict: | 233 case FeedbackSlotKind::kStoreKeyedStrict: |
220 case FeedbackSlotKind::kStoreDataPropertyInLiteral: | 234 case FeedbackSlotKind::kStoreDataPropertyInLiteral: |
221 case FeedbackSlotKind::kGeneral: | 235 case FeedbackSlotKind::kGeneral: |
| 236 case FeedbackSlotKind::kTypeProfile: |
222 array->set(index, *uninitialized_sentinel, SKIP_WRITE_BARRIER); | 237 array->set(index, *uninitialized_sentinel, SKIP_WRITE_BARRIER); |
223 break; | 238 break; |
224 | 239 |
225 case FeedbackSlotKind::kInvalid: | 240 case FeedbackSlotKind::kInvalid: |
226 case FeedbackSlotKind::kKindsNumber: | 241 case FeedbackSlotKind::kKindsNumber: |
227 UNREACHABLE(); | 242 UNREACHABLE(); |
228 array->set(index, Smi::kZero, SKIP_WRITE_BARRIER); | 243 array->set(index, Smi::kZero, SKIP_WRITE_BARRIER); |
229 break; | 244 break; |
230 } | 245 } |
231 for (int j = 1; j < entry_size; j++) { | 246 for (int j = 1; j < entry_size; j++) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 break; | 344 break; |
330 } | 345 } |
331 case FeedbackSlotKind::kBinaryOp: | 346 case FeedbackSlotKind::kBinaryOp: |
332 case FeedbackSlotKind::kCompareOp: { | 347 case FeedbackSlotKind::kCompareOp: { |
333 DCHECK(Get(slot)->IsSmi()); | 348 DCHECK(Get(slot)->IsSmi()); |
334 // don't clear these smi slots. | 349 // don't clear these smi slots. |
335 // Set(slot, Smi::kZero); | 350 // Set(slot, Smi::kZero); |
336 break; | 351 break; |
337 } | 352 } |
338 case FeedbackSlotKind::kCreateClosure: { | 353 case FeedbackSlotKind::kCreateClosure: { |
339 break; | 354 case FeedbackSlotKind::kTypeProfile: |
| 355 break; |
340 } | 356 } |
341 case FeedbackSlotKind::kGeneral: { | 357 case FeedbackSlotKind::kGeneral: { |
342 if (obj->IsHeapObject()) { | 358 if (obj->IsHeapObject()) { |
343 InstanceType instance_type = | 359 InstanceType instance_type = |
344 HeapObject::cast(obj)->map()->instance_type(); | 360 HeapObject::cast(obj)->map()->instance_type(); |
345 // AllocationSites are exempt from clearing. They don't store Maps | 361 // AllocationSites are exempt from clearing. They don't store Maps |
346 // or Code pointers which can cause memory leaks if not cleared | 362 // or Code pointers which can cause memory leaks if not cleared |
347 // regularly. | 363 // regularly. |
348 if (instance_type != ALLOCATION_SITE_TYPE) { | 364 if (instance_type != ALLOCATION_SITE_TYPE) { |
349 Set(slot, uninitialized_sentinel, SKIP_WRITE_BARRIER); | 365 Set(slot, uninitialized_sentinel, SKIP_WRITE_BARRIER); |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 } | 1032 } |
1017 | 1033 |
1018 void StoreDataPropertyInLiteralICNexus::ConfigureMonomorphic( | 1034 void StoreDataPropertyInLiteralICNexus::ConfigureMonomorphic( |
1019 Handle<Name> name, Handle<Map> receiver_map) { | 1035 Handle<Name> name, Handle<Map> receiver_map) { |
1020 Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); | 1036 Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); |
1021 | 1037 |
1022 SetFeedback(*cell); | 1038 SetFeedback(*cell); |
1023 SetFeedbackExtra(*name); | 1039 SetFeedbackExtra(*name); |
1024 } | 1040 } |
1025 | 1041 |
| 1042 InlineCacheState CollectTypeProfileNexus::StateFromFeedback() const { |
| 1043 Isolate* isolate = GetIsolate(); |
| 1044 Object* const feedback = GetFeedback(); |
| 1045 |
| 1046 if (feedback == *FeedbackVector::UninitializedSentinel(isolate)) { |
| 1047 return UNINITIALIZED; |
| 1048 } |
| 1049 return MONOMORPHIC; |
| 1050 } |
| 1051 |
| 1052 void CollectTypeProfileNexus::Collect(Handle<Name> type) { |
| 1053 Isolate* isolate = GetIsolate(); |
| 1054 |
| 1055 Object* const feedback = GetFeedback(); |
| 1056 Handle<ArrayList> types; |
| 1057 |
| 1058 if (feedback == *FeedbackVector::UninitializedSentinel(isolate)) { |
| 1059 types = ArrayList::New(isolate, 1); |
| 1060 } else { |
| 1061 types = Handle<ArrayList>(ArrayList::cast(feedback), isolate); |
| 1062 } |
| 1063 // TODO(franzih): Somehow sort this list. Either avoid duplicates |
| 1064 // or use the common base type. |
| 1065 SetFeedback(*ArrayList::Add(types, type)); |
| 1066 } |
| 1067 |
| 1068 void CollectTypeProfileNexus::Print() const { |
| 1069 Isolate* isolate = GetIsolate(); |
| 1070 |
| 1071 Object* const feedback = GetFeedback(); |
| 1072 |
| 1073 if (feedback == *FeedbackVector::UninitializedSentinel(isolate)) { |
| 1074 return; |
| 1075 } |
| 1076 |
| 1077 Handle<ArrayList> list; |
| 1078 list = Handle<ArrayList>(ArrayList::cast(feedback), isolate); |
| 1079 |
| 1080 for (int i = 0; i < list->Length(); i++) { |
| 1081 String* name = String::cast(list->Get(i)); |
| 1082 PrintF("%s\n", name->ToCString().get()); |
| 1083 } |
| 1084 } |
| 1085 |
1026 } // namespace internal | 1086 } // namespace internal |
1027 } // namespace v8 | 1087 } // namespace v8 |
OLD | NEW |