Access MemoryPressureHandler global instance via a singleton() static member function
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 17:30:34 +0000 (17:30 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 17:30:34 +0000 (17:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141691

Reviewed by Andreas Kling.

Access MemoryPressureHandler global instance via a singleton() static
Source/WebCore:

member function as per coding style. Also make all other member
functions non-static as callers can just use singleton() to get the
instance and access methods. This avoid having to call
MemoryPressureHandler::singleton() from member functions.

* bindings/js/ScriptController.cpp:
(WebCore::collectGarbageAfterWindowShellDestruction):
* history/PageCache.cpp:
(WebCore::PageCache::canCache):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::commitProvisionalLoad):
* page/FrameView.cpp:
(WebCore::FrameView::willPaintContents):
(WebCore::FrameView::didPaintContents):
(WebCore::FrameView::computeCoverageRect):
* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::singleton):
(WebCore::MemoryPressureHandler::MemoryPressureHandler):
(WebCore::MemoryPressureHandler::releaseCriticalMemory):
(WebCore::memoryPressureHandler): Deleted.
* platform/MemoryPressureHandler.h:
(WebCore::MemoryPressureHandler::setLowMemoryHandler):
* platform/cocoa/MemoryPressureHandlerCocoa.mm:
(WebCore::MemoryPressureHandler::platformReleaseMemory):
(WebCore::MemoryPressureHandler::install):
(WebCore::MemoryPressureHandler::holdOff):
(WebCore::respondToMemoryPressureCallback):
* platform/graphics/FontCache.cpp:
(WebCore::FontCache::purgeInactiveFontDataIfNeeded):
* platform/ios/LegacyTileCache.mm:
(WebCore::LegacyTileCache::createTilesInActiveGrid):
* platform/ios/LegacyTileGrid.mm:
(WebCore::LegacyTileGrid::shouldUseMinimalTileCoverage):
* platform/ios/LegacyTileLayerPool.mm:
(WebCore::LegacyTileLayerPool::addLayer):
* platform/ios/TileControllerMemoryHandlerIOS.cpp:
(WebCore::TileControllerMemoryHandler::tileControllerGainedUnparentedTiles):
* platform/linux/MemoryPressureHandlerLinux.cpp:
(WebCore::MemoryPressureHandler::waitForMemoryPressureEvent):

Source/WebKit/mac:

member function.

* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
(+[WebView registerForMemoryNotifications]):
(+[WebView _isUnderMemoryPressure]):
(+[WebView _clearMemoryPressure]):
(+[WebView _shouldWaitForMemoryClearMessage]):
(WebInstallMemoryPressureHandler):

Source/WebKit2:

member function.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
(WebKit::NetworkProcess::lowMemoryHandler): Deleted.
* NetworkProcess/NetworkProcess.h:
* PluginProcess/PluginProcess.cpp:
(WebKit::PluginProcess::initializeProcess):
(WebKit::PluginProcess::lowMemoryHandler): Deleted.
* PluginProcess/PluginProcess.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::updateVisibleContentRects):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):
(WebKit::WebProcess::processWillSuspend):

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

23 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/ScriptController.cpp
Source/WebCore/history/PageCache.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/platform/MemoryPressureHandler.cpp
Source/WebCore/platform/MemoryPressureHandler.h
Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm
Source/WebCore/platform/graphics/FontCache.cpp
Source/WebCore/platform/ios/LegacyTileCache.mm
Source/WebCore/platform/ios/LegacyTileGrid.mm
Source/WebCore/platform/ios/LegacyTileLayerPool.mm
Source/WebCore/platform/ios/TileControllerMemoryHandlerIOS.cpp
Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkProcess.cpp
Source/WebKit2/NetworkProcess/NetworkProcess.h
Source/WebKit2/PluginProcess/PluginProcess.cpp
Source/WebKit2/PluginProcess/PluginProcess.h
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
Source/WebKit2/WebProcess/WebProcess.cpp

