Bug 408720, trying to reduce MH/tpbytes, patch 3, r+sr=sicking

This commit is contained in:
Olli.Pettay@helsinki.fi 2008-01-18 05:24:57 -08:00
parent 454bb73392
commit 4cbcd550cf
2 changed files with 39 additions and 12 deletions

View File

@ -55,6 +55,12 @@
#include "plarena.h"
#include "nsMemory.h"
#define NS_SMALL_NODE_ARENA_SIZE \
(512 * (sizeof(void*)/4))
#define NS_LARGE_NODE_ARENA_SIZE \
(4096 * (sizeof(void*)/4))
#define NS_MAX_NODE_RECYCLE_SIZE \
(NS_NODE_RECYCLER_SIZE * sizeof(void*))
@ -97,9 +103,13 @@ nsDOMNodeAllocatorTester gDOMAllocatorTester;
nsDOMNodeAllocator::~nsDOMNodeAllocator()
{
if (mPool) {
PL_FinishArenaPool(mPool);
delete mPool;
if (mSmallPool) {
PL_FinishArenaPool(mSmallPool);
delete mSmallPool;
}
if (mLargePool) {
PL_FinishArenaPool(mLargePool);
delete mLargePool;
}
#ifdef DEBUG
--gDOMNodeAllocators;
@ -147,14 +157,28 @@ nsDOMNodeAllocator::Alloc(size_t aSize)
mRecyclers[index] = next;
}
if (!result) {
if (!mPool) {
mPool = new PLArenaPool();
NS_ENSURE_TRUE(mPool, nsnull);
PL_InitArenaPool(mPool, "nsDOMNodeAllocator",
4096 * (sizeof(void*)/4), 0);
if ((mSmallPoolAllocated + aSize) > NS_LARGE_NODE_ARENA_SIZE) {
if (!mLargePool) {
mLargePool = new PLArenaPool();
NS_ENSURE_TRUE(mLargePool, nsnull);
PL_InitArenaPool(mLargePool, "nsDOMNodeAllocator-large",
NS_LARGE_NODE_ARENA_SIZE, 0);
}
// Allocate a new chunk from the 'large' arena
PL_ARENA_ALLOCATE(result, mLargePool, aSize);
} else {
if (!mSmallPool) {
mSmallPool = new PLArenaPool();
NS_ENSURE_TRUE(mSmallPool, nsnull);
PL_InitArenaPool(mSmallPool, "nsDOMNodeAllocator-small",
NS_SMALL_NODE_ARENA_SIZE, 0);
}
// Allocate a new chunk from the 'small' arena
PL_ARENA_ALLOCATE(result, mSmallPool, aSize);
if (result) {
mSmallPoolAllocated += aSize;
}
}
// Allocate a new chunk from the arena
PL_ARENA_ALLOCATE(result, mPool, aSize);
}
#ifdef DEBUG
++gDOMNodeRecyclerCounters[index];

View File

@ -68,7 +68,8 @@ struct PLArenaPool;
class nsDOMNodeAllocator
{
public:
nsDOMNodeAllocator() : mPool(nsnull) {}
nsDOMNodeAllocator()
: mSmallPool(nsnull), mLargePool(nsnull), mSmallPoolAllocated(0) {}
~nsDOMNodeAllocator();
nsrefcnt AddRef()
@ -86,7 +87,9 @@ protected:
friend class nsNodeInfoManager;
nsresult Init();
nsAutoRefCnt mRefCnt;
PLArenaPool* mPool;
PLArenaPool* mSmallPool;
PLArenaPool* mLargePool;
size_t mSmallPoolAllocated;
// The recycler array points to recycled memory, where the size of
// block is index*sizeof(void*), i.e., 0, 4, 8, 12, 16, ... or 0, 8, 16, ...
void* mRecyclers[NS_NODE_RECYCLER_SIZE];