<!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>[213214] 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/213214">213214</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2017-03-01 01:38:44 -0800 (Wed, 01 Mar 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>Move MemoryPressureHandler to WTF
<https://webkit.org/b/168908>
Reviewed by Sam Weinig.
Source/WebCore:
* CMakeLists.txt:
* PlatformMac.cmake:
* PlatformWin.cmake:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/ScriptController.cpp:
* history/PageCache.cpp:
* html/HTMLMediaElement.cpp:
* inspector/InspectorInstrumentation.h:
* inspector/InspectorMemoryAgent.h:
* page/FrameView.cpp:
* page/MemoryRelease.h:
* page/linux/ResourceUsageThreadLinux.cpp:
* platform/Linux.cmake:
* platform/graphics/FontCache.cpp:
* platform/graphics/WidthCache.h:
* platform/graphics/ca/TileController.cpp:
* platform/graphics/win/MediaPlayerPrivateMediaFoundation.h:
* platform/ios/LegacyTileCache.mm:
* platform/ios/LegacyTileGrid.mm:
* platform/ios/LegacyTileLayerPool.mm:
* platform/ios/TileControllerMemoryHandlerIOS.cpp:
* testing/Internals.cpp:
Source/WebKit2:
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/mac/NetworkProcessMac.mm:
* PluginProcess/PluginProcess.cpp:
* Shared/linux/WebMemorySamplerLinux.cpp:
* WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp:
* WebProcess/WebPage/ios/WebPageIOS.mm:
Source/WTF:
Move MemoryPressureHandler down to WTF so it can be used from JavaScriptCore.
I had to do a blind rewrite of the Windows memory checking timer since it can
no longer use WebCore::Timer. I also moved the Win32Handle helper class to WTF.
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/MemoryPressureHandler.cpp: Renamed from Source/WebCore/platform/MemoryPressureHandler.cpp.
(WTF::MemoryPressureHandler::singleton):
(WTF::MemoryPressureHandler::MemoryPressureHandler):
(WTF::MemoryPressureHandler::setShouldUsePeriodicMemoryMonitor):
(WTF::toString):
(WTF::thresholdForPolicy):
(WTF::policyForFootprint):
(WTF::MemoryPressureHandler::measurementTimerFired):
(WTF::MemoryPressureHandler::beginSimulatedMemoryPressure):
(WTF::MemoryPressureHandler::endSimulatedMemoryPressure):
(WTF::MemoryPressureHandler::releaseMemory):
(WTF::MemoryPressureHandler::ReliefLogger::logMemoryUsageChange):
(WTF::MemoryPressureHandler::install):
(WTF::MemoryPressureHandler::uninstall):
(WTF::MemoryPressureHandler::holdOff):
(WTF::MemoryPressureHandler::respondToMemoryPressure):
(WTF::MemoryPressureHandler::platformReleaseMemory):
(WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage):
(WTF::MemoryPressureHandler::platformInitialize):
* wtf/MemoryPressureHandler.h: Renamed from Source/WebCore/platform/MemoryPressureHandler.h.
(WTF::MemoryPressureHandler::setMemoryKillCallback):
(WTF::MemoryPressureHandler::setProcessIsEligibleForMemoryKillCallback):
(WTF::MemoryPressureHandler::setLowMemoryHandler):
(WTF::MemoryPressureHandler::isUnderMemoryPressure):
(WTF::MemoryPressureHandler::setUnderMemoryPressure):
(WTF::MemoryPressureHandler::ReliefLogger::ReliefLogger):
(WTF::MemoryPressureHandler::ReliefLogger::~ReliefLogger):
(WTF::MemoryPressureHandler::ReliefLogger::logString):
(WTF::MemoryPressureHandler::ReliefLogger::setLoggingEnabled):
(WTF::MemoryPressureHandler::ReliefLogger::loggingEnabled):
(WTF::MemoryPressureHandler::ReliefLogger::MemoryUsage::MemoryUsage):
* wtf/PlatformEfl.cmake:
* wtf/PlatformGTK.cmake:
* wtf/PlatformMac.cmake:
* wtf/PlatformWin.cmake:
* wtf/cocoa/MemoryPressureHandlerCocoa.mm: Renamed from Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm.
(WTF::MemoryPressureHandler::platformReleaseMemory):
(WTF::MemoryPressureHandler::install):
(WTF::MemoryPressureHandler::uninstall):
(WTF::MemoryPressureHandler::holdOff):
(WTF::MemoryPressureHandler::respondToMemoryPressure):
(WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage):
* wtf/linux/CurrentProcessMemoryStatus.cpp: Renamed from Source/WebCore/platform/linux/CurrentProcessMemoryStatus.cpp.
(WTF::systemPageSize):
(WTF::currentProcessMemoryStatus):
* wtf/linux/CurrentProcessMemoryStatus.h: Renamed from Source/WebCore/platform/linux/CurrentProcessMemoryStatus.h.
* wtf/linux/MemoryPressureHandlerLinux.cpp: Renamed from Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp.
(WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller):
* wtf/win/MemoryPressureHandlerWin.cpp: Renamed from Source/WebCore/platform/win/MemoryPressureHandlerWin.cpp.
(WTF::MemoryPressureHandler::platformInitialize):
(WTF::MemoryPressureHandler::windowsMeasurementTimerFired):
(WTF::MemoryPressureHandler::platformReleaseMemory):
(WTF::MemoryPressureHandler::install):
(WTF::MemoryPressureHandler::uninstall):
(WTF::MemoryPressureHandler::holdOff):
(WTF::MemoryPressureHandler::respondToMemoryPressure):
(WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage):
* wtf/win/Win32Handle.h: Renamed from Source/WebCore/platform/win/Win32Handle.h.
(WTF::Win32Handle::Win32Handle):
(WTF::Win32Handle::~Win32Handle):
(WTF::Win32Handle::clear):
(WTF::Win32Handle::isValid):
(WTF::Win32Handle::get):
(WTF::Win32Handle::release):
(WTF::Win32Handle::operator=):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFWTFxcodeprojprojectpbxproj">trunk/Source/WTF/WTF.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWTFwtfCMakeListstxt">trunk/Source/WTF/wtf/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWTFwtfPlatformEflcmake">trunk/Source/WTF/wtf/PlatformEfl.cmake</a></li>
<li><a href="#trunkSourceWTFwtfPlatformGTKcmake">trunk/Source/WTF/wtf/PlatformGTK.cmake</a></li>
<li><a href="#trunkSourceWTFwtfPlatformMaccmake">trunk/Source/WTF/wtf/PlatformMac.cmake</a></li>
<li><a href="#trunkSourceWTFwtfPlatformWincmake">trunk/Source/WTF/wtf/PlatformWin.cmake</a></li>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorePlatformMaccmake">trunk/Source/WebCore/PlatformMac.cmake</a></li>
<li><a href="#trunkSourceWebCorePlatformWincmake">trunk/Source/WebCore/PlatformWin.cmake</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorebindingsjsScriptControllercpp">trunk/Source/WebCore/bindings/js/ScriptController.cpp</a></li>
<li><a href="#trunkSourceWebCorehistoryPageCachecpp">trunk/Source/WebCore/history/PageCache.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorInstrumentationh">trunk/Source/WebCore/inspector/InspectorInstrumentation.h</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorMemoryAgenth">trunk/Source/WebCore/inspector/InspectorMemoryAgent.h</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewcpp">trunk/Source/WebCore/page/FrameView.cpp</a></li>
<li><a href="#trunkSourceWebCorepageMemoryReleaseh">trunk/Source/WebCore/page/MemoryRelease.h</a></li>
<li><a href="#trunkSourceWebCorepagelinuxResourceUsageThreadLinuxcpp">trunk/Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformLinuxcmake">trunk/Source/WebCore/platform/Linux.cmake</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontCachecpp">trunk/Source/WebCore/platform/graphics/FontCache.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsWidthCacheh">trunk/Source/WebCore/platform/graphics/WidthCache.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscaTileControllercpp">trunk/Source/WebCore/platform/graphics/ca/TileController.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinMediaPlayerPrivateMediaFoundationh">trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.h</a></li>
<li><a href="#trunkSourceWebCoreplatformiosLegacyTileCachemm">trunk/Source/WebCore/platform/ios/LegacyTileCache.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosLegacyTileGridmm">trunk/Source/WebCore/platform/ios/LegacyTileGrid.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosLegacyTileLayerPoolmm">trunk/Source/WebCore/platform/ios/LegacyTileLayerPool.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosTileControllerMemoryHandlerIOScpp">trunk/Source/WebCore/platform/ios/TileControllerMemoryHandlerIOS.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkProcessh">trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessmacNetworkProcessMacmm">trunk/Source/WebKit2/NetworkProcess/mac/NetworkProcessMac.mm</a></li>
<li><a href="#trunkSourceWebKit2PluginProcessPluginProcesscpp">trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedlinuxWebMemorySamplerLinuxcpp">trunk/Source/WebKit2/Shared/linux/WebMemorySamplerLinux.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageCoordinatedGraphicsCompositingCoordinatorcpp">trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWTFwtfMemoryPressureHandlercpp">trunk/Source/WTF/wtf/MemoryPressureHandler.cpp</a></li>
<li><a href="#trunkSourceWTFwtfMemoryPressureHandlerh">trunk/Source/WTF/wtf/MemoryPressureHandler.h</a></li>
<li><a href="#trunkSourceWTFwtfcocoaMemoryPressureHandlerCocoamm">trunk/Source/WTF/wtf/cocoa/MemoryPressureHandlerCocoa.mm</a></li>
<li>trunk/Source/WTF/wtf/linux/</li>
<li><a href="#trunkSourceWTFwtflinuxCurrentProcessMemoryStatuscpp">trunk/Source/WTF/wtf/linux/CurrentProcessMemoryStatus.cpp</a></li>
<li><a href="#trunkSourceWTFwtflinuxCurrentProcessMemoryStatush">trunk/Source/WTF/wtf/linux/CurrentProcessMemoryStatus.h</a></li>
<li><a href="#trunkSourceWTFwtflinuxMemoryPressureHandlerLinuxcpp">trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp</a></li>
<li><a href="#trunkSourceWTFwtfwinMemoryPressureHandlerWincpp">trunk/Source/WTF/wtf/win/MemoryPressureHandlerWin.cpp</a></li>
<li><a href="#trunkSourceWTFwtfwinWin32Handleh">trunk/Source/WTF/wtf/win/Win32Handle.h</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<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>trunk/Source/WebCore/platform/linux/</li>
<li><a href="#trunkSourceWebCoreplatformwinMemoryPressureHandlerWincpp">trunk/Source/WebCore/platform/win/MemoryPressureHandlerWin.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformwinWin32Handleh">trunk/Source/WebCore/platform/win/Win32Handle.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WTF/ChangeLog        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,3 +1,83 @@
</span><ins>+2017-03-01 Andreas Kling <akling@apple.com>
+
+ Move MemoryPressureHandler to WTF
+ <https://webkit.org/b/168908>
+
+ Reviewed by Sam Weinig.
+
+ Move MemoryPressureHandler down to WTF so it can be used from JavaScriptCore.
+
+ I had to do a blind rewrite of the Windows memory checking timer since it can
+ no longer use WebCore::Timer. I also moved the Win32Handle helper class to WTF.
+
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/CMakeLists.txt:
+ * wtf/MemoryPressureHandler.cpp: Renamed from Source/WebCore/platform/MemoryPressureHandler.cpp.
+ (WTF::MemoryPressureHandler::singleton):
+ (WTF::MemoryPressureHandler::MemoryPressureHandler):
+ (WTF::MemoryPressureHandler::setShouldUsePeriodicMemoryMonitor):
+ (WTF::toString):
+ (WTF::thresholdForPolicy):
+ (WTF::policyForFootprint):
+ (WTF::MemoryPressureHandler::measurementTimerFired):
+ (WTF::MemoryPressureHandler::beginSimulatedMemoryPressure):
+ (WTF::MemoryPressureHandler::endSimulatedMemoryPressure):
+ (WTF::MemoryPressureHandler::releaseMemory):
+ (WTF::MemoryPressureHandler::ReliefLogger::logMemoryUsageChange):
+ (WTF::MemoryPressureHandler::install):
+ (WTF::MemoryPressureHandler::uninstall):
+ (WTF::MemoryPressureHandler::holdOff):
+ (WTF::MemoryPressureHandler::respondToMemoryPressure):
+ (WTF::MemoryPressureHandler::platformReleaseMemory):
+ (WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage):
+ (WTF::MemoryPressureHandler::platformInitialize):
+ * wtf/MemoryPressureHandler.h: Renamed from Source/WebCore/platform/MemoryPressureHandler.h.
+ (WTF::MemoryPressureHandler::setMemoryKillCallback):
+ (WTF::MemoryPressureHandler::setProcessIsEligibleForMemoryKillCallback):
+ (WTF::MemoryPressureHandler::setLowMemoryHandler):
+ (WTF::MemoryPressureHandler::isUnderMemoryPressure):
+ (WTF::MemoryPressureHandler::setUnderMemoryPressure):
+ (WTF::MemoryPressureHandler::ReliefLogger::ReliefLogger):
+ (WTF::MemoryPressureHandler::ReliefLogger::~ReliefLogger):
+ (WTF::MemoryPressureHandler::ReliefLogger::logString):
+ (WTF::MemoryPressureHandler::ReliefLogger::setLoggingEnabled):
+ (WTF::MemoryPressureHandler::ReliefLogger::loggingEnabled):
+ (WTF::MemoryPressureHandler::ReliefLogger::MemoryUsage::MemoryUsage):
+ * wtf/PlatformEfl.cmake:
+ * wtf/PlatformGTK.cmake:
+ * wtf/PlatformMac.cmake:
+ * wtf/PlatformWin.cmake:
+ * wtf/cocoa/MemoryPressureHandlerCocoa.mm: Renamed from Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm.
+ (WTF::MemoryPressureHandler::platformReleaseMemory):
+ (WTF::MemoryPressureHandler::install):
+ (WTF::MemoryPressureHandler::uninstall):
+ (WTF::MemoryPressureHandler::holdOff):
+ (WTF::MemoryPressureHandler::respondToMemoryPressure):
+ (WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage):
+ * wtf/linux/CurrentProcessMemoryStatus.cpp: Renamed from Source/WebCore/platform/linux/CurrentProcessMemoryStatus.cpp.
+ (WTF::systemPageSize):
+ (WTF::currentProcessMemoryStatus):
+ * wtf/linux/CurrentProcessMemoryStatus.h: Renamed from Source/WebCore/platform/linux/CurrentProcessMemoryStatus.h.
+ * wtf/linux/MemoryPressureHandlerLinux.cpp: Renamed from Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp.
+ (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller):
+ * wtf/win/MemoryPressureHandlerWin.cpp: Renamed from Source/WebCore/platform/win/MemoryPressureHandlerWin.cpp.
+ (WTF::MemoryPressureHandler::platformInitialize):
+ (WTF::MemoryPressureHandler::windowsMeasurementTimerFired):
+ (WTF::MemoryPressureHandler::platformReleaseMemory):
+ (WTF::MemoryPressureHandler::install):
+ (WTF::MemoryPressureHandler::uninstall):
+ (WTF::MemoryPressureHandler::holdOff):
+ (WTF::MemoryPressureHandler::respondToMemoryPressure):
+ (WTF::MemoryPressureHandler::ReliefLogger::platformMemoryUsage):
+ * wtf/win/Win32Handle.h: Renamed from Source/WebCore/platform/win/Win32Handle.h.
+ (WTF::Win32Handle::Win32Handle):
+ (WTF::Win32Handle::~Win32Handle):
+ (WTF::Win32Handle::clear):
+ (WTF::Win32Handle::isValid):
+ (WTF::Win32Handle::get):
+ (WTF::Win32Handle::release):
+ (WTF::Win32Handle::operator=):
+
</ins><span class="cx"> 2017-02-28 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><span class="cx"> [iOS] Throttle requestAnimationFrame to 30fps in low power mode
</span></span></pre></div>
<a id="trunkSourceWTFWTFxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -340,6 +340,9 @@
</span><span class="cx">                 A8A47487151A825B004123FF /* WTFThreadData.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A4737B151A825B004123FF /* WTFThreadData.h */; };
</span><span class="cx">                 A8A4748C151A8264004123FF /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A4748B151A8264004123FF /* config.h */; };
</span><span class="cx">                 AD7C434B1DD2A4A70026888B /* Expected.h in Headers */ = {isa = PBXBuildFile; fileRef = AD7C434A1DD2A4A70026888B /* Expected.h */; };
</span><ins>+                AD89B6B71E6415080090707F /* MemoryPressureHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD89B6B51E6415080090707F /* MemoryPressureHandler.cpp */; };
+                AD89B6B81E6415080090707F /* MemoryPressureHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = AD89B6B61E6415080090707F /* MemoryPressureHandler.h */; };
+                AD89B6BA1E64150F0090707F /* MemoryPressureHandlerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = AD89B6B91E64150F0090707F /* MemoryPressureHandlerCocoa.mm */; };
</ins><span class="cx">                 ADF2CE661E39F106006889DB /* MemoryFootprint.h in Headers */ = {isa = PBXBuildFile; fileRef = ADF2CE641E39F106006889DB /* MemoryFootprint.h */; };
</span><span class="cx">                 ADF2CE671E39F106006889DB /* MemoryFootprint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADF2CE651E39F106006889DB /* MemoryFootprint.cpp */; };
</span><span class="cx">                 B38FD7BD168953E80065C969 /* FeatureDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = B38FD7BC168953E80065C969 /* FeatureDefines.h */; };
</span><span class="lines">@@ -728,6 +731,9 @@
</span><span class="cx">                 A8A4737B151A825B004123FF /* WTFThreadData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFThreadData.h; sourceTree = "<group>"; };
</span><span class="cx">                 A8A4748B151A8264004123FF /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
</span><span class="cx">                 AD7C434A1DD2A4A70026888B /* Expected.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Expected.h; sourceTree = "<group>"; };
</span><ins>+                AD89B6B51E6415080090707F /* MemoryPressureHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryPressureHandler.cpp; sourceTree = "<group>"; };
+                AD89B6B61E6415080090707F /* MemoryPressureHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryPressureHandler.h; sourceTree = "<group>"; };
+                AD89B6B91E64150F0090707F /* MemoryPressureHandlerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryPressureHandlerCocoa.mm; sourceTree = "<group>"; };
</ins><span class="cx">                 ADF2CE641E39F106006889DB /* MemoryFootprint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryFootprint.h; sourceTree = "<group>"; };
</span><span class="cx">                 ADF2CE651E39F106006889DB /* MemoryFootprint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryFootprint.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 B38FD7BC168953E80065C969 /* FeatureDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FeatureDefines.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -1022,6 +1028,8 @@
</span><span class="cx">                                 CD5497AB15857D0300B5BC30 /* MediaTime.h */,
</span><span class="cx">                                 ADF2CE641E39F106006889DB /* MemoryFootprint.h */,
</span><span class="cx">                                 ADF2CE651E39F106006889DB /* MemoryFootprint.cpp */,
</span><ins>+                                AD89B6B51E6415080090707F /* MemoryPressureHandler.cpp */,
+                                AD89B6B61E6415080090707F /* MemoryPressureHandler.h */,
</ins><span class="cx">                                 A8A472CC151A825B004123FF /* MessageQueue.h */,
</span><span class="cx">                                 A8A472CD151A825B004123FF /* MetaAllocator.cpp */,
</span><span class="cx">                                 A8A472CE151A825B004123FF /* MetaAllocator.h */,
</span><span class="lines">@@ -1330,6 +1338,7 @@
</span><span class="cx">                 E4A0AD3B1A96251900536DF6 /* cocoa */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                AD89B6B91E64150F0090707F /* MemoryPressureHandlerCocoa.mm */,
</ins><span class="cx">                                 E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */,
</span><span class="cx">                         );
</span><span class="cx">                         path = cocoa;
</span><span class="lines">@@ -1578,6 +1587,7 @@
</span><span class="cx">                                 1C181C901D307AB800F5FA16 /* UTextProvider.h in Headers */,
</span><span class="cx">                                 1C181C921D307AB800F5FA16 /* UTextProviderLatin1.h in Headers */,
</span><span class="cx">                                 1C181C941D307AB800F5FA16 /* UTextProviderUTF16.h in Headers */,
</span><ins>+                                AD89B6B81E6415080090707F /* MemoryPressureHandler.h in Headers */,
</ins><span class="cx">                                 A8A4746A151A825B004123FF /* UTF8.h in Headers */,
</span><span class="cx">                                 A8A473B9151A825B004123FF /* utils.h in Headers */,
</span><span class="cx">                                 A8A4747D151A825B004123FF /* ValueCheck.h in Headers */,
</span><span class="lines">@@ -1713,6 +1723,7 @@
</span><span class="cx">                                 A8A47460151A825B004123FF /* CollatorDefault.cpp in Sources */,
</span><span class="cx">                                 A8A47463151A825B004123FF /* CollatorICU.cpp in Sources */,
</span><span class="cx">                                 0F8F2B92172E0103007DBDA5 /* CompilationThread.cpp in Sources */,
</span><ins>+                                AD89B6B71E6415080090707F /* MemoryPressureHandler.cpp in Sources */,
</ins><span class="cx">                                 515F794E1CFC9F4A00CCED93 /* CrossThreadCopier.cpp in Sources */,
</span><span class="cx">                                 A8A4739A151A825B004123FF /* CryptographicallyRandomNumber.cpp in Sources */,
</span><span class="cx">                                 E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */,
</span><span class="lines">@@ -1776,6 +1787,7 @@
</span><span class="cx">                                 0FDDBFA71666DFA300C55FEF /* StringPrintStream.cpp in Sources */,
</span><span class="cx">                                 A8A47443151A825B004123FF /* StringStatics.cpp in Sources */,
</span><span class="cx">                                 93F1993E19D7958D00C2390B /* StringView.cpp in Sources */,
</span><ins>+                                AD89B6BA1E64150F0090707F /* MemoryPressureHandlerCocoa.mm in Sources */,
</ins><span class="cx">                                 93934BD518A1F16900D0D6A1 /* StringViewCF.cpp in Sources */,
</span><span class="cx">                                 93934BD318A1E8C300D0D6A1 /* StringViewObjC.mm in Sources */,
</span><span class="cx">                                 A8A473B7151A825B004123FF /* strtod.cc in Sources */,
</span></span></pre></div>
<a id="trunkSourceWTFwtfCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/CMakeLists.txt (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/CMakeLists.txt        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WTF/wtf/CMakeLists.txt        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx"> MathExtras.h
</span><span class="cx"> MediaTime.h
</span><span class="cx"> MemoryFootprint.h
</span><ins>+ MemoryPressureHandler.h
</ins><span class="cx"> MessageQueue.h
</span><span class="cx"> MetaAllocator.h
</span><span class="cx"> MetaAllocatorHandle.h
</span><span class="lines">@@ -206,6 +207,7 @@
</span><span class="cx"> MainThread.cpp
</span><span class="cx"> MediaTime.cpp
</span><span class="cx"> MemoryFootprint.cpp
</span><ins>+ MemoryPressureHandler.cpp
</ins><span class="cx"> MetaAllocator.cpp
</span><span class="cx"> MonotonicTime.cpp
</span><span class="cx"> NumberOfCores.cpp
</span></span></pre></div>
<a id="trunkSourceWTFwtfMemoryPressureHandlercppfromrev213211trunkSourceWebCoreplatformMemoryPressureHandlercpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/MemoryPressureHandler.cpp (from rev 213211, trunk/Source/WebCore/platform/MemoryPressureHandler.cpp) (0 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/MemoryPressureHandler.cpp         (rev 0)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -0,0 +1,228 @@
</span><ins>+/*
+ * Copyright (C) 2011-2017 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MemoryPressureHandler.h"
+
+#include <wtf/MemoryFootprint.h>
+
+#define LOG_CHANNEL_PREFIX Log
+
+namespace WTF {
+
+#if RELEASE_LOG_DISABLED
+WTFLogChannel LogMemoryPressure = { WTFLogChannelOn, "MemoryPressure" };
+#else
+WTFLogChannel LogMemoryPressure = { WTFLogChannelOn, "MemoryPressure", LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
+#endif
+
+WTF_EXPORT_PRIVATE bool MemoryPressureHandler::ReliefLogger::s_loggingEnabled = false;
+
+MemoryPressureHandler& MemoryPressureHandler::singleton()
+{
+ static NeverDestroyed<MemoryPressureHandler> memoryPressureHandler;
+ return memoryPressureHandler;
+}
+
+MemoryPressureHandler::MemoryPressureHandler()
+#if OS(LINUX)
+ : m_holdOffTimer(RunLoop::main(), this, &MemoryPressureHandler::holdOffTimerFired)
+#elif OS(WINDOWS)
+ : m_windowsMeasurementTimer(RunLoop::main(), this, &MemoryPressureHandler::windowsMeasurementTimerFired)
+#endif
+{
+}
+
+void MemoryPressureHandler::setShouldUsePeriodicMemoryMonitor(bool use)
+{
+ if (use) {
+ m_measurementTimer = std::make_unique<RunLoop::Timer<MemoryPressureHandler>>(RunLoop::main(), this, &MemoryPressureHandler::measurementTimerFired);
+ m_measurementTimer->startRepeating(30);
+ } else
+ m_measurementTimer = nullptr;
+}
+
+#if !RELEASE_LOG_DISABLED
+static const char* toString(MemoryUsagePolicy policy)
+{
+ switch (policy) {
+ case MemoryUsagePolicy::Unrestricted: return "Unrestricted";
+ case MemoryUsagePolicy::Conservative: return "Conservative";
+ case MemoryUsagePolicy::Strict: return "Strict";
+ case MemoryUsagePolicy::Panic: return "Panic";
+ }
+}
+#endif
+
+static size_t thresholdForPolicy(MemoryUsagePolicy policy)
+{
+ switch (policy) {
+ case MemoryUsagePolicy::Conservative:
+ return 1 * GB;
+ case MemoryUsagePolicy::Strict:
+ return 2 * GB;
+ case MemoryUsagePolicy::Panic:
+#if CPU(X86_64) || CPU(ARM64)
+ return 4 * GB;
+#else
+ return 3 * GB;
+#endif
+ case MemoryUsagePolicy::Unrestricted:
+ default:
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+}
+
+static MemoryUsagePolicy policyForFootprint(size_t footprint)
+{
+ if (footprint >= thresholdForPolicy(MemoryUsagePolicy::Panic))
+ return MemoryUsagePolicy::Panic;
+ if (footprint >= thresholdForPolicy(MemoryUsagePolicy::Strict))
+ return MemoryUsagePolicy::Strict;
+ if (footprint >= thresholdForPolicy(MemoryUsagePolicy::Conservative))
+ return MemoryUsagePolicy::Conservative;
+ return MemoryUsagePolicy::Unrestricted;
+}
+
+void MemoryPressureHandler::measurementTimerFired()
+{
+ auto footprint = memoryFootprint();
+ if (!footprint)
+ return;
+
+ RELEASE_LOG(MemoryPressure, "Current memory footprint: %lu MB", footprint.value() / MB);
+
+ auto newPolicy = policyForFootprint(footprint.value());
+ if (newPolicy == m_memoryUsagePolicy) {
+ if (m_memoryUsagePolicy != MemoryUsagePolicy::Panic)
+ return;
+ RELEASE_LOG(MemoryPressure, "Memory usage still above panic threshold");
+ } else
+ RELEASE_LOG(MemoryPressure, "Memory usage policy changed: %s -> %s", toString(m_memoryUsagePolicy), toString(newPolicy));
+
+ m_memoryUsagePolicy = newPolicy;
+
+ if (newPolicy == MemoryUsagePolicy::Unrestricted)
+ return;
+
+ if (newPolicy == MemoryUsagePolicy::Conservative) {
+ // FIXME: Implement this policy by choosing which caches should respect it, and hooking them up.
+ return;
+ }
+
+ if (newPolicy == MemoryUsagePolicy::Strict) {
+ RELEASE_LOG(MemoryPressure, "Attempting to reduce memory footprint by freeing less important objects.");
+ releaseMemory(Critical::No, Synchronous::No);
+ return;
+ }
+
+ RELEASE_ASSERT(newPolicy == MemoryUsagePolicy::Panic);
+
+ RELEASE_LOG(MemoryPressure, "Attempting to reduce memory footprint by freeing more important objects.");
+ if (m_processIsEligibleForMemoryKillCallback) {
+ if (!m_processIsEligibleForMemoryKillCallback()) {
+ releaseMemory(Critical::Yes, Synchronous::No);
+ return;
+ }
+ }
+
+ releaseMemory(Critical::Yes, Synchronous::Yes);
+
+ // Remeasure footprint to see how well the pressure handler did.
+ footprint = memoryFootprint();
+ RELEASE_ASSERT(footprint);
+
+ RELEASE_LOG(MemoryPressure, "New memory footprint: %lu MB", footprint.value() / MB);
+ if (footprint.value() < thresholdForPolicy(MemoryUsagePolicy::Panic)) {
+ m_memoryUsagePolicy = policyForFootprint(footprint.value());
+ RELEASE_LOG(MemoryPressure, "Pressure reduced below panic threshold. New memory usage policy: %s", toString(m_memoryUsagePolicy));
+ return;
+ }
+
+ if (m_memoryKillCallback)
+ m_memoryKillCallback();
+}
+
+void MemoryPressureHandler::beginSimulatedMemoryPressure()
+{
+ m_isSimulatingMemoryPressure = true;
+ respondToMemoryPressure(Critical::Yes, Synchronous::Yes);
+}
+
+void MemoryPressureHandler::endSimulatedMemoryPressure()
+{
+ m_isSimulatingMemoryPressure = false;
+}
+
+void MemoryPressureHandler::releaseMemory(Critical critical, Synchronous synchronous)
+{
+ if (!m_lowMemoryHandler)
+ return;
+
+ ReliefLogger log("Total");
+ m_lowMemoryHandler(critical, synchronous);
+ platformReleaseMemory(critical);
+}
+
+void MemoryPressureHandler::ReliefLogger::logMemoryUsageChange()
+{
+#if !RELEASE_LOG_DISABLED
+#define STRING_SPECIFICATION "%{public}s"
+#define MEMORYPRESSURE_LOG(...) RELEASE_LOG(MemoryPressure, __VA_ARGS__)
+#else
+#define STRING_SPECIFICATION "%s"
+#define MEMORYPRESSURE_LOG(...) WTFLogAlways(__VA_ARGS__)
+#endif
+
+ auto currentMemory = platformMemoryUsage();
+ if (!currentMemory || !m_initialMemory) {
+ MEMORYPRESSURE_LOG("Memory pressure relief: " STRING_SPECIFICATION ": (Unable to get dirty memory information for process)", m_logString);
+ return;
+ }
+
+ long residentDiff = currentMemory->resident - m_initialMemory->resident;
+ long physicalDiff = currentMemory->physical - m_initialMemory->physical;
+
+ MEMORYPRESSURE_LOG("Memory pressure relief: " STRING_SPECIFICATION ": res = %zu/%zu/%ld, res+swap = %zu/%zu/%ld",
+ m_logString,
+ m_initialMemory->resident, currentMemory->resident, residentDiff,
+ m_initialMemory->physical, currentMemory->physical, physicalDiff);
+}
+
+#if !PLATFORM(COCOA) && !OS(LINUX) && !PLATFORM(WIN)
+void MemoryPressureHandler::install() { }
+void MemoryPressureHandler::uninstall() { }
+void MemoryPressureHandler::holdOff(unsigned) { }
+void MemoryPressureHandler::respondToMemoryPressure(Critical, Synchronous) { }
+void MemoryPressureHandler::platformReleaseMemory(Critical) { }
+std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage() { return std::nullopt; }
+#endif
+
+#if !PLATFORM(WIN)
+void MemoryPressureHandler::platformInitialize() { }
+#endif
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWTFwtfMemoryPressureHandlerhfromrev213211trunkSourceWebCoreplatformMemoryPressureHandlerh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/MemoryPressureHandler.h (from rev 213211, trunk/Source/WebCore/platform/MemoryPressureHandler.h) (0 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/MemoryPressureHandler.h         (rev 0)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -0,0 +1,213 @@
</span><ins>+/*
+ * Copyright (C) 2011-2017 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2014 Raspberry Pi Foundation. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <atomic>
+#include <ctime>
+#include <functional>
+#include <wtf/FastMalloc.h>
+#include <wtf/Forward.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Optional.h>
+#include <wtf/RunLoop.h>
+
+#if USE(GLIB)
+#include <wtf/glib/GRefPtr.h>
+#endif
+
+#if PLATFORM(WIN)
+#include <wtf/win/Win32Handle.h>
+#endif
+
+namespace WTF {
+
+enum class MemoryUsagePolicy {
+ Unrestricted, // Allocate as much as you want
+ Conservative, // Maybe you don't cache every single thing
+ Strict, // Time to start pinching pennies for real
+ Panic, // OH GOD WE'RE SINKING, THROW EVERYTHING OVERBOARD
+};
+
+enum class Critical { No, Yes };
+enum class Synchronous { No, Yes };
+
+typedef std::function<void(Critical, Synchronous)> LowMemoryHandler;
+
+class MemoryPressureHandler {
+ friend class WTF::NeverDestroyed<MemoryPressureHandler>;
+public:
+ WTF_EXPORT_PRIVATE static MemoryPressureHandler& singleton();
+
+ WTF_EXPORT_PRIVATE void install();
+
+ WTF_EXPORT_PRIVATE void setShouldUsePeriodicMemoryMonitor(bool);
+
+ void setMemoryKillCallback(WTF::Function<void()> function) { m_memoryKillCallback = WTFMove(function); }
+ void setProcessIsEligibleForMemoryKillCallback(WTF::Function<bool()> function) { m_processIsEligibleForMemoryKillCallback = WTFMove(function); }
+
+ void setLowMemoryHandler(LowMemoryHandler&& handler)
+ {
+ m_lowMemoryHandler = WTFMove(handler);
+ }
+
+ bool isUnderMemoryPressure() const
+ {
+ return m_underMemoryPressure
+#if PLATFORM(MAC)
+ || m_memoryUsagePolicy >= MemoryUsagePolicy::Strict
+#endif
+ || m_isSimulatingMemoryPressure;
+ }
+ void setUnderMemoryPressure(bool b) { m_underMemoryPressure = b; }
+
+#if OS(LINUX)
+ void setMemoryPressureMonitorHandle(int fd);
+#endif
+
+ class ReliefLogger {
+ public:
+ explicit ReliefLogger(const char *log)
+ : m_logString(log)
+ , m_initialMemory(loggingEnabled() ? platformMemoryUsage() : MemoryUsage { })
+ {
+ }
+
+ ~ReliefLogger()
+ {
+ if (loggingEnabled())
+ logMemoryUsageChange();
+ }
+
+
+ const char* logString() const { return m_logString; }
+ static void setLoggingEnabled(bool enabled) { s_loggingEnabled = enabled; }
+ static bool loggingEnabled()
+ {
+#if RELEASE_LOG_DISABLED
+ return s_loggingEnabled;
+#else
+ return true;
+#endif
+ }
+
+ private:
+ struct MemoryUsage {
+ MemoryUsage() = default;
+ MemoryUsage(size_t resident, size_t physical)
+ : resident(resident)
+ , physical(physical)
+ {
+ }
+ size_t resident { 0 };
+ size_t physical { 0 };
+ };
+ std::optional<MemoryUsage> platformMemoryUsage();
+ void logMemoryUsageChange();
+
+ const char* m_logString;
+ std::optional<MemoryUsage> m_initialMemory;
+
+ WTF_EXPORT_PRIVATE static bool s_loggingEnabled;
+ };
+
+ WTF_EXPORT_PRIVATE void releaseMemory(Critical, Synchronous = Synchronous::No);
+
+ WTF_EXPORT_PRIVATE void beginSimulatedMemoryPressure();
+ WTF_EXPORT_PRIVATE void endSimulatedMemoryPressure();
+
+private:
+ void uninstall();
+
+ void holdOff(unsigned);
+
+ MemoryPressureHandler();
+ ~MemoryPressureHandler() = delete;
+
+ void respondToMemoryPressure(Critical, Synchronous = Synchronous::No);
+ void platformReleaseMemory(Critical);
+ void platformInitialize();
+
+ NO_RETURN_DUE_TO_CRASH void didExceedMemoryLimitAndFailedToRecover();
+ void measurementTimerFired();
+
+#if OS(LINUX)
+ class EventFDPoller {
+ WTF_MAKE_NONCOPYABLE(EventFDPoller); WTF_MAKE_FAST_ALLOCATED;
+ public:
+ EventFDPoller(int fd, std::function<void ()>&& notifyHandler);
+ ~EventFDPoller();
+
+ private:
+ void readAndNotify() const;
+
+ std::optional<int> m_fd;
+ std::function<void ()> m_notifyHandler;
+#if USE(GLIB)
+ GRefPtr<GSource> m_source;
+#else
+ ThreadIdentifier m_threadID;
+#endif
+ };
+#endif
+
+ bool m_installed { false };
+ LowMemoryHandler m_lowMemoryHandler;
+
+ std::atomic<bool> m_underMemoryPressure;
+ bool m_isSimulatingMemoryPressure { false };
+
+ std::unique_ptr<RunLoop::Timer<MemoryPressureHandler>> m_measurementTimer;
+ MemoryUsagePolicy m_memoryUsagePolicy { MemoryUsagePolicy::Unrestricted };
+ WTF::Function<void()> m_memoryKillCallback;
+ WTF::Function<bool()> m_processIsEligibleForMemoryKillCallback;
+
+ WTFLogChannel m_logChannel;
+
+#if OS(WINDOWS)
+ void windowsMeasurementTimerFired();
+ RunLoop::Timer<MemoryPressureHandler> m_windowsMeasurementTimer;
+ Win32Handle m_lowMemoryHandle;
+#endif
+
+#if OS(LINUX)
+ std::optional<int> m_eventFD;
+ std::optional<int> m_pressureLevelFD;
+ std::unique_ptr<EventFDPoller> m_eventFDPoller;
+ RunLoop::Timer<MemoryPressureHandler> m_holdOffTimer;
+ void holdOffTimerFired();
+ void logErrorAndCloseFDs(const char* error);
+ bool tryEnsureEventFD();
+#endif
+};
+
+extern WTFLogChannel LogMemoryPressure;
+
+} // namespace WTF
+
+using WTF::Critical;
+using WTF::MemoryPressureHandler;
+using WTF::Synchronous;
</ins></span></pre></div>
<a id="trunkSourceWTFwtfPlatformEflcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/PlatformEfl.cmake (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/PlatformEfl.cmake        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WTF/wtf/PlatformEfl.cmake        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -10,6 +10,9 @@
</span><span class="cx"> efl/WorkQueueEfl.cpp
</span><span class="cx">
</span><span class="cx"> glib/GRefPtr.cpp
</span><ins>+
+ linux/CurrentProcessMemoryStatus.cpp
+ linux/MemoryPressureHandlerLinux.cpp
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> list(APPEND WTF_LIBRARIES
</span></span></pre></div>
<a id="trunkSourceWTFwtfPlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/PlatformGTK.cmake (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/PlatformGTK.cmake        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WTF/wtf/PlatformGTK.cmake        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -7,6 +7,10 @@
</span><span class="cx"> glib/GRefPtr.cpp
</span><span class="cx"> glib/MainThreadGLib.cpp
</span><span class="cx"> glib/RunLoopGLib.cpp
</span><ins>+
+ linux/CurrentProcessMemoryStatus.cpp
+ linux/MemoryPressureHandlerLinux.cpp
+
</ins><span class="cx"> PlatformUserPreferredLanguagesUnix.cpp
</span><span class="cx"> UniStdExtras.cpp
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWTFwtfPlatformMaccmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/PlatformMac.cmake (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/PlatformMac.cmake        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WTF/wtf/PlatformMac.cmake        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -22,6 +22,7 @@
</span><span class="cx">
</span><span class="cx"> cf/RunLoopCF.cpp
</span><span class="cx">
</span><ins>+ cocoa/MemoryPressureHandlerCocoa.mm
</ins><span class="cx"> cocoa/WorkQueueCocoa.cpp
</span><span class="cx">
</span><span class="cx"> mac/DeprecatedSymbolsUsedBySafari.mm
</span></span></pre></div>
<a id="trunkSourceWTFwtfPlatformWincmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/PlatformWin.cmake (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/PlatformWin.cmake        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WTF/wtf/PlatformWin.cmake        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -9,6 +9,7 @@
</span><span class="cx"> text/cf/StringViewCF.cpp
</span><span class="cx">
</span><span class="cx"> win/MainThreadWin.cpp
</span><ins>+ win/MemoryPressureHandlerWin.cpp
</ins><span class="cx"> win/RunLoopWin.cpp
</span><span class="cx"> win/WorkQueueWin.cpp
</span><span class="cx"> )
</span></span></pre></div>
<a id="trunkSourceWTFwtfcocoaMemoryPressureHandlerCocoammfromrev213211trunkSourceWebCoreplatformcocoaMemoryPressureHandlerCocoamm"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/cocoa/MemoryPressureHandlerCocoa.mm (from rev 213211, trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm) (0 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/cocoa/MemoryPressureHandlerCocoa.mm         (rev 0)
+++ trunk/Source/WTF/wtf/cocoa/MemoryPressureHandlerCocoa.mm        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -0,0 +1,193 @@
</span><ins>+/*
+ * Copyright (C) 2011-2017 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "MemoryPressureHandler.h"
+
+#import <mach/mach.h>
+#import <mach/task_info.h>
+#import <malloc/malloc.h>
+#import <notify.h>
+#import <wtf/CurrentTime.h>
+
+#define ENABLE_FMW_FOOTPRINT_COMPARISON 0
+
+extern "C" void cache_simulate_memory_warning_event(uint64_t);
+
+namespace WTF {
+
+void MemoryPressureHandler::platformReleaseMemory(Critical critical)
+{
+ if (critical == Critical::Yes && (!isUnderMemoryPressure() || m_isSimulatingMemoryPressure)) {
+ // libcache listens to OS memory notifications, but for process suspension
+ // or memory pressure simulation, we need to prod it manually:
+ cache_simulate_memory_warning_event(DISPATCH_MEMORYPRESSURE_CRITICAL);
+ }
+}
+
+static dispatch_source_t _cache_event_source = 0;
+static dispatch_source_t _timer_event_source = 0;
+static int _notifyToken;
+
+// Disable memory event reception for a minimum of s_minimumHoldOffTime
+// seconds after receiving an event. Don't let events fire any sooner than
+// s_holdOffMultiplier times the last cleanup processing time. Effectively
+// this is 1 / s_holdOffMultiplier percent of the time.
+// These value seems reasonable and testing verifies that it throttles frequent
+// low memory events, greatly reducing CPU usage.
+static const unsigned s_minimumHoldOffTime = 5;
+#if !PLATFORM(IOS)
+static const unsigned s_holdOffMultiplier = 20;
+#endif
+
+void MemoryPressureHandler::install()
+{
+ if (m_installed || _timer_event_source)
+ return;
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+#if PLATFORM(IOS)
+ _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_NORMAL | DISPATCH_MEMORYPRESSURE_WARN | DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue());
+#elif PLATFORM(MAC)
+ _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue());
+#endif
+
+ dispatch_set_context(_cache_event_source, this);
+ dispatch_source_set_event_handler(_cache_event_source, ^{
+ bool critical = true;
+#if PLATFORM(IOS)
+ unsigned long status = dispatch_source_get_data(_cache_event_source);
+ critical = status == DISPATCH_MEMORYPRESSURE_CRITICAL;
+ auto& memoryPressureHandler = MemoryPressureHandler::singleton();
+ bool wasCritical = memoryPressureHandler.isUnderMemoryPressure();
+ memoryPressureHandler.setUnderMemoryPressure(critical);
+ if (status == DISPATCH_MEMORYPRESSURE_NORMAL) {
+ if (ReliefLogger::loggingEnabled())
+ NSLog(@"System is no longer under (%s) memory pressure.", wasCritical ? "critical" : "non-critical");
+ return;
+ }
+
+ if (ReliefLogger::loggingEnabled())
+ NSLog(@"Got memory pressure notification (%s)", critical ? "critical" : "non-critical");
+#endif
+ MemoryPressureHandler::singleton().respondToMemoryPressure(critical ? Critical::Yes : Critical::No);
+ });
+ dispatch_resume(_cache_event_source);
+ });
+
+ // Allow simulation of memory pressure with "notifyutil -p org.WebKit.lowMemory"
+ notify_register_dispatch("org.WebKit.lowMemory", &_notifyToken, dispatch_get_main_queue(), ^(int) {
+#if ENABLE(FMW_FOOTPRINT_COMPARISON)
+ auto footprintBefore = pagesPerVMTag();
+#endif
+ beginSimulatedMemoryPressure();
+
+ WTF::releaseFastMallocFreeMemory();
+ malloc_zone_pressure_relief(nullptr, 0);
+
+#if ENABLE(FMW_FOOTPRINT_COMPARISON)
+ auto footprintAfter = pagesPerVMTag();
+ logFootprintComparison(footprintBefore, footprintAfter);
+#endif
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ endSimulatedMemoryPressure();
+ });
+ });
+
+ m_installed = true;
+}
+
+void MemoryPressureHandler::uninstall()
+{
+ if (!m_installed)
+ return;
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (_cache_event_source) {
+ dispatch_source_cancel(_cache_event_source);
+ dispatch_release(_cache_event_source);
+ _cache_event_source = 0;
+ }
+
+ if (_timer_event_source) {
+ dispatch_source_cancel(_timer_event_source);
+ dispatch_release(_timer_event_source);
+ _timer_event_source = 0;
+ }
+ });
+
+ m_installed = false;
+
+ notify_cancel(_notifyToken);
+}
+
+void MemoryPressureHandler::holdOff(unsigned seconds)
+{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ _timer_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
+ if (_timer_event_source) {
+ dispatch_set_context(_timer_event_source, this);
+ dispatch_source_set_timer(_timer_event_source, dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 1 * s_minimumHoldOffTime);
+ dispatch_source_set_event_handler(_timer_event_source, ^{
+ if (_timer_event_source) {
+ dispatch_source_cancel(_timer_event_source);
+ dispatch_release(_timer_event_source);
+ _timer_event_source = 0;
+ }
+ MemoryPressureHandler::singleton().install();
+ });
+ dispatch_resume(_timer_event_source);
+ }
+ });
+}
+
+void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
+{
+#if !PLATFORM(IOS)
+ uninstall();
+ double startTime = monotonicallyIncreasingTime();
+#endif
+
+ releaseMemory(critical, synchronous);
+
+#if !PLATFORM(IOS)
+ unsigned holdOffTime = (monotonicallyIncreasingTime() - startTime) * s_holdOffMultiplier;
+ holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
+#endif
+}
+
+std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage()
+{
+ task_vm_info_data_t vmInfo;
+ mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
+ kern_return_t err = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
+ if (err != KERN_SUCCESS)
+ return std::nullopt;
+
+ return MemoryUsage {static_cast<size_t>(vmInfo.internal), static_cast<size_t>(vmInfo.phys_footprint)};
+}
+
+} // namespace WTF
</ins></span></pre></div>
<a id="trunkSourceWTFwtflinuxCurrentProcessMemoryStatuscppfromrev213211trunkSourceWebCoreplatformlinuxCurrentProcessMemoryStatuscpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/linux/CurrentProcessMemoryStatus.cpp (from rev 213211, trunk/Source/WebCore/platform/linux/CurrentProcessMemoryStatus.cpp) (0 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/linux/CurrentProcessMemoryStatus.cpp         (rev 0)
+++ trunk/Source/WTF/wtf/linux/CurrentProcessMemoryStatus.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -0,0 +1,77 @@
</span><ins>+/*
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CurrentProcessMemoryStatus.h"
+
+#if OS(LINUX)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+namespace WTF {
+
+static inline size_t systemPageSize()
+{
+ static size_t pageSize = 0;
+ if (!pageSize)
+ pageSize = sysconf(_SC_PAGE_SIZE);
+ return pageSize;
+}
+
+void currentProcessMemoryStatus(ProcessMemoryStatus& memoryStatus)
+{
+ FILE* file = fopen("/proc/self/statm", "r");
+ if (!file)
+ return;
+
+ char buffer[128];
+ char* line = fgets(buffer, 128, file);
+ fclose(file);
+ if (!line)
+ return;
+
+ size_t pageSize = systemPageSize();
+ char* end = nullptr;
+ unsigned long long intValue = strtoull(line, &end, 10);
+ memoryStatus.size = intValue * pageSize;
+ intValue = strtoull(end, &end, 10);
+ memoryStatus.resident = intValue * pageSize;
+ intValue = strtoull(end, &end, 10);
+ memoryStatus.shared = intValue * pageSize;
+ intValue = strtoull(end, &end, 10);
+ memoryStatus.text = intValue * pageSize;
+ intValue = strtoull(end, &end, 10);
+ memoryStatus.lib = intValue * pageSize;
+ intValue = strtoull(end, &end, 10);
+ memoryStatus.data = intValue * pageSize;
+ intValue = strtoull(end, &end, 10);
+ memoryStatus.dt = intValue * pageSize;
+}
+
+} // namespace WTF
+
+#endif // OS(LINUX)
</ins></span></pre></div>
<a id="trunkSourceWTFwtflinuxCurrentProcessMemoryStatushfromrev213211trunkSourceWebCoreplatformlinuxCurrentProcessMemoryStatush"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/linux/CurrentProcessMemoryStatus.h (from rev 213211, trunk/Source/WebCore/platform/linux/CurrentProcessMemoryStatus.h) (0 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/linux/CurrentProcessMemoryStatus.h         (rev 0)
+++ trunk/Source/WTF/wtf/linux/CurrentProcessMemoryStatus.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -0,0 +1,49 @@
</span><ins>+/*
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if OS(LINUX)
+
+namespace WTF {
+
+struct ProcessMemoryStatus {
+ size_t size { 0 };
+ size_t resident { 0 };
+ size_t shared { 0 };
+ size_t text { 0 };
+ size_t lib { 0 };
+ size_t data { 0 };
+ size_t dt { 0 };
+};
+
+void currentProcessMemoryStatus(ProcessMemoryStatus&);
+
+} // namespace WTF
+
+using WTF::ProcessMemoryStatus;
+using WTF::currentProcessMemoryStatus;
+
+#endif // OS(LINUX)
</ins></span></pre></div>
<a id="trunkSourceWTFwtflinuxMemoryPressureHandlerLinuxcppfromrev213211trunkSourceWebCoreplatformlinuxMemoryPressureHandlerLinuxcpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp (from rev 213211, trunk/Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp) (0 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp         (rev 0)
+++ trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -0,0 +1,320 @@
</span><ins>+/*
+ * Copyright (C) 2011, 2012 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2014 Raspberry Pi Foundation. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MemoryPressureHandler.h"
+
+#if OS(LINUX)
+
+#include <errno.h>
+#include <fcntl.h>
+#include <malloc.h>
+#include <sys/eventfd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/MainThread.h>
+#include <wtf/linux/CurrentProcessMemoryStatus.h>
+#include <wtf/text/WTFString.h>
+
+#if USE(GLIB)
+#include <glib-unix.h>
+#endif
+
+#define LOG_CHANNEL_PREFIX Log
+
+namespace WTF {
+
+// Disable memory event reception for a minimum of s_minimumHoldOffTime
+// seconds after receiving an event. Don't let events fire any sooner than
+// s_holdOffMultiplier times the last cleanup processing time. Effectively
+// this is 1 / s_holdOffMultiplier percent of the time.
+// If after releasing the memory we don't free at least s_minimumBytesFreedToUseMinimumHoldOffTime,
+// we wait longer to try again (s_maximumHoldOffTime).
+// These value seems reasonable and testing verifies that it throttles frequent
+// low memory events, greatly reducing CPU usage.
+static const unsigned s_minimumHoldOffTime = 5;
+static const unsigned s_maximumHoldOffTime = 30;
+static const size_t s_minimumBytesFreedToUseMinimumHoldOffTime = 1 * MB;
+static const unsigned s_holdOffMultiplier = 20;
+
+static const char* s_cgroupMemoryPressureLevel = "/sys/fs/cgroup/memory/memory.pressure_level";
+static const char* s_cgroupEventControl = "/sys/fs/cgroup/memory/cgroup.event_control";
+
+#if USE(GLIB)
+typedef struct {
+ GSource source;
+ gpointer fdTag;
+ GIOCondition condition;
+} EventFDSource;
+
+static const unsigned eventFDSourceCondition = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
+
+static GSourceFuncs eventFDSourceFunctions = {
+ nullptr, // prepare
+ nullptr, // check
+ // dispatch
+ [](GSource* source, GSourceFunc callback, gpointer userData) -> gboolean
+ {
+ EventFDSource* eventFDSource = reinterpret_cast<EventFDSource*>(source);
+ unsigned events = g_source_query_unix_fd(source, eventFDSource->fdTag) & eventFDSourceCondition;
+ if (events & G_IO_HUP || events & G_IO_ERR || events & G_IO_NVAL)
+ return G_SOURCE_REMOVE;
+
+ gboolean returnValue = G_SOURCE_CONTINUE;
+ if (events & G_IO_IN)
+ returnValue = callback(userData);
+ g_source_set_ready_time(source, -1);
+ return returnValue;
+ },
+ nullptr, // finalize
+ nullptr, // closure_callback
+ nullptr, // closure_marshall
+};
+#endif
+
+MemoryPressureHandler::EventFDPoller::EventFDPoller(int fd, std::function<void ()>&& notifyHandler)
+ : m_fd(fd)
+ , m_notifyHandler(WTFMove(notifyHandler))
+{
+#if USE(GLIB)
+ m_source = adoptGRef(g_source_new(&eventFDSourceFunctions, sizeof(EventFDSource)));
+ g_source_set_name(m_source.get(), "WTF: MemoryPressureHandler");
+ if (!g_unix_set_fd_nonblocking(m_fd.value(), TRUE, nullptr)) {
+ LOG(MemoryPressure, "Failed to set eventfd nonblocking");
+ return;
+ }
+
+ EventFDSource* eventFDSource = reinterpret_cast<EventFDSource*>(m_source.get());
+ eventFDSource->fdTag = g_source_add_unix_fd(m_source.get(), m_fd.value(), static_cast<GIOCondition>(eventFDSourceCondition));
+ g_source_set_callback(m_source.get(), [](gpointer userData) -> gboolean {
+ static_cast<EventFDPoller*>(userData)->readAndNotify();
+ return G_SOURCE_REMOVE;
+ }, this, nullptr);
+ g_source_attach(m_source.get(), nullptr);
+#else
+ m_threadID = createThread("WTF: MemoryPressureHandler", [this] { readAndNotify(); }
+#endif
+}
+
+MemoryPressureHandler::EventFDPoller::~EventFDPoller()
+{
+ m_fd = std::nullopt;
+#if USE(GLIB)
+ g_source_destroy(m_source.get());
+#else
+ detachThread(m_threadID);
+#endif
+}
+
+static inline bool isFatalReadError(int error)
+{
+#if USE(GLIB)
+ // We don't really need to read the buffer contents, if the poller
+ // notified us, but read would block or is no longer available, is
+ // enough to trigger the memory pressure handler.
+ return error != EAGAIN && error != EWOULDBLOCK;
+#else
+ return true;
+#endif
+}
+
+void MemoryPressureHandler::EventFDPoller::readAndNotify() const
+{
+ if (!m_fd) {
+ LOG(MemoryPressure, "Invalidate eventfd.");
+ return;
+ }
+
+ uint64_t buffer;
+ if (read(m_fd.value(), &buffer, sizeof(buffer)) == -1) {
+ if (isFatalReadError(errno)) {
+ LOG(MemoryPressure, "Failed to read eventfd.");
+ return;
+ }
+ }
+
+ m_notifyHandler();
+}
+
+inline void MemoryPressureHandler::logErrorAndCloseFDs(const char* log)
+{
+ if (log)
+ LOG(MemoryPressure, "%s, error : %m", log);
+
+ if (m_eventFD) {
+ close(m_eventFD.value());
+ m_eventFD = std::nullopt;
+ }
+ if (m_pressureLevelFD) {
+ close(m_pressureLevelFD.value());
+ m_pressureLevelFD = std::nullopt;
+ }
+}
+
+bool MemoryPressureHandler::tryEnsureEventFD()
+{
+ if (m_eventFD)
+ return true;
+
+ // Try to use cgroups instead.
+ int fd = eventfd(0, EFD_CLOEXEC);
+ if (fd == -1) {
+ LOG(MemoryPressure, "eventfd() failed: %m");
+ return false;
+ }
+ m_eventFD = fd;
+
+ fd = open(s_cgroupMemoryPressureLevel, O_CLOEXEC | O_RDONLY);
+ if (fd == -1) {
+ logErrorAndCloseFDs("Failed to open memory.pressure_level");
+ return false;
+ }
+ m_pressureLevelFD = fd;
+
+ fd = open(s_cgroupEventControl, O_CLOEXEC | O_WRONLY);
+ if (fd == -1) {
+ logErrorAndCloseFDs("Failed to open cgroup.event_control");
+ return false;
+ }
+
+ char line[128] = {0, };
+ if (snprintf(line, sizeof(line), "%d %d low", m_eventFD.value(), m_pressureLevelFD.value()) < 0
+ || write(fd, line, strlen(line) + 1) < 0) {
+ logErrorAndCloseFDs("Failed to write cgroup.event_control");
+ close(fd);
+ return false;
+ }
+ close(fd);
+
+ return true;
+}
+
+void MemoryPressureHandler::install()
+{
+ if (m_installed || m_holdOffTimer.isActive())
+ return;
+
+ if (!tryEnsureEventFD())
+ return;
+
+ m_eventFDPoller = std::make_unique<EventFDPoller>(m_eventFD.value(), [this] {
+ // FIXME: Current memcg does not provide any way for users to know how serious the memory pressure is.
+ // So we assume all notifications from memcg are critical for now. If memcg had better inferfaces
+ // to get a detailed memory pressure level in the future, we should update here accordingly.
+ bool critical = true;
+ if (ReliefLogger::loggingEnabled())
+ LOG(MemoryPressure, "Got memory pressure notification (%s)", critical ? "critical" : "non-critical");
+
+ setUnderMemoryPressure(critical);
+ if (isMainThread())
+ respondToMemoryPressure(critical ? Critical::Yes : Critical::No);
+ else
+ RunLoop::main().dispatch([this, critical] { respondToMemoryPressure(critical ? Critical::Yes : Critical::No); });
+ });
+
+ if (ReliefLogger::loggingEnabled() && isUnderMemoryPressure())
+ LOG(MemoryPressure, "System is no longer under memory pressure.");
+
+ setUnderMemoryPressure(false);
+ m_installed = true;
+}
+
+void MemoryPressureHandler::uninstall()
+{
+ if (!m_installed)
+ return;
+
+ m_holdOffTimer.stop();
+ m_eventFDPoller = nullptr;
+
+ if (m_pressureLevelFD) {
+ close(m_pressureLevelFD.value());
+ m_pressureLevelFD = std::nullopt;
+
+ // Only close the eventFD used for cgroups.
+ if (m_eventFD) {
+ close(m_eventFD.value());
+ m_eventFD = std::nullopt;
+ }
+ }
+
+ m_installed = false;
+}
+
+void MemoryPressureHandler::holdOffTimerFired()
+{
+ install();
+}
+
+void MemoryPressureHandler::holdOff(unsigned seconds)
+{
+ m_holdOffTimer.startOneShot(seconds);
+}
+
+static size_t processMemoryUsage()
+{
+ ProcessMemoryStatus memoryStatus;
+ currentProcessMemoryStatus(memoryStatus);
+ return (memoryStatus.resident - memoryStatus.shared);
+}
+
+void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
+{
+ uninstall();
+
+ double startTime = monotonicallyIncreasingTime();
+ int64_t processMemory = processMemoryUsage();
+ releaseMemory(critical, synchronous);
+ int64_t bytesFreed = processMemory - processMemoryUsage();
+ unsigned holdOffTime = s_maximumHoldOffTime;
+ if (bytesFreed > 0 && static_cast<size_t>(bytesFreed) >= s_minimumBytesFreedToUseMinimumHoldOffTime)
+ holdOffTime = (monotonicallyIncreasingTime() - startTime) * s_holdOffMultiplier;
+ holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
+}
+
+void MemoryPressureHandler::platformReleaseMemory(Critical)
+{
+#ifdef __GLIBC__
+ malloc_trim(0);
+#endif
+}
+
+std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage()
+{
+ return MemoryUsage {processMemoryUsage(), 0};
+}
+
+void MemoryPressureHandler::setMemoryPressureMonitorHandle(int fd)
+{
+ ASSERT(!m_eventFD);
+ m_eventFD = fd;
+}
+
+} // namespace WTF
+
+#endif // OS(LINUX)
</ins></span></pre></div>
<a id="trunkSourceWTFwtfwinMemoryPressureHandlerWincppfromrev213211trunkSourceWebCoreplatformwinMemoryPressureHandlerWincpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/win/MemoryPressureHandlerWin.cpp (from rev 213211, trunk/Source/WebCore/platform/win/MemoryPressureHandlerWin.cpp) (0 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/win/MemoryPressureHandlerWin.cpp         (rev 0)
+++ trunk/Source/WTF/wtf/win/MemoryPressureHandlerWin.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -0,0 +1,104 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MemoryPressureHandler.h"
+
+#include <psapi.h>
+#include <wtf/NeverDestroyed.h>
+
+namespace WTF {
+
+void MemoryPressureHandler::platformInitialize()
+{
+ m_lowMemoryHandle = CreateMemoryResourceNotification(LowMemoryResourceNotification);
+}
+
+void MemoryPressureHandler::windowsMeasurementTimerFired()
+{
+ setUnderMemoryPressure(false);
+
+ BOOL memoryLow;
+
+ if (QueryMemoryResourceNotification(m_lowMemoryHandle.get(), &memoryLow) && memoryLow) {
+ setUnderMemoryPressure(true);
+ releaseMemory(Critical::Yes);
+ return;
+ }
+
+#if CPU(X86)
+ PROCESS_MEMORY_COUNTERS_EX counters;
+
+ if (!GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&counters), sizeof(counters)))
+ return;
+
+ // On Windows, 32-bit processes have 2GB of memory available, where some is used by the system.
+ // Debugging has shown that allocations might fail and cause crashes when memory usage is > ~1GB.
+ // We should start releasing memory before we reach 1GB.
+ const int maxMemoryUsageBytes = 0.9 * 1024 * 1024 * 1024;
+
+ if (counters.PrivateUsage > maxMemoryUsageBytes) {
+ setUnderMemoryPressure(true);
+ releaseMemory(Critical::Yes);
+ }
+#endif
+}
+
+void MemoryPressureHandler::platformReleaseMemory(Critical)
+{
+}
+
+void MemoryPressureHandler::install()
+{
+ m_installed = true;
+ m_windowsMeasurementTimer.startRepeating(60.0);
+}
+
+void MemoryPressureHandler::uninstall()
+{
+ if (!m_installed)
+ return;
+
+ m_windowsMeasurementTimer.stop();
+ m_installed = false;
+}
+
+void MemoryPressureHandler::holdOff(unsigned seconds)
+{
+}
+
+void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
+{
+ uninstall();
+
+ releaseMemory(critical, synchronous);
+}
+
+std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage()
+{
+ return std::nullopt;
+}
+
+} // namespace WTF
</ins></span></pre></div>
<a id="trunkSourceWTFwtfwinWin32Handlehfromrev213211trunkSourceWebCoreplatformwinWin32Handleh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/win/Win32Handle.h (from rev 213211, trunk/Source/WebCore/platform/win/Win32Handle.h) (0 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/win/Win32Handle.h         (rev 0)
+++ trunk/Source/WTF/wtf/win/Win32Handle.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -0,0 +1,66 @@
</span><ins>+/*
+ * Copyright (C) 2011 Patrick Gansterer <paroga@paroga.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <memory>
+#include <windows.h>
+#include <wtf/Noncopyable.h>
+
+namespace WTF {
+
+class Win32Handle {
+ WTF_MAKE_NONCOPYABLE(Win32Handle);
+public:
+ Win32Handle() : m_handle(INVALID_HANDLE_VALUE) { }
+ explicit Win32Handle(HANDLE handle) : m_handle(handle) { }
+
+ ~Win32Handle() { clear(); }
+
+ void clear()
+ {
+ if (!isValid())
+ return;
+ CloseHandle(m_handle);
+ m_handle = INVALID_HANDLE_VALUE;
+ }
+
+ bool isValid() const { return m_handle != INVALID_HANDLE_VALUE; }
+
+ HANDLE get() const { return m_handle; }
+ HANDLE release() { HANDLE ret = m_handle; m_handle = INVALID_HANDLE_VALUE; return ret; }
+
+ Win32Handle& operator=(HANDLE handle)
+ {
+ clear();
+ m_handle = handle;
+ return *this;
+ }
+
+private:
+ HANDLE m_handle;
+};
+
+} // namespace WTF
+
</ins></span></pre></div>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/CMakeLists.txt        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -2107,7 +2107,6 @@
</span><span class="cx"> platform/LowPowerModeNotifier.cpp
</span><span class="cx"> platform/MIMETypeRegistry.cpp
</span><span class="cx"> platform/MainThreadSharedTimer.cpp
</span><del>- platform/MemoryPressureHandler.cpp
</del><span class="cx"> platform/NotImplemented.cpp
</span><span class="cx"> platform/PasteboardWriterData.cpp
</span><span class="cx"> platform/PlatformSpeechSynthesisUtterance.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/ChangeLog        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2017-03-01 Andreas Kling <akling@apple.com>
+
+ Move MemoryPressureHandler to WTF
+ <https://webkit.org/b/168908>
+
+ Reviewed by Sam Weinig.
+
+ * CMakeLists.txt:
+ * PlatformMac.cmake:
+ * PlatformWin.cmake:
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/ScriptController.cpp:
+ * history/PageCache.cpp:
+ * html/HTMLMediaElement.cpp:
+ * inspector/InspectorInstrumentation.h:
+ * inspector/InspectorMemoryAgent.h:
+ * page/FrameView.cpp:
+ * page/MemoryRelease.h:
+ * page/linux/ResourceUsageThreadLinux.cpp:
+ * platform/Linux.cmake:
+ * platform/graphics/FontCache.cpp:
+ * platform/graphics/WidthCache.h:
+ * platform/graphics/ca/TileController.cpp:
+ * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h:
+ * platform/ios/LegacyTileCache.mm:
+ * platform/ios/LegacyTileGrid.mm:
+ * platform/ios/LegacyTileLayerPool.mm:
+ * platform/ios/TileControllerMemoryHandlerIOS.cpp:
+ * testing/Internals.cpp:
+
</ins><span class="cx"> 2017-03-01 Per Arne Vollan <pvollan@apple.com>
</span><span class="cx">
</span><span class="cx"> [Win] Popup menus are too small in HiDPI mode.
</span></span></pre></div>
<a id="trunkSourceWebCorePlatformMaccmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PlatformMac.cmake (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PlatformMac.cmake        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/PlatformMac.cmake        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -324,7 +324,6 @@
</span><span class="cx"> platform/cocoa/LocalizedStringsCocoa.mm
</span><span class="cx"> platform/cocoa/MIMETypeRegistryCocoa.mm
</span><span class="cx"> platform/cocoa/MachSendRight.cpp
</span><del>- platform/cocoa/MemoryPressureHandlerCocoa.mm
</del><span class="cx"> platform/cocoa/NetworkExtensionContentFilter.mm
</span><span class="cx"> platform/cocoa/ParentalControlsContentFilter.mm
</span><span class="cx"> platform/cocoa/ScrollController.mm
</span></span></pre></div>
<a id="trunkSourceWebCorePlatformWincmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PlatformWin.cmake (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PlatformWin.cmake        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/PlatformWin.cmake        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -128,7 +128,6 @@
</span><span class="cx"> platform/win/KeyEventWin.cpp
</span><span class="cx"> platform/win/LocalizedStringsWin.cpp
</span><span class="cx"> platform/win/LoggingWin.cpp
</span><del>- platform/win/MemoryPressureHandlerWin.cpp
</del><span class="cx"> platform/win/MIMETypeRegistryWin.cpp
</span><span class="cx"> platform/win/MainThreadSharedTimerWin.cpp
</span><span class="cx"> platform/win/PasteboardWin.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -2595,8 +2595,6 @@
</span><span class="cx">                 656D373F0ADBA5DE00A4554D /* ResourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37270ADBA5DE00A4554D /* ResourceLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 656D37430ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 656D37480ADBA5DE00A4554D /* SubresourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37300ADBA5DE00A4554D /* SubresourceLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><del>-                6571DCC81385E6A400702DD0 /* MemoryPressureHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 657EDA071385CB97004E0645 /* MemoryPressureHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
-                657EDA081385CB97004E0645 /* MemoryPressureHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */; };
</del><span class="cx">                 658436860AE01B7400E53753 /* FrameLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 658436850AE01B7400E53753 /* FrameLoadRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 658F540319A1C9240088FC92 /* NSURLFileTypeMappingsSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 653EF83819A043AE0052202C /* NSURLFileTypeMappingsSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 6593923709AE4346002C531F /* URL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6593923509AE4346002C531F /* URL.cpp */; };
</span><span class="lines">@@ -4655,7 +4653,6 @@
</span><span class="cx">                 AD726FEE16DA11BC003A4E6D /* JSStyleSheetCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = AD726FEC16D9F4B9003A4E6D /* JSStyleSheetCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 AD726FEF16DA11F5003A4E6D /* JSCSSRuleCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = AD726FE916D9F40A003A4E6D /* JSCSSRuleCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 AD9FF6E11908391D003B61E0 /* IOSurfacePoolCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = AD9FF6E01908391D003B61E0 /* IOSurfacePoolCocoa.mm */; };
</span><del>-                ADB6B29818FB90240081963E /* MemoryPressureHandlerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = ADB6B29718FB90240081963E /* MemoryPressureHandlerCocoa.mm */; };
</del><span class="cx">                 ADBAD6EE1BCDD95500381325 /* ResourceUsageOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADBAD6EC1BCDD95000381325 /* ResourceUsageOverlay.cpp */; };
</span><span class="cx">                 ADBAD6EF1BCDD95700381325 /* ResourceUsageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = ADBAD6ED1BCDD95000381325 /* ResourceUsageOverlay.h */; };
</span><span class="cx">                 ADDA94C219687AA500453029 /* JSDocumentCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDA94BF19686F8000453029 /* JSDocumentCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -10050,8 +10047,6 @@
</span><span class="cx">                 656D37270ADBA5DE00A4554D /* ResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceLoader.h; sourceTree = "<group>"; };
</span><span class="cx">                 656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NetscapePlugInStreamLoader.h; sourceTree = "<group>"; };
</span><span class="cx">                 656D37300ADBA5DE00A4554D /* SubresourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SubresourceLoader.h; sourceTree = "<group>"; };
</span><del>-                657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryPressureHandler.cpp; sourceTree = "<group>"; };
-                657EDA071385CB97004E0645 /* MemoryPressureHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryPressureHandler.h; sourceTree = "<group>"; };
</del><span class="cx">                 658436850AE01B7400E53753 /* FrameLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoadRequest.h; sourceTree = "<group>"; };
</span><span class="cx">                 6593923509AE4346002C531F /* URL.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = URL.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 6593923609AE4346002C531F /* URL.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = URL.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -12573,7 +12568,6 @@
</span><span class="cx">                 AD726FEA16D9F40B003A4E6D /* JSCSSStyleDeclarationCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCSSStyleDeclarationCustom.h; sourceTree = "<group>"; };
</span><span class="cx">                 AD726FEC16D9F4B9003A4E6D /* JSStyleSheetCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStyleSheetCustom.h; sourceTree = "<group>"; };
</span><span class="cx">                 AD9FF6E01908391D003B61E0 /* IOSurfacePoolCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IOSurfacePoolCocoa.mm; sourceTree = "<group>"; };
</span><del>-                ADB6B29718FB90240081963E /* MemoryPressureHandlerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryPressureHandlerCocoa.mm; sourceTree = "<group>"; };
</del><span class="cx">                 ADBAD6EC1BCDD95000381325 /* ResourceUsageOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceUsageOverlay.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 ADBAD6ED1BCDD95000381325 /* ResourceUsageOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceUsageOverlay.h; sourceTree = "<group>"; };
</span><span class="cx">                 ADDA94BF19686F8000453029 /* JSDocumentCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDocumentCustom.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -20289,7 +20283,6 @@
</span><span class="cx">                                 1A4832B21A953BA6008B4DFE /* LocalizedStringsCocoa.mm */,
</span><span class="cx">                                 1A0409F21A43675C009E47F3 /* MachSendRight.cpp */,
</span><span class="cx">                                 1A0409DB1A4360B5009E47F3 /* MachSendRight.h */,
</span><del>-                                ADB6B29718FB90240081963E /* MemoryPressureHandlerCocoa.mm */,
</del><span class="cx">                                 C53D39331C97892D007F3AE9 /* MIMETypeRegistryCocoa.mm */,
</span><span class="cx">                                 A19D93491AA11B1E00B46C24 /* NetworkExtensionContentFilter.h */,
</span><span class="cx">                                 A19D93481AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm */,
</span><span class="lines">@@ -23110,8 +23103,6 @@
</span><span class="cx">                                 7AE6C93A1BE0C60100E19E03 /* MainThreadSharedTimer.h */,
</span><span class="cx">                                 CDF2B003181F059C00F2B424 /* MediaDescription.h */,
</span><span class="cx">                                 CD641EC7181ED60100EE4C41 /* MediaSample.h */,
</span><del>-                                657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */,
-                                657EDA071385CB97004E0645 /* MemoryPressureHandler.h */,
</del><span class="cx">                                 BC772C4C0C4EB3040083285F /* MIMETypeRegistry.cpp */,
</span><span class="cx">                                 BC772C4D0C4EB3040083285F /* MIMETypeRegistry.h */,
</span><span class="cx">                                 E1513D501677F08800149FCB /* NotImplemented.cpp */,
</span><span class="lines">@@ -27523,7 +27514,6 @@
</span><span class="cx">                                 519755FA1BFD7DC3003DE980 /* MemoryIndexCursor.h in Headers */,
</span><span class="cx">                                 51771DFF1BDB485000CAE8E4 /* MemoryObjectStore.h in Headers */,
</span><span class="cx">                                 517139061BF64DEC000D5F01 /* MemoryObjectStoreCursor.h in Headers */,
</span><del>-                                6571DCC81385E6A400702DD0 /* MemoryPressureHandler.h in Headers */,
</del><span class="cx">                                 413E00791DB0E4F2002341D2 /* MemoryRelease.h in Headers */,
</span><span class="cx">                                 93309DFA099E64920056E581 /* MergeIdenticalElementsCommand.h in Headers */,
</span><span class="cx">                                 E1ADECCE0E76AD8B004A1A5E /* MessageChannel.h in Headers */,
</span><span class="lines">@@ -31379,8 +31369,6 @@
</span><span class="cx">                                 519755F91BFD7DC3003DE980 /* MemoryIndexCursor.cpp in Sources */,
</span><span class="cx">                                 51771DFE1BDB485000CAE8E4 /* MemoryObjectStore.cpp in Sources */,
</span><span class="cx">                                 517139051BF64DEC000D5F01 /* MemoryObjectStoreCursor.cpp in Sources */,
</span><del>-                                657EDA081385CB97004E0645 /* MemoryPressureHandler.cpp in Sources */,
-                                ADB6B29818FB90240081963E /* MemoryPressureHandlerCocoa.mm in Sources */,
</del><span class="cx">                                 413E007A1DB0E4F9002341D2 /* MemoryRelease.cpp in Sources */,
</span><span class="cx">                                 413E007C1DB0E70A002341D2 /* MemoryReleaseCocoa.mm in Sources */,
</span><span class="cx">                                 93309DF9099E64920056E581 /* MergeIdenticalElementsCommand.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsScriptControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/ScriptController.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/ScriptController.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/bindings/js/ScriptController.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -39,7 +39,6 @@
</span><span class="cx"> #include "JSMainThreadExecState.h"
</span><span class="cx"> #include "LoadableModuleScript.h"
</span><span class="cx"> #include "MainFrame.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "ModuleFetchFailureKind.h"
</span><span class="cx"> #include "NP_jsobject.h"
</span><span class="cx"> #include "Page.h"
</span><span class="lines">@@ -63,6 +62,7 @@
</span><span class="cx"> #include <runtime/JSModuleRecord.h>
</span><span class="cx"> #include <runtime/JSNativeStdFunction.h>
</span><span class="cx"> #include <runtime/JSScriptFetcher.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/SetForScope.h>
</span><span class="cx"> #include <wtf/Threading.h>
</span><span class="cx"> #include <wtf/text/TextPosition.h>
</span></span></pre></div>
<a id="trunkSourceWebCorehistoryPageCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/history/PageCache.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/history/PageCache.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/history/PageCache.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -44,11 +44,11 @@
</span><span class="cx"> #include "IgnoreOpensDuringUnloadCountIncrementer.h"
</span><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include "MainFrame.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "NoEventDispatchAssertion.h"
</span><span class="cx"> #include "Page.h"
</span><span class="cx"> #include "Settings.h"
</span><span class="cx"> #include "SubframeLoader.h"
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><span class="cx"> #include <wtf/SetForScope.h>
</span><span class="cx"> #include <wtf/text/CString.h>
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -70,7 +70,6 @@
</span><span class="cx"> #include "MediaPlayer.h"
</span><span class="cx"> #include "MediaQueryEvaluator.h"
</span><span class="cx"> #include "MediaResourceLoader.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "NetworkingContext.h"
</span><span class="cx"> #include "NoEventDispatchAssertion.h"
</span><span class="cx"> #include "Page.h"
</span><span class="lines">@@ -95,6 +94,7 @@
</span><span class="cx"> #include <runtime/Uint8Array.h>
</span><span class="cx"> #include <wtf/CurrentTime.h>
</span><span class="cx"> #include <wtf/MathExtras.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/Ref.h>
</span><span class="cx"> #include <wtf/text/CString.h>
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorInstrumentationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -39,12 +39,12 @@
</span><span class="cx"> #include "HitTestResult.h"
</span><span class="cx"> #include "InspectorController.h"
</span><span class="cx"> #include "InspectorInstrumentationCookie.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "Page.h"
</span><span class="cx"> #include "ScriptExecutionContext.h"
</span><span class="cx"> #include "StorageArea.h"
</span><span class="cx"> #include "WorkerGlobalScope.h"
</span><span class="cx"> #include "WorkerInspectorController.h"
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/RefPtr.h>
</span><span class="cx">
</span><span class="cx"> #if ENABLE(WEB_REPLAY)
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorMemoryAgenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.h (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.h        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -28,10 +28,10 @@
</span><span class="cx"> #if ENABLE(RESOURCE_USAGE)
</span><span class="cx">
</span><span class="cx"> #include "InspectorWebAgentBase.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "ResourceUsageData.h"
</span><span class="cx"> #include <inspector/InspectorBackendDispatchers.h>
</span><span class="cx"> #include <inspector/InspectorFrontendDispatchers.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/page/FrameView.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -63,7 +63,6 @@
</span><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include "MainFrame.h"
</span><span class="cx"> #include "MemoryCache.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "OverflowEvent.h"
</span><span class="cx"> #include "Page.h"
</span><span class="cx"> #include "PageCache.h"
</span><span class="lines">@@ -98,6 +97,7 @@
</span><span class="cx"> #include "WheelEventTestTrigger.h"
</span><span class="cx">
</span><span class="cx"> #include <wtf/CurrentTime.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/Ref.h>
</span><span class="cx"> #include <wtf/SetForScope.h>
</span><span class="cx"> #include <wtf/SystemTracing.h>
</span></span></pre></div>
<a id="trunkSourceWebCorepageMemoryReleaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/MemoryRelease.h (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/MemoryRelease.h        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/page/MemoryRelease.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -25,7 +25,7 @@
</span><span class="cx">
</span><span class="cx"> #pragma once
</span><span class="cx">
</span><del>-#include "MemoryPressureHandler.h"
</del><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorepagelinuxResourceUsageThreadLinuxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -28,7 +28,6 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(RESOURCE_USAGE) && OS(LINUX)
</span><span class="cx">
</span><del>-#include "CurrentProcessMemoryStatus.h"
</del><span class="cx"> #include <errno.h>
</span><span class="cx"> #include <fcntl.h>
</span><span class="cx"> #include <heap/GCActivityCallback.h>
</span><span class="lines">@@ -38,6 +37,7 @@
</span><span class="cx"> #include <sys/stat.h>
</span><span class="cx"> #include <sys/types.h>
</span><span class="cx"> #include <unistd.h>
</span><ins>+#include <wtf/linux/CurrentProcessMemoryStatus.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformLinuxcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/Linux.cmake (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/Linux.cmake        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/Linux.cmake        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,11 +1,7 @@
</span><span class="cx"> list(APPEND WebCore_INCLUDE_DIRECTORIES
</span><del>- "${WEBCORE_DIR}/platform/linux"
</del><span class="cx"> "${WEBCORE_DIR}/platform/gamepad/linux"
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> list(APPEND WebCore_SOURCES
</span><span class="cx"> platform/gamepad/linux/GamepadDeviceLinux.cpp
</span><del>-
- platform/linux/CurrentProcessMemoryStatus.cpp
- platform/linux/MemoryPressureHandlerLinux.cpp
</del><span class="cx"> )
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformMemoryPressureHandlercpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/platform/MemoryPressureHandler.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/MemoryPressureHandler.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,215 +0,0 @@
</span><del>-/*
- * Copyright (C) 2011-2017 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "MemoryPressureHandler.h"
-
-#include "Logging.h"
-#include <wtf/MemoryFootprint.h>
-
-namespace WebCore {
-
-WEBCORE_EXPORT bool MemoryPressureHandler::ReliefLogger::s_loggingEnabled = false;
-
-MemoryPressureHandler& MemoryPressureHandler::singleton()
-{
- static NeverDestroyed<MemoryPressureHandler> memoryPressureHandler;
- return memoryPressureHandler;
-}
-
-MemoryPressureHandler::MemoryPressureHandler()
-#if OS(LINUX)
- : m_holdOffTimer(RunLoop::main(), this, &MemoryPressureHandler::holdOffTimerFired)
-#endif
-{
-}
-
-void MemoryPressureHandler::setShouldUsePeriodicMemoryMonitor(bool use)
-{
- if (use) {
- m_measurementTimer = std::make_unique<RunLoop::Timer<MemoryPressureHandler>>(RunLoop::main(), this, &MemoryPressureHandler::measurementTimerFired);
- m_measurementTimer->startRepeating(30);
- } else
- m_measurementTimer = nullptr;
-}
-
-#if !RELEASE_LOG_DISABLED
-static const char* toString(MemoryUsagePolicy policy)
-{
- switch (policy) {
- case MemoryUsagePolicy::Unrestricted: return "Unrestricted";
- case MemoryUsagePolicy::Conservative: return "Conservative";
- case MemoryUsagePolicy::Strict: return "Strict";
- case MemoryUsagePolicy::Panic: return "Panic";
- }
-}
-#endif
-
-static size_t thresholdForPolicy(MemoryUsagePolicy policy)
-{
- switch (policy) {
- case MemoryUsagePolicy::Conservative:
- return 1 * GB;
- case MemoryUsagePolicy::Strict:
- return 2 * GB;
- case MemoryUsagePolicy::Panic:
-#if CPU(X86_64) || CPU(ARM64)
- return 4 * GB;
-#else
- return 3 * GB;
-#endif
- case MemoryUsagePolicy::Unrestricted:
- default:
- ASSERT_NOT_REACHED();
- return 0;
- }
-}
-
-static MemoryUsagePolicy policyForFootprint(size_t footprint)
-{
- if (footprint >= thresholdForPolicy(MemoryUsagePolicy::Panic))
- return MemoryUsagePolicy::Panic;
- if (footprint >= thresholdForPolicy(MemoryUsagePolicy::Strict))
- return MemoryUsagePolicy::Strict;
- if (footprint >= thresholdForPolicy(MemoryUsagePolicy::Conservative))
- return MemoryUsagePolicy::Conservative;
- return MemoryUsagePolicy::Unrestricted;
-}
-
-void MemoryPressureHandler::measurementTimerFired()
-{
- auto footprint = memoryFootprint();
- if (!footprint)
- return;
-
- RELEASE_LOG(MemoryPressure, "Current memory footprint: %lu MB", footprint.value() / MB);
-
- auto newPolicy = policyForFootprint(footprint.value());
- if (newPolicy == m_memoryUsagePolicy) {
- if (m_memoryUsagePolicy != MemoryUsagePolicy::Panic)
- return;
- RELEASE_LOG(MemoryPressure, "Memory usage still above panic threshold");
- } else
- RELEASE_LOG(MemoryPressure, "Memory usage policy changed: %s -> %s", toString(m_memoryUsagePolicy), toString(newPolicy));
-
- m_memoryUsagePolicy = newPolicy;
-
- if (newPolicy == MemoryUsagePolicy::Unrestricted)
- return;
-
- if (newPolicy == MemoryUsagePolicy::Conservative) {
- // FIXME: Implement this policy by choosing which caches should respect it, and hooking them up.
- return;
- }
-
- if (newPolicy == MemoryUsagePolicy::Strict) {
- RELEASE_LOG(MemoryPressure, "Attempting to reduce memory footprint by freeing less important objects.");
- releaseMemory(Critical::No, Synchronous::No);
- return;
- }
-
- RELEASE_ASSERT(newPolicy == MemoryUsagePolicy::Panic);
-
- RELEASE_LOG(MemoryPressure, "Attempting to reduce memory footprint by freeing more important objects.");
- if (m_processIsEligibleForMemoryKillCallback) {
- if (!m_processIsEligibleForMemoryKillCallback()) {
- releaseMemory(Critical::Yes, Synchronous::No);
- return;
- }
- }
-
- releaseMemory(Critical::Yes, Synchronous::Yes);
-
- // Remeasure footprint to see how well the pressure handler did.
- footprint = memoryFootprint();
- RELEASE_ASSERT(footprint);
-
- RELEASE_LOG(MemoryPressure, "New memory footprint: %lu MB", footprint.value() / MB);
- if (footprint.value() < thresholdForPolicy(MemoryUsagePolicy::Panic)) {
- m_memoryUsagePolicy = policyForFootprint(footprint.value());
- RELEASE_LOG(MemoryPressure, "Pressure reduced below panic threshold. New memory usage policy: %s", toString(m_memoryUsagePolicy));
- return;
- }
-
- if (m_memoryKillCallback)
- m_memoryKillCallback();
-}
-
-void MemoryPressureHandler::beginSimulatedMemoryPressure()
-{
- m_isSimulatingMemoryPressure = true;
- respondToMemoryPressure(Critical::Yes, Synchronous::Yes);
-}
-
-void MemoryPressureHandler::endSimulatedMemoryPressure()
-{
- m_isSimulatingMemoryPressure = false;
-}
-
-void MemoryPressureHandler::releaseMemory(Critical critical, Synchronous synchronous)
-{
- if (!m_lowMemoryHandler)
- return;
-
- ReliefLogger log("Total");
- m_lowMemoryHandler(critical, synchronous);
- platformReleaseMemory(critical);
-}
-
-void MemoryPressureHandler::ReliefLogger::logMemoryUsageChange()
-{
-#if !RELEASE_LOG_DISABLED
-#define STRING_SPECIFICATION "%{public}s"
-#define MEMORYPRESSURE_LOG(...) RELEASE_LOG(MemoryPressure, __VA_ARGS__)
-#else
-#define STRING_SPECIFICATION "%s"
-#define MEMORYPRESSURE_LOG(...) WTFLogAlways(__VA_ARGS__)
-#endif
-
- auto currentMemory = platformMemoryUsage();
- if (!currentMemory || !m_initialMemory) {
- MEMORYPRESSURE_LOG("Memory pressure relief: " STRING_SPECIFICATION ": (Unable to get dirty memory information for process)", m_logString);
- return;
- }
-
- long residentDiff = currentMemory->resident - m_initialMemory->resident;
- long physicalDiff = currentMemory->physical - m_initialMemory->physical;
-
- MEMORYPRESSURE_LOG("Memory pressure relief: " STRING_SPECIFICATION ": res = %zu/%zu/%ld, res+swap = %zu/%zu/%ld",
- m_logString,
- m_initialMemory->resident, currentMemory->resident, residentDiff,
- m_initialMemory->physical, currentMemory->physical, physicalDiff);
-}
-
-#if !PLATFORM(COCOA) && !OS(LINUX) && !PLATFORM(WIN)
-void MemoryPressureHandler::install() { }
-void MemoryPressureHandler::uninstall() { }
-void MemoryPressureHandler::holdOff(unsigned) { }
-void MemoryPressureHandler::respondToMemoryPressure(Critical, Synchronous) { }
-void MemoryPressureHandler::platformReleaseMemory(Critical) { }
-std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage() { return std::nullopt; }
-#endif
-
-} // namespace WebCore
</del></span></pre></div>
<a id="trunkSourceWebCoreplatformMemoryPressureHandlerh"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/platform/MemoryPressureHandler.h (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/MemoryPressureHandler.h        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,198 +0,0 @@
</span><del>-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- * Copyright (C) 2014 Raspberry Pi Foundation. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef MemoryPressureHandler_h
-#define MemoryPressureHandler_h
-
-#include <atomic>
-#include <ctime>
-#include <functional>
-#include <wtf/FastMalloc.h>
-#include <wtf/Forward.h>
-#include <wtf/NeverDestroyed.h>
-#include <wtf/Optional.h>
-#include <wtf/RunLoop.h>
-
-#if USE(GLIB)
-#include <wtf/glib/GRefPtr.h>
-#endif
-
-namespace WebCore {
-
-enum class MemoryUsagePolicy {
- Unrestricted, // Allocate as much as you want
- Conservative, // Maybe you don't cache every single thing
- Strict, // Time to start pinching pennies for real
- Panic, // OH GOD WE'RE SINKING, THROW EVERYTHING OVERBOARD
-};
-
-enum class Critical { No, Yes };
-enum class Synchronous { No, Yes };
-
-typedef std::function<void(Critical, Synchronous)> LowMemoryHandler;
-
-class MemoryPressureHandler {
- WTF_MAKE_FAST_ALLOCATED;
- friend class WTF::NeverDestroyed<MemoryPressureHandler>;
-public:
- WEBCORE_EXPORT static MemoryPressureHandler& singleton();
-
- WEBCORE_EXPORT void install();
-
- WEBCORE_EXPORT void setShouldUsePeriodicMemoryMonitor(bool);
-
- void setMemoryKillCallback(WTF::Function<void()> function) { m_memoryKillCallback = WTFMove(function); }
- void setProcessIsEligibleForMemoryKillCallback(WTF::Function<bool()> function) { m_processIsEligibleForMemoryKillCallback = WTFMove(function); }
-
- void setLowMemoryHandler(LowMemoryHandler&& handler)
- {
- m_lowMemoryHandler = WTFMove(handler);
- }
-
- bool isUnderMemoryPressure() const
- {
- return m_underMemoryPressure
-#if PLATFORM(MAC)
- || m_memoryUsagePolicy >= MemoryUsagePolicy::Strict
-#endif
- || m_isSimulatingMemoryPressure;
- }
- void setUnderMemoryPressure(bool b) { m_underMemoryPressure = b; }
-
-#if OS(LINUX)
- void setMemoryPressureMonitorHandle(int fd);
-#endif
-
- class ReliefLogger {
- public:
- explicit ReliefLogger(const char *log)
- : m_logString(log)
- , m_initialMemory(loggingEnabled() ? platformMemoryUsage() : MemoryUsage { })
- {
- }
-
- ~ReliefLogger()
- {
- if (loggingEnabled())
- logMemoryUsageChange();
- }
-
-
- const char* logString() const { return m_logString; }
- static void setLoggingEnabled(bool enabled) { s_loggingEnabled = enabled; }
- static bool loggingEnabled()
- {
-#if RELEASE_LOG_DISABLED
- return s_loggingEnabled;
-#else
- return true;
-#endif
- }
-
- private:
- struct MemoryUsage {
- MemoryUsage() = default;
- MemoryUsage(size_t resident, size_t physical)
- : resident(resident)
- , physical(physical)
- {
- }
- size_t resident { 0 };
- size_t physical { 0 };
- };
- std::optional<MemoryUsage> platformMemoryUsage();
- void logMemoryUsageChange();
-
- const char* m_logString;
- std::optional<MemoryUsage> m_initialMemory;
-
- WEBCORE_EXPORT static bool s_loggingEnabled;
- };
-
- WEBCORE_EXPORT void releaseMemory(Critical, Synchronous = Synchronous::No);
-
- WEBCORE_EXPORT void beginSimulatedMemoryPressure();
- WEBCORE_EXPORT void endSimulatedMemoryPressure();
-
-private:
- void uninstall();
-
- void holdOff(unsigned);
-
- MemoryPressureHandler();
- ~MemoryPressureHandler() = delete;
-
- void respondToMemoryPressure(Critical, Synchronous = Synchronous::No);
- void platformReleaseMemory(Critical);
-
- NO_RETURN_DUE_TO_CRASH void didExceedMemoryLimitAndFailedToRecover();
- void measurementTimerFired();
-
-#if OS(LINUX)
- class EventFDPoller {
- WTF_MAKE_NONCOPYABLE(EventFDPoller); WTF_MAKE_FAST_ALLOCATED;
- public:
- EventFDPoller(int fd, std::function<void ()>&& notifyHandler);
- ~EventFDPoller();
-
- private:
- void readAndNotify() const;
-
- std::optional<int> m_fd;
- std::function<void ()> m_notifyHandler;
-#if USE(GLIB)
- GRefPtr<GSource> m_source;
-#else
- ThreadIdentifier m_threadID;
-#endif
- };
-#endif
-
- bool m_installed { false };
- LowMemoryHandler m_lowMemoryHandler;
-
- std::atomic<bool> m_underMemoryPressure;
- bool m_isSimulatingMemoryPressure { false };
-
- std::unique_ptr<RunLoop::Timer<MemoryPressureHandler>> m_measurementTimer;
- MemoryUsagePolicy m_memoryUsagePolicy { MemoryUsagePolicy::Unrestricted };
- WTF::Function<void()> m_memoryKillCallback;
- WTF::Function<bool()> m_processIsEligibleForMemoryKillCallback;
-
-#if OS(LINUX)
- std::optional<int> m_eventFD;
- std::optional<int> m_pressureLevelFD;
- std::unique_ptr<EventFDPoller> m_eventFDPoller;
- RunLoop::Timer<MemoryPressureHandler> m_holdOffTimer;
- void holdOffTimerFired();
- void logErrorAndCloseFDs(const char* error);
- bool tryEnsureEventFD();
-#endif
-};
-
-} // namespace WebCore
-
-#endif // MemoryPressureHandler_h
</del></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaMemoryPressureHandlerCocoamm"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,200 +0,0 @@
</span><del>-/*
- * Copyright (C) 2011-2015 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "MemoryPressureHandler.h"
-
-#import "Logging.h"
-#import <mach/mach.h>
-#import <mach/task_info.h>
-#import <malloc/malloc.h>
-#import <notify.h>
-#import <wtf/CurrentTime.h>
-
-#if PLATFORM(IOS)
-#import "GraphicsServicesSPI.h"
-#import "SystemMemory.h"
-#import "WebCoreThreadInternal.h"
-#endif
-
-#define ENABLE_FMW_FOOTPRINT_COMPARISON 0
-
-extern "C" void cache_simulate_memory_warning_event(uint64_t);
-
-namespace WebCore {
-
-void MemoryPressureHandler::platformReleaseMemory(Critical critical)
-{
- if (critical == Critical::Yes && (!isUnderMemoryPressure() || m_isSimulatingMemoryPressure)) {
- // libcache listens to OS memory notifications, but for process suspension
- // or memory pressure simulation, we need to prod it manually:
- cache_simulate_memory_warning_event(DISPATCH_MEMORYPRESSURE_CRITICAL);
- }
-}
-
-static dispatch_source_t _cache_event_source = 0;
-static dispatch_source_t _timer_event_source = 0;
-static int _notifyToken;
-
-// Disable memory event reception for a minimum of s_minimumHoldOffTime
-// seconds after receiving an event. Don't let events fire any sooner than
-// s_holdOffMultiplier times the last cleanup processing time. Effectively
-// this is 1 / s_holdOffMultiplier percent of the time.
-// These value seems reasonable and testing verifies that it throttles frequent
-// low memory events, greatly reducing CPU usage.
-static const unsigned s_minimumHoldOffTime = 5;
-#if !PLATFORM(IOS)
-static const unsigned s_holdOffMultiplier = 20;
-#endif
-
-void MemoryPressureHandler::install()
-{
- if (m_installed || _timer_event_source)
- return;
-
- dispatch_async(dispatch_get_main_queue(), ^{
-#if PLATFORM(IOS)
- _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_NORMAL | DISPATCH_MEMORYPRESSURE_WARN | DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue());
-#elif PLATFORM(MAC)
- _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue());
-#endif
-
- dispatch_set_context(_cache_event_source, this);
- dispatch_source_set_event_handler(_cache_event_source, ^{
- bool critical = true;
-#if PLATFORM(IOS)
- unsigned long status = dispatch_source_get_data(_cache_event_source);
- critical = status == DISPATCH_MEMORYPRESSURE_CRITICAL;
- auto& memoryPressureHandler = MemoryPressureHandler::singleton();
- bool wasCritical = memoryPressureHandler.isUnderMemoryPressure();
- memoryPressureHandler.setUnderMemoryPressure(critical);
- if (status == DISPATCH_MEMORYPRESSURE_NORMAL) {
- if (ReliefLogger::loggingEnabled())
- NSLog(@"System is no longer under (%s) memory pressure.", wasCritical ? "critical" : "non-critical");
- return;
- }
-
- if (ReliefLogger::loggingEnabled())
- NSLog(@"Got memory pressure notification (%s)", critical ? "critical" : "non-critical");
-#endif
- MemoryPressureHandler::singleton().respondToMemoryPressure(critical ? Critical::Yes : Critical::No);
- });
- dispatch_resume(_cache_event_source);
- });
-
- // Allow simulation of memory pressure with "notifyutil -p org.WebKit.lowMemory"
- notify_register_dispatch("org.WebKit.lowMemory", &_notifyToken, dispatch_get_main_queue(), ^(int) {
-#if ENABLE(FMW_FOOTPRINT_COMPARISON)
- auto footprintBefore = pagesPerVMTag();
-#endif
- beginSimulatedMemoryPressure();
-
- WTF::releaseFastMallocFreeMemory();
- malloc_zone_pressure_relief(nullptr, 0);
-
-#if ENABLE(FMW_FOOTPRINT_COMPARISON)
- auto footprintAfter = pagesPerVMTag();
- logFootprintComparison(footprintBefore, footprintAfter);
-#endif
-
- dispatch_async(dispatch_get_main_queue(), ^{
- endSimulatedMemoryPressure();
- });
- });
-
- m_installed = true;
-}
-
-void MemoryPressureHandler::uninstall()
-{
- if (!m_installed)
- return;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- if (_cache_event_source) {
- dispatch_source_cancel(_cache_event_source);
- dispatch_release(_cache_event_source);
- _cache_event_source = 0;
- }
-
- if (_timer_event_source) {
- dispatch_source_cancel(_timer_event_source);
- dispatch_release(_timer_event_source);
- _timer_event_source = 0;
- }
- });
-
- m_installed = false;
-
- notify_cancel(_notifyToken);
-}
-
-void MemoryPressureHandler::holdOff(unsigned seconds)
-{
- dispatch_async(dispatch_get_main_queue(), ^{
- _timer_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
- if (_timer_event_source) {
- dispatch_set_context(_timer_event_source, this);
- dispatch_source_set_timer(_timer_event_source, dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 1 * s_minimumHoldOffTime);
- dispatch_source_set_event_handler(_timer_event_source, ^{
- if (_timer_event_source) {
- dispatch_source_cancel(_timer_event_source);
- dispatch_release(_timer_event_source);
- _timer_event_source = 0;
- }
- MemoryPressureHandler::singleton().install();
- });
- dispatch_resume(_timer_event_source);
- }
- });
-}
-
-void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
-{
-#if !PLATFORM(IOS)
- uninstall();
- double startTime = monotonicallyIncreasingTime();
-#endif
-
- releaseMemory(critical, synchronous);
-
-#if !PLATFORM(IOS)
- unsigned holdOffTime = (monotonicallyIncreasingTime() - startTime) * s_holdOffMultiplier;
- holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
-#endif
-}
-
-std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage()
-{
- task_vm_info_data_t vmInfo;
- mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
- kern_return_t err = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
- if (err != KERN_SUCCESS)
- return std::nullopt;
-
- return MemoryUsage {static_cast<size_t>(vmInfo.internal), static_cast<size_t>(vmInfo.phys_footprint)};
-}
-
-} // namespace WebCore
</del></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontCache.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -33,9 +33,9 @@
</span><span class="cx"> #include "FontCascade.h"
</span><span class="cx"> #include "FontPlatformData.h"
</span><span class="cx"> #include "FontSelector.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "WebKitFontFamilyNames.h"
</span><span class="cx"> #include <wtf/HashMap.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><span class="cx"> #include <wtf/StdLibExtras.h>
</span><span class="cx"> #include <wtf/text/AtomicStringHash.h>
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsWidthCacheh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/WidthCache.h (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/WidthCache.h        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/graphics/WidthCache.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -26,12 +26,12 @@
</span><span class="cx"> #ifndef WidthCache_h
</span><span class="cx"> #define WidthCache_h
</span><span class="cx">
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "TextRun.h"
</span><span class="cx"> #include <wtf/Forward.h>
</span><span class="cx"> #include <wtf/HashFunctions.h>
</span><span class="cx"> #include <wtf/HashSet.h>
</span><span class="cx"> #include <wtf/Hasher.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscaTileControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/ca/TileController.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/ca/TileController.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/graphics/ca/TileController.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -43,8 +43,8 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "TileControllerMemoryHandlerIOS.h"
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinMediaPlayerPrivateMediaFoundationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.h (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.h        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -29,7 +29,6 @@
</span><span class="cx">
</span><span class="cx"> #include "COMPtr.h"
</span><span class="cx"> #include "MediaPlayerPrivate.h"
</span><del>-#include "Win32Handle.h"
</del><span class="cx">
</span><span class="cx"> #include <D3D9.h>
</span><span class="cx"> #include <Dxva2api.h>
</span><span class="lines">@@ -44,6 +43,7 @@
</span><span class="cx"> #include <wtf/Lock.h>
</span><span class="cx"> #include <wtf/ThreadingPrimitives.h>
</span><span class="cx"> #include <wtf/WeakPtr.h>
</span><ins>+#include <wtf/Win32Handle.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosLegacyTileCachemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/LegacyTileCache.mm (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/LegacyTileCache.mm        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/ios/LegacyTileCache.mm        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -35,7 +35,6 @@
</span><span class="cx"> #include "LegacyTileLayer.h"
</span><span class="cx"> #include "LegacyTileLayerPool.h"
</span><span class="cx"> #include "Logging.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "QuartzCoreSPI.h"
</span><span class="cx"> #include "SystemMemory.h"
</span><span class="cx"> #include "WAKWindow.h"
</span><span class="lines">@@ -43,6 +42,7 @@
</span><span class="cx"> #include "WebCoreSystemInterface.h"
</span><span class="cx"> #include "WebCoreThreadRun.h"
</span><span class="cx"> #include <wtf/CurrentTime.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/RAMSize.h>
</span><span class="cx">
</span><span class="cx"> @interface WAKView (WebViewExtras)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosLegacyTileGridmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/LegacyTileGrid.mm (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/LegacyTileGrid.mm        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/ios/LegacyTileGrid.mm        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -32,12 +32,12 @@
</span><span class="cx"> #include "LegacyTileGridTile.h"
</span><span class="cx"> #include "LegacyTileLayer.h"
</span><span class="cx"> #include "LegacyTileLayerPool.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "QuartzCoreSPI.h"
</span><span class="cx"> #include "SystemMemory.h"
</span><span class="cx"> #include "WAKWindow.h"
</span><span class="cx"> #include <algorithm>
</span><span class="cx"> #include <functional>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosLegacyTileLayerPoolmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/LegacyTileLayerPool.mm (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/LegacyTileLayerPool.mm        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/ios/LegacyTileLayerPool.mm        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -31,8 +31,8 @@
</span><span class="cx"> #include "LegacyTileLayer.h"
</span><span class="cx"> #include "LegacyTileGrid.h"
</span><span class="cx"> #include "Logging.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include <wtf/CurrentTime.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosTileControllerMemoryHandlerIOScpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/TileControllerMemoryHandlerIOS.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/TileControllerMemoryHandlerIOS.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/ios/TileControllerMemoryHandlerIOS.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -26,8 +26,8 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "TileControllerMemoryHandlerIOS.h"
</span><span class="cx">
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "TileController.h"
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformwinMemoryPressureHandlerWincpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/platform/win/MemoryPressureHandlerWin.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/win/MemoryPressureHandlerWin.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/win/MemoryPressureHandlerWin.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,132 +0,0 @@
</span><del>-/*
- * Copyright (C) 2015 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "MemoryPressureHandler.h"
-
-#include <WebCore/Timer.h>
-#include <WebCore/Win32Handle.h>
-#include <psapi.h>
-#include <wtf/NeverDestroyed.h>
-
-namespace WebCore {
-
-// We create a timer for checking the memory usage at regular intervals.
-
-class CheckMemoryTimer : public TimerBase {
-public:
- CheckMemoryTimer(MemoryPressureHandler&);
-
-private:
- virtual void fired();
-
- void handleMemoryLow();
-
- MemoryPressureHandler& m_pressureHandler;
- Win32Handle m_lowMemoryHandle;
-};
-
-CheckMemoryTimer::CheckMemoryTimer(MemoryPressureHandler& pressureHandler)
- : m_pressureHandler(pressureHandler)
-{
- m_lowMemoryHandle = CreateMemoryResourceNotification(LowMemoryResourceNotification);
-}
-
-void CheckMemoryTimer::fired()
-{
- m_pressureHandler.setUnderMemoryPressure(false);
-
- BOOL memoryLow;
-
- if (QueryMemoryResourceNotification(m_lowMemoryHandle.get(), &memoryLow) && memoryLow) {
- handleMemoryLow();
- return;
- }
-
-#if CPU(X86)
- PROCESS_MEMORY_COUNTERS_EX counters;
-
- if (!GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&counters), sizeof(counters)))
- return;
-
- // On Windows, 32-bit processes have 2GB of memory available, where some is used by the system.
- // Debugging has shown that allocations might fail and cause crashes when memory usage is > ~1GB.
- // We should start releasing memory before we reach 1GB.
- const int maxMemoryUsageBytes = 0.9 * 1024 * 1024 * 1024;
-
- if (counters.PrivateUsage > maxMemoryUsageBytes)
- handleMemoryLow();
-#endif
-}
-
-void CheckMemoryTimer::handleMemoryLow()
-{
- m_pressureHandler.setUnderMemoryPressure(true);
- m_pressureHandler.releaseMemory(Critical::Yes);
-}
-
-void MemoryPressureHandler::platformReleaseMemory(Critical)
-{
-}
-
-static std::unique_ptr<CheckMemoryTimer>& memCheckTimer()
-{
- static NeverDestroyed<std::unique_ptr<CheckMemoryTimer>> memCheckTimer;
- return memCheckTimer;
-}
-
-void MemoryPressureHandler::install()
-{
- m_installed = true;
- memCheckTimer() = std::make_unique<CheckMemoryTimer>(*this);
- memCheckTimer()->startRepeating(60.0);
-}
-
-void MemoryPressureHandler::uninstall()
-{
- if (!m_installed)
- return;
-
- memCheckTimer() = nullptr;
- m_installed = false;
-}
-
-void MemoryPressureHandler::holdOff(unsigned seconds)
-{
-}
-
-void MemoryPressureHandler::respondToMemoryPressure(Critical critical, Synchronous synchronous)
-{
- uninstall();
-
- releaseMemory(critical, synchronous);
-}
-
-std::optional<MemoryPressureHandler::ReliefLogger::MemoryUsage> MemoryPressureHandler::ReliefLogger::platformMemoryUsage()
-{
- return std::nullopt;
-}
-
-} // namespace WebCore
</del></span></pre></div>
<a id="trunkSourceWebCoreplatformwinWin32Handleh"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/platform/win/Win32Handle.h (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/win/Win32Handle.h        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/platform/win/Win32Handle.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,68 +0,0 @@
</span><del>-/*
- * Copyright (C) 2011 Patrick Gansterer <paroga@paroga.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef Win32Handle_h
-#define Win32Handle_h
-
-#include <memory>
-#include <windows.h>
-#include <wtf/Noncopyable.h>
-
-namespace WebCore {
-
-class Win32Handle {
- WTF_MAKE_NONCOPYABLE(Win32Handle);
-public:
- Win32Handle() : m_handle(INVALID_HANDLE_VALUE) { }
- explicit Win32Handle(HANDLE handle) : m_handle(handle) { }
-
- ~Win32Handle() { clear(); }
-
- void clear()
- {
- if (!isValid())
- return;
- CloseHandle(m_handle);
- m_handle = INVALID_HANDLE_VALUE;
- }
-
- bool isValid() const { return m_handle != INVALID_HANDLE_VALUE; }
-
- HANDLE get() const { return m_handle; }
- HANDLE release() { HANDLE ret = m_handle; m_handle = INVALID_HANDLE_VALUE; return ret; }
-
- Win32Handle& operator=(HANDLE handle)
- {
- clear();
- m_handle = handle;
- return *this;
- }
-
-private:
- HANDLE m_handle;
-};
-
-} // namespace WebCore
-
-#endif // Win32Handle_h
</del></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebCore/testing/Internals.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -92,7 +92,6 @@
</span><span class="cx"> #include "MediaProducer.h"
</span><span class="cx"> #include "MemoryCache.h"
</span><span class="cx"> #include "MemoryInfo.h"
</span><del>-#include "MemoryPressureHandler.h"
</del><span class="cx"> #include "MockLibWebRTCPeerConnection.h"
</span><span class="cx"> #include "MockPageOverlay.h"
</span><span class="cx"> #include "MockPageOverlayClient.h"
</span><span class="lines">@@ -146,6 +145,7 @@
</span><span class="cx"> #include <inspector/InspectorValues.h>
</span><span class="cx"> #include <runtime/JSCInlines.h>
</span><span class="cx"> #include <runtime/JSCJSValue.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/text/CString.h>
</span><span class="cx"> #include <wtf/text/StringBuffer.h>
</span><span class="cx"> #include <wtf/text/StringBuilder.h>
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebKit2/ChangeLog        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2017-03-01 Andreas Kling <akling@apple.com>
+
+ Move MemoryPressureHandler to WTF
+ <https://webkit.org/b/168908>
+
+ Reviewed by Sam Weinig.
+
+ * NetworkProcess/NetworkProcess.h:
+ * NetworkProcess/mac/NetworkProcessMac.mm:
+ * PluginProcess/PluginProcess.cpp:
+ * Shared/linux/WebMemorySamplerLinux.cpp:
+ * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp:
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+
</ins><span class="cx"> 2017-03-01 Joseph Pecoraro <pecoraro@apple.com>
</span><span class="cx">
</span><span class="cx"> [WebRTC] Install libwebrtc.dylib inside of WebCore.framework
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkProcessh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -30,11 +30,11 @@
</span><span class="cx"> #include "DownloadManager.h"
</span><span class="cx"> #include "MessageReceiverMap.h"
</span><span class="cx"> #include <WebCore/DiagnosticLoggingClient.h>
</span><del>-#include <WebCore/MemoryPressureHandler.h>
</del><span class="cx"> #include <WebCore/SessionID.h>
</span><span class="cx"> #include <memory>
</span><span class="cx"> #include <wtf/Forward.h>
</span><span class="cx"> #include <wtf/Function.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><span class="cx"> #include <wtf/RetainPtr.h>
</span><span class="cx">
</span><span class="lines">@@ -127,7 +127,7 @@
</span><span class="cx"> void terminate() override;
</span><span class="cx"> void platformTerminate();
</span><span class="cx">
</span><del>- void lowMemoryHandler(WebCore::Critical);
</del><ins>+ void lowMemoryHandler(Critical);
</ins><span class="cx">
</span><span class="cx"> // ChildProcess
</span><span class="cx"> void initializeProcess(const ChildProcessInitializationParameters&) override;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessmacNetworkProcessMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/mac/NetworkProcessMac.mm (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/mac/NetworkProcessMac.mm        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebKit2/NetworkProcess/mac/NetworkProcessMac.mm        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -40,10 +40,10 @@
</span><span class="cx"> #import <WebCore/CertificateInfo.h>
</span><span class="cx"> #import <WebCore/FileSystem.h>
</span><span class="cx"> #import <WebCore/LocalizedStrings.h>
</span><del>-#import <WebCore/MemoryPressureHandler.h>
</del><span class="cx"> #import <WebKitSystemInterface.h>
</span><span class="cx"> #import <notify.h>
</span><span class="cx"> #import <sysexits.h>
</span><ins>+#import <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #import <wtf/text/WTFString.h>
</span><span class="cx">
</span><span class="cx"> using namespace WebCore;
</span></span></pre></div>
<a id="trunkSourceWebKit2PluginProcessPluginProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -36,8 +36,8 @@
</span><span class="cx"> #include "PluginProcessCreationParameters.h"
</span><span class="cx"> #include "PluginProcessProxyMessages.h"
</span><span class="cx"> #include "WebProcessConnection.h"
</span><del>-#include <WebCore/MemoryPressureHandler.h>
</del><span class="cx"> #include <WebCore/NotImplemented.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/RunLoop.h>
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedlinuxWebMemorySamplerLinuxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/linux/WebMemorySamplerLinux.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/linux/WebMemorySamplerLinux.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebKit2/Shared/linux/WebMemorySamplerLinux.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -30,7 +30,6 @@
</span><span class="cx">
</span><span class="cx"> #include <JavaScriptCore/MemoryStatistics.h>
</span><span class="cx"> #include <WebCore/CommonVM.h>
</span><del>-#include <WebCore/CurrentProcessMemoryStatus.h>
</del><span class="cx"> #include <WebCore/JSDOMWindow.h>
</span><span class="cx"> #include <WebCore/NotImplemented.h>
</span><span class="cx"> #include <runtime/JSCInlines.h>
</span><span class="lines">@@ -38,6 +37,7 @@
</span><span class="cx"> #include <string.h>
</span><span class="cx"> #include <sys/sysinfo.h>
</span><span class="cx"> #include <wtf/CurrentTime.h>
</span><ins>+#include <wtf/linux/CurrentProcessMemoryStatus.h>
</ins><span class="cx"> #include <wtf/text/WTFString.h>
</span><span class="cx">
</span><span class="cx"> using namespace WebCore;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageCoordinatedGraphicsCompositingCoordinatorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -35,8 +35,8 @@
</span><span class="cx"> #include <WebCore/GraphicsContext.h>
</span><span class="cx"> #include <WebCore/InspectorController.h>
</span><span class="cx"> #include <WebCore/MainFrame.h>
</span><del>-#include <WebCore/MemoryPressureHandler.h>
</del><span class="cx"> #include <WebCore/Page.h>
</span><ins>+#include <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #include <wtf/SetForScope.h>
</span><span class="cx">
</span><span class="cx"> using namespace WebCore;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (213213 => 213214)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2017-03-01 09:23:28 UTC (rev 213213)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2017-03-01 09:38:44 UTC (rev 213214)
</span><span class="lines">@@ -85,7 +85,6 @@
</span><span class="cx"> #import <WebCore/KeyboardEvent.h>
</span><span class="cx"> #import <WebCore/MainFrame.h>
</span><span class="cx"> #import <WebCore/MediaSessionManagerIOS.h>
</span><del>-#import <WebCore/MemoryPressureHandler.h>
</del><span class="cx"> #import <WebCore/Node.h>
</span><span class="cx"> #import <WebCore/NotImplemented.h>
</span><span class="cx"> #import <WebCore/Page.h>
</span><span class="lines">@@ -107,6 +106,7 @@
</span><span class="cx"> #import <WebCore/WebEvent.h>
</span><span class="cx"> #import <WebCore/htmlediting.h>
</span><span class="cx"> #import <wtf/MathExtras.h>
</span><ins>+#import <wtf/MemoryPressureHandler.h>
</ins><span class="cx"> #import <wtf/SetForScope.h>
</span><span class="cx">
</span><span class="cx"> using namespace WebCore;
</span></span></pre>
</div>
</div>
</body>
</html>