index d92ccde..aebf3cc 100644 (file)
@@ -1,3 +1,51 @@
+2015-02-17  Chris Dumez  <cdumez@apple.com>
+
+        Access MemoryPressureHandler global instance via a singleton() static member function
+        https://bugs.webkit.org/show_bug.cgi?id=141691
+
+        Reviewed by Andreas Kling.
+
+        Access MemoryPressureHandler global instance via a singleton() static
+        member function as per coding style. Also make all other member
+        functions non-static as callers can just use singleton() to get the
+        instance and access methods. This avoid having to call
+        MemoryPressureHandler::singleton() from member functions.
+
+        * bindings/js/ScriptController.cpp:
+        (WebCore::collectGarbageAfterWindowShellDestruction):
+        * history/PageCache.cpp:
+        (WebCore::PageCache::canCache):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::commitProvisionalLoad):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::willPaintContents):
+        (WebCore::FrameView::didPaintContents):
+        (WebCore::FrameView::computeCoverageRect):
+        * platform/MemoryPressureHandler.cpp:
+        (WebCore::MemoryPressureHandler::singleton):
+        (WebCore::MemoryPressureHandler::MemoryPressureHandler):
+        (WebCore::MemoryPressureHandler::releaseCriticalMemory):
+        (WebCore::memoryPressureHandler): Deleted.
+        * platform/MemoryPressureHandler.h:
+        (WebCore::MemoryPressureHandler::setLowMemoryHandler):
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        (WebCore::MemoryPressureHandler::platformReleaseMemory):
+        (WebCore::MemoryPressureHandler::install):
+        (WebCore::MemoryPressureHandler::holdOff):
+        (WebCore::respondToMemoryPressureCallback):
+        * platform/graphics/FontCache.cpp:
+        (WebCore::FontCache::purgeInactiveFontDataIfNeeded):
+        * platform/ios/LegacyTileCache.mm:
+        (WebCore::LegacyTileCache::createTilesInActiveGrid):
+        * platform/ios/LegacyTileGrid.mm:
+        (WebCore::LegacyTileGrid::shouldUseMinimalTileCoverage):
+        * platform/ios/LegacyTileLayerPool.mm:
+        (WebCore::LegacyTileLayerPool::addLayer):
+        * platform/ios/TileControllerMemoryHandlerIOS.cpp:
+        (WebCore::TileControllerMemoryHandler::tileControllerGainedUnparentedTiles):
+        * platform/linux/MemoryPressureHandlerLinux.cpp:
+        (WebCore::MemoryPressureHandler::waitForMemoryPressureEvent):
+
 2015-02-17  Alex Christensen  <achristensen@webkit.org>
 
         Remove WebCore.exp.in and clean up.
 2015-02-17  Alex Christensen  <achristensen@webkit.org>
 
         Remove WebCore.exp.in and clean up.
