Chromium Code Reviews| Index: Source/platform/heap/Heap.cpp |
| diff --git a/Source/platform/heap/Heap.cpp b/Source/platform/heap/Heap.cpp |
| index ebdfabeafd5697c4653865246d80c37b948394c0..de08e8c2b1cc629e6b9e97f6dd1c174a57297ae2 100644 |
| --- a/Source/platform/heap/Heap.cpp |
| +++ b/Source/platform/heap/Heap.cpp |
| @@ -609,31 +609,51 @@ Address BaseHeap::lazySweep(size_t allocationSize, size_t gcInfoIndex) |
| return result; |
| } |
| -void BaseHeap::completeSweep() |
| +void BaseHeap::sweepUnsweptPage() |
| +{ |
| + BasePage* page = m_firstUnsweptPage; |
| + if (page->isEmpty()) { |
| + page->unlink(&m_firstUnsweptPage); |
| + page->removeFromHeap(); |
| + } else { |
| + // Sweep a page and move the page from m_firstUnsweptPages to |
| + // m_firstPages. |
| + page->sweep(); |
| + page->unlink(&m_firstUnsweptPage); |
| + page->link(&m_firstPage); |
| + page->markAsSwept(); |
| + } |
| +} |
| + |
| +bool BaseHeap::lazySweepWithDeadline(double deadlineSeconds) |
| { |
| RELEASE_ASSERT(threadState()->isSweepingInProgress()); |
| ASSERT(threadState()->sweepForbidden()); |
| - if (threadState()->isMainThread()) |
| - ScriptForbiddenScope::enter(); |
| - |
| + int pageCount = 1; |
| while (m_firstUnsweptPage) { |
| - BasePage* page = m_firstUnsweptPage; |
| - if (page->isEmpty()) { |
| - page->unlink(&m_firstUnsweptPage); |
| - page->removeFromHeap(); |
| - } else { |
| - // Sweep a page and move the page from m_firstUnsweptPages to |
| - // m_firstPages. |
| - page->sweep(); |
| - page->unlink(&m_firstUnsweptPage); |
| - page->link(&m_firstPage); |
| - page->markAsSwept(); |
| + sweepUnsweptPage(); |
| + // It might be heavy to call Platform::current()->monotonicallyIncreasingTime() |
| + // per page (i.e., 128 KB sweep or one LargeObject sweep), so we check |
| + // the deadline per 10 pages. |
| + if (pageCount % 10 == 0) { |
| + if (deadlineSeconds <= Platform::current()->monotonicallyIncreasingTime()) { |
|
rmcilroy
2015/03/31 13:01:30
Could we add some slack here (e.g., deadlineSecond
haraken
2015/03/31 13:07:45
That is a hard question to answer since the time t
rmcilroy
2015/03/31 13:19:26
Right I thought this might be the case.
|
| + return false; |
| + } |
| } |
| + pageCount++; |
| } |
| + return true; |
| +} |
| - if (threadState()->isMainThread()) |
| - ScriptForbiddenScope::exit(); |
| +void BaseHeap::completeSweep() |
| +{ |
| + RELEASE_ASSERT(threadState()->isSweepingInProgress()); |
| + ASSERT(threadState()->sweepForbidden()); |
| + |
| + while (m_firstUnsweptPage) { |
| + sweepUnsweptPage(); |
| + } |
| } |
| NormalPageHeap::NormalPageHeap(ThreadState* state, int index) |