Bug 675641: Enumerate nsIStyleRuleProcessors in about:memory. r=bz
authorKyle Huey <khuey@kylehuey.com>
Mon, 01 Aug 2011 14:25:20 -0400
changeset 73675 94aa13f4a1a6a63e95640a7551be992b59d80457
parent 73674 26a5993c1193bfc2e465114d8b59eb6536117026
child 73676 fa54a739294bf6ae1df98ec15a1308d77ecafc2d
push id20903
push userkhuey@kylehuey.com
push dateTue, 02 Aug 2011 15:33:56 +0000
treeherdermozilla-central@b1013d7d7cd8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs675641
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 675641: Enumerate nsIStyleRuleProcessors in about:memory. r=bz
content/base/src/nsDocument.cpp
layout/style/AnimationCommon.cpp
layout/style/AnimationCommon.h
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSRuleProcessor.h
layout/style/nsHTMLCSSStyleSheet.h
layout/style/nsHTMLStyleSheet.cpp
layout/style/nsHTMLStyleSheet.h
layout/style/nsIStyleRuleProcessor.h
layout/style/nsStyleSet.cpp
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -8396,12 +8396,12 @@ nsIDocument::SizeOf() const
 
   return size;
 }
 
 PRInt64
 nsDocument::SizeOf() const
 {
   PRInt64 size = MemoryReporter::GetBasicSize<nsDocument, nsIDocument>(this);
-  size += mAttrStyleSheet ? mAttrStyleSheet->SizeOf() : 0;
+  size += mAttrStyleSheet ? mAttrStyleSheet->DOMSizeOf() : 0;
   return size;
 }
 
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -121,16 +121,22 @@ CommonAnimationManager::HasAttributeDepe
 }
 
 /* virtual */ PRBool
 CommonAnimationManager::MediumFeaturesChanged(nsPresContext* aPresContext)
 {
   return PR_FALSE;
 }
 
