Title: [280987] branches/safari-612.1.27.0-branch/Source/WebKit
Revision
280987
Author
[email protected]
Date
2021-08-12 15:24:55 -0700 (Thu, 12 Aug 2021)

Log Message

Cherry-pick r280981. rdar://problem/81870941

    [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.
    2. 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:

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

Modified Paths

Diff

Modified: branches/safari-612.1.27.0-branch/Source/WebKit/ChangeLog (280986 => 280987)


--- branches/safari-612.1.27.0-branch/Source/WebKit/ChangeLog	2021-08-12 21:13:45 UTC (rev 280986)
+++ branches/safari-612.1.27.0-branch/Source/WebKit/ChangeLog	2021-08-12 22:24:55 UTC (rev 280987)
@@ -1,5 +1,142 @@
 2021-08-12  Alan Coon  <[email protected]>
 
+        Cherry-pick r280981. rdar://problem/81870941
+
+    [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.
+    2. 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:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280981 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-08-12  Said Abou-Hallawa  <[email protected]>
+
+            [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.
+            2. 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:
+
+2021-08-12  Alan Coon  <[email protected]>
+
         Cherry-pick r280776. rdar://problem/81861548
 
     [Cocoa|GPU] platformLayer() not always added to remotedly hosted context; black video while playing

Modified: branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h (280986 => 280987)


--- branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h	2021-08-12 21:13:45 UTC (rev 280986)
+++ branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h	2021-08-12 22:24:55 UTC (rev 280987)
@@ -65,7 +65,7 @@
 
     ~RemoteImageBufferProxy()
     {
-        if (!m_remoteRenderingBackendProxy) {
+        if (!m_remoteRenderingBackendProxy || m_remoteRenderingBackendProxy->isGPUProcessConnectionClosed()) {
             clearDisplayList();
             return;
         }

Modified: branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h (280986 => 280987)


--- branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2021-08-12 21:13:45 UTC (rev 280986)
+++ branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2021-08-12 22:24:55 UTC (rev 280987)
@@ -122,6 +122,8 @@
 
     RenderingBackendIdentifier ensureBackendCreated();
 
+    bool isGPUProcessConnectionClosed() const { return !m_gpuProcessConnection; }
+
 private:
     explicit RemoteRenderingBackendProxy(WebPage&);
 

Modified: branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp (280986 => 280987)


--- branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp	2021-08-12 21:13:45 UTC (rev 280986)
+++ branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp	2021-08-12 22:24:55 UTC (rev 280987)
@@ -164,10 +164,14 @@
     m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
 }
 
-void RemoteResourceCacheProxy::clearFontMap()
+void RemoteResourceCacheProxy::releaseAllRemoteFonts()
 {
     for (auto& fontState : m_fonts)
         m_remoteRenderingBackendProxy.releaseRemoteResource(fontState.key, fontState.value.useCount);
+}
+
+void RemoteResourceCacheProxy::clearFontMap()
+{
     m_fonts.clear();
     m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
 }
@@ -203,19 +207,28 @@
 
 void RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed()
 {
-    for (auto& item : m_imageBuffers.values()) {
+    clearNativeImageMap();
+    clearFontMap();
+
+    // Get a copy of m_imageBuffers.values() because clearBackend()
+    // may release some of the cached ImageBuffers.
+    for (auto& item : copyToVector(m_imageBuffers.values())) {
         if (!item.imageBuffer)
             continue;
-        m_remoteRenderingBackendProxy.createRemoteImageBuffer(*item.imageBuffer);
         item.useCount = 0;
         item.imageBuffer->clearBackend();
     }
-    clearNativeImageMap();
-    clearFontMap();
+
+    for (auto& item : m_imageBuffers.values()) {
+        if (!item.imageBuffer)
+            continue;
+        m_remoteRenderingBackendProxy.createRemoteImageBuffer(*item.imageBuffer);
+    }
 }
 
 void RemoteResourceCacheProxy::releaseMemory()
 {
+    releaseAllRemoteFonts();
     clearFontMap();
     m_remoteRenderingBackendProxy.deleteAllFonts();
 }

Modified: branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h (280986 => 280987)


--- branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h	2021-08-12 21:13:45 UTC (rev 280986)
+++ branches/safari-612.1.27.0-branch/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h	2021-08-12 22:24:55 UTC (rev 280987)
@@ -57,6 +57,7 @@
     void finalizeRenderingUpdate();
 
     void remoteResourceCacheWasDestroyed();
+    void releaseAllRemoteFonts();
     void releaseMemory();
 
 private:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to