Changeset 201561 in webkit
- Timestamp:
- Jun 1, 2016, 11:50:09 AM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
-
ChangeLog (modified) (1 diff)
-
bindings/js/JSDocumentCustom.cpp (modified) (1 diff)
-
dom/Node.h (modified) (1 diff)
-
platform/graphics/Image.h (modified) (1 diff)
-
svg/SVGGraphicsElement.h (modified) (1 diff)
-
svg/SVGPathElement.cpp (modified) (1 diff)
-
svg/SVGPathElement.h (modified) (1 diff)
-
svg/SVGPolyElement.cpp (modified) (1 diff)
-
svg/SVGPolyElement.h (modified) (1 diff)
-
svg/graphics/SVGImage.cpp (modified) (5 diffs)
-
svg/graphics/SVGImage.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r201559 r201561 1 2016-06-01 Said Abou-Hallawa <sabouhallawa@apple.com> 2 3 SVGImage should report its memory cost to JS garbage collector 4 https://bugs.webkit.org/show_bug.cgi?id=158139 5 6 Reviewed by Geoffrey Garen. 7 8 Like what we do in HTMLImageLoader::notifyFinished() by reporting the memory 9 cost of the BitmapImage, we need to do something similar for the SVGImage. In 10 SVGImage::dataChange() and when allDataReceived is true, we can calculate 11 the size of all DOM nodes and their renderers. The size of the encoded data 12 has to be added as well to the total memory cost. An approximation for the 13 memory cost has to be used since it is costly to get an accurate number. 14 15 * bindings/js/JSDocumentCustom.cpp: 16 (WebCore::reportMemoryForDocumentIfFrameless): Use Node::approximateMemoryCost() 17 instead of sizeof(Node). A Node's descendant can override this function and 18 return a more accurate memory cost. 19 20 * dom/Node.h: 21 (WebCore::Node::approximateMemoryCost): Define this new virtual function in the 22 Node class. Its default value is sizeof(Node) but any descendant can return a 23 more accurate number. 24 25 * platform/graphics/Image.h: 26 (WebCore::Image::data): Define a const version of data() so it can be called 27 the const function SVGImage::reportApproximateMemoryCost(). 28 29 * svg/SVGGraphicsElement.h: Override approximateMemoryCost() to return 30 sizeof(SVGGraphicsElement). 31 32 * svg/SVGPathElement.cpp: 33 (WebCore::SVGPathElement::approximateMemoryCost): Override this function to return 34 the memory cost of the points and the m_path of the renderer. 35 * svg/SVGPathElement.h: 36 37 * svg/SVGPolyElement.cpp: 38 (WebCore::SVGPolyElement::approximateMemoryCost): Override this function to return 39 the memory cost of the points and the m_path of the renderer. 40 * svg/SVGPolyElement.h: 41 42 * svg/graphics/SVGImage.cpp: 43 (WebCore::SVGImage::reportApproximateMemoryCost): Calculate the memory cost of the 44 nodes in the SVGDocument of an SVGImage. Then report this number to the JS garbage 45 collector. 46 47 (WebCore::SVGImage::dataChanged): After loading all the SVG encoded data and building 48 its DOM tree and the render tree, report the total memory cost to the JS garbage collector. 49 * svg/graphics/SVGImage.h: 50 1 51 2016-06-01 Andreas Kling <akling@apple.com> 2 52 -
trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp
r201129 r201561 90 90 return; 91 91 92 size_t nodeCount = 0;92 size_t memoryCost = 0; 93 93 for (Node* node = &document; node; node = NodeTraversal::next(*node)) 94 ++nodeCount;94 memoryCost += node->approximateMemoryCost(); 95 95 96 96 // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated. 97 97 // https://bugs.webkit.org/show_bug.cgi?id=142595 98 state.heap()->deprecatedReportExtraMemory( nodeCount * sizeof(Node));98 state.heap()->deprecatedReportExtraMemory(memoryCost); 99 99 } 100 100 -
trunk/Source/WebCore/dom/Node.h
r201305 r201561 144 144 virtual void setNodeValue(const String&, ExceptionCode&); 145 145 virtual NodeType nodeType() const = 0; 146 virtual size_t approximateMemoryCost() const { return sizeof(*this); } 146 147 ContainerNode* parentNode() const; 147 148 static ptrdiff_t parentNodeMemoryOffset() { return OBJECT_OFFSETOF(Node, m_parentNode); } -
trunk/Source/WebCore/platform/graphics/Image.h
r201424 r201561 123 123 124 124 SharedBuffer* data() { return m_encodedImageData.get(); } 125 const SharedBuffer* data() const { return m_encodedImageData.get(); } 125 126 126 127 // Animation begins whenever someone draws the image, so startAnimation() is not normally called. -
trunk/Source/WebCore/svg/SVGGraphicsElement.h
r200041 r201561 54 54 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override; 55 55 56 size_t approximateMemoryCost() const override { return sizeof(*this); } 57 56 58 protected: 57 59 SVGGraphicsElement(const QualifiedName&, Document&); -
trunk/Source/WebCore/svg/SVGPathElement.cpp
r200041 r201561 364 364 } 365 365 366 size_t SVGPathElement::approximateMemoryCost() const 367 { 368 // This is an approximation for path memory cost since the path is parsed on demand. 369 size_t pathMemoryCost = (m_pathByteStream.size() / 10) * sizeof(FloatPoint); 370 // We need to account for the memory which is allocated by the RenderSVGPath::m_path. 371 return sizeof(*this) + (renderer() ? pathMemoryCost * 2 + sizeof(RenderSVGPath) : pathMemoryCost); 372 } 373 366 374 void SVGPathElement::pathSegListChanged(SVGPathSegRole role, ListModification listModification) 367 375 { -
trunk/Source/WebCore/svg/SVGPathElement.h
r200041 r201561 102 102 void animatedPropertyWillBeDeleted(); 103 103 104 size_t approximateMemoryCost() const override; 105 104 106 private: 105 107 SVGPathElement(const QualifiedName&, Document&); -
trunk/Source/WebCore/svg/SVGPolyElement.cpp
r196268 r201561 131 131 } 132 132 133 size_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); 133 138 } 139 140 } -
trunk/Source/WebCore/svg/SVGPolyElement.h
r197563 r201561 39 39 static const SVGPropertyInfo* pointsPropertyInfo(); 40 40 41 size_t approximateMemoryCost() const override; 42 41 43 protected: 42 44 SVGPolyElement(const QualifiedName&, Document&); -
trunk/Source/WebCore/svg/graphics/SVGImage.cpp
r198655 r201561 30 30 31 31 #include "Chrome.h" 32 #include "DOMWindow.h" 32 33 #include "DocumentLoader.h" 33 34 #include "ElementIterator.h" … … 37 38 #include "ImageObserver.h" 38 39 #include "IntRect.h" 40 #include "JSDOMWindowBase.h" 39 41 #include "MainFrame.h" 40 42 #include "PageConfiguration.h" … … 49 51 #include "Settings.h" 50 52 #include "TextStream.h" 53 #include <runtime/JSCInlines.h> 54 #include <runtime/JSLock.h> 51 55 52 56 namespace WebCore { … … 354 358 } 355 359 360 void SVGImage::reportApproximateMemoryCost() const 361 { 362 Document* document = m_page->mainFrame().document(); 363 size_t decodedImageMemoryCost = 0; 364 365 for (Node* node = document; node; node = NodeTraversal::next(*node)) 366 decodedImageMemoryCost += node->approximateMemoryCost(); 367 368 JSC::VM& vm = JSDOMWindowBase::commonVM(); 369 JSC::JSLockHolder lock(vm); 370 // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated. 371 // https://bugs.webkit.org/show_bug.cgi?id=142595 372 vm.heap.deprecatedReportExtraMemory(decodedImageMemoryCost + data()->size()); 373 } 374 356 375 bool SVGImage::dataChanged(bool allDataReceived) 357 376 { … … 394 413 // Set the intrinsic size before a container size is available. 395 414 m_intrinsicSize = containerSize(); 415 reportApproximateMemoryCost(); 396 416 } 397 417 -
trunk/Source/WebCore/svg/graphics/SVGImage.h
r198655 r201561 83 83 void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) override; 84 84 85 void reportApproximateMemoryCost() const; 85 86 bool dataChanged(bool allDataReceived) override; 86 87
Note:
See TracChangeset
for help on using the changeset viewer.