Title: [201563] branches/safari-601.1.46-branch/Source/WebCore

Diff

Modified: branches/safari-601.1.46-branch/Source/WebCore/ChangeLog (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/ChangeLog	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/ChangeLog	2016-06-01 19:47:19 UTC (rev 201563)
@@ -1,3 +1,57 @@
+2016-06-01  Babak Shafiei  <[email protected]>
+
+        Merge r201561.
+
+    2016-06-01  Said Abou-Hallawa  <[email protected]>
+
+            SVGImage should report its memory cost to JS garbage collector
+            https://bugs.webkit.org/show_bug.cgi?id=158139
+
+            Reviewed by Geoffrey Garen.
+
+            Like what we do in HTMLImageLoader::notifyFinished() by reporting the memory
+            cost of the BitmapImage, we need to do something similar for the SVGImage. In
+            SVGImage::dataChange() and when allDataReceived is true, we can calculate
+            the size of all DOM nodes and their renderers. The size of the encoded data
+            has to be added as well to the total memory cost. An approximation for the
+            memory cost has to be used since it is costly to get an accurate number.
+
+            * bindings/js/JSDocumentCustom.cpp: 
+            (WebCore::reportMemoryForDocumentIfFrameless): Use Node::approximateMemoryCost()
+            instead of sizeof(Node). A Node's descendant can override this function and
+            return a more accurate memory cost.
+
+            * dom/Node.h:
+            (WebCore::Node::approximateMemoryCost): Define this new virtual function in the
+            Node class. Its default value is sizeof(Node) but any descendant can return a
+            more accurate number.
+
+            * platform/graphics/Image.h:
+            (WebCore::Image::data): Define a const version of data() so it can be called
+            the const function SVGImage::reportApproximateMemoryCost().
+
+            * svg/SVGGraphicsElement.h: Override approximateMemoryCost() to return 
+            sizeof(SVGGraphicsElement).
+
+            * svg/SVGPathElement.cpp:
+            (WebCore::SVGPathElement::approximateMemoryCost): Override this function to return
+            the memory cost of the points and the m_path of the renderer.
+            * svg/SVGPathElement.h:
+
+            * svg/SVGPolyElement.cpp:
+            (WebCore::SVGPolyElement::approximateMemoryCost): Override this function to return
+            the memory cost of the points and the m_path of the renderer.
+            * svg/SVGPolyElement.h:
+
+            * svg/graphics/SVGImage.cpp:
+            (WebCore::SVGImage::reportApproximateMemoryCost): Calculate the memory cost of the 
+            nodes in the SVGDocument of an SVGImage. Then report this number to the JS garbage 
+            collector.
+
+            (WebCore::SVGImage::dataChanged): After loading all the SVG encoded data and building
+            its DOM tree and the render tree, report the total memory cost to the JS garbage collector.
+            * svg/graphics/SVGImage.h:
+
 2016-05-16  Babak Shafiei  <[email protected]>
 
         Merge r200986.

Modified: branches/safari-601.1.46-branch/Source/WebCore/bindings/js/JSDocumentCustom.cpp (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/bindings/js/JSDocumentCustom.cpp	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/bindings/js/JSDocumentCustom.cpp	2016-06-01 19:47:19 UTC (rev 201563)
@@ -105,13 +105,13 @@
     // Make sure the document is kept around by the window object, and works right with the
     // back/forward cache.
     if (!document->frame()) {
-        size_t nodeCount = 0;
+        size_t memoryCost = 0;
         for (Node* n = document; n; n = NodeTraversal::next(*n))
-            nodeCount++;
+            memoryCost += n->approximateMemoryCost();
         
         // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
         // https://bugs.webkit.org/show_bug.cgi?id=142595
-        exec->heap()->deprecatedReportExtraMemory(nodeCount * sizeof(Node));
+        exec->heap()->deprecatedReportExtraMemory(memoryCost);
     }
 
     return wrapper;

Modified: branches/safari-601.1.46-branch/Source/WebCore/dom/Node.h (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/dom/Node.h	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/dom/Node.h	2016-06-01 19:47:19 UTC (rev 201563)
@@ -164,6 +164,7 @@
     virtual String nodeValue() const;
     virtual void setNodeValue(const String&, ExceptionCode&);
     virtual NodeType nodeType() const = 0;
+    virtual size_t approximateMemoryCost() const { return sizeof(*this); }
     ContainerNode* parentNode() const;
     static ptrdiff_t parentNodeMemoryOffset() { return OBJECT_OFFSETOF(Node, m_parentNode); }
     Element* parentElement() const;

Modified: branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/Image.h (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/Image.h	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/Image.h	2016-06-01 19:47:19 UTC (rev 201563)
@@ -119,6 +119,7 @@
     virtual bool decodedDataIsPurgeable() const { return false; }
 
     SharedBuffer* data() { return m_encodedImageData.get(); }
+    const SharedBuffer* data() const { return m_encodedImageData.get(); }
 
     // Animation begins whenever someone draws the image, so startAnimation() is not normally called.
     // It will automatically pause once all observers no longer want to render the image anywhere.

Modified: branches/safari-601.1.46-branch/Source/WebCore/svg/SVGGraphicsElement.h (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/svg/SVGGraphicsElement.h	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/svg/SVGGraphicsElement.h	2016-06-01 19:47:19 UTC (rev 201563)
@@ -53,6 +53,8 @@
     virtual void toClipPath(Path&);
     virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&, const RenderTreePosition&) override;
 
+    size_t approximateMemoryCost() const override { return sizeof(*this); }
+
 protected:
     SVGGraphicsElement(const QualifiedName&, Document&);
 

Modified: branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPathElement.cpp (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPathElement.cpp	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPathElement.cpp	2016-06-01 19:47:19 UTC (rev 201563)
@@ -359,6 +359,14 @@
     return nullptr;
 }
 
+size_t SVGPathElement::approximateMemoryCost() const
+{
+    // This is an approximation for path memory cost since the path is parsed on demand.
+    size_t pathMemoryCost = (m_pathByteStream->size() / 10) * sizeof(FloatPoint);
+    // We need to account for the memory which is allocated by the RenderSVGPath::m_path.
+    return sizeof(*this) + (renderer() ? pathMemoryCost * 2 + sizeof(RenderSVGPath) : pathMemoryCost);
+}
+
 void SVGPathElement::pathSegListChanged(SVGPathSegRole role, ListModification listModification)
 {
     switch (role) {

Modified: branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPathElement.h (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPathElement.h	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPathElement.h	2016-06-01 19:47:19 UTC (rev 201563)
@@ -99,6 +99,8 @@
 
     void animatedPropertyWillBeDeleted();
 
+    size_t approximateMemoryCost() const override;
+
 private:
     SVGPathElement(const QualifiedName&, Document&);
 

Modified: branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPolyElement.cpp (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPolyElement.cpp	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPolyElement.cpp	2016-06-01 19:47:19 UTC (rev 201563)
@@ -130,4 +130,11 @@
     return static_cast<SVGListPropertyTearOff<SVGPointList>*>(static_reference_cast<SVGAnimatedPointList>(lookupOrCreatePointsWrapper(this))->animVal().get());
 }
 
+size_t SVGPolyElement::approximateMemoryCost() const
+{
+    size_t pointsCost = pointList().size() * sizeof(FloatPoint);
+    // We need to account for the memory which is allocated by the RenderSVGPath::m_path.
+    return sizeof(*this) + (renderer() ? pointsCost * 2 + sizeof(RenderSVGPath) : pointsCost);
 }
+
+}

Modified: branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPolyElement.h (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPolyElement.h	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/svg/SVGPolyElement.h	2016-06-01 19:47:19 UTC (rev 201563)
@@ -38,6 +38,8 @@
 
     static const SVGPropertyInfo* pointsPropertyInfo();
 
+    size_t approximateMemoryCost() const override;
+
 protected:
     SVGPolyElement(const QualifiedName&, Document&);
 

Modified: branches/safari-601.1.46-branch/Source/WebCore/svg/graphics/SVGImage.cpp (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/svg/graphics/SVGImage.cpp	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/svg/graphics/SVGImage.cpp	2016-06-01 19:47:19 UTC (rev 201563)
@@ -29,6 +29,7 @@
 #include "SVGImage.h"
 
 #include "Chrome.h"
+#include "DOMWindow.h"
 #include "DocumentLoader.h"
 #include "ElementIterator.h"
 #include "FrameLoader.h"
@@ -36,6 +37,7 @@
 #include "ImageBuffer.h"
 #include "ImageObserver.h"
 #include "IntRect.h"
+#include "JSDOMWindowBase.h"
 #include "MainFrame.h"
 #include "PageConfiguration.h"
 #include "RenderSVGRoot.h"
@@ -47,6 +49,8 @@
 #include "SVGImageElement.h"
 #include "SVGSVGElement.h"
 #include "Settings.h"
+#include <runtime/JSCInlines.h>
+#include <runtime/JSLock.h>
 
 namespace WebCore {
 
@@ -351,6 +355,21 @@
     stopAnimation();
 }
 
+void SVGImage::reportApproximateMemoryCost() const
+{
+    Document* document = m_page->mainFrame().document();
+    size_t decodedImageMemoryCost = 0;
+
+    for (Node* node = document; node; node = NodeTraversal::next(*node))
+        decodedImageMemoryCost += node->approximateMemoryCost();
+
+    JSC::VM& vm = JSDOMWindowBase::commonVM();
+    JSC::JSLockHolder lock(vm);
+    // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
+    // https://bugs.webkit.org/show_bug.cgi?id=142595
+    vm.heap.deprecatedReportExtraMemory(decodedImageMemoryCost + data()->size());
+}
+
 bool SVGImage::dataChanged(bool allDataReceived)
 {
     // Don't do anything if is an empty image.
@@ -393,6 +412,7 @@
 
         // Set the intrinsic size before a container size is available.
         m_intrinsicSize = containerSize();
+        reportApproximateMemoryCost();
     }
 
     return m_page != nullptr;

Modified: branches/safari-601.1.46-branch/Source/WebCore/svg/graphics/SVGImage.h (201562 => 201563)


--- branches/safari-601.1.46-branch/Source/WebCore/svg/graphics/SVGImage.h	2016-06-01 19:32:34 UTC (rev 201562)
+++ branches/safari-601.1.46-branch/Source/WebCore/svg/graphics/SVGImage.h	2016-06-01 19:47:19 UTC (rev 201563)
@@ -87,6 +87,8 @@
 
     virtual bool dataChanged(bool allDataReceived) override;
 
+    void reportApproximateMemoryCost() const;
+
     // FIXME: SVGImages will be unable to prune because this function is not implemented yet.
     virtual void destroyDecodedData(bool) override { }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to