author | Nicholas Nethercote <nnethercote@mozilla.com> |
Wed, 01 Jun 2016 09:18:33 +1000 | |
changeset 340843 | a584b40f1933d36ca0ca22de516b17e481761b1a |
parent 340842 | 75d948bafca38c5ce9ed9c79e3b385136ddf1abc |
child 340844 | aeca77cdf8eaa8be001f4eb17174f28c505cdd3d |
push id | 1183 |
push user | raliiev@mozilla.com |
push date | Mon, 05 Sep 2016 20:01:49 +0000 |
treeherder | mozilla-release@3148731bed45 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mccr8 |
bugs | 1276837 |
milestone | 49.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
|
--- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -363,19 +363,19 @@ public: { MOZ_ASSERT(!mSentinelAndBlocks[0].block && !mSentinelAndBlocks[1].block, "Didn't call Clear()?"); } void Clear() { - Block* b = Blocks(); + EdgeBlock* b = EdgeBlocks(); while (b) { - Block* next = b->Next(); + EdgeBlock* next = b->Next(); delete b; b = next; } mSentinelAndBlocks[0].block = nullptr; mSentinelAndBlocks[1].block = nullptr; } @@ -383,57 +383,57 @@ public: bool IsEmpty() { return !mSentinelAndBlocks[0].block && !mSentinelAndBlocks[1].block; } #endif private: - struct Block; + struct EdgeBlock; union PtrInfoOrBlock { // Use a union to avoid reinterpret_cast and the ensuing // potential aliasing bugs. PtrInfo* ptrInfo; - Block* block; + EdgeBlock* block; }; - struct Block + struct EdgeBlock { - enum { BlockSize = 16 * 1024 }; - - PtrInfoOrBlock mPointers[BlockSize]; - Block() + enum { EdgeBlockSize = 16 * 1024 }; + + PtrInfoOrBlock mPointers[EdgeBlockSize]; + EdgeBlock() { - mPointers[BlockSize - 2].block = nullptr; // sentinel - mPointers[BlockSize - 1].block = nullptr; // next block pointer + mPointers[EdgeBlockSize - 2].block = nullptr; // sentinel + mPointers[EdgeBlockSize - 1].block = nullptr; // next block pointer } - Block*& Next() + EdgeBlock*& Next() { - return mPointers[BlockSize - 1].block; + return mPointers[EdgeBlockSize - 1].block; } PtrInfoOrBlock* Start() { return &mPointers[0]; } PtrInfoOrBlock* End() { - return &mPointers[BlockSize - 2]; + return &mPointers[EdgeBlockSize - 2]; } }; // Store the null sentinel so that we can have valid iterators // before adding any edges and without adding any blocks. PtrInfoOrBlock mSentinelAndBlocks[2]; - Block*& Blocks() + EdgeBlock*& EdgeBlocks() { return mSentinelAndBlocks[1].block; } - Block* Blocks() const + EdgeBlock* EdgeBlocks() const { return mSentinelAndBlocks[1].block; } public: class Iterator { public: @@ -482,47 +482,47 @@ public: class Builder; friend class Builder; class Builder { public: explicit Builder(EdgePool& aPool) : mCurrent(&aPool.mSentinelAndBlocks[0]) , mBlockEnd(&aPool.mSentinelAndBlocks[0]) - , mNextBlockPtr(&aPool.Blocks()) + , mNextBlockPtr(&aPool.EdgeBlocks()) { } Iterator Mark() { return Iterator(mCurrent); } void Add(PtrInfo* aEdge) { if (mCurrent == mBlockEnd) { - Block* b = new Block(); + EdgeBlock* b = new EdgeBlock(); *mNextBlockPtr = b; mCurrent = b->Start(); mBlockEnd = b->End(); mNextBlockPtr = &b->Next(); } (mCurrent++)->ptrInfo = aEdge; } private: // mBlockEnd points to space for null sentinel PtrInfoOrBlock* mCurrent; PtrInfoOrBlock* mBlockEnd; - Block** mNextBlockPtr; + EdgeBlock** mNextBlockPtr; }; size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { size_t n = 0; - Block* b = Blocks(); + EdgeBlock* b = EdgeBlocks(); while (b) { n += aMallocSizeOf(b); b = b->Next(); } return n; } }; @@ -572,17 +572,17 @@ public: MOZ_ASSERT(aParticipant); // We initialize mRefCount to a large non-zero value so // that it doesn't look like a JS object to the cycle collector // in the case where the object dies before being traversed. MOZ_ASSERT(!IsGrayJS() && !IsBlackJS()); } - // Allow NodePool::Block's constructor to compile. + // Allow NodePool::NodeBlock's constructor to compile. PtrInfo() { NS_NOTREACHED("should never be called"); } bool IsGrayJS() const { return mRefCount == 0; @@ -627,62 +627,62 @@ public: /** * A structure designed to be used like a linked list of PtrInfo, except * it allocates many PtrInfos at a time. */ class NodePool { private: - // The -2 allows us to use |BlockSize + 1| for |mEntries|, and fit |mNext|, - // all without causing slop. - enum { BlockSize = 4 * 1024 - 2 }; - - struct Block + // The -2 allows us to use |NodeBlockSize + 1| for |mEntries|, and fit + // |mNext|, all without causing slop. + enum { NodeBlockSize = 4 * 1024 - 2 }; + + struct NodeBlock { - // We create and destroy Block using moz_xmalloc/free rather - // than new and delete to avoid calling its constructor and - // destructor. - Block() + // We create and destroy NodeBlock using moz_xmalloc/free rather than new + // and delete to avoid calling its constructor and destructor. + NodeBlock() { NS_NOTREACHED("should never be called"); - // Ensure Block is the right size (see the comment on BlockSize above). + // Ensure NodeBlock is the right size (see the comment on NodeBlockSize + // above). static_assert( - sizeof(Block) == 81904 || // 32-bit; equals 19.996 x 4 KiB pages - sizeof(Block) == 131048, // 64-bit; equals 31.994 x 4 KiB pages - "ill-sized NodePool::Block" + sizeof(NodeBlock) == 81904 || // 32-bit; equals 19.996 x 4 KiB pages + sizeof(NodeBlock) == 131048, // 64-bit; equals 31.994 x 4 KiB pages + "ill-sized NodeBlock" ); } - ~Block() + ~NodeBlock() { NS_NOTREACHED("should never be called"); } - Block* mNext; - PtrInfo mEntries[BlockSize + 1]; // +1 to store last child of last node + NodeBlock* mNext; + PtrInfo mEntries[NodeBlockSize + 1]; // +1 to store last child of last node }; public: NodePool() : mBlocks(nullptr) , mLast(nullptr) { } ~NodePool() { MOZ_ASSERT(!mBlocks, "Didn't call Clear()?"); } void Clear() { - Block* b = mBlocks; + NodeBlock* b = mBlocks; while (b) { - Block* n = b->mNext; + NodeBlock* n = b->mNext; free(b); b = n; } mBlocks = nullptr; mLast = nullptr; } @@ -703,31 +703,31 @@ public: , mNext(aPool.mLast) , mBlockEnd(nullptr) { MOZ_ASSERT(!aPool.mBlocks && !aPool.mLast, "pool not empty"); } PtrInfo* Add(void* aPointer, nsCycleCollectionParticipant* aParticipant) { if (mNext == mBlockEnd) { - Block* block = static_cast<Block*>(malloc(sizeof(Block))); + NodeBlock* block = static_cast<NodeBlock*>(malloc(sizeof(NodeBlock))); if (!block) { return nullptr; } *mNextBlock = block; mNext = block->mEntries; - mBlockEnd = block->mEntries + BlockSize; + mBlockEnd = block->mEntries + NodeBlockSize; block->mNext = nullptr; mNextBlock = &block->mNext; } return new (mNext++) PtrInfo(aPointer, aParticipant); } private: - Block** mNextBlock; + NodeBlock** mNextBlock; PtrInfo*& mNext; PtrInfo* mBlockEnd; }; class Enumerator; friend class Enumerator; class Enumerator { @@ -750,50 +750,50 @@ public: { return mNext == mBlockEnd; } PtrInfo* GetNext() { MOZ_ASSERT(!IsDone(), "calling GetNext when done"); if (mNext == mBlockEnd) { - Block* nextBlock = mCurBlock ? mCurBlock->mNext : mFirstBlock; + NodeBlock* nextBlock = mCurBlock ? mCurBlock->mNext : mFirstBlock; mNext = nextBlock->mEntries; - mBlockEnd = mNext + BlockSize; + mBlockEnd = mNext + NodeBlockSize; mCurBlock = nextBlock; } return mNext++; } private: // mFirstBlock is a reference to allow an Enumerator to be constructed // for an empty graph. - Block*& mFirstBlock; - Block* mCurBlock; + NodeBlock*& mFirstBlock; + NodeBlock* mCurBlock; // mNext is the next value we want to return, unless mNext == mBlockEnd // NB: mLast is a reference to allow enumerating while building! PtrInfo* mNext; PtrInfo* mBlockEnd; PtrInfo*& mLast; }; size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { // We don't measure the things pointed to by mEntries[] because those // pointers are non-owning. size_t n = 0; - Block* b = mBlocks; + NodeBlock* b = mBlocks; while (b) { n += aMallocSizeOf(b); b = b->mNext; } return n; } private: - Block* mBlocks; + NodeBlock* mBlocks; PtrInfo* mLast; }; // Declarations for mPtrToNodeMap. struct PtrToNodeEntry : public PLDHashEntryHdr { @@ -987,33 +987,33 @@ struct nsPurpleBufferEntry nsCycleCollectionParticipant* mParticipant; // nullptr for nsISupports }; class nsCycleCollector; struct nsPurpleBuffer { private: - struct Block + struct PurpleBlock { - Block* mNext; + PurpleBlock* mNext; // Try to match the size of a jemalloc bucket, to minimize slop bytes. // - On 32-bit platforms sizeof(nsPurpleBufferEntry) is 12, so mEntries // is 16,380 bytes, which leaves 4 bytes for mNext. // - On 64-bit platforms sizeof(nsPurpleBufferEntry) is 24, so mEntries // is 32,544 bytes, which leaves 8 bytes for mNext. nsPurpleBufferEntry mEntries[1365]; - Block() : mNext(nullptr) + PurpleBlock() : mNext(nullptr) { - // Ensure Block is the right size (see above). + // Ensure PurpleBlock is the right size (see above). static_assert( - sizeof(Block) == 16384 || // 32-bit - sizeof(Block) == 32768, // 64-bit - "ill-sized nsPurpleBuffer::Block" + sizeof(PurpleBlock) == 16384 || // 32-bit + sizeof(PurpleBlock) == 32768, // 64-bit + "ill-sized nsPurpleBuffer::PurpleBlock" ); } template<class PurpleVisitor> void VisitEntries(nsPurpleBuffer& aBuffer, PurpleVisitor& aVisitor) { nsPurpleBufferEntry* eEnd = ArrayEnd(mEntries); for (nsPurpleBufferEntry* e = mEntries; e != eEnd; ++e) { @@ -1023,46 +1023,46 @@ private: } } } }; // This class wraps a linked list of the elements in the purple // buffer. uint32_t mCount; - Block mFirstBlock; + PurpleBlock mFirstBlock; nsPurpleBufferEntry* mFreeList; public: nsPurpleBuffer() { InitBlocks(); } ~nsPurpleBuffer() { FreeBlocks(); } template<class PurpleVisitor> void VisitEntries(PurpleVisitor& aVisitor) { - for (Block* b = &mFirstBlock; b; b = b->mNext) { + for (PurpleBlock* b = &mFirstBlock; b; b = b->mNext) { b->VisitEntries(*this, aVisitor); } } void InitBlocks() { mCount = 0; mFreeList = nullptr; StartBlock(&mFirstBlock); } - void StartBlock(Block* aBlock) + void StartBlock(PurpleBlock* aBlock) { MOZ_ASSERT(!mFreeList, "should not have free list"); // Put all the entries in the block on the free list. nsPurpleBufferEntry* entries = aBlock->mEntries; mFreeList = entries; for (uint32_t i = 1; i < ArrayLength(aBlock->mEntries); ++i) { entries[i - 1].mNextInFreeList = @@ -1072,22 +1072,22 @@ public: (nsPurpleBufferEntry*)1; } void FreeBlocks() { if (mCount > 0) { UnmarkRemainingPurple(&mFirstBlock); } - Block* b = mFirstBlock.mNext; + PurpleBlock* b = mFirstBlock.mNext; while (b) { if (mCount > 0) { UnmarkRemainingPurple(b); } - Block* next = b->mNext; + PurpleBlock* next = b->mNext; delete b; b = next; } mFirstBlock.mNext = nullptr; } struct UnmarkRemainingPurpleVisitor { @@ -1098,17 +1098,17 @@ public: aEntry->mRefCnt->RemoveFromPurpleBuffer(); aEntry->mRefCnt = nullptr; } aEntry->mObject = nullptr; --aBuffer.mCount; } }; - void UnmarkRemainingPurple(Block* aBlock) + void UnmarkRemainingPurple(PurpleBlock* aBlock) { UnmarkRemainingPurpleVisitor visitor; aBlock->VisitEntries(*this, visitor); } void SelectPointers(CCGraphBuilder& aBuilder); // RemoveSkippable removes entries from the purple buffer synchronously @@ -1121,17 +1121,17 @@ public: void RemoveSkippable(nsCycleCollector* aCollector, bool aRemoveChildlessNodes, bool aAsyncSnowWhiteFreeing, CC_ForgetSkippableCallback aCb); MOZ_ALWAYS_INLINE nsPurpleBufferEntry* NewEntry() { if (MOZ_UNLIKELY(!mFreeList)) { - Block* b = new Block; + PurpleBlock* b = new PurpleBlock; StartBlock(b); // Add the new block as the second block in the list. b->mNext = mFirstBlock.mNext; mFirstBlock.mNext = b; } nsPurpleBufferEntry* e = mFreeList; @@ -1172,17 +1172,17 @@ public: return mCount; } size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { size_t n = 0; // Don't measure mFirstBlock because it's within |this|. - const Block* block = mFirstBlock.mNext; + const PurpleBlock* block = mFirstBlock.mNext; while (block) { n += aMallocSizeOf(block); block = block->mNext; } // mFreeList is deliberately not measured because it points into // the purple buffer, which is within mFirstBlock and thus within |this|. //