add a debug setting "MemoryPrivatePoolEnabled" to turn on/off private memory pool.

meow-7.2.2
Xiaohong Bao 2011-07-20 16:05:19 -06:00
parent f7861eaf4e
commit 48d949150c
4 changed files with 45 additions and 27 deletions

View File

@ -61,10 +61,6 @@ BOOL LLMemory::sEnableMemoryFailurePrevention = FALSE;
LLPrivateMemoryPoolManager::mem_allocation_info_t LLPrivateMemoryPoolManager::sMemAllocationTracker;
#endif
#ifndef _USE_PRIVATE_MEM_POOL_
#define _USE_PRIVATE_MEM_POOL_ 1
#endif
//static
void LLMemory::initClass()
{
@ -1386,7 +1382,7 @@ void LLPrivateMemoryPool::freeMem(void* addr)
{
return ;
}
lock() ;
LLMemoryChunk* chunk = findChunk((char*)addr) ;
@ -1789,7 +1785,7 @@ bool LLPrivateMemoryPool::fillHashTable(U16 start, U16 end, LLMemoryChunk* chunk
//--------------------------------------------------------------------
LLPrivateMemoryPoolManager* LLPrivateMemoryPoolManager::sInstance = NULL ;
LLPrivateMemoryPoolManager::LLPrivateMemoryPoolManager()
LLPrivateMemoryPoolManager::LLPrivateMemoryPoolManager(BOOL enabled)
{
mPoolList.resize(LLPrivateMemoryPool::MAX_TYPES) ;
@ -1797,6 +1793,8 @@ LLPrivateMemoryPoolManager::LLPrivateMemoryPoolManager()
{
mPoolList[i] = NULL ;
}
mPrivatePoolEnabled = enabled ;
}
LLPrivateMemoryPoolManager::~LLPrivateMemoryPoolManager()
@ -1838,13 +1836,21 @@ LLPrivateMemoryPoolManager::~LLPrivateMemoryPoolManager()
#endif
}
//static
void LLPrivateMemoryPoolManager::initClass(BOOL enabled)
{
llassert_always(!sInstance) ;
sInstance = new LLPrivateMemoryPoolManager(enabled) ;
}
//static
LLPrivateMemoryPoolManager* LLPrivateMemoryPoolManager::getInstance()
{
if(!sInstance)
{
sInstance = new LLPrivateMemoryPoolManager() ;
}
//if(!sInstance)
//{
// sInstance = new LLPrivateMemoryPoolManager(FALSE) ;
//}
return sInstance ;
}
@ -1860,6 +1866,11 @@ void LLPrivateMemoryPoolManager::destroyClass()
LLPrivateMemoryPool* LLPrivateMemoryPoolManager::newPool(S32 type)
{
if(!mPrivatePoolEnabled)
{
return NULL ;
}
if(!mPoolList[type])
{
mPoolList[type] = new LLPrivateMemoryPool(type) ;
@ -1870,7 +1881,7 @@ LLPrivateMemoryPool* LLPrivateMemoryPoolManager::newPool(S32 type)
void LLPrivateMemoryPoolManager::deletePool(LLPrivateMemoryPool* pool)
{
if(pool->isEmpty())
if(pool && pool->isEmpty())
{
mPoolList[pool->getType()] = NULL ;
delete pool;
@ -1907,7 +1918,7 @@ char* LLPrivateMemoryPoolManager::allocate(LLPrivateMemoryPool* poolp, U32 size,
{
p = poolp->allocate(size) ;
}
if(p)
{
char num[16] ;
@ -1924,18 +1935,14 @@ char* LLPrivateMemoryPoolManager::allocate(LLPrivateMemoryPool* poolp, U32 size,
//static
char* LLPrivateMemoryPoolManager::allocate(LLPrivateMemoryPool* poolp, U32 size)
{
#if _USE_PRIVATE_MEM_POOL_
if(!poolp)
if(poolp)
{
return (char*)malloc(size) ;
return poolp->allocate(size) ;
}
else
{
return poolp->allocate(size) ;
return (char*)malloc(size) ;
}
#else
return (char*)malloc(size) ;
#endif
}
#endif
@ -1951,7 +1958,6 @@ void LLPrivateMemoryPoolManager::freeMem(LLPrivateMemoryPool* poolp, void* addr
sMemAllocationTracker.erase((char*)addr) ;
#endif
#if _USE_PRIVATE_MEM_POOL_
if(poolp)
{
poolp->freeMem(addr) ;
@ -1959,10 +1965,7 @@ void LLPrivateMemoryPoolManager::freeMem(LLPrivateMemoryPool* poolp, void* addr
else
{
free(addr) ;
}
#else
free(addr) ;
#endif
}
}
//--------------------------------------------------------------------

View File

@ -367,11 +367,12 @@ private:
class LL_COMMON_API LLPrivateMemoryPoolManager
{
private:
LLPrivateMemoryPoolManager() ;
LLPrivateMemoryPoolManager(BOOL enabled) ;
~LLPrivateMemoryPoolManager() ;
public:
public:
static LLPrivateMemoryPoolManager* getInstance() ;
static void initClass(BOOL enabled) ;
static void destroyClass() ;
LLPrivateMemoryPool* newPool(S32 type) ;
@ -380,6 +381,7 @@ public:
private:
static LLPrivateMemoryPoolManager* sInstance ;
std::vector<LLPrivateMemoryPool*> mPoolList ;
BOOL mPrivatePoolEnabled;
public:
//debug and statistics info.

View File

@ -5561,7 +5561,7 @@
<key>Comment</key>
<string>If set, the viewer will quit to avoid crash when memory failure happens</string>
<key>Persist</key>
<integer>0</integer>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
@ -5578,6 +5578,17 @@
<key>Value</key>
<real>600.0</real>
</map>
<key>MemoryPrivatePoolEnabled</key>
<map>
<key>Comment</key>
<string>Enable the private memory pool management</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>0</integer>
</map>
<key>MemProfiling</key>
<map>
<key>Comment</key>

View File

@ -686,6 +686,8 @@ bool LLAppViewer::init()
//set the max heap size.
initMaxHeapSize() ;
LLPrivateMemoryPoolManager::initClass((BOOL)gSavedSettings.getBOOL("MemoryPrivatePoolEnabled")) ;
// write Google Breakpad minidump files to our log directory
std::string logdir = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "");
logdir += gDirUtilp->getDirDelimiter();