Bug 1027921 - Part 4: Add SizeOf functions. r=njn, r=froydnj
--- a/xpcom/glue/BlockingResourceBase.h
+++ b/xpcom/glue/BlockingResourceBase.h
@@ -47,16 +47,23 @@ public:
* kResourceTypeName
* Human-readable version of BlockingResourceType enum.
*/
static const char* const kResourceTypeName[];
#ifdef DEBUG
+ static size_t
+ SizeOfDeadlockDetector(MallocSizeOf aMallocSizeOf)
+ {
+ return sDeadlockDetector ?
+ sDeadlockDetector->SizeOfIncludingThis(aMallocSizeOf) : 0;
+ }
+
private:
// forward declaration for the following typedef
struct DeadlockDetectorEntry;
// ``DDT'' = ``Deadlock Detector Type''
typedef DeadlockDetector<DeadlockDetectorEntry> DDT;
/**
@@ -74,16 +81,26 @@ private:
BlockingResourceType aType)
: mName(aName)
, mType(aType)
, mAcquisitionContext(CallStack::kNone)
{
NS_ABORT_IF_FALSE(mName, "Name must be nonnull");
}
+ size_t
+ SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+ {
+ // NB: |mName| is not reported as it's expected to be a static string.
+ // If we switch to a nsString it should be added to the tally.
+ // |mAcquisitionContext| has no measurable heap allocations in it.
+ size_t n = aMallocSizeOf(this);
+ return n;
+ }
+
/**
* Print
* Write a description of this blocking resource to |aOut|. If
* the resource appears to be currently acquired, the current
* acquisition context is printed and true is returned.
* Otherwise, we print the context from |aFirstSeen|, the
* first acquisition from which the code calling |Print()|
* became interested in us, and return false. |Print()| can
--- a/xpcom/glue/DeadlockDetector.h
+++ b/xpcom/glue/DeadlockDetector.h
@@ -197,16 +197,25 @@ private:
, mOrderedLT() // FIXME bug 456272: set to empirical dep size?
, mResource(aResource)
{
}
~OrderingEntry()
{
}
+ size_t
+ SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+ {
+ size_t n = aMallocSizeOf(this);
+ n += mOrderedLT.SizeOfExcludingThis(aMallocSizeOf);
+ n += mResource->SizeOfIncludingThis(aMallocSizeOf);
+ return n;
+ }
+
CallStack mFirstSeen; // first site from which the resource appeared
HashEntryArray mOrderedLT; // this <_o Other
const T* mResource;
};
// Throwaway RAII lock to make the following code safer.
struct PRAutoLock
{
@@ -239,16 +248,33 @@ public:
*
* *NOT* thread safe.
*/
~DeadlockDetector()
{
PR_DestroyLock(mLock);
}
+ static size_t
+ SizeOfEntryExcludingThis(const T* aKey, const nsAutoPtr<OrderingEntry>& aEntry,
+ MallocSizeOf aMallocSizeOf, void* aUserArg)
+ {
+ // NB: Key is accounted for in the entry.
+ size_t n = aEntry->SizeOfIncludingThis(aMallocSizeOf);
+ return n;
+ }
+
+ size_t
+ SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+ {
+ size_t n = aMallocSizeOf(this);
+ n += mOrdering.SizeOfExcludingThis(SizeOfEntryExcludingThis, aMallocSizeOf);
+ return n;
+ }
+
/**
* Add
* Make the deadlock detector aware of |aResource|.
*
* WARNING: The deadlock detector owns |aResource|.
*
* Thread safe.
*