+/* virtual */ PRInt64
+CommonAnimationManager::SizeOf() const
+{
+  return sizeof(*this);
+}
+
 /* static */ PRBool
 CommonAnimationManager::ExtractComputedValueForTransition(
                           nsCSSProperty aProperty,
                           nsStyleContext* aStyleContext,
                           nsStyleAnimation::Value& aComputedValue)
 {
   PRBool result =
     nsStyleAnimation::ExtractComputedValue(aProperty, aStyleContext,
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -66,16 +66,17 @@ public:
   NS_DECL_ISUPPORTS
 
   // nsIStyleRuleProcessor (parts)
   virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData);
   virtual PRBool HasDocumentStateDependentStyle(StateRuleProcessorData* aData);
   virtual nsRestyleHint
     HasAttributeDependentStyle(AttributeRuleProcessorData* aData);
   virtual PRBool MediumFeaturesChanged(nsPresContext* aPresContext);
+  virtual PRInt64 SizeOf() const;
 
   /**
    * Notify the manager that the pres context is going away.
    */
   void Disconnect();
 
   static PRBool ExtractComputedValueForTransition(
                   nsCSSProperty aProperty,
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -2449,16 +2449,24 @@ nsCSSRuleProcessor::MediumFeaturesChange
   // enabled).  And if there's nothing cached, it doesn't matter if
   // anything changed.  See bug 448281.
   if (old) {
     RefreshRuleCascade(aPresContext);
   }
   return (old != mRuleCascades);
 }
 
+/* virtual */ PRInt64
+nsCSSRuleProcessor::SizeOf() const
+{
+  size_t n = sizeof(*this);
+
+  return n;
+}
+
 // Append all the currently-active font face rules to aArray.  Return
 // true for success and false for failure.
 PRBool
 nsCSSRuleProcessor::AppendFontFaceRules(
                               nsPresContext *aPresContext,
                               nsTArray<nsFontFaceRuleContainer>& aArray)
 {
   RuleCascadeData* cascade = GetRuleCascade(aPresContext);
--- a/layout/style/nsCSSRuleProcessor.h
+++ b/layout/style/nsCSSRuleProcessor.h
@@ -131,16 +131,18 @@ public:
 
   virtual PRBool HasDocumentStateDependentStyle(StateRuleProcessorData* aData);
 
   virtual nsRestyleHint
     HasAttributeDependentStyle(AttributeRuleProcessorData* aData);
 
   virtual PRBool MediumFeaturesChanged(nsPresContext* aPresContext);
 
+  virtual PRInt64 SizeOf() const;
+
   // Append all the currently-active font face rules to aArray.  Return
   // true for success and false for failure.
   PRBool AppendFontFaceRules(nsPresContext* aPresContext,
                              nsTArray<nsFontFaceRuleContainer>& aArray);
 
   PRBool AppendKeyframesRules(nsPresContext* aPresContext,
                               nsTArray<nsCSSKeyframesRule*>& aArray);
 
--- a/layout/style/nsHTMLCSSStyleSheet.h
+++ b/layout/style/nsHTMLCSSStyleSheet.h
@@ -79,16 +79,17 @@ public:
 #ifdef MOZ_XUL
   virtual void RulesMatching(XULTreeRuleProcessorData* aData);
 #endif
   virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData);
   virtual PRBool HasDocumentStateDependentStyle(StateRuleProcessorData* aData);
   virtual nsRestyleHint
     HasAttributeDependentStyle(AttributeRuleProcessorData* aData);
   virtual PRBool MediumFeaturesChanged(nsPresContext* aPresContext);
+  virtual PRInt64 SizeOf() const { return sizeof(*this); }
 
 private: 
   // These are not supported and are not implemented! 
   nsHTMLCSSStyleSheet(const nsHTMLCSSStyleSheet& aCopy); 
   nsHTMLCSSStyleSheet& operator=(const nsHTMLCSSStyleSheet& aCopy); 
 
 protected:
   nsCOMPtr<nsIURI> mURL;
--- a/layout/style/nsHTMLStyleSheet.cpp
+++ b/layout/style/nsHTMLStyleSheet.cpp
@@ -306,16 +306,21 @@ nsHTMLStyleSheet::HasAttributeDependentS
 }
 
 /* virtual */ PRBool
 nsHTMLStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
 {
   return PR_FALSE;
 }
 
+/* virtual */ PRInt64
+nsHTMLStyleSheet::SizeOf() const
+{
+  return 0; // nsHTMLStyleSheets are charged to the DOM, not layout
+}
 
 /* virtual */ void
 nsHTMLStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
 {
 }
 
 /* virtual */ void
 nsHTMLStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
@@ -541,17 +546,17 @@ GetHashEntryAttributesSize(PLDHashTable*
 
   NS_ASSERTION(entry->mAttributes, "entry->mAttributes should not be null!");
   size += entry->mAttributes->SizeOf();
 
   return PL_DHASH_NEXT;
 }
 
 PRInt64
-nsHTMLStyleSheet::SizeOf() const
+nsHTMLStyleSheet::DOMSizeOf() const
 {
   PRInt64 size = sizeof(*this);
 
   size += mLinkRule ? sizeof(*mLinkRule.get()) : 0;
   size += mVisitedRule ? sizeof(*mVisitedRule.get()) : 0;
   size += mActiveRule ? sizeof(*mActiveRule.get()) : 0;
   size += mTableQuirkColorRule ? sizeof(*mTableQuirkColorRule.get()) : 0;
   size += mTableTHRule ? sizeof(*mTableTHRule.get()) : 0;
--- a/layout/style/nsHTMLStyleSheet.h
+++ b/layout/style/nsHTMLStyleSheet.h
@@ -84,30 +84,30 @@ public:
 #ifdef MOZ_XUL
   virtual void RulesMatching(XULTreeRuleProcessorData* aData);
 #endif
   virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData);
   virtual PRBool HasDocumentStateDependentStyle(StateRuleProcessorData* aData);
   virtual nsRestyleHint
     HasAttributeDependentStyle(AttributeRuleProcessorData* aData);
   virtual PRBool MediumFeaturesChanged(nsPresContext* aPresContext);
