Title: [87575] branches/safari-534-branch/Source

Diff

Modified: branches/safari-534-branch/Source/WebCore/ChangeLog (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/ChangeLog	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/ChangeLog	2011-05-27 21:50:11 UTC (rev 87575)
@@ -1,5 +1,51 @@
 2011-05-27  Mark Rowe  <mr...@apple.com>
 
+        Merge r87228.
+
+    2011-05-24  Michael Saboff  <msab...@apple.com>
+
+        Reviewed by Geoffrey Garen.
+
+        Improve handling in WebCore of low memory situations
+        https://bugs.webkit.org/show_bug.cgi?id=61222
+
+        Added new class, MemoryPressureHandler, to platform to respond to low
+        system memory events. Added Mac specific implementation that reduces the
+        page cache, NSURL cache, WebCore cache by half their current usage
+        and then garbage collects.  This can allow Safari to continue operating
+        in a low memory situation with minimal paging.
+        Split up prune operations in MemoryCache to allow for pruning to a
+        specific actual size to support this change.
+
+        No tests added as the functionality of WebKit wasn't changed.
+
+        * GNUmakefile.list.am:
+        * WebCore.exp.in:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::MemoryCache::pruneLiveResources):
+        (WebCore::MemoryCache::forcePruneLiveResources):
+        (WebCore::MemoryCache::pruneLiveResourcesToTarget):
+        (WebCore::MemoryCache::pruneDeadResources):
+        (WebCore::MemoryCache::forcePruneDeadResources):
+        (WebCore::MemoryCache::pruneDeadResourcesToTarget):
+        * loader/cache/MemoryCache.h:
+        (WebCore::MemoryCache::forcePrune):
+        * platform/MemoryPressureHandler.cpp: Added.
+        (WebCore::memoryPressureHandler):
+        (WebCore::MemoryPressureHandler::MemoryPressureHandler):
+        (WebCore::MemoryPressureHandler::install):
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+        * platform/MemoryPressureHandler.h: Added.
+        * platform/mac/MemoryPressureHandler.mm: Added.
+        (WebCore::MemoryPressureHandler::install):
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+
+2011-05-27  Mark Rowe  <mr...@apple.com>
+
         Merge r87460.
 
     2011-05-26  Stephanie Lewis  <sle...@apple.com>

