summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <je@facebook.com>2010-09-21 02:20:48 (GMT)
committerJason Evans <je@facebook.com>2010-09-21 02:20:48 (GMT)
commit355b438c854227bbf8185cb7a3ce247d271a842e (patch)
treea173a96412a2c5ac1f02ac6d3a3f1c188eeefe48
parent6a0d2918ceede07a36a50389c1a8a95755b0a7f6 (diff)
downloadjemalloc-355b438c854227bbf8185cb7a3ce247d271a842e.zip
jemalloc-355b438c854227bbf8185cb7a3ce247d271a842e.tar.gz
jemalloc-355b438c854227bbf8185cb7a3ce247d271a842e.tar.bz2
Fix compiler warnings.
Add --enable-cc-silence, which can be used to silence harmless warnings. Fix an aliasing bug in ckh_pointer_hash().
-rw-r--r--jemalloc/INSTALL5
-rw-r--r--jemalloc/configure.ac18
-rw-r--r--jemalloc/include/jemalloc/internal/jemalloc_internal.h.in30
-rw-r--r--jemalloc/include/jemalloc/jemalloc_defs.h.in3
-rw-r--r--jemalloc/src/ckh.c13
-rw-r--r--jemalloc/src/jemalloc.c66
-rw-r--r--jemalloc/src/prof.c6
-rw-r--r--jemalloc/test/thread_arena.c15
8 files changed, 124 insertions, 32 deletions
diff --git a/jemalloc/INSTALL b/jemalloc/INSTALL
index a895743..1bf5158 100644
--- a/jemalloc/INSTALL
+++ b/jemalloc/INSTALL
@@ -40,6 +40,11 @@ any of the following arguments (not a definitive list) to 'configure':
versions of jemalloc can coexist in the same installation directory. For
example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0.
+--enable-cc-silence
+ Enable code that silences unuseful compiler warnings. This is helpful when
+ trying to tell serious warnings from those due to compiler limitations, but
+ it potentially incurs a performance penalty.
+
--enable-debug
Enable assertions and validation code. This incurs a substantial
performance hit, but is very useful during application development.
diff --git a/jemalloc/configure.ac b/jemalloc/configure.ac
index 127b695..7d0561a 100644
--- a/jemalloc/configure.ac
+++ b/jemalloc/configure.ac
@@ -289,6 +289,23 @@ cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
+dnl Do not silence irrelevant compiler warnings by default, since enabling this
+dnl option incurs a performance penalty.
+AC_ARG_ENABLE([cc-silence],
+ [AS_HELP_STRING([--enable-cc-silence],
+ [Silence irrelevant compiler warnings])],
+[if test "x$enable_cc_silence" = "xno" ; then
+ enable_cc_silence="0"
+else
+ enable_cc_silence="1"
+fi
+],
+[enable_cc_silence="0"]
+)
+if test "x$enable_cc_silence" = "x1" ; then
+ AC_DEFINE([JEMALLOC_CC_SILENCE])
+fi
+
dnl Do not compile with debugging by default.
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug], [Build debugging code])],
@@ -807,6 +824,7 @@ AC_MSG_RESULT([])
AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
AC_MSG_RESULT([install_suffix : ${install_suffix}])
AC_MSG_RESULT([autogen : ${enable_autogen}])
+AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
AC_MSG_RESULT([debug : ${enable_debug}])
AC_MSG_RESULT([stats : ${enable_stats}])
AC_MSG_RESULT([prof : ${enable_prof}])
diff --git a/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in b/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in
index 514ef5c..2320e3e 100644
--- a/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in
+++ b/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in
@@ -399,9 +399,9 @@ size_t isalloc(const void *ptr);
# ifdef JEMALLOC_IVSALLOC
size_t ivsalloc(const void *ptr);
# endif
+void idalloc(void *ptr);
void *iralloc(void *ptr, size_t size, size_t extra, size_t alignment,
bool zero, bool no_move);
-void idalloc(void *ptr);
#endif
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_C_))
@@ -559,6 +559,20 @@ ivsalloc(const void *ptr)
}
#endif
+JEMALLOC_INLINE void
+idalloc(void *ptr)
+{
+ arena_chunk_t *chunk;
+
+ assert(ptr != NULL);
+
+ chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
+ if (chunk != ptr)
+ arena_dalloc(chunk->arena, chunk, ptr);
+ else
+ huge_dalloc(ptr);
+}
+
JEMALLOC_INLINE void *
iralloc(void *ptr, size_t size, size_t extra, size_t alignment, bool zero,
bool no_move)
@@ -619,20 +633,6 @@ iralloc(void *ptr, size_t size, size_t extra, size_t alignment, bool zero,
}
}
}
-
-JEMALLOC_INLINE void
-idalloc(void *ptr)
-{
- arena_chunk_t *chunk;
-
- assert(ptr != NULL);
-
- chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
- if (chunk != ptr)
- arena_dalloc(chunk->arena, chunk, ptr);
- else
- huge_dalloc(ptr);
-}
#endif
#undef JEMALLOC_H_INLINES
diff --git a/jemalloc/include/jemalloc/jemalloc_defs.h.in b/jemalloc/include/jemalloc/jemalloc_defs.h.in
index 6bdcbaa..fe35170 100644
--- a/jemalloc/include/jemalloc/jemalloc_defs.h.in
+++ b/jemalloc/include/jemalloc/jemalloc_defs.h.in
@@ -31,6 +31,9 @@
# define JEMALLOC_ATTR(s)
#endif
+/* JEMALLOC_CC_SILENCE enables code that silences unuseful compiler warnings. */
+#undef JEMALLOC_CC_SILENCE
+
/*
* JEMALLOC_DEBUG enables assertions and other sanity checks, and disables
* inline functions.
diff --git a/jemalloc/src/ckh.c b/jemalloc/src/ckh.c
index 95c0967..682a8db 100644
--- a/jemalloc/src/ckh.c
+++ b/jemalloc/src/ckh.c
@@ -567,12 +567,21 @@ ckh_pointer_hash(const void *key, unsigned minbits, size_t *hash1,
{
size_t ret1, ret2;
uint64_t h;
+ union {
+ const void *v;
+ uint64_t i;
+ } u;
assert(minbits <= 32 || (SIZEOF_PTR == 8 && minbits <= 64));
assert(hash1 != NULL);
assert(hash2 != NULL);
- h = hash(&key, sizeof(void *), 0xd983396e68886082LLU);
+ assert(sizeof(u.v) == sizeof(u.i));
+#if (LG_SIZEOF_PTR != LG_SIZEOF_INT)
+ u.i = 0;
+#endif
+ u.v = key;
+ h = hash(&u.i, sizeof(u.i), 0xd983396e68886082LLU);
if (minbits <= 32) {
/*
* Avoid doing multiple hashes, since a single hash provides
@@ -583,7 +592,7 @@ ckh_pointer_hash(const void *key, unsigned minbits, size_t *hash1,
} else {
assert(SIZEOF_PTR == 8);
ret1 = h;
- ret2 = hash(&key, sizeof(void *), 0x5e2be9aff8709a5dLLU);
+ ret2 = hash(&u.i, sizeof(u.i), 0x5e2be9aff8709a5dLLU);
}
*hash1 = ret1;
diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c
index 3f115d8..f252f59 100644
--- a/jemalloc/src/jemalloc.c
+++ b/jemalloc/src/jemalloc.c
@@ -76,8 +76,14 @@ static
void
wrtmessage(void *cbopaque, const char *s)
{
-
- write(STDERR_FILENO, s, strlen(s));
+#ifdef JEMALLOC_CC_SILENCE
+ int result =
+#endif
+ write(STDERR_FILENO, s, strlen(s));
+#ifdef JEMALLOC_CC_SILENCE
+ if (result < 0)
+ result = errno;
+#endif
}
void (*JEMALLOC_P(malloc_message))(void *, const char *s)
@@ -746,7 +752,11 @@ JEMALLOC_P(malloc)(size_t size)
{
void *ret;
#ifdef JEMALLOC_PROF
- prof_thr_cnt_t *cnt;
+ prof_thr_cnt_t *cnt
+# ifdef JEMALLOC_CC_SILENCE
+ = NULL
+# endif
+ ;
#endif
if (malloc_init()) {
@@ -821,7 +831,11 @@ JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size)
int ret;
void *result;
#ifdef JEMALLOC_PROF
- prof_thr_cnt_t *cnt;
+ prof_thr_cnt_t *cnt
+# ifdef JEMALLOC_CC_SILENCE
+ = NULL
+# endif
+ ;
#endif
if (malloc_init())
@@ -920,7 +934,11 @@ JEMALLOC_P(calloc)(size_t num, size_t size)
void *ret;
size_t num_size;
#ifdef JEMALLOC_PROF
- prof_thr_cnt_t *cnt;
+ prof_thr_cnt_t *cnt
+# ifdef JEMALLOC_CC_SILENCE
+ = NULL
+# endif
+ ;
#endif
if (malloc_init()) {
@@ -995,9 +1013,21 @@ JEMALLOC_P(realloc)(void *ptr, size_t size)
{
void *ret;
#ifdef JEMALLOC_PROF
- size_t old_size;
- prof_thr_cnt_t *cnt;
- prof_ctx_t *old_ctx;
+ size_t old_size
+# ifdef JEMALLOC_CC_SILENCE
+ = 0
+# endif
+ ;
+ prof_thr_cnt_t *cnt
+# ifdef JEMALLOC_CC_SILENCE
+ = NULL
+# endif
+ ;
+ prof_ctx_t *old_ctx
+# ifdef JEMALLOC_CC_SILENCE
+ = NULL
+# endif
+ ;
#endif
if (size == 0) {
@@ -1160,8 +1190,14 @@ void *
JEMALLOC_P(memalign)(size_t alignment, size_t size)
{
void *ret;
-
- posix_memalign(&ret, alignment, size);
+#ifdef JEMALLOC_CC_SILENCE
+ int result =
+#endif
+ JEMALLOC_P(posix_memalign)(&ret, alignment, size);
+#ifdef JEMALLOC_CC_SILENCE
+ if (result != 0)
+ return (NULL);
+#endif
return (ret);
}
#endif
@@ -1173,8 +1209,14 @@ void *
JEMALLOC_P(valloc)(size_t size)
{
void *ret;
-
- posix_memalign(&ret, PAGE_SIZE, size);
+#ifdef JEMALLOC_CC_SILENCE
+ int result =
+#endif
+ JEMALLOC_P(posix_memalign)(&ret, PAGE_SIZE, size);
+#ifdef JEMALLOC_CC_SILENCE
+ if (result != 0)
+ return (NULL);
+#endif
return (ret);
}
#endif
diff --git a/jemalloc/src/prof.c b/jemalloc/src/prof.c
index 7d596df..a414bb9 100644
--- a/jemalloc/src/prof.c
+++ b/jemalloc/src/prof.c
@@ -737,7 +737,11 @@ void
prof_realloc(const void *ptr, prof_thr_cnt_t *cnt, const void *old_ptr,
size_t old_size, prof_ctx_t *old_ctx)
{
- size_t size;
+ size_t size
+#ifdef JEMALLOC_CC_SILENCE
+ = 0
+#endif
+ ;
prof_thr_cnt_t *told_cnt;
assert(ptr != NULL || (uintptr_t)cnt <= (uintptr_t)1U);
diff --git a/jemalloc/test/thread_arena.c b/jemalloc/test/thread_arena.c
index d52435f..5b1058b 100644
--- a/jemalloc/test/thread_arena.c
+++ b/jemalloc/test/thread_arena.c
@@ -10,11 +10,16 @@ void *
thread_start(void *arg)
{
unsigned main_arena_ind = *(unsigned *)arg;
+ void *p;
unsigned arena_ind;
size_t size;
int err;
- JEMALLOC_P(malloc)(1);
+ p = JEMALLOC_P(malloc)(1);
+ if (p == NULL) {
+ fprintf(stderr, "%s(): Error in malloc()\n", __func__);
+ return (void *)1;
+ }
size = sizeof(arena_ind);
if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size,
@@ -31,6 +36,7 @@ int
main(void)
{
int ret = 0;
+ void *p;
unsigned arena_ind;
size_t size;
int err;
@@ -38,7 +44,12 @@ main(void)
fprintf(stderr, "Test begin\n");
- JEMALLOC_P(malloc)(1);
+ p = JEMALLOC_P(malloc)(1);
+ if (p == NULL) {
+ fprintf(stderr, "%s(): Error in malloc()\n", __func__);
+ ret = 1;
+ goto RETURN;
+ }
size = sizeof(arena_ind);
if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, NULL,