diff options
author | Aliaksey Kandratsenka <alkondratenko@gmail.com> | 2017-05-21 23:15:59 -0700 |
---|---|---|
committer | Aliaksey Kandratsenka <alkondratenko@gmail.com> | 2017-05-22 01:55:50 -0700 |
commit | cef582350c952bad761476d01ea64bb4087371ce (patch) | |
tree | 7e690e42fa7fe5a5ee70934e4a4daef72b074fac | |
parent | bddf862b189c4508d5212f6e0e8ea81c4dd18811 (diff) | |
download | gperftools-cef582350c952bad761476d01ea64bb4087371ce.tar.gz |
align fast-path functions only if compiler supports that
Apparently gcc only supports __attribute__((aligned(N))) on functions
only since version 4.3. So lets test it in configure script and only
use when possible. We now use CACHELINE_ALIGNED_FN macro for aligning
functions.
-rw-r--r-- | configure.ac | 16 | ||||
-rw-r--r-- | src/base/basictypes.h | 8 | ||||
-rw-r--r-- | src/tcmalloc.cc | 12 |
3 files changed, 29 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac index e0599ff..59b2467 100644 --- a/configure.ac +++ b/configure.ac @@ -165,6 +165,22 @@ AC_PROG_LIBTOOL AC_C_INLINE AX_C___ATTRIBUTE__ +AC_MSG_CHECKING(for __attribute__((aligned(N))) on functions) +AC_CACHE_VAL(ac_cv___attribute__aligned_fn, [ + AC_TRY_COMPILE( + [#include <stdlib.h> + void foo(void) __attribute__((aligned(128))); + void foo(void) { exit(1); }], + [], + ac_cv___attribute__aligned_fn=yes, + ac_cv___attribute__aligned_fn=no + )]) +if test "$ac_cv___attribute__aligned_fn" = "yes"; then + AC_DEFINE(HAVE___ATTRIBUTE__ALIGNED_FN, 1, [define if your compiler supports alignment of functions]) +fi +AC_MSG_RESULT($ac_cv___attribute__aligned_fn) + + # Check whether some low-level functions/files are available AC_HEADER_STDC diff --git a/src/base/basictypes.h b/src/base/basictypes.h index 1a7b73a..42dbe5c 100644 --- a/src/base/basictypes.h +++ b/src/base/basictypes.h @@ -388,7 +388,13 @@ class AssignAttributeStartEnd { # endif #else # define CACHELINE_ALIGNED -#endif // defined(HAVE___ATTRIBUTE__) && (__i386__ || __x86_64__) +#endif // defined(HAVE___ATTRIBUTE__) + +#if defined(HAVE___ATTRIBUTE__ALIGNED_FN) +# define CACHELINE_ALIGNED_FN CACHELINE_ALIGNED +#else +# define CACHELINE_ALIGNED_FN +#endif // Structure for discovering alignment union MemoryAligner { diff --git a/src/tcmalloc.cc b/src/tcmalloc.cc index fde8a8a..c6edefd 100644 --- a/src/tcmalloc.cc +++ b/src/tcmalloc.cc @@ -1394,7 +1394,7 @@ void do_free_with_callback(void* ptr, // cache could return bogus result (cl = 0 as of this // writing). But since there is no way we could be dealing with // ptr we've allocated, since successfull malloc implies IsInited, - // we can just call invalid_free_fn here. + // we can just call "invalid free" handling code. free_null_or_invalid(ptr, invalid_free_fn); return; } @@ -1749,12 +1749,12 @@ static void * malloc_fast_path(size_t size) { return CheckedMallocResult(cache->Allocate(allocated_size, cl)); } -extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED +extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED_FN void* tc_malloc(size_t size) PERFTOOLS_THROW { return malloc_fast_path<tcmalloc::allocate_full_malloc_oom>(size); } -extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED +extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED_FN void tc_free(void* ptr) PERFTOOLS_THROW { if (PREDICT_FALSE(!base::internal::delete_hooks_.empty())) { tcmalloc::invoke_hooks_and_free(ptr); @@ -1763,7 +1763,7 @@ void tc_free(void* ptr) PERFTOOLS_THROW { do_free(ptr); } -extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED +extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED_FN void tc_free_sized(void *ptr, size_t size) PERFTOOLS_THROW { if (PREDICT_FALSE(!base::internal::delete_hooks_.empty())) { tcmalloc::invoke_hooks_and_free(ptr); @@ -1844,12 +1844,12 @@ extern "C" PERFTOOLS_DLL_DECL void* tc_realloc(void* old_ptr, return do_realloc(old_ptr, new_size); } -extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED +extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED_FN void* tc_new(size_t size) { return malloc_fast_path<tcmalloc::allocate_full_cpp_throw_oom>(size); } -extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED +extern "C" PERFTOOLS_DLL_DECL CACHELINE_ALIGNED_FN void* tc_new_nothrow(size_t size, const std::nothrow_t&) PERFTOOLS_THROW { return malloc_fast_path<tcmalloc::allocate_full_cpp_nothrow_oom>(size); } |