Backed out changeset: 8adddabce214, work to be redone after LL merge of also removing tcmalloc.
parent
e8566ec4ea
commit
097b8d762c
|
|
@ -276,7 +276,7 @@ elseif(LINUX)
|
|||
libopenal.so
|
||||
libopenjpeg.so
|
||||
libssl.so
|
||||
# libtcmalloc_minimal.so
|
||||
libtcmalloc_minimal.so
|
||||
libuuid.so.16
|
||||
libuuid.so.16.0.22
|
||||
libssl.so.1.0.0
|
||||
|
|
@ -284,10 +284,6 @@ elseif(LINUX)
|
|||
#libnotify.so # *TODO test/fix/get linux libnotify(growl)
|
||||
)
|
||||
|
||||
if(USE_GOOGLE_PERFTOOLS)
|
||||
set(release_files ${release_files} "libtcmalloc_minimal.so")
|
||||
endif(USE_GOOGLE_PERFTOOLS)
|
||||
|
||||
if (FMOD)
|
||||
set(release_files ${release_files} "libfmod-3.75.so")
|
||||
endif (FMOD)
|
||||
|
|
|
|||
|
|
@ -1,48 +1,41 @@
|
|||
# -*- cmake -*-
|
||||
include(Prebuilt)
|
||||
|
||||
set(ND_USE_ND_ALLOCS ON)
|
||||
if (STANDALONE)
|
||||
include(FindGooglePerfTools)
|
||||
else (STANDALONE)
|
||||
if (WINDOWS)
|
||||
use_prebuilt_binary(tcmalloc)
|
||||
set(TCMALLOC_LIBRARIES
|
||||
debug libtcmalloc_minimal-debug
|
||||
optimized libtcmalloc_minimal)
|
||||
set(GOOGLE_PERFTOOLS_FOUND "YES")
|
||||
endif (WINDOWS)
|
||||
if (LINUX)
|
||||
use_prebuilt_binary(tcmalloc)
|
||||
set(TCMALLOC_LIBRARIES
|
||||
tcmalloc)
|
||||
set(PROFILER_LIBRARIES profiler)
|
||||
set(GOOGLE_PERFTOOLS_INCLUDE_DIR
|
||||
${LIBS_PREBUILT_DIR}/include)
|
||||
set(GOOGLE_PERFTOOLS_FOUND "YES")
|
||||
endif (LINUX)
|
||||
endif (STANDALONE)
|
||||
|
||||
if( NOT ND_USE_ND_ALLOCS )
|
||||
if (STANDALONE)
|
||||
include(FindGooglePerfTools)
|
||||
else (STANDALONE)
|
||||
if (WINDOWS)
|
||||
use_prebuilt_binary(tcmalloc)
|
||||
set(TCMALLOC_LIBRARIES
|
||||
debug libtcmalloc_minimal-debug
|
||||
optimized libtcmalloc_minimal)
|
||||
set(GOOGLE_PERFTOOLS_FOUND "YES")
|
||||
endif (WINDOWS)
|
||||
if (LINUX)
|
||||
use_prebuilt_binary(tcmalloc)
|
||||
set(TCMALLOC_LIBRARIES
|
||||
tcmalloc)
|
||||
set(PROFILER_LIBRARIES profiler)
|
||||
set(GOOGLE_PERFTOOLS_INCLUDE_DIR
|
||||
${LIBS_PREBUILT_DIR}/include)
|
||||
set(GOOGLE_PERFTOOLS_FOUND "YES")
|
||||
endif (LINUX)
|
||||
endif (STANDALONE)
|
||||
|
||||
if (GOOGLE_PERFTOOLS_FOUND)
|
||||
# XXX Disable temporarily, until we have compilation issues on 64-bit
|
||||
# Etch sorted.
|
||||
set(USE_GOOGLE_PERFTOOLS OFF CACHE BOOL "Build with Google PerfTools support.")
|
||||
endif (GOOGLE_PERFTOOLS_FOUND)
|
||||
|
||||
if (WINDOWS)
|
||||
set(USE_GOOGLE_PERFTOOLS ON)
|
||||
endif (WINDOWS)
|
||||
|
||||
if (USE_GOOGLE_PERFTOOLS)
|
||||
set( FORCE_TCMALLOC_LINK_INCLUDE "/INCLUDE:__tcmalloc" )
|
||||
set(TCMALLOC_FLAG -DLL_USE_TCMALLOC=1)
|
||||
include_directories(${GOOGLE_PERFTOOLS_INCLUDE_DIR})
|
||||
set(GOOGLE_PERFTOOLS_LIBRARIES ${TCMALLOC_LIBRARIES} ${STACKTRACE_LIBRARIES} ${PROFILER_LIBRARIES})
|
||||
else (USE_GOOGLE_PERFTOOLS)
|
||||
set(TCMALLOC_FLAG -ULL_USE_TCMALLOC)
|
||||
endif (USE_GOOGLE_PERFTOOLS)
|
||||
else( NOT ND_USE_ND_ALLOCS )
|
||||
add_definitions( -DND_USE_ND_ALLOCS )
|
||||
endif( NOT ND_USE_ND_ALLOCS )
|
||||
if (GOOGLE_PERFTOOLS_FOUND)
|
||||
# XXX Disable temporarily, until we have compilation issues on 64-bit
|
||||
# Etch sorted.
|
||||
set(USE_GOOGLE_PERFTOOLS OFF CACHE BOOL "Build with Google PerfTools support.")
|
||||
endif (GOOGLE_PERFTOOLS_FOUND)
|
||||
|
||||
if (WINDOWS)
|
||||
set(USE_GOOGLE_PERFTOOLS ON)
|
||||
endif (WINDOWS)
|
||||
|
||||
if (USE_GOOGLE_PERFTOOLS)
|
||||
set(TCMALLOC_FLAG -ULL_USE_TCMALLOC=1)
|
||||
include_directories(${GOOGLE_PERFTOOLS_INCLUDE_DIR})
|
||||
set(GOOGLE_PERFTOOLS_LIBRARIES ${TCMALLOC_LIBRARIES} ${STACKTRACE_LIBRARIES} ${PROFILER_LIBRARIES})
|
||||
else (USE_GOOGLE_PERFTOOLS)
|
||||
set(TCMALLOC_FLAG -ULL_USE_TCMALLOC)
|
||||
endif (USE_GOOGLE_PERFTOOLS)
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@ set(llcommon_SOURCE_FILES
|
|||
timing.cpp
|
||||
u64.cpp
|
||||
ndintrin.cpp
|
||||
ndmemorypool.cpp
|
||||
)
|
||||
|
||||
set(llcommon_HEADER_FILES
|
||||
|
|
@ -266,10 +265,7 @@ set(llcommon_HEADER_FILES
|
|||
timer.h
|
||||
timing.h
|
||||
u64.h
|
||||
ndmemorypool.h
|
||||
ndintrin.h
|
||||
ndlocks.h
|
||||
ndpooldefines.h
|
||||
)
|
||||
|
||||
set_source_files_properties(${llcommon_HEADER_FILES}
|
||||
|
|
@ -277,10 +273,6 @@ set_source_files_properties(${llcommon_HEADER_FILES}
|
|||
|
||||
list(APPEND llcommon_SOURCE_FILES ${llcommon_HEADER_FILES})
|
||||
|
||||
if(WINDOWS)
|
||||
list(APPEND llcommon_SOURCE_FILES ndallocators.cpp)
|
||||
endif(WINDOWS)
|
||||
|
||||
if(LLCOMMON_LINK_SHARED)
|
||||
add_library (llcommon SHARED ${llcommon_SOURCE_FILES})
|
||||
if(WINDOWS)
|
||||
|
|
|
|||
|
|
@ -27,28 +27,6 @@
|
|||
#define LLMEMORY_H
|
||||
|
||||
#include "llmemtype.h"
|
||||
namespace ndAllocators
|
||||
{
|
||||
#ifdef ND_USE_ND_ALLOCS
|
||||
void *ndMalloc( size_t aSize, size_t aAlign );
|
||||
void ndFree( void* ptr );
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign );
|
||||
#else
|
||||
inline void *ndMalloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
return malloc( aSize );
|
||||
}
|
||||
inline void ndFree( void* ptr )
|
||||
{
|
||||
return free( ptr );
|
||||
}
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
return realloc( ptr, aSize );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LL_DEBUG
|
||||
inline void* ll_aligned_malloc( size_t size, int align )
|
||||
{
|
||||
|
|
@ -118,14 +96,12 @@ inline void ll_aligned_free_32(void *p)
|
|||
}
|
||||
#else // LL_DEBUG
|
||||
// ll_aligned_foo are noops now that we use tcmalloc everywhere (tcmalloc aligns automatically at appropriate intervals)
|
||||
#define ll_aligned_malloc( size, align ) ndAllocators::ndMalloc(size, align)
|
||||
#define ll_aligned_free( ptr ) ndAllocators::ndFree(ptr)
|
||||
#define ll_aligned_malloc_16( size ) ndAllocators::ndMalloc( size, 16 )
|
||||
#define ll_aligned_free_16( ptr ) ndAllocators::ndFree( ptr )
|
||||
#define ll_aligned_malloc_32(size) ndAllocators::ndMalloc( size, 32 )
|
||||
#define ll_aligned_free_32( ptr ) ndAllocators::ndFree( ptr )
|
||||
#define ll_aligned_realloc_16( ptr, size ) ndAllocators::ndRealloc( ptr, size, 16 )
|
||||
|
||||
#define ll_aligned_malloc( size, align ) malloc(size)
|
||||
#define ll_aligned_free( ptr ) free(ptr)
|
||||
#define ll_aligned_malloc_16 malloc
|
||||
#define ll_aligned_free_16 free
|
||||
#define ll_aligned_malloc_32 malloc
|
||||
#define ll_aligned_free_32 free
|
||||
#endif // LL_DEBUG
|
||||
|
||||
#ifndef __DEBUG_PRIVATE_MEM__
|
||||
|
|
@ -447,12 +423,6 @@ public:
|
|||
static void freeMem(LLPrivateMemoryPool* poolp, void* addr) ;
|
||||
};
|
||||
|
||||
#ifdef ND_USE_ND_ALLOCS
|
||||
#define ALLOCATE_MEM(poolp, size) ll_aligned_malloc_16(size);
|
||||
#define FREE_MEM(poolp, addr) ll_aligned_free_16( addr );
|
||||
|
||||
#else
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
#if __DEBUG_PRIVATE_MEM__
|
||||
#define ALLOCATE_MEM(poolp, size) LLPrivateMemoryPoolManager::allocate((poolp), (size), __FUNCTION__, __LINE__)
|
||||
|
|
@ -462,8 +432,6 @@ public:
|
|||
#define FREE_MEM(poolp, addr) LLPrivateMemoryPoolManager::freeMem((poolp), (addr))
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
//the below singleton is used to test the private memory pool.
|
||||
//
|
||||
|
|
@ -547,6 +515,7 @@ void LLPrivateMemoryPoolTester::operator delete[](void* addr)
|
|||
|
||||
// LLSingleton moved to llsingleton.h
|
||||
|
||||
|
||||
// <FS:ND> HACK! There are times when there's pointer that are not 0, but 1
|
||||
// This is to find those and research where they are coming.
|
||||
inline bool ndIsValidPtr( void const *aPtr )
|
||||
|
|
@ -557,5 +526,4 @@ inline bool ndIsValidPtr( void const *aPtr )
|
|||
return true;
|
||||
}
|
||||
// </FS:ND>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,71 +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$
|
||||
*/
|
||||
|
||||
|
||||
#include <new>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "ndmemorypool.h"
|
||||
|
||||
#ifdef ND_USE_ND_ALLOCS
|
||||
|
||||
namespace ndAllocators
|
||||
{
|
||||
void *ndMalloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
return ndMemoryPool::malloc( aSize, aAlign );
|
||||
}
|
||||
|
||||
void *ndRealloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
return ndMemoryPool::realloc( ptr, aSize, aAlign );
|
||||
}
|
||||
|
||||
void ndFree( void* ptr )
|
||||
{
|
||||
return ndMemoryPool::free( ptr );
|
||||
}
|
||||
}
|
||||
using namespace ndAllocators;
|
||||
|
||||
void *operator new(size_t nSize )
|
||||
{
|
||||
return ndMalloc( nSize, 16 );
|
||||
}
|
||||
|
||||
void *operator new[](size_t nSize )
|
||||
{
|
||||
return ndMalloc( nSize, 16 );
|
||||
}
|
||||
|
||||
void operator delete( void *pMem )
|
||||
{
|
||||
ndFree( pMem );
|
||||
}
|
||||
|
||||
void operator delete[]( void *pMem )
|
||||
{
|
||||
ndFree( pMem );
|
||||
}
|
||||
#endif
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#ifndef LL_STDTYPES_H
|
||||
#if LL_WINDOWS
|
||||
typedef unsigned long U32;
|
||||
typedef LONG U32;
|
||||
#else
|
||||
typedef unsigned int U32;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
#ifndef NDLOCKS_H
|
||||
#define NDLOCKS_H
|
||||
|
||||
#include "ndintrin.h"
|
||||
|
||||
namespace ndLocks
|
||||
{
|
||||
inline void lock( volatile U32 *aLock )
|
||||
{
|
||||
while( 0 != ndIntrin::CAS( aLock, 0, 1 ) )
|
||||
;
|
||||
}
|
||||
|
||||
inline void unlock ( volatile U32 *aLock )
|
||||
{
|
||||
*aLock = 0;
|
||||
}
|
||||
|
||||
inline bool tryLock( volatile U32 *aLock )
|
||||
{
|
||||
return 0 == ndIntrin::CAS( aLock, 0, 1 );
|
||||
}
|
||||
|
||||
class LockHolder
|
||||
{
|
||||
volatile U32 *mLock;
|
||||
public:
|
||||
LockHolder( volatile U32 *aLock )
|
||||
: mLock( aLock )
|
||||
{
|
||||
if( mLock )
|
||||
lock( mLock );
|
||||
}
|
||||
|
||||
~LockHolder()
|
||||
{
|
||||
if( mLock )
|
||||
unlock( mLock );
|
||||
}
|
||||
|
||||
void attach( volatile U32 *aLock )
|
||||
{
|
||||
mLock = aLock;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,426 +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$
|
||||
*/
|
||||
|
||||
|
||||
#include <new>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "ndmemorypool.h"
|
||||
#include "ndintrin.h"
|
||||
#include "ndlocks.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 *malloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
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 *realloc( void *aPtr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
void* pMem = malloc( aSize, aAlign );
|
||||
|
||||
if( !pMem )
|
||||
return 0;
|
||||
|
||||
if( aPtr )
|
||||
{
|
||||
int nToCopy = nd_min( aSize, sizeFromAlloc( aPtr ) );
|
||||
memcpy( pMem, aPtr, nToCopy );
|
||||
::free( OSbaseFromAlloc( aPtr ) );
|
||||
}
|
||||
|
||||
return pMem;
|
||||
|
||||
}
|
||||
|
||||
void free( void* ptr )
|
||||
{
|
||||
if( ptr )
|
||||
::free( OSbaseFromAlloc( ptr ) );
|
||||
}
|
||||
}
|
||||
|
||||
#if MAX_PAGES > 0
|
||||
namespace ndMemoryPool
|
||||
{
|
||||
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;
|
||||
time_t sLastLog;
|
||||
|
||||
void allocMemoryForPage( Page &aPage )
|
||||
{
|
||||
aPage.mMemory = static_cast<U8*>(OSAllocator::malloc( PAGE_SIZE, CHUNK_ALIGNMENT ));
|
||||
aPage.mMemoryEnd = aPage.mMemory + PAGE_SIZE;
|
||||
aPage.mFree = PAGE_SIZE;
|
||||
}
|
||||
|
||||
void allocPage( int i )
|
||||
{
|
||||
ndLocks::LockHolder( &sPages[i].mLocked );
|
||||
|
||||
if( sPages[i].mMemory )
|
||||
return;
|
||||
|
||||
allocMemoryForPage( sPages[i] );
|
||||
}
|
||||
|
||||
void freePage( int i )
|
||||
{
|
||||
ndLocks::LockHolder( &sPages[i].mLocked );
|
||||
|
||||
if( !sPages[i].mMemory )
|
||||
return;
|
||||
|
||||
OSAllocator::free( sPages[i].mMemory );
|
||||
new (&sPages[i]) Page;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ndMemoryPool
|
||||
{
|
||||
int allocNewPage( )
|
||||
{
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
{
|
||||
if( 0 == sPages[i].mMemory && ndLocks::tryLock( &sPages[i].mLocked ) )
|
||||
{
|
||||
if( 0 != sPages[i].mFree && 0 != sPages[i].mMemory )
|
||||
return i;
|
||||
|
||||
if( 0 == sPages[i].mMemory )
|
||||
{
|
||||
allocMemoryForPage( sPages[i] );
|
||||
return i;
|
||||
}
|
||||
|
||||
ndLocks::unlock( &sPages[i].mLocked );
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int findPageIndex( )
|
||||
{
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
{
|
||||
if( 0 != sPages[i].mFree && ndLocks::tryLock( &sPages[i].mLocked ) )
|
||||
{
|
||||
if( 0 != sPages[i].mFree )
|
||||
return i;
|
||||
|
||||
ndLocks::unlock( &sPages[i].mLocked );
|
||||
}
|
||||
}
|
||||
return allocNewPage();
|
||||
}
|
||||
|
||||
bool isActive()
|
||||
{
|
||||
return sActive;
|
||||
}
|
||||
|
||||
bool usePool( size_t aAllocSize )
|
||||
{
|
||||
return isActive() && aAllocSize <= 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()
|
||||
{
|
||||
for( int i = 0; i < MAX_PAGES; ++i )
|
||||
freePage( i );
|
||||
}
|
||||
|
||||
void *malloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
if( !usePool( aSize ) )
|
||||
return OSAllocator::malloc( aSize, aAlign );
|
||||
|
||||
int nPageIdx( findPageIndex() );
|
||||
|
||||
if( -1 == nPageIdx )
|
||||
return OSAllocator::malloc( aSize, aAlign );
|
||||
|
||||
Page &oPage = sPages[ nPageIdx ];
|
||||
ndLocks::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::malloc( 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 -= CHUNK_SIZE;
|
||||
|
||||
size_t nOffset = ( ( nBitmapIdx * BITS_PER_U32 ) + nBit) * CHUNK_SIZE;
|
||||
void *pRet = oPage.mMemory + nOffset;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void *realloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
int nPoolIdx = toPoolIndex( ptr );
|
||||
|
||||
// Not in pool or 0 == ptr
|
||||
if( -1 == nPoolIdx )
|
||||
return OSAllocator::realloc( ptr, aSize, aAlign );
|
||||
|
||||
void *pRet = OSAllocator::malloc( aSize, aAlign );
|
||||
|
||||
int nToCopy = nd_min( aSize, CHUNK_SIZE );
|
||||
memcpy( pRet, ptr, nToCopy );
|
||||
|
||||
free( ptr );
|
||||
|
||||
return pRet;
|
||||
|
||||
}
|
||||
|
||||
void free( void* ptr )
|
||||
{
|
||||
int nPoolIdx = toPoolIndex( ptr );
|
||||
|
||||
if( -1 == nPoolIdx )
|
||||
{
|
||||
OSAllocator::free( ptr );
|
||||
return;
|
||||
}
|
||||
|
||||
ndLocks::LockHolder oLocker( &sPages[nPoolIdx].mLocked );
|
||||
Page &oPage = sPages[nPoolIdx];
|
||||
|
||||
U8 *pChunk = reinterpret_cast< U8* >( ptr );
|
||||
int nDiff = pChunk - oPage.mMemory;
|
||||
|
||||
int nBitmapIdx = nDiff / CHUNK_SIZE;
|
||||
int nBit( nBitmapIdx % BITS_PER_U32);
|
||||
|
||||
nBitmapIdx -= nBit;
|
||||
nBitmapIdx /= BITS_PER_U32;
|
||||
|
||||
oPage.mBitmap[ nBitmapIdx ] &= ~ ( 0x1 << nBit );
|
||||
oPage.mFree += CHUNK_SIZE;
|
||||
}
|
||||
|
||||
void dumpStats( )
|
||||
{
|
||||
if( (time(0) - sLastLog ) < STATS_FREQ )
|
||||
return;
|
||||
|
||||
sLastLog = time(0);
|
||||
|
||||
int nPagesActive(0);
|
||||
int nUnusedPages(0);
|
||||
int nTotalUsed(0);
|
||||
|
||||
std::vector< double > vPercentages;
|
||||
|
||||
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;
|
||||
vPercentages.push_back( 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) );
|
||||
|
||||
std::cerr << "total pages: " << nPagesActive << " unused pages: " << nUnusedPages << " total bytes: " << std::fixed << std::setprecision( 2 ) << dTotal
|
||||
<< " used: " << dUsed << " (" << dPercent << "%) unused: " << dUnused << std::endl;
|
||||
|
||||
std::cerr << "page usage (% free): ";
|
||||
std::cerr << std::setprecision( 1 );
|
||||
for( std::vector<double>::iterator itr = vPercentages.begin(); vPercentages.end() != itr; ++itr )
|
||||
std::cerr << *itr << " ";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
void tryShrink( )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
namespace ndMemoryPool
|
||||
{
|
||||
void startUp()
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
void *malloc( size_t aSize, size_t aAlign )
|
||||
{
|
||||
return OSAllocator::malloc( aSize, aAlign );
|
||||
}
|
||||
|
||||
void *realloc( void *ptr, size_t aSize, size_t aAlign )
|
||||
{
|
||||
return OSAllocator::realloc( ptr, aSize, aAlign );
|
||||
}
|
||||
|
||||
void free( void* ptr )
|
||||
{
|
||||
OSAllocator::free( ptr );
|
||||
}
|
||||
|
||||
void dumpStats( )
|
||||
{
|
||||
}
|
||||
|
||||
void tryShrink()
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#include "llpreprocessor.h"
|
||||
|
||||
namespace ndMemoryPool
|
||||
{
|
||||
LL_COMMON_API void startUp();
|
||||
LL_COMMON_API void tearDown();
|
||||
|
||||
LL_COMMON_API void *malloc( size_t aSize, size_t aAlign );
|
||||
LL_COMMON_API void *realloc( void *ptr, size_t aSize, size_t aAlign );
|
||||
|
||||
LL_COMMON_API void free( void* ptr );
|
||||
|
||||
LL_COMMON_API void dumpStats( );
|
||||
LL_COMMON_API void tryShrink( );
|
||||
}
|
||||
|
|
@ -1,53 +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 NDPOOLDEFINES_H
|
||||
#define NDPOOLDEFINES_H
|
||||
|
||||
#ifndef LL_STDTYPES_H
|
||||
#if LL_WINDOWS
|
||||
#include <Windows.h>
|
||||
typedef LONG U32;
|
||||
#else
|
||||
typedef unsigned int U32;
|
||||
#endif
|
||||
|
||||
typedef unsigned char U8;
|
||||
#endif
|
||||
|
||||
#define FROM_MB( mbVal ) (mbVal*1024*1024)
|
||||
#define TO_MB( bVal ) ( bVal / (1024*1024) )
|
||||
#define BITS_PER_U8 (8)
|
||||
#define BITS_PER_U32 ( sizeof(U32) * BITS_PER_U8 )
|
||||
|
||||
#define MAX_PAGES (0)
|
||||
#define CHUNK_SIZE (64)
|
||||
#define CHUNK_ALIGNMENT (16)
|
||||
#define PAGE_SIZE (FROM_MB(1) )
|
||||
#define BITMAP_SIZE ( PAGE_SIZE / BITS_PER_U8 / CHUNK_SIZE )
|
||||
|
||||
#define STATS_FREQ ( 15 )
|
||||
|
||||
#endif
|
||||
|
|
@ -7036,14 +7036,14 @@ void LLVolumeFace::pushVertex(const LLVector4a& pos, const LLVector4a& norm, con
|
|||
// S32 old_size = mNumVertices*16;
|
||||
|
||||
//positions
|
||||
mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_size);
|
||||
mPositions = (LLVector4a*) realloc(mPositions, new_size);
|
||||
|
||||
//normals
|
||||
mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_size);
|
||||
mNormals = (LLVector4a*) realloc(mNormals, new_size);
|
||||
|
||||
//tex coords
|
||||
new_size = ((new_verts*8)+0xF) & ~0xF;
|
||||
mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, new_size);
|
||||
mTexCoords = (LLVector2*) realloc(mTexCoords, new_size);
|
||||
|
||||
|
||||
//just clear binormals
|
||||
|
|
@ -7096,7 +7096,7 @@ void LLVolumeFace::pushIndex(const U16& idx)
|
|||
S32 old_size = ((mNumIndices*2)+0xF) & ~0xF;
|
||||
if (new_size != old_size)
|
||||
{
|
||||
mIndices = (U16*) ll_aligned_realloc_16(mIndices, new_size);
|
||||
mIndices = (U16*) realloc(mIndices, new_size);
|
||||
}
|
||||
|
||||
mIndices[mNumIndices++] = idx;
|
||||
|
|
@ -7137,11 +7137,11 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat
|
|||
}
|
||||
|
||||
//allocate new buffer space
|
||||
mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_count*sizeof(LLVector4a));
|
||||
mPositions = (LLVector4a*) realloc(mPositions, new_count*sizeof(LLVector4a));
|
||||
assert_aligned(mPositions, 16);
|
||||
mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_count*sizeof(LLVector4a));
|
||||
mNormals = (LLVector4a*) realloc(mNormals, new_count*sizeof(LLVector4a));
|
||||
assert_aligned(mNormals, 16);
|
||||
mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, (new_count*sizeof(LLVector2)+0xF) & ~0xF);
|
||||
mTexCoords = (LLVector2*) realloc(mTexCoords, (new_count*sizeof(LLVector2)+0xF) & ~0xF);
|
||||
assert_aligned(mTexCoords, 16);
|
||||
|
||||
mNumVertices = new_count;
|
||||
|
|
@ -7188,7 +7188,7 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat
|
|||
new_count = mNumIndices + face.mNumIndices;
|
||||
|
||||
//allocate new index buffer
|
||||
mIndices = (U16*) ll_aligned_realloc_16(mIndices, (new_count*sizeof(U16)+0xF) & ~0xF);
|
||||
mIndices = (U16*) realloc(mIndices, (new_count*sizeof(U16)+0xF) & ~0xF);
|
||||
|
||||
//get destination address into new index buffer
|
||||
U16* dst_idx = mIndices+mNumIndices;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ endif (DARWIN)
|
|||
|
||||
set(SLPlugin_SOURCE_FILES
|
||||
slplugin.cpp
|
||||
../../llcommon/ndallocators.cpp
|
||||
)
|
||||
|
||||
if (DARWIN)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ set(media_plugin_gstreamer010_SOURCE_FILES
|
|||
media_plugin_gstreamer010.cpp
|
||||
llmediaimplgstreamer_syms.cpp
|
||||
llmediaimplgstreamervidplug.cpp
|
||||
../../llcommon/ndallocators.cpp
|
||||
)
|
||||
|
||||
set(media_plugin_gstreamer010_HEADER_FILES
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ endif (DARWIN)
|
|||
|
||||
set(media_plugin_quicktime_SOURCE_FILES
|
||||
media_plugin_quicktime.cpp
|
||||
../../llcommon/ndallocators.cpp
|
||||
)
|
||||
|
||||
add_library(media_plugin_quicktime
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ endif(NOT WORD_SIZE EQUAL 32)
|
|||
|
||||
set(media_plugin_webkit_SOURCE_FILES
|
||||
media_plugin_webkit.cpp
|
||||
../../llcommon/ndallocators.cpp
|
||||
)
|
||||
|
||||
set(media_plugin_webkit_HEADER_FILES
|
||||
|
|
|
|||
|
|
@ -738,10 +738,6 @@ else (HAS_OPENSIM_SUPPORT)
|
|||
)
|
||||
endif (HAS_OPENSIM_SUPPORT)
|
||||
|
||||
if( ND_USE_ND_ALLOCS )
|
||||
list(APPEND viewer_SOURCE_FILES ndallocators.cpp)
|
||||
endif( ND_USE_ND_ALLOCS )
|
||||
|
||||
set(VIEWER_BINARY_NAME "firestorm-bin" CACHE STRING
|
||||
"The name of the viewer executable to create.")
|
||||
|
||||
|
|
@ -1764,7 +1760,7 @@ if (WINDOWS)
|
|||
PROPERTIES
|
||||
# *TODO -reenable this once we get server usage sorted out
|
||||
#LINK_FLAGS "/debug /NODEFAULTLIB:LIBCMT /SUBSYSTEM:WINDOWS /INCLUDE:\"__tcmalloc\""
|
||||
LINK_FLAGS "/debug /NODEFAULTLIB:LIBCMT /SUBSYSTEM:WINDOWS ${FORCE_TCMALLOC_LINK_INCLUDE} "
|
||||
LINK_FLAGS "/debug /NODEFAULTLIB:LIBCMT /SUBSYSTEM:WINDOWS /INCLUDE:__tcmalloc "
|
||||
LINK_FLAGS_DEBUG "/NODEFAULTLIB:\"LIBCMT;LIBCMTD;MSVCRT\" /INCREMENTAL:NO"
|
||||
LINK_FLAGS_RELEASE "/FORCE:MULTIPLE /MAP\"secondlife-bin.MAP\" /OPT:REF"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,31 +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$
|
||||
*/
|
||||
|
||||
|
||||
// Yes, that a hack :(
|
||||
// MSVC really complains badly if you do not compiler the pch header into every source files that uses it.
|
||||
// Usage of pch could be disabled for ../llcommon/ndallocators in newview/CMakeLists.txt, but that's even more magic
|
||||
// that needs to be merged when upstream changes CMakeLists.txt
|
||||
#include "llviewerprecompiledheaders.h"
|
||||
#include "../llcommon/ndallocators.cpp"
|
||||
|
|
@ -26,7 +26,6 @@ set(win_crash_logger_SOURCE_FILES
|
|||
win_crash_logger.cpp
|
||||
llcrashloggerwindows.cpp
|
||||
llcrashlookupwindows.cpp
|
||||
../llcommon/ndallocators.cpp
|
||||
)
|
||||
|
||||
set(win_crash_logger_HEADER_FILES
|
||||
|
|
|
|||
Loading…
Reference in New Issue