Allow one sync GC per gcTimer interval on critical memory pressure warning
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 22:15:36 +0000 (22:15 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 22:15:36 +0000 (22:15 +0000)
commitbfd8fdc1f666e8254ab71b74421f4fac67703e54
tree44654b6f01666cbe1913c2af16163305929668a3
parentd0226cefe066f09c0a563fb6e524e1315d324a10
Allow one sync GC per gcTimer interval on critical memory pressure warning
https://bugs.webkit.org/show_bug.cgi?id=145773

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

On critical memory pressure warning, we were calling GCController::garbageCollectSoon(),
which does not offer any guarantee on when the garbage collection will actually take
place.

On critical memory pressure, we need to free up memory as soon as possible to avoid
getting killed so this is an issue. Also, the fact that we clear the PageCache on
critical memory pressure means a GC would likely be useful, even if the last
collection did not free much memory.

This patch adds a new GCController::garbageCollectNowIfNotDoneRecently() API that allows
one synchronous GC per gcTimer interval on critical memory pressure warning. This makes
us more responsive to critical memory pressure and avoids doing synchronous GCs too
often.

* heap/FullGCActivityCallback.cpp:
(JSC::FullGCActivityCallback::doCollection):
* heap/FullGCActivityCallback.h:
(JSC::GCActivityCallback::createFullTimer):
* heap/GCActivityCallback.h:
* heap/Heap.cpp:
(JSC::Heap::collectAllGarbageIfNotDoneRecently):
* heap/Heap.h:

* heap/IncrementalSweeper.cpp:
(JSC::IncrementalSweeper::doWork): Deleted.
* heap/IncrementalSweeper.h:

Drop fullSweep() API as it no longer seems useful. garbageCollectNow()
already does a sweep after the full collection.

Source/WebCore:

* bindings/js/GCController.cpp:
(WebCore::GCController::garbageCollectNowIfNotDoneRecently):

Add new GCController::garbageCollectNowIfNotDoneRecently() API that
allows one synchronous GC per full GC timer interval. If called more
than once per interval, it becomes equivalent to garbageCollectSoon()
and merely accelerates the next collection.

* bindings/js/GCController.h:
* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::releaseCriticalMemory):

Call the new GCController::garbageCollectNowIfNotDoneRecently() on
critical memory pressure instead of garbageCollectionSoon() to try
as do a synchronous GC if one wasn't already done recently.
Also drop call to fullSweep() as GCController::garbageCollectNow*()
already do a sweep after the collection.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185387 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/FullGCActivityCallback.cpp
Source/JavaScriptCore/heap/FullGCActivityCallback.h
Source/JavaScriptCore/heap/GCActivityCallback.h
Source/JavaScriptCore/heap/Heap.cpp
Source/JavaScriptCore/heap/Heap.h
Source/JavaScriptCore/heap/IncrementalSweeper.cpp
Source/JavaScriptCore/heap/IncrementalSweeper.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/GCController.cpp
Source/WebCore/bindings/js/GCController.h
Source/WebCore/platform/MemoryPressureHandler.cpp