Title: [279104] trunk/Source/WebKit
Revision
279104
Author
[email protected]
Date
2021-06-21 23:08:29 -0700 (Mon, 21 Jun 2021)

Log Message

[GPU Process] RELEASE_ASSERT in RemoteResourceCacheProxy::didFinalizeRenderingUpdate() may fire if GPUP is relaunched
https://bugs.webkit.org/show_bug.cgi?id=227229
<rdar://79147947>

Reviewed by Myles C. Maxfield.

1) Remove maximumUnusedFontCountToSkipRemoval because
   'unusedFontCount < maximumUnusedFontCountToSkipRemoval' can't be true
   since both unusedFontCount and maximumUnusedFontCountToSkipRemoval are
   unsigned and maximumUnusedFontCountToSkipRemoval is equal to zero.
   So they can only be equal and we can replace this by '!unusedFontCount'.

2) RemoteResourceCacheProxy::cacheFont() assumes if the font is cached in
   m_fontIdentifierToLastRenderingUpdateVersionMap then it is also cached
   in GPUP. We have to keep this assumption correct by removing the
   corresponding entries from m_fontIdentifierToLastRenderingUpdateVersionMap.

3) RemoteResourceCacheProxy::didFinalizeRenderingUpdate() needs to reset
   m_numberOfFontsUsedInCurrentRenderingUpdate and to increment
   m_currentRenderingUpdateVersion in all its code branches.

4) If the GPUP is relaunched, we need to set
   m_numberOfFontsUsedInCurrentRenderingUpdate to zero after we clear
   m_fontIdentifierToLastRenderingUpdateVersionMap. Otherwise the
   RELEASE_ASSERT in RemoteResourceCacheProxy::didFinalizeRenderingUpdate()
   will fire.

* WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:
(WebKit::RemoteResourceCacheProxy::prepareForNextRenderingUpdate):
(WebKit::RemoteResourceCacheProxy::clearFontMap):
(WebKit::RemoteResourceCacheProxy::didFinalizeRenderingUpdate):
(WebKit::RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed):
(WebKit::RemoteResourceCacheProxy::releaseMemory):
* WebProcess/GPU/graphics/RemoteResourceCacheProxy.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (279103 => 279104)


--- trunk/Source/WebKit/ChangeLog	2021-06-22 04:57:23 UTC (rev 279103)
+++ trunk/Source/WebKit/ChangeLog	2021-06-22 06:08:29 UTC (rev 279104)
@@ -1,3 +1,40 @@
+2021-06-21  Said Abou-Hallawa  <[email protected]>
+
+        [GPU Process] RELEASE_ASSERT in RemoteResourceCacheProxy::didFinalizeRenderingUpdate() may fire if GPUP is relaunched
+        https://bugs.webkit.org/show_bug.cgi?id=227229
+        <rdar://79147947>
+
+        Reviewed by Myles C. Maxfield.
+
+        1) Remove maximumUnusedFontCountToSkipRemoval because 
+           'unusedFontCount < maximumUnusedFontCountToSkipRemoval' can't be true
+           since both unusedFontCount and maximumUnusedFontCountToSkipRemoval are
+           unsigned and maximumUnusedFontCountToSkipRemoval is equal to zero.
+           So they can only be equal and we can replace this by '!unusedFontCount'.
+
+        2) RemoteResourceCacheProxy::cacheFont() assumes if the font is cached in
+           m_fontIdentifierToLastRenderingUpdateVersionMap then it is also cached
+           in GPUP. We have to keep this assumption correct by removing the 
+           corresponding entries from m_fontIdentifierToLastRenderingUpdateVersionMap.
+
+        3) RemoteResourceCacheProxy::didFinalizeRenderingUpdate() needs to reset
+           m_numberOfFontsUsedInCurrentRenderingUpdate and to increment 
+           m_currentRenderingUpdateVersion in all its code branches.
+
+        4) If the GPUP is relaunched, we need to set 
+           m_numberOfFontsUsedInCurrentRenderingUpdate to zero after we clear
+           m_fontIdentifierToLastRenderingUpdateVersionMap. Otherwise the
+           RELEASE_ASSERT in RemoteResourceCacheProxy::didFinalizeRenderingUpdate()
+           will fire.
+
+        * WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:
+        (WebKit::RemoteResourceCacheProxy::prepareForNextRenderingUpdate):
+        (WebKit::RemoteResourceCacheProxy::clearFontMap):
+        (WebKit::RemoteResourceCacheProxy::didFinalizeRenderingUpdate):
+        (WebKit::RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed):
+        (WebKit::RemoteResourceCacheProxy::releaseMemory):
+        * WebProcess/GPU/graphics/RemoteResourceCacheProxy.h:
+
 2021-06-21  Wenson Hsieh  <[email protected]>
 
         [macOS] [WebKitLegacy] Non-actionable "Look Up" action appears when right clicking images

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp (279103 => 279104)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp	2021-06-22 04:57:23 UTC (rev 279103)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp	2021-06-22 06:08:29 UTC (rev 279104)
@@ -105,15 +105,16 @@
 void RemoteResourceCacheProxy::cacheFont(Font& font)
 {
     auto result = m_fontIdentifierToLastRenderingUpdateVersionMap.ensure(font.renderingResourceIdentifier(), [&] {
-        return 0;
+        m_remoteRenderingBackendProxy.cacheFont(makeRef(font));
+        ++m_numberOfFontsUsedInCurrentRenderingUpdate;
+        return m_currentRenderingUpdateVersion;
     });
+
     auto& lastVersion = result.iterator->value;
     if (lastVersion != m_currentRenderingUpdateVersion) {
         lastVersion = m_currentRenderingUpdateVersion;
         ++m_numberOfFontsUsedInCurrentRenderingUpdate;
     }
-    if (result.isNewEntry)
-        m_remoteRenderingBackendProxy.cacheFont(makeRef(font));
 }
 
 void RemoteResourceCacheProxy::releaseNativeImage(RenderingResourceIdentifier renderingResourceIdentifier)
