Chromium Code Reviews| Index: third_party/WebKit/Source/platform/heap/Heap.cpp |
| diff --git a/third_party/WebKit/Source/platform/heap/Heap.cpp b/third_party/WebKit/Source/platform/heap/Heap.cpp |
| index bf086aa367139e968bb66a85da19f122ecec1b8d..d0f83d8a13370cd0aca5863cb2c3e1c2f25111e9 100644 |
| --- a/third_party/WebKit/Source/platform/heap/Heap.cpp |
| +++ b/third_party/WebKit/Source/platform/heap/Heap.cpp |
| @@ -145,8 +145,9 @@ void ThreadHeapStats::decreaseAllocatedSpace(size_t delta) { |
| ProcessHeap::decreaseTotalAllocatedSpace(delta); |
| } |
| -ThreadHeap::ThreadHeap() |
| - : m_regionTree(WTF::makeUnique<RegionTree>()), |
| +ThreadHeap::ThreadHeap(ThreadState* threadState) |
| + : m_threadState(threadState), |
| + m_regionTree(WTF::makeUnique<RegionTree>()), |
| m_heapDoesNotContainCache(WTF::wrapUnique(new HeapDoesNotContainCache)), |
| m_safePointBarrier(WTF::makeUnique<SafePointBarrier>()), |
| m_freePagePool(WTF::wrapUnique(new PagePool)), |
| @@ -176,50 +177,13 @@ HashSet<ThreadHeap*>& ThreadHeap::allHeaps() { |
| return heaps; |
| } |
| -void ThreadHeap::attach(ThreadState* thread) { |
| - MutexLocker locker(m_threadAttachMutex); |
| - m_threads.insert(thread); |
| -} |
| - |
| -void ThreadHeap::detach(ThreadState* thread) { |
| - ASSERT(ThreadState::current() == thread); |
| - bool isLastThread = false; |
| - { |
| - // Grab the threadAttachMutex to ensure only one thread can shutdown at |
| - // a time and that no other thread can do a global GC. It also allows |
| - // safe iteration of the m_threads set which happens as part of |
| - // thread local GC asserts. We enter a safepoint while waiting for the |
| - // lock to avoid a dead-lock where another thread has already requested |
| - // GC. |
| - MutexLocker locker(m_threadAttachMutex); |
| - thread->runTerminationGC(); |
| - ASSERT(m_threads.contains(thread)); |
| - m_threads.remove(thread); |
| - isLastThread = m_threads.isEmpty(); |
| - } |
| - if (thread->isMainThread()) |
|
sof
2017/02/15 09:18:21
we could move this to the dtor, up to you.
|
| - DCHECK_EQ(heapStats().allocatedSpace(), 0u); |
| - if (isLastThread) |
| - delete this; |
| -} |
| - |
| #if DCHECK_IS_ON() |
| BasePage* ThreadHeap::findPageFromAddress(Address address) { |
| - MutexLocker locker(m_threadAttachMutex); |
| - for (ThreadState* state : m_threads) { |
| - if (BasePage* page = state->findPageFromAddress(address)) |
| - return page; |
| - } |
| - return nullptr; |
| + return m_threadState->findPageFromAddress(address); |
| } |
| bool ThreadHeap::isAtSafePoint() { |
| - MutexLocker locker(m_threadAttachMutex); |
| - for (ThreadState* state : m_threads) { |
| - if (!state->isAtSafePoint()) |
| - return false; |
| - } |
| - return true; |
| + return m_threadState->isAtSafePoint(); |
| } |
| #endif |
| @@ -371,19 +335,16 @@ void ThreadHeap::decommitCallbackStacks() { |
| void ThreadHeap::preGC() { |
| ASSERT(!ThreadState::current()->isInGC()); |
| - for (ThreadState* state : m_threads) |
| - state->preGC(); |
| + m_threadState->preGC(); |
| } |
| void ThreadHeap::postGC(BlinkGC::GCType gcType) { |
| ASSERT(ThreadState::current()->isInGC()); |
| - for (ThreadState* state : m_threads) |
| - state->postGC(gcType); |
| + m_threadState->postGC(gcType); |
| } |
| void ThreadHeap::preSweep(BlinkGC::GCType gcType) { |
| - for (ThreadState* state : m_threads) |
| - state->preSweep(gcType); |
| + m_threadState->preSweep(gcType); |
| } |
| void ThreadHeap::processMarkingStack(Visitor* visitor) { |
| @@ -535,15 +496,12 @@ void ThreadHeap::reportMemoryUsageForTracing() { |
| } |
| size_t ThreadHeap::objectPayloadSizeForTesting() { |
| - // MEMO: is threadAttachMutex locked? |
| size_t objectPayloadSize = 0; |
| - for (ThreadState* state : m_threads) { |
| - state->setGCState(ThreadState::GCRunning); |
| - state->makeConsistentForGC(); |
| - objectPayloadSize += state->objectPayloadSizeForTesting(); |
| - state->setGCState(ThreadState::Sweeping); |
| - state->setGCState(ThreadState::NoGCScheduled); |
| - } |
| + m_threadState->setGCState(ThreadState::GCRunning); |
| + m_threadState->makeConsistentForGC(); |
| + objectPayloadSize += m_threadState->objectPayloadSizeForTesting(); |
| + m_threadState->setGCState(ThreadState::Sweeping); |
| + m_threadState->setGCState(ThreadState::NoGCScheduled); |
| return objectPayloadSize; |
| } |
| @@ -552,15 +510,13 @@ void ThreadHeap::visitPersistentRoots(Visitor* visitor) { |
| TRACE_EVENT0("blink_gc", "ThreadHeap::visitPersistentRoots"); |
| ProcessHeap::crossThreadPersistentRegion().tracePersistentNodes(visitor); |
| - for (ThreadState* state : m_threads) |
| - state->visitPersistents(visitor); |
| + m_threadState->visitPersistents(visitor); |
| } |
| void ThreadHeap::visitStackRoots(Visitor* visitor) { |
| ASSERT(ThreadState::current()->isInGC()); |
| TRACE_EVENT0("blink_gc", "ThreadHeap::visitStackRoots"); |
| - for (ThreadState* state : m_threads) |
| - state->visitStack(visitor); |
| + m_threadState->visitStack(visitor); |
| } |
| void ThreadHeap::enterSafePoint(ThreadState* threadState) { |
| @@ -588,8 +544,7 @@ void ThreadHeap::resetHeapCounters() { |
| ProcessHeap::decreaseTotalMarkedObjectSize(m_stats.markedObjectSize()); |
| m_stats.reset(); |
| - for (ThreadState* state : m_threads) |
| - state->resetHeapCounters(); |
| + m_threadState->resetHeapCounters(); |
| } |
| ThreadHeap* ThreadHeap::s_mainThreadHeap = nullptr; |