Title: [167277] trunk/Source
Revision
167277
Author
[email protected]
Date
2014-04-14 16:03:54 -0700 (Mon, 14 Apr 2014)

Log Message

Do more things under memory pressure on non-iOS platforms.
<https://webkit.org/b/131625>

Reviewed by Antti Koivisto.

Rename hasReceivedMemoryPressure() to isUnderMemoryPressure() and
make it use std::atomic<bool> instead of OSAtomic primitives.

Unmask most of the PLATFORM(IOS) blocks so all platforms can take
advantage of optimizations done while under pressure. Note that
isUnderMemoryPressure() will still always return false on platforms
other than iOS/WK1, but this will change soon.

* history/PageCache.cpp:
(WebCore::PageCache::canCache):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::commitProvisionalLoad):
* page/FrameView.cpp:
(WebCore::FrameView::willPaintContents):
(WebCore::FrameView::didPaintContents):
* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::MemoryPressureHandler):
* platform/MemoryPressureHandler.h:
(WebCore::MemoryPressureHandler::isUnderMemoryPressure):
* platform/cocoa/MemoryPressureHandlerCocoa.mm:
(WebCore::MemoryPressureHandler::setReceivedMemoryPressure):
(WebCore::MemoryPressureHandler::clearMemoryPressure):
(WebCore::MemoryPressureHandler::respondToMemoryPressureIfNeeded):
(WebCore::MemoryPressureHandler::hasReceivedMemoryPressure): Deleted.
* 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (167276 => 167277)


--- trunk/Source/WebCore/ChangeLog	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/ChangeLog	2014-04-14 23:03:54 UTC (rev 167277)
@@ -1,3 +1,45 @@
+2014-04-14  Andreas Kling  <[email protected]>
+
+        Do more things under memory pressure on non-iOS platforms.
+        <https://webkit.org/b/131625>
+
+        Reviewed by Antti Koivisto.
+
+        Rename hasReceivedMemoryPressure() to isUnderMemoryPressure() and
+        make it use std::atomic<bool> instead of OSAtomic primitives.
+
+        Unmask most of the PLATFORM(IOS) blocks so all platforms can take
+        advantage of optimizations done while under pressure. Note that
+        isUnderMemoryPressure() will still always return false on platforms
+        other than iOS/WK1, but this will change soon.
+
+        * history/PageCache.cpp:
+        (WebCore::PageCache::canCache):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::commitProvisionalLoad):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::willPaintContents):
+        (WebCore::FrameView::didPaintContents):
+        * platform/MemoryPressureHandler.cpp:
+        (WebCore::MemoryPressureHandler::MemoryPressureHandler):
+        * platform/MemoryPressureHandler.h:
+        (WebCore::MemoryPressureHandler::isUnderMemoryPressure):
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        (WebCore::MemoryPressureHandler::setReceivedMemoryPressure):
+        (WebCore::MemoryPressureHandler::clearMemoryPressure):
+        (WebCore::MemoryPressureHandler::respondToMemoryPressureIfNeeded):
+        (WebCore::MemoryPressureHandler::hasReceivedMemoryPressure): Deleted.
+        * 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):
+
 2014-04-14  Beth Dakin  <[email protected]>
 
         RenderLayerCompositor's m_layerForOverhangAreas should be offset by the 

Modified: trunk/Source/WebCore/WebCore.exp.in (167276 => 167277)


--- trunk/Source/WebCore/WebCore.exp.in	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-04-14 23:03:54 UTC (rev 167277)
@@ -2557,7 +2557,6 @@
 __ZN7WebCore20previousWordPositionERKNS_15VisiblePositionE
 __ZN7WebCore21DeviceOrientationData6createEbdbdbdbdbd
 __ZN7WebCore21MemoryPressureHandler19clearMemoryPressureEv
-__ZN7WebCore21MemoryPressureHandler25hasReceivedMemoryPressureEv
 __ZN7WebCore21MemoryPressureHandler25installMemoryReleaseBlockEU13block_pointerFvvEb
 __ZN7WebCore21MemoryPressureHandler25setReceivedMemoryPressureENS_20MemoryPressureReasonE
 __ZN7WebCore21MemoryPressureHandler31shouldWaitForMemoryClearMessageEv

Modified: trunk/Source/WebCore/history/PageCache.cpp (167276 => 167277)


--- trunk/Source/WebCore/history/PageCache.cpp	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/history/PageCache.cpp	2014-04-14 23:03:54 UTC (rev 167277)
@@ -45,6 +45,7 @@
 #include "HistoryItem.h"
 #include "Logging.h"
 #include "MainFrame.h"
