Share MemoryPressureHandler::releaseMemory() between platforms.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Mar 2014 02:33:27 +0000 (02:33 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Mar 2014 02:33:27 +0000 (02:33 +0000)
<https://webkit.org/b/130416>

Move the code that scours WebKit for things we can free up right now
to the common part of MemoryPressureHandler. This will enable other
platforms to do the same thing under pressure.

There's now also a platformReleaseMemory() where platform-specific
pressure relief stuff can go.

Reviewed by Antti Koivisto.

* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::releaseMemory):
(WebCore::MemoryPressureHandler::platformReleaseMemory):
* platform/MemoryPressureHandler.h:
* platform/mac/MemoryPressureHandlerMac.mm:
(WebCore::MemoryPressureHandler::respondToMemoryPressure):
(WebCore::MemoryPressureHandler::platformReleaseMemory):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/MemoryPressureHandler.cpp
Source/WebCore/platform/MemoryPressureHandler.h
Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm

index 29abb14d3b8b4c86b9753b19e8bd0e43e602eec1..269f7f4f688dee5c75ee6a682e8cd006ce5d73d8 100644 (file)
@@ -1,3 +1,25 @@
+2014-03-18  Andreas Kling  <akling@apple.com>
+
+        Share MemoryPressureHandler::releaseMemory() between platforms.
+        <https://webkit.org/b/130416>
+
+        Move the code that scours WebKit for things we can free up right now
+        to the common part of MemoryPressureHandler. This will enable other
+        platforms to do the same thing under pressure.
+
+        There's now also a platformReleaseMemory() where platform-specific
+        pressure relief stuff can go.
+
+        Reviewed by Antti Koivisto.
+
+        * platform/MemoryPressureHandler.cpp:
+        (WebCore::MemoryPressureHandler::releaseMemory):
+        (WebCore::MemoryPressureHandler::platformReleaseMemory):
+        * platform/MemoryPressureHandler.h:
+        * platform/mac/MemoryPressureHandlerMac.mm:
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+        (WebCore::MemoryPressureHandler::platformReleaseMemory):
+
 2014-03-18  Dean Jackson  <dino@apple.com>
 
         [WebGL] Destroy EAGLContext's backing store
index 744e2102f9f110e39cb818e26a6d3e545bb2e7d3..a3ac0a816d49553e6bb0fddc3b58e481179909ec 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2011, 2014 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "config.h"
 #include "MemoryPressureHandler.h"
 
+#include "CSSValuePool.h"
+#include "Document.h"
+#include "Font.h"
+#include "FontCache.h"
+#include "GCController.h"
+#include "MemoryCache.h"
+#include "Page.h"
+#include "PageCache.h"
+#include "ScrollingThread.h"
+#include "StorageThread.h"
+#include "WorkerThread.h"
+#include <wtf/CurrentTime.h>
+#include <wtf/FastMalloc.h>
+#include <wtf/Functional.h>
 #include <wtf/StdLibExtras.h>
 
 namespace WebCore {
@@ -51,15 +65,43 @@ MemoryPressureHandler::MemoryPressureHandler()
 {
 }
 
+void MemoryPressureHandler::releaseMemory(bool critical)
+{
+    int savedPageCacheCapacity = pageCache()->capacity();
+    pageCache()->setCapacity(0);
+    pageCache()->setCapacity(savedPageCacheCapacity);
+
+    fontCache()->purgeInactiveFontData();
+
+    memoryCache()->pruneToPercentage(0);
+
+    cssValuePool().drain();
+
+    clearWidthCaches();
+
+    for (auto* document : Document::allDocuments())
+        document->clearStyleResolver();
+
+    gcController().discardAllCompiledCode();
+
+    platformReleaseMemory(critical);
+
+    // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself.
+    StorageThread::releaseFastMallocFreeMemoryInAllThreads();
+    WorkerThread::releaseFastMallocFreeMemoryInAllThreads();
+#if ENABLE(ASYNC_SCROLLING)
+    ScrollingThread::dispatch(bind(WTF::releaseFastMallocFreeMemory));
+#endif
+    WTF::releaseFastMallocFreeMemory();
+}
+
 #if !PLATFORM(MAC)
 
 void MemoryPressureHandler::install() { }
 void MemoryPressureHandler::uninstall() { }
 void MemoryPressureHandler::holdOff(unsigned) { }
 void MemoryPressureHandler::respondToMemoryPressure() { }
-#if !PLATFORM(IOS)
-void MemoryPressureHandler::releaseMemory(bool) { }
-#endif // !PLATFORM(IOS)
+void MemoryPressureHandler::platformReleaseMemory(bool) { }
 
 #endif
 
index ebfb84ca10b7ffe3c999d3be1554131ab683f075..fec7d522bf066155059c725bc200263e0a5cbe85 100644 (file)
@@ -78,6 +78,7 @@ private:
 
     void respondToMemoryPressure();
     static void releaseMemory(bool critical);
+    static void platformReleaseMemory(bool critical);
 
     bool m_installed;
     time_t m_lastRespondTime;
index 362167ec41ba91ec7de6787e60ad174937e0373d..6e8d546b02dd74a739e5da9cc80379ee0be1ba80 100644 (file)
 #import "config.h"
 #import "MemoryPressureHandler.h"
 
-#import <WebCore/CSSValuePool.h>
-#import <WebCore/Document.h>
-#import <WebCore/GCController.h>
-#import <WebCore/FontCache.h>
-#import <WebCore/MemoryCache.h>
-#import <WebCore/Page.h>
-#import <WebCore/PageCache.h>
 #import <WebCore/LayerPool.h>
-#import <WebCore/ScrollingThread.h>
-#import <WebCore/StorageThread.h>
-#import <WebCore/WorkerThread.h>
 #import <wtf/CurrentTime.h>
-#import <wtf/FastMalloc.h>
-#import <wtf/Functional.h>
 #import <malloc/malloc.h>
 
 #if !PLATFORM(IOS)
@@ -146,38 +134,12 @@ void MemoryPressureHandler::respondToMemoryPressure()
 
     holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
 }
-#endif // !PLATFORM(IOS)
 
-void MemoryPressureHandler::releaseMemory(bool)
+void MemoryPressureHandler::platformReleaseMemory(bool)
 {
-    int savedPageCacheCapacity = pageCache()->capacity();
-    pageCache()->setCapacity(0);
-    pageCache()->setCapacity(savedPageCacheCapacity);
-
-    fontCache()->purgeInactiveFontData();
-
-    memoryCache()->pruneToPercentage(0);
-
-#if !PLATFORM(IOS)
     LayerPool::sharedPool()->drain();
-#endif
-
-    cssValuePool().drain();
-
-    clearWidthCaches();
-
-    for (auto* document : Document::allDocuments())
-        document->clearStyleResolver();
-
-    gcController().discardAllCompiledCode();
-
-    // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself.
-    StorageThread::releaseFastMallocFreeMemoryInAllThreads();
-    WorkerThread::releaseFastMallocFreeMemoryInAllThreads();
-#if ENABLE(ASYNC_SCROLLING)
-    ScrollingThread::dispatch(bind(WTF::releaseFastMallocFreeMemory));
-#endif
-    WTF::releaseFastMallocFreeMemory();
 }
 
+#endif // !PLATFORM(IOS)
+
 } // namespace WebCore