Jemalloc upgraded to version 5.0.1.

This commit is contained in:
antirez
2018-05-24 17:17:37 +02:00
parent 8f4e2075a7
commit 08e1c8e820
300 changed files with 40996 additions and 35024 deletions

View File

@ -1,14 +1,53 @@
#include "test/jemalloc_test.h"
TEST_BEGIN(test_grow_and_shrink)
{
static unsigned
get_nsizes_impl(const char *cmd) {
unsigned ret;
size_t z;
z = sizeof(unsigned);
assert_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
"Unexpected mallctl(\"%s\", ...) failure", cmd);
return ret;
}
static unsigned
get_nlarge(void) {
return get_nsizes_impl("arenas.nlextents");
}
static size_t
get_size_impl(const char *cmd, size_t ind) {
size_t ret;
size_t z;
size_t mib[4];
size_t miblen = 4;
z = sizeof(size_t);
assert_d_eq(mallctlnametomib(cmd, mib, &miblen),
0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
mib[2] = ind;
z = sizeof(size_t);
assert_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
return ret;
}
static size_t
get_large_size(size_t ind) {
return get_size_impl("arenas.lextent.0.size", ind);
}
TEST_BEGIN(test_grow_and_shrink) {
void *p, *q;
size_t tsz;
#define NCYCLES 3
#define NCYCLES 3
unsigned i, j;
#define NSZS 2500
#define NSZS 1024
size_t szs[NSZS];
#define MAXSZ ZU(12 * 1024 * 1024)
#define MAXSZ ZU(12 * 1024 * 1024)
p = mallocx(1, 0);
assert_ptr_not_null(p, "Unexpected mallocx() error");
@ -46,8 +85,7 @@ TEST_BEGIN(test_grow_and_shrink)
TEST_END
static bool
validate_fill(const void *p, uint8_t c, size_t offset, size_t len)
{
validate_fill(const void *p, uint8_t c, size_t offset, size_t len) {
bool ret = false;
const uint8_t *buf = (const uint8_t *)p;
size_t i;
@ -62,16 +100,15 @@ validate_fill(const void *p, uint8_t c, size_t offset, size_t len)
}
}
return (ret);
return ret;
}
TEST_BEGIN(test_zero)
{
TEST_BEGIN(test_zero) {
void *p, *q;
size_t psz, qsz, i, j;
size_t start_sizes[] = {1, 3*1024, 63*1024, 4095*1024};
#define FILL_BYTE 0xaaU
#define RANGE 2048
#define FILL_BYTE 0xaaU
#define RANGE 2048
for (i = 0; i < sizeof(start_sizes)/sizeof(size_t); i++) {
size_t start_size = start_sizes[i];
@ -110,11 +147,10 @@ TEST_BEGIN(test_zero)
}
TEST_END
TEST_BEGIN(test_align)
{
TEST_BEGIN(test_align) {
void *p, *q;
size_t align;
#define MAX_ALIGN (ZU(1) << 25)
#define MAX_ALIGN (ZU(1) << 25)
align = ZU(1);
p = mallocx(1, MALLOCX_ALIGN(align));
@ -135,25 +171,24 @@ TEST_BEGIN(test_align)
}
TEST_END
TEST_BEGIN(test_lg_align_and_zero)
{
TEST_BEGIN(test_lg_align_and_zero) {
void *p, *q;
size_t lg_align, sz;
#define MAX_LG_ALIGN 25
#define MAX_VALIDATE (ZU(1) << 22)
unsigned lg_align;
size_t sz;
#define MAX_LG_ALIGN 25
#define MAX_VALIDATE (ZU(1) << 22)
lg_align = ZU(0);
lg_align = 0;
p = mallocx(1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO);
assert_ptr_not_null(p, "Unexpected mallocx() error");
for (lg_align++; lg_align <= MAX_LG_ALIGN; lg_align++) {
q = rallocx(p, 1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO);
assert_ptr_not_null(q,
"Unexpected rallocx() error for lg_align=%zu", lg_align);
"Unexpected rallocx() error for lg_align=%u", lg_align);
assert_ptr_null(
(void *)((uintptr_t)q & ((ZU(1) << lg_align)-1)),
"%p inadequately aligned for lg_align=%zu",
q, lg_align);
"%p inadequately aligned for lg_align=%u", q, lg_align);
sz = sallocx(q, 0);
if ((sz << 1) <= MAX_VALIDATE) {
assert_false(validate_fill(q, 0, 0, sz),
@ -173,13 +208,38 @@ TEST_BEGIN(test_lg_align_and_zero)
}
TEST_END
int
main(void)
{
TEST_BEGIN(test_overflow) {
size_t largemax;
void *p;
return (test(
largemax = get_large_size(get_nlarge()-1);
p = mallocx(1, 0);
assert_ptr_not_null(p, "Unexpected mallocx() failure");
assert_ptr_null(rallocx(p, largemax+1, 0),
"Expected OOM for rallocx(p, size=%#zx, 0)", largemax+1);
assert_ptr_null(rallocx(p, ZU(PTRDIFF_MAX)+1, 0),
"Expected OOM for rallocx(p, size=%#zx, 0)", ZU(PTRDIFF_MAX)+1);
assert_ptr_null(rallocx(p, SIZE_T_MAX, 0),
"Expected OOM for rallocx(p, size=%#zx, 0)", SIZE_T_MAX);
assert_ptr_null(rallocx(p, 1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX)+1)),
"Expected OOM for rallocx(p, size=1, MALLOCX_ALIGN(%#zx))",
ZU(PTRDIFF_MAX)+1);
dallocx(p, 0);
}
TEST_END
int
main(void) {
return test(
test_grow_and_shrink,
test_zero,
test_align,
test_lg_align_and_zero));
test_lg_align_and_zero,
test_overflow);
}