+#include "MemoryPressureHandler.h"
 #include "Page.h"
 #include "Settings.h"
 #include "SharedWorkerRepository.h"
@@ -360,10 +361,8 @@
     logCanCachePageDecision(page);
 #endif
 
-#if PLATFORM(IOS)
-    if (memoryPressureHandler().hasReceivedMemoryPressure())
+    if (memoryPressureHandler().isUnderMemoryPressure())
         return false;
-#endif
 
     // Cache the page, if possible.
     // Don't write to the cache if in the middle of a redirect, since we will want to

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (167276 => 167277)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2014-04-14 23:03:54 UTC (rev 167277)
@@ -1757,7 +1757,7 @@
     // 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().hasReceivedMemoryPressure()) {
+        if (memoryPressureHandler().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.

Modified: trunk/Source/WebCore/page/FrameView.cpp (167276 => 167277)


--- trunk/Source/WebCore/page/FrameView.cpp	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/page/FrameView.cpp	2014-04-14 23:03:54 UTC (rev 167277)
@@ -55,6 +55,8 @@
 #include "InspectorController.h"
 #include "InspectorInstrumentation.h"
 #include "MainFrame.h"
+#include "MemoryCache.h"
+#include "MemoryPressureHandler.h"
 #include "OverflowEvent.h"
 #include "ProgressTracker.h"
 #include "RenderEmbeddedObject.h"
@@ -3446,16 +3448,14 @@
 
     paintingState.isTopLevelPainter = !sCurrentPaintTimeStamp;
 
-#if PLATFORM(IOS)
-    // FIXME: Remove PLATFORM(IOS)-guard once we upstream the iOS changes to MemoryPressureHandler.h.
-    if (paintingState.isTopLevelPainter && memoryPressureHandler().hasReceivedMemoryPressure()) {
+    if (paintingState.isTopLevelPainter && memoryPressureHandler().isUnderMemoryPressure()) {
         LOG(MemoryPressure, "Under memory pressure: %s", __PRETTY_FUNCTION__);
 
         // To avoid unnecessary image decoding, we don't prune recently-decoded live resources here since
         // we might need some live bitmaps on painting.
         memoryCache()->prune();
     }
-#endif
+
     if (paintingState.isTopLevelPainter)
         sCurrentPaintTimeStamp = monotonicallyIncreasingTime();
 
@@ -3490,13 +3490,10 @@
     m_paintBehavior = paintingState.paintBehavior;
     m_lastPaintTime = monotonicallyIncreasingTime();
 
-#if PLATFORM(IOS)
     // Painting can lead to decoding of large amounts of bitmaps
     // If we are low on memory, wipe them out after the paint.
-    // FIXME: Remove PLATFORM(IOS)-guard once we upstream the iOS changes to MemoryPressureHandler.h.
-    if (paintingState.isTopLevelPainter && memoryPressureHandler().hasReceivedMemoryPressure())
+    if (paintingState.isTopLevelPainter && memoryPressureHandler().isUnderMemoryPressure())
         memoryCache()->pruneLiveResources(true);
-#endif
 
     // Regions may have changed as a result of the visibility/z-index of element changing.
 #if ENABLE(DASHBOARD_SUPPORT)

Modified: trunk/Source/WebCore/platform/MemoryPressureHandler.cpp (167276 => 167277)


--- trunk/Source/WebCore/platform/MemoryPressureHandler.cpp	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.cpp	2014-04-14 23:03:54 UTC (rev 167277)
@@ -54,9 +54,9 @@
     : m_installed(false)
     , m_lastRespondTime(0)
     , m_lowMemoryHandler(releaseMemory)
+    , m_underMemoryPressure(false)
 #if PLATFORM(IOS)
     // FIXME: Can we share more of this with OpenSource?
-    , m_receivedMemoryPressure(0)
     , m_memoryPressureReason(MemoryPressureReasonNone)
     , m_clearPressureOnMemoryRelease(true)
     , m_releaseMemoryBlock(0)

Modified: trunk/Source/WebCore/platform/MemoryPressureHandler.h (167276 => 167277)


--- trunk/Source/WebCore/platform/MemoryPressureHandler.h	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.h	2014-04-14 23:03:54 UTC (rev 167277)
@@ -26,6 +26,7 @@
 #ifndef MemoryPressureHandler_h
 #define MemoryPressureHandler_h
 
+#include <atomic>
 #include <time.h>
 #include <wtf/FastMalloc.h>
 
@@ -58,11 +59,12 @@
         m_lowMemoryHandler = handler;
     }
 
+    bool isUnderMemoryPressure() const { return m_underMemoryPressure; }
+
 #if PLATFORM(IOS)
     // FIXME: Can we share more of this with OpenSource?
     void installMemoryReleaseBlock(void (^releaseMemoryBlock)(), bool clearPressureOnMemoryRelease = true);
     void setReceivedMemoryPressure(MemoryPressureReason);
-    bool hasReceivedMemoryPressure();
     void clearMemoryPressure();
     bool shouldWaitForMemoryClearMessage();
     void respondToMemoryPressureIfNeeded();
@@ -84,8 +86,9 @@
     time_t m_lastRespondTime;
     LowMemoryHandler m_lowMemoryHandler;
 
+    std::atomic<bool> m_underMemoryPressure;
+
 #if PLATFORM(IOS)
-    uint32_t m_receivedMemoryPressure;
     uint32_t m_memoryPressureReason;
     bool m_clearPressureOnMemoryRelease;
     void (^m_releaseMemoryBlock)();

Modified: trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm (167276 => 167277)


--- trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm	2014-04-14 23:03:54 UTC (rev 167277)
@@ -38,7 +38,6 @@
 #if PLATFORM(IOS)
 #import "SystemMemory.h"
 #import "WebCoreThread.h"
-#import <libkern/OSAtomic.h>
 #endif
 
 namespace WebCore {
@@ -177,7 +176,7 @@
 
 void MemoryPressureHandler::setReceivedMemoryPressure(MemoryPressureReason reason)
 {
-    OSAtomicTestAndSet(0, &m_receivedMemoryPressure);
+    m_underMemoryPressure = true;
 
     {
         MutexLocker locker(m_observerMutex);
@@ -191,14 +190,9 @@
     }
 }
 
-bool MemoryPressureHandler::hasReceivedMemoryPressure()
-{
-    return OSAtomicOr32(0, &m_receivedMemoryPressure);
-}
-
 void MemoryPressureHandler::clearMemoryPressure()
 {
-    OSAtomicTestAndClear(0, &m_receivedMemoryPressure);
+    m_underMemoryPressure = false;
 
     {
         MutexLocker locker(m_observerMutex);
@@ -221,7 +215,7 @@
         m_observer = 0;
     }
 
-    if (hasReceivedMemoryPressure()) {
+    if (isUnderMemoryPressure()) {
         ASSERT(m_releaseMemoryBlock);
         LOG(MemoryPressure, "Handle memory pressure at %s", __PRETTY_FUNCTION__);
         m_releaseMemoryBlock();

Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (167276 => 167277)


--- trunk/Source/WebCore/platform/graphics/FontCache.cpp	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp	2014-04-14 23:03:54 UTC (rev 167277)
@@ -34,6 +34,7 @@
 #include "FontGlyphs.h"
 #include "FontPlatformData.h"
 #include "FontSelector.h"
+#include "MemoryPressureHandler.h"
 #include "WebKitFontFamilyNames.h"
 #include <wtf/HashMap.h>
 #include <wtf/ListHashSet.h>
@@ -47,7 +48,6 @@
 #endif
 
 #if PLATFORM(IOS)
-#include "MemoryPressureHandler.h"
 #include <wtf/Noncopyable.h>
 
 // FIXME: We may be able to simplify this code using C++11 threading primitives, including std::call_once().
@@ -361,12 +361,14 @@
 #if PLATFORM(IOS)
 const int cMaxInactiveFontData = 120;
 const int cTargetInactiveFontData = 100;
-const int cMaxUnderMemoryPressureInactiveFontData = 50;
-const int cTargetUnderMemoryPressureInactiveFontData = 30;
 #else
 const int cMaxInactiveFontData = 225;
 const int cTargetInactiveFontData = 200;
 #endif
+
+const int cMaxUnderMemoryPressureInactiveFontData = 50;
+const int cTargetUnderMemoryPressureInactiveFontData = 30;
+
 static ListHashSet<RefPtr<SimpleFontData>>* gInactiveFontData = 0;
 
 PassRefPtr<SimpleFontData> FontCache::getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName, ShouldRetain shouldRetain)
@@ -448,17 +450,12 @@
 
 void FontCache::purgeInactiveFontDataIfNeeded()
 {
-#if PLATFORM(IOS)
-    bool underMemoryPressure = memoryPressureHandler().hasReceivedMemoryPressure();
+    bool underMemoryPressure = memoryPressureHandler().isUnderMemoryPressure();
     int inactiveFontDataLimit = underMemoryPressure ? cMaxUnderMemoryPressureInactiveFontData : cMaxInactiveFontData;
     int targetFontDataLimit = underMemoryPressure ? cTargetUnderMemoryPressureInactiveFontData : cTargetInactiveFontData;
 
     if (gInactiveFontData && !m_purgePreventCount && gInactiveFontData->size() > inactiveFontDataLimit)
         purgeInactiveFontData(gInactiveFontData->size() - targetFontDataLimit);
-#else
-    if (gInactiveFontData && !m_purgePreventCount && gInactiveFontData->size() > cMaxInactiveFontData)
-        purgeInactiveFontData(gInactiveFontData->size() - cTargetInactiveFontData);
-#endif
 }
 
 void FontCache::purgeInactiveFontData(int count)

Modified: trunk/Source/WebCore/platform/ios/LegacyTileCache.mm (167276 => 167277)


--- trunk/Source/WebCore/platform/ios/LegacyTileCache.mm	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/platform/ios/LegacyTileCache.mm	2014-04-14 23:03:54 UTC (rev 167277)
@@ -424,7 +424,7 @@
 
 void LegacyTileCache::createTilesInActiveGrid(SynchronousTileCreationMode mode)
 {
-    if (memoryPressureHandler().hasReceivedMemoryPressure()) {
+    if (memoryPressureHandler().isUnderMemoryPressure()) {
         LOG(MemoryPressure, "Under memory pressure at: %s", __PRETTY_FUNCTION__);
         removeAllNonVisibleTilesInternal();
     }

Modified: trunk/Source/WebCore/platform/ios/LegacyTileGrid.mm (167276 => 167277)


--- trunk/Source/WebCore/platform/ios/LegacyTileGrid.mm	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/platform/ios/LegacyTileGrid.mm	2014-04-14 23:03:54 UTC (rev 167277)
@@ -391,7 +391,7 @@
 {
     return m_tileCache->tilingMode() == LegacyTileCache::Minimal
         || !m_tileCache->isSpeculativeTileCreationEnabled()
-        || memoryPressureHandler().hasReceivedMemoryPressure();
+        || memoryPressureHandler().isUnderMemoryPressure();
 }
 
 IntRect LegacyTileGrid::adjustCoverRectForPageBounds(const IntRect& rect) const

Modified: trunk/Source/WebCore/platform/ios/LegacyTileLayerPool.mm (167276 => 167277)


--- trunk/Source/WebCore/platform/ios/LegacyTileLayerPool.mm	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/platform/ios/LegacyTileLayerPool.mm	2014-04-14 23:03:54 UTC (rev 167277)
@@ -79,7 +79,7 @@
     if (!canReuseLayerWithSize(layerSize))
         return;
 
-    if (memoryPressureHandler().hasReceivedMemoryPressure()) {
+    if (memoryPressureHandler().isUnderMemoryPressure()) {
         LOG(MemoryPressure, "Under memory pressure: %s, totalBytes: %d", __PRETTY_FUNCTION__, m_totalBytes);
         return;
     }

Modified: trunk/Source/WebCore/platform/ios/TileControllerMemoryHandlerIOS.cpp (167276 => 167277)


--- trunk/Source/WebCore/platform/ios/TileControllerMemoryHandlerIOS.cpp	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebCore/platform/ios/TileControllerMemoryHandlerIOS.cpp	2014-04-14 23:03:54 UTC (rev 167277)
@@ -54,7 +54,7 @@
     m_tileControllers.appendOrMoveToLast(controller);
 
     // If we are under memory pressure, remove all unparented tiles now.
-    if (memoryPressureHandler().hasReceivedMemoryPressure()) {
+    if (memoryPressureHandler().isUnderMemoryPressure()) {
         trimUnparentedTilesToTarget(0);
         return;
     }

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (167276 => 167277)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2014-04-14 22:46:22 UTC (rev 167276)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2014-04-14 23:03:54 UTC (rev 167277)
@@ -1601,7 +1601,7 @@
 
 + (BOOL)_isUnderMemoryPressure
 {
-    return memoryPressureHandler().hasReceivedMemoryPressure();
+    return memoryPressureHandler().isUnderMemoryPressure();
 }
 
 + (void)_clearMemoryPressure
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to