Changeset 91384 in webkit


Ignore:
Timestamp:
Jul 20, 2011 11:45:47 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Patch by Scott Graham <scottmg@chromium.org> on 2011-07-20
Reviewed by Antti Koivisto.

REGRESSION (r39725?): Resources removed from document can not be freed
until the document is deleted
https://bugs.webkit.org/show_bug.cgi?id=61006

Upon completing a load start a Timer to iterate through
CachedResourceLoader's m_documentResources map to check for any items
that have only one reference (thus being the reference in the map
itself). The map should really be weak, but because the
CachedResourceHandle achieves bookkeeping work in addition to
reference counting, this is a simpler and more localized way to free
the used memory while maintaining the other behaviour (when
CachedResource is used as proxy).

No new layout tests, but with this patch the testcase at
https://bugs.webkit.org/attachment.cgi?id=93850 should no longer
consume 400MB of ram on load.

  • loader/cache/CachedResource.h:

(WebCore::CachedResource::getHandleCount):

  • loader/cache/CachedResourceLoader.cpp:

(WebCore::CachedResourceLoader::loadDone):
(WebCore::CachedResourceLoader::garbageCollectDocumentResources):

  • loader/cache/CachedResourceLoader.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r91383 r91384  
     12011-07-20  Scott Graham  <scottmg@chromium.org>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        REGRESSION (r39725?): Resources removed from document can not be freed
     6        until the document is deleted
     7        https://bugs.webkit.org/show_bug.cgi?id=61006
     8
     9        Upon completing a load start a Timer to iterate through
     10        CachedResourceLoader's m_documentResources map to check for any items
     11        that have only one reference (thus being the reference in the map
     12        itself). The map should really be weak, but because the
     13        CachedResourceHandle achieves bookkeeping work in addition to
     14        reference counting, this is a simpler and more localized way to free
     15        the used memory while maintaining the other behaviour (when
     16        CachedResource is used as proxy).
     17
     18        No new layout tests, but with this patch the testcase at
     19        https://bugs.webkit.org/attachment.cgi?id=93850 should no longer
     20        consume 400MB of ram on load.
     21
     22        * loader/cache/CachedResource.h:
     23        (WebCore::CachedResource::getHandleCount):
     24        * loader/cache/CachedResourceLoader.cpp:
     25        (WebCore::CachedResourceLoader::loadDone):
     26        (WebCore::CachedResourceLoader::garbageCollectDocumentResources):
     27        * loader/cache/CachedResourceLoader.h:
     28
    1292011-07-20  James Robinson  <jamesr@chromium.org>
    230
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r88391 r91384  
    183183
    184184    bool canDelete() const { return !hasClients() && !m_request && !m_preloadCount && !m_handleCount && !m_resourceToRevalidate && !m_proxyResource; }
     185    bool hasOneHandle() const { return m_handleCount == 1; }
    185186
    186187    bool isExpired() const;
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r90164 r91384  
    8787    : m_document(document)
    8888    , m_requestCount(0)
     89    , m_garbageCollectDocumentResourcesTimer(this, &CachedResourceLoader::garbageCollectDocumentResourcesTimerFired)
    8990    , m_autoLoadImages(true)
    9091    , m_loadFinishing(false)
     
    562563        frame()->loader()->loadDone();
    563564    performPostLoadActions();
     565
     566    if (!m_garbageCollectDocumentResourcesTimer.isActive())
     567        m_garbageCollectDocumentResourcesTimer.startOneShot(0);
     568}
     569
     570// Garbage collecting m_documentResources is a workaround for the
     571// CachedResourceHandles on the RHS being strong references. Ideally this
     572// would be a weak map, however CachedResourceHandles perform additional
     573// bookkeeping on CachedResources, so instead pseudo-GC them -- when the
     574// reference count reaches 1, m_documentResources is the only reference, so
     575// remove it from the map.
     576void CachedResourceLoader::garbageCollectDocumentResourcesTimerFired(Timer<CachedResourceLoader>* timer)
     577{
     578    Vector<String, 10> toDelete;
     579
     580    for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != m_documentResources.end(); ++it) {
     581        if (it->second->hasOneHandle())
     582            toDelete.append(it->first);
     583    }
     584
     585    for (Vector<String, 10>::const_iterator idel = toDelete.begin(); idel != toDelete.end(); ++idel)
     586        m_documentResources.remove(*idel);
    564587}
    565588
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.h

    r89503 r91384  
    3131#include "CachePolicy.h"
    3232#include "ResourceLoadPriority.h"
     33#include "Timer.h"
    3334#include <wtf/Deque.h>
    3435#include <wtf/HashMap.h>
     
    118119    bool canRequest(CachedResource::Type, const KURL&, bool forPreload = false);
    119120
     121    void garbageCollectDocumentResourcesTimerFired(Timer<CachedResourceLoader>*);
    120122    void performPostLoadActions();
    121123   
     
    133135    };
    134136    Deque<PendingPreload> m_pendingPreloads;
     137
     138    Timer<CachedResourceLoader> m_garbageCollectDocumentResourcesTimer;
    135139   
    136140    //29 bits left
Note: See TracChangeset for help on using the changeset viewer.