diff --git a/indra/cmake/GooglePerfTools.cmake b/indra/cmake/GooglePerfTools.cmake index 09501e0406..7356e4f5a5 100644 --- a/indra/cmake/GooglePerfTools.cmake +++ b/indra/cmake/GooglePerfTools.cmake @@ -4,6 +4,7 @@ include(Prebuilt) # If you want to enable or disable TCMALLOC in viewer builds, this is the place. # set ON or OFF as desired. set (USE_TCMALLOC ON) +#set (USE_TCMALLOC OFF) # tcmalloc removal if (STANDALONE) include(FindGooglePerfTools) @@ -59,3 +60,9 @@ if (USE_GOOGLE_PERFTOOLS) set(GOOGLE_PERFTOOLS_LIBRARIES ${TCMALLOC_LIBRARIES} ${STACKTRACE_LIBRARIES} ${PROFILER_LIBRARIES}) else (USE_GOOGLE_PERFTOOLS) endif (USE_GOOGLE_PERFTOOLS) + +# tcmalloc removal +if( NOT USE_TCMALLOC ) + add_definitions( -DND_NO_TCMALLOC ) +endif( NOT USE_TCMALLOC ) +# tcmalloc removal diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 1089d22bd2..3dd68bb4ea 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -108,7 +108,6 @@ set(llcommon_SOURCE_FILES reflective.cpp timing.cpp u64.cpp - ndintrin.cpp ) set(llcommon_HEADER_FILES @@ -266,9 +265,13 @@ set(llcommon_HEADER_FILES timer.h timing.h u64.h - ndintrin.h ) +# Add all nd* files. memory pool, intrinsics, ... +list(APPEND llcommon_SOURCE_FILES ndallocators.cpp ndintrin.cpp ndmemorypool.cpp ) +list(APPEND llcommon_HEADER_FILES ndintrin.h ndlocks.h ndmemory.h ndmemorypool.h ndpooldefines.h ) +# + # Add OSSL constants for OpenSim builds if (HAS_OPENSIM_SUPPORT) LIST(APPEND llcommon_HEADER_FILES diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index ac6826c87a..a30286d227 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -34,6 +34,11 @@ #define LL_CHECK_MEMORY #endif +// No tcmalloc +#ifdef ND_NO_TCMALLOC +#include "ndmemory.h" +#else + inline void* ll_aligned_malloc( size_t size, int align ) { void* mem = malloc( size + (align - 1) + sizeof(void*) ); @@ -130,6 +135,7 @@ inline void ll_aligned_free_32(void *p) free(p); // posix_memalign() is compatible with heap deallocator #endif } +#endif // No tcmalloc #ifndef __DEBUG_PRIVATE_MEM__ #define __DEBUG_PRIVATE_MEM__ 0 @@ -450,6 +456,9 @@ public: static void freeMem(LLPrivateMemoryPool* poolp, void* addr) ; }; +// No tcmalloc +#ifndef ND_NO_TCMALLOC + //------------------------------------------------------------------------------------- #if __DEBUG_PRIVATE_MEM__ #define ALLOCATE_MEM(poolp, size) LLPrivateMemoryPoolManager::allocate((poolp), (size), __FUNCTION__, __LINE__) @@ -459,6 +468,9 @@ public: #define FREE_MEM(poolp, addr) LLPrivateMemoryPoolManager::freeMem((poolp), (addr)) //------------------------------------------------------------------------------------- +#endif +// No tcmalloc + // //the below singleton is used to test the private memory pool. // diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index b184fa3780..013a0f0677 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -93,6 +93,7 @@ const char MEMINFO_FILE[] = "/proc/meminfo"; extern int errno; #endif +#include "ndmemorypool.h" // tcmalloc replacement static const S32 CPUINFO_BUFFER_SIZE = 16383; LLCPUInfo gSysCPU; @@ -916,6 +917,10 @@ void LLMemoryInfo::stream(std::ostream& s) const s << value; // just use default LLSD formatting s << std::endl; } + + // tcmalloc replacement + ndMemoryPool::dumpStats( s ); + // } LLSD LLMemoryInfo::getStatsMap() const diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 2f4219400e..62a0361335 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -241,6 +241,8 @@ // define a self-registering event API object #include "llappviewerlistener.h" +#include "ndmemorypool.h" // tcmalloc replacement + #if (LL_LINUX || LL_SOLARIS) && LL_GTK #include "glib.h" #endif // (LL_LINUX || LL_SOLARIS) && LL_GTK @@ -718,6 +720,8 @@ LLAppViewer::~LLAppViewer() bool LLAppViewer::init() { + ndMemoryPool::startUp(); // tcmalloc replacement + // // Start of the application // @@ -2177,6 +2181,9 @@ 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. + // ndMemoryPool::tearDown(); // tcmalloc replacement + // return 0; return true; }