Remove the *allocm() API, which is superceded by the *allocx() API.
This commit is contained in:
parent
9b0cbf0850
commit
9790b9667f
3
INSTALL
3
INSTALL
@ -157,9 +157,6 @@ any of the following arguments (not a definitive list) to 'configure':
|
||||
--disable-valgrind
|
||||
Disable support for Valgrind.
|
||||
|
||||
--disable-experimental
|
||||
Disable support for the experimental API (*allocm()).
|
||||
|
||||
--disable-zone-allocator
|
||||
Disable zone allocator for Darwin. This means jemalloc won't be hooked as
|
||||
the default allocator on OSX/iOS.
|
||||
|
@ -48,7 +48,6 @@ cfgoutputs_in := @cfgoutputs_in@
|
||||
cfgoutputs_out := @cfgoutputs_out@
|
||||
enable_autogen := @enable_autogen@
|
||||
enable_code_coverage := @enable_code_coverage@
|
||||
enable_experimental := @enable_experimental@
|
||||
enable_zone_allocator := @enable_zone_allocator@
|
||||
DSO_LDFLAGS = @DSO_LDFLAGS@
|
||||
SOREV = @SOREV@
|
||||
@ -133,17 +132,13 @@ TESTS_UNIT_AUX := $(srcroot)test/unit/prof_accum_a.c \
|
||||
TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \
|
||||
$(srcroot)test/integration/allocated.c \
|
||||
$(srcroot)test/integration/mallocx.c \
|
||||
$(srcroot)test/integration/MALLOCX_ARENA.c \
|
||||
$(srcroot)test/integration/mremap.c \
|
||||
$(srcroot)test/integration/posix_memalign.c \
|
||||
$(srcroot)test/integration/rallocx.c \
|
||||
$(srcroot)test/integration/thread_arena.c \
|
||||
$(srcroot)test/integration/thread_tcache_enabled.c \
|
||||
$(srcroot)test/integration/xallocx.c
|
||||
ifeq ($(enable_experimental), 1)
|
||||
TESTS_INTEGRATION += $(srcroot)test/integration/allocm.c \
|
||||
$(srcroot)test/integration/MALLOCX_ARENA.c \
|
||||
$(srcroot)test/integration/rallocm.c
|
||||
endif
|
||||
TESTS_STRESS :=
|
||||
TESTS := $(TESTS_UNIT) $(TESTS_INTEGRATION) $(TESTS_STRESS)
|
||||
|
||||
|
21
configure.ac
21
configure.ac
@ -44,7 +44,7 @@ AC_CACHE_CHECK([whether $1 is compilable],
|
||||
dnl ============================================================================
|
||||
|
||||
dnl Library revision.
|
||||
rev=1
|
||||
rev=2
|
||||
AC_SUBST([rev])
|
||||
|
||||
srcroot=$srcdir
|
||||
@ -438,24 +438,6 @@ AC_CHECK_FUNC([valloc],
|
||||
[AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
|
||||
public_syms="${public_syms} valloc"])
|
||||
|
||||
dnl Support the experimental API by default.
|
||||
AC_ARG_ENABLE([experimental],
|
||||
[AS_HELP_STRING([--disable-experimental],
|
||||
[Disable support for the experimental API])],
|
||||
[if test "x$enable_experimental" = "xno" ; then
|
||||
enable_experimental="0"
|
||||
else
|
||||
enable_experimental="1"
|
||||
fi
|
||||
],
|
||||
[enable_experimental="1"]
|
||||
)
|
||||
if test "x$enable_experimental" = "x1" ; then
|
||||
AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
|
||||
public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
|
||||
fi
|
||||
AC_SUBST([enable_experimental])
|
||||
|
||||
dnl Do not compute test code coverage by default.
|
||||
GCOV_FLAGS=
|
||||
AC_ARG_ENABLE([code-coverage],
|
||||
@ -1465,7 +1447,6 @@ AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
|
||||
AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
|
||||
AC_MSG_RESULT([install_suffix : ${install_suffix}])
|
||||
AC_MSG_RESULT([autogen : ${enable_autogen}])
|
||||
AC_MSG_RESULT([experimental : ${enable_experimental}])
|
||||
AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
|
||||
AC_MSG_RESULT([debug : ${enable_debug}])
|
||||
AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
|
||||
|
@ -44,11 +44,6 @@
|
||||
<refname>mallctlbymib</refname>
|
||||
<refname>malloc_stats_print</refname>
|
||||
<refname>malloc_usable_size</refname>
|
||||
<refname>allocm</refname>
|
||||
<refname>rallocm</refname>
|
||||
<refname>sallocm</refname>
|
||||
<refname>dallocm</refname>
|
||||
<refname>nallocm</refname>
|
||||
-->
|
||||
<refpurpose>general purpose memory allocation functions</refpurpose>
|
||||
</refnamediv>
|
||||
@ -172,41 +167,6 @@
|
||||
</funcprototype>
|
||||
<para><type>const char *</type><varname>malloc_conf</varname>;</para>
|
||||
</refsect2>
|
||||
<refsect2>
|
||||
<title>Experimental API</title>
|
||||
<funcprototype>
|
||||
<funcdef>int <function>allocm</function></funcdef>
|
||||
<paramdef>void **<parameter>ptr</parameter></paramdef>
|
||||
<paramdef>size_t *<parameter>rsize</parameter></paramdef>
|
||||
<paramdef>size_t <parameter>size</parameter></paramdef>
|
||||
<paramdef>int <parameter>flags</parameter></paramdef>
|
||||
</funcprototype>
|
||||
<funcprototype>
|
||||
<funcdef>int <function>rallocm</function></funcdef>
|
||||
<paramdef>void **<parameter>ptr</parameter></paramdef>
|
||||
<paramdef>size_t *<parameter>rsize</parameter></paramdef>
|
||||
<paramdef>size_t <parameter>size</parameter></paramdef>
|
||||
<paramdef>size_t <parameter>extra</parameter></paramdef>
|
||||
<paramdef>int <parameter>flags</parameter></paramdef>
|
||||
</funcprototype>
|
||||
<funcprototype>
|
||||
<funcdef>int <function>sallocm</function></funcdef>
|
||||
<paramdef>const void *<parameter>ptr</parameter></paramdef>
|
||||
<paramdef>size_t *<parameter>rsize</parameter></paramdef>
|
||||
<paramdef>int <parameter>flags</parameter></paramdef>
|
||||
</funcprototype>
|
||||
<funcprototype>
|
||||
<funcdef>int <function>dallocm</function></funcdef>
|
||||
<paramdef>void *<parameter>ptr</parameter></paramdef>
|
||||
<paramdef>int <parameter>flags</parameter></paramdef>
|
||||
</funcprototype>
|
||||
<funcprototype>
|
||||
<funcdef>int <function>nallocm</function></funcdef>
|
||||
<paramdef>size_t *<parameter>rsize</parameter></paramdef>
|
||||
<paramdef>size_t <parameter>size</parameter></paramdef>
|
||||
<paramdef>int <parameter>flags</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</refsect2>
|
||||
</funcsynopsis>
|
||||
</refsynopsisdiv>
|
||||
<refsect1 id="description">
|
||||
@ -449,116 +409,6 @@ for (i = 0; i < nbins; i++) {
|
||||
depended on, since such behavior is entirely implementation-dependent.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2>
|
||||
<title>Experimental API</title>
|
||||
<para>The experimental API is subject to change or removal without regard
|
||||
for backward compatibility. If <option>--disable-experimental</option>
|
||||
is specified during configuration, the experimental API is
|
||||
omitted.</para>
|
||||
|
||||
<para>The <function>allocm<parameter/></function>,
|
||||
<function>rallocm<parameter/></function>,
|
||||
<function>sallocm<parameter/></function>,
|
||||
<function>dallocm<parameter/></function>, and
|
||||
<function>nallocm<parameter/></function> functions all have a
|
||||
<parameter>flags</parameter> argument that can be used to specify
|
||||
options. The functions only check the options that are contextually
|
||||
relevant. Use bitwise or (<code language="C">|</code>) operations to
|
||||
specify one or more of the following:
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><constant>ALLOCM_LG_ALIGN(<parameter>la</parameter>)
|
||||
</constant></term>
|
||||
|
||||
<listitem><para>Align the memory allocation to start at an address
|
||||
that is a multiple of <code language="C">(1 <<
|
||||
<parameter>la</parameter>)</code>. This macro does not validate
|
||||
that <parameter>la</parameter> is within the valid
|
||||
range.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><constant>ALLOCM_ALIGN(<parameter>a</parameter>)
|
||||
</constant></term>
|
||||
|
||||
<listitem><para>Align the memory allocation to start at an address
|
||||
that is a multiple of <parameter>a</parameter>, where
|
||||
<parameter>a</parameter> is a power of two. This macro does not
|
||||
validate that <parameter>a</parameter> is a power of 2.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><constant>ALLOCM_ZERO</constant></term>
|
||||
|
||||
<listitem><para>Initialize newly allocated memory to contain zero
|
||||
bytes. In the growing reallocation case, the real size prior to
|
||||
reallocation defines the boundary between untouched bytes and those
|
||||
that are initialized to contain zero bytes. If this macro is
|
||||
absent, newly allocated memory is uninitialized.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><constant>ALLOCM_NO_MOVE</constant></term>
|
||||
|
||||
<listitem><para>For reallocation, fail rather than moving the
|
||||
object. This constraint can apply to both growth and
|
||||
shrinkage.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><constant>ALLOCM_ARENA(<parameter>a</parameter>)
|
||||
</constant></term>
|
||||
|
||||
<listitem><para>Use the arena specified by the index
|
||||
<parameter>a</parameter> (and by necessity bypass the thread
|
||||
cache). This macro has no effect for huge regions, nor for regions
|
||||
that were allocated via an arena other than the one specified.
|
||||
This macro does not validate that <parameter>a</parameter>
|
||||
specifies an arena index in the valid range.</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
|
||||
<para>The <function>allocm<parameter/></function> function allocates at
|
||||
least <parameter>size</parameter> bytes of memory, sets
|
||||
<parameter>*ptr</parameter> to the base address of the allocation, and
|
||||
sets <parameter>*rsize</parameter> to the real size of the allocation if
|
||||
<parameter>rsize</parameter> is not <constant>NULL</constant>. Behavior
|
||||
is undefined if <parameter>size</parameter> is <constant>0</constant>, or
|
||||
if request size overflows due to size class and/or alignment
|
||||
constraints.</para>
|
||||
|
||||
<para>The <function>rallocm<parameter/></function> function resizes the
|
||||
allocation at <parameter>*ptr</parameter> to be at least
|
||||
<parameter>size</parameter> bytes, sets <parameter>*ptr</parameter> to
|
||||
the base address of the allocation if it moved, and sets
|
||||
<parameter>*rsize</parameter> to the real size of the allocation if
|
||||
<parameter>rsize</parameter> is not <constant>NULL</constant>. If
|
||||
<parameter>extra</parameter> is non-zero, an attempt is made to resize
|
||||
the allocation to be at least <code
|
||||
language="C">(<parameter>size</parameter> +
|
||||
<parameter>extra</parameter>)</code> bytes, though inability to allocate
|
||||
the extra byte(s) will not by itself result in failure. Behavior is
|
||||
undefined if <parameter>size</parameter> is <constant>0</constant>, if
|
||||
request size overflows due to size class and/or alignment constraints, or
|
||||
if <code language="C">(<parameter>size</parameter> +
|
||||
<parameter>extra</parameter> >
|
||||
<constant>SIZE_T_MAX</constant>)</code>.</para>
|
||||
|
||||
<para>The <function>sallocm<parameter/></function> function sets
|
||||
<parameter>*rsize</parameter> to the real size of the allocation.</para>
|
||||
|
||||
<para>The <function>dallocm<parameter/></function> function causes the
|
||||
memory referenced by <parameter>ptr</parameter> to be made available for
|
||||
future allocations.</para>
|
||||
|
||||
<para>The <function>nallocm<parameter/></function> function allocates no
|
||||
memory, but it performs the same size computation as the
|
||||
<function>allocm<parameter/></function> function, and if
|
||||
<parameter>rsize</parameter> is not <constant>NULL</constant> it sets
|
||||
<parameter>*rsize</parameter> to the real size of the allocation that
|
||||
would result from the equivalent <function>allocm<parameter/></function>
|
||||
function call. Behavior is undefined if <parameter>size</parameter> is
|
||||
<constant>0</constant>, or if request size overflows due to size class
|
||||
and/or alignment constraints.</para>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
<refsect1 id="tuning">
|
||||
<title>TUNING</title>
|
||||
@ -1076,9 +926,8 @@ for (i = 0; i < nbins; i++) {
|
||||
<listitem><para>Zero filling enabled/disabled. If enabled, each byte
|
||||
of uninitialized allocated memory will be initialized to 0. Note that
|
||||
this initialization only happens once for each byte, so
|
||||
<function>realloc<parameter/></function>,
|
||||
<function>rallocx<parameter/></function> and
|
||||
<function>rallocm<parameter/></function> calls do not zero memory that
|
||||
<function>realloc<parameter/></function> and
|
||||
<function>rallocx<parameter/></function> calls do not zero memory that
|
||||
was previously allocated. This is intended for debugging and will
|
||||
impact performance negatively. This option is disabled by default.
|
||||
</para></listitem>
|
||||
@ -2253,42 +2102,6 @@ malloc_conf = "xmalloc:true";]]></programlisting>
|
||||
returns the usable size of the allocation pointed to by
|
||||
<parameter>ptr</parameter>. </para>
|
||||
</refsect2>
|
||||
<refsect2>
|
||||
<title>Experimental API</title>
|
||||
<para>The <function>allocm<parameter/></function>,
|
||||
<function>rallocm<parameter/></function>,
|
||||
<function>sallocm<parameter/></function>,
|
||||
<function>dallocm<parameter/></function>, and
|
||||
<function>nallocm<parameter/></function> functions return
|
||||
<constant>ALLOCM_SUCCESS</constant> on success; otherwise they return an
|
||||
error value. The <function>allocm<parameter/></function>,
|
||||
<function>rallocm<parameter/></function>, and
|
||||
<function>nallocm<parameter/></function> functions will fail if:
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><errorname>ALLOCM_ERR_OOM</errorname></term>
|
||||
|
||||
<listitem><para>Out of memory. Insufficient contiguous memory was
|
||||
available to service the allocation request. The
|
||||
<function>allocm<parameter/></function> function additionally sets
|
||||
<parameter>*ptr</parameter> to <constant>NULL</constant>, whereas
|
||||
the <function>rallocm<parameter/></function> function leaves
|
||||
<constant>*ptr</constant> unmodified.</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
The <function>rallocm<parameter/></function> function will also
|
||||
fail if:
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><errorname>ALLOCM_ERR_NOT_MOVED</errorname></term>
|
||||
|
||||
<listitem><para><constant>ALLOCM_NO_MOVE</constant> was specified,
|
||||
but the reallocation request could not be serviced without moving
|
||||
the object.</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
<refsect1 id="environment">
|
||||
<title>ENVIRONMENT</title>
|
||||
|
@ -230,7 +230,6 @@ static const bool config_ivsalloc =
|
||||
#include "jemalloc/internal/jemalloc_internal_macros.h"
|
||||
|
||||
#define MALLOCX_LG_ALIGN_MASK ((int)0x3f)
|
||||
#define ALLOCM_LG_ALIGN_MASK ((int)0x3f)
|
||||
|
||||
/* Smallest size class to support. */
|
||||
#define LG_TINY_MIN 3
|
||||
|
@ -211,7 +211,6 @@ huge_prof_ctx_set
|
||||
huge_ralloc
|
||||
huge_ralloc_no_move
|
||||
huge_salloc
|
||||
iallocm
|
||||
icalloc
|
||||
icalloct
|
||||
idalloc
|
||||
|
@ -1,9 +1,6 @@
|
||||
/* Defined if __attribute__((...)) syntax is supported. */
|
||||
#undef JEMALLOC_HAVE_ATTR
|
||||
|
||||
/* Support the experimental API. */
|
||||
#undef JEMALLOC_EXPERIMENTAL
|
||||
|
||||
/*
|
||||
* Define overrides for non-standard allocator-related functions if they are
|
||||
* present on the system.
|
||||
|
@ -19,23 +19,6 @@
|
||||
/* Bias arena index bits so that 0 encodes "MALLOCX_ARENA() unspecified". */
|
||||
# define MALLOCX_ARENA(a) ((int)(((a)+1) << 8))
|
||||
|
||||
#ifdef JEMALLOC_EXPERIMENTAL
|
||||
# define ALLOCM_LG_ALIGN(la) (la)
|
||||
# if LG_SIZEOF_PTR == 2
|
||||
# define ALLOCM_ALIGN(a) (ffs(a)-1)
|
||||
# else
|
||||
# define ALLOCM_ALIGN(a) \
|
||||
((a < (size_t)INT_MAX) ? ffs(a)-1 : ffs(a>>32)+31)
|
||||
# endif
|
||||
# define ALLOCM_ZERO ((int)0x40)
|
||||
# define ALLOCM_NO_MOVE ((int)0x80)
|
||||
/* Bias arena index bits so that 0 encodes "ALLOCM_ARENA() unspecified". */
|
||||
# define ALLOCM_ARENA(a) ((int)(((a)+1) << 8))
|
||||
# define ALLOCM_SUCCESS 0
|
||||
# define ALLOCM_ERR_OOM 1
|
||||
# define ALLOCM_ERR_NOT_MOVED 2
|
||||
#endif
|
||||
|
||||
#ifdef JEMALLOC_HAVE_ATTR
|
||||
# define JEMALLOC_ATTR(s) __attribute__((s))
|
||||
# define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default"))
|
||||
|
@ -44,15 +44,3 @@ JEMALLOC_EXPORT void * @je_@memalign(size_t alignment, size_t size)
|
||||
#ifdef JEMALLOC_OVERRIDE_VALLOC
|
||||
JEMALLOC_EXPORT void * @je_@valloc(size_t size) JEMALLOC_ATTR(malloc);
|
||||
#endif
|
||||
|
||||
#ifdef JEMALLOC_EXPERIMENTAL
|
||||
JEMALLOC_EXPORT int @je_@allocm(void **ptr, size_t *rsize, size_t size,
|
||||
int flags) JEMALLOC_ATTR(nonnull(1));
|
||||
JEMALLOC_EXPORT int @je_@rallocm(void **ptr, size_t *rsize, size_t size,
|
||||
size_t extra, int flags) JEMALLOC_ATTR(nonnull(1));
|
||||
JEMALLOC_EXPORT int @je_@sallocm(const void *ptr, size_t *rsize, int flags)
|
||||
JEMALLOC_ATTR(nonnull(1));
|
||||
JEMALLOC_EXPORT int @je_@dallocm(void *ptr, int flags)
|
||||
JEMALLOC_ATTR(nonnull(1));
|
||||
JEMALLOC_EXPORT int @je_@nallocm(size_t *rsize, size_t size, int flags);
|
||||
#endif
|
||||
|
@ -1867,91 +1867,6 @@ je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr)
|
||||
* End non-standard functions.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Begin experimental functions.
|
||||
*/
|
||||
#ifdef JEMALLOC_EXPERIMENTAL
|
||||
|
||||
int
|
||||
je_allocm(void **ptr, size_t *rsize, size_t size, int flags)
|
||||
{
|
||||
void *p;
|
||||
|
||||
assert(ptr != NULL);
|
||||
|
||||
p = je_mallocx(size, flags);
|
||||
if (p == NULL)
|
||||
return (ALLOCM_ERR_OOM);
|
||||
if (rsize != NULL)
|
||||
*rsize = isalloc(p, config_prof);
|
||||
*ptr = p;
|
||||
return (ALLOCM_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags)
|
||||
{
|
||||
int ret;
|
||||
bool no_move = flags & ALLOCM_NO_MOVE;
|
||||
|
||||
assert(ptr != NULL);
|
||||
assert(*ptr != NULL);
|
||||
assert(size != 0);
|
||||
assert(SIZE_T_MAX - size >= extra);
|
||||
|
||||
if (no_move) {
|
||||
size_t usize = je_xallocx(*ptr, size, extra, flags);
|
||||
ret = (usize >= size) ? ALLOCM_SUCCESS : ALLOCM_ERR_NOT_MOVED;
|
||||
if (rsize != NULL)
|
||||
*rsize = usize;
|
||||
} else {
|
||||
void *p = je_rallocx(*ptr, size+extra, flags);
|
||||
if (p != NULL) {
|
||||
*ptr = p;
|
||||
ret = ALLOCM_SUCCESS;
|
||||
} else
|
||||
ret = ALLOCM_ERR_OOM;
|
||||
if (rsize != NULL)
|
||||
*rsize = isalloc(*ptr, config_prof);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
je_sallocm(const void *ptr, size_t *rsize, int flags)
|
||||
{
|
||||
|
||||
assert(rsize != NULL);
|
||||
*rsize = je_sallocx(ptr, flags);
|
||||
return (ALLOCM_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
je_dallocm(void *ptr, int flags)
|
||||
{
|
||||
|
||||
je_dallocx(ptr, flags);
|
||||
return (ALLOCM_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
je_nallocm(size_t *rsize, size_t size, int flags)
|
||||
{
|
||||
size_t usize;
|
||||
|
||||
usize = je_nallocx(size, flags);
|
||||
if (usize == 0)
|
||||
return (ALLOCM_ERR_OOM);
|
||||
if (rsize != NULL)
|
||||
*rsize = usize;
|
||||
return (ALLOCM_SUCCESS);
|
||||
}
|
||||
|
||||
#endif
|
||||
/*
|
||||
* End experimental functions.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* The following functions are used by threading libraries for protection of
|
||||
* malloc during fork().
|
||||
|
@ -34,7 +34,7 @@ thd_start(void *arg)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_ALLOCM_ARENA)
|
||||
TEST_BEGIN(test_MALLOCX_ARENA)
|
||||
{
|
||||
thd_t thds[NTHREADS];
|
||||
unsigned i;
|
||||
@ -54,5 +54,5 @@ main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_ALLOCM_ARENA));
|
||||
test_MALLOCX_ARENA));
|
||||
}
|
||||
|
@ -1,107 +0,0 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define CHUNK 0x400000
|
||||
#define MAXALIGN (((size_t)1) << 25)
|
||||
#define NITER 4
|
||||
|
||||
TEST_BEGIN(test_basic)
|
||||
{
|
||||
size_t nsz, rsz, sz;
|
||||
void *p;
|
||||
|
||||
sz = 42;
|
||||
nsz = 0;
|
||||
assert_d_eq(nallocm(&nsz, sz, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected nallocm() error");
|
||||
rsz = 0;
|
||||
assert_d_eq(allocm(&p, &rsz, sz, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
assert_zu_ge(rsz, sz, "Real size smaller than expected");
|
||||
assert_zu_eq(nsz, rsz, "nallocm()/allocm() rsize mismatch");
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
|
||||
assert_d_eq(allocm(&p, NULL, sz, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
|
||||
nsz = 0;
|
||||
assert_d_eq(nallocm(&nsz, sz, ALLOCM_ZERO), ALLOCM_SUCCESS,
|
||||
"Unexpected nallocm() error");
|
||||
rsz = 0;
|
||||
assert_d_eq(allocm(&p, &rsz, sz, ALLOCM_ZERO), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
assert_zu_eq(nsz, rsz, "nallocm()/allocm() rsize mismatch");
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_alignment_and_size)
|
||||
{
|
||||
int r;
|
||||
size_t nsz, rsz, sz, alignment, total;
|
||||
unsigned i;
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++)
|
||||
ps[i] = NULL;
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
total = 0;
|
||||
for (sz = 1;
|
||||
sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
nsz = 0;
|
||||
r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment) |
|
||||
ALLOCM_ZERO);
|
||||
assert_d_eq(r, ALLOCM_SUCCESS,
|
||||
"nallocm() error for alignment=%zu, "
|
||||
"size=%zu (%#zx): %d",
|
||||
alignment, sz, sz, r);
|
||||
rsz = 0;
|
||||
r = allocm(&ps[i], &rsz, sz,
|
||||
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
|
||||
assert_d_eq(r, ALLOCM_SUCCESS,
|
||||
"allocm() error for alignment=%zu, "
|
||||
"size=%zu (%#zx): %d",
|
||||
alignment, sz, sz, r);
|
||||
assert_zu_ge(rsz, sz,
|
||||
"Real size smaller than expected for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
assert_zu_eq(nsz, rsz,
|
||||
"nallocm()/allocm() rsize mismatch for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
assert_ptr_null(
|
||||
(void *)((uintptr_t)ps[i] & (alignment-1)),
|
||||
"%p inadequately aligned for"
|
||||
" alignment=%zu, size=%zu", ps[i],
|
||||
alignment, sz);
|
||||
sallocm(ps[i], &rsz, 0);
|
||||
total += rsz;
|
||||
if (total >= (MAXALIGN << 1))
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < NITER; i++) {
|
||||
if (ps[i] != NULL) {
|
||||
dallocm(ps[i], 0);
|
||||
ps[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_basic,
|
||||
test_alignment_and_size));
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
TEST_BEGIN(test_same_size)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t sz, tsz;
|
||||
|
||||
assert_d_eq(allocm(&p, &sz, 42, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &tsz, sz, 0, ALLOCM_NO_MOVE), ALLOCM_SUCCESS,
|
||||
"Unexpected rallocm() error");
|
||||
assert_ptr_eq(q, p, "Unexpected object move");
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_extra_no_move)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t sz, tsz;
|
||||
|
||||
assert_d_eq(allocm(&p, &sz, 42, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &tsz, sz, sz-42, ALLOCM_NO_MOVE),
|
||||
ALLOCM_SUCCESS, "Unexpected rallocm() error");
|
||||
assert_ptr_eq(q, p, "Unexpected object move");
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_no_move_fail)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t sz, tsz;
|
||||
|
||||
assert_d_eq(allocm(&p, &sz, 42, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE),
|
||||
ALLOCM_ERR_NOT_MOVED, "Unexpected rallocm() result");
|
||||
assert_ptr_eq(q, p, "Unexpected object move");
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_grow_and_shrink)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t tsz;
|
||||
#define NCYCLES 3
|
||||
unsigned i, j;
|
||||
#define NSZS 2500
|
||||
size_t szs[NSZS];
|
||||
#define MAXSZ ZU(12 * 1024 * 1024)
|
||||
|
||||
assert_d_eq(allocm(&p, &szs[0], 1, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
|
||||
for (i = 0; i < NCYCLES; i++) {
|
||||
for (j = 1; j < NSZS && szs[j-1] < MAXSZ; j++) {
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &szs[j], szs[j-1]+1, 0, 0),
|
||||
ALLOCM_SUCCESS,
|
||||
"Unexpected rallocm() error for size=%zu-->%zu",
|
||||
szs[j-1], szs[j-1]+1);
|
||||
assert_zu_ne(szs[j], szs[j-1]+1,
|
||||
"Expected size to at least: %zu", szs[j-1]+1);
|
||||
p = q;
|
||||
}
|
||||
|
||||
for (j--; j > 0; j--) {
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &tsz, szs[j-1], 0, 0),
|
||||
ALLOCM_SUCCESS,
|
||||
"Unexpected rallocm() error for size=%zu-->%zu",
|
||||
szs[j], szs[j-1]);
|
||||
assert_zu_eq(tsz, szs[j-1],
|
||||
"Expected size=%zu, got size=%zu", szs[j-1], tsz);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_same_size,
|
||||
test_extra_no_move,
|
||||
test_no_move_fail,
|
||||
test_grow_and_shrink));
|
||||
}
|
@ -54,7 +54,7 @@ thd_sender_start(void *arg)
|
||||
mq_msg_t *msg;
|
||||
void *p;
|
||||
p = mallocx(sizeof(mq_msg_t), 0);
|
||||
assert_ptr_not_null(p, "Unexpected allocm() failure");
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() failure");
|
||||
msg = (mq_msg_t *)p;
|
||||
mq_put(mq, msg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user