| 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-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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 case FeedbackVectorSlotKind::KEYED_STORE_IC: | 157 case FeedbackVectorSlotKind::KEYED_STORE_IC: |
| 158 return "KEYED_STORE_IC"; | 158 return "KEYED_STORE_IC"; |
| 159 case FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC: | 159 case FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC: |
| 160 return "INTERPRETER_BINARYOP_IC"; | 160 return "INTERPRETER_BINARYOP_IC"; |
| 161 case FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC: | 161 case FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC: |
| 162 return "INTERPRETER_COMPARE_IC"; | 162 return "INTERPRETER_COMPARE_IC"; |
| 163 case FeedbackVectorSlotKind::STORE_DATA_PROPERTY_IN_LITERAL_IC: | 163 case FeedbackVectorSlotKind::STORE_DATA_PROPERTY_IN_LITERAL_IC: |
| 164 return "STORE_DATA_PROPERTY_IN_LITERAL_IC"; | 164 return "STORE_DATA_PROPERTY_IN_LITERAL_IC"; |
| 165 case FeedbackVectorSlotKind::CREATE_CLOSURE: | 165 case FeedbackVectorSlotKind::CREATE_CLOSURE: |
| 166 return "CREATE_CLOSURE"; | 166 return "CREATE_CLOSURE"; |
| 167 case FeedbackVectorSlotKind::LITERAL: |
| 168 return "LITERAL"; |
| 167 case FeedbackVectorSlotKind::GENERAL: | 169 case FeedbackVectorSlotKind::GENERAL: |
| 168 return "STUB"; | 170 return "STUB"; |
| 169 case FeedbackVectorSlotKind::KINDS_NUMBER: | 171 case FeedbackVectorSlotKind::KINDS_NUMBER: |
| 170 break; | 172 break; |
| 171 } | 173 } |
| 172 UNREACHABLE(); | 174 UNREACHABLE(); |
| 173 return "?"; | 175 return "?"; |
| 174 } | 176 } |
| 175 | 177 |
| 176 FeedbackVectorSlotKind TypeFeedbackVector::GetKind( | 178 FeedbackVectorSlotKind TypeFeedbackVector::GetKind( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 195 array->set_map_no_write_barrier(isolate->heap()->type_feedback_vector_map()); | 197 array->set_map_no_write_barrier(isolate->heap()->type_feedback_vector_map()); |
| 196 array->set(kMetadataIndex, *metadata); | 198 array->set(kMetadataIndex, *metadata); |
| 197 array->set(kInvocationCountIndex, Smi::kZero); | 199 array->set(kInvocationCountIndex, Smi::kZero); |
| 198 for (int i = 0; i < slot_count;) { | 200 for (int i = 0; i < slot_count;) { |
| 199 FeedbackVectorSlot slot(i); | 201 FeedbackVectorSlot slot(i); |
| 200 FeedbackVectorSlotKind kind = metadata->GetKind(slot); | 202 FeedbackVectorSlotKind kind = metadata->GetKind(slot); |
| 201 int index = TypeFeedbackVector::GetIndex(slot); | 203 int index = TypeFeedbackVector::GetIndex(slot); |
| 202 int entry_size = TypeFeedbackMetadata::GetSlotSize(kind); | 204 int entry_size = TypeFeedbackMetadata::GetSlotSize(kind); |
| 203 | 205 |
| 204 if (kind == FeedbackVectorSlotKind::CREATE_CLOSURE) { | 206 if (kind == FeedbackVectorSlotKind::CREATE_CLOSURE) { |
| 205 // TODO(mvstanton): Root literal arrays in this location. | 207 // TODO(mvstanton): Root feedback vectors in this location. |
| 206 array->set(index, *factory->empty_literals_array(), SKIP_WRITE_BARRIER); | 208 array->set(index, *factory->empty_type_feedback_vector(), |
| 209 SKIP_WRITE_BARRIER); |
| 207 } | 210 } |
| 208 i += entry_size; | 211 i += entry_size; |
| 209 } | 212 } |
| 210 | 213 |
| 211 DisallowHeapAllocation no_gc; | 214 DisallowHeapAllocation no_gc; |
| 212 | 215 |
| 213 // Ensure we can skip the write barrier | 216 // Ensure we can skip the write barrier |
| 214 Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); | 217 Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); |
| 218 Handle<Oddball> undefined_value = factory->undefined_value(); |
| 215 DCHECK_EQ(isolate->heap()->uninitialized_symbol(), *uninitialized_sentinel); | 219 DCHECK_EQ(isolate->heap()->uninitialized_symbol(), *uninitialized_sentinel); |
| 216 for (int i = 0; i < slot_count;) { | 220 for (int i = 0; i < slot_count;) { |
| 217 FeedbackVectorSlot slot(i); | 221 FeedbackVectorSlot slot(i); |
| 218 FeedbackVectorSlotKind kind = metadata->GetKind(slot); | 222 FeedbackVectorSlotKind kind = metadata->GetKind(slot); |
| 219 int index = TypeFeedbackVector::GetIndex(slot); | 223 int index = TypeFeedbackVector::GetIndex(slot); |
| 220 int entry_size = TypeFeedbackMetadata::GetSlotSize(kind); | 224 int entry_size = TypeFeedbackMetadata::GetSlotSize(kind); |
| 221 | 225 |
| 222 Object* value; | 226 Object* value; |
| 223 if (kind == FeedbackVectorSlotKind::LOAD_GLOBAL_IC) { | 227 if (kind == FeedbackVectorSlotKind::LOAD_GLOBAL_IC) { |
| 224 value = isolate->heap()->empty_weak_cell(); | 228 value = isolate->heap()->empty_weak_cell(); |
| 225 } else if (kind == FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC || | 229 } else if (kind == FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC || |
| 226 kind == FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC) { | 230 kind == FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC) { |
| 227 value = Smi::kZero; | 231 value = Smi::kZero; |
| 232 } else if (kind == FeedbackVectorSlotKind::LITERAL) { |
| 233 value = *undefined_value; |
| 228 } else { | 234 } else { |
| 229 value = *uninitialized_sentinel; | 235 value = *uninitialized_sentinel; |
| 230 } | 236 } |
| 231 | 237 |
| 232 if (kind != FeedbackVectorSlotKind::CREATE_CLOSURE) { | 238 if (kind != FeedbackVectorSlotKind::CREATE_CLOSURE) { |
| 233 array->set(index, value, SKIP_WRITE_BARRIER); | 239 array->set(index, value, SKIP_WRITE_BARRIER); |
| 234 value = kind == FeedbackVectorSlotKind::CALL_IC ? Smi::kZero | 240 value = kind == FeedbackVectorSlotKind::CALL_IC ? Smi::kZero |
| 235 : *uninitialized_sentinel; | 241 : *uninitialized_sentinel; |
| 236 for (int j = 1; j < entry_size; j++) { | 242 for (int j = 1; j < entry_size; j++) { |
| 237 array->set(index + j, value, SKIP_WRITE_BARRIER); | 243 array->set(index + j, value, SKIP_WRITE_BARRIER); |
| 238 } | 244 } |
| 239 } | 245 } |
| 240 i += entry_size; | 246 i += entry_size; |
| 241 } | 247 } |
| 242 return Handle<TypeFeedbackVector>::cast(array); | 248 return Handle<TypeFeedbackVector>::cast(array); |
| 243 } | 249 } |
| 244 | 250 |
| 245 | |
| 246 // static | |
| 247 int TypeFeedbackVector::GetIndexFromSpec(const FeedbackVectorSpec* spec, | |
| 248 FeedbackVectorSlot slot) { | |
| 249 return kReservedIndexCount + slot.ToInt(); | |
| 250 } | |
| 251 | |
| 252 | |
| 253 // static | 251 // static |
| 254 Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( | 252 Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( |
| 255 Isolate* isolate, Handle<TypeFeedbackVector> vector) { | 253 Isolate* isolate, Handle<TypeFeedbackVector> vector) { |
| 256 Handle<TypeFeedbackVector> result; | 254 Handle<TypeFeedbackVector> result; |
| 257 result = Handle<TypeFeedbackVector>::cast( | 255 result = Handle<TypeFeedbackVector>::cast( |
| 258 isolate->factory()->CopyFixedArray(Handle<FixedArray>::cast(vector))); | 256 isolate->factory()->CopyFixedArray(Handle<FixedArray>::cast(vector))); |
| 259 return result; | 257 return result; |
| 260 } | 258 } |
| 261 | 259 |
| 262 | 260 |
| 263 // This logic is copied from | 261 // This logic is copied from |
| 264 // StaticMarkingVisitor<StaticVisitor>::VisitCodeTarget. | 262 // StaticMarkingVisitor<StaticVisitor>::VisitCodeTarget. |
| 265 static bool ClearLogic(Isolate* isolate) { | 263 static bool ClearLogic(Isolate* isolate) { |
| 266 return FLAG_cleanup_code_caches_at_gc && isolate->serializer_enabled(); | 264 return FLAG_cleanup_code_caches_at_gc && isolate->serializer_enabled(); |
| 267 } | 265 } |
| 268 | 266 |
| 269 | 267 |
| 270 void TypeFeedbackVector::ClearSlotsImpl(SharedFunctionInfo* shared, | 268 void TypeFeedbackVector::ClearSlotsImpl(SharedFunctionInfo* shared, |
| 271 bool force_clear) { | 269 bool force_clear) { |
| 272 Isolate* isolate = GetIsolate(); | 270 Isolate* isolate = GetIsolate(); |
| 273 if (!force_clear && !ClearLogic(isolate)) return; | 271 if (!force_clear && !ClearLogic(isolate)) return; |
| 274 | 272 |
| 275 if (this == isolate->heap()->empty_type_feedback_vector()) return; | 273 if (this == isolate->heap()->empty_type_feedback_vector()) return; |
| 276 | 274 |
| 277 Object* uninitialized_sentinel = | 275 Object* uninitialized_sentinel = |
| 278 TypeFeedbackVector::RawUninitializedSentinel(isolate); | 276 TypeFeedbackVector::RawUninitializedSentinel(isolate); |
| 277 Oddball* undefined_value = isolate->heap()->undefined_value(); |
| 279 | 278 |
| 280 TypeFeedbackMetadataIterator iter(metadata()); | 279 TypeFeedbackMetadataIterator iter(metadata()); |
| 281 while (iter.HasNext()) { | 280 while (iter.HasNext()) { |
| 282 FeedbackVectorSlot slot = iter.Next(); | 281 FeedbackVectorSlot slot = iter.Next(); |
| 283 FeedbackVectorSlotKind kind = iter.kind(); | 282 FeedbackVectorSlotKind kind = iter.kind(); |
| 284 | 283 |
| 285 Object* obj = Get(slot); | 284 Object* obj = Get(slot); |
| 286 if (obj != uninitialized_sentinel) { | 285 if (obj != uninitialized_sentinel) { |
| 287 switch (kind) { | 286 switch (kind) { |
| 288 case FeedbackVectorSlotKind::CALL_IC: { | 287 case FeedbackVectorSlotKind::CALL_IC: { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 316 break; | 315 break; |
| 317 } | 316 } |
| 318 case FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC: | 317 case FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC: |
| 319 case FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC: { | 318 case FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC: { |
| 320 DCHECK(Get(slot)->IsSmi()); | 319 DCHECK(Get(slot)->IsSmi()); |
| 321 // don't clear these smi slots. | 320 // don't clear these smi slots. |
| 322 // Set(slot, Smi::kZero); | 321 // Set(slot, Smi::kZero); |
| 323 break; | 322 break; |
| 324 } | 323 } |
| 325 case FeedbackVectorSlotKind::CREATE_CLOSURE: { | 324 case FeedbackVectorSlotKind::CREATE_CLOSURE: { |
| 326 // Fill the array with undefined. | |
| 327 FixedArray* array = FixedArray::cast(Get(slot)); | |
| 328 for (int i = 1; i < array->length(); i++) { | |
| 329 array->set_undefined(i); | |
| 330 } | |
| 331 break; | 325 break; |
| 332 } | 326 } |
| 333 case FeedbackVectorSlotKind::GENERAL: { | 327 case FeedbackVectorSlotKind::GENERAL: { |
| 334 if (obj->IsHeapObject()) { | 328 if (obj->IsHeapObject()) { |
| 335 InstanceType instance_type = | 329 InstanceType instance_type = |
| 336 HeapObject::cast(obj)->map()->instance_type(); | 330 HeapObject::cast(obj)->map()->instance_type(); |
| 337 // AllocationSites are exempt from clearing. They don't store Maps | 331 // AllocationSites are exempt from clearing. They don't store Maps |
| 338 // or Code pointers which can cause memory leaks if not cleared | 332 // or Code pointers which can cause memory leaks if not cleared |
| 339 // regularly. | 333 // regularly. |
| 340 if (instance_type != ALLOCATION_SITE_TYPE) { | 334 if (instance_type != ALLOCATION_SITE_TYPE) { |
| 341 Set(slot, uninitialized_sentinel, SKIP_WRITE_BARRIER); | 335 Set(slot, uninitialized_sentinel, SKIP_WRITE_BARRIER); |
| 342 } | 336 } |
| 343 } | 337 } |
| 344 break; | 338 break; |
| 345 } | 339 } |
| 340 case FeedbackVectorSlotKind::LITERAL: { |
| 341 Set(slot, undefined_value, SKIP_WRITE_BARRIER); |
| 342 break; |
| 343 } |
| 346 case FeedbackVectorSlotKind::STORE_DATA_PROPERTY_IN_LITERAL_IC: { | 344 case FeedbackVectorSlotKind::STORE_DATA_PROPERTY_IN_LITERAL_IC: { |
| 347 StoreDataPropertyInLiteralICNexus nexus(this, slot); | 345 StoreDataPropertyInLiteralICNexus nexus(this, slot); |
| 348 nexus.Clear(shared->code()); | 346 nexus.Clear(shared->code()); |
| 349 break; | 347 break; |
| 350 } | 348 } |
| 351 case FeedbackVectorSlotKind::INVALID: | 349 case FeedbackVectorSlotKind::INVALID: |
| 352 case FeedbackVectorSlotKind::KINDS_NUMBER: | 350 case FeedbackVectorSlotKind::KINDS_NUMBER: |
| 353 UNREACHABLE(); | 351 UNREACHABLE(); |
| 354 break; | 352 break; |
| 355 } | 353 } |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 void StoreDataPropertyInLiteralICNexus::ConfigureMonomorphic( | 1034 void StoreDataPropertyInLiteralICNexus::ConfigureMonomorphic( |
| 1037 Handle<Name> name, Handle<Map> receiver_map) { | 1035 Handle<Name> name, Handle<Map> receiver_map) { |
| 1038 Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); | 1036 Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); |
| 1039 | 1037 |
| 1040 SetFeedback(*cell); | 1038 SetFeedback(*cell); |
| 1041 SetFeedbackExtra(*name); | 1039 SetFeedbackExtra(*name); |
| 1042 } | 1040 } |
| 1043 | 1041 |
| 1044 } // namespace internal | 1042 } // namespace internal |
| 1045 } // namespace v8 | 1043 } // namespace v8 |
| OLD | NEW |