Changeset 142212 in webkit


Ignore:
Timestamp:
Feb 7, 2013 5:22:05 PM (11 years ago)
Author:
barraclough@apple.com
Message:

PluginProcess should quit immediately if idle in response to low-memory notifications
https://bugs.webkit.org/show_bug.cgi?id=109103
<rdar://problem/12679827>

Reviewed by Darin Adler.

Source/WebCore:

This patch allows a process to set a custom callback for low memory warnings
(defaulting to the current behaviour, as implemented in releaseMemory).

MemoryPressureHandler::install is currently used for two purposes - it is
called when first initializing a low memory handler for a process, and also
used to reinstall the handler (on a delay) after the notification has occured.
Since reinstallation doesn't change the callback, split these behaviours out -
MemoryPressureHandler::initialize is added to initialization, and accepts a
custom callback, install in made private.

  • WebCore.exp.in:
    • Added export for releaseMemory.
  • platform/MemoryPressureHandler.cpp:

(WebCore::MemoryPressureHandler::releaseMemory):

  • Added null implementation for non-Mac builds.
  • platform/MemoryPressureHandler.h:

(WebCore::MemoryPressureHandler::initialize):

  • distinguish initialization from reinstallations, allow handler to be set.

(MemoryPressureHandler):

  • Added m_lowMemoryHandler function pointer member variable.
  • platform/mac/MemoryPressureHandlerMac.mm:

(WebCore::MemoryPressureHandler::respondToMemoryPressure):

  • Call m_lowMemoryHandler instead of releaseMemory.

Source/WebKit/mac:

  • WebView/WebView.mm:

(-[WebView _commonInitializationWithFrameName:groupName:]):

  • MemoryPressureHandler::install is now called via MemoryPressureHandler::initialize.

(WebInstallMemoryPressureHandler):

  • MemoryPressureHandler::install is now called via MemoryPressureHandler::initialize.

Source/WebKit2:

PluginProcess now initializes a MemoryPressureHandler for the process, providing
a custom callback which will call terminate if appropriate (if the plugin is not
currently in use).

  • PluginProcess/PluginProcess.cpp:

(WebKit::PluginProcess::lowMemoryHandler):

  • Custom callback to terminate if appropriate.

(WebKit::PluginProcess::initializeProcess):

  • Initialize the MemoryPressureHandler.

(WebKit::PluginProcess::shouldTerminate):

  • This method now also needs to be callable in situations where it might return false.
  • PluginProcess/PluginProcess.h:

