⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280981 in webkit


Ignore:
Timestamp:
Aug 12, 2021, 1:28:00 PM (5 years ago)
Author:
Said Abou-Hallawa
Message:

[GPU Process] REGRESSION: WebContent often crashes when using iCloud photos
https://bugs.webkit.org/show_bug.cgi?id=228969
<rdar://81761078>

Reviewed by Simon Fraser.

Terminating the GPUProcess is very stressful situation which has to be
handled carefully. The side effect of each function which is called through
gpuProcessConnectionDidClose() has to be understood to get the right
sequence of calls. There are problems in releasing all kinds of resources.

  • Releasing NativeImage: Calling clearNativeImageMap() after clearing the

backend of the ImageBuffers was causing a problem. When clearing the
backend of an ImageBuffer, it will clear its DisplayList which may have
the last reference to a NativeImage. The destructor of NativeImage calls
releaseRemoteResource() before it is removed from the the NativeImageMap.
This will send a message to the relaunched GPUP to release a NativeImage
which is not in its cache.

  • Releasing Font: clearFontMap() was always calling releaseRemoteResource()

even if it is called form remoteResourceCacheWasDestroyed(). This should
not happen because the connection with GPUProcess has been closed.

  • Releasing ImageBuffer: This happen when a DisplayList of an ImageBuffer

'A' holds the last reference to another ImageBuffer 'B' and we call
clearBackend() for 'A'. clearBackend() will clear the DisplayList of 'A'
and causes the deletion of 'B'. In this case we should not call
releaseImageBuffer() for 'B' because the GPUPProcess is closed.

  • WebProcess/GPU/graphics/RemoteImageBufferProxy.h:

(WebKit::RemoteImageBufferProxy::~RemoteImageBufferProxy):
If the ImageBuffer is being released because of the clean-up we do when
the GPUProcess is terminated, we should not release the corresponding
RemoteImageBuffer since it is already gone.

  • WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:

(WebKit::RemoteRenderingBackendProxy::isGPUProcessConnectionClosed const):
This will return true if we are deleting a RemoteImageBufferProxy through
RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed().

  • WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:

(WebKit::RemoteResourceCacheProxy::releaseAllRemoteFonts):
This function will be used to release the remote fonts. It should be called
from RemoteResourceCacheProxy::releaseMemory() where we sure the GPUP is
alive and all the fonts are cached there.

(WebKit::RemoteResourceCacheProxy::clearFontMap):
The part of releasing the remote fonts was moved from this function to
releaseAllRemoteFonts().

(WebKit::RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed):

  1. Clearing the NativeImages and the Fonts has to come before clearing

the backends of the ImageBuffers. The reason is clearBackend() clears the
DisplayList which may release the last reference of a NativeImage or Font.
We want to detach the NativeImages and the Fonts from the cache before then.

  1. We should have two different loops: one for clearing the backends of

the ImageBuffers and another one for recreating these backends. The reason
for this is clearBackend() clears the DisplayList which may release the
last reference of a another source RemoteImageBufferProxy used by a
DrawImageBuffer item for example.

