Title: [236100] trunk
Revision
236100
Author
[email protected]
Date
2018-09-17 21:14:39 -0700 (Mon, 17 Sep 2018)

Log Message

Many modern media control tests leak documents in testing
https://bugs.webkit.org/show_bug.cgi?id=189437

Reviewed by Darin Adler.
Source/WebCore:

In order to accurately detect leaks in media controls tests which use lots of
SVGImages, we have to:
- Fire a zero-delay timer after the postTask, in order for ImagesLoader's m_derefElementTimer
  to clear references to elements.
- Have releaseCriticalMemory() call CachedResourceLoader's garbageCollectDocumentResources()
  to drop the last handle to the CachedResource for an SVGImage.
- Call WKBundleReleaseMemory() after the GC and timer, since we need garbageCollectDocumentResources()
  to run again after that timer has fired.

This should fix most of the spurious leak reports involving SVGImage documents.

* page/MemoryRelease.cpp:
(WebCore::releaseCriticalMemory):

Source/WebKit:

In order to accurately detect leaks in media controls tests which use lots of
SVGImages, we have to:
- Fire a zero-delay timer after the postTask, in order for ImagesLoader's m_derefElementTimer
  to clear references to elements.
- Have releaseCriticalMemory() call CachedResourceLoader's garbageCollectDocumentResources()
  to drop the last handle to the CachedResource for an SVGImage.
- Call WKBundleReleaseMemory() after the GC and timer, since we need garbageCollectDocumentResources()
  to run again after that timer has fired.

This should fix most of the spurious leak reports involving SVGImage documents.

* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageCallAfterTasksAndTimers):
(WKBundlePagePostTask): Deleted.
* WebProcess/InjectedBundle/API/c/WKBundlePage.h:

Tools:

In order to accurately detect leaks in media controls tests which use lots of
SVGImages, we have to:
- Fire a zero-delay timer after the postTask, in order for ImagesLoader's m_derefElementTimer
  to clear references to elements.
- Have releaseCriticalMemory() call CachedResourceLoader's garbageCollectDocumentResources()
  to drop the last handle to the CachedResource for an SVGImage.
- Call WKBundleReleaseMemory() after the GC and timer, since we need garbageCollectDocumentResources()
  to run again after that timer has fired.

This should fix most of the spurious leak reports involving SVGImage documents.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::reportLiveDocuments):
(WTR::InjectedBundle::didReceiveMessageToPage):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (236099 => 236100)


--- trunk/Source/WebCore/ChangeLog	2018-09-18 02:54:37 UTC (rev 236099)
+++ trunk/Source/WebCore/ChangeLog	2018-09-18 04:14:39 UTC (rev 236100)
@@ -1,3 +1,24 @@
+2018-09-17  Simon Fraser  <[email protected]>
+
+        Many modern media control tests leak documents in testing
+        https://bugs.webkit.org/show_bug.cgi?id=189437
+
+        Reviewed by Darin Adler.
+
+        In order to accurately detect leaks in media controls tests which use lots of
+        SVGImages, we have to:
+        - Fire a zero-delay timer after the postTask, in order for ImagesLoader's m_derefElementTimer
+          to clear references to elements.
+        - Have releaseCriticalMemory() call CachedResourceLoader's garbageCollectDocumentResources()
+          to drop the last handle to the CachedResource for an SVGImage.
+        - Call WKBundleReleaseMemory() after the GC and timer, since we need garbageCollectDocumentResources()
+          to run again after that timer has fired.
+        
+        This should fix most of the spurious leak reports involving SVGImage documents.
+
+        * page/MemoryRelease.cpp:
+        (WebCore::releaseCriticalMemory):
+
 2018-09-17  Jer Noble  <[email protected]>
 
         Add support for HEVC codec types in Media Capabilities

Modified: trunk/Source/WebCore/page/MemoryRelease.cpp (236099 => 236100)


--- trunk/Source/WebCore/page/MemoryRelease.cpp	2018-09-18 02:54:37 UTC (rev 236099)
+++ trunk/Source/WebCore/page/MemoryRelease.cpp	2018-09-18 04:14:39 UTC (rev 236100)
@@ -28,6 +28,7 @@
 
 #include "CSSFontSelector.h"
 #include "CSSValuePool.h"
+#include "CachedResourceLoader.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
 #include "CommonVM.h"
@@ -88,6 +89,7 @@
     for (auto& document : copyToVectorOf<RefPtr<Document>>(Document::allDocuments())) {
         document->styleScope().releaseMemory();
         document->fontSelector().emptyCaches();
+        document->cachedResourceLoader().garbageCollectDocumentResources();
     }
 
     GCController::singleton().deleteAllCode(JSC::DeleteAllCodeIfNotCollecting);

Modified: trunk/Source/WebKit/ChangeLog (236099 => 236100)


