OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/heap/ThreadState.h" | 31 #include "platform/heap/ThreadState.h" |
32 | 32 |
| 33 #include "platform/Histogram.h" |
33 #include "platform/ScriptForbiddenScope.h" | 34 #include "platform/ScriptForbiddenScope.h" |
34 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
35 #include "platform/heap/BlinkGCMemoryDumpProvider.h" | 36 #include "platform/heap/BlinkGCMemoryDumpProvider.h" |
36 #include "platform/heap/CallbackStack.h" | 37 #include "platform/heap/CallbackStack.h" |
37 #include "platform/heap/Handle.h" | 38 #include "platform/heap/Handle.h" |
38 #include "platform/heap/Heap.h" | 39 #include "platform/heap/Heap.h" |
39 #include "platform/heap/MarkingVisitor.h" | 40 #include "platform/heap/MarkingVisitor.h" |
40 #include "platform/heap/SafePoint.h" | 41 #include "platform/heap/SafePoint.h" |
41 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
42 #include "public/platform/WebMemoryAllocatorDump.h" | 43 #include "public/platform/WebMemoryAllocatorDump.h" |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 // Due to the complexity, we just forbid allocations. | 479 // Due to the complexity, we just forbid allocations. |
479 NoAllocationScope noAllocationScope(this); | 480 NoAllocationScope noAllocationScope(this); |
480 | 481 |
481 MarkingVisitor<Visitor::WeakProcessing> weakProcessingVisitor; | 482 MarkingVisitor<Visitor::WeakProcessing> weakProcessingVisitor; |
482 | 483 |
483 // Perform thread-specific weak processing. | 484 // Perform thread-specific weak processing. |
484 while (popAndInvokeThreadLocalWeakCallback(&weakProcessingVisitor)) { } | 485 while (popAndInvokeThreadLocalWeakCallback(&weakProcessingVisitor)) { } |
485 | 486 |
486 if (isMainThread()) { | 487 if (isMainThread()) { |
487 double timeForThreadLocalWeakProcessing = WTF::currentTimeMS() - startTi
me; | 488 double timeForThreadLocalWeakProcessing = WTF::currentTimeMS() - startTi
me; |
488 Platform::current()->histogramCustomCounts("BlinkGC.timeForThreadLocalWe
akProcessing", timeForThreadLocalWeakProcessing, 1, 10 * 1000, 50); | 489 DEFINE_STATIC_LOCAL(CustomCountHistogram, timeForWeakHistogram, ("BlinkG
C.timeForThreadLocalWeakProcessing", 1, 10 * 1000, 50)); |
| 490 timeForWeakHistogram.count(timeForThreadLocalWeakProcessing); |
489 } | 491 } |
490 } | 492 } |
491 | 493 |
492 size_t ThreadState::totalMemorySize() | 494 size_t ThreadState::totalMemorySize() |
493 { | 495 { |
494 return Heap::allocatedObjectSize() + Heap::markedObjectSize() + WTF::Partiti
ons::totalSizeOfCommittedPages(); | 496 return Heap::allocatedObjectSize() + Heap::markedObjectSize() + WTF::Partiti
ons::totalSizeOfCommittedPages(); |
495 } | 497 } |
496 | 498 |
497 size_t ThreadState::estimatedLiveSize(size_t estimationBaseSize, size_t sizeAtLa
stGC) | 499 size_t ThreadState::estimatedLiveSize(size_t estimationBaseSize, size_t sizeAtLa
stGC) |
498 { | 500 { |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 TRACE_EVENT0("blink_gc", "ThreadState::completeSweep"); | 1095 TRACE_EVENT0("blink_gc", "ThreadState::completeSweep"); |
1094 double startTime = WTF::currentTimeMS(); | 1096 double startTime = WTF::currentTimeMS(); |
1095 | 1097 |
1096 static_assert(BlinkGC::EagerSweepHeapIndex == 0, "Eagerly swept heaps mu
st be processed first."); | 1098 static_assert(BlinkGC::EagerSweepHeapIndex == 0, "Eagerly swept heaps mu
st be processed first."); |
1097 for (int i = 0; i < BlinkGC::NumberOfHeaps; i++) | 1099 for (int i = 0; i < BlinkGC::NumberOfHeaps; i++) |
1098 m_heaps[i]->completeSweep(); | 1100 m_heaps[i]->completeSweep(); |
1099 | 1101 |
1100 double timeForCompleteSweep = WTF::currentTimeMS() - startTime; | 1102 double timeForCompleteSweep = WTF::currentTimeMS() - startTime; |
1101 accumulateSweepingTime(timeForCompleteSweep); | 1103 accumulateSweepingTime(timeForCompleteSweep); |
1102 | 1104 |
1103 if (isMainThread()) | 1105 if (isMainThread()) { |
1104 Platform::current()->histogramCustomCounts("BlinkGC.CompleteSweep",
timeForCompleteSweep, 1, 10 * 1000, 50); | 1106 DEFINE_STATIC_LOCAL(CustomCountHistogram, completeSweepHistogram, ("
BlinkGC.CompleteSweep", 1, 10 * 1000, 50)); |
| 1107 completeSweepHistogram.count(timeForCompleteSweep); |
| 1108 } |
1105 } | 1109 } |
1106 | 1110 |
1107 postSweep(); | 1111 postSweep(); |
1108 } | 1112 } |
1109 | 1113 |
1110 void ThreadState::postSweep() | 1114 void ThreadState::postSweep() |
1111 { | 1115 { |
1112 ASSERT(checkThread()); | 1116 ASSERT(checkThread()); |
1113 Heap::reportMemoryUsageForTracing(); | 1117 Heap::reportMemoryUsageForTracing(); |
1114 | 1118 |
1115 if (isMainThread()) { | 1119 if (isMainThread()) { |
1116 double collectionRate = 0; | 1120 double collectionRate = 0; |
1117 if (Heap::objectSizeAtLastGC() > 0) | 1121 if (Heap::objectSizeAtLastGC() > 0) |
1118 collectionRate = 1 - 1.0 * Heap::markedObjectSize() / Heap::objectSi
zeAtLastGC(); | 1122 collectionRate = 1 - 1.0 * Heap::markedObjectSize() / Heap::objectSi
zeAtLastGC(); |
1119 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::coll
ectionRate", static_cast<int>(100 * collectionRate)); | 1123 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "ThreadState::coll
ectionRate", static_cast<int>(100 * collectionRate)); |
1120 | 1124 |
1121 #if PRINT_HEAP_STATS | 1125 #if PRINT_HEAP_STATS |
1122 dataLogF("ThreadState::postSweep (collectionRate=%d%%)\n", static_cast<i
nt>(100 * collectionRate)); | 1126 dataLogF("ThreadState::postSweep (collectionRate=%d%%)\n", static_cast<i
nt>(100 * collectionRate)); |
1123 #endif | 1127 #endif |
1124 | 1128 |
1125 // Heap::markedObjectSize() may be underestimated here if any other | 1129 // Heap::markedObjectSize() may be underestimated here if any other |
1126 // thread has not yet finished lazy sweeping. | 1130 // thread has not yet finished lazy sweeping. |
1127 Heap::setMarkedObjectSizeAtLastCompleteSweep(Heap::markedObjectSize()); | 1131 Heap::setMarkedObjectSizeAtLastCompleteSweep(Heap::markedObjectSize()); |
1128 | 1132 |
1129 Platform::current()->histogramCustomCounts("BlinkGC.ObjectSizeBeforeGC",
Heap::objectSizeAtLastGC() / 1024, 1, 4 * 1024 * 1024, 50); | 1133 DEFINE_STATIC_LOCAL(CustomCountHistogram, objectSizeBeforeGCHistogram, (
"BlinkGC.ObjectSizeBeforeGC", 1, 4 * 1024 * 1024, 50)); |
1130 Platform::current()->histogramCustomCounts("BlinkGC.ObjectSizeAfterGC",
Heap::markedObjectSize() / 1024, 1, 4 * 1024 * 1024, 50); | 1134 objectSizeBeforeGCHistogram.count(Heap::objectSizeAtLastGC() / 1024); |
1131 Platform::current()->histogramCustomCounts("BlinkGC.CollectionRate", sta
tic_cast<int>(100 * collectionRate), 1, 100, 20); | 1135 DEFINE_STATIC_LOCAL(CustomCountHistogram, objectSizeAfterGCHistogram, ("
BlinkGC.ObjectSizeAfterGC", 1, 4 * 1024 * 1024, 50)); |
1132 Platform::current()->histogramCustomCounts("BlinkGC.TimeForSweepingAllOb
jects", m_accumulatedSweepingTime, 1, 10 * 1000, 50); | 1136 objectSizeAfterGCHistogram.count(Heap::markedObjectSize() / 1024); |
| 1137 DEFINE_STATIC_LOCAL(CustomCountHistogram, collectionRateHistogram, ("Bli
nkGC.CollectionRate", 1, 100, 20)); |
| 1138 collectionRateHistogram.count(static_cast<int>(100 * collectionRate)); |
| 1139 DEFINE_STATIC_LOCAL(CustomCountHistogram, timeForSweepHistogram, ("Blink
GC.TimeForSweepingAllObjects", 1, 10 * 1000, 50)); |
| 1140 timeForSweepHistogram.count(m_accumulatedSweepingTime); |
1133 } | 1141 } |
1134 | 1142 |
1135 switch (gcState()) { | 1143 switch (gcState()) { |
1136 case Sweeping: | 1144 case Sweeping: |
1137 setGCState(NoGCScheduled); | 1145 setGCState(NoGCScheduled); |
1138 break; | 1146 break; |
1139 case SweepingAndPreciseGCScheduled: | 1147 case SweepingAndPreciseGCScheduled: |
1140 setGCState(PreciseGCScheduled); | 1148 setGCState(PreciseGCScheduled); |
1141 break; | 1149 break; |
1142 case SweepingAndIdleGCScheduled: | 1150 case SweepingAndIdleGCScheduled: |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 auto entry = it; | 1376 auto entry = it; |
1369 done = it == m_orderedPreFinalizers.begin(); | 1377 done = it == m_orderedPreFinalizers.begin(); |
1370 if (!done) | 1378 if (!done) |
1371 --it; | 1379 --it; |
1372 if ((entry->second)(entry->first)) | 1380 if ((entry->second)(entry->first)) |
1373 m_orderedPreFinalizers.remove(entry); | 1381 m_orderedPreFinalizers.remove(entry); |
1374 } while (!done); | 1382 } while (!done); |
1375 } | 1383 } |
1376 if (isMainThread()) { | 1384 if (isMainThread()) { |
1377 double timeForInvokingPreFinalizers = WTF::currentTimeMS() - startTime; | 1385 double timeForInvokingPreFinalizers = WTF::currentTimeMS() - startTime; |
1378 Platform::current()->histogramCustomCounts("BlinkGC.TimeForInvokingPreFi
nalizers", timeForInvokingPreFinalizers, 1, 10 * 1000, 50); | 1386 DEFINE_STATIC_LOCAL(CustomCountHistogram, preFinalizersHistogram, ("Blin
kGC.TimeForInvokingPreFinalizers", 1, 10 * 1000, 50)); |
| 1387 preFinalizersHistogram.count(timeForInvokingPreFinalizers); |
1379 } | 1388 } |
1380 } | 1389 } |
1381 | 1390 |
1382 void ThreadState::clearHeapAges() | 1391 void ThreadState::clearHeapAges() |
1383 { | 1392 { |
1384 memset(m_heapAges, 0, sizeof(size_t) * BlinkGC::NumberOfHeaps); | 1393 memset(m_heapAges, 0, sizeof(size_t) * BlinkGC::NumberOfHeaps); |
1385 memset(m_likelyToBePromptlyFreed.get(), 0, sizeof(int) * likelyToBePromptlyF
reedArraySize); | 1394 memset(m_likelyToBePromptlyFreed.get(), 0, sizeof(int) * likelyToBePromptlyF
reedArraySize); |
1386 m_currentHeapAges = 0; | 1395 m_currentHeapAges = 0; |
1387 } | 1396 } |
1388 | 1397 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 threadDump->addScalar("dead_count", "objects", totalDeadCount); | 1509 threadDump->addScalar("dead_count", "objects", totalDeadCount); |
1501 threadDump->addScalar("live_size", "bytes", totalLiveSize); | 1510 threadDump->addScalar("live_size", "bytes", totalLiveSize); |
1502 threadDump->addScalar("dead_size", "bytes", totalDeadSize); | 1511 threadDump->addScalar("dead_size", "bytes", totalDeadSize); |
1503 | 1512 |
1504 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c
reateMemoryAllocatorDumpForCurrentGC(heapsDumpName); | 1513 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c
reateMemoryAllocatorDumpForCurrentGC(heapsDumpName); |
1505 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()-
>createMemoryAllocatorDumpForCurrentGC(classesDumpName); | 1514 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()-
>createMemoryAllocatorDumpForCurrentGC(classesDumpName); |
1506 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->addOwners
hipEdge(classesDump->guid(), heapsDump->guid()); | 1515 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->addOwners
hipEdge(classesDump->guid(), heapsDump->guid()); |
1507 } | 1516 } |
1508 | 1517 |
1509 } // namespace blink | 1518 } // namespace blink |
OLD | NEW |