Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/Source/platform/heap/ThreadState.cpp

Issue 1840103004: Introduce ThreadHeapStats (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/heap/PersistentNode.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 510
511 if (isMainThread()) { 511 if (isMainThread()) {
512 double timeForThreadLocalWeakProcessing = WTF::currentTimeMS() - startTi me; 512 double timeForThreadLocalWeakProcessing = WTF::currentTimeMS() - startTi me;
513 DEFINE_STATIC_LOCAL(CustomCountHistogram, timeForWeakHistogram, ("BlinkG C.TimeForThreadLocalWeakProcessing", 1, 10 * 1000, 50)); 513 DEFINE_STATIC_LOCAL(CustomCountHistogram, timeForWeakHistogram, ("BlinkG C.TimeForThreadLocalWeakProcessing", 1, 10 * 1000, 50));
514 timeForWeakHistogram.count(timeForThreadLocalWeakProcessing); 514 timeForWeakHistogram.count(timeForThreadLocalWeakProcessing);
515 } 515 }
516 } 516 }
517 517
518 size_t ThreadState::totalMemorySize() 518 size_t ThreadState::totalMemorySize()
519 { 519 {
520 return Heap::allocatedObjectSize() + Heap::markedObjectSize() + WTF::Partiti ons::totalSizeOfCommittedPages(); 520 return Heap::heapStats().allocatedObjectSize() + Heap::heapStats().markedObj ectSize() + WTF::Partitions::totalSizeOfCommittedPages();
521 } 521 }
522 522
523 size_t ThreadState::estimatedLiveSize(size_t estimationBaseSize, size_t sizeAtLa stGC) 523 size_t ThreadState::estimatedLiveSize(size_t estimationBaseSize, size_t sizeAtLa stGC)
524 { 524 {
525 if (Heap::wrapperCountAtLastGC() == 0) { 525 if (Heap::heapStats().wrapperCountAtLastGC() == 0) {
526 // We'll reach here only before hitting the first GC. 526 // We'll reach here only before hitting the first GC.
527 return 0; 527 return 0;
528 } 528 }
529 529
530 // (estimated size) = (estimation base size) - (heap size at the last GC) / (# of persistent handles at the last GC) * (# of persistent handles collected si nce the last GC); 530 // (estimated size) = (estimation base size) - (heap size at the last GC) / (# of persistent handles at the last GC) * (# of persistent handles collected si nce the last GC);
531 size_t sizeRetainedByCollectedPersistents = static_cast<size_t>(1.0 * sizeAt LastGC / Heap::wrapperCountAtLastGC() * Heap::collectedWrapperCount()); 531 size_t sizeRetainedByCollectedPersistents = static_cast<size_t>(1.0 * sizeAt LastGC / Heap::heapStats().wrapperCountAtLastGC() * Heap::heapStats().collectedW rapperCount());
532 if (estimationBaseSize < sizeRetainedByCollectedPersistents) 532 if (estimationBaseSize < sizeRetainedByCollectedPersistents)
533 return 0; 533 return 0;
534 return estimationBaseSize - sizeRetainedByCollectedPersistents; 534 return estimationBaseSize - sizeRetainedByCollectedPersistents;
535 } 535 }
536 536
537 double ThreadState::heapGrowingRate() 537 double ThreadState::heapGrowingRate()
538 { 538 {
539 size_t currentSize = Heap::allocatedObjectSize() + Heap::markedObjectSize(); 539 size_t currentSize = Heap::heapStats().allocatedObjectSize() + Heap::heapSta ts().markedObjectSize();
540 size_t estimatedSize = estimatedLiveSize(Heap::markedObjectSizeAtLastComplet eSweep(), Heap::markedObjectSizeAtLastCompleteSweep()); 540 size_t estimatedSize = estimatedLiveSize(Heap::heapStats().markedObjectSizeA tLastCompleteSweep(), Heap::heapStats().markedObjectSizeAtLastCompleteSweep());
541 541
542 // If the estimatedSize is 0, we set a high growing rate to trigger a GC. 542 // If the estimatedSize is 0, we set a high growing rate to trigger a GC.
543 double growingRate = estimatedSize > 0 ? 1.0 * currentSize / estimatedSize : 100; 543 double growingRate = estimatedSize > 0 ? 1.0 * currentSize / estimatedSize : 100;
544 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::heapEsti matedSizeKB", std::min(estimatedSize / 1024, static_cast<size_t>(INT_MAX))); 544 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::heapEsti matedSizeKB", std::min(estimatedSize / 1024, static_cast<size_t>(INT_MAX)));
545 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::heapGrow ingRate", static_cast<int>(100 * growingRate)); 545 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::heapGrow ingRate", static_cast<int>(100 * growingRate));
546 return growingRate; 546 return growingRate;
547 } 547 }
548 548
549 double ThreadState::partitionAllocGrowingRate() 549 double ThreadState::partitionAllocGrowingRate()
550 { 550 {
551 size_t currentSize = WTF::Partitions::totalSizeOfCommittedPages(); 551 size_t currentSize = WTF::Partitions::totalSizeOfCommittedPages();
552 size_t estimatedSize = estimatedLiveSize(currentSize, Heap::partitionAllocSi zeAtLastGC()); 552 size_t estimatedSize = estimatedLiveSize(currentSize, Heap::heapStats().part itionAllocSizeAtLastGC());
553 553
554 // If the estimatedSize is 0, we set a high growing rate to trigger a GC. 554 // If the estimatedSize is 0, we set a high growing rate to trigger a GC.
555 double growingRate = estimatedSize > 0 ? 1.0 * currentSize / estimatedSize : 100; 555 double growingRate = estimatedSize > 0 ? 1.0 * currentSize / estimatedSize : 100;
556 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::partitio nAllocEstimatedSizeKB", std::min(estimatedSize / 1024, static_cast<size_t>(INT_M AX))); 556 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::partitio nAllocEstimatedSizeKB", std::min(estimatedSize / 1024, static_cast<size_t>(INT_M AX)));
557 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::partitio nAllocGrowingRate", static_cast<int>(100 * growingRate)); 557 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::partitio nAllocGrowingRate", static_cast<int>(100 * growingRate));
558 return growingRate; 558 return growingRate;
559 } 559 }
560 560
561 // TODO(haraken): We should improve the GC heuristics. The heuristics affect 561 // TODO(haraken): We should improve the GC heuristics. The heuristics affect
562 // performance significantly. 562 // performance significantly.
563 bool ThreadState::judgeGCThreshold(size_t totalMemorySizeThreshold, double heapG rowingRateThreshold) 563 bool ThreadState::judgeGCThreshold(size_t totalMemorySizeThreshold, double heapG rowingRateThreshold)
564 { 564 {
565 // If the allocated object size or the total memory size is small, don't tri gger a GC. 565 // If the allocated object size or the total memory size is small, don't tri gger a GC.
566 if (Heap::allocatedObjectSize() < 100 * 1024 || totalMemorySize() < totalMem orySizeThreshold) 566 if (Heap::heapStats().allocatedObjectSize() < 100 * 1024 || totalMemorySize( ) < totalMemorySizeThreshold)
567 return false; 567 return false;
568 // If the growing rate of Oilpan's heap or PartitionAlloc is high enough, 568 // If the growing rate of Oilpan's heap or PartitionAlloc is high enough,
569 // trigger a GC. 569 // trigger a GC.
570 #if PRINT_HEAP_STATS 570 #if PRINT_HEAP_STATS
571 dataLogF("heapGrowingRate=%.1lf, partitionAllocGrowingRate=%.1lf\n", heapGro wingRate(), partitionAllocGrowingRate()); 571 dataLogF("heapGrowingRate=%.1lf, partitionAllocGrowingRate=%.1lf\n", heapGro wingRate(), partitionAllocGrowingRate());
572 #endif 572 #endif
573 return heapGrowingRate() >= heapGrowingRateThreshold || partitionAllocGrowin gRate() >= heapGrowingRateThreshold; 573 return heapGrowingRate() >= heapGrowingRateThreshold || partitionAllocGrowin gRate() >= heapGrowingRateThreshold;
574 } 574 }
575 575
576 bool ThreadState::shouldScheduleIdleGC() 576 bool ThreadState::shouldScheduleIdleGC()
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 void ThreadState::performIdleGC(double deadlineSeconds) 750 void ThreadState::performIdleGC(double deadlineSeconds)
751 { 751 {
752 ASSERT(checkThread()); 752 ASSERT(checkThread());
753 ASSERT(isMainThread()); 753 ASSERT(isMainThread());
754 ASSERT(Platform::current()->currentThread()->scheduler()); 754 ASSERT(Platform::current()->currentThread()->scheduler());
755 755
756 if (gcState() != IdleGCScheduled) 756 if (gcState() != IdleGCScheduled)
757 return; 757 return;
758 758
759 double idleDeltaInSeconds = deadlineSeconds - monotonicallyIncreasingTime(); 759 double idleDeltaInSeconds = deadlineSeconds - monotonicallyIncreasingTime();
760 TRACE_EVENT2("blink_gc", "ThreadState::performIdleGC", "idleDeltaInSeconds", idleDeltaInSeconds, "estimatedMarkingTime", Heap::estimatedMarkingTime()); 760 TRACE_EVENT2("blink_gc", "ThreadState::performIdleGC", "idleDeltaInSeconds", idleDeltaInSeconds, "estimatedMarkingTime", Heap::heapStats().estimatedMarkingT ime());
761 if (idleDeltaInSeconds <= Heap::estimatedMarkingTime() && !Platform::current ()->currentThread()->scheduler()->canExceedIdleDeadlineIfRequired()) { 761 if (idleDeltaInSeconds <= Heap::heapStats().estimatedMarkingTime() && !Platf orm::current()->currentThread()->scheduler()->canExceedIdleDeadlineIfRequired()) {
762 // If marking is estimated to take longer than the deadline and we can't 762 // If marking is estimated to take longer than the deadline and we can't
763 // exceed the deadline, then reschedule for the next idle period. 763 // exceed the deadline, then reschedule for the next idle period.
764 scheduleIdleGC(); 764 scheduleIdleGC();
765 return; 765 return;
766 } 766 }
767 767
768 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithoutSweep , BlinkGC::IdleGC); 768 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithoutSweep , BlinkGC::IdleGC);
769 } 769 }
770 770
771 void ThreadState::performIdleLazySweep(double deadlineSeconds) 771 void ThreadState::performIdleLazySweep(double deadlineSeconds)
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 postSweep(); 1126 postSweep();
1127 } 1127 }
1128 1128
1129 void ThreadState::postSweep() 1129 void ThreadState::postSweep()
1130 { 1130 {
1131 ASSERT(checkThread()); 1131 ASSERT(checkThread());
1132 Heap::reportMemoryUsageForTracing(); 1132 Heap::reportMemoryUsageForTracing();
1133 1133
1134 if (isMainThread()) { 1134 if (isMainThread()) {
1135 double collectionRate = 0; 1135 double collectionRate = 0;
1136 if (Heap::objectSizeAtLastGC() > 0) 1136 if (Heap::heapStats().objectSizeAtLastGC() > 0)
1137 collectionRate = 1 - 1.0 * Heap::markedObjectSize() / Heap::objectSi zeAtLastGC(); 1137 collectionRate = 1 - 1.0 * Heap::heapStats().markedObjectSize() / He ap::heapStats().objectSizeAtLastGC();
1138 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::coll ectionRate", static_cast<int>(100 * collectionRate)); 1138 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::coll ectionRate", static_cast<int>(100 * collectionRate));
1139 1139
1140 #if PRINT_HEAP_STATS 1140 #if PRINT_HEAP_STATS
1141 dataLogF("ThreadState::postSweep (collectionRate=%d%%)\n", static_cast<i nt>(100 * collectionRate)); 1141 dataLogF("ThreadState::postSweep (collectionRate=%d%%)\n", static_cast<i nt>(100 * collectionRate));
1142 #endif 1142 #endif
1143 1143
1144 // Heap::markedObjectSize() may be underestimated here if any other 1144 // Heap::markedObjectSize() may be underestimated here if any other
1145 // thread has not yet finished lazy sweeping. 1145 // thread has not yet finished lazy sweeping.
1146 Heap::setMarkedObjectSizeAtLastCompleteSweep(Heap::markedObjectSize()); 1146 Heap::heapStats().setMarkedObjectSizeAtLastCompleteSweep(Heap::heapStats ().markedObjectSize());
1147 1147
1148 DEFINE_STATIC_LOCAL(CustomCountHistogram, objectSizeBeforeGCHistogram, ( "BlinkGC.ObjectSizeBeforeGC", 1, 4 * 1024 * 1024, 50)); 1148 DEFINE_STATIC_LOCAL(CustomCountHistogram, objectSizeBeforeGCHistogram, ( "BlinkGC.ObjectSizeBeforeGC", 1, 4 * 1024 * 1024, 50));
1149 objectSizeBeforeGCHistogram.count(Heap::objectSizeAtLastGC() / 1024); 1149 objectSizeBeforeGCHistogram.count(Heap::heapStats().objectSizeAtLastGC() / 1024);
1150 DEFINE_STATIC_LOCAL(CustomCountHistogram, objectSizeAfterGCHistogram, (" BlinkGC.ObjectSizeAfterGC", 1, 4 * 1024 * 1024, 50)); 1150 DEFINE_STATIC_LOCAL(CustomCountHistogram, objectSizeAfterGCHistogram, (" BlinkGC.ObjectSizeAfterGC", 1, 4 * 1024 * 1024, 50));
1151 objectSizeAfterGCHistogram.count(Heap::markedObjectSize() / 1024); 1151 objectSizeAfterGCHistogram.count(Heap::heapStats().markedObjectSize() / 1024);
1152 DEFINE_STATIC_LOCAL(CustomCountHistogram, collectionRateHistogram, ("Bli nkGC.CollectionRate", 1, 100, 20)); 1152 DEFINE_STATIC_LOCAL(CustomCountHistogram, collectionRateHistogram, ("Bli nkGC.CollectionRate", 1, 100, 20));
1153 collectionRateHistogram.count(static_cast<int>(100 * collectionRate)); 1153 collectionRateHistogram.count(static_cast<int>(100 * collectionRate));
1154 DEFINE_STATIC_LOCAL(CustomCountHistogram, timeForSweepHistogram, ("Blink GC.TimeForSweepingAllObjects", 1, 10 * 1000, 50)); 1154 DEFINE_STATIC_LOCAL(CustomCountHistogram, timeForSweepHistogram, ("Blink GC.TimeForSweepingAllObjects", 1, 10 * 1000, 50));
1155 timeForSweepHistogram.count(m_accumulatedSweepingTime); 1155 timeForSweepHistogram.count(m_accumulatedSweepingTime);
1156 1156
1157 1157
1158 #define COUNT_COLLECTION_RATE_HISTOGRAM_BY_GC_REASON(GCReason) \ 1158 #define COUNT_COLLECTION_RATE_HISTOGRAM_BY_GC_REASON(GCReason) \
1159 case BlinkGC::GCReason: { \ 1159 case BlinkGC::GCReason: { \
1160 DEFINE_STATIC_LOCAL(CustomCountHistogram, histogram, \ 1160 DEFINE_STATIC_LOCAL(CustomCountHistogram, histogram, \
1161 ("BlinkGC.CollectionRate_" #GCReason, 1, 100, 20)); \ 1161 ("BlinkGC.CollectionRate_" #GCReason, 1, 100, 20)); \
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 1307
1308 void ThreadState::resetHeapCounters() 1308 void ThreadState::resetHeapCounters()
1309 { 1309 {
1310 m_allocatedObjectSize = 0; 1310 m_allocatedObjectSize = 0;
1311 m_markedObjectSize = 0; 1311 m_markedObjectSize = 0;
1312 } 1312 }
1313 1313
1314 void ThreadState::increaseAllocatedObjectSize(size_t delta) 1314 void ThreadState::increaseAllocatedObjectSize(size_t delta)
1315 { 1315 {
1316 m_allocatedObjectSize += delta; 1316 m_allocatedObjectSize += delta;
1317 Heap::increaseAllocatedObjectSize(delta); 1317 Heap::heapStats().increaseAllocatedObjectSize(delta);
1318 } 1318 }
1319 1319
1320 void ThreadState::decreaseAllocatedObjectSize(size_t delta) 1320 void ThreadState::decreaseAllocatedObjectSize(size_t delta)
1321 { 1321 {
1322 m_allocatedObjectSize -= delta; 1322 m_allocatedObjectSize -= delta;
1323 Heap::decreaseAllocatedObjectSize(delta); 1323 Heap::heapStats().decreaseAllocatedObjectSize(delta);
1324 } 1324 }
1325 1325
1326 void ThreadState::increaseMarkedObjectSize(size_t delta) 1326 void ThreadState::increaseMarkedObjectSize(size_t delta)
1327 { 1327 {
1328 m_markedObjectSize += delta; 1328 m_markedObjectSize += delta;
1329 Heap::increaseMarkedObjectSize(delta); 1329 Heap::heapStats().increaseMarkedObjectSize(delta);
1330 } 1330 }
1331 1331
1332 void ThreadState::copyStackUntilSafePointScope() 1332 void ThreadState::copyStackUntilSafePointScope()
1333 { 1333 {
1334 if (!m_safePointScopeMarker || m_stackState == BlinkGC::NoHeapPointersOnStac k) 1334 if (!m_safePointScopeMarker || m_stackState == BlinkGC::NoHeapPointersOnStac k)
1335 return; 1335 return;
1336 1336
1337 Address* to = reinterpret_cast<Address*>(m_safePointScopeMarker); 1337 Address* to = reinterpret_cast<Address*>(m_safePointScopeMarker);
1338 Address* from = reinterpret_cast<Address*>(m_endOfStack); 1338 Address* from = reinterpret_cast<Address*>(m_endOfStack);
1339 RELEASE_ASSERT(from < to); 1339 RELEASE_ASSERT(from < to);
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 threadDump->addScalar("dead_count", "objects", totalDeadCount); 1557 threadDump->addScalar("dead_count", "objects", totalDeadCount);
1558 threadDump->addScalar("live_size", "bytes", totalLiveSize); 1558 threadDump->addScalar("live_size", "bytes", totalLiveSize);
1559 threadDump->addScalar("dead_size", "bytes", totalDeadSize); 1559 threadDump->addScalar("dead_size", "bytes", totalDeadSize);
1560 1560
1561 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c reateMemoryAllocatorDumpForCurrentGC(heapsDumpName); 1561 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c reateMemoryAllocatorDumpForCurrentGC(heapsDumpName);
1562 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()- >createMemoryAllocatorDumpForCurrentGC(classesDumpName); 1562 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()- >createMemoryAllocatorDumpForCurrentGC(classesDumpName);
1563 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->addOwners hipEdge(classesDump->guid(), heapsDump->guid()); 1563 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->addOwners hipEdge(classesDump->guid(), heapsDump->guid());
1564 } 1564 }
1565 1565
1566 } // namespace blink 1566 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/PersistentNode.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698