2014-10-06 03:05:37 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
#include <limits.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
2017-01-20 13:41:41 +08:00
|
|
|
#define JEMALLOC_VERSION "@jemalloc_version@"
|
|
|
|
#define JEMALLOC_VERSION_MAJOR @jemalloc_version_major@
|
|
|
|
#define JEMALLOC_VERSION_MINOR @jemalloc_version_minor@
|
|
|
|
#define JEMALLOC_VERSION_BUGFIX @jemalloc_version_bugfix@
|
|
|
|
#define JEMALLOC_VERSION_NREV @jemalloc_version_nrev@
|
|
|
|
#define JEMALLOC_VERSION_GID "@jemalloc_version_gid@"
|
2018-10-05 19:11:21 +08:00
|
|
|
#define JEMALLOC_VERSION_GID_IDENT @jemalloc_version_gid@
|
Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
|
2017-01-20 13:41:41 +08:00
|
|
|
#define MALLOCX_LG_ALIGN(la) ((int)(la))
|
2016-12-28 11:16:41 +08:00
|
|
|
#if LG_SIZEOF_PTR == 2
|
|
|
|
# define MALLOCX_ALIGN(a) ((int)(ffs((int)(a))-1))
|
|
|
|
#else
|
|
|
|
# define MALLOCX_ALIGN(a) \
|
|
|
|
((int)(((size_t)(a) < (size_t)INT_MAX) ? ffs((int)(a))-1 : \
|
|
|
|
ffs((int)(((size_t)(a))>>32))+31))
|
|
|
|
#endif
|
2017-01-20 13:41:41 +08:00
|
|
|
#define MALLOCX_ZERO ((int)0x40)
|
2015-01-30 07:30:47 +08:00
|
|
|
/*
|
|
|
|
* Bias tcache index bits so that 0 encodes "automatic tcache management", and 1
|
|
|
|
* encodes MALLOCX_TCACHE_NONE.
|
|
|
|
*/
|
2017-01-20 13:41:41 +08:00
|
|
|
#define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8))
|
|
|
|
#define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1)
|
2015-01-30 07:30:47 +08:00
|
|
|
/*
|
|
|
|
* Bias arena index bits so that 0 encodes "use an automatically chosen arena".
|
|
|
|
*/
|
2017-01-20 13:41:41 +08:00
|
|
|
#define MALLOCX_ARENA(a) ((((int)(a))+1) << 20)
|
Implement the *allocx() API.
Implement the *allocx() API, which is a successor to the *allocm() API.
The *allocx() functions are slightly simpler to use because they have
fewer parameters, they directly return the results of primary interest,
and mallocx()/rallocx() avoid the strict aliasing pitfall that
allocm()/rallocx() share with posix_memalign(). The following code
violates strict aliasing rules:
foo_t *foo;
allocm((void **)&foo, NULL, 42, 0);
whereas the following is safe:
foo_t *foo;
void *p;
allocm(&p, NULL, 42, 0);
foo = (foo_t *)p;
mallocx() does not have this problem:
foo_t *foo = (foo_t *)mallocx(42, 0);
2013-12-13 14:35:52 +08:00
|
|
|
|
2017-01-03 23:27:42 +08:00
|
|
|
/*
|
|
|
|
* Use as arena index in "arena.<i>.{purge,decay,dss}" and
|
|
|
|
* "stats.arenas.<i>.*" mallctl interfaces to select all arenas. This
|
|
|
|
* definition is intentionally specified in raw decimal format to support
|
|
|
|
* cpp-based string concatenation, e.g.
|
|
|
|
*
|
|
|
|
* #define STRINGIFY_HELPER(x) #x
|
|
|
|
* #define STRINGIFY(x) STRINGIFY_HELPER(x)
|
|
|
|
*
|
|
|
|
* mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".purge", NULL, NULL, NULL,
|
|
|
|
* 0);
|
|
|
|
*/
|
2017-01-20 13:41:41 +08:00
|
|
|
#define MALLCTL_ARENAS_ALL 4096
|
2017-01-04 09:21:59 +08:00
|
|
|
/*
|
|
|
|
* Use as arena index in "stats.arenas.<i>.*" mallctl interfaces to select
|
|
|
|
* destroyed arenas.
|
|
|
|
*/
|
2017-01-20 13:41:41 +08:00
|
|
|
#define MALLCTL_ARENAS_DESTROYED 4097
|
2017-01-03 23:27:42 +08:00
|
|
|
|
2015-07-11 05:33:00 +08:00
|
|
|
#if defined(__cplusplus) && defined(JEMALLOC_USE_CXX_THROW)
|
|
|
|
# define JEMALLOC_CXX_THROW throw()
|
|
|
|
#else
|
|
|
|
# define JEMALLOC_CXX_THROW
|
|
|
|
#endif
|
|
|
|
|
2016-09-16 05:33:28 +08:00
|
|
|
#if defined(_MSC_VER)
|
2013-12-06 13:43:46 +08:00
|
|
|
# define JEMALLOC_ATTR(s)
|
2015-07-23 06:44:47 +08:00
|
|
|
# define JEMALLOC_ALIGNED(s) __declspec(align(s))
|
|
|
|
# define JEMALLOC_ALLOC_SIZE(s)
|
|
|
|
# define JEMALLOC_ALLOC_SIZE2(s1, s2)
|
2015-03-04 20:48:01 +08:00
|
|
|
# ifndef JEMALLOC_EXPORT
|
|
|
|
# ifdef DLLEXPORT
|
|
|
|
# define JEMALLOC_EXPORT __declspec(dllexport)
|
|
|
|
# else
|
|
|
|
# define JEMALLOC_EXPORT __declspec(dllimport)
|
|
|
|
# endif
|
2013-12-06 13:43:46 +08:00
|
|
|
# endif
|
2019-03-16 08:19:16 +08:00
|
|
|
# define JEMALLOC_FORMAT_ARG(i)
|
2015-07-23 06:44:47 +08:00
|
|
|
# define JEMALLOC_FORMAT_PRINTF(s, i)
|
2013-12-06 13:43:46 +08:00
|
|
|
# define JEMALLOC_NOINLINE __declspec(noinline)
|
2015-07-21 23:10:38 +08:00
|
|
|
# ifdef __cplusplus
|
|
|
|
# define JEMALLOC_NOTHROW __declspec(nothrow)
|
|
|
|
# else
|
|
|
|
# define JEMALLOC_NOTHROW
|
|
|
|
# endif
|
2015-07-11 05:33:00 +08:00
|
|
|
# define JEMALLOC_SECTION(s) __declspec(allocate(s))
|
2015-07-28 04:48:27 +08:00
|
|
|
# define JEMALLOC_RESTRICT_RETURN __declspec(restrict)
|
|
|
|
# if _MSC_VER >= 1900 && !defined(__EDG__)
|
|
|
|
# define JEMALLOC_ALLOCATOR __declspec(allocator)
|
|
|
|
# else
|
|
|
|
# define JEMALLOC_ALLOCATOR
|
|
|
|
# endif
|
2015-11-06 01:18:43 +08:00
|
|
|
#elif defined(JEMALLOC_HAVE_ATTR)
|
|
|
|
# define JEMALLOC_ATTR(s) __attribute__((s))
|
|
|
|
# define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s))
|
|
|
|
# ifdef JEMALLOC_HAVE_ATTR_ALLOC_SIZE
|
|
|
|
# define JEMALLOC_ALLOC_SIZE(s) JEMALLOC_ATTR(alloc_size(s))
|
|
|
|
# define JEMALLOC_ALLOC_SIZE2(s1, s2) JEMALLOC_ATTR(alloc_size(s1, s2))
|
|
|
|
# else
|
|
|
|
# define JEMALLOC_ALLOC_SIZE(s)
|
|
|
|
# define JEMALLOC_ALLOC_SIZE2(s1, s2)
|
|
|
|
# endif
|
|
|
|
# ifndef JEMALLOC_EXPORT
|
|
|
|
# define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default"))
|
|
|
|
# endif
|
2019-03-16 08:19:16 +08:00
|
|
|
# ifdef JEMALLOC_HAVE_ATTR_FORMAT_ARG
|
|
|
|
# define JEMALLOC_FORMAT_ARG(i) JEMALLOC_ATTR(__format_arg__(3))
|
|
|
|
# else
|
|
|
|
# define JEMALLOC_FORMAT_ARG(i)
|
|
|
|
# endif
|
2015-11-06 01:18:43 +08:00
|
|
|
# ifdef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF
|
|
|
|
# define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(gnu_printf, s, i))
|
|
|
|
# elif defined(JEMALLOC_HAVE_ATTR_FORMAT_PRINTF)
|
|
|
|
# define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(printf, s, i))
|
|
|
|
# else
|
|
|
|
# define JEMALLOC_FORMAT_PRINTF(s, i)
|
|
|
|
# endif
|
|
|
|
# define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline)
|
|
|
|
# define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow)
|
|
|
|
# define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s))
|
|
|
|
# define JEMALLOC_RESTRICT_RETURN
|
|
|
|
# define JEMALLOC_ALLOCATOR
|
2013-12-06 13:43:46 +08:00
|
|
|
#else
|
|
|
|
# define JEMALLOC_ATTR(s)
|
|
|
|
# define JEMALLOC_ALIGNED(s)
|
2015-07-11 05:33:00 +08:00
|
|
|
# define JEMALLOC_ALLOC_SIZE(s)
|
|
|
|
# define JEMALLOC_ALLOC_SIZE2(s1, s2)
|
2015-07-23 06:44:47 +08:00
|
|
|
# define JEMALLOC_EXPORT
|
|
|
|
# define JEMALLOC_FORMAT_PRINTF(s, i)
|
2013-12-06 13:43:46 +08:00
|
|
|
# define JEMALLOC_NOINLINE
|
2015-07-11 05:33:00 +08:00
|
|
|
# define JEMALLOC_NOTHROW
|
|
|
|
# define JEMALLOC_SECTION(s)
|
2015-07-28 04:48:27 +08:00
|
|
|
# define JEMALLOC_RESTRICT_RETURN
|
|
|
|
# define JEMALLOC_ALLOCATOR
|
2013-12-06 13:43:46 +08:00
|
|
|
#endif
|