Changeset 208534 in webkit


Ignore:
Timestamp:
Nov 10, 2016 6:24:26 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

MemoryPressureHandler shouldn't know how to release WebCore memory
https://bugs.webkit.org/show_bug.cgi?id=160497

Reviewed by Michael Catanzaro.

Source/WebCore:

All processes should set their own low memory handler, instead of leaving the web process using the default one
that needs to access APIs that are not in platform layer. This patch fixes all the layering violations in the
MemoryPressureHandler. Since the default implementation, that releases the WebCore memory, is shared by the
WebProcess in WebKit2 and WebKit1 ports, it has been moved to its own file to the WebCore layer.

  • CMakeLists.txt: Add new files to compilation.
  • PlatformMac.cmake: Ditto.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::commitProvisionalLoad): Use WebCore::jettisonExpensiveObjectsOnTopLevelNavigation().

  • page/MemoryRelease.cpp: Added.

(WebCore::releaseNoncriticalMemory):
(WebCore::releaseCriticalMemory):
(WebCore::releaseMemory):
(WebCore::platformReleaseMemory):
(WebCore::jettisonExpensiveObjectsOnTopLevelNavigation):
(WebCore::registerMemoryReleaseNotifyCallbacks):

  • page/MemoryRelease.h: Added.
  • page/cocoa/MemoryReleaseCocoa.mm: Added.

(WebCore::platformReleaseMemory):
(WebCore::jettisonExpensiveObjectsOnTopLevelNavigation):
(WebCore::registerMemoryReleaseNotifyCallbacks):

  • platform/MemoryPressureHandler.cpp:

(WebCore::MemoryPressureHandler::MemoryPressureHandler):
(WebCore::MemoryPressureHandler::beginSimulatedMemoryPressure):
(WebCore::MemoryPressureHandler::releaseMemory): Use the current handler if it has been set.
(WebCore::MemoryPressureHandler::platformReleaseMemory): Deleted.

  • platform/MemoryPressureHandler.h:

(WebCore::MemoryPressureHandler::setLowMemoryHandler):
(WebCore::MemoryPressureHandler::m_releaseMemoryBlock):

  • platform/cocoa/MemoryPressureHandlerCocoa.mm:

(WebCore::MemoryPressureHandler::respondToMemoryPressure): Call releaseMemory() instead of using the handler directly.
(WebCore::MemoryPressureHandler::platformReleaseMemory): Deleted.

  • platform/linux/MemoryPressureHandlerLinux.cpp:
  • platform/win/MemoryPressureHandlerWin.cpp:

(WebCore::MemoryPressureHandler::respondToMemoryPressure): Call releaseMemory() instead of using the handler directly.

Source/WebKit/mac:

Set the low memory handler before installing the memory pressure handler.

  • WebView/WebView.mm:

(-[WebView _commonInitializationWithFrameName:groupName:]):

Source/WebKit/win:

Set the low memory handler before installing the memory pressure handler.

  • WebView.cpp:

(WebView::initWithFrame):

Source/WebKit2:

Set the low memory handler before installing the memory pressure handler.

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::initializeWebProcess):

  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::platformInitializeWebProcess):

