<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[185206] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/185206">185206</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-06-04 11:23:42 -0700 (Thu, 04 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WK2] Prune more resources from the MemoryCache before process suspension
https://bugs.webkit.org/show_bug.cgi?id=145633

Reviewed by Andreas Kling.

Source/JavaScriptCore:

No longer move protect IncrementalSweeper::fullSweep() behind
USE(CF) so we don't need #ifdefs at call sites, similarly to what is
done for the rest of the IncrementalSweeper API.

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

Source/WebCore:

Prune more resources from the MemoryCache before process suspension or
on simulated memory warning by doing a synchronous JS garbage collection
and sweep *before* pruning dead resources from the memory cache.
Previously, we would do the garbage collection after pruning the
MemoryCache which meant that a lot of resources became dead after we
tried to prune them.

At the end a basic browsing on apple.com, we are able to remove ~17%
more resources from the MemoryCache on simulated memory warning with this
change.

Pruning as much as we can from the memory cache on critical memory
pressure or before process suspension is not only useful to free up
memory but also to make room in the vnode table as a lot of
CachedResources are mmmap'd from the network disk cache.

* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::MemoryPressureHandler):
(WebCore::MemoryPressureHandler::releaseCriticalMemory):

- Pass 'synchronous' argument so that we know if we need to do a
  synchronous JS garbage collection.
- Move here code from in the Cocoa handler that is doing a JS garbage
  collection as well as a sweep, and make this code cross-platform.
  This code used to be iOS specific but I see no reason we shouldn't
  do this on Mac.

(WebCore::MemoryPressureHandler::releaseMemory):
* platform/MemoryPressureHandler.h:

Use enum class arguments for critical / synchronous. The 'synchronous'
argument is new so that the call site can let us know if memory needs
to be freed synchronously (e.g. in case of imminent process suspension).

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

Remove iOS-specific code that was doing a JS garbage collection and
sweep as this code is now in the generic memory pressure handler.

(WebCore::MemoryPressureHandler::install):

On simulated memory pressure, set 'synchronous' argument to Yes so that
a synchronous GC is done by the generic memory pressure handler. This
way, we no longer need to do a sync GC after calling the memory pressure
handler. This avoids code duplication and makes sure the GC is done
before pruning the memory cache.

Source/WebKit2:

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::lowMemoryHandler):
(WebKit::NetworkProcess::initializeNetworkProcess):
(WebKit::NetworkProcess::processWillSuspendImminently):
(WebKit::NetworkProcess::prepareToSuspend):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformLowMemoryHandler):
* PluginProcess/PluginProcess.cpp:
(WebKit::PluginProcess::initializeProcess):

Update low memory handler prototype to match WebCore changes.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::actualPrepareToSuspend):