Modified: branches/safari-534-branch/Source/WebCore/GNUmakefile.list.am (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/GNUmakefile.list.am	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/GNUmakefile.list.am	2011-05-27 21:50:11 UTC (rev 87575)
@@ -2520,6 +2520,8 @@
 	Source/WebCore/platform/Logging.h \
 	Source/WebCore/platform/MIMETypeRegistry.cpp \
 	Source/WebCore/platform/MIMETypeRegistry.h \
+	Source/WebCore/platform/MemoryPressureHandler.cpp \
+	Source/WebCore/platform/MemoryPressureHandler.h \
 	Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp \
 	Source/WebCore/platform/mock/DeviceOrientationClientMock.h \
 	Source/WebCore/platform/mock/GeolocationClientMock.cpp \

Modified: branches/safari-534-branch/Source/WebCore/WebCore.exp.in (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/WebCore.exp.in	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/WebCore.exp.in	2011-05-27 21:50:11 UTC (rev 87575)
@@ -546,6 +546,8 @@
 __ZN7WebCore20makeRGBA32FromFloatsEffff
 __ZN7WebCore20protocolIsJavaScriptERKN3WTF6StringE
 __ZN7WebCore21BackForwardController11itemAtIndexEi
+__ZN7WebCore21memoryPressureHandlerEv
+__ZN7WebCore21MemoryPressureHandler7installEv
 __ZN7WebCore21PlatformKeyboardEvent24disambiguateKeyDownEventENS0_4TypeEb
 __ZN7WebCore21PlatformKeyboardEventC1EP7NSEvent
 __ZN7WebCore21ResourceLoadScheduler20servePendingRequestsENS_20ResourceLoadPriorityE

Modified: branches/safari-534-branch/Source/WebCore/WebCore.gypi (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/WebCore.gypi	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/WebCore.gypi	2011-05-27 21:50:11 UTC (rev 87575)
@@ -760,6 +760,7 @@
             'platform/LocalizationStrategy.h',
             'platform/LocalizedStrings.h',
             'platform/Logging.h',
+            'platform/MemoryPressureHandler.h',
             'platform/MIMETypeRegistry.h',
             'platform/NotImplemented.h',
             'platform/PlatformGestureEvent.h',
@@ -3565,6 +3566,7 @@
             'platform/LinkHash.cpp',
             'platform/LocalizedStrings.cpp',
             'platform/Logging.cpp',
+            'platform/MemoryPressureHandler.cpp',
             'platform/MIMETypeRegistry.cpp',
             'platform/Pasteboard.h',
             'platform/PlatformStrategies.cpp',

Modified: branches/safari-534-branch/Source/WebCore/WebCore.pro (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/WebCore.pro	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/WebCore.pro	2011-05-27 21:50:11 UTC (rev 87575)
@@ -1015,6 +1015,7 @@
     platform/leveldb/LevelDBSlice.h \
     platform/LinkHash.cpp \
     platform/Logging.cpp \
+    platform/MemoryPressureHandler.cpp \
     platform/MIMETypeRegistry.cpp \
     platform/mock/DeviceOrientationClientMock.cpp \
     platform/mock/GeolocationClientMock.cpp \
@@ -1989,6 +1990,7 @@
     platform/LinkHash.h \
     platform/Logging.h \
     platform/Language.h \
+    platfory/MemoryPressureHandler.h \
     platform/MIMETypeRegistry.h \
     platform/network/AuthenticationChallengeBase.h \
     platform/network/AuthenticationClient.h \

Modified: branches/safari-534-branch/Source/WebCore/WebCore.vcproj/WebCore.vcproj (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-05-27 21:50:11 UTC (rev 87575)
@@ -25838,6 +25838,14 @@
 				>
 			</File>
 			<File
+				RelativePath="..\platform\MemoryPressureHandler.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\platform\MemoryPressureHandler.h"
+				>
+			</File>
+			<File
 				RelativePath="..\platform\NotImplemented.h"
 				>
 			</File>

Modified: branches/safari-534-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-05-27 21:50:11 UTC (rev 87575)
@@ -1475,6 +1475,9 @@
 		656D37410ADBA5DE00A4554D /* MainResourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37290ADBA5DE00A4554D /* MainResourceLoader.h */; };
 		656D37430ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		656D37480ADBA5DE00A4554D /* SubresourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37300ADBA5DE00A4554D /* SubresourceLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		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 */; };
+		657EDA0B1385CBD8004E0645 /* MemoryPressureHandlerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */; };
 		6582A16309999D6D00BEEB6D /* SystemTimeMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */; };
 		658436860AE01B7400E53753 /* FrameLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 658436850AE01B7400E53753 /* FrameLoadRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6593923709AE4346002C531F /* KURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6593923509AE4346002C531F /* KURL.cpp */; };
@@ -8023,6 +8026,9 @@
 		656D37290ADBA5DE00A4554D /* MainResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MainResourceLoader.h; sourceTree = "<group>"; };
 		656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NetscapePlugInStreamLoader.h; sourceTree = "<group>"; };
 		656D37300ADBA5DE00A4554D /* SubresourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SubresourceLoader.h; sourceTree = "<group>"; };
+		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>"; };
+		657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryPressureHandlerMac.mm; sourceTree = "<group>"; };
 		6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SystemTimeMac.cpp; sourceTree = "<group>"; };
 		658436850AE01B7400E53753 /* FrameLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoadRequest.h; sourceTree = "<group>"; };
 		6593923509AE4346002C531F /* KURL.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = KURL.cpp; sourceTree = "<group>"; };
@@ -14068,6 +14074,7 @@
 				06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */,
 				BC25B528131C6D3900180E10 /* LocalizedStringsMac.mm */,
 				1402645D0AFDC19B005919E2 /* LoggingMac.mm */,
+				657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */,
 				BC772C5D0C4EB3440083285F /* MIMETypeRegistryMac.mm */,
 				A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */,
 				4B2709810AF2E5E00065127F /* PasteboardMac.mm */,
@@ -18544,6 +18551,8 @@
 				935207BD09BD410A00F2038D /* LocalizedStrings.h */,
 				A8239DFE09B3CF8A00B60641 /* Logging.cpp */,
 				A8239DFF09B3CF8A00B60641 /* Logging.h */,
+				657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */,
+				657EDA071385CB97004E0645 /* MemoryPressureHandler.h */,
 				BC772C4C0C4EB3040083285F /* MIMETypeRegistry.cpp */,
 				BC772C4D0C4EB3040083285F /* MIMETypeRegistry.h */,
 				98EB1F941313FE0500D0E1EA /* NotImplemented.h */,
@@ -22817,6 +22826,7 @@
 				FD537357137B653B00008DCE /* DynamicsCompressorKernel.h in Headers */,
 				BCF7E491137CD7C7001DDAE7 /* AdjustViewSizeOrNot.h in Headers */,
 				B1E54593134629C10092A545 /* CallbackTask.h in Headers */,
