Bug 1003479 - Fix incorrect usage of SizeOfIncludingThis and SizeOfExcludingThis functions. r=njn
authorEric Rahm <erahm@mozilla.com>
Thu, 01 May 2014 10:37:54 -0700
changeset 181607 eb14c610d90a5ca396ede261e0ec156715a092a5
parent 181606 695049af76549c433f0798327a1f17139d163b96
child 181608 6e1d2f5b54e3f42d35104cf09cad968eb1ce2e85
push id43110
push usererahm@mozilla.com
push dateMon, 05 May 2014 21:55:29 +0000
treeherdermozilla-inbound@eb14c610d90a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1003479
milestone32.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 1003479 - Fix incorrect usage of SizeOfIncludingThis and SizeOfExcludingThis functions. r=njn
content/base/src/nsDocument.cpp
content/base/src/nsPropertyTable.cpp
content/base/src/nsPropertyTable.h
content/media/AudioNodeEngine.h
content/media/webaudio/AudioBuffer.cpp
content/media/webaudio/AudioContext.cpp
content/media/webaudio/MediaBufferDecoder.cpp
content/media/webaudio/MediaBufferDecoder.h
content/media/webaudio/OscillatorNode.cpp
content/media/webaudio/PeriodicWave.cpp
content/media/webaudio/PeriodicWave.h
gfx/thebes/gfxDWriteFonts.cpp
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxGDIFont.cpp
layout/style/nsCSSValue.cpp
xpcom/glue/nsTHashtable.h
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -11895,17 +11895,17 @@ nsIDocument::DocAddSizeOfExcludingThis(n
                                        &aWindowSizes->mLayoutPresContextSize);
   }
 
   aWindowSizes->mPropertyTablesSize +=
     mPropertyTable.SizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
   for (uint32_t i = 0, count = mExtraPropertyTables.Length();
        i < count; ++i) {
     aWindowSizes->mPropertyTablesSize +=
-      mExtraPropertyTables[i]->SizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
+      mExtraPropertyTables[i]->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf);
   }
 
   if (EventListenerManager* elm = GetExistingListenerManager()) {
     aWindowSizes->mDOMEventListenersCount += elm->ListenerCount();
   }
 
   // Measurement of the following members may be added later if DMD finds it
   // is worthwhile:
--- a/content/base/src/nsPropertyTable.cpp
+++ b/content/base/src/nsPropertyTable.cpp
@@ -357,16 +357,22 @@ nsPropertyTable::SizeOfExcludingThis(moz
 
   for (PropertyList *prop = mPropertyList; prop; prop = prop->mNext) {
     n += prop->SizeOfIncludingThis(aMallocSizeOf);
   }
 
   return n;
 }
 
+size_t
+nsPropertyTable::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+}
+
 /* static */
 void
 nsPropertyTable::SupportsDtorFunc(void *aObject, nsIAtom *aPropertyName,
                                   void *aPropertyValue, void *aData)
 {
   nsISupports *propertyValue = static_cast<nsISupports*>(aPropertyValue);
   NS_IF_RELEASE(propertyValue);
 }
--- a/content/base/src/nsPropertyTable.h
+++ b/content/base/src/nsPropertyTable.h
@@ -173,16 +173,17 @@ class nsPropertyTable
    * to destroy it.
    */
   static void SupportsDtorFunc(void *aObject, nsIAtom *aPropertyName,
                                void *aPropertyValue, void *aData);
 
   class PropertyList;
 
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
  private:
   NS_HIDDEN_(void) DestroyPropertyList();
   NS_HIDDEN_(PropertyList*) GetPropertyListFor(nsIAtom *aPropertyName) const;
   NS_HIDDEN_(void*) GetPropertyInternal(nsPropertyOwner aObject,
                                         nsIAtom    *aPropertyName,
                                         bool        aRemove,
                                         nsresult   *aStatus);
--- a/content/media/AudioNodeEngine.h
+++ b/content/media/AudioNodeEngine.h
@@ -86,16 +86,21 @@ public:
     amount += mContents.SizeOfExcludingThis(aMallocSizeOf);
     for (size_t i = 0; i < mContents.Length(); i++) {
       amount += mContents[i].SizeOfExcludingThis(aMallocSizeOf);
     }
 
     return amount;
   }
 
+  virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
+  {
+    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+  }
+
 private:
   AutoFallibleTArray<Storage,2> mContents;
 };
 
 /**
  * Allocates an AudioChunk with fresh buffers of WEBAUDIO_BLOCK_SIZE float samples.
  * AudioChunk::mChannelData's entries can be cast to float* for writing.
  */