Location:
trunk/Source
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r208486 r208534  
    20412041    page/Location.cpp
    20422042    page/MainFrame.cpp
     2043    page/MemoryRelease.cpp
    20432044    page/MouseEventWithHitTestResults.cpp
    20442045    page/Navigator.cpp
  • trunk/Source/WebCore/ChangeLog

    r208531 r208534  
     12016-10-14  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        MemoryPressureHandler shouldn't know how to release WebCore memory
     4        https://bugs.webkit.org/show_bug.cgi?id=160497
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        All processes should set their own low memory handler, instead of leaving the web process using the default one
     9        that needs to access APIs that are not in platform layer. This patch fixes all the layering violations in the
     10        MemoryPressureHandler. Since the default implementation, that releases the WebCore memory, is shared by the
     11        WebProcess in WebKit2 and WebKit1 ports, it has been moved to its own file to the WebCore layer.
     12
     13        * CMakeLists.txt: Add new files to compilation.
     14        * PlatformMac.cmake: Ditto.
     15        * WebCore.xcodeproj/project.pbxproj: Ditto.
     16        * loader/FrameLoader.cpp:
     17        (WebCore::FrameLoader::commitProvisionalLoad): Use WebCore::jettisonExpensiveObjectsOnTopLevelNavigation().
     18        * page/MemoryRelease.cpp: Added.
     19        (WebCore::releaseNoncriticalMemory):
     20        (WebCore::releaseCriticalMemory):
     21        (WebCore::releaseMemory):
     22        (WebCore::platformReleaseMemory):
     23        (WebCore::jettisonExpensiveObjectsOnTopLevelNavigation):
     24        (WebCore::registerMemoryReleaseNotifyCallbacks):
     25        * page/MemoryRelease.h: Added.
     26        * page/cocoa/MemoryReleaseCocoa.mm: Added.
     27        (WebCore::platformReleaseMemory):
     28        (WebCore::jettisonExpensiveObjectsOnTopLevelNavigation):
     29        (WebCore::registerMemoryReleaseNotifyCallbacks):
     30        * platform/MemoryPressureHandler.cpp:
     31        (WebCore::MemoryPressureHandler::MemoryPressureHandler):
     32        (WebCore::MemoryPressureHandler::beginSimulatedMemoryPressure):
     33        (WebCore::MemoryPressureHandler::releaseMemory): Use the current handler if it has been set.
     34        (WebCore::MemoryPressureHandler::platformReleaseMemory): Deleted.
     35        * platform/MemoryPressureHandler.h:
     36        (WebCore::MemoryPressureHandler::setLowMemoryHandler):
     37        (WebCore::MemoryPressureHandler::m_releaseMemoryBlock):
     38        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
     39        (WebCore::MemoryPressureHandler::respondToMemoryPressure): Call releaseMemory() instead of using the handler directly.
     40        (WebCore::MemoryPressureHandler::platformReleaseMemory): Deleted.
     41        * platform/linux/MemoryPressureHandlerLinux.cpp:
     42        * platform/win/MemoryPressureHandlerWin.cpp:
     43        (WebCore::MemoryPressureHandler::respondToMemoryPressure): Call releaseMemory() instead of using the handler directly.
     44
    1452016-11-08  Sergio Villar Senin  <svillar@igalia.com>
    246
  • trunk/Source/WebCore/PlatformMac.cmake

    r208433 r208534  
    261261    page/PageDebuggable.cpp
    262262
     263    page/cocoa/MemoryReleaseCocoa.mm
    263264    page/cocoa/UserAgent.mm
    264265    page/cocoa/ResourceUsageOverlayCocoa.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r208491 r208534  
    15461546                4138F8581D253F0E001CB61E /* JSDOMIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4138F8561D253EEE001CB61E /* JSDOMIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
    15471547                413C2C341BC29A8F0075204C /* JSDOMConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 413C2C331BC29A7B0075204C /* JSDOMConstructor.h */; };
     1548                413E00791DB0E4F2002341D2 /* MemoryRelease.h in Headers */ = {isa = PBXBuildFile; fileRef = 413E00781DB0E4DE002341D2 /* MemoryRelease.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1549                413E007A1DB0E4F9002341D2 /* MemoryRelease.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413E00771DB0E4DE002341D2 /* MemoryRelease.cpp */; };
     1550                413E007C1DB0E70A002341D2 /* MemoryReleaseCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 413E007B1DB0E707002341D2 /* MemoryReleaseCocoa.mm */; };
    15481551                4147E2B71C89912C00A7E715 /* FetchLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4147E2B41C89912600A7E715 /* FetchLoader.cpp */; };
    15491552                4147E2B81C89912F00A7E715 /* FetchBodyOwner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4147E2B31C89912600A7E715 /* FetchBodyOwner.cpp */; };
     
    86058608                4138F8561D253EEE001CB61E /* JSDOMIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMIterator.h; sourceTree = "<group>"; };
    86068609                413C2C331BC29A7B0075204C /* JSDOMConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMConstructor.h; sourceTree = "<group>"; };
     8610                413E00771DB0E4DE002341D2 /* MemoryRelease.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryRelease.cpp; sourceTree = "<group>"; };
     8611                413E00781DB0E4DE002341D2 /* MemoryRelease.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryRelease.h; sourceTree = "<group>"; };
     8612                413E007B1DB0E707002341D2 /* MemoryReleaseCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryReleaseCocoa.mm; sourceTree = "<group>"; };
    86078613                4147E2B21C88337F00A7E715 /* FetchBodyOwner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchBodyOwner.h; sourceTree = "<group>"; };
    86088614                4147E2B31C89912600A7E715 /* FetchBodyOwner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchBodyOwner.cpp; sourceTree = "<group>"; };
     
    1718317189                        isa = PBXGroup;
    1718417190                        children = (
     17191                                413E007B1DB0E707002341D2 /* MemoryReleaseCocoa.mm */,
    1718517192                                ADFE2B541BD5F41200DAB457 /* ResourceUsageOverlayCocoa.mm */,
    1718617193                                A5071E881C56D4FA009951BE /* ResourceUsageThreadCocoa.mm */,
     
    1773917746                                931BCC601124DFCB00BE70DD /* MediaCanStartListener.h */,
    1774017747                                52E2CAFB19FF0207001EEB4F /* MediaProducer.h */,
     17748                                413E00771DB0E4DE002341D2 /* MemoryRelease.cpp */,
     17749                                413E00781DB0E4DE002341D2 /* MemoryRelease.h */,
    1774117750                                93EB355E09E37FD600F43799 /* MouseEventWithHitTestResults.cpp */,
    1774217751                                935C476209AC4CE600A6AAB4 /* MouseEventWithHitTestResults.h */,
     
    2523025239                                416E6FE81BBD12DF000A6023 /* FetchInternalsBuiltins.h in Headers */,
    2523125240                                41AD753A1CEF6BD100A31486 /* FetchOptions.h in Headers */,
     25241                                413E00791DB0E4F2002341D2 /* MemoryRelease.h in Headers */,
    2523225242                                84730D8B1248F0B300D3A9C9 /* FETile.h in Headers */,
    2523325243                                84730D8D1248F0B300D3A9C9 /* FETurbulence.h in Headers */,
     
    2854128551                                CDCA98EB18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp in Sources */,
    2854228552                                CD318622199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.mm in Sources */,
     28553                                413E007C1DB0E70A002341D2 /* MemoryReleaseCocoa.mm in Sources */,
    2854328554                                CDE595951BF16DF300A1CBE8 /* CDMSessionAVContentKeySession.mm in Sources */,
    2854428555                                CDDE02ED18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.mm in Sources */,
     
    3027530286                                07FFDE68181AED420072D409 /* MediaStreamTrackPrivate.cpp in Sources */,
    3027630287                                CD641EBF1819B36000EE4C41 /* MediaTimeAVFoundation.cpp in Sources */,
     30288                                413E007A1DB0E4F9002341D2 /* MemoryRelease.cpp in Sources */,
    3027730289                                CD60C0C6193E87C7003C656B /* MediaTimeQTKit.mm in Sources */,
    3027830290                                0705853A17FE0770005F2BCB /* MediaTrackConstraint.cpp in Sources */,
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r208329 r208534  
    8686#include "MainFrame.h"
    8787#include "MemoryCache.h"
     88#include "MemoryRelease.h"
    8889#include "Page.h"
    8990#include "PageCache.h"
     
    134135#if PLATFORM(IOS)
    135136#include "DocumentType.h"
    136 #include "MemoryPressureHandler.h"
    137137#include "ResourceLoader.h"
    138138#include "RuntimeApplicationChecks.h"
     
    17761776        PageCache::singleton().addIfCacheable(*history().currentItem(), m_frame.page());
    17771777       
    1778         MemoryPressureHandler::singleton().jettisonExpensiveObjectsOnTopLevelNavigation();
     1778        WebCore::jettisonExpensiveObjectsOnTopLevelNavigation();
    17791779    }
    17801780
  • trunk/Source/WebCore/platform/MemoryPressureHandler.cpp

    r207339 r208534  
    2727#include "MemoryPressureHandler.h"
    2828
    29 #include "CSSValuePool.h"
    30 #include "Chrome.h"
    31 #include "ChromeClient.h"
    32 #include "Document.h"
    33 #include "FontCache.h"
    34 #include "GCController.h"
    35 #include "HTMLMediaElement.h"
    36 #include "InlineStyleSheetOwner.h"
    37 #include "InspectorInstrumentation.h"
    3829#include "Logging.h"
    39 #include "MemoryCache.h"
    40 #include "Page.h"
    41 #include "PageCache.h"
    42 #include "ScrollingThread.h"
    43 #include "StyleScope.h"
    44 #include "StyledElement.h"
    45 #include "WorkerThread.h"
    46 #include <JavaScriptCore/IncrementalSweeper.h>
    47 #include <chrono>
    48 #include <wtf/CurrentTime.h>
    49 #include <wtf/FastMalloc.h>
    50 #include <wtf/StdLibExtras.h>
    5130
    5231namespace WebCore {
     
    6039}
    6140
    62 MemoryPressureHandler::MemoryPressureHandler()
    63     : m_installed(false)
    64     , m_lastRespondTime(0)
    65     , m_lowMemoryHandler([this] (Critical critical, Synchronous synchronous) { releaseMemory(critical, synchronous); })
    66     , m_underMemoryPressure(false)
    67 #if PLATFORM(IOS)
    68     // FIXME: Can we share more of this with OpenSource?
    69     , m_memoryPressureReason(MemoryPressureReasonNone)
    70     , m_clearPressureOnMemoryRelease(true)
    71     , m_releaseMemoryBlock(0)
    72     , m_observer(0)
    73 #elif OS(LINUX)
    74     , m_holdOffTimer(RunLoop::main(), this, &MemoryPressureHandler::holdOffTimerFired)
     41MemoryPressureHandler::MemoryPressureHandler()
     42#if OS(LINUX)
     43    : m_holdOffTimer(RunLoop::main(), this, &MemoryPressureHandler::holdOffTimerFired)
    7544#endif
    7645{
    77     platformInitialize();
    78 }
    79 
    80 void MemoryPressureHandler::releaseNoncriticalMemory()
    81 {
    82     {
    83         ReliefLogger log("Purge inactive FontData");
    84         FontCache::singleton().purgeInactiveFontData();
    85     }
    86 
    87     {
    88         ReliefLogger log("Clear WidthCaches");
    89         clearWidthCaches();
    90     }
    91 
    92     {
    93         ReliefLogger log("Discard Selector Query Cache");
    94         for (auto* document : Document::allDocuments())
    95             document->clearSelectorQueryCache();
    96     }
    97 
    98     {
    99         ReliefLogger log("Prune MemoryCache dead resources");
    100         MemoryCache::singleton().pruneDeadResourcesToSize(0);
    101     }
    102 
    103     {
    104         ReliefLogger log("Prune presentation attribute cache");
    105         StyledElement::clearPresentationAttributeCache();
    106     }
    107 
    108     {
    109         ReliefLogger log("Clear inline stylesheet cache");
    110         InlineStyleSheetOwner::clearCache();
    111     }
    112 }
    113 
    114 void MemoryPressureHandler::releaseCriticalMemory(Synchronous synchronous)
    115 {
    116     {
    117         ReliefLogger log("Empty the PageCache");
    118         // Right now, the only reason we call release critical memory while not under memory pressure is if the process is about to be suspended.
    119         PruningReason pruningReason = isUnderMemoryPressure() ? PruningReason::MemoryPressure : PruningReason::ProcessSuspended;
    120         PageCache::singleton().pruneToSizeNow(0, pruningReason);
    121     }
    122 
    123     {
    124         ReliefLogger log("Prune MemoryCache live resources");
    125         MemoryCache::singleton().pruneLiveResourcesToSize(0, /*shouldDestroyDecodedDataForAllLiveResources*/ true);
    126     }
    127 
    128     {
    129         ReliefLogger log("Drain CSSValuePool");
    130         CSSValuePool::singleton().drain();
    131     }
    132 
    133     {
    134         ReliefLogger log("Discard StyleResolvers");
    135         Vector<RefPtr<Document>> documents;
    136         copyToVector(Document::allDocuments(), documents);
    137         for (auto& document : documents)
    138             document->styleScope().clearResolver();
    139     }
    140 
    141     {
    142         ReliefLogger log("Discard all JIT-compiled code");
    143         GCController::singleton().deleteAllCode();
    144     }
    145 
    146 #if ENABLE(VIDEO)
    147     {
    148         ReliefLogger log("Dropping buffered data from paused media elements");
    149         for (auto* mediaElement: HTMLMediaElement::allMediaElements()) {
    150             if (mediaElement->paused())
    151                 mediaElement->purgeBufferedDataIfPossible();
    152         }
    153     }
    154 #endif
    155 
    156     if (synchronous == Synchronous::Yes) {
    157         ReliefLogger log("Collecting JavaScript garbage");
    158         GCController::singleton().garbageCollectNow();
    159     } else
    160         GCController::singleton().garbageCollectNowIfNotDoneRecently();
    161 
    162     // We reduce tiling coverage while under memory pressure, so make sure to drop excess tiles ASAP.
    163     Page::forEachPage([](Page& page) {
    164         page.chrome().client().scheduleCompositingLayerFlush();
    165     });
    166 }
    167 
    168 void MemoryPressureHandler::jettisonExpensiveObjectsOnTopLevelNavigation()
    169 {
    170 #if PLATFORM(IOS)
    171     // Protect against doing excessive jettisoning during repeated navigations.
    172     const auto minimumTimeSinceNavigation = 2s;
    173 
    174     static auto timeOfLastNavigation = std::chrono::steady_clock::now();
    175     auto now = std::chrono::steady_clock::now();
    176     bool shouldJettison = now - timeOfLastNavigation >= minimumTimeSinceNavigation;
    177     timeOfLastNavigation = now;
    178 
    179     if (!shouldJettison)
    180         return;
    181 
    182     // Throw away linked JS code. Linked code is tied to a global object and is not reusable.
    183     // The immediate memory savings outweigh the cost of recompilation in case we go back again.
    184     GCController::singleton().deleteAllLinkedCode();
    185 #endif
    18646}
    18747
     
    18949{
    19050    m_isSimulatingMemoryPressure = true;
    191     MemoryPressureHandler::singleton().respondToMemoryPressure(Critical::Yes, Synchronous::Yes);
     51    respondToMemoryPressure(Critical::Yes, Synchronous::Yes);
    19252}
    19353
     
    19959void MemoryPressureHandler::releaseMemory(Critical critical, Synchronous synchronous)
    20060{
    201     if (critical == Critical::Yes)
    202         releaseCriticalMemory(synchronous);
     61    if (!m_lowMemoryHandler)
     62        return;
    20363
    204     releaseNoncriticalMemory();
    205 
     64    m_lowMemoryHandler(critical, synchronous);
    20665    platformReleaseMemory(critical);
    207 
    208     {
    209         ReliefLogger log("Release free FastMalloc memory");
    210         // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself.
    211         WorkerThread::releaseFastMallocFreeMemoryInAllThreads();
    212 #if ENABLE(ASYNC_SCROLLING) && !PLATFORM(IOS)
    213         ScrollingThread::dispatch([]() {
    214             WTF::releaseFastMallocFreeMemory();
    215         });
    216 #endif
    217         WTF::releaseFastMallocFreeMemory();
    218     }
    219 
    220 #if ENABLE(RESOURCE_USAGE)
    221     Page::forEachPage([&](Page& page) {
    222         InspectorInstrumentation::didHandleMemoryPressure(page, critical);
    223     });
    224 #endif
    22566}
    22667
     
    25091}
    25192
    252 #if !PLATFORM(COCOA)
    253 void MemoryPressureHandler::platformInitialize() { }
    254 #endif
    255 
    25693#if !PLATFORM(COCOA) && !OS(LINUX) && !PLATFORM(WIN)
    25794void MemoryPressureHandler::install() { }
  • trunk/Source/WebCore/platform/MemoryPressureHandler.h

    r204472 r208534  
    3333#include <wtf/FastMalloc.h>
    3434#include <wtf/Forward.h>
     35#include <wtf/NeverDestroyed.h>
    3536
    3637#if PLATFORM(IOS)
     
    6768    WEBCORE_EXPORT void install();
    6869
    69     void setLowMemoryHandler(LowMemoryHandler handler)
     70    void setLowMemoryHandler(LowMemoryHandler&& handler)
    7071    {
    7172        ASSERT(!m_installed);
    72         m_lowMemoryHandler = handler;
     73        m_lowMemoryHandler = WTFMove(handler);
    7374    }
    74 
    75     void jettisonExpensiveObjectsOnTopLevelNavigation();
    7675
    7776    bool isUnderMemoryPressure() const { return m_underMemoryPressure || m_isSimulatingMemoryPressure; }
     
    131130
    132131private:
    133     void platformInitialize();
    134     void releaseNoncriticalMemory();
    135     void releaseCriticalMemory(Synchronous);
    136 
    137132    void uninstall();
    138133
     
    165160#endif
    166161
    167     bool m_installed;
    168     time_t m_lastRespondTime;
     162    bool m_installed { false };
     163    time_t m_lastRespondTime { 0 };
    169164    LowMemoryHandler m_lowMemoryHandler;
    170165
     
    173168
    174169#if PLATFORM(IOS)
    175     uint32_t m_memoryPressureReason;
    176     bool m_clearPressureOnMemoryRelease;
    177     void (^m_releaseMemoryBlock)();
    178     CFRunLoopObserverRef m_observer;
     170    // FIXME: Can we share more of this with OpenSource?
     171    uint32_t m_memoryPressureReason { MemoryPressureReasonNone };
     172    bool m_clearPressureOnMemoryRelease { true };
     173    void (^m_releaseMemoryBlock)() { nullptr };
     174    CFRunLoopObserverRef m_observer { nullptr };
    179175    Lock m_observerMutex;
    180176#elif OS(LINUX)
  • trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm

    r203379 r208534  
    2727#import "MemoryPressureHandler.h"
    2828
    29 #import "GCController.h"
    30 #import "IOSurfacePool.h"
    31 #import "LayerPool.h"
    3229#import "Logging.h"
    33 #import "ResourceUsageThread.h"
    3430#import <mach/mach.h>
    3531#import <mach/task_info.h>
    3632#import <malloc/malloc.h>
    3733#import <notify.h>
     34#import <wtf/CurrentTime.h>
    3835
    3936#if PLATFORM(IOS)
     
    4542
    4643extern "C" void cache_simulate_memory_warning_event(uint64_t);
    47 extern "C" void _sqlite3_purgeEligiblePagerCacheMemory(void);
    4844
    4945namespace WebCore {
    5046
    51 void MemoryPressureHandler::platformInitialize()
    52 {
    53     int dummy;
    54     notify_register_dispatch("com.apple.WebKit.fullGC", &dummy, dispatch_get_main_queue(), ^(int) {
    55         GCController::singleton().garbageCollectNow();
    56     });
    57     notify_register_dispatch("com.apple.WebKit.deleteAllCode", &dummy, dispatch_get_main_queue(), ^(int) {
    58         GCController::singleton().deleteAllCode();
    59         GCController::singleton().garbageCollectNow();
    60     });
    61 }
    62 
    6347void MemoryPressureHandler::platformReleaseMemory(Critical critical)
    6448{
    65     {
    66         ReliefLogger log("Purging SQLite caches");
    67         _sqlite3_purgeEligiblePagerCacheMemory();
    68     }
    69 
    70     {
    71         ReliefLogger log("Drain LayerPools");
    72         for (auto& pool : LayerPool::allLayerPools())
    73             pool->drain();
    74     }
    75 #if USE(IOSURFACE)
    76     {
    77         ReliefLogger log("Drain IOSurfacePool");
    78         IOSurfacePool::sharedPool().discardAllSurfaces();
    79     }
    80 #endif
    81 
    8249    if (critical == Critical::Yes && (!isUnderMemoryPressure() || m_isSimulatingMemoryPressure)) {
    8350        // libcache listens to OS memory notifications, but for process suspension
     
    212179#endif
    213180
    214     m_lowMemoryHandler(critical, synchronous);
     181    releaseMemory(critical, synchronous);
    215182
    216183#if !PLATFORM(IOS)
  • trunk/Source/WebCore/platform/linux/MemoryPressureHandlerLinux.cpp

    r203342 r208534  
    299299
    300300    double startTime = monotonicallyIncreasingTime();
    301     m_lowMemoryHandler(critical, synchronous);
     301    releaseMemory(critical, synchronous);
    302302    unsigned holdOffTime = (monotonicallyIncreasingTime() - startTime) * s_holdOffMultiplier;
    303303    holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
  • trunk/Source/WebCore/platform/win/MemoryPressureHandlerWin.cpp

    r197728 r208534  
    121121    uninstall();
    122122
    123     m_lowMemoryHandler(critical, synchronous);
     123    releaseMemory(critical, synchronous);
    124124}
    125125
  • trunk/Source/WebKit/mac/ChangeLog

    r208527 r208534  
     12016-10-14  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        MemoryPressureHandler shouldn't know how to release WebCore memory
     4        https://bugs.webkit.org/show_bug.cgi?id=160497
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Set the low memory handler before installing the memory pressure handler.
     9
     10        * WebView/WebView.mm:
     11        (-[WebView _commonInitializationWithFrameName:groupName:]):
     12
    1132016-11-09  Ryosuke Niwa  <rniwa@webkit.org>
    214
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r208509 r208534  
    162162#import <WebCore/MainFrame.h>
    163163#import <WebCore/MemoryCache.h>
    164 #import <WebCore/MemoryPressureHandler.h>
     164#import <WebCore/MemoryRelease.h>
    165165#import <WebCore/NSSpellCheckerSPI.h>
    166166#import <WebCore/NSTouchBarSPI.h>
     
    14311431#endif
    14321432
    1433     if (![[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitSuppressMemoryPressureHandler"])
    1434         MemoryPressureHandler::singleton().install();
     1433    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitSuppressMemoryPressureHandler"]) {
     1434        WebCore::registerMemoryReleaseNotifyCallbacks();
     1435
     1436        static std::once_flag onceFlag;
     1437        std::call_once(onceFlag, [] {
     1438            auto& memoryPressureHandler = MemoryPressureHandler::singleton();
     1439            memoryPressureHandler.setLowMemoryHandler([] (Critical critical, Synchronous synchronous) {
     1440                WebCore::releaseMemory(critical, synchronous);
     1441            });
     1442            memoryPressureHandler.install();
     1443        });
     1444    }
    14351445
    14361446    if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION)) {
  • trunk/Source/WebKit/win/ChangeLog

    r208505 r208534  
     12016-10-14  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        MemoryPressureHandler shouldn't know how to release WebCore memory
     4        https://bugs.webkit.org/show_bug.cgi?id=160497
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Set the low memory handler before installing the memory pressure handler.
     9
     10        * WebView.cpp:
     11        (WebView::initWithFrame):
     12
    1132016-11-09  Alex Christensen  <achristensen@webkit.org>
    214
  • trunk/Source/WebKit/win/WebView.cpp

    r208479 r208534  
    128128#include <WebCore/MainFrame.h>
    129129#include <WebCore/MemoryCache.h>
    130 #include <WebCore/MemoryPressureHandler.h>
     130#include <WebCore/MemoryRelease.h>
    131131#include <WebCore/NotImplemented.h>
    132132#include <WebCore/Page.h>
     
    30853085        WebKitInitializeWebDatabasesIfNecessary();
    30863086
    3087         MemoryPressureHandler::singleton().install();
     3087        auto& memoryPressureHandler = MemoryPressureHandler::singleton();
     3088        memoryPressureHandler.setLowMemoryHandler([] (Critical critical, Synchronous synchronous) {
     3089            WebCore::releaseMemory(critical, synchronous);
     3090        });
     3091        memoryPressureHandler.install();
    30883092
    30893093        didOneTimeInitialization = true;
  • trunk/Source/WebKit2/ChangeLog

    r208532 r208534  
     12016-10-14  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        MemoryPressureHandler shouldn't know how to release WebCore memory
     4        https://bugs.webkit.org/show_bug.cgi?id=160497
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Set the low memory handler before installing the memory pressure handler.
     9
     10        * WebProcess/WebProcess.cpp:
     11        (WebKit::WebProcess::initializeWebProcess):
     12        * WebProcess/cocoa/WebProcessCocoa.mm:
     13        (WebKit::WebProcess::platformInitializeWebProcess):
     14
    1152016-10-27  Sergio Villar Senin  <svillar@igalia.com>
    216
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r208307 r208534  
    8989#include <WebCore/MainFrame.h>
    9090#include <WebCore/MemoryCache.h>
    91 #include <WebCore/MemoryPressureHandler.h>
     91#include <WebCore/MemoryRelease.h>
    9292#include <WebCore/NetworkStorageSession.h>
    9393#include <WebCore/Page.h>
     
    274274
    275275    m_suppressMemoryPressureHandler = parameters.shouldSuppressMemoryPressureHandler;
    276     if (!m_suppressMemoryPressureHandler)
    277         MemoryPressureHandler::singleton().install();
     276    if (!m_suppressMemoryPressureHandler) {
     277        auto& memoryPressureHandler = MemoryPressureHandler::singleton();
     278        memoryPressureHandler.setLowMemoryHandler([] (Critical critical, Synchronous synchronous) {
     279            WebCore::releaseMemory(critical, synchronous);
     280        });
     281        memoryPressureHandler.install();
     282    }
    278283
    279284    if (!parameters.injectedBundlePath.isEmpty())
  • trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm

    r207769 r208534  
    5050#import <WebCore/FontCascade.h>
    5151#import <WebCore/LocalizedStrings.h>
    52 #import <WebCore/MemoryPressureHandler.h>
     52#import <WebCore/MemoryRelease.h>
    5353#import <WebCore/NSAccessibilitySPI.h>
    5454#import <WebCore/RuntimeApplicationChecks.h>
     
    121121    m_presenterApplicationPid = parameters.presenterApplicationPid;
    122122
     123    WebCore::registerMemoryReleaseNotifyCallbacks();
    123124    MemoryPressureHandler::ReliefLogger::setLoggingEnabled(parameters.shouldEnableMemoryPressureReliefLogging);
    124125
Note: See TracChangeset for help on using the changeset viewer.