--- trunk/Source/WebKit/ChangeLog	2018-09-18 02:54:37 UTC (rev 236099)
+++ trunk/Source/WebKit/ChangeLog	2018-09-18 04:14:39 UTC (rev 236100)
@@ -1,3 +1,26 @@
+2018-09-17  Simon Fraser  <[email protected]>
+
+        Many modern media control tests leak documents in testing
+        https://bugs.webkit.org/show_bug.cgi?id=189437
+
+        Reviewed by Darin Adler.
+
+        In order to accurately detect leaks in media controls tests which use lots of
+        SVGImages, we have to:
+        - Fire a zero-delay timer after the postTask, in order for ImagesLoader's m_derefElementTimer
+          to clear references to elements.
+        - Have releaseCriticalMemory() call CachedResourceLoader's garbageCollectDocumentResources()
+          to drop the last handle to the CachedResource for an SVGImage.
+        - Call WKBundleReleaseMemory() after the GC and timer, since we need garbageCollectDocumentResources()
+          to run again after that timer has fired.
+        
+        This should fix most of the spurious leak reports involving SVGImage documents.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+        (WKBundlePageCallAfterTasksAndTimers):
+        (WKBundlePagePostTask): Deleted.
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.h:
+
 2018-09-17  Dan Bernstein  <[email protected]>
 
         Try to fix Apple internal builds with the iOS 12.0 SDK.

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp (236099 => 236100)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2018-09-18 02:54:37 UTC (rev 236099)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2018-09-18 04:14:39 UTC (rev 236100)
@@ -620,7 +620,7 @@
     });
 }
 
-void WKBundlePagePostTask(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)
+void WKBundlePageCallAfterTasksAndTimers(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)
 {
     if (!callback)
         return;
@@ -634,8 +634,29 @@
     if (!document)
         return;
 
+    class TimerOwner {
+    public:
+        TimerOwner(WTF::Function<void (void*)>&& callback, void* context)
+            : m_timer(*this, &TimerOwner::timerFired)
+            , m_callback(WTFMove(callback))
+            , m_context(context)
+        {
+            m_timer.startOneShot(0_s);
+        }
+        
+        void timerFired()
+        {
+            m_callback(m_context);
+            delete this;
+        }
+        
+        WebCore::Timer m_timer;
+        WTF::Function<void (void*)> m_callback;
+        void* m_context;
+    };
+    
     document->postTask([=] (WebCore::ScriptExecutionContext&) {
-        callback(context);
+        new TimerOwner(callback, context); // deletes itself when done.
     });
 }
 

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h (236099 => 236100)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h	2018-09-18 02:54:37 UTC (rev 236099)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h	2018-09-18 04:14:39 UTC (rev 236100)
@@ -117,8 +117,8 @@
 typedef void (*WKBundlePageTestNotificationCallback)(void* context);
 WK_EXPORT void WKBundlePageRegisterScrollOperationCompletionCallback(WKBundlePageRef, WKBundlePageTestNotificationCallback, void* context);
 
-// Posts a task in the ScriptExecutionContext of the main frame. Used to do work after other tasks have completed.
-WK_EXPORT void WKBundlePagePostTask(WKBundlePageRef, WKBundlePageTestNotificationCallback, void* context);
+// Call the given callback after both a postTask() on the page's document's ScriptExecutionContext, and a zero-delay timer.
+WK_EXPORT void WKBundlePageCallAfterTasksAndTimers(WKBundlePageRef, WKBundlePageTestNotificationCallback, void* context);
 
 WK_EXPORT void WKBundlePagePostMessage(WKBundlePageRef page, WKStringRef messageName, WKTypeRef messageBody);
 

Modified: trunk/Tools/ChangeLog (236099 => 236100)


--- trunk/Tools/ChangeLog	2018-09-18 02:54:37 UTC (rev 236099)
+++ trunk/Tools/ChangeLog	2018-09-18 04:14:39 UTC (rev 236100)
@@ -1,3 +1,25 @@
+2018-09-17  Simon Fraser  <[email protected]>
+
+        Many modern media control tests leak documents in testing
+        https://bugs.webkit.org/show_bug.cgi?id=189437
+
+        Reviewed by Darin Adler.
+        
+        In order to accurately detect leaks in media controls tests which use lots of
+        SVGImages, we have to:
+        - Fire a zero-delay timer after the postTask, in order for ImagesLoader's m_derefElementTimer
+          to clear references to elements.
+        - Have releaseCriticalMemory() call CachedResourceLoader's garbageCollectDocumentResources()
+          to drop the last handle to the CachedResource for an SVGImage.
+        - Call WKBundleReleaseMemory() after the GC and timer, since we need garbageCollectDocumentResources()
+          to run again after that timer has fired.
+        
+        This should fix most of the spurious leak reports involving SVGImage documents.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::reportLiveDocuments):
+        (WTR::InjectedBundle::didReceiveMessageToPage):
+
 2018-09-17  Chris Dumez  <[email protected]>
 
         PSON: window.open() with 'noopener' should only process-swap cross-site, not cross-origin

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (236099 => 236100)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2018-09-18 02:54:37 UTC (rev 236099)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2018-09-18 04:14:39 UTC (rev 236100)
@@ -189,6 +189,9 @@
 
 void InjectedBundle::reportLiveDocuments(WKBundlePageRef page)
 {
+    // Release memory again, after the GC and timer fire. This is necessary to clear entries from CachedResourceLoader's m_documentResources in some scenarios.
+    WKBundleReleaseMemory(m_bundle);
+
     const bool excludeDocumentsInPageGroup = true;
     auto documentURLs = adoptWK(WKBundleGetLiveDocumentURLs(m_bundle, m_pageGroup, excludeDocumentsInPageGroup));
     auto ackMessageName = adoptWK(WKStringCreateWithUTF8CString("LiveDocuments"));
@@ -274,7 +277,7 @@
         WKBundleReleaseMemory(m_bundle);
 
         WKRetain(page); // Balanced by the release in postGCTask.
-        WKBundlePagePostTask(page, postGCTask, (void*)page);
+        WKBundlePageCallAfterTasksAndTimers(page, postGCTask, (void*)page);
         return;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to