Bug 1486480. Add memory reporting for custom element data. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D4350
This commit is contained in:
Boris Zbarsky 2018-08-27 19:20:53 +00:00
Родитель 51f81819e8
Коммит bd242c33f1
5 изменённых файлов: 128 добавлений и 2 удалений

Просмотреть файл

@ -42,6 +42,13 @@ public:
aCb.NoteNativeChild(mDefinition,
NS_CYCLE_COLLECTION_PARTICIPANT(CustomElementDefinition));
}
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
{
// We don't really own mDefinition.
return aMallocSizeOf(this);
}
private:
virtual void Invoke(Element* aElement, ErrorResult& aRv) override
{
@ -67,6 +74,15 @@ class CustomElementCallbackReaction final : public CustomElementReaction
mCustomElementCallback->Traverse(aCb);
}
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
{
size_t n = aMallocSizeOf(this);
n += mCustomElementCallback->SizeOfIncludingThis(aMallocSizeOf);
return n;
}
private:
virtual void Invoke(Element* aElement, ErrorResult& aRv) override
{
@ -79,6 +95,16 @@ class CustomElementCallbackReaction final : public CustomElementReaction
//-----------------------------------------------------
// CustomElementCallback
size_t
LifecycleCallbackArgs::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = name.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += oldValue.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += newValue.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += namespaceURI.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
return n;
}
void
CustomElementCallback::Call()
{
@ -113,6 +139,24 @@ CustomElementCallback::Traverse(nsCycleCollectionTraversalCallback& aCb) const
aCb.NoteXPCOMChild(mCallback);
}
size_t
CustomElementCallback::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
// We don't uniquely own mThisObject.
// We own mCallback but it doesn't have any special memory reporting we can do
// for it other than report its own size.
n += aMallocSizeOf(mCallback);
n += mArgs.SizeOfExcludingThis(aMallocSizeOf);
// mAdoptedCallbackArgs doesn't really uniquely own its members.
return n;
}
CustomElementCallback::CustomElementCallback(Element* aThisObject,
nsIDocument::ElementCallbackType aCallbackType,
mozilla::dom::CallbackFunction* aCallback)
@ -214,6 +258,20 @@ CustomElementData::Unlink()
mCustomElementDefinition = nullptr;
}
size_t
CustomElementData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
n += mReactionQueue.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto& reaction : mReactionQueue) {
n += reaction->SizeOfIncludingThis(aMallocSizeOf);
}
return n;
}
//-----------------------------------------------------
// CustomElementRegistry

Просмотреть файл

@ -41,6 +41,8 @@ struct LifecycleCallbackArgs
nsString oldValue;
nsString newValue;
nsString namespaceURI;
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
};
struct LifecycleAdoptedCallbackArgs
@ -56,6 +58,7 @@ public:
nsIDocument::ElementCallbackType aCallbackType,
CallbackFunction* aCallback);
void Traverse(nsCycleCollectionTraversalCallback& aCb) const;
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
void Call();
void SetArgs(LifecycleCallbackArgs& aArgs)
{
@ -130,6 +133,7 @@ struct CustomElementData
void Traverse(nsCycleCollectionTraversalCallback& aCb) const;
void Unlink();
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
nsAtom* GetIs(Element* aElement)
{
@ -208,6 +212,7 @@ public:
virtual ~CustomElementReaction() = default;
virtual void Invoke(Element* aElement, ErrorResult& aRv) = 0;
virtual void Traverse(nsCycleCollectionTraversalCallback& aCb) const = 0;
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const = 0;
bool IsUpgradeReaction()
{

Просмотреть файл

@ -674,6 +674,14 @@ nsIContent::nsExtendedContentSlots::nsExtendedContentSlots()
nsIContent::nsExtendedContentSlots::~nsExtendedContentSlots() = default;
size_t
nsIContent::nsExtendedContentSlots::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
// For now, nothing to measure here. We don't actually own any of our
// members.
return 0;
}
FragmentOrElement::nsDOMSlots::nsDOMSlots()
: nsIContent::nsContentSlots(),
mDataset(nullptr)
@ -725,8 +733,14 @@ size_t
FragmentOrElement::nsDOMSlots::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
if (OwnsExtendedSlots()) {
n += aMallocSizeOf(GetExtendedContentSlots());
nsExtendedContentSlots* extendedSlots = GetExtendedContentSlots();
if (extendedSlots) {
if (OwnsExtendedSlots()) {
n += aMallocSizeOf(extendedSlots);
}
n += extendedSlots->SizeOfExcludingThis(aMallocSizeOf);
}
if (mAttributeMap) {
@ -800,6 +814,49 @@ FragmentOrElement::nsExtendedDOMSlots::TraverseExtendedSlots(nsCycleCollectionTr
}
}
size_t
FragmentOrElement::nsExtendedDOMSlots::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = nsIContent::nsExtendedContentSlots::SizeOfExcludingThis(aMallocSizeOf);
// We own mSMILOverrideStyle but there seems to be no memory reporting on CSS
// declarations? At least report the memory the declaration takes up
// directly.
if (mSMILOverrideStyle) {
n += aMallocSizeOf(mSMILOverrideStyle);
}
// We don't really own mSMILOverrideStyleDeclaration. mSMILOverrideStyle owns
// it.
// We don't seem to have memory reporting for nsXULControllers. At least
// report the memory it's using directly.
if (mControllers) {
n += aMallocSizeOf(mControllers);
}
// We don't seem to have memory reporting for nsLabelsNodeList. At least
// report the memory it's using directly.
if (mLabelsList) {
n += aMallocSizeOf(mLabelsList);
}
// mShadowRoot should be handled during normal DOM tree memory reporting, just
// like kids, siblings, etc.
// We don't seem to have memory reporting for nsXBLBinding. At least
// report the memory it's using directly.
if (mXBLBinding) {
n += aMallocSizeOf(mXBLBinding);
}
if (mCustomElementData) {
n += mCustomElementData->SizeOfIncludingThis(aMallocSizeOf);
}
return n;
}
FragmentOrElement::FragmentOrElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: nsIContent(aNodeInfo)
{

Просмотреть файл

@ -174,6 +174,8 @@ public:
void TraverseExtendedSlots(nsCycleCollectionTraversalCallback&) final;
void UnlinkExtendedSlots() final;
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const final;
/**
* SMIL Overridde style rules (for SMIL animation of CSS properties)
* @see Element::GetSMILOverrideStyle

Просмотреть файл

@ -797,6 +797,8 @@ protected:
virtual void TraverseExtendedSlots(nsCycleCollectionTraversalCallback&);
virtual void UnlinkExtendedSlots();
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
/**
* The nearest enclosing content node with a binding that created us.
* TODO(emilio): This should be an Element*.
@ -861,6 +863,8 @@ protected:
}
}
// OwnsExtendedSlots returns true if we have no extended slots or if we
// have extended slots and own them.
bool OwnsExtendedSlots() const
{
return !(mExtendedSlots & sNonOwningExtendedSlotsFlag);