+				6571DCC81385E6A400702DD0 /* MemoryPressureHandler.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -25490,6 +25500,8 @@
 				379E371613736A6600B9E919 /* QuotedPrintable.cpp in Sources */,
 				FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
 				FD537356137B653B00008DCE /* DynamicsCompressorKernel.cpp in Sources */,
+				657EDA081385CB97004E0645 /* MemoryPressureHandler.cpp in Sources */,
+				657EDA0B1385CBD8004E0645 /* MemoryPressureHandlerMac.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: branches/safari-534-branch/Source/WebCore/loader/cache/MemoryCache.cpp (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/loader/cache/MemoryCache.cpp	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/loader/cache/MemoryCache.cpp	2011-05-27 21:50:11 UTC (rev 87575)
@@ -172,6 +172,26 @@
         return;
 
     unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again.
+
+    pruneLiveResourcesToSize(targetSize);
+}
+
+void MemoryCache::PruneLiveResourcesToPercentage(float prunePercentage)
+{
+    if (!m_pruneEnabled)
+        return;
+
+    if (prunePercentage < 0.0f  || prunePercentage > 0.95f)
+        return;
+
+    unsigned currentSize = m_liveSize + m_deadSize;
+    unsigned targetSize = static_cast<unsigned>(currentSize * prunePercentage);
+
+    pruneLiveResourcesToSize(targetSize);
+}
+
+void MemoryCache::pruneLiveResourcesToSize(unsigned targetSize)
+{
     double currentTime = FrameView::currentPaintTimeStamp();
     if (!currentTime) // In case prune is called directly, outside of a Frame paint.
         currentTime = WTF::currentTime();
@@ -216,8 +236,27 @@
         return;
 
     unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again.
+    pruneDeadResourcesToSize(targetSize);
+}
+
+void MemoryCache::PruneDeadResourcesToPercentage(float prunePercentage)
+{
+    if (!m_pruneEnabled)
+        return;
+
+    if (prunePercentage < 0.0f  || prunePercentage > 0.95f)
+        return;
+
+    unsigned currentSize = m_liveSize + m_deadSize;
+    unsigned targetSize = static_cast<unsigned>(currentSize * prunePercentage);
+
+    pruneDeadResourcesToSize(targetSize);
+}
+
+void MemoryCache::pruneDeadResourcesToSize(unsigned targetSize)
+{ 
     int size = m_allResources.size();
-    
+ 
     if (!m_inPruneDeadResources) {
         // See if we have any purged resources we can evict.
         for (int i = 0; i < size; i++) {

Modified: branches/safari-534-branch/Source/WebCore/loader/cache/MemoryCache.h (87574 => 87575)


--- branches/safari-534-branch/Source/WebCore/loader/cache/MemoryCache.h	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebCore/loader/cache/MemoryCache.h	2011-05-27 21:50:11 UTC (rev 87575)
@@ -139,6 +139,12 @@
         pruneLiveResources();
     }
 
+    void pruneToPercentage(float targetPercentLive)
+    {
+        PruneDeadResourcesToPercentage(targetPercentLive); // Prune dead first, in case it was "borrowing" capacity from live.
+        PruneLiveResourcesToPercentage(targetPercentLive);
+    }
+
     void setDeadDecodedDataDeletionInterval(double interval) { m_deadDecodedDataDeletionInterval = interval; }
     double deadDecodedDataDeletionInterval() const { return m_deadDecodedDataDeletionInterval; }
 
@@ -182,10 +188,16 @@
 
     unsigned liveCapacity() const;
     unsigned deadCapacity() const;
-    
-    void pruneDeadResources(); // Flush decoded and encoded data from resources not referenced by Web pages.
-    void pruneLiveResources(); // Flush decoded data from resources still referenced by Web pages.
 
+    // pruneDead*() - Flush decoded and encoded data from resources not referenced by Web pages.
+    // pruneLive*() - Flush decoded data from resources still referenced by Web pages.
+    void pruneDeadResources(); // Automatically decide how much to prune.
+    void pruneLiveResources();
+    void PruneDeadResourcesToPercentage(float prunePercentage);
+    void PruneLiveResourcesToPercentage(float prunePercentage);
+    void pruneDeadResourcesToSize(unsigned targetSize);
+    void pruneLiveResourcesToSize(unsigned targetSize);
+
     bool makeResourcePurgeable(CachedResource*);
     void evict(CachedResource*);
 

Added: branches/safari-534-branch/Source/WebCore/platform/MemoryPressureHandler.cpp (0 => 87575)


--- branches/safari-534-branch/Source/WebCore/platform/MemoryPressureHandler.cpp	                        (rev 0)
+++ branches/safari-534-branch/Source/WebCore/platform/MemoryPressureHandler.cpp	2011-05-27 21:50:11 UTC (rev 87575)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011 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/StdLibExtras.h>
+
+namespace WebCore {
+
+MemoryPressureHandler& memoryPressureHandler()
+{
+    DEFINE_STATIC_LOCAL(MemoryPressureHandler, staticMemoryPressureHandler, ());
+    return staticMemoryPressureHandler;
+}
+
+MemoryPressureHandler::MemoryPressureHandler() { }
+
+#if !PLATFORM(MAC) || defined(BUILDING_ON_LEOPARD) || defined(BUILDING_ON_SNOW_LEOPARD)
+void MemoryPressureHandler::install() { }
+
+void MemoryPressureHandler::respondToMemoryPressure() { }
+#endif
+ 
+} // namespace WebCore

Added: branches/safari-534-branch/Source/WebCore/platform/MemoryPressureHandler.h (0 => 87575)


--- branches/safari-534-branch/Source/WebCore/platform/MemoryPressureHandler.h	                        (rev 0)
+++ branches/safari-534-branch/Source/WebCore/platform/MemoryPressureHandler.h	2011-05-27 21:50:11 UTC (rev 87575)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#ifndef MemoryPressureHandler_h
+#define MemoryPressureHandler_h
+
+#include <wtf/Platform.h>
+
+namespace WebCore {
+
+class MemoryPressureHandler {
+public:
+    friend MemoryPressureHandler& memoryPressureHandler();
+
+    void install();
+
+private:
+    MemoryPressureHandler();
+    ~MemoryPressureHandler();
+
+    void respondToMemoryPressure();
+};
+ 
+// Function to obtain the global memory pressure object.
+MemoryPressureHandler& memoryPressureHandler();
+
+} // namespace WebCore
+
+#endif // MemoryPressureHandler_h

Added: branches/safari-534-branch/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm (0 => 87575)


--- branches/safari-534-branch/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm	                        (rev 0)
+++ branches/safari-534-branch/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm	2011-05-27 21:50:11 UTC (rev 87575)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 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 <WebCore/GCController.h>
+#import <WebCore/MemoryCache.h>
+#import <WebCore/PageCache.h>
+#import <wtf/FastMalloc.h>
+
+#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
+#import <dispatch/dispatch.h>
+
+#ifndef DISPATCH_SOURCE_TYPE_VM
+#define DISPATCH_SOURCE_TYPE_VM (&_dispatch_source_type_vm)
+DISPATCH_EXPORT const struct dispatch_source_type_s _dispatch_source_type_vm;
+#endif
+
+#ifdef DISPATCH_VM_PRESSURE
+enum {
+ DISPATCH_VM_PRESSURE = 0x80000000,
+};
+#endif
+
+#endif
+
+namespace WebCore {
+
+#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
+
+static dispatch_source_t _cache_event_source = 0;
+#ifndef NDEBUG
+static dispatch_source_t _cache_event_source2 = 0;
+#endif
+
+void MemoryPressureHandler::install()
+{
+    if (!_cache_event_source) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VM, 0, DISPATCH_VM_PRESSURE, dispatch_get_main_queue());
+            if (_cache_event_source) {
+                dispatch_set_context(_cache_event_source, this);
+                dispatch_source_set_event_handler(_cache_event_source, ^{ memoryPressureHandler().respondToMemoryPressure();});
+                dispatch_resume(_cache_event_source);
+            }
+        });
+    }
+
+#ifndef NDEBUG
+    if (!_cache_event_source2) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            _cache_event_source2 = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGUSR2, 0, dispatch_get_main_queue());
+            if (_cache_event_source2) {
+                dispatch_set_context(_cache_event_source2, this);
+                dispatch_source_set_event_handler(_cache_event_source2, ^{ memoryPressureHandler().respondToMemoryPressure();});
+                dispatch_resume(_cache_event_source2);
+                signal((int)SIGUSR2, SIG_IGN);
+            }
+        });
+    }
+#endif
+}
+
+void MemoryPressureHandler::respondToMemoryPressure()
+{
+    int savedPageCacheCapacity = pageCache()->capacity();
+    pageCache()->setCapacity(pageCache()->pageCount()>>1);
+    pageCache()->setCapacity(savedPageCacheCapacity);
+    pageCache()->releaseAutoreleasedPagesNow();
+
+    NSURLCache *nsurlCache = [NSURLCache sharedURLCache];
+    NSUInteger savedNsurlCacheMemoryCapacity = [nsurlCache memoryCapacity];
+    [nsurlCache setMemoryCapacity:[nsurlCache currentMemoryUsage]>>1];
+    [nsurlCache setMemoryCapacity:savedNsurlCacheMemoryCapacity];
+ 
+    memoryCache()->pruneToPercentage(0.5f);
+
+    gcController().garbageCollectNow();
+
+    WTF::releaseFastMallocFreeMemory();
+}
+#endif
+
+} // namespace WebCore

Modified: branches/safari-534-branch/Source/WebKit/mac/ChangeLog (87574 => 87575)


--- branches/safari-534-branch/Source/WebKit/mac/ChangeLog	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebKit/mac/ChangeLog	2011-05-27 21:50:11 UTC (rev 87575)
@@ -1,5 +1,22 @@
 2011-05-27  Mark Rowe  <mr...@apple.com>
 
+        Merge r87228.
+
+    2011-05-24  Michael Saboff  <msab...@apple.com>
+
+        Reviewed by Geoffrey Garen.
+
+        Improve handling in WebCore of low memory situations
+        https://bugs.webkit.org/show_bug.cgi?id=61222
+
+        Added call to enable memory pressure handling.
+
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:usesDocumentViews:]):
+        * WebView/WebViewInternal.h:
+
+2011-05-27  Mark Rowe  <mr...@apple.com>
+
         Merge r87329.
 
     2011-05-25  Stephanie Lewis  <sle...@apple.com>

Modified: branches/safari-534-branch/Source/WebKit/mac/WebView/WebView.mm (87574 => 87575)


--- branches/safari-534-branch/Source/WebKit/mac/WebView/WebView.mm	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebKit/mac/WebView/WebView.mm	2011-05-27 21:50:11 UTC (rev 87575)
@@ -138,6 +138,7 @@
 #import <WebCore/JSElement.h>
 #import <WebCore/JSNodeList.h>
 #import <WebCore/Logging.h>
+#import <WebCore/MemoryPressureHandler.h>
 #import <WebCore/MIMETypeRegistry.h>
 #import <WebCore/NodeList.h>
 #import <WebCore/Page.h>
@@ -798,6 +799,8 @@
     [self _preferencesChanged:[self preferences]];
     [[self preferences] _postPreferencesChangedAPINotification];
 
+    memoryPressureHandler().install();
+
     if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION)) {
         // Originally, we allowed all local loads.
         SecurityOrigin::setLocalLoadPolicy(SecurityOrigin::AllowLocalLoadsForAll);

Modified: branches/safari-534-branch/Source/WebKit2/ChangeLog (87574 => 87575)


--- branches/safari-534-branch/Source/WebKit2/ChangeLog	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebKit2/ChangeLog	2011-05-27 21:50:11 UTC (rev 87575)
@@ -1,5 +1,24 @@
 2011-05-27  Mark Rowe  <mr...@apple.com>
 
+        Merge r87228.
+
+    2011-05-24  Michael Saboff  <msab...@apple.com>
+
+        Reviewed by Geoffrey Garen.
+
+        Improve handling in WebCore of low memory situations
+        https://bugs.webkit.org/show_bug.cgi?id=61222
+
+        Added call to enable memory pressure handling for Mac case.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+        * WebProcess/WebProcess.h:
+        * WebProcess/mac/WebProcessMac.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
+2011-05-27  Mark Rowe  <mr...@apple.com>
+
         Merge r87456.
 
     2011-05-26  Jon Lee  <jon...@apple.com>

Modified: branches/safari-534-branch/Source/WebKit2/WebProcess/WebProcess.cpp (87574 => 87575)


--- branches/safari-534-branch/Source/WebKit2/WebProcess/WebProcess.cpp	2011-05-27 21:43:04 UTC (rev 87574)
+++ branches/safari-534-branch/Source/WebKit2/WebProcess/WebProcess.cpp	2011-05-27 21:50:11 UTC (rev 87575)
@@ -58,6 +58,7 @@
 #include <WebCore/Language.h>
 #include <WebCore/Logging.h>
 #include <WebCore/MemoryCache.h>
+#include <WebCore/MemoryPressureHandler.h>
 #include <WebCore/Page.h>
 #include <WebCore/PageCache.h>
 #include <WebCore/PageGroup.h>
@@ -164,6 +165,8 @@
 
     platformInitializeWebProcess(parameters, arguments);
 
+    memoryPressureHandler().install();
+
     RefPtr<APIObject> injectedBundleInitializationUserData;
     InjectedBundleUserMessageDecoder messageDecoder(injectedBundleInitializationUserData);
     if (!arguments->decode(messageDecoder))
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to