--- a/content/media/webaudio/AudioBuffer.cpp
+++ b/content/media/webaudio/AudioBuffer.cpp
@@ -230,15 +230,15 @@ AudioBuffer::GetThreadSharedChannelsForR
 }
 
 size_t
 AudioBuffer::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t amount = aMallocSizeOf(this);
   amount += mJSChannels.SizeOfExcludingThis(aMallocSizeOf);
   if (mSharedChannels) {
-    amount += mSharedChannels->SizeOfExcludingThis(aMallocSizeOf);
+    amount += mSharedChannels->SizeOfIncludingThis(aMallocSizeOf);
   }
   return amount;
 }
 
 }
 }
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -659,17 +659,17 @@ AudioContext::SizeOfIncludingThis(mozill
 
   size_t amount = aMallocSizeOf(this);
   if (mListener) {
     amount += mListener->SizeOfIncludingThis(aMallocSizeOf);
   }
   amount += mDecoder.SizeOfExcludingThis(aMallocSizeOf);
   amount += mDecodeJobs.SizeOfExcludingThis(aMallocSizeOf);
   for (uint32_t i = 0; i < mDecodeJobs.Length(); ++i) {
-    amount += mDecodeJobs[i]->SizeOfExcludingThis(aMallocSizeOf);
+    amount += mDecodeJobs[i]->SizeOfIncludingThis(aMallocSizeOf);
   }
   amount += mActiveNodes.SizeOfExcludingThis(nullptr, aMallocSizeOf);
   amount += mPannerNodes.SizeOfExcludingThis(nullptr, aMallocSizeOf);
   return amount;
 }
 
 NS_IMETHODIMP
 AudioContext::CollectReports(nsIHandleReportCallback* aHandleReport,
--- a/content/media/webaudio/MediaBufferDecoder.cpp
+++ b/content/media/webaudio/MediaBufferDecoder.cpp
@@ -579,10 +579,16 @@ WebAudioDecodeJob::SizeOfExcludingThis(M
   }
   amount += mChannelBuffers.SizeOfExcludingThis(aMallocSizeOf);
   for (uint32_t i = 0; i < mChannelBuffers.Length(); ++i) {
     amount += mChannelBuffers[i].SizeOfExcludingThis(aMallocSizeOf);
   }
   return amount;
 }
 
+size_t
+WebAudioDecodeJob::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
 }
 
+}
+
--- a/content/media/webaudio/MediaBufferDecoder.h
+++ b/content/media/webaudio/MediaBufferDecoder.h
@@ -52,16 +52,17 @@ struct WebAudioDecodeJob MOZ_FINAL
   typedef nsAutoArrayPtr<float> ChannelBuffer;
 
   void OnSuccess(ErrorCode /* ignored */);
   void OnFailure(ErrorCode aErrorCode);
 
   bool AllocateBuffer();
 
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   JS::Heap<JSObject*> mArrayBuffer;
   nsCString mContentType;
   uint32_t mWriteIndex;
   nsRefPtr<dom::AudioContext> mContext;
   nsRefPtr<dom::DecodeSuccessCallback> mSuccessCallback;
   nsRefPtr<dom::DecodeErrorCallback> mFailureCallback; // can be null
   nsRefPtr<dom::AudioBuffer> mOutput;
--- a/content/media/webaudio/OscillatorNode.cpp
+++ b/content/media/webaudio/OscillatorNode.cpp
@@ -537,17 +537,17 @@ OscillatorNode::~OscillatorNode()
 }
 
 size_t
 OscillatorNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
 
   // For now only report if we know for sure that it's not shared.
-  amount += mPeriodicWave->SizeOfExcludingThisIfNotShared(aMallocSizeOf);
+  amount += mPeriodicWave->SizeOfIncludingThisIfNotShared(aMallocSizeOf);
   amount += mFrequency->SizeOfIncludingThis(aMallocSizeOf);
   amount += mDetune->SizeOfIncludingThis(aMallocSizeOf);
   return amount;
 }
 
 size_t
 OscillatorNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
--- a/content/media/webaudio/PeriodicWave.cpp
+++ b/content/media/webaudio/PeriodicWave.cpp
@@ -52,16 +52,22 @@ PeriodicWave::SizeOfExcludingThisIfNotSh
   size_t amount = 0;
   if (!mCoefficients->IsShared()) {
     amount += mCoefficients->SizeOfIncludingThis(aMallocSizeOf);
   }
 
   return amount;
 }
 
+size_t
+PeriodicWave::SizeOfIncludingThisIfNotShared(MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThisIfNotShared(aMallocSizeOf);
+}
+
 JSObject*
 PeriodicWave::WrapObject(JSContext* aCx)
 {
   return PeriodicWaveBinding::Wrap(aCx, this);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/content/media/webaudio/PeriodicWave.h
+++ b/content/media/webaudio/PeriodicWave.h
@@ -43,16 +43,17 @@ public:
   }
 
   ThreadSharedFloatArrayBufferList* GetThreadSharedBuffer() const
   {
     return mCoefficients;
   }
 
   size_t SizeOfExcludingThisIfNotShared(MallocSizeOf aMallocSizeOf) const;
