| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "conversions-inl.h" | 41 #include "conversions-inl.h" |
| 42 #include "heap.h" | 42 #include "heap.h" |
| 43 #include "isolate.h" | 43 #include "isolate.h" |
| 44 #include "property.h" | 44 #include "property.h" |
| 45 #include "spaces.h" | 45 #include "spaces.h" |
| 46 #include "store-buffer.h" | 46 #include "store-buffer.h" |
| 47 #include "v8memory.h" | 47 #include "v8memory.h" |
| 48 #include "factory.h" | 48 #include "factory.h" |
| 49 #include "incremental-marking.h" | 49 #include "incremental-marking.h" |
| 50 #include "transitions-inl.h" | 50 #include "transitions-inl.h" |
| 51 #include "objects-visiting.h" |
| 51 | 52 |
| 52 namespace v8 { | 53 namespace v8 { |
| 53 namespace internal { | 54 namespace internal { |
| 54 | 55 |
| 55 PropertyDetails::PropertyDetails(Smi* smi) { | 56 PropertyDetails::PropertyDetails(Smi* smi) { |
| 56 value_ = smi->value(); | 57 value_ = smi->value(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 | 60 |
| 60 Smi* PropertyDetails::AsSmi() { | 61 Smi* PropertyDetails::AsSmi() { |
| (...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 accessor->Validate(this); | 1298 accessor->Validate(this); |
| 1298 } | 1299 } |
| 1299 #endif | 1300 #endif |
| 1300 } | 1301 } |
| 1301 | 1302 |
| 1302 | 1303 |
| 1303 void AllocationSite::Initialize() { | 1304 void AllocationSite::Initialize() { |
| 1304 set_transition_info(Smi::FromInt(0)); | 1305 set_transition_info(Smi::FromInt(0)); |
| 1305 SetElementsKind(GetInitialFastElementsKind()); | 1306 SetElementsKind(GetInitialFastElementsKind()); |
| 1306 set_nested_site(Smi::FromInt(0)); | 1307 set_nested_site(Smi::FromInt(0)); |
| 1307 set_memento_create_count(Smi::FromInt(0)); | 1308 set_pretenure_data(Smi::FromInt(0)); |
| 1308 set_memento_found_count(Smi::FromInt(0)); | 1309 set_pretenure_create_count(Smi::FromInt(0)); |
| 1309 set_pretenure_decision(Smi::FromInt(0)); | |
| 1310 set_dependent_code(DependentCode::cast(GetHeap()->empty_fixed_array()), | 1310 set_dependent_code(DependentCode::cast(GetHeap()->empty_fixed_array()), |
| 1311 SKIP_WRITE_BARRIER); | 1311 SKIP_WRITE_BARRIER); |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 | 1314 |
| 1315 void AllocationSite::MarkZombie() { | 1315 void AllocationSite::MarkZombie() { |
| 1316 ASSERT(!IsZombie()); | 1316 ASSERT(!IsZombie()); |
| 1317 set_pretenure_decision(Smi::FromInt(kZombie)); | 1317 Initialize(); |
| 1318 // Clear all non-smi fields | 1318 set_pretenure_decision(kZombie); |
| 1319 set_transition_info(Smi::FromInt(0)); | |
| 1320 set_dependent_code(DependentCode::cast(GetHeap()->empty_fixed_array()), | |
| 1321 SKIP_WRITE_BARRIER); | |
| 1322 } | 1319 } |
| 1323 | 1320 |
| 1324 | 1321 |
| 1325 // Heuristic: We only need to create allocation site info if the boilerplate | 1322 // Heuristic: We only need to create allocation site info if the boilerplate |
| 1326 // elements kind is the initial elements kind. | 1323 // elements kind is the initial elements kind. |
| 1327 AllocationSiteMode AllocationSite::GetMode( | 1324 AllocationSiteMode AllocationSite::GetMode( |
| 1328 ElementsKind boilerplate_elements_kind) { | 1325 ElementsKind boilerplate_elements_kind) { |
| 1329 if (FLAG_track_allocation_sites && | 1326 if (IsFastSmiElementsKind(boilerplate_elements_kind)) { |
| 1330 IsFastSmiElementsKind(boilerplate_elements_kind)) { | |
| 1331 return TRACK_ALLOCATION_SITE; | 1327 return TRACK_ALLOCATION_SITE; |
| 1332 } | 1328 } |
| 1333 | 1329 |
| 1334 return DONT_TRACK_ALLOCATION_SITE; | 1330 return DONT_TRACK_ALLOCATION_SITE; |
| 1335 } | 1331 } |
| 1336 | 1332 |
| 1337 | 1333 |
| 1338 AllocationSiteMode AllocationSite::GetMode(ElementsKind from, | 1334 AllocationSiteMode AllocationSite::GetMode(ElementsKind from, |
| 1339 ElementsKind to) { | 1335 ElementsKind to) { |
| 1340 if (FLAG_track_allocation_sites && | 1336 if (IsFastSmiElementsKind(from) && |
| 1341 IsFastSmiElementsKind(from) && | |
| 1342 IsMoreGeneralElementsKindTransition(from, to)) { | 1337 IsMoreGeneralElementsKindTransition(from, to)) { |
| 1343 return TRACK_ALLOCATION_SITE; | 1338 return TRACK_ALLOCATION_SITE; |
| 1344 } | 1339 } |
| 1345 | 1340 |
| 1346 return DONT_TRACK_ALLOCATION_SITE; | 1341 return DONT_TRACK_ALLOCATION_SITE; |
| 1347 } | 1342 } |
| 1348 | 1343 |
| 1349 | 1344 |
| 1350 inline bool AllocationSite::CanTrack(InstanceType type) { | 1345 inline bool AllocationSite::CanTrack(InstanceType type) { |
| 1351 if (FLAG_allocation_site_pretenuring) { | 1346 if (FLAG_allocation_site_pretenuring) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1365 break; | 1360 break; |
| 1366 case TRANSITIONS: | 1361 case TRANSITIONS: |
| 1367 return DependentCode::kAllocationSiteTransitionChangedGroup; | 1362 return DependentCode::kAllocationSiteTransitionChangedGroup; |
| 1368 break; | 1363 break; |
| 1369 } | 1364 } |
| 1370 UNREACHABLE(); | 1365 UNREACHABLE(); |
| 1371 return DependentCode::kAllocationSiteTransitionChangedGroup; | 1366 return DependentCode::kAllocationSiteTransitionChangedGroup; |
| 1372 } | 1367 } |
| 1373 | 1368 |
| 1374 | 1369 |
| 1370 inline void AllocationSite::set_memento_found_count(int count) { |
| 1371 int value = pretenure_data()->value(); |
| 1372 // Verify that we can count more mementos than we can possibly find in one |
| 1373 // new space collection. |
| 1374 ASSERT((GetHeap()->MaxSemiSpaceSize() / |
| 1375 (StaticVisitorBase::kMinObjectSizeInWords * kPointerSize + |
| 1376 AllocationMemento::kSize)) < MementoFoundCountBits::kMax); |
| 1377 ASSERT(count < MementoFoundCountBits::kMax); |
| 1378 set_pretenure_data( |
| 1379 Smi::FromInt(MementoFoundCountBits::update(value, count)), |
| 1380 SKIP_WRITE_BARRIER); |
| 1381 } |
| 1382 |
| 1375 inline bool AllocationSite::IncrementMementoFoundCount() { | 1383 inline bool AllocationSite::IncrementMementoFoundCount() { |
| 1376 if (IsZombie()) return false; | 1384 if (IsZombie()) return false; |
| 1377 | 1385 |
| 1378 int value = memento_found_count()->value(); | 1386 int value = memento_found_count(); |
| 1379 set_memento_found_count(Smi::FromInt(value + 1)); | 1387 set_memento_found_count(value + 1); |
| 1380 return value == 0; | 1388 return value == 0; |
| 1381 } | 1389 } |
| 1382 | 1390 |
| 1383 | 1391 |
| 1384 inline void AllocationSite::IncrementMementoCreateCount() { | 1392 inline void AllocationSite::IncrementMementoCreateCount() { |
| 1385 ASSERT(FLAG_allocation_site_pretenuring); | 1393 ASSERT(FLAG_allocation_site_pretenuring); |
| 1386 int value = memento_create_count()->value(); | 1394 int value = memento_create_count(); |
| 1387 set_memento_create_count(Smi::FromInt(value + 1)); | 1395 set_memento_create_count(value + 1); |
| 1388 } | 1396 } |
| 1389 | 1397 |
| 1390 | 1398 |
| 1391 inline bool AllocationSite::DigestPretenuringFeedback() { | 1399 inline bool AllocationSite::DigestPretenuringFeedback() { |
| 1392 bool decision_made = false; | 1400 bool decision_made = false; |
| 1393 if (!PretenuringDecisionMade()) { | 1401 int create_count = memento_create_count(); |
| 1394 int create_count = memento_create_count()->value(); | 1402 if (create_count >= kPretenureMinimumCreated) { |
| 1395 if (create_count >= kPretenureMinimumCreated) { | 1403 int found_count = memento_found_count(); |
| 1396 int found_count = memento_found_count()->value(); | 1404 double ratio = static_cast<double>(found_count) / create_count; |
| 1397 double ratio = static_cast<double>(found_count) / create_count; | 1405 if (FLAG_trace_track_allocation_sites) { |
| 1398 if (FLAG_trace_track_allocation_sites) { | 1406 PrintF("AllocationSite: %p (created, found, ratio) (%d, %d, %f)\n", |
| 1399 PrintF("AllocationSite: %p (created, found, ratio) (%d, %d, %f)\n", | 1407 static_cast<void*>(this), create_count, found_count, ratio); |
| 1400 static_cast<void*>(this), create_count, found_count, ratio); | 1408 } |
| 1401 } | 1409 int current_mode = GetPretenureMode(); |
| 1402 int result = ratio >= kPretenureRatio ? kTenure : kDontTenure; | 1410 PretenureDecision result = ratio >= kPretenureRatio |
| 1403 set_pretenure_decision(Smi::FromInt(result)); | 1411 ? kTenure |
| 1404 decision_made = true; | 1412 : kDontTenure; |
| 1405 // TODO(mvstanton): if the decision represents a change, any dependent | 1413 set_pretenure_decision(result); |
| 1406 // code registered for pretenuring changes should be deopted. | 1414 decision_made = true; |
| 1415 if (current_mode != GetPretenureMode()) { |
| 1416 dependent_code()->DeoptimizeDependentCodeGroup( |
| 1417 GetIsolate(), |
| 1418 DependentCode::kAllocationSiteTenuringChangedGroup); |
| 1407 } | 1419 } |
| 1408 } | 1420 } |
| 1409 | 1421 |
| 1410 // Clear feedback calculation fields until the next gc. | 1422 // Clear feedback calculation fields until the next gc. |
| 1411 set_memento_found_count(Smi::FromInt(0)); | 1423 set_memento_found_count(0); |
| 1412 set_memento_create_count(Smi::FromInt(0)); | 1424 set_memento_create_count(0); |
| 1413 return decision_made; | 1425 return decision_made; |
| 1414 } | 1426 } |
| 1415 | 1427 |
| 1416 | 1428 |
| 1417 void JSObject::EnsureCanContainHeapObjectElements(Handle<JSObject> object) { | 1429 void JSObject::EnsureCanContainHeapObjectElements(Handle<JSObject> object) { |
| 1418 object->ValidateElements(); | 1430 object->ValidateElements(); |
| 1419 ElementsKind elements_kind = object->map()->elements_kind(); | 1431 ElementsKind elements_kind = object->map()->elements_kind(); |
| 1420 if (!IsFastObjectElementsKind(elements_kind)) { | 1432 if (!IsFastObjectElementsKind(elements_kind)) { |
| 1421 if (IsFastHoleyElementsKind(elements_kind)) { | 1433 if (IsFastHoleyElementsKind(elements_kind)) { |
| 1422 TransitionElementsKind(object, FAST_HOLEY_ELEMENTS); | 1434 TransitionElementsKind(object, FAST_HOLEY_ELEMENTS); |
| (...skipping 3173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4596 ACCESSORS(ObjectTemplateInfo, internal_field_count, Object, | 4608 ACCESSORS(ObjectTemplateInfo, internal_field_count, Object, |
| 4597 kInternalFieldCountOffset) | 4609 kInternalFieldCountOffset) |
| 4598 | 4610 |
| 4599 ACCESSORS(SignatureInfo, receiver, Object, kReceiverOffset) | 4611 ACCESSORS(SignatureInfo, receiver, Object, kReceiverOffset) |
| 4600 ACCESSORS(SignatureInfo, args, Object, kArgsOffset) | 4612 ACCESSORS(SignatureInfo, args, Object, kArgsOffset) |
| 4601 | 4613 |
| 4602 ACCESSORS(TypeSwitchInfo, types, Object, kTypesOffset) | 4614 ACCESSORS(TypeSwitchInfo, types, Object, kTypesOffset) |
| 4603 | 4615 |
| 4604 ACCESSORS(AllocationSite, transition_info, Object, kTransitionInfoOffset) | 4616 ACCESSORS(AllocationSite, transition_info, Object, kTransitionInfoOffset) |
| 4605 ACCESSORS(AllocationSite, nested_site, Object, kNestedSiteOffset) | 4617 ACCESSORS(AllocationSite, nested_site, Object, kNestedSiteOffset) |
| 4606 ACCESSORS_TO_SMI(AllocationSite, memento_found_count, kMementoFoundCountOffset) | 4618 ACCESSORS_TO_SMI(AllocationSite, pretenure_data, kPretenureDataOffset) |
| 4607 ACCESSORS_TO_SMI(AllocationSite, memento_create_count, | 4619 ACCESSORS_TO_SMI(AllocationSite, pretenure_create_count, |
| 4608 kMementoCreateCountOffset) | 4620 kPretenureCreateCountOffset) |
| 4609 ACCESSORS_TO_SMI(AllocationSite, pretenure_decision, kPretenureDecisionOffset) | |
| 4610 ACCESSORS(AllocationSite, dependent_code, DependentCode, | 4621 ACCESSORS(AllocationSite, dependent_code, DependentCode, |
| 4611 kDependentCodeOffset) | 4622 kDependentCodeOffset) |
| 4612 ACCESSORS(AllocationSite, weak_next, Object, kWeakNextOffset) | 4623 ACCESSORS(AllocationSite, weak_next, Object, kWeakNextOffset) |
| 4613 ACCESSORS(AllocationMemento, allocation_site, Object, kAllocationSiteOffset) | 4624 ACCESSORS(AllocationMemento, allocation_site, Object, kAllocationSiteOffset) |
| 4614 | 4625 |
| 4615 ACCESSORS(Script, source, Object, kSourceOffset) | 4626 ACCESSORS(Script, source, Object, kSourceOffset) |
| 4616 ACCESSORS(Script, name, Object, kNameOffset) | 4627 ACCESSORS(Script, name, Object, kNameOffset) |
| 4617 ACCESSORS(Script, id, Smi, kIdOffset) | 4628 ACCESSORS(Script, id, Smi, kIdOffset) |
| 4618 ACCESSORS_TO_SMI(Script, line_offset, kLineOffsetOffset) | 4629 ACCESSORS_TO_SMI(Script, line_offset, kLineOffsetOffset) |
| 4619 ACCESSORS_TO_SMI(Script, column_offset, kColumnOffsetOffset) | 4630 ACCESSORS_TO_SMI(Script, column_offset, kColumnOffsetOffset) |
| (...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6480 #undef WRITE_UINT32_FIELD | 6491 #undef WRITE_UINT32_FIELD |
| 6481 #undef READ_SHORT_FIELD | 6492 #undef READ_SHORT_FIELD |
| 6482 #undef WRITE_SHORT_FIELD | 6493 #undef WRITE_SHORT_FIELD |
| 6483 #undef READ_BYTE_FIELD | 6494 #undef READ_BYTE_FIELD |
| 6484 #undef WRITE_BYTE_FIELD | 6495 #undef WRITE_BYTE_FIELD |
| 6485 | 6496 |
| 6486 | 6497 |
| 6487 } } // namespace v8::internal | 6498 } } // namespace v8::internal |
| 6488 | 6499 |
| 6489 #endif // V8_OBJECTS_INL_H_ | 6500 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |