Index: Source/platform/heap/Heap.cpp |
diff --git a/Source/platform/heap/Heap.cpp b/Source/platform/heap/Heap.cpp |
index 8d427e01653243a1ed74979eca0a426d27464632..7027df8157fdf6f9c0dfb096ea6ffc1ea7dad09f 100644 |
--- a/Source/platform/heap/Heap.cpp |
+++ b/Source/platform/heap/Heap.cpp |
@@ -609,31 +609,56 @@ 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) |
+{ |
+ // 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. |
+ static const int deadlineCheckInterval = 10; |
+ |
RELEASE_ASSERT(threadState()->isSweepingInProgress()); |
ASSERT(threadState()->sweepForbidden()); |
+ ASSERT(!threadState()->isMainThread() || ScriptForbiddenScope::isScriptForbidden()); |
- 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(); |
+ if (pageCount % deadlineCheckInterval == 0) { |
+ if (deadlineSeconds <= Platform::current()->monotonicallyIncreasingTime()) { |
+ // Deadline has come. |
+ return !m_firstUnsweptPage; |
+ } |
} |
+ pageCount++; |
} |
+ return true; |
+} |
- if (threadState()->isMainThread()) |
- ScriptForbiddenScope::exit(); |
+void BaseHeap::completeSweep() |
+{ |
+ RELEASE_ASSERT(threadState()->isSweepingInProgress()); |
+ ASSERT(threadState()->sweepForbidden()); |
+ ASSERT(!threadState()->isMainThread() || ScriptForbiddenScope::isScriptForbidden()); |
+ |
+ while (m_firstUnsweptPage) { |
+ sweepUnsweptPage(); |
+ } |
} |
NormalPageHeap::NormalPageHeap(ThreadState* state, int index) |