summaryrefslogtreecommitdiff
path: root/src/tcmalloc.cc
diff options
context:
space:
mode:
authorcsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2011-03-02 08:10:05 +0000
committercsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2011-03-02 08:10:05 +0000
commit75584139e40c9d6c952d9c5339c52e5b58302fc8 (patch)
tree6c36a0e0c71ef75a57b9f8daaf965de781cccdf9 /src/tcmalloc.cc
parentc1abbfae802af5bf949c78e0bfdfd58d5c669a86 (diff)
downloadgperftools-75584139e40c9d6c952d9c5339c52e5b58302fc8.tar.gz
* Enhance cycleclock on ARM v6 and above (sanek)
* Reduce object copying by using a reference (nherring) * Modified lock annotations a bit (lcwu) * Make debugallocation test a bit more forgiving (csilvers) * Count .dll/.dylib as shared libs in heapchecker (csilvers) * Disable sys_futex for arm (sanek) * Don't use macros as much in windows/port.h (andrey.s...) * Update #includes in case malloc.h is in weird places (csilvers) * Turn off some not-so-useful warnings in gcc 4 (csilvers) * Do some casting to make solaris happier about types (csilvers) * Disable debugallocation_test in 'minimal' mode (csilvers) * Rewrite debugallocation to be more modular (csilvers) * We can't run the heap-checker under valgrind (ppluzhnikov) git-svn-id: http://gperftools.googlecode.com/svn/trunk@106 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/tcmalloc.cc')
-rw-r--r--src/tcmalloc.cc42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/tcmalloc.cc b/src/tcmalloc.cc
index 8d94d20..b037f57 100644
--- a/src/tcmalloc.cc
+++ b/src/tcmalloc.cc
@@ -97,8 +97,16 @@
#else
#include <sys/types.h>
#endif
-#if defined(HAVE_MALLOC_H) && defined(HAVE_STRUCT_MALLINFO)
-#include <malloc.h> // for struct mallinfo
+// We only need malloc.h for struct mallinfo.
+#ifdef HAVE_STRUCT_MALLINFO
+// Malloc can be in several places on older versions of OS X.
+# if defined(HAVE_MALLOC_H)
+# include <malloc.h>
+# elif defined(HAVE_SYS_MALLOC_H)
+# include <sys/malloc.h>
+# elif defined(HAVE_MALLOC_MALLOC_H)
+# include <malloc/malloc.h>
+# endif
#endif
#include <string.h>
#ifdef HAVE_PTHREAD
@@ -259,7 +267,7 @@ extern "C" {
// exception: in windows, by default, we patch our code into these
// functions (via src/windows/patch_function.cc) rather than override
// them. In that case, we don't want to do this overriding here.
-#if !defined(WIN32_DO_PATCHING) && !defined(TCMALLOC_FOR_DEBUGALLOCATION)
+#if !defined(WIN32_DO_PATCHING)
#if defined(__GNUC__) && !defined(__MACH__)
// Potentially faster variants that use the gcc alias extension.
@@ -373,7 +381,7 @@ extern "C" {
#undef ALIAS
-#endif // #ifndef(WIN32_DO_PATCHING) && ndef(TCMALLOC_FOR_DEBUGALLOCATION)
+#endif // #ifndef(WIN32_DO_PATCHING)
// ----------------------- IMPLEMENTATION -------------------------------
@@ -1474,6 +1482,19 @@ extern "C" PERFTOOLS_DLL_DECL const char* tc_version(
return TC_VERSION_STRING;
}
+// This function behaves similarly to MSVC's _set_new_mode.
+// If flag is 0 (default), calls to malloc will behave normally.
+// If flag is 1, calls to malloc will behave like calls to new,
+// and the std_new_handler will be invoked on failure.
+// Returns the previous mode.
+extern "C" PERFTOOLS_DLL_DECL int tc_set_new_mode(int flag) __THROW {
+ int old_mode = tc_new_mode;
+ tc_new_mode = flag;
+ return old_mode;
+}
+
+#ifndef TCMALLOC_FOR_DEBUGALLOCATION // debugallocation.cc defines its own
+
// CAVEAT: The code structure below ensures that MallocHook methods are always
// called from the stack frame of the invoked allocation function.
// heap-checker.cc depends on this to start a stack trace from
@@ -1640,17 +1661,6 @@ extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW {
return GetSizeWithCallback(ptr, &InvalidGetAllocatedSize);
}
-// This function behaves similarly to MSVC's _set_new_mode.
-// If flag is 0 (default), calls to malloc will behave normally.
-// If flag is 1, calls to malloc will behave like calls to new,
-// and the std_new_handler will be invoked on failure.
-// Returns the previous mode.
-extern "C" PERFTOOLS_DLL_DECL int tc_set_new_mode(int flag) __THROW {
- int old_mode = tc_new_mode;
- tc_new_mode = flag;
- return old_mode;
-}
-
// Override __libc_memalign in libc on linux boxes specially.
// They have a bug in libc that causes them to (very rarely) allocate
@@ -1659,7 +1669,6 @@ extern "C" PERFTOOLS_DLL_DECL int tc_set_new_mode(int flag) __THROW {
// This function is an exception to the rule of calling MallocHook method
// from the stack frame of the allocation function;
// heap-checker handles this special case explicitly.
-#ifndef TCMALLOC_FOR_DEBUGALLOCATION
static void *MemalignOverride(size_t align, size_t size, const void *caller)
__THROW ATTRIBUTE_SECTION(google_malloc);
@@ -1670,4 +1679,5 @@ static void *MemalignOverride(size_t align, size_t size, const void *caller)
return result;
}
void *(*__memalign_hook)(size_t, size_t, const void *) = MemalignOverride;
+
#endif // #ifndef TCMALLOC_FOR_DEBUGALLOCATION