Bug 1557430 - Add memory reporters for SVG mapped attribute declarations. r=njn,heycam

These are owned by the element and not referenced from the stylesheets.

They're referenced from the rule tree, but the rule nodes don't measure their
style source (since they're non-owning).

So unconditionally reporting them even though it's a refcounted object is ok.

While at it, remove some other fields from the old style system that are no
longer used.

Differential Revision: https://phabricator.services.mozilla.com/D34014

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-06-08 18:58:57 +00:00
parent ee806041c6
commit 351d40e7c3
7 changed files with 62 additions and 18 deletions

View File

@ -332,6 +332,9 @@ static void CollectWindowReports(nsGlobalWindowInner* aWindow,
REPORT_SIZE("/layout/style-sheets", mLayoutStyleSheetsSize,
"Memory used by document style sheets within a window.");
REPORT_SIZE("/layout/svg-mapped-declarations", mLayoutSvgMappedDeclarations,
"Memory used by mapped declarations of SVG elements");
REPORT_SIZE("/layout/shadow-dom/style-sheets",
mLayoutShadowDomStyleSheetsSize,
"Memory used by Shadow DOM style sheets within a window.");
@ -416,12 +419,6 @@ static void CollectWindowReports(nsGlobalWindowInner* aWindow,
REPORT_SIZE("/layout/line-boxes", mArenaSizes.mLineBoxes,
"Memory used by line boxes within a window.");
REPORT_SIZE("/layout/rule-nodes", mArenaSizes.mRuleNodes,
"Memory used by CSS rule nodes within a window.");
REPORT_SIZE("/layout/style-contexts", mArenaSizes.mComputedStyles,
"Memory used by ComputedStyles within a window.");
// There are many different kinds of style structs, but it is likely that
// only a few matter. Implement a cutoff so we don't bloat about:memory with
// many uninteresting entries.
@ -645,14 +642,6 @@ nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
windowTotalSizes.mArenaSizes.mLineBoxes,
"This is the sum of all windows' 'layout/line-boxes' numbers.");
REPORT("window-objects/layout/rule-nodes",
windowTotalSizes.mArenaSizes.mRuleNodes,
"This is the sum of all windows' 'layout/rule-nodes' numbers.");
REPORT("window-objects/layout/style-contexts",
windowTotalSizes.mArenaSizes.mComputedStyles,
"This is the sum of all windows' 'layout/style-contexts' numbers.");
size_t frameTotal = 0;
#define FRAME_ID(classname, ...) \
frameTotal += windowTotalSizes.mArenaSizes.NS_ARENA_SIZES_FIELD(classname);

View File

@ -87,10 +87,7 @@ struct nsStyleSizes {
#define NS_ARENA_SIZES_FIELD(classname) mArena##classname
struct nsArenaSizes {
#define FOR_EACH_SIZE(MACRO) \
MACRO(Other, mLineBoxes) \
MACRO(Style, mRuleNodes) \
MACRO(Style, mComputedStyles)
#define FOR_EACH_SIZE(MACRO) MACRO(Other, mLineBoxes)
nsArenaSizes()
: FOR_EACH_SIZE(ZERO_SIZE)
@ -170,6 +167,7 @@ class nsWindowSizes {
MACRO(Style, mLayoutComputedValuesDom) \
MACRO(Style, mLayoutComputedValuesNonDom) \
MACRO(Style, mLayoutComputedValuesVisited) \
MACRO(Style, mLayoutSvgMappedDeclarations) \
MACRO(Other, mPropertyTablesSize) \
MACRO(Other, mBindingsSize)

View File

@ -2375,5 +2375,20 @@ void SVGElement::FlushAnimations() {
}
}
void SVGElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
size_t* aNodeSize) const {
Element::AddSizeOfExcludingThis(aSizes, aNodeSize);
// These are owned by the element and not referenced from the stylesheets.
// They're referenced from the rule tree, but the rule nodes don't measure
// their style source (since they're non-owning), so unconditionally reporting
// them even though it's a refcounted object is ok.
if (mContentDeclarationBlock) {
aSizes.mLayoutSvgMappedDeclarations +=
mContentDeclarationBlock->SizeofIncludingThis(
aSizes.mState.mMallocSizeOf);
}
}
} // namespace dom
} // namespace mozilla

View File

@ -79,6 +79,8 @@ class SVGElement : public SVGElementBase // nsIContent
// nsISupports
NS_INLINE_DECL_REFCOUNTING_INHERITED(SVGElement, SVGElementBase)
NS_DECL_ADDSIZEOFEXCLUDINGTHIS
void DidAnimateClass();
// nsIContent interface methods

View File

@ -10,6 +10,7 @@
#include "mozilla/ServoBindings.h"
#include "nsCSSProps.h"
#include "nsIMemoryReporter.h"
namespace mozilla {
@ -24,6 +25,17 @@ already_AddRefed<DeclarationBlock> DeclarationBlock::FromCssText(
return decl.forget();
}
MOZ_DEFINE_MALLOC_SIZE_OF(ServoDeclarationBlockMallocSizeOf)
MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoDeclarationBlockEnclosingSizeOf)
size_t DeclarationBlock::SizeofIncludingThis(MallocSizeOf aMallocSizeOf) {
size_t n = aMallocSizeOf(this);
n += Servo_DeclarationBlock_SizeOfIncludingThis(
ServoDeclarationBlockMallocSizeOf, ServoDeclarationBlockEnclosingSizeOf,
mRaw.get());
return n;
}
bool DeclarationBlock::OwnerIsReadOnly() const {
css::Rule* rule = GetOwningRule();
return rule && rule->IsReadOnly();

View File

@ -141,6 +141,8 @@ class DeclarationBlock final {
bool IsReadOnly() const;
size_t SizeofIncludingThis(MallocSizeOf);
static already_AddRefed<DeclarationBlock> FromCssText(
const nsAString& aCssText, URLExtraData* aExtraData,
nsCompatibility aMode, css::Loader* aLoader);

View File

@ -1540,6 +1540,32 @@ pub unsafe extern "C" fn Servo_AuthorStyles_Flush(
styles.flush::<GeckoElement>(stylist.device(), stylist.quirks_mode(), &guard);
}
#[no_mangle]
pub unsafe extern "C" fn Servo_DeclarationBlock_SizeOfIncludingThis(
malloc_size_of: GeckoMallocSizeOf,
malloc_enclosing_size_of: GeckoMallocSizeOf,
declarations: &RawServoDeclarationBlock,
) -> usize {
use malloc_size_of::MallocSizeOf;
use malloc_size_of::MallocUnconditionalShallowSizeOf;
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
let mut ops = MallocSizeOfOps::new(
malloc_size_of.unwrap(),
Some(malloc_enclosing_size_of.unwrap()),
None,
);
Locked::<PropertyDeclarationBlock>::as_arc(&declarations).with_arc(|declarations| {
let mut n = 0;
n += declarations.unconditional_shallow_size_of(&mut ops);
n += declarations.read_with(&guard).size_of(&mut ops);
n
})
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AuthorStyles_SizeOfIncludingThis(
malloc_size_of: GeckoMallocSizeOf,