| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 bool m_shouldResumeThreads; | 98 bool m_shouldResumeThreads; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 void Heap::flushHeapDoesNotContainCache() | 101 void Heap::flushHeapDoesNotContainCache() |
| 102 { | 102 { |
| 103 s_heapDoesNotContainCache->flush(); | 103 s_heapDoesNotContainCache->flush(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ProcessHeap::init() |
| 107 { |
| 108 s_totalAllocatedSpace = 0; |
| 109 s_totalAllocatedObjectSize = 0; |
| 110 s_totalMarkedObjectSize = 0; |
| 111 s_isLowEndDevice = base::SysInfo::IsLowEndDevice(); |
| 112 } |
| 113 |
| 106 void Heap::init() | 114 void Heap::init() |
| 107 { | 115 { |
| 108 ThreadState::init(); | 116 ThreadState::init(); |
| 117 ProcessHeap::init(); |
| 109 s_markingStack = new CallbackStack(); | 118 s_markingStack = new CallbackStack(); |
| 110 s_postMarkingCallbackStack = new CallbackStack(); | 119 s_postMarkingCallbackStack = new CallbackStack(); |
| 111 s_globalWeakCallbackStack = new CallbackStack(); | 120 s_globalWeakCallbackStack = new CallbackStack(); |
| 112 // Use smallest supported block size for ephemerons. | 121 // Use smallest supported block size for ephemerons. |
| 113 s_ephemeronStack = new CallbackStack(CallbackStack::kMinimalBlockSize); | 122 s_ephemeronStack = new CallbackStack(CallbackStack::kMinimalBlockSize); |
| 114 s_heapDoesNotContainCache = new HeapDoesNotContainCache(); | 123 s_heapDoesNotContainCache = new HeapDoesNotContainCache(); |
| 115 s_freePagePool = new FreePagePool(); | 124 s_freePagePool = new FreePagePool(); |
| 116 s_orphanedPagePool = new OrphanedPagePool(); | 125 s_orphanedPagePool = new OrphanedPagePool(); |
| 117 s_allocatedSpace = 0; | 126 s_allocatedSpace = 0; |
| 118 s_allocatedObjectSize = 0; | 127 s_allocatedObjectSize = 0; |
| 119 s_objectSizeAtLastGC = 0; | 128 s_objectSizeAtLastGC = 0; |
| 120 s_markedObjectSize = 0; | |
| 121 s_markedObjectSizeAtLastCompleteSweep = 0; | 129 s_markedObjectSizeAtLastCompleteSweep = 0; |
| 122 s_wrapperCount = 0; | 130 s_wrapperCount = 0; |
| 123 s_wrapperCountAtLastGC = 0; | 131 s_wrapperCountAtLastGC = 0; |
| 124 s_collectedWrapperCount = 0; | 132 s_collectedWrapperCount = 0; |
| 125 s_partitionAllocSizeAtLastGC = WTF::Partitions::totalSizeOfCommittedPages(); | 133 s_partitionAllocSizeAtLastGC = WTF::Partitions::totalSizeOfCommittedPages(); |
| 126 s_estimatedMarkingTimePerByte = 0.0; | 134 s_estimatedMarkingTimePerByte = 0.0; |
| 127 s_isLowEndDevice = base::SysInfo::IsLowEndDevice(); | |
| 128 s_lastGCReason = BlinkGC::NumberOfGCReason; | 135 s_lastGCReason = BlinkGC::NumberOfGCReason; |
| 129 #if ENABLE(ASSERT) | |
| 130 s_gcGeneration = 1; | |
| 131 #endif | |
| 132 | 136 |
| 133 GCInfoTable::init(); | 137 GCInfoTable::init(); |
| 134 | 138 |
| 135 if (Platform::current() && Platform::current()->currentThread()) | 139 if (Platform::current() && Platform::current()->currentThread()) |
| 136 Platform::current()->registerMemoryDumpProvider(BlinkGCMemoryDumpProvide
r::instance(), "BlinkGC"); | 140 Platform::current()->registerMemoryDumpProvider(BlinkGCMemoryDumpProvide
r::instance(), "BlinkGC"); |
| 137 } | 141 } |
| 138 | 142 |
| 139 void Heap::shutdown() | 143 void Heap::shutdown() |
| 140 { | 144 { |
| 141 ASSERT(s_markingStack); | 145 ASSERT(s_markingStack); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 158 s_postMarkingCallbackStack = nullptr; | 162 s_postMarkingCallbackStack = nullptr; |
| 159 delete s_markingStack; | 163 delete s_markingStack; |
| 160 s_markingStack = nullptr; | 164 s_markingStack = nullptr; |
| 161 delete s_ephemeronStack; | 165 delete s_ephemeronStack; |
| 162 s_ephemeronStack = nullptr; | 166 s_ephemeronStack = nullptr; |
| 163 GCInfoTable::shutdown(); | 167 GCInfoTable::shutdown(); |
| 164 ThreadState::shutdown(); | 168 ThreadState::shutdown(); |
| 165 ASSERT(Heap::allocatedSpace() == 0); | 169 ASSERT(Heap::allocatedSpace() == 0); |
| 166 } | 170 } |
| 167 | 171 |
| 168 CrossThreadPersistentRegion& Heap::crossThreadPersistentRegion() | 172 CrossThreadPersistentRegion& ProcessHeap::crossThreadPersistentRegion() |
| 169 { | 173 { |
| 170 DEFINE_THREAD_SAFE_STATIC_LOCAL(CrossThreadPersistentRegion, persistentRegio
n, new CrossThreadPersistentRegion()); | 174 DEFINE_THREAD_SAFE_STATIC_LOCAL(CrossThreadPersistentRegion, persistentRegio
n, new CrossThreadPersistentRegion()); |
| 171 return persistentRegion; | 175 return persistentRegion; |
| 172 } | 176 } |
| 173 | 177 |
| 178 bool ProcessHeap::s_isLowEndDevice = false; |
| 179 size_t ProcessHeap::s_totalAllocatedSpace = 0; |
| 180 size_t ProcessHeap::s_totalAllocatedObjectSize = 0; |
| 181 size_t ProcessHeap::s_totalMarkedObjectSize = 0; |
| 182 |
| 174 #if ENABLE(ASSERT) | 183 #if ENABLE(ASSERT) |
| 175 BasePage* Heap::findPageFromAddress(Address address) | 184 BasePage* Heap::findPageFromAddress(Address address) |
| 176 { | 185 { |
| 177 MutexLocker lock(ThreadState::threadAttachMutex()); | 186 MutexLocker lock(ThreadState::threadAttachMutex()); |
| 178 for (ThreadState* state : ThreadState::attachedThreads()) { | 187 for (ThreadState* state : ThreadState::attachedThreads()) { |
| 179 if (BasePage* page = state->findPageFromAddress(address)) | 188 if (BasePage* page = state->findPageFromAddress(address)) |
| 180 return page; | 189 return page; |
| 181 } | 190 } |
| 182 return nullptr; | 191 return nullptr; |
| 183 } | 192 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 double markingTimeInMilliseconds = WTF::currentTimeMS() - startTime; | 414 double markingTimeInMilliseconds = WTF::currentTimeMS() - startTime; |
| 406 s_estimatedMarkingTimePerByte = totalObjectSize ? (markingTimeInMilliseconds
/ 1000 / totalObjectSize) : 0; | 415 s_estimatedMarkingTimePerByte = totalObjectSize ? (markingTimeInMilliseconds
/ 1000 / totalObjectSize) : 0; |
| 407 | 416 |
| 408 #if PRINT_HEAP_STATS | 417 #if PRINT_HEAP_STATS |
| 409 dataLogF("Heap::collectGarbage (gcReason=%s, lazySweeping=%d, time=%.1lfms)\
n", gcReasonString(reason), gcType == BlinkGC::GCWithoutSweep, markingTimeInMill
iseconds); | 418 dataLogF("Heap::collectGarbage (gcReason=%s, lazySweeping=%d, time=%.1lfms)\
n", gcReasonString(reason), gcType == BlinkGC::GCWithoutSweep, markingTimeInMill
iseconds); |
| 410 #endif | 419 #endif |
| 411 | 420 |
| 412 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, markingTimeHistogram,
new CustomCountHistogram("BlinkGC.CollectGarbage", 0, 10 * 1000, 50)); | 421 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, markingTimeHistogram,
new CustomCountHistogram("BlinkGC.CollectGarbage", 0, 10 * 1000, 50)); |
| 413 markingTimeHistogram.count(markingTimeInMilliseconds); | 422 markingTimeHistogram.count(markingTimeInMilliseconds); |
| 414 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, totalObjectSpaceHistog
ram, new CustomCountHistogram("BlinkGC.TotalObjectSpace", 0, 4 * 1024 * 1024, 50
)); | 423 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, totalObjectSpaceHistog
ram, new CustomCountHistogram("BlinkGC.TotalObjectSpace", 0, 4 * 1024 * 1024, 50
)); |
| 415 totalObjectSpaceHistogram.count(Heap::allocatedObjectSize() / 1024); | 424 totalObjectSpaceHistogram.count(ProcessHeap::totalAllocatedObjectSize() / 10
24); |
| 416 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, totalAllocatedSpaceHis
togram, new CustomCountHistogram("BlinkGC.TotalAllocatedSpace", 0, 4 * 1024 * 10
24, 50)); | 425 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, totalAllocatedSpaceHis
togram, new CustomCountHistogram("BlinkGC.TotalAllocatedSpace", 0, 4 * 1024 * 10
24, 50)); |
| 417 totalAllocatedSpaceHistogram.count(Heap::allocatedSpace() / 1024); | 426 totalAllocatedSpaceHistogram.count(ProcessHeap::totalAllocatedSpace() / 1024
); |
| 418 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, gcReasonHistogram, new
EnumerationHistogram("BlinkGC.GCReason", BlinkGC::NumberOfGCReason)); | 427 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, gcReasonHistogram, new
EnumerationHistogram("BlinkGC.GCReason", BlinkGC::NumberOfGCReason)); |
| 419 gcReasonHistogram.count(reason); | 428 gcReasonHistogram.count(reason); |
| 420 | 429 |
| 421 s_lastGCReason = reason; | 430 s_lastGCReason = reason; |
| 422 | 431 |
| 423 Heap::reportMemoryUsageHistogram(); | 432 Heap::reportMemoryUsageHistogram(); |
| 424 WTF::Partitions::reportMemoryUsageHistogram(); | 433 WTF::Partitions::reportMemoryUsageHistogram(); |
| 425 | 434 |
| 426 postGC(gcType); | 435 postGC(gcType); |
| 427 Heap::decommitCallbackStacks(); | 436 Heap::decommitCallbackStacks(); |
| 428 | |
| 429 #if ENABLE(ASSERT) | |
| 430 // 0 is used to figure non-assigned area, so avoid to use 0 in s_gcGeneratio
n. | |
| 431 if (++s_gcGeneration == 0) { | |
| 432 s_gcGeneration = 1; | |
| 433 } | |
| 434 #endif | |
| 435 } | 437 } |
| 436 | 438 |
| 437 void Heap::collectGarbageForTerminatingThread(ThreadState* state) | 439 void Heap::collectGarbageForTerminatingThread(ThreadState* state) |
| 438 { | 440 { |
| 439 { | 441 { |
| 440 // A thread-specific termination GC must not allow other global GCs to g
o | 442 // A thread-specific termination GC must not allow other global GCs to g
o |
| 441 // ahead while it is running, hence the termination GC does not enter a | 443 // ahead while it is running, hence the termination GC does not enter a |
| 442 // safepoint. VisitorScope will not enter also a safepoint scope for | 444 // safepoint. VisitorScope will not enter also a safepoint scope for |
| 443 // ThreadTerminationGC. | 445 // ThreadTerminationGC. |
| 444 OwnPtr<Visitor> visitor = Visitor::create(state, BlinkGC::ThreadTerminat
ionGC); | 446 OwnPtr<Visitor> visitor = Visitor::create(state, BlinkGC::ThreadTerminat
ionGC); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 size_t Heap::s_allocatedSpace = 0; | 659 size_t Heap::s_allocatedSpace = 0; |
| 658 size_t Heap::s_allocatedObjectSize = 0; | 660 size_t Heap::s_allocatedObjectSize = 0; |
| 659 size_t Heap::s_objectSizeAtLastGC = 0; | 661 size_t Heap::s_objectSizeAtLastGC = 0; |
| 660 size_t Heap::s_markedObjectSize = 0; | 662 size_t Heap::s_markedObjectSize = 0; |
| 661 size_t Heap::s_markedObjectSizeAtLastCompleteSweep = 0; | 663 size_t Heap::s_markedObjectSizeAtLastCompleteSweep = 0; |
| 662 size_t Heap::s_wrapperCount = 0; | 664 size_t Heap::s_wrapperCount = 0; |
| 663 size_t Heap::s_wrapperCountAtLastGC = 0; | 665 size_t Heap::s_wrapperCountAtLastGC = 0; |
| 664 size_t Heap::s_collectedWrapperCount = 0; | 666 size_t Heap::s_collectedWrapperCount = 0; |
| 665 size_t Heap::s_partitionAllocSizeAtLastGC = 0; | 667 size_t Heap::s_partitionAllocSizeAtLastGC = 0; |
| 666 double Heap::s_estimatedMarkingTimePerByte = 0.0; | 668 double Heap::s_estimatedMarkingTimePerByte = 0.0; |
| 667 bool Heap::s_isLowEndDevice = false; | 669 |
| 668 BlinkGC::GCReason Heap::s_lastGCReason = BlinkGC::NumberOfGCReason; | 670 BlinkGC::GCReason Heap::s_lastGCReason = BlinkGC::NumberOfGCReason; |
| 669 #if ENABLE(ASSERT) | |
| 670 uint16_t Heap::s_gcGeneration = 0; | |
| 671 #endif | |
| 672 | 671 |
| 673 } // namespace blink | 672 } // namespace blink |
| OLD | NEW |