Simplify JEMALLOC_ATTR_* macros to become JEMALLOC_ATTR().
Use JEMALLOC_ATTR(tls_model("initial-exec)) instead of -ftls-model=initial-exec so that libjemalloc_pic.a can be directly linked into another library without needing linker options changes. Add attributes to malloc, calloc, and posix_memalign, for compatibility with glibc's declarations. Add function prototypes for the standard malloc(3) API.
This commit is contained in:
parent
bf10ae64a7
commit
9ad48230ed
@ -94,7 +94,6 @@ if test "x$CFLAGS" = "x" ; then
|
|||||||
JE_CFLAGS_APPEND([-pipe])
|
JE_CFLAGS_APPEND([-pipe])
|
||||||
JE_CFLAGS_APPEND([-g3])
|
JE_CFLAGS_APPEND([-g3])
|
||||||
JE_CFLAGS_APPEND([-march=native])
|
JE_CFLAGS_APPEND([-march=native])
|
||||||
JE_CFLAGS_APPEND([-ftls-model=initial-exec])
|
|
||||||
fi
|
fi
|
||||||
dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
|
dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
|
||||||
if test "x$EXTRA_CFLAGS" != "x" ; then
|
if test "x$EXTRA_CFLAGS" != "x" ; then
|
||||||
@ -152,9 +151,7 @@ JE_COMPILABLE([__attribute__ syntax],
|
|||||||
[],
|
[],
|
||||||
[attribute])
|
[attribute])
|
||||||
if test "x${attribute}" = "xyes" ; then
|
if test "x${attribute}" = "xyes" ; then
|
||||||
AC_DEFINE_UNQUOTED([JEMALLOC_UNUSED], [__attribute__((unused))])
|
AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
|
||||||
else
|
|
||||||
AC_DEFINE_UNQUOTED([JEMALLOC_UNUSED], [])
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dnl Platform-specific settings. abi and RPATH can probably be determined
|
dnl Platform-specific settings. abi and RPATH can probably be determined
|
||||||
|
@ -739,7 +739,8 @@ static unsigned ncpus;
|
|||||||
static malloc_mutex_t trace_mtx;
|
static malloc_mutex_t trace_mtx;
|
||||||
static unsigned trace_next_tid = 1;
|
static unsigned trace_next_tid = 1;
|
||||||
|
|
||||||
static unsigned __thread trace_tid;
|
static unsigned __thread trace_tid
|
||||||
|
JEMALLOC_ATTR(tls_model("initial-exec"));
|
||||||
/* Used to cause trace_cleanup() to be called. */
|
/* Used to cause trace_cleanup() to be called. */
|
||||||
static pthread_key_t trace_tsd;
|
static pthread_key_t trace_tsd;
|
||||||
#endif
|
#endif
|
||||||
@ -1008,12 +1009,14 @@ static malloc_mutex_t arenas_lock; /* Protects arenas initialization. */
|
|||||||
* Map of pthread_self() --> arenas[???], used for selecting an arena to use
|
* Map of pthread_self() --> arenas[???], used for selecting an arena to use
|
||||||
* for allocations.
|
* for allocations.
|
||||||
*/
|
*/
|
||||||
static __thread arena_t *arenas_map;
|
static __thread arena_t *arenas_map
|
||||||
|
JEMALLOC_ATTR(tls_model("initial-exec"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef JEMALLOC_TCACHE
|
#ifdef JEMALLOC_TCACHE
|
||||||
/* Map of thread-specific caches. */
|
/* Map of thread-specific caches. */
|
||||||
static __thread tcache_t *tcache_tls;
|
static __thread tcache_t *tcache_tls
|
||||||
|
JEMALLOC_ATTR(tls_model("initial-exec"));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Same contents as tcache, but initialized such that the TSD destructor is
|
* Same contents as tcache, but initialized such that the TSD destructor is
|
||||||
@ -1041,8 +1044,11 @@ static
|
|||||||
#ifndef NO_TLS
|
#ifndef NO_TLS
|
||||||
__thread
|
__thread
|
||||||
#endif
|
#endif
|
||||||
bool mmap_unaligned;
|
bool mmap_unaligned
|
||||||
|
#ifndef NO_TLS
|
||||||
|
JEMALLOC_ATTR(tls_model("initial-exec"))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
#ifdef JEMALLOC_STATS
|
#ifdef JEMALLOC_STATS
|
||||||
/* Chunk statistics. */
|
/* Chunk statistics. */
|
||||||
static chunk_stats_t stats_chunks;
|
static chunk_stats_t stats_chunks;
|
||||||
@ -1749,8 +1755,8 @@ extent_szad_comp(extent_node_t *a, extent_node_t *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap red-black tree macros in functions. */
|
/* Wrap red-black tree macros in functions. */
|
||||||
rb_wrap(static JEMALLOC_UNUSED, extent_tree_szad_, extent_tree_t, extent_node_t,
|
rb_wrap(static JEMALLOC_ATTR(unused), extent_tree_szad_, extent_tree_t,
|
||||||
link_szad, extent_szad_comp)
|
extent_node_t, link_szad, extent_szad_comp)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
@ -1763,8 +1769,8 @@ extent_ad_comp(extent_node_t *a, extent_node_t *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap red-black tree macros in functions. */
|
/* Wrap red-black tree macros in functions. */
|
||||||
rb_wrap(static JEMALLOC_UNUSED, extent_tree_ad_, extent_tree_t, extent_node_t,
|
rb_wrap(static JEMALLOC_ATTR(unused), extent_tree_ad_, extent_tree_t,
|
||||||
link_ad, extent_ad_comp)
|
extent_node_t, link_ad, extent_ad_comp)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* End extent tree code.
|
* End extent tree code.
|
||||||
@ -2322,8 +2328,8 @@ arena_chunk_comp(arena_chunk_t *a, arena_chunk_t *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap red-black tree macros in functions. */
|
/* Wrap red-black tree macros in functions. */
|
||||||
rb_wrap(static JEMALLOC_UNUSED, arena_chunk_tree_dirty_, arena_chunk_tree_t,
|
rb_wrap(static JEMALLOC_ATTR(unused), arena_chunk_tree_dirty_,
|
||||||
arena_chunk_t, link_dirty, arena_chunk_comp)
|
arena_chunk_tree_t, arena_chunk_t, link_dirty, arena_chunk_comp)
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
arena_run_comp(arena_chunk_map_t *a, arena_chunk_map_t *b)
|
arena_run_comp(arena_chunk_map_t *a, arena_chunk_map_t *b)
|
||||||
@ -2338,7 +2344,7 @@ arena_run_comp(arena_chunk_map_t *a, arena_chunk_map_t *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap red-black tree macros in functions. */
|
/* Wrap red-black tree macros in functions. */
|
||||||
rb_wrap(static JEMALLOC_UNUSED, arena_run_tree_, arena_run_tree_t,
|
rb_wrap(static JEMALLOC_ATTR(unused), arena_run_tree_, arena_run_tree_t,
|
||||||
arena_chunk_map_t, link, arena_run_comp)
|
arena_chunk_map_t, link, arena_run_comp)
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
@ -2370,7 +2376,7 @@ arena_avail_comp(arena_chunk_map_t *a, arena_chunk_map_t *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap red-black tree macros in functions. */
|
/* Wrap red-black tree macros in functions. */
|
||||||
rb_wrap(static JEMALLOC_UNUSED, arena_avail_tree_, arena_avail_tree_t,
|
rb_wrap(static JEMALLOC_ATTR(unused), arena_avail_tree_, arena_avail_tree_t,
|
||||||
arena_chunk_map_t, link, arena_avail_comp)
|
arena_chunk_map_t, link, arena_avail_comp)
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@ -6086,6 +6092,7 @@ MALLOC_OUT:
|
|||||||
* Begin malloc(3)-compatible functions.
|
* Begin malloc(3)-compatible functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
JEMALLOC_ATTR(malloc)
|
||||||
void *
|
void *
|
||||||
malloc(size_t size)
|
malloc(size_t size)
|
||||||
{
|
{
|
||||||
@ -6142,6 +6149,7 @@ RETURN:
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JEMALLOC_ATTR(nonnull(1))
|
||||||
int
|
int
|
||||||
posix_memalign(void **memptr, size_t alignment, size_t size)
|
posix_memalign(void **memptr, size_t alignment, size_t size)
|
||||||
{
|
{
|
||||||
@ -6217,6 +6225,7 @@ RETURN:
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JEMALLOC_ATTR(malloc)
|
||||||
void *
|
void *
|
||||||
calloc(size_t num, size_t size)
|
calloc(size_t num, size_t size)
|
||||||
{
|
{
|
||||||
|
@ -6,8 +6,14 @@ extern "C" {
|
|||||||
|
|
||||||
#include "jemalloc_defs.h"
|
#include "jemalloc_defs.h"
|
||||||
|
|
||||||
size_t malloc_usable_size(const void *ptr);
|
void *malloc(size_t size) JEMALLOC_ATTR(malloc);
|
||||||
|
void *calloc(size_t num, size_t size) JEMALLOC_ATTR(malloc);
|
||||||
|
int posix_memalign(void **memptr, size_t alignment, size_t size)
|
||||||
|
JEMALLOC_ATTR(nonnull(1));
|
||||||
|
void *realloc(void *ptr, size_t size);
|
||||||
|
void free(void *ptr);
|
||||||
|
|
||||||
|
size_t malloc_usable_size(const void *ptr);
|
||||||
#ifdef JEMALLOC_TCACHE
|
#ifdef JEMALLOC_TCACHE
|
||||||
void malloc_tcache_flush(void);
|
void malloc_tcache_flush(void);
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,12 +36,13 @@
|
|||||||
*/
|
*/
|
||||||
#undef CPU_SPINWAIT
|
#undef CPU_SPINWAIT
|
||||||
|
|
||||||
/*
|
/* Defined if __attribute__((...)) syntax is supported. */
|
||||||
* Attribute with which to mark potentially unused functions. For gcc this is:
|
#undef JEMALLOC_HAVE_ATTR
|
||||||
*
|
#ifdef JEMALLOC_HAVE_ATTR
|
||||||
* __attribute__((unused))
|
# define JEMALLOC_ATTR(s) __attribute__((s))
|
||||||
*/
|
#else
|
||||||
#undef JEMALLOC_UNUSED
|
# define JEMALLOC_ATTR(s)
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JEMALLOC_DEBUG enables assertions and other sanity checks, and disables
|
* JEMALLOC_DEBUG enables assertions and other sanity checks, and disables
|
||||||
|
@ -65,7 +65,7 @@ cacheComp(AllocationCacheRecord *a, AllocationCacheRecord *b)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_wrap(static JEMALLOC_UNUSED, cache_tree_, AllocationCache,
|
rb_wrap(static JEMALLOC_ATTR(unused), cache_tree_, AllocationCache,
|
||||||
AllocationCacheRecord, link, cacheComp)
|
AllocationCacheRecord, link, cacheComp)
|
||||||
|
|
||||||
// Parse utrace records. Following are prototypical examples of each type of
|
// Parse utrace records. Following are prototypical examples of each type of
|
||||||
@ -324,7 +324,7 @@ genOutput(FILE *outfile, const char *fileType, bool legend,
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"mtrgraph: Trace record %"PRIu64
|
"mtrgraph: Trace record %"PRIu64
|
||||||
" realloc()s unknown object 0x%"PRIx64"\n",
|
" realloc()s unknown object 0x%"PRIx64"\n",
|
||||||
i, trace->trace[i].oldAddr);
|
i, (uint64_t)trace->trace[i].oldAddr);
|
||||||
rVal = true;
|
rVal = true;
|
||||||
goto RETURN;
|
goto RETURN;
|
||||||
}
|
}
|
||||||
@ -429,7 +429,7 @@ genOutput(FILE *outfile, const char *fileType, bool legend,
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"mtrgraph: Trace record %"PRIu64
|
"mtrgraph: Trace record %"PRIu64
|
||||||
" free()s unknown object 0x%"PRIx64"\n",
|
" free()s unknown object 0x%"PRIx64"\n",
|
||||||
i, trace->trace[i].oldAddr);
|
i, (uint64_t)trace->trace[i].oldAddr);
|
||||||
rVal = true;
|
rVal = true;
|
||||||
goto RETURN;
|
goto RETURN;
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ record_comp(record_t *a, record_t *b)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_wrap(static JEMALLOC_UNUSED, record_tree_, record_tree_t, record_t, link,
|
rb_wrap(static JEMALLOC_ATTR(unused), record_tree_, record_tree_t, record_t,
|
||||||
record_comp)
|
link, record_comp)
|
||||||
|
|
||||||
static record_t *rec_stack = NULL;
|
static record_t *rec_stack = NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user