+  virtual PRInt64 SizeOf() const;
 
   nsresult Init(nsIURI* aURL, nsIDocument* aDocument);
   void Reset(nsIURI* aURL);
   nsresult SetLinkColor(nscolor aColor);
   nsresult SetActiveLinkColor(nscolor aColor);
   nsresult SetVisitedLinkColor(nscolor aColor);
 
   // Mapped Attribute management methods
   already_AddRefed<nsMappedAttributes>
     UniqueMappedAttributes(nsMappedAttributes* aMapped);
   void DropMappedAttributes(nsMappedAttributes* aMapped);
 
-  PRInt64 SizeOf() const;
-
+  PRInt64 DOMSizeOf() const;
 private: 
   // These are not supported and are not implemented! 
   nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy); 
   nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy); 
 
   ~nsHTMLStyleSheet();
 
   class HTMLColorRule;
--- a/layout/style/nsIStyleRuleProcessor.h
+++ b/layout/style/nsIStyleRuleProcessor.h
@@ -56,20 +56,20 @@ struct AnonBoxRuleProcessorData;
 #ifdef MOZ_XUL
 struct XULTreeRuleProcessorData;
 #endif
 struct StateRuleProcessorData;
 struct AttributeRuleProcessorData;
 class nsPresContext;
 
 // IID for the nsIStyleRuleProcessor interface
-// {b8e44bbe-aaac-4125-8ab2-0f42802e14ad}
+// {32612c0e-3d34-4a6f-89d9-464f6811ac13}
 #define NS_ISTYLE_RULE_PROCESSOR_IID     \
-{ 0xb8e44bbe, 0xaaac, 0x4125, \
- { 0x8a, 0xb2, 0x0f, 0x42, 0x80, 0x2e, 0x14, 0xad } }
+{ 0x32612c0e, 0x3d34, 0x4a6f, \
+  {0x89, 0xd9, 0x46, 0x4f, 0x68, 0x11, 0xac, 0x13} }
 
 
 /* The style rule processor interface is a mechanism to separate the matching
  * of style rules from style sheet instances.
  * Simple style sheets can and will act as their own processor. 
  * Sheets where rule ordering interlaces between multiple sheets, will need to 
  * share a single rule processor between them (CSS sheets do this for cascading order)
  *
@@ -149,14 +149,20 @@ public:
     HasAttributeDependentStyle(AttributeRuleProcessorData* aData) = 0;
 
   /**
    * Do any processing that needs to happen as a result of a change in
    * the characteristics of the medium, and return whether this rule
    * processor's rules have changed (e.g., because of media queries).
    */
   virtual PRBool MediumFeaturesChanged(nsPresContext* aPresContext) = 0;
+
+  /**
+   * Report the size of this style rule processor to about:memory.  A
+   * processor may return 0.
+   */
+  virtual PRInt64 SizeOf() const = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRuleProcessor,
                               NS_ISTYLE_RULE_PROCESSOR_IID)
 
 #endif /* nsIStyleRuleProcessor_h___ */
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -96,17 +96,25 @@ nsStyleSet::nsStyleSet()
     mInReconstruct(PR_FALSE),
     mDirty(0)
 {
 }
 
 size_t
 nsStyleSet::SizeOf() const
 {
-  return sizeof(*this);
+  size_t n = sizeof(*this);
+
+  for (int i = 0; i < eSheetTypeCount; i++) {
+    if (mRuleProcessors[i]) {
+      n += mRuleProcessors[i]->SizeOf();
+    }
+  }
+
+  return n;
 }
 
 nsresult
 nsStyleSet::Init(nsPresContext *aPresContext)
 {
   mFirstLineRule = new nsEmptyStyleRule;
   mFirstLetterRule = new nsEmptyStyleRule;
   if (!mFirstLineRule || !mFirstLetterRule) {