Fix compiler warnings.

Add --enable-cc-silence, which can be used to silence harmless warnings.

Fix an aliasing bug in ckh_pointer_hash().
This commit is contained in:
Jason Evans 2010-09-20 19:20:48 -07:00
parent 6a0d2918ce
commit 355b438c85
8 changed files with 124 additions and 32 deletions

View File

@ -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.

View File

@ -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}])

View File

@ -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

View File

@ -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.

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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,