Remove functionally not used since month (op. new/delete/pool) or that was the same as LL's (*_aligned_*)
parent
5d4c672aaf
commit
2c880e6cce
|
|
@ -270,17 +270,14 @@ set(llcommon_HEADER_FILES
|
|||
# <FS:ND> Add all nd* files. memory pool, intrinsics, ...
|
||||
|
||||
SET( llcommon_ND_SOURCE_FILES
|
||||
nd/ndallocators.cpp
|
||||
nd/ndallocstats.cpp
|
||||
nd/ndexceptions.cpp
|
||||
nd/ndfile.cpp
|
||||
nd/ndintrin.cpp
|
||||
nd/ndlogthrottle.cpp
|
||||
nd/ndmallocstats.cpp
|
||||
nd/ndmemorypool.cpp
|
||||
)
|
||||
SET( llcommon_ND_HEADER_FILES
|
||||
nd/ndallocators.h
|
||||
nd/ndallocstats.h
|
||||
nd/ndboolswitch.h
|
||||
nd/ndcallstack.h
|
||||
|
|
@ -291,8 +288,6 @@ SET( llcommon_ND_HEADER_FILES
|
|||
nd/ndlocks.h
|
||||
nd/ndlogthrottle.h
|
||||
nd/ndmallocstats.h
|
||||
nd/ndmemory.h
|
||||
nd/ndmemorypool.h
|
||||
nd/ndobjectpool.h
|
||||
nd/ndpooldefines.h
|
||||
nd/ndstackwalk.h
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@
|
|||
#include "llsys.h"
|
||||
#include "llframetimer.h"
|
||||
|
||||
#include "nd/ndmemorypool.h" // <FS:ND/> tcmalloc replacement
|
||||
#include "nd/ndallocstats.h" // <FS:ND/> Allocation stats.
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -74,11 +74,6 @@ template <typename T> T* LL_NEXT_ALIGNED_ADDRESS_64(T* address)
|
|||
|
||||
#define LL_ALIGN_16(var) LL_ALIGN_PREFIX(16) var LL_ALIGN_POSTFIX(16)
|
||||
|
||||
// <FS:ND> No tcmalloc
|
||||
#ifdef ND_NO_TCMALLOC
|
||||
#include "nd/ndmemory.h"
|
||||
#else
|
||||
|
||||
inline void* ll_aligned_malloc( size_t size, int align )
|
||||
{
|
||||
#if defined(LL_WINDOWS)
|
||||
|
|
@ -186,8 +181,6 @@ inline void ll_aligned_free_32(void *p)
|
|||
free(p); // posix_memalign() is compatible with heap deallocator
|
||||
#endif
|
||||
}
|
||||
#endif // </FS:ND> No tcmalloc
|
||||
|
||||
|
||||
// Copy words 16-byte blocks from src to dst. Source and destination MUST NOT OVERLAP.
|
||||
// Source and dest must be 16-byte aligned and size must be multiple of 16.
|
||||
|
|
@ -589,9 +582,6 @@ public:
|
|||
static void freeMem(LLPrivateMemoryPool* poolp, void* addr) ;
|
||||
};
|
||||
|
||||
// <FS:ND> No tcmalloc
|
||||
#ifndef ND_NO_TCMALLOC
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
#if __DEBUG_PRIVATE_MEM__
|
||||
#define ALLOCATE_MEM(poolp, size) LLPrivateMemoryPoolManager::allocate((poolp), (size), __FUNCTION__, __LINE__)
|
||||
|
|
@ -601,9 +591,6 @@ public:
|
|||
#define FREE_MEM(poolp, addr) LLPrivateMemoryPoolManager::freeMem((poolp), (addr))
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
// </FS:ND> No tcmalloc
|
||||
|
||||
//
|
||||
//the below singleton is used to test the private memory pool.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -100,7 +100,6 @@ const char MEMINFO_FILE[] = "/proc/meminfo";
|
|||
extern int errno;
|
||||
#endif
|
||||
|
||||
#include "nd/ndmemorypool.h" // <FS:ND/> tcmalloc replacement
|
||||
#include "nd/ndallocstats.h" // <FS:ND/> Allocation stats.
|
||||
|
||||
static const S32 CPUINFO_BUFFER_SIZE = 16383;
|
||||
|
|
|
|||
|
|
@ -1,102 +0,0 @@
|
|||
/**
|
||||
* $LicenseInfo:firstyear=2012&license=fsviewerlgpl$
|
||||
* Phoenix Firestorm Viewer Source Code
|
||||
* Copyright (C) 2012, Nicky Dasmijn
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
|
||||
* http://www.firestormviewer.org
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
|
||||
#include <new>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "ndpooldefines.h"
|
||||
#include "ndmemorypool.h"
|
||||
|
||||
#if defined(ND_NO_TCMALLOC)
|
||||
namespace nd
|
||||
{
|
||||
namespace allocators
|
||||
{
|
||||
#ifdef ND_USE_NATIVE_ALLOCS
|
||||
void *ndMalloc( size_t aSize, size_t aAlign )
|
||||
{ return _aligned_malloc( aSize, aAlign ); }
|
||||
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{ return _aligned_realloc( ptr, aSize, aAlign ); }
|
||||
|
||||
void ndFree( void* ptr )
|
||||
{ return _aligned_free( ptr ); }
|
||||
#else
|
||||
void *ndMalloc( size_t aSize, size_t aAlign )
|
||||
{ return nd::memorypool::ndMalloc( aSize, aAlign ); }
|
||||
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{ return nd::memorypool::ndRealloc( ptr, aSize, aAlign ); }
|
||||
|
||||
void ndFree( void* ptr )
|
||||
{ return nd::memorypool::ndFree( ptr ); }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if ND_OVERRIDE_NEW
|
||||
void *operator new(size_t nSize )
|
||||
{
|
||||
return nd::allocators::ndMalloc( nSize, 16 );
|
||||
}
|
||||
|
||||
void *operator new[](size_t nSize )
|
||||
{
|
||||
return nd::allocators::ndMalloc( nSize, 16 );
|
||||
}
|
||||
|
||||
void operator delete( void *pMem )
|
||||
{
|
||||
nd::allocators::ndFree( pMem );
|
||||
}
|
||||
|
||||
void operator delete[]( void *pMem )
|
||||
{
|
||||
nd::allocators::ndFree( pMem );
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
namespace nd
|
||||
{
|
||||
namespace allocators
|
||||
{
|
||||
void *ndMalloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
return ::malloc( aSize );
|
||||
}
|
||||
void ndFree( void* ptr )
|
||||
{
|
||||
::free( ptr );
|
||||
}
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
return ::realloc( ptr, aSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* $LicenseInfo:firstyear=2012&license=fsviewerlgpl$
|
||||
* Phoenix Firestorm Viewer Source Code
|
||||
* Copyright (C) 2012, Nicky Dasmijn
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* The Phoenix Viewer Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
|
||||
* http://www.phoenixviewer.com
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NDALLOCATORS_H
|
||||
#define NDALLOCATORS_H
|
||||
|
||||
|
||||
#include <new>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "ndmemorypool.h"
|
||||
|
||||
namespace nd
|
||||
{
|
||||
namespace allocators
|
||||
{
|
||||
void *ndMalloc( size_t aSize, size_t aAlign );
|
||||
void ndFree( void* ptr );
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
|
||||
#include "ndallocstats.h"
|
||||
#include "ndmemorypool.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
|
|
@ -53,7 +52,6 @@ namespace nd
|
|||
|
||||
void dumpStats( std::ostream &aOut )
|
||||
{
|
||||
nd::memorypool::dumpStats( aOut );
|
||||
for( std::set< provider * >::iterator itr = s_stProvider.begin(); itr != s_stProvider.end(); ++itr )
|
||||
(*itr)->dumpStats( aOut );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,88 +0,0 @@
|
|||
/**
|
||||
* $LicenseInfo:firstyear=2012&license=fsviewerlgpl$
|
||||
* Phoenix Firestorm Viewer Source Code
|
||||
* Copyright (C) 2012, Nicky Dasmijn
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
|
||||
* http://www.firestormviewer.org
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#ifndef NDMEMORY_H
|
||||
#define NDMEMORY_H
|
||||
|
||||
//#define ND_USE_NATIVE_ALLOCS
|
||||
|
||||
namespace nd
|
||||
{
|
||||
namespace allocators
|
||||
{
|
||||
void *ndMalloc( size_t aSize, size_t aAlign );
|
||||
void ndFree( void* ptr );
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign );
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
#define ll_aligned_malloc( size, align ) nd::allocators::ndMalloc(size, align)
|
||||
#define ll_aligned_malloc_16( size ) nd::allocators::malloc( size, 16 )
|
||||
#define ll_aligned_malloc_32(size) nd::allocators::malloc( size, 32 )
|
||||
|
||||
#define ll_aligned_free( ptr ) nd::allocators::ndFree(ptr)
|
||||
#define ll_aligned_free_16( ptr ) nd::allocators::ndFree( ptr )
|
||||
#define ll_aligned_free_32( ptr ) nd::allocators::ndFree( ptr )
|
||||
|
||||
#define ll_aligned_realloc_16( ptr, size, x ) nd::allocators::ndRealloc( ptr, size, 16 )
|
||||
|
||||
#define ALLOCATE_MEM(poolp, size) ll_aligned_malloc_16(size);
|
||||
#define FREE_MEM(poolp, addr) ll_aligned_free_16( addr );
|
||||
|
||||
#else
|
||||
|
||||
#ifdef ND_USE_NATIVE_ALLOCS
|
||||
#define ll_aligned_malloc( size, align ) _aligned_malloc(size, align)
|
||||
#define ll_aligned_malloc_16( size ) _aligned_malloc( size, 16 )
|
||||
#define ll_aligned_malloc_32(size) _aligned_malloc( size, 32 )
|
||||
|
||||
#define ll_aligned_free( ptr ) _aligned_ndFree (ptr)
|
||||
#define ll_aligned_free_16( ptr ) _aligned_ndFree ( ptr )
|
||||
#define ll_aligned_free_32( ptr ) _aligned_ndFree ( ptr )
|
||||
|
||||
#define ll_aligned_realloc_16( ptr, size, x ) _aligned_ndRealloc( ptr, size, 16 )
|
||||
|
||||
#define ALLOCATE_MEM(poolp, size) ll_aligned_malloc_16(size);
|
||||
#define FREE_MEM(poolp, addr) ll_aligned_free_16( addr );
|
||||
#else
|
||||
inline void* ll_aligned_malloc( size_t aSize, size_t aAlign ) { return nd::allocators::ndMalloc(aSize, aAlign); }
|
||||
inline void* ll_aligned_malloc_16( size_t aSize ) { return nd::allocators::ndMalloc(aSize, 16); }
|
||||
inline void* ll_aligned_malloc_32( size_t aSize ) { return nd::allocators::ndMalloc(aSize, 32); }
|
||||
|
||||
inline void ll_aligned_free( void *aPtr ) { nd::allocators::ndFree( aPtr ); }
|
||||
inline void ll_aligned_free_16( void *aPtr ) { nd::allocators::ndFree( aPtr ); }
|
||||
inline void ll_aligned_free_32( void *aPtr ) { nd::allocators::ndFree( aPtr ); }
|
||||
|
||||
inline void* ll_aligned_realloc_16( void *aPtr, size_t aSize, size_t ) { return nd::allocators::ndRealloc( aPtr, aSize, 16 ); }
|
||||
|
||||
inline void* ALLOCATE_MEM( void *aPool, size_t aSize ) { return ll_aligned_malloc_16(aSize); }
|
||||
inline void FREE_MEM( void *poolp, void *aPtr) { ll_aligned_free_16( aPtr ); }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,477 +0,0 @@
|
|||
/**
|
||||
* $LicenseInfo:firstyear=2012&license=fsviewerlgpl$
|
||||
* Phoenix Firestorm Viewer Source Code
|
||||
* Copyright (C) 2012, Nicky Dasmijn
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
|
||||
* http://www.firestormviewer.org
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#include <new>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
|
||||
#include "ndmemorypool.h"
|
||||
#include "ndintrin.h"
|
||||
#include "ndlocks.h"
|
||||
#include "ndpooldefines.h"
|
||||
#include "ndmallocstats.h"
|
||||
#include "ndcallstack.h"
|
||||
|
||||
inline size_t nd_min( size_t a1, size_t a2 )
|
||||
{
|
||||
if( a1 < a2 )
|
||||
return a1;
|
||||
|
||||
return a2;
|
||||
}
|
||||
|
||||
namespace OSAllocator
|
||||
{
|
||||
inline void OSbaseToAlloc( void *aPtr, void *aOSBase )
|
||||
{
|
||||
uintptr_t *pTmp = reinterpret_cast<uintptr_t*>(aPtr);
|
||||
pTmp[-1] = reinterpret_cast<uintptr_t>(aOSBase);
|
||||
}
|
||||
|
||||
inline void* OSbaseFromAlloc( void *aPtr )
|
||||
{
|
||||
uintptr_t *pTmp = reinterpret_cast<uintptr_t*>(aPtr);
|
||||
return reinterpret_cast< void* >( pTmp[-1] );
|
||||
}
|
||||
|
||||
inline size_t sizeFromAlloc( void *aPtr )
|
||||
{
|
||||
uintptr_t *pTmp = reinterpret_cast<uintptr_t*>(aPtr);
|
||||
return pTmp[-2];
|
||||
}
|
||||
|
||||
inline void sizeToAlloc( void *aPtr, size_t aSize )
|
||||
{
|
||||
uintptr_t *pTmp = reinterpret_cast<uintptr_t*>(aPtr);
|
||||
pTmp[-2] = aSize;
|
||||
}
|
||||
|
||||
void *ndMalloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
nd::debugging::sEBP *pEBP(0);
|
||||
|
||||
#ifdef LOG_ALLOCATION_STACKS
|
||||
if( aSize >= MIN_ALLOC_SIZE_FOR_LOG_STACK && aSize <= MAX_ALLOC_SIZE_FOR_LOG_STACK )
|
||||
pEBP = nd::debugging::getEBP();
|
||||
#endif
|
||||
nd::mallocstats::logAllocation( aSize, pEBP );
|
||||
|
||||
aSize += sizeof(uintptr_t)*2;
|
||||
aSize += aAlign;
|
||||
|
||||
void* pMem = ::malloc( aSize );
|
||||
|
||||
if( !pMem )
|
||||
return 0;
|
||||
|
||||
uintptr_t nMem = reinterpret_cast<uintptr_t>(pMem);
|
||||
nMem += sizeof(uintptr_t)*2;
|
||||
nMem += aAlign;
|
||||
nMem &= ~(aAlign - 1);
|
||||
|
||||
char *pRet = reinterpret_cast< char* >( nMem );
|
||||
|
||||
OSbaseToAlloc( pRet, pMem );
|
||||
sizeToAlloc( pRet, aSize );
|
||||
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void *ndRealloc( void *aPtr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
void* pMem = ndMalloc( aSize, aAlign );
|
||||
|
||||
if( !pMem )
|
||||
return 0;
|
||||
|
||||
if( aPtr )
|
||||
{
|
||||
size_t oldSize = sizeFromAlloc( aPtr );
|
||||
void *osBase = OSbaseFromAlloc( aPtr );
|
||||
|
||||
oldSize -= ( reinterpret_cast< uintptr_t >( aPtr ) - reinterpret_cast< uintptr_t >( osBase ) );
|
||||
size_t nToCopy = nd_min( aSize, oldSize );
|
||||
memcpy( pMem, aPtr, nToCopy );
|
||||
|
||||
::free( osBase );
|
||||
}
|
||||
|
||||
return pMem;
|
||||
}
|
||||
|
||||
void ndFree( void* ptr )
|
||||
{
|
||||
if( ptr )
|
||||
::free( OSbaseFromAlloc( ptr ) );
|
||||
}
|
||||
}
|
||||
|
||||
#if MAX_PAGES > 0
|
||||
namespace nd
|
||||
{
|
||||
namespace memorypool
|
||||
{
|
||||
struct Page
|
||||
{
|
||||
U32 mFree;
|
||||
U32 mLocked;
|
||||
U32 mBitmap[BITMAP_SIZE];
|
||||
U8 *mMemory;
|
||||
U8 *mMemoryEnd;
|
||||
|
||||
Page()
|
||||
: mFree(0)
|
||||
, mLocked(0)
|
||||
, mMemory(0)
|
||||
, mMemoryEnd(0)
|
||||
{
|
||||
memset( mBitmap, 0, sizeof(mBitmap) );
|
||||
}
|
||||
};
|
||||
|
||||
Page sPages[ MAX_PAGES ];
|
||||
U32 mPageLock;
|
||||
bool sActive = false;
|
||||
|
||||
bool allocMemoryForPage( Page &aPage )
|
||||
{
|
||||
aPage.mMemory = static_cast<U8*>(OSAllocator::ndMalloc( PAGE_SIZE, POOL_CHUNK_ALIGNMENT ));
|
||||
|
||||
if( 0 == aPage.mMemory )
|
||||
{
|
||||
aPage.mMemoryEnd = 0;
|
||||
aPage.mFree = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
aPage.mMemoryEnd = aPage.mMemory + PAGE_SIZE;
|
||||
aPage.mFree = PAGE_SIZE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool allocPage( int i )
|
||||
{
|
||||
nd::locks::LockHolder( &sPages[i].mLocked );
|
||||
|
||||
if( sPages[i].mMemory )
|
||||
return true;
|
||||
|
||||
return allocMemoryForPage( sPages[i] );
|
||||
}
|
||||
|
||||
void freePage( int i )
|
||||
{
|
||||
nd::locks::LockHolder( &sPages[i].mLocked );
|
||||
|
||||
if( !sPages[i].mMemory )
|
||||
return;
|
||||
|
||||
OSAllocator::ndFree( sPages[i].mMemory );
|
||||
new (&sPages[i]) Page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace nd
|
||||
{
|
||||
namespace memorypool
|
||||
{
|
||||
int allocNewPage( )
|
||||
{
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
{
|
||||
if( 0 == sPages[i].mMemory && nd::locks::tryLock( &sPages[i].mLocked ) )
|
||||
{
|
||||
if( 0 != sPages[i].mFree && 0 != sPages[i].mMemory )
|
||||
return i;
|
||||
|
||||
if( 0 == sPages[i].mMemory )
|
||||
{
|
||||
if( allocMemoryForPage( sPages[i] ) )
|
||||
return i;
|
||||
else
|
||||
{
|
||||
nd::locks::unlock( &sPages[i].mLocked );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
nd::locks::unlock( &sPages[i].mLocked );
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int findPageIndex( )
|
||||
{
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
{
|
||||
if( 0 != sPages[i].mFree && nd::locks::tryLock( &sPages[i].mLocked ) )
|
||||
{
|
||||
if( 0 != sPages[i].mFree )
|
||||
return i;
|
||||
|
||||
nd::locks::unlock( &sPages[i].mLocked );
|
||||
}
|
||||
}
|
||||
return allocNewPage();
|
||||
}
|
||||
|
||||
bool isActive()
|
||||
{
|
||||
return sActive;
|
||||
}
|
||||
|
||||
bool usePool( size_t aAllocSize )
|
||||
{
|
||||
return isActive() && aAllocSize <= POOL_CHUNK_SIZE;
|
||||
}
|
||||
|
||||
int toPoolIndex( void *aMemory )
|
||||
{
|
||||
if( !isActive() || !aMemory )
|
||||
return -1;
|
||||
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
if( aMemory >= sPages[i].mMemory && aMemory < sPages[ i ].mMemoryEnd )
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void startUp()
|
||||
{
|
||||
allocPage( 0 );
|
||||
sActive = true;
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
sActive = false;
|
||||
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
freePage( i );
|
||||
}
|
||||
|
||||
void *ndMalloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
if( !usePool( aSize ) )
|
||||
return OSAllocator::ndMalloc( aSize, aAlign );
|
||||
|
||||
int nPageIdx( findPageIndex() );
|
||||
|
||||
if( -1 == nPageIdx )
|
||||
return OSAllocator::ndMalloc( aSize, aAlign );
|
||||
|
||||
Page &oPage = sPages[ nPageIdx ];
|
||||
nd::locks::LockHolder oLock(0);
|
||||
oLock.attach( &oPage.mLocked );
|
||||
|
||||
int nBitmapIdx = 0;
|
||||
while( nBitmapIdx < BITMAP_SIZE && oPage.mBitmap[ nBitmapIdx ] == 0xFFFFFFFF )
|
||||
++nBitmapIdx;
|
||||
|
||||
if( BITMAP_SIZE == nBitmapIdx )
|
||||
return OSAllocator::ndMalloc( aSize, aAlign );
|
||||
|
||||
U32 bBitmap = oPage.mBitmap[ nBitmapIdx ];
|
||||
int nBit = 0;
|
||||
|
||||
while( (bBitmap & 0x1) )
|
||||
{
|
||||
bBitmap = (bBitmap & 0xFFFFFFFE) >> 1;
|
||||
nBit++;
|
||||
}
|
||||
|
||||
oPage.mBitmap[ nBitmapIdx ] |= ( 0x1 << nBit );
|
||||
oPage.mFree -= POOL_CHUNK_SIZE;
|
||||
|
||||
size_t nOffset = ( ( nBitmapIdx * BITS_PER_U32 ) + nBit) * POOL_CHUNK_SIZE;
|
||||
void *pRet = oPage.mMemory + nOffset;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
int nPoolIdx = toPoolIndex( ptr );
|
||||
|
||||
// Not in pool or 0 == ptr
|
||||
if( -1 == nPoolIdx )
|
||||
return OSAllocator::ndRealloc( ptr, aSize, aAlign );
|
||||
|
||||
void *pRet = OSAllocator::ndMalloc( aSize, aAlign );
|
||||
|
||||
int nToCopy = nd_min( aSize, POOL_CHUNK_SIZE );
|
||||
memcpy( pRet, ptr, nToCopy );
|
||||
|
||||
ndFree( ptr );
|
||||
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void ndFree( void* ptr )
|
||||
{
|
||||
int nPoolIdx = toPoolIndex( ptr );
|
||||
|
||||
if( -1 == nPoolIdx )
|
||||
{
|
||||
OSAllocator::ndFree( ptr );
|
||||
return;
|
||||
}
|
||||
|
||||
nd::locks::LockHolder oLocker( &sPages[nPoolIdx].mLocked );
|
||||
Page &oPage = sPages[nPoolIdx];
|
||||
|
||||
U8 *pChunk = reinterpret_cast< U8* >( ptr );
|
||||
int nDiff = pChunk - oPage.mMemory;
|
||||
|
||||
int nBitmapIdx = nDiff / POOL_CHUNK_SIZE;
|
||||
int nBit( nBitmapIdx % BITS_PER_U32);
|
||||
|
||||
nBitmapIdx -= nBit;
|
||||
nBitmapIdx /= BITS_PER_U32;
|
||||
|
||||
oPage.mBitmap[ nBitmapIdx ] &= ~ ( 0x1 << nBit );
|
||||
oPage.mFree += POOL_CHUNK_SIZE;
|
||||
}
|
||||
|
||||
void dumpStats( std::ostream &aOut )
|
||||
{
|
||||
int nPagesActive(0);
|
||||
int nUnusedPages(0);
|
||||
int nTotalUsed(0);
|
||||
|
||||
double dPercentages[ MAX_PAGES ] = {0};
|
||||
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
{
|
||||
if( sPages[i].mMemory )
|
||||
{
|
||||
U32 nFree = sPages[i].mFree;
|
||||
nTotalUsed += PAGE_SIZE - nFree ;
|
||||
++nPagesActive;
|
||||
|
||||
if( PAGE_SIZE == nFree )
|
||||
++nUnusedPages;
|
||||
|
||||
double dPercent = nFree;
|
||||
dPercent *= 100;
|
||||
dPercent /= PAGE_SIZE;
|
||||
dPercentages[i] = dPercent;
|
||||
}
|
||||
}
|
||||
|
||||
int nTotal = PAGE_SIZE * nPagesActive;
|
||||
int nTotalUnused = PAGE_SIZE * nUnusedPages;
|
||||
|
||||
double dPercent = nTotalUsed;
|
||||
dPercent *= 100;
|
||||
dPercent /= nTotal;
|
||||
|
||||
double dTotal( TO_MB( nTotal ) );
|
||||
double dUnused( TO_MB( nTotalUnused ) );
|
||||
double dUsed( TO_MB( nTotalUsed) );
|
||||
|
||||
aOut << "total pages: " << nPagesActive << " unused pages: " << nUnusedPages << " total bytes: " << std::fixed << std::setprecision( 2 ) << dTotal
|
||||
<< " used: " << dUsed << " (" << dPercent << "%) unused: " << dUnused << std::endl;
|
||||
|
||||
aOut << "page usage (page #/% free):";
|
||||
aOut << std::setprecision( 1 );
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
{
|
||||
if( dPercentages[i] > 0 )
|
||||
aOut << " " << i << "/" << dPercentages[i];
|
||||
}
|
||||
aOut << std::endl;
|
||||
nd::mallocstats::dumpStats( aOut );
|
||||
}
|
||||
|
||||
void tryShrink( )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
namespace nd
|
||||
{
|
||||
namespace memorypool
|
||||
{
|
||||
void startUp()
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
void *ndMalloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
nd::debugging::sEBP *pEBP(0);
|
||||
|
||||
#ifdef LOG_ALLOCATION_STACKS
|
||||
if( aSize >= MIN_ALLOC_SIZE_FOR_LOG_STACK && aSize <= MAX_ALLOC_SIZE_FOR_LOG_STACK )
|
||||
pEBP = nd::debugging::getEBP();
|
||||
#endif
|
||||
nd::mallocstats::logAllocation( aSize, pEBP );
|
||||
|
||||
return OSAllocator::ndMalloc( aSize, aAlign );
|
||||
}
|
||||
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
nd::debugging::sEBP *pEBP(0);
|
||||
|
||||
#ifdef LOG_ALLOCATION_STACKS
|
||||
if( aSize >= MIN_ALLOC_SIZE_FOR_LOG_STACK && aSize <= MAX_ALLOC_SIZE_FOR_LOG_STACK )
|
||||
pEBP = nd::debugging::getEBP();
|
||||
#endif
|
||||
nd::mallocstats::logAllocation( aSize, pEBP );
|
||||
|
||||
return OSAllocator::ndRealloc( ptr, aSize, aAlign );
|
||||
}
|
||||
|
||||
void ndFree( void* ptr )
|
||||
{
|
||||
OSAllocator::ndFree( ptr );
|
||||
}
|
||||
|
||||
void dumpStats( std::ostream &aOut )
|
||||
{
|
||||
nd::mallocstats::dumpStats( aOut );
|
||||
}
|
||||
|
||||
void tryShrink()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#ifndef NDMEMORYPOOL_H
|
||||
#define NDMEMORYPOOL_H
|
||||
|
||||
/**
|
||||
* $LicenseInfo:firstyear=2012&license=fsviewerlgpl$
|
||||
* Phoenix Firestorm Viewer Source Code
|
||||
* Copyright (C) 2012, Nicky Dasmijn
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
|
||||
* http://www.firestormviewer.org
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#include "llpreprocessor.h"
|
||||
#include "ndmallocstats.h"
|
||||
|
||||
namespace nd
|
||||
{
|
||||
namespace memorypool
|
||||
{
|
||||
LL_COMMON_API void startUp();
|
||||
LL_COMMON_API void tearDown();
|
||||
|
||||
LL_COMMON_API void *ndMalloc( size_t aSize, size_t aAlign );
|
||||
LL_COMMON_API void *ndRealloc( void *ptr, size_t aSize, size_t aAlign );
|
||||
|
||||
LL_COMMON_API void ndFree( void* ptr );
|
||||
|
||||
LL_COMMON_API void dumpStats( std::ostream & );
|
||||
LL_COMMON_API void tryShrink( );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -26,7 +26,6 @@
|
|||
*/
|
||||
|
||||
#include "ndlocks.h"
|
||||
#include "ndallocators.h"
|
||||
|
||||
namespace nd
|
||||
{
|
||||
|
|
|
|||
|
|
@ -255,7 +255,6 @@
|
|||
// define a self-registering event API object
|
||||
#include "llappviewerlistener.h"
|
||||
|
||||
#include "nd/ndmemorypool.h" // <FS:ND/> tcmalloc replacement
|
||||
#include "nd/ndmallocstats.h" // <FS:ND/> collect stats about memory allocations
|
||||
#include "nd/ndallocstats.h" // <FS:ND/> collect stats about memory allocations
|
||||
#include "fsradar.h"
|
||||
|
|
@ -789,7 +788,6 @@ public:
|
|||
|
||||
bool LLAppViewer::init()
|
||||
{
|
||||
nd::memorypool::startUp(); // <FS:ND/> tcmalloc replacement
|
||||
nd::allocstats::startUp(); // <FS:ND/> start collecting alloc stats
|
||||
nd::mallocstats::startUp(); // <FS:ND/> start collecting alloc stats
|
||||
|
||||
|
|
@ -2353,9 +2351,6 @@ bool LLAppViewer::cleanup()
|
|||
|
||||
llinfos << "Goodbye!" << llendflush;
|
||||
|
||||
// This coud leak memory that was allocated in the pool. But that's ok. We're about to die and the OS will take care of this.
|
||||
// nd::memorypool::tearDown(); // <FS:ND/> tcmalloc replacement
|
||||
|
||||
// return 0;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue