Bug 822148 (part 3) - DMD: Rename |LiveBlock| as |Block|. r=jlebar.

--HG--
extra : rebase_source : 65ccba830ca872fd28a410122ebf65c12cbf6377
This commit is contained in:
Nicholas Nethercote 2012-12-17 19:56:51 -08:00
parent 1cf85ccdfe
commit 6c71e7b725
3 changed files with 32 additions and 38 deletions

View File

@ -366,7 +366,7 @@ public:
}; };
// This lock must be held while manipulating global state, such as // This lock must be held while manipulating global state, such as
// gStackTraceTable, gLiveBlockTable, etc. // gStackTraceTable, gBlockTable, etc.
static Mutex* gStateLock = nullptr; static Mutex* gStateLock = nullptr;
class AutoLockState class AutoLockState
@ -865,7 +865,7 @@ public:
}; };
// A live heap block. // A live heap block.
class LiveBlock class Block
{ {
const void* mPtr; const void* mPtr;
const size_t mReqSize; // size requested const size_t mReqSize; // size requested
@ -883,13 +883,13 @@ class LiveBlock
// allocation? If so, DMD must not clear the report at the end of Dump(). // allocation? If so, DMD must not clear the report at the end of Dump().
// Only relevant if |mReportStackTrace| is non-nullptr. // Only relevant if |mReportStackTrace| is non-nullptr.
// //
// |mPtr| is used as the key in LiveBlockTable, so it's ok for this member // |mPtr| is used as the key in BlockTable, so it's ok for this member
// to be |mutable|. // to be |mutable|.
mutable TaggedPtr<const StackTrace*> mReportStackTrace_mReportedOnAlloc[2]; mutable TaggedPtr<const StackTrace*> mReportStackTrace_mReportedOnAlloc[2];
public: public:
LiveBlock(const void* aPtr, size_t aReqSize, Block(const void* aPtr, size_t aReqSize, const StackTrace* aAllocStackTrace,
const StackTrace* aAllocStackTrace, bool aSampled) bool aSampled)
: mPtr(aPtr), : mPtr(aPtr),
mReqSize(aReqSize), mReqSize(aReqSize),
mAllocStackTrace_mSampled(aAllocStackTrace, aSampled), mAllocStackTrace_mSampled(aAllocStackTrace, aSampled),
@ -985,15 +985,14 @@ public:
return mozilla::HashGeneric(aPtr); return mozilla::HashGeneric(aPtr);
} }
static bool match(const LiveBlock& aB, const void* const& aPtr) static bool match(const Block& aB, const void* const& aPtr)
{ {
return aB.mPtr == aPtr; return aB.mPtr == aPtr;
} }
}; };
// Nb: js::DefaultHasher<void*> is a high quality hasher. typedef js::HashSet<Block, Block, InfallibleAllocPolicy> BlockTable;
typedef js::HashSet<LiveBlock, LiveBlock, InfallibleAllocPolicy> LiveBlockTable; static BlockTable* gBlockTable = nullptr;
static LiveBlockTable* gLiveBlockTable = nullptr;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// malloc/free callbacks // malloc/free callbacks
@ -1025,14 +1024,13 @@ AllocCallback(void* aPtr, size_t aReqSize, Thread* aT)
if (gSmallBlockActualSizeCounter >= gSampleBelowSize) { if (gSmallBlockActualSizeCounter >= gSampleBelowSize) {
gSmallBlockActualSizeCounter -= gSampleBelowSize; gSmallBlockActualSizeCounter -= gSampleBelowSize;
LiveBlock b(aPtr, gSampleBelowSize, StackTrace::Get(aT), Block b(aPtr, gSampleBelowSize, StackTrace::Get(aT), /* sampled */ true);
/* sampled */ true); (void)gBlockTable->putNew(aPtr, b);
(void)gLiveBlockTable->putNew(aPtr, b);
} }
} else { } else {
// If this block size is larger than the sample size, record it exactly. // If this block size is larger than the sample size, record it exactly.
LiveBlock b(aPtr, aReqSize, StackTrace::Get(aT), /* sampled */ false); Block b(aPtr, aReqSize, StackTrace::Get(aT), /* sampled */ false);
(void)gLiveBlockTable->putNew(aPtr, b); (void)gBlockTable->putNew(aPtr, b);
} }
} }
@ -1048,7 +1046,7 @@ FreeCallback(void* aPtr, Thread* aT)
AutoLockState lock; AutoLockState lock;
AutoBlockIntercepts block(aT); AutoBlockIntercepts block(aT);
gLiveBlockTable->remove(aPtr); gBlockTable->remove(aPtr);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -1205,7 +1203,7 @@ protected:
const StackTrace* const mReportStackTrace2; // nullptr if not 2x-reported const StackTrace* const mReportStackTrace2; // nullptr if not 2x-reported
public: public:
BlockGroupKey(const LiveBlock& aB) BlockGroupKey(const Block& aB)
: mAllocStackTrace(aB.AllocStackTrace()), : mAllocStackTrace(aB.AllocStackTrace()),
mReportStackTrace1(aB.ReportStackTrace1()), mReportStackTrace1(aB.ReportStackTrace1()),
mReportStackTrace2(aB.ReportStackTrace2()) mReportStackTrace2(aB.ReportStackTrace2())
@ -1253,7 +1251,7 @@ public:
bool IsSampled() const { return mSampled; } bool IsSampled() const { return mSampled; }
void Add(const LiveBlock& aB) void Add(const Block& aB)
{ {
mReq += aB.ReqSize(); mReq += aB.ReqSize();
mSlop += aB.SlopSize(); mSlop += aB.SlopSize();
@ -1292,7 +1290,7 @@ class BlockGroup : public BlockGroupKey
// The BlockGroupKey base class serves as the key in BlockGroupTables. These // The BlockGroupKey base class serves as the key in BlockGroupTables. These
// two fields constitute the value, so it's ok for them to be |mutable|. // two fields constitute the value, so it's ok for them to be |mutable|.
mutable uint32_t mNumBlocks; // number of blocks with this LiveBlockKey mutable uint32_t mNumBlocks; // number of blocks with this BlockGroupKey
mutable GroupSize mGroupSize; // combined size of those blocks mutable GroupSize mGroupSize; // combined size of those blocks
public: public:
@ -1305,7 +1303,7 @@ public:
const GroupSize& GetGroupSize() const { return mGroupSize; } const GroupSize& GetGroupSize() const { return mGroupSize; }
// This is |const| thanks to the |mutable| fields above. // This is |const| thanks to the |mutable| fields above.
void Add(const LiveBlock& aB) const void Add(const Block& aB) const
{ {
mNumBlocks++; mNumBlocks++;
mGroupSize.Add(aB); mGroupSize.Add(aB);
@ -1674,8 +1672,8 @@ Init(const malloc_table_t* aMallocTable)
gStackTraceTable = InfallibleAllocPolicy::new_<StackTraceTable>(); gStackTraceTable = InfallibleAllocPolicy::new_<StackTraceTable>();
gStackTraceTable->init(8192); gStackTraceTable->init(8192);
gLiveBlockTable = InfallibleAllocPolicy::new_<LiveBlockTable>(); gBlockTable = InfallibleAllocPolicy::new_<BlockTable>();
gLiveBlockTable->init(8192); gBlockTable->init(8192);
if (gMode == Test) { if (gMode == Test) {
// OpenTestOrStressFile() can allocate. So do this before setting // OpenTestOrStressFile() can allocate. So do this before setting
@ -1721,7 +1719,7 @@ ReportHelper(const void* aPtr, bool aReportedOnAlloc)
AutoBlockIntercepts block(t); AutoBlockIntercepts block(t);
AutoLockState lock; AutoLockState lock;
if (LiveBlockTable::Ptr p = gLiveBlockTable->lookup(aPtr)) { if (BlockTable::Ptr p = gBlockTable->lookup(aPtr)) {
p->Report(t, aReportedOnAlloc); p->Report(t, aReportedOnAlloc);
} else { } else {
// We have no record of the block. Do nothing. Either: // We have no record of the block. Do nothing. Either:
@ -1873,7 +1871,7 @@ SizeOf(Sizes* aSizes)
aSizes->mStackTraceTable = aSizes->mStackTraceTable =
gStackTraceTable->sizeOfIncludingThis(MallocSizeOf); gStackTraceTable->sizeOfIncludingThis(MallocSizeOf);
aSizes->mLiveBlockTable = gLiveBlockTable->sizeOfIncludingThis(MallocSizeOf); aSizes->mBlockTable = gBlockTable->sizeOfIncludingThis(MallocSizeOf);
} }
static void static void
@ -1881,9 +1879,7 @@ ClearGlobalState()
{ {
// Unreport all blocks, except those that were reported on allocation, // Unreport all blocks, except those that were reported on allocation,
// because they need to keep their reported marking. // because they need to keep their reported marking.
for (LiveBlockTable::Range r = gLiveBlockTable->all(); for (BlockTable::Range r = gBlockTable->all(); !r.empty(); r.popFront()) {
!r.empty();
r.popFront()) {
r.front().UnreportIfNotReportedOnAlloc(); r.front().UnreportIfNotReportedOnAlloc();
} }
} }
@ -1920,10 +1916,8 @@ Dump(Writer aWriter)
bool anyBlocksSampled = false; bool anyBlocksSampled = false;
for (LiveBlockTable::Range r = gLiveBlockTable->all(); for (BlockTable::Range r = gBlockTable->all(); !r.empty(); r.popFront()) {
!r.empty(); const Block& b = r.front();
r.popFront()) {
const LiveBlock& b = r.front();
BlockGroupTable* table; BlockGroupTable* table;
uint32_t numReports = b.NumReports(); uint32_t numReports = b.NumReports();
@ -2005,10 +1999,10 @@ Dump(Writer aWriter)
Show(gStackTraceTable->capacity(), gBuf2, kBufLen), Show(gStackTraceTable->capacity(), gBuf2, kBufLen),
Show(gStackTraceTable->count(), gBuf3, kBufLen)); Show(gStackTraceTable->count(), gBuf3, kBufLen));
W(" Live block table: %10s bytes (%s entries, %s used)\n", W(" Block table: %10s bytes (%s entries, %s used)\n",
Show(sizes.mLiveBlockTable, gBuf1, kBufLen), Show(sizes.mBlockTable, gBuf1, kBufLen),
Show(gLiveBlockTable->capacity(), gBuf2, kBufLen), Show(gBlockTable->capacity(), gBuf2, kBufLen),
Show(gLiveBlockTable->count(), gBuf3, kBufLen)); Show(gBlockTable->count(), gBuf3, kBufLen));
W("\nData structures that are destroyed after Dump() ends:\n"); W("\nData structures that are destroyed after Dump() ends:\n");
@ -2234,7 +2228,7 @@ RunTestMode(FILE* fp)
//--------- //---------
// Clear all knowledge of existing blocks to give us a clean slate. // Clear all knowledge of existing blocks to give us a clean slate.
gLiveBlockTable->clear(); gBlockTable->clear();
// Reset the counter just in case |sample-size| was specified in $DMD. // Reset the counter just in case |sample-size| was specified in $DMD.
// Otherwise the assertions fail. // Otherwise the assertions fail.

View File

@ -54,7 +54,7 @@ struct Sizes
{ {
size_t mStackTraces; size_t mStackTraces;
size_t mStackTraceTable; size_t mStackTraceTable;
size_t mLiveBlockTable; size_t mBlockTable;
Sizes() { Clear(); } Sizes() { Clear(); }
void Clear() { memset(this, 0, sizeof(Sizes)); } void Clear() { memset(this, 0, sizeof(Sizes)); }

View File

@ -604,8 +604,8 @@ public:
sizes.mStackTraceTable, sizes.mStackTraceTable,
"Memory used by DMD's stack trace table."); "Memory used by DMD's stack trace table.");
REPORT("explicit/dmd/live-block-table", REPORT("explicit/dmd/block-table",
sizes.mLiveBlockTable, sizes.mBlockTable,
"Memory used by DMD's live block table."); "Memory used by DMD's live block table.");
#undef REPORT #undef REPORT