[iOS] Sweep all collected objects on critical memory pressure
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Mar 2015 05:32:49 +0000 (05:32 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Mar 2015 05:32:49 +0000 (05:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142457
<rdar://problem/20044440>

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

All fullSweep() API to IncrementalSweeper so that we can call it in the
memory pressure handler.

* heap/IncrementalSweeper.cpp:
(JSC::IncrementalSweeper::fullSweep):
* heap/IncrementalSweeper.h:
(JSC::IncrementalSweeper::hasWork):

Source/WebCore:

Do a full sweep of objects marked for destruction on critical memory
pressure to free up memory.

* platform/cocoa/MemoryPressureHandlerCocoa.mm:
(WebCore::MemoryPressureHandler::platformReleaseMemory):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181310 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/IncrementalSweeper.cpp
Source/JavaScriptCore/heap/IncrementalSweeper.h
Source/WebCore/ChangeLog
Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm

index 0082b7b..4f2bdd0 100644 (file)
@@ -1,3 +1,19 @@
+2015-03-09  Chris Dumez  <cdumez@apple.com>
+
+        [iOS] Sweep all collected objects on critical memory pressure
+        https://bugs.webkit.org/show_bug.cgi?id=142457
+        <rdar://problem/20044440>
+
+        Reviewed by Geoffrey Garen.
+
+        All fullSweep() API to IncrementalSweeper so that we can call it in the
+        memory pressure handler.
+
+        * heap/IncrementalSweeper.cpp:
+        (JSC::IncrementalSweeper::fullSweep):
+        * heap/IncrementalSweeper.h:
+        (JSC::IncrementalSweeper::hasWork):
+
 2015-03-09  Mark Lam  <mark.lam@apple.com>
 
         Another build fix for Windows.
index da15137..4809f62 100644 (file)
@@ -60,6 +60,12 @@ void IncrementalSweeper::cancelTimer()
     CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
 }
 
+void IncrementalSweeper::fullSweep()
+{
+    while (hasWork())
+        doWork();
+}
+
 void IncrementalSweeper::doWork()
 {
     doSweep(WTF::monotonicallyIncreasingTime());
index af826c4..199f948 100644 (file)
@@ -38,6 +38,7 @@ class IncrementalSweeper : public HeapTimer {
 public:
 #if USE(CF)
     JS_EXPORT_PRIVATE IncrementalSweeper(Heap*, CFRunLoopRef);
+    JS_EXPORT_PRIVATE void fullSweep();
 #else
     explicit IncrementalSweeper(VM*);
 #endif
@@ -52,6 +53,7 @@ private:
     void doSweep(double startTime);
     void scheduleTimer();
     void cancelTimer();
+    bool hasWork() const { return !m_blocksToSweep.isEmpty(); }
     
     unsigned m_currentBlockToSweepIndex;
     Vector<MarkedBlock*>& m_blocksToSweep;
index 7842b33..e15c734 100644 (file)
@@ -1,3 +1,17 @@
+2015-03-09  Chris Dumez  <cdumez@apple.com>
+
+        [iOS] Sweep all collected objects on critical memory pressure
+        https://bugs.webkit.org/show_bug.cgi?id=142457
+        <rdar://problem/20044440>
+
+        Reviewed by Geoffrey Garen.
+
+        Do a full sweep of objects marked for destruction on critical memory
+        pressure to free up memory.
+
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        (WebCore::MemoryPressureHandler::platformReleaseMemory):
+
 2015-03-09  Andy Estes  <aestes@apple.com>
 
         [Content Filtering] Give ContentFilter subclasses private constructors, and make them fast-allocated and non-copyable
index 17858c4..1ee3b8f 100644 (file)
 #import "DispatchSPI.h"
 #import "IOSurfacePool.h"
 #import "GCController.h"
+#import "JSDOMWindow.h"
 #import "JSDOMWindowBase.h"
 #import "LayerPool.h"
 #import "Logging.h"
 #import "WebCoreSystemInterface.h"
+#import <JavaScriptCore/IncrementalSweeper.h>
 #import <mach/mach.h>
 #import <mach/task_info.h>
 #import <malloc/malloc.h>
@@ -88,6 +90,13 @@ void MemoryPressureHandler::platformReleaseMemory(bool critical)
         ReliefLogger log("Collecting JavaScript garbage");
         gcController().garbageCollectNow();
     }
+
+    // Do a full sweep of collected objects.
+    {
+        ReliefLogger log("Full JavaScript garbage sweep");
+        JSC::JSLockHolder lock(JSDOMWindow::commonVM());
+        JSDOMWindow::commonVM().heap.sweeper()->fullSweep();
+    }
 #endif
 }