WebKit Bugzilla
Attachment 349851 Details for
Bug 189437
: Many modern media control tests leak documents in testing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to use RefTracker for tracking CachedResourceHandles on CachedResource
ref-tracker-for-resource-handles.patch (text/plain), 6.35 KB, created by
Simon Fraser (smfr)
on 2018-09-14 21:50:47 PDT
(
hide
)
Description:
Patch to use RefTracker for tracking CachedResourceHandles on CachedResource
Filename:
MIME Type:
Creator:
Simon Fraser (smfr)
Created:
2018-09-14 21:50:47 PDT
Size:
6.35 KB
patch
obsolete
>diff --git a/Source/WebCore/loader/cache/CachedResource.cpp b/Source/WebCore/loader/cache/CachedResource.cpp >index b40f130e6b755e7e375005b915f88764d9dc37d2..1fd46a3096cedfe300275db9b314db85c1cb5e5f 100644 >--- a/Source/WebCore/loader/cache/CachedResource.cpp >+++ b/Source/WebCore/loader/cache/CachedResource.cpp >@@ -24,6 +24,7 @@ > #include "config.h" > #include "CachedResource.h" > >+#include "CachedImage.h" > #include "CachedResourceClient.h" > #include "CachedResourceClientWalker.h" > #include "CachedResourceHandle.h" >@@ -65,6 +66,12 @@ > namespace WebCore { > using namespace WTF; > >+HashSet<CachedResource*>& CachedResource::allCachedResources() >+{ >+ static NeverDestroyed<HashSet<CachedResource*>> set; >+ return set; >+} >+ > ResourceLoadPriority CachedResource::defaultPriorityForResourceType(Type type) > { > switch (type) { >@@ -131,6 +138,7 @@ CachedResource::CachedResource(CachedResourceRequest&& request, Type type, PAL:: > , m_hasUnknownEncoding(request.isLinkPreload()) > , m_ignoreForRequestCount(request.ignoreForRequestCount()) > { >+ allCachedResources().add(this); > ASSERT(sessionID.isValid()); > > setLoadPriority(request.priority()); >@@ -155,6 +163,8 @@ CachedResource::CachedResource(const URL& url, Type type, PAL::SessionID session > , m_status(Cached) > , m_type(type) > { >+ allCachedResources().add(this); >+ > ASSERT(sessionID.isValid()); > #ifndef NDEBUG > cachedResourceLeakCounter.increment(); >@@ -176,6 +186,8 @@ CachedResource::~CachedResource() > > if (m_owningCachedResourceLoader) > m_owningCachedResourceLoader->removeCachedResource(*this); >+ >+ allCachedResources().remove(this); > } > > void CachedResource::failBeforeStarting() >@@ -612,6 +624,7 @@ void CachedResource::decodedDataDeletionTimerFired() > bool CachedResource::deleteIfPossible() > { > if (canDelete()) { >+ LOG(ResourceLoading, "CachedResource %p deleteIfPossible - can delete, in cache %d", this, inCache()); > if (!inCache()) { > InspectorInstrumentation::willDestroyCachedResource(*this); > delete this; >@@ -620,6 +633,8 @@ bool CachedResource::deleteIfPossible() > if (m_data) > m_data->hintMemoryNotNeededSoon(); > } >+ >+ LOG(ResourceLoading, "CachedResource %p deleteIfPossible - can't delete (hasClients %d loader %p preloadCount %u handleCount %u resourceToRevalidate %p proxyResource %p)", this, hasClients(), m_loader.get(), m_preloadCount, m_handleCount, m_resourceToRevalidate, m_proxyResource); > return false; > } > >@@ -780,8 +795,15 @@ void CachedResource::updateResponseAfterRevalidation(const ResourceResponse& val > void CachedResource::registerHandle(CachedResourceHandleBase* h) > { > ++m_handleCount; >+ LOG(ResourceLoading, "CachedResource %p registerHandle - handle count %u", this, m_handleCount); >+ >+ h->setToken(m_handleTracker.trackRef()); >+ > if (m_resourceToRevalidate) > m_handlesToRevalidate.add(h); >+ >+// if (is<CachedImage>(this)) >+// WTFReportBacktrace(); > } > > void CachedResource::unregisterHandle(CachedResourceHandleBase* h) >@@ -789,9 +811,17 @@ void CachedResource::unregisterHandle(CachedResourceHandleBase* h) > ASSERT(m_handleCount > 0); > --m_handleCount; > >+ LOG(ResourceLoading, "CachedResource %p unregisterHandle - handle count %u", this, m_handleCount); >+ >+ m_handleTracker.trackDeref(h->token()); >+ h->setToken(UntrackedRefToken()); >+ > if (m_resourceToRevalidate) > m_handlesToRevalidate.remove(h); > >+// if (is<CachedImage>(this)) >+// WTFReportBacktrace(); >+ > if (!m_handleCount) > deleteIfPossible(); > } >diff --git a/Source/WebCore/loader/cache/CachedResource.h b/Source/WebCore/loader/cache/CachedResource.h >index ef229550f411dc56505261bc525c7dbcde7d43da..d04f3a46e2220c1b2dbaf1fd270fcaf26b3adfa2 100644 >--- a/Source/WebCore/loader/cache/CachedResource.h >+++ b/Source/WebCore/loader/cache/CachedResource.h >@@ -35,6 +35,7 @@ > #include <time.h> > #include <wtf/HashCountedSet.h> > #include <wtf/HashSet.h> >+#include <wtf/RefTracker.h> > #include <wtf/TypeCasts.h> > #include <wtf/Vector.h> > #include <wtf/text/WTFString.h> >@@ -96,6 +97,8 @@ public: > > CachedResource(CachedResourceRequest&&, Type, PAL::SessionID); > virtual ~CachedResource(); >+ >+ static HashSet<CachedResource*>& allCachedResources(); > > virtual void load(CachedResourceLoader&); > >@@ -216,6 +219,8 @@ public: > > bool canDelete() const { return !hasClients() && !m_loader && !m_preloadCount && !m_handleCount && !m_resourceToRevalidate && !m_proxyResource; } > bool hasOneHandle() const { return m_handleCount == 1; } >+ >+ unsigned handleCount() const { return m_handleCount; } > > bool isExpired() const; > >@@ -279,6 +284,8 @@ public: > void setOriginalRequest(std::unique_ptr<ResourceRequest>&& originalRequest) { m_originalRequest = WTFMove(originalRequest); } > const std::unique_ptr<ResourceRequest>& originalRequest() const { return m_originalRequest; } > >+ RefTracker& handleTracker() { return m_handleTracker; } >+ > protected: > // CachedResource constructor that may be used when the CachedResource can already be filled with response data. > CachedResource(const URL&, Type, PAL::SessionID); >@@ -378,6 +385,8 @@ private: > bool m_deleted { false }; > unsigned m_lruIndex { 0 }; > #endif >+ >+ RefTracker m_handleTracker; > }; > > class CachedResource::Callback { >diff --git a/Source/WebCore/loader/cache/CachedResourceHandle.h b/Source/WebCore/loader/cache/CachedResourceHandle.h >index 82a0d7576148c6c2660af51263cde1d8811a16ec..1d3621c4cdc47edda61c22f9e205a73187ef06bd 100644 >--- a/Source/WebCore/loader/cache/CachedResourceHandle.h >+++ b/Source/WebCore/loader/cache/CachedResourceHandle.h >@@ -26,6 +26,7 @@ > #pragma once > > #include <wtf/Forward.h> >+#include <wtf/RefTracking.h> > > namespace WebCore { > >@@ -43,6 +44,9 @@ public: > typedef CachedResource* CachedResourceHandleBase::*UnspecifiedBoolType; > operator UnspecifiedBoolType() const { return m_resource ? &CachedResourceHandleBase::m_resource : 0; } > >+ void setToken(RefTrackingToken token) { m_token = token; } >+ RefTrackingToken& token() { return m_token; } >+ > protected: > CachedResourceHandleBase(); > CachedResourceHandleBase(CachedResource*); >@@ -56,6 +60,7 @@ private: > friend class CachedResource; > > CachedResource* m_resource; >+ RefTrackingToken m_token; > }; > > template <class R> class CachedResourceHandle : public CachedResourceHandleBase {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189437
: 349851 |
349860