@@ -125,25 +126,42 @@
     m_remoteRenderingBackendProxy.releaseRemoteResource(renderingResourceIdentifier);
 }
 
+void RemoteResourceCacheProxy::prepareForNextRenderingUpdate()
+{
+    ++m_currentRenderingUpdateVersion;
+    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+}
+
+void RemoteResourceCacheProxy::clearFontMap()
+{
+    m_fontIdentifierToLastRenderingUpdateVersionMap.clear();
+    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+    m_currentRenderingUpdateVersion = 0;
+}
+
 void RemoteResourceCacheProxy::didFinalizeRenderingUpdate()
 {
     static constexpr unsigned minimumRenderingUpdateCountToKeepFontAlive = 4;
     static constexpr double minimumFractionOfUnusedFontCountToTriggerRemoval = 0.25;
-    static constexpr unsigned maximumUnusedFontCountToSkipRemoval = 0;
 
     unsigned totalFontCount = m_fontIdentifierToLastRenderingUpdateVersionMap.size();
     RELEASE_ASSERT(m_numberOfFontsUsedInCurrentRenderingUpdate <= totalFontCount);
+
     unsigned unusedFontCount = totalFontCount - m_numberOfFontsUsedInCurrentRenderingUpdate;
-    if (unusedFontCount < minimumFractionOfUnusedFontCountToTriggerRemoval * totalFontCount && unusedFontCount <= maximumUnusedFontCountToSkipRemoval)
+    if (unusedFontCount <= minimumFractionOfUnusedFontCountToTriggerRemoval * totalFontCount) {
+        prepareForNextRenderingUpdate();
         return;
-
-    for (auto& item : m_fontIdentifierToLastRenderingUpdateVersionMap) {
-        if (m_currentRenderingUpdateVersion - item.value >= minimumRenderingUpdateCountToKeepFontAlive)
-            m_remoteRenderingBackendProxy.releaseRemoteResource(item.key);
     }
 
-    ++m_currentRenderingUpdateVersion;
-    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+    m_fontIdentifierToLastRenderingUpdateVersionMap.removeIf([&] (const auto& item) {
+        if (m_currentRenderingUpdateVersion - item.value < minimumRenderingUpdateCountToKeepFontAlive)
+            return false;
+
+        m_remoteRenderingBackendProxy.releaseRemoteResource(item.key);
+        return true;
+    });
+    
+    prepareForNextRenderingUpdate();
 }
 
 void RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed()
@@ -155,14 +173,13 @@
         imageBuffer->clearBackend();
     }
     m_nativeImages.clear();
-    m_fontIdentifierToLastRenderingUpdateVersionMap.clear();
+    clearFontMap();
 }
 
 void RemoteResourceCacheProxy::releaseMemory()
 {
-    m_fontIdentifierToLastRenderingUpdateVersionMap.clear();
-    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
     m_remoteRenderingBackendProxy.deleteAllFonts();
+    clearFontMap();
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h (279103 => 279104)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h	2021-06-22 04:57:23 UTC (rev 279103)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h	2021-06-22 06:08:29 UTC (rev 279104)
@@ -62,6 +62,8 @@
     using NativeImageHashMap = HashMap<WebCore::RenderingResourceIdentifier, WeakPtr<WebCore::NativeImage>>;
     
     void releaseNativeImage(WebCore::RenderingResourceIdentifier) override;
+    void prepareForNextRenderingUpdate();
+    void clearFontMap();
 
     ImageBufferHashMap m_imageBuffers;
     NativeImageHashMap m_nativeImages;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to