(WebKit::RemoteResourceCacheProxy::releaseMemory):

  • WebProcess/GPU/graphics/RemoteResourceCacheProxy.h:
Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r280980 r280981  
     12021-08-12  Said Abou-Hallawa  <said@apple.com>
     2
     3        [GPU Process] REGRESSION: WebContent often crashes when using iCloud photos
     4        https://bugs.webkit.org/show_bug.cgi?id=228969
     5        <rdar://81761078>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Terminating the GPUProcess is very stressful situation which has to be
     10        handled carefully. The side effect of each function which is called through
     11        gpuProcessConnectionDidClose() has to be understood to get the right
     12        sequence of calls. There are problems in releasing all kinds of resources.
     13
     14        - Releasing NativeImage: Calling clearNativeImageMap() after clearing the
     15        backend of the ImageBuffers was causing a problem. When clearing the
     16        backend of an ImageBuffer, it will clear its DisplayList which may have
     17        the last reference to a NativeImage. The destructor of NativeImage calls
     18        releaseRemoteResource() before it is removed from the the NativeImageMap.
     19        This will send a message to the relaunched GPUP to release a NativeImage
     20        which is not in its cache.
     21
     22        - Releasing Font: clearFontMap() was always calling releaseRemoteResource()
     23        even if it is called form  remoteResourceCacheWasDestroyed(). This should
     24        not happen because the connection with GPUProcess has been closed.
     25
     26        - Releasing ImageBuffer: This happen when a DisplayList of an ImageBuffer
     27        'A' holds the last reference to another ImageBuffer 'B' and we call
     28        clearBackend() for 'A'. clearBackend() will clear the DisplayList of 'A'
     29        and causes the deletion of 'B'. In this case we should not call
     30        releaseImageBuffer() for 'B' because the GPUPProcess is closed.
     31
     32        * WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
     33        (WebKit::RemoteImageBufferProxy::~RemoteImageBufferProxy):
     34        If the ImageBuffer is being released because of the clean-up we do when
     35        the GPUProcess is terminated, we should not release the corresponding
     36        RemoteImageBuffer since it is already gone.
     37
     38        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
     39        (WebKit::RemoteRenderingBackendProxy::isGPUProcessConnectionClosed const):
     40        This will return true if we are deleting a RemoteImageBufferProxy through
     41        RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed().
     42
     43        * WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:
     44        (WebKit::RemoteResourceCacheProxy::releaseAllRemoteFonts):
     45        This function will be used to release the remote fonts. It should be called
     46        from RemoteResourceCacheProxy::releaseMemory() where we sure the GPUP is
     47        alive and all the fonts are cached there.
     48
     49        (WebKit::RemoteResourceCacheProxy::clearFontMap):
     50        The part of releasing the remote fonts was moved from this function to
     51        releaseAllRemoteFonts().
     52
     53        (WebKit::RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed):
     54        1. Clearing the NativeImages and the Fonts has to come before clearing
     55        the backends of the ImageBuffers. The reason is clearBackend() clears the
     56        DisplayList which may release the last reference of a NativeImage or Font.
     57        We want to detach the NativeImages and the Fonts from the cache before then.
     58        2. We should have two different loops: one for clearing the backends of
     59        the ImageBuffers and another one for recreating these backends. The reason
     60        for this is clearBackend() clears the DisplayList which may release the
     61        last reference of a another source RemoteImageBufferProxy used by a
     62        DrawImageBuffer item for example.
     63
     64        (WebKit::RemoteResourceCacheProxy::releaseMemory):
     65        * WebProcess/GPU/graphics/RemoteResourceCacheProxy.h:
     66
    1672021-08-12  Sam Weinig  <weinig@apple.com>
    268
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h

    r280652 r280981  
    6666    ~RemoteImageBufferProxy()
    6767    {
    68         if (!m_remoteRenderingBackendProxy) {
     68        if (!m_remoteRenderingBackendProxy || m_remoteRenderingBackendProxy->isGPUProcessConnectionClosed()) {
    6969            clearDisplayList();
    7070            return;
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h

    r280337 r280981  
    123123    RenderingBackendIdentifier ensureBackendCreated();
    124124
     125    bool isGPUProcessConnectionClosed() const { return !m_gpuProcessConnection; }
     126
    125127private:
    126128    explicit RemoteRenderingBackendProxy(WebPage&);
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp

    r280639 r280981  
    165165}
    166166
    167 void RemoteResourceCacheProxy::clearFontMap()
     167void RemoteResourceCacheProxy::releaseAllRemoteFonts()
    168168{
    169169    for (auto& fontState : m_fonts)
    170170        m_remoteRenderingBackendProxy.releaseRemoteResource(fontState.key, fontState.value.useCount);
     171}
     172
     173void RemoteResourceCacheProxy::clearFontMap()
     174{
    171175    m_fonts.clear();
    172176    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
     
    204208void RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed()
    205209{
     210    clearNativeImageMap();
     211    clearFontMap();
     212
     213    // Get a copy of m_imageBuffers.values() because clearBackend()
     214    // may release some of the cached ImageBuffers.
     215    for (auto& item : copyToVector(m_imageBuffers.values())) {
     216        if (!item.imageBuffer)
     217            continue;
     218        item.useCount = 0;
     219        item.imageBuffer->clearBackend();
     220    }
     221
    206222    for (auto& item : m_imageBuffers.values()) {
    207223        if (!item.imageBuffer)
    208224            continue;
    209225        m_remoteRenderingBackendProxy.createRemoteImageBuffer(*item.imageBuffer);
    210         item.useCount = 0;
    211         item.imageBuffer->clearBackend();
    212     }
    213     clearNativeImageMap();
    214     clearFontMap();
     226    }
    215227}
    216228
    217229void RemoteResourceCacheProxy::releaseMemory()
    218230{
     231    releaseAllRemoteFonts();
    219232    clearFontMap();
    220233    m_remoteRenderingBackendProxy.deleteAllFonts();
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h

    r280639 r280981  
    5858
    5959    void remoteResourceCacheWasDestroyed();
     60    void releaseAllRemoteFonts();
    6061    void releaseMemory();
    6162
Note: See TracChangeset for help on using the changeset viewer.