+  size_t SizeOfIncludingThisIfNotShared(MallocSizeOf aMallocSizeOf) const;
 
 private:
   nsRefPtr<AudioContext> mContext;
   nsRefPtr<ThreadSharedFloatArrayBufferList> mCoefficients;
   uint32_t mLength;
 };
 
 }
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -673,17 +673,17 @@ gfxDWriteFont::MeasureGlyphWidth(uint16_
 void
 gfxDWriteFont::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
                                       FontCacheSizes* aSizes) const
 {
     gfxFont::AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
     aSizes->mFontInstances += aMallocSizeOf(mMetrics);
     if (mGlyphWidths) {
         aSizes->mFontInstances +=
-            mGlyphWidths->SizeOfExcludingThis(nullptr, aMallocSizeOf);
+            mGlyphWidths->SizeOfIncludingThis(nullptr, aMallocSizeOf);
     }
 }
 
 void
 gfxDWriteFont::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
                                       FontCacheSizes* aSizes) const
 {
     aSizes->mFontInstances += aMallocSizeOf(this);
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -854,17 +854,17 @@ gfxFontEntry::AddSizeOfExcludingThis(Mal
 
     // cmaps are shared so only non-shared cmaps are included here
     if (mCharacterMap && mCharacterMap->mBuildOnTheFly) {
         aSizes->mCharMapsSize +=
             mCharacterMap->SizeOfIncludingThis(aMallocSizeOf);
     }
     if (mFontTableCache) {
         aSizes->mFontTableCacheSize +=
-            mFontTableCache->SizeOfExcludingThis(
+            mFontTableCache->SizeOfIncludingThis(
                 FontTableHashEntry::SizeOfEntryExcludingThis,
                 aMallocSizeOf);
     }
 }
 
 void
 gfxFontEntry::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
                                      FontListSizes* aSizes) const
@@ -4391,17 +4391,17 @@ gfxFont::AddSizeOfExcludingThis(MallocSi
                                 FontCacheSizes* aSizes) const
 {
     for (uint32_t i = 0; i < mGlyphExtentsArray.Length(); ++i) {
         aSizes->mFontInstances +=
             mGlyphExtentsArray[i]->SizeOfIncludingThis(aMallocSizeOf);
     }
     if (mWordCache) {
         aSizes->mShapedWords +=
-            mWordCache->SizeOfExcludingThis(WordCacheEntrySizeOfExcludingThis,
+            mWordCache->SizeOfIncludingThis(WordCacheEntrySizeOfExcludingThis,
                                             aMallocSizeOf);
     }
 }
 
 void
 gfxFont::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
                                 FontCacheSizes* aSizes) const
 {
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -566,17 +566,17 @@ gfxGDIFont::GetGlyphWidth(gfxContext *aC
 void
 gfxGDIFont::AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                                    FontCacheSizes* aSizes) const
 {
     gfxFont::AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
     aSizes->mFontInstances += aMallocSizeOf(mMetrics);
     if (mGlyphWidths) {
         aSizes->mFontInstances +=
-            mGlyphWidths->SizeOfExcludingThis(nullptr, aMallocSizeOf);
+            mGlyphWidths->SizeOfIncludingThis(nullptr, aMallocSizeOf);
     }
 }
 
 void
 gfxGDIFont::AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                                    FontCacheSizes* aSizes) const
 {
     aSizes->mFontInstances += aMallocSizeOf(this);
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -2411,11 +2411,11 @@ nsCSSCornerSizes::corners[4] = {
   &nsCSSCornerSizes::mBottomRight,
   &nsCSSCornerSizes::mBottomLeft,
 };
 
 size_t
 mozilla::css::GridTemplateAreasValue::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
 {
   size_t n = mNamedAreas.SizeOfExcludingThis(aMallocSizeOf);
-  n += mTemplates.SizeOfIncludingThis(aMallocSizeOf);
+  n += mTemplates.SizeOfExcludingThis(aMallocSizeOf);
   return n;
 }
--- a/xpcom/glue/nsTHashtable.h
+++ b/xpcom/glue/nsTHashtable.h
@@ -270,16 +270,27 @@ public:
   {
     if (sizeOfEntryExcludingThis) {
       s_SizeOfArgs args = { sizeOfEntryExcludingThis, userArg };
       return PL_DHashTableSizeOfExcludingThis(&mTable, s_SizeOfStub, mallocSizeOf, &args);
     }
     return PL_DHashTableSizeOfExcludingThis(&mTable, nullptr, mallocSizeOf);
   }
 
+  /**
+   * Like SizeOfExcludingThis, but includes sizeof(*this).
+   */
+  size_t SizeOfIncludingThis(SizeOfEntryExcludingThisFun sizeOfEntryExcludingThis,
+                             mozilla::MallocSizeOf mallocSizeOf,
+                             void *userArg = nullptr) const
+  {
+    return mallocSizeOf(this) +
+        SizeOfExcludingThis(sizeOfEntryExcludingThis, mallocSizeOf, userArg);
+  }
+
 #ifdef DEBUG
   /**
    * Mark the table as constant after initialization.
    *
    * This will prevent assertions when a read-only hash is accessed on multiple
    * threads without synchronization.
    */
   void MarkImmutable()