index 59b2924..97b80fb 100644 (file)
@@ -65,7 +65,7 @@ static void collectGarbageAfterWindowShellDestruction()
 {
     // Make sure to GC Extra Soon(tm) during memory pressure conditions
     // to soften high peaks of memory usage during navigation.
 {
     // Make sure to GC Extra Soon(tm) during memory pressure conditions
     // to soften high peaks of memory usage during navigation.
-    if (memoryPressureHandler().isUnderMemoryPressure()) {
+    if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
         // NOTE: We do the collection on next runloop to ensure that there's no pointer
         //       to the window object on the stack.
         gcController().garbageCollectOnNextRunLoop();
         // NOTE: We do the collection on next runloop to ensure that there's no pointer
         //       to the window object on the stack.
         gcController().garbageCollectOnNextRunLoop();
index 11c1615..0bc9d8e 100644 (file)
@@ -337,7 +337,7 @@ bool PageCache::canCache(Page* page) const
     
     logCanCachePageDecision(*page);
 
     
     logCanCachePageDecision(*page);
 
-    if (memoryPressureHandler().isUnderMemoryPressure())
+    if (MemoryPressureHandler::singleton().isUnderMemoryPressure())
         return false;
 
     // Cache the page, if possible.
         return false;
 
     // Cache the page, if possible.
index 05c8206..1fb3715 100644 (file)
@@ -1748,7 +1748,7 @@ void FrameLoader::commitProvisionalLoad()
     // page cache. We could still preemptively prune the page cache while navigating to a cached page if capacity > 1.
     // See <rdar://problem/11779846> for more details.
     if (!cachedPage) {
     // page cache. We could still preemptively prune the page cache while navigating to a cached page if capacity > 1.
     // See <rdar://problem/11779846> for more details.
     if (!cachedPage) {
-        if (memoryPressureHandler().isUnderMemoryPressure()) {
+        if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
             LOG(MemoryPressure, "Pruning page cache because under memory pressure at: %s", __PRETTY_FUNCTION__);
             LOG(PageCache, "Pruning page cache to 0 due to memory pressure");
             // Don't cache any page if we are under memory pressure.
             LOG(MemoryPressure, "Pruning page cache because under memory pressure at: %s", __PRETTY_FUNCTION__);
             LOG(PageCache, "Pruning page cache to 0 due to memory pressure");
             // Don't cache any page if we are under memory pressure.
index 7643fb1..9785a40 100644 (file)
@@ -3784,7 +3784,7 @@ void FrameView::willPaintContents(GraphicsContext* context, const IntRect& dirty
 
     paintingState.isTopLevelPainter = !sCurrentPaintTimeStamp;
 
 
     paintingState.isTopLevelPainter = !sCurrentPaintTimeStamp;
 
-    if (paintingState.isTopLevelPainter && memoryPressureHandler().isUnderMemoryPressure()) {
+    if (paintingState.isTopLevelPainter && MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
         LOG(MemoryPressure, "Under memory pressure: %s", WTF_PRETTY_FUNCTION);
 
         // To avoid unnecessary image decoding, we don't prune recently-decoded live resources here since
         LOG(MemoryPressure, "Under memory pressure: %s", WTF_PRETTY_FUNCTION);
 
         // To avoid unnecessary image decoding, we don't prune recently-decoded live resources here since
@@ -3828,7 +3828,7 @@ void FrameView::didPaintContents(GraphicsContext* context, const IntRect& dirtyR
 
     // Painting can lead to decoding of large amounts of bitmaps
     // If we are low on memory, wipe them out after the paint.
 
     // Painting can lead to decoding of large amounts of bitmaps
     // If we are low on memory, wipe them out after the paint.
-    if (paintingState.isTopLevelPainter && memoryPressureHandler().isUnderMemoryPressure())
+    if (paintingState.isTopLevelPainter && MemoryPressureHandler::singleton().isUnderMemoryPressure())
         MemoryCache::singleton().pruneLiveResources(true);
 
     // Regions may have changed as a result of the visibility/z-index of element changing.
         MemoryCache::singleton().pruneLiveResources(true);
 
     // Regions may have changed as a result of the visibility/z-index of element changing.
@@ -4505,7 +4505,7 @@ void FrameView::setScrollVelocity(double horizontalVelocity, double verticalVelo
 FloatRect FrameView::computeCoverageRect(double horizontalMargin, double verticalMargin) const
 {
     FloatRect exposedContentRect = this->exposedContentRect();
 FloatRect FrameView::computeCoverageRect(double horizontalMargin, double verticalMargin) const
 {
     FloatRect exposedContentRect = this->exposedContentRect();
-    if (!m_speculativeTilingEnabled || memoryPressureHandler().isUnderMemoryPressure())
+    if (!m_speculativeTilingEnabled || MemoryPressureHandler::singleton().isUnderMemoryPressure())
         return exposedContentRect;
 
     double currentTime = monotonicallyIncreasingTime();
         return exposedContentRect;
 
     double currentTime = monotonicallyIncreasingTime();
index 034141d..d73ae97 100644 (file)
@@ -46,16 +46,16 @@ namespace WebCore {
 
 WEBCORE_EXPORT bool MemoryPressureHandler::ReliefLogger::s_loggingEnabled = false;
 
 
 WEBCORE_EXPORT bool MemoryPressureHandler::ReliefLogger::s_loggingEnabled = false;
 
-MemoryPressureHandler& memoryPressureHandler()
+MemoryPressureHandler& MemoryPressureHandler::singleton()
 {
 {
-    DEPRECATED_DEFINE_STATIC_LOCAL(MemoryPressureHandler, staticMemoryPressureHandler, ());
-    return staticMemoryPressureHandler;
+    static NeverDestroyed<MemoryPressureHandler> memoryPressureHandler;
+    return memoryPressureHandler;
 }
 
 MemoryPressureHandler::MemoryPressureHandler() 
     : m_installed(false)
     , m_lastRespondTime(0)
 }
 
 MemoryPressureHandler::MemoryPressureHandler() 
     : m_installed(false)
     , m_lastRespondTime(0)
-    , m_lowMemoryHandler(releaseMemory)
+    , m_lowMemoryHandler([this] (bool critical) { releaseMemory(critical); })
     , m_underMemoryPressure(false)
 #if PLATFORM(IOS)
     // FIXME: Can we share more of this with OpenSource?
     , m_underMemoryPressure(false)
 #if PLATFORM(IOS)
     // FIXME: Can we share more of this with OpenSource?
@@ -101,7 +101,7 @@ void MemoryPressureHandler::releaseCriticalMemory()
     {
         ReliefLogger log("Empty the PageCache");
         // Right now, the only reason we call release critical memory while not under memory pressure is if the process is about to be suspended.
     {
         ReliefLogger log("Empty the PageCache");
         // Right now, the only reason we call release critical memory while not under memory pressure is if the process is about to be suspended.
-        PruningReason pruningReason = memoryPressureHandler().isUnderMemoryPressure() ? PruningReason::MemoryPressure : PruningReason::ProcessSuspended;
+        PruningReason pruningReason = isUnderMemoryPressure() ? PruningReason::MemoryPressure : PruningReason::ProcessSuspended;
         PageCache::singleton().pruneToSizeNow(0, pruningReason);
     }
 
         PageCache::singleton().pruneToSizeNow(0, pruningReason);
     }
 
index 2caca4e..0f73030 100644 (file)
 #define MemoryPressureHandler_h
 
 #include <atomic>
 #define MemoryPressureHandler_h
 
 #include <atomic>
-#include <time.h>
+#include <ctime>
+#include <functional>
 #include <wtf/FastMalloc.h>
 #include <wtf/FastMalloc.h>
+#include <wtf/Forward.h>
 
 #if PLATFORM(IOS)
 #include <wtf/ThreadingPrimitives.h>
 
 #if PLATFORM(IOS)
 #include <wtf/ThreadingPrimitives.h>
@@ -47,12 +49,13 @@ enum MemoryPressureReason {
 };
 #endif
 
 };
 #endif
 
-typedef void (*LowMemoryHandler)(bool critical);
+typedef std::function<void(bool critical)> LowMemoryHandler;
 
 class MemoryPressureHandler {
     WTF_MAKE_FAST_ALLOCATED;
 
 class MemoryPressureHandler {
     WTF_MAKE_FAST_ALLOCATED;
+    friend class WTF::NeverDestroyed<MemoryPressureHandler>;
 public:
 public:
-    friend MemoryPressureHandler& memoryPressureHandler();
+    WEBCORE_EXPORT static MemoryPressureHandler& singleton();
 
     WEBCORE_EXPORT void install();
 
 
     WEBCORE_EXPORT void install();
 
@@ -104,21 +107,21 @@ public:
         static bool s_loggingEnabled;
     };
 
         static bool s_loggingEnabled;
     };
 
-    WEBCORE_EXPORT static void releaseMemory(bool critical);
+    WEBCORE_EXPORT void releaseMemory(bool critical);
 
 private:
 
 private:
-    static void releaseNoncriticalMemory();
-    static void releaseCriticalMemory();
+    void releaseNoncriticalMemory();
+    void releaseCriticalMemory();
 
     void uninstall();
 
     void holdOff(unsigned);
 
     MemoryPressureHandler();
 
     void uninstall();
 
     void holdOff(unsigned);
 
     MemoryPressureHandler();
-    ~MemoryPressureHandler();
+    ~MemoryPressureHandler() = delete;
 
     void respondToMemoryPressure(bool critical);
 
     void respondToMemoryPressure(bool critical);
-    static void platformReleaseMemory(bool critical);
+    void platformReleaseMemory(bool critical);
 
     bool m_installed;
     time_t m_lastRespondTime;
 
     bool m_installed;
     time_t m_lastRespondTime;
@@ -142,9 +145,6 @@ private:
 #endif
 };
 
 #endif
 };
 
-// Function to obtain the global memory pressure object.
-WEBCORE_EXPORT MemoryPressureHandler& memoryPressureHandler();
-
 } // namespace WebCore
 
 #endif // MemoryPressureHandler_h
 } // namespace WebCore
 
 #endif // MemoryPressureHandler_h
index 49b5029..40239c2 100644 (file)
@@ -61,7 +61,7 @@ void MemoryPressureHandler::platformReleaseMemory(bool)
 #endif
 
 #if PLATFORM(IOS)
 #endif
 
 #if PLATFORM(IOS)
-    if (memoryPressureHandler().isUnderMemoryPressure()) {
+    if (isUnderMemoryPressure()) {
         gcController().garbageCollectSoon();
     } else {
         // If we're not under memory pressure, that means we're here due to impending process suspension.
         gcController().garbageCollectSoon();
     } else {
         // If we're not under memory pressure, that means we're here due to impending process suspension.
@@ -107,8 +107,9 @@ void MemoryPressureHandler::install()
 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
                 unsigned long status = dispatch_source_get_data(_cache_event_source);
                 critical = status == DISPATCH_MEMORYPRESSURE_CRITICAL;
 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
                 unsigned long status = dispatch_source_get_data(_cache_event_source);
                 critical = status == DISPATCH_MEMORYPRESSURE_CRITICAL;
-                bool wasCritical = memoryPressureHandler().isUnderMemoryPressure();
-                memoryPressureHandler().setUnderMemoryPressure(critical);
+                auto& memoryPressureHandler = MemoryPressureHandler::singleton();
+                bool wasCritical = memoryPressureHandler.isUnderMemoryPressure();
+                memoryPressureHandler.setUnderMemoryPressure(critical);
                 if (status == DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL) {
                     if (ReliefLogger::loggingEnabled())
                         NSLog(@"System is no longer under (%s) memory pressure.", wasCritical ? "critical" : "non-critical");
                 if (status == DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL) {
                     if (ReliefLogger::loggingEnabled())
                         NSLog(@"System is no longer under (%s) memory pressure.", wasCritical ? "critical" : "non-critical");
@@ -118,7 +119,7 @@ void MemoryPressureHandler::install()
                 if (ReliefLogger::loggingEnabled())
                     NSLog(@"Got memory pressure notification (%s)", critical ? "critical" : "non-critical");
 #endif
                 if (ReliefLogger::loggingEnabled())
                     NSLog(@"Got memory pressure notification (%s)", critical ? "critical" : "non-critical");
 #endif
-                memoryPressureHandler().respondToMemoryPressure(critical);
+                MemoryPressureHandler::singleton().respondToMemoryPressure(critical);
             });
             dispatch_resume(_cache_event_source);
         }
             });
             dispatch_resume(_cache_event_source);
         }
@@ -126,7 +127,7 @@ void MemoryPressureHandler::install()
 
     // Allow simulation of memory pressure with "notifyutil -p org.WebKit.lowMemory"
     notify_register_dispatch("org.WebKit.lowMemory", &_notifyToken, dispatch_get_main_queue(), ^(int) {
 
     // Allow simulation of memory pressure with "notifyutil -p org.WebKit.lowMemory"
     notify_register_dispatch("org.WebKit.lowMemory", &_notifyToken, dispatch_get_main_queue(), ^(int) {
-        memoryPressureHandler().respondToMemoryPressure(true);
+        MemoryPressureHandler::singleton().respondToMemoryPressure(true);
 
         // We only do a synchronous GC when *simulating* memory pressure.
         // This gives us a more consistent picture of live objects at the end of testing.
 
         // We only do a synchronous GC when *simulating* memory pressure.
         // This gives us a more consistent picture of live objects at the end of testing.
@@ -180,7 +181,7 @@ void MemoryPressureHandler::holdOff(unsigned seconds)
                     dispatch_release(_timer_event_source);
                     _timer_event_source = 0;
                 }
                     dispatch_release(_timer_event_source);
                     _timer_event_source = 0;
                 }
-                memoryPressureHandler().install();
+                MemoryPressureHandler::singleton().install();
             });
             dispatch_resume(_timer_event_source);
         }
             });
             dispatch_resume(_timer_event_source);
         }
@@ -238,7 +239,7 @@ void MemoryPressureHandler::ReliefLogger::platformLog()
 #if PLATFORM(IOS)
 static void respondToMemoryPressureCallback(CFRunLoopObserverRef observer, CFRunLoopActivity /*activity*/, void* /*info*/)
 {
 #if PLATFORM(IOS)
 static void respondToMemoryPressureCallback(CFRunLoopObserverRef observer, CFRunLoopActivity /*activity*/, void* /*info*/)
 {
-    memoryPressureHandler().respondToMemoryPressureIfNeeded();
+    MemoryPressureHandler::singleton().respondToMemoryPressureIfNeeded();
     CFRunLoopObserverInvalidate(observer);
     CFRelease(observer);
 }
     CFRunLoopObserverInvalidate(observer);
     CFRelease(observer);
 }
index a1de300..02d3dda 100644 (file)
@@ -411,7 +411,7 @@ void FontCache::purgeTimerFired()
 
 void FontCache::purgeInactiveFontDataIfNeeded()
 {
 
 void FontCache::purgeInactiveFontDataIfNeeded()
 {
-    bool underMemoryPressure = memoryPressureHandler().isUnderMemoryPressure();
+    bool underMemoryPressure = MemoryPressureHandler::singleton().isUnderMemoryPressure();
     int inactiveFontDataLimit = underMemoryPressure ? cMaxUnderMemoryPressureInactiveFontData : cMaxInactiveFontData;
 
     if (cachedFonts().size() < inactiveFontDataLimit)
     int inactiveFontDataLimit = underMemoryPressure ? cMaxUnderMemoryPressureInactiveFontData : cMaxInactiveFontData;
 
     if (cachedFonts().size() < inactiveFontDataLimit)
index 32e9736..1ae7497 100644 (file)
@@ -425,7 +425,7 @@ void LegacyTileCache::tileCreationTimerFired()
 
 void LegacyTileCache::createTilesInActiveGrid(SynchronousTileCreationMode mode)
 {
 
 void LegacyTileCache::createTilesInActiveGrid(SynchronousTileCreationMode mode)
 {
-    if (memoryPressureHandler().isUnderMemoryPressure()) {
+    if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
         LOG(MemoryPressure, "Under memory pressure at: %s", __PRETTY_FUNCTION__);
         removeAllNonVisibleTilesInternal();
     }
         LOG(MemoryPressure, "Under memory pressure at: %s", __PRETTY_FUNCTION__);
         removeAllNonVisibleTilesInternal();
     }
index c55fb46..09156d2 100644 (file)
@@ -390,7 +390,7 @@ bool LegacyTileGrid::shouldUseMinimalTileCoverage() const
 {
     return m_tileCache->tilingMode() == LegacyTileCache::Minimal
         || !m_tileCache->isSpeculativeTileCreationEnabled()
 {
     return m_tileCache->tilingMode() == LegacyTileCache::Minimal
         || !m_tileCache->isSpeculativeTileCreationEnabled()
-        || memoryPressureHandler().isUnderMemoryPressure();
+        || MemoryPressureHandler::singleton().isUnderMemoryPressure();
 }
 
 IntRect LegacyTileGrid::adjustCoverRectForPageBounds(const IntRect& rect) const
 }
 
 IntRect LegacyTileGrid::adjustCoverRectForPageBounds(const IntRect& rect) const
index 0322b76..dad4c83 100644 (file)
@@ -79,7 +79,7 @@ void LegacyTileLayerPool::addLayer(const RetainPtr<LegacyTileLayer>& layer)
     if (!canReuseLayerWithSize(layerSize))
         return;
 
     if (!canReuseLayerWithSize(layerSize))
         return;
 
-    if (memoryPressureHandler().isUnderMemoryPressure()) {
+    if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
         LOG(MemoryPressure, "Under memory pressure: %s, totalBytes: %d", __PRETTY_FUNCTION__, m_totalBytes);
         return;
     }
         LOG(MemoryPressure, "Under memory pressure: %s, totalBytes: %d", __PRETTY_FUNCTION__, m_totalBytes);
         return;
     }
index 9a4cffc..de7b4e0 100644 (file)
@@ -54,7 +54,7 @@ void TileControllerMemoryHandler::tileControllerGainedUnparentedTiles(TileContro
     m_tileControllers.appendOrMoveToLast(controller);
 
     // If we are under memory pressure, remove all unparented tiles now.
     m_tileControllers.appendOrMoveToLast(controller);
 
     // If we are under memory pressure, remove all unparented tiles now.
-    if (memoryPressureHandler().isUnderMemoryPressure()) {
+    if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
         trimUnparentedTilesToTarget(0);
         return;
     }
         trimUnparentedTilesToTarget(0);
         return;
     }
index b1be083..2e48699 100644 (file)
@@ -77,15 +77,10 @@ static inline String nextToken(FILE* file)
     return String(buffer);
 }
 
     return String(buffer);
 }
 
-MemoryPressureHandler::~MemoryPressureHandler()
-{
-    uninstall();
-}
-
 void MemoryPressureHandler::waitForMemoryPressureEvent(void*)
 {
     ASSERT(!isMainThread());
 void MemoryPressureHandler::waitForMemoryPressureEvent(void*)
 {
     ASSERT(!isMainThread());
-    int eventFD = memoryPressureHandler().m_eventFD;
+    int eventFD = MemoryPressureHandler::singleton().m_eventFD;
     if (!eventFD) {
         LOG(MemoryPressure, "Invalidate eventfd.");
         return;
     if (!eventFD) {
         LOG(MemoryPressure, "Invalidate eventfd.");
         return;
@@ -104,9 +99,9 @@ void MemoryPressureHandler::waitForMemoryPressureEvent(void*)
     if (ReliefLogger::loggingEnabled())
         LOG(MemoryPressure, "Got memory pressure notification (%s)", critical ? "critical" : "non-critical");
 
     if (ReliefLogger::loggingEnabled())
         LOG(MemoryPressure, "Got memory pressure notification (%s)", critical ? "critical" : "non-critical");
 
-    memoryPressureHandler().setUnderMemoryPressure(critical);
+    MemoryPressureHandler::singleton().setUnderMemoryPressure(critical);
     callOnMainThread([critical] {
     callOnMainThread([critical] {
-        memoryPressureHandler().respondToMemoryPressure(critical);
+        MemoryPressureHandler::singleton().respondToMemoryPressure(critical);
     });
 }
 
     });
 }
 
index 18c7e5a..e0d0ee0 100644 (file)
@@ -1,3 +1,21 @@
+2015-02-17  Chris Dumez  <cdumez@apple.com>
+
+        Access MemoryPressureHandler global instance via a singleton() static member function
+        https://bugs.webkit.org/show_bug.cgi?id=141691
+
+        Reviewed by Andreas Kling.
+
+        Access MemoryPressureHandler global instance via a singleton() static
+        member function.
+
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:]):
+        (+[WebView registerForMemoryNotifications]):
+        (+[WebView _isUnderMemoryPressure]):
+        (+[WebView _clearMemoryPressure]):
+        (+[WebView _shouldWaitForMemoryClearMessage]):
+        (WebInstallMemoryPressureHandler):
+
 2015-02-15  Sam Weinig  <sam@webkit.org>
 
         Add experimental <attachment> element support
 2015-02-15  Sam Weinig  <sam@webkit.org>
 
         Add experimental <attachment> element support
index c2bdade..eb2c6ae 100644 (file)
@@ -1054,7 +1054,7 @@ static void WebKitInitializeGamepadProviderIfNecessary()
     _private->page->settings().setFontFallbackPrefersPictographs(true);
 #endif
 
     _private->page->settings().setFontFallbackPrefersPictographs(true);
 #endif
 
-    memoryPressureHandler().install();
+    MemoryPressureHandler::singleton().install();
 
     if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION)) {
         // Originally, we allowed all local loads.
 
     if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION)) {
         // Originally, we allowed all local loads.
@@ -1263,14 +1263,14 @@ static void WebKitInitializeGamepadProviderIfNecessary()
 {
     BOOL shouldAutoClearPressureOnMemoryRelease = !WebCore::applicationIsMobileSafari();
 
 {
     BOOL shouldAutoClearPressureOnMemoryRelease = !WebCore::applicationIsMobileSafari();
 
-    memoryPressureHandler().installMemoryReleaseBlock(^{
+    MemoryPressureHandler::singleton().installMemoryReleaseBlock(^{
         [WebView _handleMemoryWarning];
     }, shouldAutoClearPressureOnMemoryRelease);
 
     static dispatch_source_t memoryNotificationEventSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYSTATUS, 0, DISPATCH_MEMORYSTATUS_PRESSURE_WARN, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
     dispatch_source_set_event_handler(memoryNotificationEventSource, ^{
         // Set memory pressure flag and schedule releasing memory in web thread runloop exit.
         [WebView _handleMemoryWarning];
     }, shouldAutoClearPressureOnMemoryRelease);
 
     static dispatch_source_t memoryNotificationEventSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYSTATUS, 0, DISPATCH_MEMORYSTATUS_PRESSURE_WARN, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
     dispatch_source_set_event_handler(memoryNotificationEventSource, ^{
         // Set memory pressure flag and schedule releasing memory in web thread runloop exit.
-        memoryPressureHandler().setReceivedMemoryPressure(WebCore::MemoryPressureReasonVMPressure);
+        MemoryPressureHandler::singleton().setReceivedMemoryPressure(WebCore::MemoryPressureReasonVMPressure);
     });
 
     dispatch_resume(memoryNotificationEventSource);
     });
 
     dispatch_resume(memoryNotificationEventSource);
@@ -1284,9 +1284,9 @@ static void WebKitInitializeGamepadProviderIfNecessary()
         dispatch_source_set_event_handler(memoryStatusEventSource, ^{
             unsigned long currentStatus = dispatch_source_get_data(memoryStatusEventSource);
             if (currentStatus == DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL)
         dispatch_source_set_event_handler(memoryStatusEventSource, ^{
             unsigned long currentStatus = dispatch_source_get_data(memoryStatusEventSource);
             if (currentStatus == DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL)
-                memoryPressureHandler().clearMemoryPressure();
+                MemoryPressureHandler::singleton().clearMemoryPressure();
             else if (currentStatus == DISPATCH_MEMORYSTATUS_PRESSURE_WARN)
             else if (currentStatus == DISPATCH_MEMORYSTATUS_PRESSURE_WARN)
-                memoryPressureHandler().setReceivedMemoryPressure(WebCore::MemoryPressureReasonVMStatus);
+                MemoryPressureHandler::singleton().setReceivedMemoryPressure(WebCore::MemoryPressureReasonVMStatus);
         });
 
         dispatch_resume(memoryStatusEventSource);
         });
 
         dispatch_resume(memoryStatusEventSource);
@@ -1610,17 +1610,17 @@ static NSMutableSet *knownPluginMIMETypes()
 
 + (BOOL)_isUnderMemoryPressure
 {
 
 + (BOOL)_isUnderMemoryPressure
 {
-    return memoryPressureHandler().isUnderMemoryPressure();
+    return MemoryPressureHandler::singleton().isUnderMemoryPressure();
 }
 
 + (void)_clearMemoryPressure
 {
 }
 
 + (void)_clearMemoryPressure
 {
-    memoryPressureHandler().clearMemoryPressure();
+    MemoryPressureHandler::singleton().clearMemoryPressure();
 }
 
 + (BOOL)_shouldWaitForMemoryClearMessage
 {
 }
 
 + (BOOL)_shouldWaitForMemoryClearMessage
 {
-    return memoryPressureHandler().shouldWaitForMemoryClearMessage();
+    return MemoryPressureHandler::singleton().shouldWaitForMemoryClearMessage();
 }
 #endif // PLATFORM(IOS)
 
 }
 #endif // PLATFORM(IOS)
 
@@ -8813,5 +8813,5 @@ bool LayerFlushController::flushLayers()
 
 void WebInstallMemoryPressureHandler(void)
 {
 
 void WebInstallMemoryPressureHandler(void)
 {
-    memoryPressureHandler().install();
+    MemoryPressureHandler::singleton().install();
 }
 }
index 7eeba7a..604c1a9 100644 (file)
@@ -1,3 +1,27 @@
+2015-02-17  Chris Dumez  <cdumez@apple.com>
+
+        Access MemoryPressureHandler global instance via a singleton() static member function
+        https://bugs.webkit.org/show_bug.cgi?id=141691
+
+        Reviewed by Andreas Kling.
+
+        Access MemoryPressureHandler global instance via a singleton() static
+        member function.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        (WebKit::NetworkProcess::lowMemoryHandler): Deleted.
+        * NetworkProcess/NetworkProcess.h:
+        * PluginProcess/PluginProcess.cpp:
+        (WebKit::PluginProcess::initializeProcess):
+        (WebKit::PluginProcess::lowMemoryHandler): Deleted.
+        * PluginProcess/PluginProcess.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::updateVisibleContentRects):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+        (WebKit::WebProcess::processWillSuspend):
+
 2015-02-16  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] WebKitFrame objects are never released
 2015-02-16  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] WebKitFrame objects are never released