Pass Synchronous::Yes argument to MemoryPressureHandler::releaseMemory()
to request that the memory is free up synchronously (e.g. synchronous
JS garbage collection) as the process is about to be suspended.
Previously, the memory pressure handler was trying to detect this case
by checking if the system was really under memory pressure but this was
a bit hackish and it wouldn't work if the process happened to get
suspended while the system was under memory pressure.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreheapIncrementalSweepercpp">trunk/Source/JavaScriptCore/heap/IncrementalSweeper.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreheapIncrementalSweeperh">trunk/Source/JavaScriptCore/heap/IncrementalSweeper.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformMemoryPressureHandlercpp">trunk/Source/WebCore/platform/MemoryPressureHandler.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformMemoryPressureHandlerh">trunk/Source/WebCore/platform/MemoryPressureHandler.h</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaMemoryPressureHandlerCocoamm">trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformlinuxMemoryPressureHandlerLinuxcpp">trunk/Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkProcesscpp">trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkProcessh">trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscocoaNetworkProcessCocoamm">trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2PluginProcessPluginProcesscpp">trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcesscpp">trunk/Source/WebKit2/WebProcess/WebProcess.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-06-04  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2] Prune more resources from the MemoryCache before process suspension
+        https://bugs.webkit.org/show_bug.cgi?id=145633
+
+        Reviewed by Andreas Kling.
+
+        No longer move protect IncrementalSweeper::fullSweep() behind
+        USE(CF) so we don't need #ifdefs at call sites, similarly to what is
+        done for the rest of the IncrementalSweeper API.
+
+        * heap/IncrementalSweeper.cpp:
+        (JSC::IncrementalSweeper::fullSweep):
+        * heap/IncrementalSweeper.h:
+
</ins><span class="cx"> 2015-06-01  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         CallLinkStatus should return takesSlowPath if the GC often cleared the IC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreheapIncrementalSweepercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/heap/IncrementalSweeper.cpp (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/heap/IncrementalSweeper.cpp        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/JavaScriptCore/heap/IncrementalSweeper.cpp        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -132,6 +132,10 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IncrementalSweeper::fullSweep()
+{
+}
+
</ins><span class="cx"> bool IncrementalSweeper::sweepNextBlock()
</span><span class="cx"> {
</span><span class="cx">     return false;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreheapIncrementalSweeperh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/heap/IncrementalSweeper.h (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/heap/IncrementalSweeper.h        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/JavaScriptCore/heap/IncrementalSweeper.h        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -39,11 +39,11 @@
</span><span class="cx"> public:
</span><span class="cx"> #if USE(CF)
</span><span class="cx">     JS_EXPORT_PRIVATE IncrementalSweeper(Heap*, CFRunLoopRef);
</span><del>-    JS_EXPORT_PRIVATE void fullSweep();
</del><span class="cx"> #else
</span><span class="cx">     explicit IncrementalSweeper(VM*);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    JS_EXPORT_PRIVATE void fullSweep();
</ins><span class="cx">     void startSweeping();
</span><span class="cx"> 
</span><span class="cx">     JS_EXPORT_PRIVATE virtual void doWork() override;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebCore/ChangeLog        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -1,3 +1,59 @@
</span><ins>+2015-06-04  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2] Prune more resources from the MemoryCache before process suspension
+        https://bugs.webkit.org/show_bug.cgi?id=145633
+
+        Reviewed by Andreas Kling.
+
+        Prune more resources from the MemoryCache before process suspension or
+        on simulated memory warning by doing a synchronous JS garbage collection
+        and sweep *before* pruning dead resources from the memory cache.
+        Previously, we would do the garbage collection after pruning the
+        MemoryCache which meant that a lot of resources became dead after we
+        tried to prune them.
+
+        At the end a basic browsing on apple.com, we are able to remove ~17%
+        more resources from the MemoryCache on simulated memory warning with this
+        change.
+
+        Pruning as much as we can from the memory cache on critical memory
+        pressure or before process suspension is not only useful to free up
+        memory but also to make room in the vnode table as a lot of
+        CachedResources are mmmap'd from the network disk cache.
+
+        * platform/MemoryPressureHandler.cpp:
+        (WebCore::MemoryPressureHandler::MemoryPressureHandler):
+        (WebCore::MemoryPressureHandler::releaseCriticalMemory):
+
+        - Pass 'synchronous' argument so that we know if we need to do a
+          synchronous JS garbage collection.
+        - Move here code from in the Cocoa handler that is doing a JS garbage
+          collection as well as a sweep, and make this code cross-platform.
+          This code used to be iOS specific but I see no reason we shouldn't
+          do this on Mac.
+
+        (WebCore::MemoryPressureHandler::releaseMemory):
+        * platform/MemoryPressureHandler.h:
+
+        Use enum class arguments for critical / synchronous. The 'synchronous'
+        argument is new so that the call site can let us know if memory needs
+        to be freed synchronously (e.g. in case of imminent process suspension).
+
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        (WebCore::MemoryPressureHandler::platformReleaseMemory):
+
+        Remove iOS-specific code that was doing a JS garbage collection and
+        sweep as this code is now in the generic memory pressure handler.
+
+        (WebCore::MemoryPressureHandler::install):
+
+        On simulated memory pressure, set 'synchronous' argument to Yes so that
+        a synchronous GC is done by the generic memory pressure handler. This
+        way, we no longer need to do a sync GC after calling the memory pressure
+        handler. This avoids code duplication and makes sure the GC is done
+        before pruning the memory cache.
+
+
</ins><span class="cx"> 2015-06-04  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] Clean up m_isEmoji in FontPlatformData
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformMemoryPressureHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/MemoryPressureHandler.cpp (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/MemoryPressureHandler.cpp        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.cpp        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> #include &quot;PageCache.h&quot;
</span><span class="cx"> #include &quot;ScrollingThread.h&quot;
</span><span class="cx"> #include &quot;WorkerThread.h&quot;
</span><ins>+#include &lt;JavaScriptCore/IncrementalSweeper.h&gt;
</ins><span class="cx"> #include &lt;wtf/CurrentTime.h&gt;
</span><span class="cx"> #include &lt;wtf/FastMalloc.h&gt;
</span><span class="cx"> #include &lt;wtf/StdLibExtras.h&gt;
</span><span class="lines">@@ -54,7 +55,7 @@
</span><span class="cx"> MemoryPressureHandler::MemoryPressureHandler() 
</span><span class="cx">     : m_installed(false)
</span><span class="cx">     , m_lastRespondTime(0)
</span><del>-    , m_lowMemoryHandler([this] (bool critical) { releaseMemory(critical); })
</del><ins>+    , m_lowMemoryHandler([this] (Critical critical, Synchronous synchronous) { releaseMemory(critical, synchronous); })
</ins><span class="cx">     , m_underMemoryPressure(false)
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     // FIXME: Can we share more of this with OpenSource?
</span><span class="lines">@@ -100,7 +101,7 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MemoryPressureHandler::releaseCriticalMemory()
</del><ins>+void MemoryPressureHandler::releaseCriticalMemory(Synchronous synchronous)
</ins><span class="cx"> {
</span><span class="cx">     {
</span><span class="cx">         ReliefLogger log(&quot;Empty the PageCache&quot;);
</span><span class="lines">@@ -134,12 +135,29 @@
</span><span class="cx">         ReliefLogger log(&quot;Invalidate font cache&quot;);
</span><span class="cx">         FontCache::singleton().invalidate();
</span><span class="cx">     }
</span><ins>+
+    if (synchronous == Synchronous::Yes) {
+        ReliefLogger log(&quot;Collecting JavaScript garbage&quot;);
+        gcController().garbageCollectNow();
+    } else {
+        // FIXME: We should do a garbage sweep and prune dead resources from the MemoryCache
+        // after the garbage collection has completed to free up more memory.
+        gcController().garbageCollectSoon();
+
+        // Do a full sweep of collected objects. garbageCollectNow() already does this so we only
+        // need to do this if it isn't called.
+        {
+            ReliefLogger log(&quot;Full JavaScript garbage sweep&quot;);
+            JSC::JSLockHolder lock(JSDOMWindow::commonVM());
+            JSDOMWindow::commonVM().heap.sweeper()-&gt;fullSweep();
+        }
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MemoryPressureHandler::releaseMemory(bool critical)
</del><ins>+void MemoryPressureHandler::releaseMemory(Critical critical, Synchronous synchronous)
</ins><span class="cx"> {
</span><del>-    if (critical)
-        releaseCriticalMemory();
</del><ins>+    if (critical == Critical::Yes)
+        releaseCriticalMemory(synchronous);
</ins><span class="cx"> 
</span><span class="cx">     releaseNoncriticalMemory();
</span><span class="cx"> 
</span><span class="lines">@@ -160,8 +178,8 @@
</span><span class="cx"> void MemoryPressureHandler::install() { }
</span><span class="cx"> void MemoryPressureHandler::uninstall() { }
</span><span class="cx"> void MemoryPressureHandler::holdOff(unsigned) { }
</span><del>-void MemoryPressureHandler::respondToMemoryPressure(bool) { }
-void MemoryPressureHandler::platformReleaseMemory(bool) { }
</del><ins>+void MemoryPressureHandler::respondToMemoryPressure(Critical, Synchronous) { }
+void MemoryPressureHandler::platformReleaseMemory(Critical) { }
</ins><span class="cx"> void MemoryPressureHandler::ReliefLogger::platformLog() { }
</span><span class="cx"> size_t MemoryPressureHandler::ReliefLogger::platformMemoryUsage() { return 0; }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformMemoryPressureHandlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/MemoryPressureHandler.h (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/MemoryPressureHandler.h        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.h        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -49,8 +49,11 @@
</span><span class="cx"> };
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-typedef std::function&lt;void(bool critical)&gt; LowMemoryHandler;
</del><ins>+enum class Critical { No, Yes };
+enum class Synchronous { No, Yes };
</ins><span class="cx"> 
</span><ins>+typedef std::function&lt;void(Critical, Synchronous)&gt; LowMemoryHandler;
+
</ins><span class="cx"> class MemoryPressureHandler {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx">     friend class WTF::NeverDestroyed&lt;MemoryPressureHandler&gt;;
</span><span class="lines">@@ -107,11 +110,11 @@
</span><span class="cx">         WEBCORE_EXPORT static bool s_loggingEnabled;
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT void releaseMemory(bool critical);
</del><ins>+    WEBCORE_EXPORT void releaseMemory(Critical, Synchronous = Synchronous::No);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     void releaseNoncriticalMemory();
</span><del>-    void releaseCriticalMemory();
</del><ins>+    void releaseCriticalMemory(Synchronous);
</ins><span class="cx"> 
</span><span class="cx">     void uninstall();
</span><span class="cx"> 
</span><span class="lines">@@ -120,8 +123,8 @@
</span><span class="cx">     MemoryPressureHandler();
</span><span class="cx">     ~MemoryPressureHandler() = delete;
</span><span class="cx"> 
</span><del>-    void respondToMemoryPressure(bool critical);
-    void platformReleaseMemory(bool critical);
</del><ins>+    void respondToMemoryPressure(Critical, Synchronous = Synchronous::No);
+    void platformReleaseMemory(Critical);
</ins><span class="cx"> 
</span><span class="cx">     bool m_installed;
</span><span class="cx">     time_t m_lastRespondTime;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaMemoryPressureHandlerCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -34,7 +34,6 @@
</span><span class="cx"> #import &quot;LayerPool.h&quot;
</span><span class="cx"> #import &quot;Logging.h&quot;
</span><span class="cx"> #import &quot;WebCoreSystemInterface.h&quot;
</span><del>-#import &lt;JavaScriptCore/IncrementalSweeper.h&gt;
</del><span class="cx"> #import &lt;mach/mach.h&gt;
</span><span class="cx"> #import &lt;mach/task_info.h&gt;
</span><span class="cx"> #import &lt;malloc/malloc.h&gt;
</span><span class="lines">@@ -51,7 +50,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-void MemoryPressureHandler::platformReleaseMemory(bool critical)
</del><ins>+void MemoryPressureHandler::platformReleaseMemory(Critical critical)
</ins><span class="cx"> {
</span><span class="cx">     {
</span><span class="cx">         ReliefLogger log(&quot;Purging SQLite caches&quot;);
</span><span class="lines">@@ -71,7 +70,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101000
</span><del>-    if (critical &amp;&amp; !isUnderMemoryPressure()) {
</del><ins>+    if (critical == Critical::Yes &amp;&amp; !isUnderMemoryPressure()) {
</ins><span class="cx">         // libcache listens to OS memory notifications, but for process suspension
</span><span class="cx">         // or memory pressure simulation, we need to prod it manually:
</span><span class="cx">         ReliefLogger log(&quot;Purging libcache caches&quot;);
</span><span class="lines">@@ -80,24 +79,6 @@
</span><span class="cx"> #else
</span><span class="cx">     UNUSED_PARAM(critical);
</span><span class="cx"> #endif
</span><del>-
-#if PLATFORM(IOS)
-    if (isUnderMemoryPressure()) {
-        gcController().garbageCollectSoon();
-    } else {
-        // If we're not under memory pressure, that means we're here due to impending process suspension.
-        // Do a full GC since this is our last chance to run any code.
-        ReliefLogger log(&quot;Collecting JavaScript garbage&quot;);
-        gcController().garbageCollectNow();
-    }
-
-    // Do a full sweep of collected objects.
-    {
-        ReliefLogger log(&quot;Full JavaScript garbage sweep&quot;);
-        JSC::JSLockHolder lock(JSDOMWindow::commonVM());
-        JSDOMWindow::commonVM().heap.sweeper()-&gt;fullSweep();
-    }
-#endif
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static dispatch_source_t _cache_event_source = 0;
</span><span class="lines">@@ -147,7 +128,7 @@
</span><span class="cx">                 if (ReliefLogger::loggingEnabled())
</span><span class="cx">                     NSLog(@&quot;Got memory pressure notification (%s)&quot;, critical ? &quot;critical&quot; : &quot;non-critical&quot;);
</span><span class="cx"> #endif
</span><del>-                MemoryPressureHandler::singleton().respondToMemoryPressure(critical);
</del><ins>+                MemoryPressureHandler::singleton().respondToMemoryPressure(critical ? Critical::Yes : Critical::No);
</ins><span class="cx">             });
</span><span class="cx">             dispatch_resume(_cache_event_source);
</span><span class="cx">         }
</span><span class="lines">@@ -155,12 +136,8 @@
</span><span class="cx"> 
</span><span class="cx">     // Allow simulation of memory pressure with &quot;notifyutil -p org.WebKit.lowMemory&quot;
</span><span class="cx">     notify_register_dispatch(&quot;org.WebKit.lowMemory&quot;, &amp;_notifyToken, dispatch_get_main_queue(), ^(int) {
</span><del>-        MemoryPressureHandler::singleton().respondToMemoryPressure(true);
</del><ins>+        MemoryPressureHandler::singleton().respondToMemoryPressure(Critical::Yes, Synchronous::Yes);
</ins><span class="cx"> 
</span><del>-        // We only do a synchronous GC when *simulating* memory pressure.
-        // This gives us a more consistent picture of live objects at the end of testing.
-        gcController().garbageCollectNow();
-
</del><span class="cx">         WTF::releaseFastMallocFreeMemory();
</span><span class="cx"> 
</span><span class="cx">         malloc_zone_pressure_relief(nullptr, 0);
</span><span class="lines">@@ -213,14 +190,14 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MemoryPressureHandler::respondToMemoryPressure(bool critical)
</del><ins>+void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
</ins><span class="cx"> {
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx">     uninstall();
</span><span class="cx">     double startTime = monotonicallyIncreasingTime();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    m_lowMemoryHandler(critical);
</del><ins>+    m_lowMemoryHandler(critical, synchronous);
</ins><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx">     unsigned holdOffTime = (monotonicallyIncreasingTime() - startTime) * s_holdOffMultiplier;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformlinuxMemoryPressureHandlerLinuxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -101,7 +101,7 @@
</span><span class="cx"> 
</span><span class="cx">     MemoryPressureHandler::singleton().setUnderMemoryPressure(critical);
</span><span class="cx">     callOnMainThread([critical] {
</span><del>-        MemoryPressureHandler::singleton().respondToMemoryPressure(critical);
</del><ins>+        MemoryPressureHandler::singleton().respondToMemoryPressure(critical ? Critical::Yes : Critical::No);
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -189,17 +189,17 @@
</span><span class="cx">     m_holdOffTimer.startOneShot(seconds);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MemoryPressureHandler::respondToMemoryPressure(bool critical)
</del><ins>+void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
</ins><span class="cx"> {
</span><span class="cx">     uninstall();
</span><span class="cx"> 
</span><span class="cx">     double startTime = monotonicallyIncreasingTime();
</span><del>-    m_lowMemoryHandler(critical);
</del><ins>+    m_lowMemoryHandler(critical, synchronous);
</ins><span class="cx">     unsigned holdOffTime = (monotonicallyIncreasingTime() - startTime) * s_holdOffMultiplier;
</span><span class="cx">     holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MemoryPressureHandler::platformReleaseMemory(bool)
</del><ins>+void MemoryPressureHandler::platformReleaseMemory(Critical)
</ins><span class="cx"> {
</span><span class="cx">     ReliefLogger log(&quot;Run malloc_trim&quot;);
</span><span class="cx">     malloc_trim(0);
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebKit2/ChangeLog        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2015-06-04  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2] Prune more resources from the MemoryCache before process suspension
+        https://bugs.webkit.org/show_bug.cgi?id=145633
+
+        Reviewed by Andreas Kling.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::lowMemoryHandler):
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        (WebKit::NetworkProcess::processWillSuspendImminently):
+        (WebKit::NetworkProcess::prepareToSuspend):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::NetworkProcess::platformLowMemoryHandler):
+        * PluginProcess/PluginProcess.cpp:
+        (WebKit::PluginProcess::initializeProcess):
+
+        Update low memory handler prototype to match WebCore changes.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::actualPrepareToSuspend):
+
+        Pass Synchronous::Yes argument to MemoryPressureHandler::releaseMemory()
+        to request that the memory is free up synchronously (e.g. synchronous
+        JS garbage collection) as the process is about to be suspended.
+        Previously, the memory pressure handler was trying to detect this case
+        by checking if the system was really under memory pressure but this was
+        a bit hackish and it wouldn't work if the process happened to get
+        suspended while the system was under memory pressure.
+
</ins><span class="cx"> 2015-06-03  Carlos Alberto Lopez Perez  &lt;clopez@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] [Wayland] Build is broken on trunk
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -48,7 +48,6 @@
</span><span class="cx"> #include &quot;WebResourceCacheManager.h&quot;
</span><span class="cx"> #include &quot;WebsiteData.h&quot;
</span><span class="cx"> #include &lt;WebCore/Logging.h&gt;
</span><del>-#include &lt;WebCore/MemoryPressureHandler.h&gt;
</del><span class="cx"> #include &lt;WebCore/PlatformCookieJar.h&gt;
</span><span class="cx"> #include &lt;WebCore/ResourceRequest.h&gt;
</span><span class="cx"> #include &lt;WebCore/SecurityOriginHash.h&gt;
</span><span class="lines">@@ -175,7 +174,7 @@
</span><span class="cx">     return authenticationManager();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void NetworkProcess::lowMemoryHandler(bool critical)
</del><ins>+void NetworkProcess::lowMemoryHandler(Critical critical)
</ins><span class="cx"> {
</span><span class="cx">     platformLowMemoryHandler(critical);
</span><span class="cx">     WTF::releaseFastMallocFreeMemory();
</span><span class="lines">@@ -188,7 +187,7 @@
</span><span class="cx">     WTF::setCurrentThreadIsUserInitiated();
</span><span class="cx"> 
</span><span class="cx">     auto&amp; memoryPressureHandler = MemoryPressureHandler::singleton();
</span><del>-    memoryPressureHandler.setLowMemoryHandler([this] (bool critical) {
</del><ins>+    memoryPressureHandler.setLowMemoryHandler([this] (Critical critical, Synchronous) {
</ins><span class="cx">         lowMemoryHandler(critical);
</span><span class="cx">     });
</span><span class="cx">     memoryPressureHandler.install();
</span><span class="lines">@@ -516,13 +515,13 @@
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::processWillSuspendImminently(bool&amp; handled)
</span><span class="cx"> {
</span><del>-    lowMemoryHandler(true);
</del><ins>+    lowMemoryHandler(Critical::Yes);
</ins><span class="cx">     handled = true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::prepareToSuspend()
</span><span class="cx"> {
</span><del>-    lowMemoryHandler(true);
</del><ins>+    lowMemoryHandler(Critical::Yes);
</ins><span class="cx">     parentProcessConnection()-&gt;send(Messages::NetworkProcessProxy::ProcessReadyToSuspend(), 0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -548,7 +547,7 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void NetworkProcess::platformLowMemoryHandler(bool)
</del><ins>+void NetworkProcess::platformLowMemoryHandler(Critical)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkProcessh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #include &quot;DownloadManager.h&quot;
</span><span class="cx"> #include &quot;MessageReceiverMap.h&quot;
</span><span class="cx"> #include &lt;WebCore/DiagnosticLoggingClient.h&gt;
</span><ins>+#include &lt;WebCore/MemoryPressureHandler.h&gt;
</ins><span class="cx"> #include &lt;WebCore/SessionID.h&gt;
</span><span class="cx"> #include &lt;memory&gt;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="lines">@@ -97,8 +98,8 @@
</span><span class="cx">     virtual void terminate() override;
</span><span class="cx">     void platformTerminate();
</span><span class="cx"> 
</span><del>-    void lowMemoryHandler(bool critical);
-    void platformLowMemoryHandler(bool critical);
</del><ins>+    void lowMemoryHandler(WebCore::Critical);
+    void platformLowMemoryHandler(WebCore::Critical);
</ins><span class="cx"> 
</span><span class="cx">     // ChildProcess
</span><span class="cx">     virtual void initializeProcess(const ChildProcessInitializationParameters&amp;) override;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscocoaNetworkProcessCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-void NetworkProcess::platformLowMemoryHandler(bool)
</del><ins>+void NetworkProcess::platformLowMemoryHandler(WebCore::Critical)
</ins><span class="cx"> {
</span><span class="cx">     CFURLConnectionInvalidateConnectionCache();
</span><span class="cx">     _CFURLCachePurgeMemoryCache(adoptCF(CFURLCacheCopySharedURLCache()).get());
</span></span></pre></div>
<a id="trunkSourceWebKit2PluginProcessPluginProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx">     platformInitializeProcess(parameters);
</span><span class="cx"> 
</span><span class="cx">     auto&amp; memoryPressureHandler = MemoryPressureHandler::singleton();
</span><del>-    memoryPressureHandler.setLowMemoryHandler([this] (bool) {
</del><ins>+    memoryPressureHandler.setLowMemoryHandler([this] (Critical, Synchronous) {
</ins><span class="cx">         if (shouldTerminate())
</span><span class="cx">             terminate();
</span><span class="cx">     });
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (185205 => 185206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2015-06-04 18:18:23 UTC (rev 185205)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2015-06-04 18:23:42 UTC (rev 185206)
</span><span class="lines">@@ -1226,7 +1226,7 @@
</span><span class="cx"> 
</span><span class="cx"> void WebProcess::actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend shouldAcknowledgeWhenReadyToSuspend)
</span><span class="cx"> {
</span><del>-    MemoryPressureHandler::singleton().releaseMemory(true);
</del><ins>+    MemoryPressureHandler::singleton().releaseMemory(Critical::Yes, Synchronous::Yes);
</ins><span class="cx">     setAllLayerTreeStatesFrozen(true);
</span><span class="cx"> 
</span><span class="cx">     if (markAllLayersVolatileIfPossible()) {
</span></span></pre>
</div>
</div>

</body>
</html>