⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 201563 in webkit


Ignore:
Timestamp:
Jun 1, 2016, 12:47:19 PM (10 years ago)
Author:
bshafiei@apple.com
Message:

Merged r201561. rdar://problem/26475175

Location:
branches/safari-601.1.46-branch/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-601.1.46-branch/Source/WebCore/ChangeLog

    r200999 r201563  
     12016-06-01  Babak Shafiei  <bshafiei@apple.com>
     2
     3        Merge r201561.
     4
     5    2016-06-01  Said Abou-Hallawa  <sabouhallawa@apple.com>
     6
     7            SVGImage should report its memory cost to JS garbage collector
     8            https://bugs.webkit.org/show_bug.cgi?id=158139
     9
     10            Reviewed by Geoffrey Garen.
     11
     12            Like what we do in HTMLImageLoader::notifyFinished() by reporting the memory
     13            cost of the BitmapImage, we need to do something similar for the SVGImage. In
     14            SVGImage::dataChange() and when allDataReceived is true, we can calculate
     15            the size of all DOM nodes and their renderers. The size of the encoded data
     16            has to be added as well to the total memory cost. An approximation for the
     17            memory cost has to be used since it is costly to get an accurate number.
     18
     19            * bindings/js/JSDocumentCustom.cpp:
     20            (WebCore::reportMemoryForDocumentIfFrameless): Use Node::approximateMemoryCost()
     21            instead of sizeof(Node). A Node's descendant can override this function and
     22            return a more accurate memory cost.
     23
     24            * dom/Node.h:
     25            (WebCore::Node::approximateMemoryCost): Define this new virtual function in the
     26            Node class. Its default value is sizeof(Node) but any descendant can return a
     27            more accurate number.
     28
     29            * platform/graphics/Image.h:
     30            (WebCore::Image::data): Define a const version of data() so it can be called
     31            the const function SVGImage::reportApproximateMemoryCost().
     32
     33            * svg/SVGGraphicsElement.h: Override approximateMemoryCost() to return
     34            sizeof(SVGGraphicsElement).
     35
     36            * svg/SVGPathElement.cpp:
     37            (WebCore::SVGPathElement::approximateMemoryCost): Override this function to return
     38            the memory cost of the points and the m_path of the renderer.
     39            * svg/SVGPathElement.h:
     40
     41            * svg/SVGPolyElement.cpp:
     42            (WebCore::SVGPolyElement::approximateMemoryCost): Override this function to return
     43            the memory cost of the points and the m_path of the renderer.
     44            * svg/SVGPolyElement.h:
     45
     46            * svg/graphics/SVGImage.cpp:
     47            (WebCore::SVGImage::reportApproximateMemoryCost): Calculate the memory cost of the
     48            nodes in the SVGDocument of an SVGImage. Then report this number to the JS garbage
     49            collector.
     50
     51            (WebCore::SVGImage::dataChanged): After loading all the SVG encoded data and building
     52            its DOM tree and the render tree, report the total memory cost to the JS garbage collector.
     53            * svg/graphics/SVGImage.h:
     54
    1552016-05-16  Babak Shafiei  <bshafiei@apple.com>
    256
  • branches/safari-601.1.46-branch/Source/WebCore/bindings/js/JSDocumentCustom.cpp

    r181411 r201563  
    106106    // back/forward cache.
    107107    if (!document->frame()) {
    108         size_t nodeCount = 0;
     108        size_t memoryCost = 0;
    109109        for (Node* n = document; n; n = NodeTraversal::next(*n))
    110             nodeCount++;
     110            memoryCost += n->approximateMemoryCost();
    111111       
    112112        // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
    113113        // https://bugs.webkit.org/show_bug.cgi?id=142595
    114         exec->heap()->deprecatedReportExtraMemory(nodeCount * sizeof(Node));
     114        exec->heap()->deprecatedReportExtraMemory(memoryCost);
    115115    }
    116116
  • branches/safari-601.1.46-branch/Source/WebCore/dom/Node.h

    r193556 r201563  
    165165    virtual void setNodeValue(const String&, ExceptionCode&);
    166166    virtual NodeType nodeType() const = 0;
     167    virtual size_t approximateMemoryCost() const { return sizeof(*this); }
    167168    ContainerNode* parentNode() const;
    168169    static ptrdiff_t parentNodeMemoryOffset() { return OBJECT_OFFSETOF(Node, m_parentNode); }
  • branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/Image.h

    r193886 r201563  
    120120
    121121    SharedBuffer* data() { return m_encodedImageData.get(); }
     122    const SharedBuffer* data() const { return m_encodedImageData.get(); }
    122123
    123124    // Animation begins whenever someone draws the image, so startAnimation() is not normally called.
  • branches/safari-601.1.46-branch/Source/WebCore/svg/SVGGraphicsElement.h

    r183160 r201563  
    5454    virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&, const RenderTreePosition&) override;
    5555
     56    size_t approximateMemoryCost() const override { return sizeof(*this); }
     57
    5658protected:
    5759    SVGGraphicsElement(const QualifiedName&, Document&);
  • branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPathElement.cpp

    r198407 r201563  
    360360}
    361361
     362size_t SVGPathElement::approximateMemoryCost() const
     363{
     364    // This is an approximation for path memory cost since the path is parsed on demand.
     365    size_t pathMemoryCost = (m_pathByteStream->size() / 10) * sizeof(FloatPoint);
     366    // We need to account for the memory which is allocated by the RenderSVGPath::m_path.
     367    return sizeof(*this) + (renderer() ? pathMemoryCost * 2 + sizeof(RenderSVGPath) : pathMemoryCost);
     368}
     369
    362370void SVGPathElement::pathSegListChanged(SVGPathSegRole role, ListModification listModification)
    363371{
  • branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPathElement.h

    r198248 r201563  
    100100    void animatedPropertyWillBeDeleted();
    101101
     102    size_t approximateMemoryCost() const override;
     103
    102104private:
    103105    SVGPathElement(const QualifiedName&, Document&);
  • branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPolyElement.cpp

    r198246 r201563  
    131131}
    132132
     133size_t SVGPolyElement::approximateMemoryCost() const
     134{
     135    size_t pointsCost = pointList().size() * sizeof(FloatPoint);
     136    // We need to account for the memory which is allocated by the RenderSVGPath::m_path.
     137    return sizeof(*this) + (renderer() ? pointsCost * 2 + sizeof(RenderSVGPath) : pointsCost);
    133138}
     139
     140}
  • branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPolyElement.h

    r198246 r201563  
    3939    static const SVGPropertyInfo* pointsPropertyInfo();
    4040
     41    size_t approximateMemoryCost() const override;
     42
    4143protected:
    4244    SVGPolyElement(const QualifiedName&, Document&);
  • branches/safari-601.1.46-branch/Source/WebCore/svg/graphics/SVGImage.cpp

    r198633 r201563  
    3030
    3131#include "Chrome.h"
     32#include "DOMWindow.h"
    3233#include "DocumentLoader.h"
    3334#include "ElementIterator.h"
     
    3738#include "ImageObserver.h"
    3839#include "IntRect.h"
     40#include "JSDOMWindowBase.h"
    3941#include "MainFrame.h"
    4042#include "PageConfiguration.h"
     
    4850#include "SVGSVGElement.h"
    4951#include "Settings.h"
     52#include <runtime/JSCInlines.h>
     53#include <runtime/JSLock.h>
    5054
    5155namespace WebCore {
     
    352356}
    353357
     358void SVGImage::reportApproximateMemoryCost() const
     359{
     360    Document* document = m_page->mainFrame().document();
     361    size_t decodedImageMemoryCost = 0;
     362
     363    for (Node* node = document; node; node = NodeTraversal::next(*node))
     364        decodedImageMemoryCost += node->approximateMemoryCost();
     365
     366    JSC::VM& vm = JSDOMWindowBase::commonVM();
     367    JSC::JSLockHolder lock(vm);
     368    // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
     369    // https://bugs.webkit.org/show_bug.cgi?id=142595
     370    vm.heap.deprecatedReportExtraMemory(decodedImageMemoryCost + data()->size());
     371}
     372
    354373bool SVGImage::dataChanged(bool allDataReceived)
    355374{
     
    394413        // Set the intrinsic size before a container size is available.
    395414        m_intrinsicSize = containerSize();
     415        reportApproximateMemoryCost();
    396416    }
    397417
  • branches/safari-601.1.46-branch/Source/WebCore/svg/graphics/SVGImage.h

    r193886 r201563  
    8888    virtual bool dataChanged(bool allDataReceived) override;
    8989
     90    void reportApproximateMemoryCost() const;
     91
    9092    // FIXME: SVGImages will be unable to prune because this function is not implemented yet.
    9193    virtual void destroyDecodedData(bool) override { }
Note: See TracChangeset for help on using the changeset viewer.