index 2c90b02..aadea0e 100644 (file)
@@ -161,8 +161,12 @@ void NetworkProcess::initializeNetworkProcess(const NetworkProcessCreationParame
 
     WTF::setCurrentThreadIsUserInitiated();
 
 
     WTF::setCurrentThreadIsUserInitiated();
 
-    memoryPressureHandler().setLowMemoryHandler(lowMemoryHandler);
-    memoryPressureHandler().install();
+    auto& memoryPressureHandler = MemoryPressureHandler::singleton();
+    memoryPressureHandler.setLowMemoryHandler([this] (bool critical) {
+        platformLowMemoryHandler(critical);
+        WTF::releaseFastMallocFreeMemory();
+    });
+    memoryPressureHandler.install();
 
     m_diskCacheIsDisabledForTesting = parameters.shouldUseTestingNetworkSession;
     setCacheModel(static_cast<uint32_t>(parameters.cacheModel));
 
     m_diskCacheIsDisabledForTesting = parameters.shouldUseTestingNetworkSession;
     setCacheModel(static_cast<uint32_t>(parameters.cacheModel));
@@ -322,12 +326,6 @@ void NetworkProcess::terminate()
     ChildProcess::terminate();
 }
 
     ChildProcess::terminate();
 }
 
-void NetworkProcess::lowMemoryHandler(bool critical)
-{
-    platformLowMemoryHandler(critical);
-    WTF::releaseFastMallocFreeMemory();
-}
-
 #if !PLATFORM(COCOA)
 void NetworkProcess::initializeProcess(const ChildProcessInitializationParameters&)
 {
 #if !PLATFORM(COCOA)
 void NetworkProcess::initializeProcess(const ChildProcessInitializationParameters&)
 {
index c9db647..fcbc98c 100644 (file)
@@ -90,8 +90,7 @@ private:
     virtual void terminate() override;
     void platformTerminate();
 
     virtual void terminate() override;
     void platformTerminate();
 
-    static void lowMemoryHandler(bool critical);
-    static void platformLowMemoryHandler(bool critical);
+    void platformLowMemoryHandler(bool critical);
 
     // ChildProcess
     virtual void initializeProcess(const ChildProcessInitializationParameters&) override;
 
     // ChildProcess
     virtual void initializeProcess(const ChildProcessInitializationParameters&) override;
index 410700e..f97b914 100644 (file)
@@ -67,21 +67,17 @@ PluginProcess::~PluginProcess()
 {
 }
 
 {
 }
 
-void PluginProcess::lowMemoryHandler(bool critical)
-{
-    UNUSED_PARAM(critical);
-    auto& pluginProcess = PluginProcess::singleton();
-    if (pluginProcess.shouldTerminate())
-        pluginProcess.terminate();
-}
-
 void PluginProcess::initializeProcess(const ChildProcessInitializationParameters& parameters)
 {
     m_pluginPath = parameters.extraInitializationData.get("plugin-path");
     platformInitializeProcess(parameters);
 
 void PluginProcess::initializeProcess(const ChildProcessInitializationParameters& parameters)
 {
     m_pluginPath = parameters.extraInitializationData.get("plugin-path");
     platformInitializeProcess(parameters);
 
-    memoryPressureHandler().setLowMemoryHandler(lowMemoryHandler);
-    memoryPressureHandler().install();
+    auto& memoryPressureHandler = MemoryPressureHandler::singleton();
+    memoryPressureHandler.setLowMemoryHandler([this] (bool) {
+        if (shouldTerminate())
+            terminate();
+    });
+    memoryPressureHandler.install();
 }
 
 void PluginProcess::removeWebProcessConnection(WebProcessConnection* webProcessConnection)
 }
 
 void PluginProcess::removeWebProcessConnection(WebProcessConnection* webProcessConnection)
index 009dd75..8844b0a 100644 (file)
@@ -134,7 +134,6 @@ private:
     String m_nsurlCacheDirectory;
 #endif
 
     String m_nsurlCacheDirectory;
 #endif
 
-    static void lowMemoryHandler(bool critical);
     CountedUserActivity m_connectionActivity;
 
     RefPtr<WebCore::AudioHardwareListener> m_audioHardwareListener;
     CountedUserActivity m_connectionActivity;
 
     RefPtr<WebCore::AudioHardwareListener> m_audioHardwareListener;
index cc5c707..88733ee 100644 (file)
@@ -2648,7 +2648,7 @@ void WebPage::updateVisibleContentRects(const VisibleContentRectUpdateInfo& visi
     double boundedScale = std::min(m_viewportConfiguration.maximumScale(), std::max(m_viewportConfiguration.minimumScale(), filteredScale));
 
     // Skip progressively redrawing tiles if pinch-zooming while the system is under memory pressure.
     double boundedScale = std::min(m_viewportConfiguration.maximumScale(), std::max(m_viewportConfiguration.minimumScale(), filteredScale));
 
     // Skip progressively redrawing tiles if pinch-zooming while the system is under memory pressure.
-    if (boundedScale != currentScale && !m_isInStableState && memoryPressureHandler().isUnderMemoryPressure())
+    if (boundedScale != currentScale && !m_isInStableState && MemoryPressureHandler::singleton().isUnderMemoryPressure())
         return;
 
     if (m_isInStableState)
         return;
 
     if (m_isInStableState)
index a8bc2c9..5730af6 100644 (file)
@@ -284,7 +284,7 @@ void WebProcess::initializeWebProcess(WebProcessCreationParameters&& parameters)
 
     WTF::setCurrentThreadIsUserInitiated();
 
 
     WTF::setCurrentThreadIsUserInitiated();
 
-    memoryPressureHandler().install();
+    MemoryPressureHandler::singleton().install();
 
     if (!parameters.injectedBundlePath.isEmpty())
         m_injectedBundle = InjectedBundle::create(parameters, transformHandlesToObjects(parameters.initializationUserData.object()).get());
 
     if (!parameters.injectedBundlePath.isEmpty())
         m_injectedBundle = InjectedBundle::create(parameters, transformHandlesToObjects(parameters.initializationUserData.object()).get());
@@ -1163,7 +1163,7 @@ void WebProcess::resetAllGeolocationPermissions()
     
 void WebProcess::processWillSuspend()
 {
     
 void WebProcess::processWillSuspend()
 {
-    memoryPressureHandler().releaseMemory(true);
+    MemoryPressureHandler::singleton().releaseMemory(true);
     setAllLayerTreeStatesFrozen(true);
 
     if (!markAllLayersVolatileIfPossible())
     setAllLayerTreeStatesFrozen(true);
 
     if (!markAllLayersVolatileIfPossible())