Fix compiler warnings and errors.
Use INT_MAX instead of MAX_INT in ALLOCM_ALIGN(), and #include <limits.h> in order to get its definition. Modify prof code related to hash tables to avoid aliasing warnings from gcc 4.1.2 (gcc 4.4.0 and 4.4.3 do not warn).
This commit is contained in:
parent
355b438c85
commit
075e77cad4
@ -4,6 +4,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
#define JEMALLOC_VERSION "@jemalloc_version@"
|
#define JEMALLOC_VERSION "@jemalloc_version@"
|
||||||
@ -22,7 +23,7 @@ extern "C" {
|
|||||||
#if LG_SIZEOF_PTR == 2
|
#if LG_SIZEOF_PTR == 2
|
||||||
#define ALLOCM_ALIGN(a) (ffs(a)-1)
|
#define ALLOCM_ALIGN(a) (ffs(a)-1)
|
||||||
#else
|
#else
|
||||||
#define ALLOCM_ALIGN(a) ((a < (size_t)MAX_INT) ? ffs(a)-1 : ffs(a>>32)+31)
|
#define ALLOCM_ALIGN(a) ((a < (size_t)INT_MAX) ? ffs(a)-1 : ffs(a>>32)+31)
|
||||||
#endif
|
#endif
|
||||||
#define ALLOCM_ZERO ((int)0x40)
|
#define ALLOCM_ZERO ((int)0x40)
|
||||||
#define ALLOCM_NO_MOVE ((int)0x80)
|
#define ALLOCM_NO_MOVE ((int)0x80)
|
||||||
|
@ -483,7 +483,10 @@ prof_backtrace(prof_bt_t *bt, unsigned nignore, unsigned max)
|
|||||||
static prof_thr_cnt_t *
|
static prof_thr_cnt_t *
|
||||||
prof_lookup(prof_bt_t *bt)
|
prof_lookup(prof_bt_t *bt)
|
||||||
{
|
{
|
||||||
prof_thr_cnt_t *ret;
|
union {
|
||||||
|
prof_thr_cnt_t *p;
|
||||||
|
void *v;
|
||||||
|
} ret;
|
||||||
ckh_t *bt2cnt = BT2CNT_GET();
|
ckh_t *bt2cnt = BT2CNT_GET();
|
||||||
|
|
||||||
if (bt2cnt == NULL) {
|
if (bt2cnt == NULL) {
|
||||||
@ -500,66 +503,72 @@ prof_lookup(prof_bt_t *bt)
|
|||||||
BT2CNT_SET(bt2cnt);
|
BT2CNT_SET(bt2cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ckh_search(bt2cnt, bt, NULL, (void **)&ret)) {
|
if (ckh_search(bt2cnt, bt, NULL, &ret.v)) {
|
||||||
prof_bt_t *btkey;
|
union {
|
||||||
prof_ctx_t *ctx;
|
prof_bt_t *p;
|
||||||
|
void *v;
|
||||||
|
} btkey;
|
||||||
|
union {
|
||||||
|
prof_ctx_t *p;
|
||||||
|
void *v;
|
||||||
|
} ctx;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This thread's cache lacks bt. Look for it in the global
|
* This thread's cache lacks bt. Look for it in the global
|
||||||
* cache.
|
* cache.
|
||||||
*/
|
*/
|
||||||
prof_enter();
|
prof_enter();
|
||||||
if (ckh_search(&bt2ctx, bt, (void **)&btkey, (void **)&ctx)) {
|
if (ckh_search(&bt2ctx, bt, &btkey.v, &ctx.v)) {
|
||||||
|
|
||||||
/* bt has never been seen before. Insert it. */
|
/* bt has never been seen before. Insert it. */
|
||||||
ctx = (prof_ctx_t *)imalloc(sizeof(prof_ctx_t));
|
ctx.v = imalloc(sizeof(prof_ctx_t));
|
||||||
if (ctx == NULL) {
|
if (ctx.v == NULL) {
|
||||||
prof_leave();
|
prof_leave();
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
btkey = bt_dup(bt);
|
btkey.p = bt_dup(bt);
|
||||||
if (btkey == NULL) {
|
if (btkey.v == NULL) {
|
||||||
prof_leave();
|
prof_leave();
|
||||||
idalloc(ctx);
|
idalloc(ctx.v);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
ctx->bt = btkey;
|
ctx.p->bt = btkey.p;
|
||||||
if (malloc_mutex_init(&ctx->lock)) {
|
if (malloc_mutex_init(&ctx.p->lock)) {
|
||||||
prof_leave();
|
prof_leave();
|
||||||
idalloc(btkey);
|
idalloc(btkey.v);
|
||||||
idalloc(ctx);
|
idalloc(ctx.v);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
memset(&ctx->cnt_merged, 0, sizeof(prof_cnt_t));
|
memset(&ctx.p->cnt_merged, 0, sizeof(prof_cnt_t));
|
||||||
ql_new(&ctx->cnts_ql);
|
ql_new(&ctx.p->cnts_ql);
|
||||||
if (ckh_insert(&bt2ctx, btkey, ctx)) {
|
if (ckh_insert(&bt2ctx, btkey.v, ctx.v)) {
|
||||||
/* OOM. */
|
/* OOM. */
|
||||||
prof_leave();
|
prof_leave();
|
||||||
idalloc(btkey);
|
idalloc(btkey.v);
|
||||||
idalloc(ctx);
|
idalloc(ctx.v);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prof_leave();
|
prof_leave();
|
||||||
|
|
||||||
/* Link a prof_thd_cnt_t into ctx for this thread. */
|
/* Link a prof_thd_cnt_t into ctx for this thread. */
|
||||||
ret = (prof_thr_cnt_t *)imalloc(sizeof(prof_thr_cnt_t));
|
ret.v = imalloc(sizeof(prof_thr_cnt_t));
|
||||||
if (ret == NULL)
|
if (ret.p == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
ql_elm_new(ret, link);
|
ql_elm_new(ret.p, link);
|
||||||
ret->ctx = ctx;
|
ret.p->ctx = ctx.p;
|
||||||
ret->epoch = 0;
|
ret.p->epoch = 0;
|
||||||
memset(&ret->cnts, 0, sizeof(prof_cnt_t));
|
memset(&ret.p->cnts, 0, sizeof(prof_cnt_t));
|
||||||
if (ckh_insert(bt2cnt, btkey, ret)) {
|
if (ckh_insert(bt2cnt, btkey.v, ret.v)) {
|
||||||
idalloc(ret);
|
idalloc(ret.v);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
malloc_mutex_lock(&ctx->lock);
|
malloc_mutex_lock(&ctx.p->lock);
|
||||||
ql_tail_insert(&ctx->cnts_ql, ret, link);
|
ql_tail_insert(&ctx.p->cnts_ql, ret.p, link);
|
||||||
malloc_mutex_unlock(&ctx->lock);
|
malloc_mutex_unlock(&ctx.p->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ret);
|
return (ret.p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@ -1022,8 +1031,14 @@ prof_dump(const char *filename, bool leakcheck, bool propagate_err)
|
|||||||
{
|
{
|
||||||
prof_cnt_t cnt_all;
|
prof_cnt_t cnt_all;
|
||||||
size_t tabind;
|
size_t tabind;
|
||||||
prof_bt_t *bt;
|
union {
|
||||||
prof_ctx_t *ctx;
|
prof_bt_t *p;
|
||||||
|
void *v;
|
||||||
|
} bt;
|
||||||
|
union {
|
||||||
|
prof_ctx_t *p;
|
||||||
|
void *v;
|
||||||
|
} ctx;
|
||||||
char buf[UMAX2S_BUFSIZE];
|
char buf[UMAX2S_BUFSIZE];
|
||||||
size_t leak_nctx;
|
size_t leak_nctx;
|
||||||
|
|
||||||
@ -1043,9 +1058,9 @@ prof_dump(const char *filename, bool leakcheck, bool propagate_err)
|
|||||||
/* Merge per thread profile stats, and sum them in cnt_all. */
|
/* Merge per thread profile stats, and sum them in cnt_all. */
|
||||||
memset(&cnt_all, 0, sizeof(prof_cnt_t));
|
memset(&cnt_all, 0, sizeof(prof_cnt_t));
|
||||||
leak_nctx = 0;
|
leak_nctx = 0;
|
||||||
for (tabind = 0; ckh_iter(&bt2ctx, &tabind, NULL, (void **)&ctx)
|
for (tabind = 0; ckh_iter(&bt2ctx, &tabind, NULL, &ctx.v)
|
||||||
== false;) {
|
== false;) {
|
||||||
prof_ctx_merge(ctx, &cnt_all, &leak_nctx);
|
prof_ctx_merge(ctx.p, &cnt_all, &leak_nctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dump profile header. */
|
/* Dump profile header. */
|
||||||
@ -1071,9 +1086,9 @@ prof_dump(const char *filename, bool leakcheck, bool propagate_err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Dump per ctx profile stats. */
|
/* Dump per ctx profile stats. */
|
||||||
for (tabind = 0; ckh_iter(&bt2ctx, &tabind, (void **)&bt, (void **)&ctx)
|
for (tabind = 0; ckh_iter(&bt2ctx, &tabind, &bt.v, &ctx.v)
|
||||||
== false;) {
|
== false;) {
|
||||||
if (prof_dump_ctx(ctx, bt, propagate_err))
|
if (prof_dump_ctx(ctx.p, bt.p, propagate_err))
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1312,28 +1327,31 @@ bt2cnt_thread_cleanup(void *arg)
|
|||||||
if (bt2cnt != NULL) {
|
if (bt2cnt != NULL) {
|
||||||
ql_head(prof_thr_cnt_t) cnts_ql;
|
ql_head(prof_thr_cnt_t) cnts_ql;
|
||||||
size_t tabind;
|
size_t tabind;
|
||||||
prof_thr_cnt_t *cnt;
|
union {
|
||||||
|
prof_thr_cnt_t *p;
|
||||||
|
void *v;
|
||||||
|
} cnt;
|
||||||
|
|
||||||
/* Iteratively merge cnt's into the global stats. */
|
/* Iteratively merge cnt's into the global stats. */
|
||||||
ql_new(&cnts_ql);
|
ql_new(&cnts_ql);
|
||||||
tabind = 0;
|
tabind = 0;
|
||||||
while (ckh_iter(bt2cnt, &tabind, NULL, (void **)&cnt) ==
|
while (ckh_iter(bt2cnt, &tabind, NULL, &cnt.v) ==
|
||||||
false) {
|
false) {
|
||||||
prof_ctx_t *ctx = cnt->ctx;
|
prof_ctx_t *ctx = cnt.p->ctx;
|
||||||
/* Merge stats and detach from ctx. */
|
/* Merge stats and detach from ctx. */
|
||||||
malloc_mutex_lock(&ctx->lock);
|
malloc_mutex_lock(&ctx->lock);
|
||||||
ctx->cnt_merged.curobjs += cnt->cnts.curobjs;
|
ctx->cnt_merged.curobjs += cnt.p->cnts.curobjs;
|
||||||
ctx->cnt_merged.curbytes += cnt->cnts.curbytes;
|
ctx->cnt_merged.curbytes += cnt.p->cnts.curbytes;
|
||||||
ctx->cnt_merged.accumobjs += cnt->cnts.accumobjs;
|
ctx->cnt_merged.accumobjs += cnt.p->cnts.accumobjs;
|
||||||
ctx->cnt_merged.accumbytes += cnt->cnts.accumbytes;
|
ctx->cnt_merged.accumbytes += cnt.p->cnts.accumbytes;
|
||||||
ql_remove(&ctx->cnts_ql, cnt, link);
|
ql_remove(&ctx->cnts_ql, cnt.p, link);
|
||||||
malloc_mutex_unlock(&ctx->lock);
|
malloc_mutex_unlock(&ctx->lock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stash cnt for deletion after finishing with
|
* Stash cnt for deletion after finishing with
|
||||||
* ckh_iter().
|
* ckh_iter().
|
||||||
*/
|
*/
|
||||||
ql_tail_insert(&cnts_ql, cnt, link);
|
ql_tail_insert(&cnts_ql, cnt.p, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1345,9 +1363,9 @@ bt2cnt_thread_cleanup(void *arg)
|
|||||||
BT2CNT_SET(NULL);
|
BT2CNT_SET(NULL);
|
||||||
|
|
||||||
/* Delete cnt's. */
|
/* Delete cnt's. */
|
||||||
while ((cnt = ql_last(&cnts_ql, link)) != NULL) {
|
while ((cnt.p = ql_last(&cnts_ql, link)) != NULL) {
|
||||||
ql_remove(&cnts_ql, cnt, link);
|
ql_remove(&cnts_ql, cnt.p, link);
|
||||||
idalloc(cnt);
|
idalloc(cnt.v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user