(PluginProcess):

  • Added declaration for lowMemoryHandler.
  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::initializeWebProcess):

  • MemoryPressureHandler::install is now called via MemoryPressureHandler::initialize.
Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142209 r142212  
     12013-02-06  Gavin Barraclough  <barraclough@apple.com>
     2
     3        PluginProcess should quit immediately if idle in response to low-memory notifications
     4        https://bugs.webkit.org/show_bug.cgi?id=109103
     5        <rdar://problem/12679827>
     6
     7        Reviewed by Darin Adler.
     8
     9        This patch allows a process to set a custom callback for low memory warnings
     10        (defaulting to the current behaviour, as implemented in releaseMemory).
     11
     12        MemoryPressureHandler::install is currently used for two purposes - it is
     13        called when first initializing a low memory handler for a process, and also
     14        used to reinstall the handler (on a delay) after the notification has occured.
     15        Since reinstallation doesn't change the callback, split these behaviours out -
     16        MemoryPressureHandler::initialize is added to initialization, and accepts a
     17        custom callback, install in made private.
     18
     19        * WebCore.exp.in:
     20            - Added export for releaseMemory.
     21        * platform/MemoryPressureHandler.cpp:
     22        (WebCore::MemoryPressureHandler::releaseMemory):
     23            - Added null implementation for non-Mac builds.
     24        * platform/MemoryPressureHandler.h:
     25        (WebCore::MemoryPressureHandler::initialize):
     26            - distinguish initialization from reinstallations, allow handler to be set.
     27        (MemoryPressureHandler):
     28            - Added m_lowMemoryHandler function pointer member variable.
     29        * platform/mac/MemoryPressureHandlerMac.mm:
     30        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
     31            - Call m_lowMemoryHandler instead of releaseMemory.
     32
    1332013-02-07  Kentaro Hara  <haraken@chromium.org>
    234
  • trunk/Source/WebCore/WebCore.exp.in

    r142189 r142212  
    601601__ZN7WebCore20SpaceSplitStringDataD1Ev
    602602__ZN7WebCore21BackForwardController11itemAtIndexEi
     603__ZN7WebCore21MemoryPressureHandler13releaseMemoryEb
    603604__ZN7WebCore21MemoryPressureHandler7installEv
    604605__ZN7WebCore21NetworkStorageSession28createPrivateBrowsingSessionERKN3WTF6StringE
  • trunk/Source/WebCore/platform/MemoryPressureHandler.cpp

    r122670 r142212  
    4444
    4545#if !PLATFORM(MAC) || PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED == 1060
     46
    4647void MemoryPressureHandler::install() { }
     48void MemoryPressureHandler::uninstall() { }
     49void MemoryPressureHandler::holdOff(unsigned) { }
     50void MemoryPressureHandler::respondToMemoryPressure() { }
     51void MemoryPressureHandler::releaseMemory(bool) { }
    4752
    48 void MemoryPressureHandler::uninstall() { }
    49 
    50 void MemoryPressureHandler::holdOff(unsigned) { }
    51 
    52 void MemoryPressureHandler::respondToMemoryPressure() { }
    5353#endif
    5454 
  • trunk/Source/WebCore/platform/MemoryPressureHandler.h

    r131496 r142212  
    3232namespace WebCore {
    3333
     34typedef void (*LowMemoryHandler)(bool critical);
     35
    3436class MemoryPressureHandler {
    3537    WTF_MAKE_FAST_ALLOCATED;
     
    3739    friend MemoryPressureHandler& memoryPressureHandler();
    3840
     41    void initialize(LowMemoryHandler handler = releaseMemory)
     42    {
     43        ASSERT(!m_installed);
     44        m_lowMemoryHandler = handler;
     45        install();
     46    }
     47
     48private:
    3949    void install();
    4050    void uninstall();
     
    4252    void holdOff(unsigned);
    4353
    44 private:
    4554    MemoryPressureHandler();
    4655    ~MemoryPressureHandler();
    4756
    4857    void respondToMemoryPressure();
    49     void releaseMemory(bool critical);
     58    static void releaseMemory(bool critical);
    5059
    5160    bool m_installed;
    5261    time_t m_lastRespondTime;
     62    LowMemoryHandler m_lowMemoryHandler;
    5363};
    5464 
  • trunk/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm

    r139218 r142212  
    135135    double startTime = monotonicallyIncreasingTime();
    136136
    137     releaseMemory(false);
     137    ASSERT(m_lowMemoryHandler);
     138    m_lowMemoryHandler(false);
    138139
    139140    unsigned holdOffTime = (monotonicallyIncreasingTime() - startTime) * s_holdOffMultiplier;
  • trunk/Source/WebKit/mac/ChangeLog

    r142171 r142212  
     12013-02-06  Gavin Barraclough  <barraclough@apple.com>
     2
     3        PluginProcess should quit immediately if idle in response to low-memory notifications
     4        https://bugs.webkit.org/show_bug.cgi?id=109103
     5        <rdar://problem/12679827>
     6
     7        Reviewed by Darin Adler.
     8
     9        * WebView/WebView.mm:
     10        (-[WebView _commonInitializationWithFrameName:groupName:]):
     11            - MemoryPressureHandler::install is now called via MemoryPressureHandler::initialize.
     12        (WebInstallMemoryPressureHandler):
     13            - MemoryPressureHandler::install is now called via MemoryPressureHandler::initialize.
     14
    1152013-02-07  Benjamin Poulain  <bpoulain@apple.com>
    216
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r141173 r142212  
    820820    [[self preferences] _postPreferencesChangedAPINotification];
    821821
    822     memoryPressureHandler().install();
     822    memoryPressureHandler().initialize();
    823823
    824824    if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION)) {
     
    67356735void WebInstallMemoryPressureHandler(void)
    67366736{
    6737     memoryPressureHandler().install();
     6737    memoryPressureHandler().initialize();
    67386738}
    67396739
  • trunk/Source/WebKit2/ChangeLog

    r142201 r142212  
     12013-02-06  Gavin Barraclough  <barraclough@apple.com>
     2
     3        PluginProcess should quit immediately if idle in response to low-memory notifications
     4        https://bugs.webkit.org/show_bug.cgi?id=109103
     5        <rdar://problem/12679827>
     6
     7        Reviewed by Darin Adler.
     8
     9        PluginProcess now initializes a MemoryPressureHandler for the process, providing
     10        a custom callback which will call terminate if appropriate (if the plugin is not
     11        currently in use).
     12
     13        * PluginProcess/PluginProcess.cpp:
     14        (WebKit::PluginProcess::lowMemoryHandler):
     15            - Custom callback to terminate if appropriate.
     16        (WebKit::PluginProcess::initializeProcess):
     17            - Initialize the MemoryPressureHandler.
     18        (WebKit::PluginProcess::shouldTerminate):
     19            - This method now also needs to be callable in situations where it might return false.
     20        * PluginProcess/PluginProcess.h:
     21        (PluginProcess):
     22            - Added declaration for lowMemoryHandler.
     23        * WebProcess/WebProcess.cpp:
     24        (WebKit::WebProcess::initializeWebProcess):
     25            - MemoryPressureHandler::install is now called via MemoryPressureHandler::initialize.
     26
    1272013-02-07  KwangYong Choi  <ky0.choi@samsung.com>
    228
  • trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp

    r141361 r142212  
    3737#include "PluginProcessProxyMessages.h"
    3838#include "WebProcessConnection.h"
     39#include <WebCore/MemoryPressureHandler.h>
    3940#include <WebCore/NotImplemented.h>
    4041#include <WebCore/RunLoop.h>
     
    8687}
    8788
     89void PluginProcess::lowMemoryHandler(bool)
     90{
     91    if (shared().shouldTerminate())
     92        shared().terminate();
     93}
     94
    8895void PluginProcess::initializeProcess(const ChildProcessInitializationParameters& parameters)
    8996{
    9097    m_pluginPath = parameters.extraInitializationData.get("plugin-path");
    9198    platformInitializeProcess(parameters);
     99
     100    memoryPressureHandler().initialize(lowMemoryHandler);
    92101}
    93102
     
    126135bool PluginProcess::shouldTerminate()
    127136{
    128     ASSERT(m_webProcessConnections.isEmpty());
    129 
    130     return true;
     137    return m_webProcessConnections.isEmpty();
    131138}
    132139
  • trunk/Source/WebKit2/PluginProcess/PluginProcess.h

    r141361 r142212  
    109109    mach_port_t m_compositingRenderServerPort;
    110110#endif
     111
     112    static void lowMemoryHandler(bool critical);
    111113};
    112114
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r141820 r142212  
    245245    platformInitializeWebProcess(parameters, decoder);
    246246
    247     memoryPressureHandler().install();
     247    memoryPressureHandler().initialize();
    248248
    249249    RefPtr<APIObject> injectedBundleInitializationUserData;
Note: See TracChangeset for help on using the changeset viewer.