summaryrefslogtreecommitdiff
path: root/deps/jemalloc/test
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-05-15 15:27:12 +0200
committerantirez <antirez@gmail.com>2012-05-16 11:09:45 +0200
commitad4c0b4117ec15c0061b702f230caf1bc5eb4e06 (patch)
tree76b8e044bab3cec328dc8c8c9210a3088f9d1849 /deps/jemalloc/test
parent3c72c94aaeb98b0c4c1a98992539f8839cea1d74 (diff)
downloadredis-ad4c0b4117ec15c0061b702f230caf1bc5eb4e06.tar.gz
Jemalloc updated to 3.0.0.
Full changelog here: http://www.canonware.com/cgi-bin/gitweb.cgi?p=jemalloc.git;a=blob_plain;f=ChangeLog;hb=master Notable improvements from the point of view of Redis: 1) Bugfixing. 2) Support for Valgrind. 3) Support for OSX Lion, FreeBSD.
Diffstat (limited to 'deps/jemalloc/test')
-rw-r--r--deps/jemalloc/test/aligned_alloc.c119
-rw-r--r--deps/jemalloc/test/aligned_alloc.exp25
-rw-r--r--deps/jemalloc/test/allocated.c88
-rw-r--r--deps/jemalloc/test/allocm.c157
-rw-r--r--deps/jemalloc/test/bitmap.c32
-rw-r--r--deps/jemalloc/test/jemalloc_test.h.in47
-rw-r--r--deps/jemalloc/test/mremap.c31
-rw-r--r--deps/jemalloc/test/posix_memalign.c58
-rw-r--r--deps/jemalloc/test/rallocm.c84
-rw-r--r--deps/jemalloc/test/thread_arena.c56
-rw-r--r--deps/jemalloc/test/thread_tcache_enabled.c91
-rw-r--r--deps/jemalloc/test/thread_tcache_enabled.exp2
12 files changed, 540 insertions, 250 deletions
diff --git a/deps/jemalloc/test/aligned_alloc.c b/deps/jemalloc/test/aligned_alloc.c
new file mode 100644
index 000000000..5a9b0caea
--- /dev/null
+++ b/deps/jemalloc/test/aligned_alloc.c
@@ -0,0 +1,119 @@
+#define JEMALLOC_MANGLE
+#include "jemalloc_test.h"
+
+#define CHUNK 0x400000
+/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
+#define MAXALIGN ((size_t)0x2000000LU)
+#define NITER 4
+
+int
+main(void)
+{
+ size_t alignment, size, total;
+ unsigned i;
+ void *p, *ps[NITER];
+
+ malloc_printf("Test begin\n");
+
+ /* Test error conditions. */
+ alignment = 0;
+ set_errno(0);
+ p = aligned_alloc(alignment, 1);
+ if (p != NULL || get_errno() != EINVAL) {
+ malloc_printf(
+ "Expected error for invalid alignment %zu\n", alignment);
+ }
+
+ for (alignment = sizeof(size_t); alignment < MAXALIGN;
+ alignment <<= 1) {
+ set_errno(0);
+ p = aligned_alloc(alignment + 1, 1);
+ if (p != NULL || get_errno() != EINVAL) {
+ malloc_printf(
+ "Expected error for invalid alignment %zu\n",
+ alignment + 1);
+ }
+ }
+
+#if LG_SIZEOF_PTR == 3
+ alignment = UINT64_C(0x8000000000000000);
+ size = UINT64_C(0x8000000000000000);
+#else
+ alignment = 0x80000000LU;
+ size = 0x80000000LU;
+#endif
+ set_errno(0);
+ p = aligned_alloc(alignment, size);
+ if (p != NULL || get_errno() != ENOMEM) {
+ malloc_printf(
+ "Expected error for aligned_alloc(%zu, %zu)\n",
+ alignment, size);
+ }
+
+#if LG_SIZEOF_PTR == 3
+ alignment = UINT64_C(0x4000000000000000);
+ size = UINT64_C(0x8400000000000001);
+#else
+ alignment = 0x40000000LU;
+ size = 0x84000001LU;
+#endif
+ set_errno(0);
+ p = aligned_alloc(alignment, size);
+ if (p != NULL || get_errno() != ENOMEM) {
+ malloc_printf(
+ "Expected error for aligned_alloc(%zu, %zu)\n",
+ alignment, size);
+ }
+
+ alignment = 0x10LU;
+#if LG_SIZEOF_PTR == 3
+ size = UINT64_C(0xfffffffffffffff0);
+#else
+ size = 0xfffffff0LU;
+#endif
+ set_errno(0);
+ p = aligned_alloc(alignment, size);
+ if (p != NULL || get_errno() != ENOMEM) {
+ malloc_printf(
+ "Expected error for aligned_alloc(&p, %zu, %zu)\n",
+ alignment, size);
+ }
+
+ for (i = 0; i < NITER; i++)
+ ps[i] = NULL;
+
+ for (alignment = 8;
+ alignment <= MAXALIGN;
+ alignment <<= 1) {
+ total = 0;
+ malloc_printf("Alignment: %zu\n", alignment);
+ for (size = 1;
+ size < 3 * alignment && size < (1U << 31);
+ size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
+ for (i = 0; i < NITER; i++) {
+ ps[i] = aligned_alloc(alignment, size);
+ if (ps[i] == NULL) {
+ char buf[BUFERROR_BUF];
+
+ buferror(buf, sizeof(buf));
+ malloc_printf(
+ "Error for size %zu (%#zx): %s\n",
+ size, size, buf);
+ exit(1);
+ }
+ total += malloc_usable_size(ps[i]);
+ if (total >= (MAXALIGN << 1))
+ break;
+ }
+ for (i = 0; i < NITER; i++) {
+ if (ps[i] != NULL) {
+ free(ps[i]);
+ ps[i] = NULL;
+ }
+ }
+ }
+ }
+
+ malloc_printf("Test end\n");
+ return (0);
+}
diff --git a/deps/jemalloc/test/aligned_alloc.exp b/deps/jemalloc/test/aligned_alloc.exp
new file mode 100644
index 000000000..b5061c727
--- /dev/null
+++ b/deps/jemalloc/test/aligned_alloc.exp
@@ -0,0 +1,25 @@
+Test begin
+Alignment: 8
+Alignment: 16
+Alignment: 32
+Alignment: 64
+Alignment: 128
+Alignment: 256
+Alignment: 512
+Alignment: 1024
+Alignment: 2048
+Alignment: 4096
+Alignment: 8192
+Alignment: 16384
+Alignment: 32768
+Alignment: 65536
+Alignment: 131072
+Alignment: 262144
+Alignment: 524288
+Alignment: 1048576
+Alignment: 2097152
+Alignment: 4194304
+Alignment: 8388608
+Alignment: 16777216
+Alignment: 33554432
+Test end
diff --git a/deps/jemalloc/test/allocated.c b/deps/jemalloc/test/allocated.c
index b1e40e472..9884905d8 100644
--- a/deps/jemalloc/test/allocated.c
+++ b/deps/jemalloc/test/allocated.c
@@ -1,17 +1,8 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <pthread.h>
-#include <assert.h>
-#include <errno.h>
-#include <string.h>
-
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
void *
-thread_start(void *arg)
+je_thread_start(void *arg)
{
int err;
void *p;
@@ -20,89 +11,85 @@ thread_start(void *arg)
size_t sz, usize;
sz = sizeof(a0);
- if ((err = JEMALLOC_P(mallctl)("thread.allocated", &a0, &sz, NULL,
- 0))) {
+ if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) {
if (err == ENOENT) {
#ifdef JEMALLOC_STATS
assert(false);
#endif
- goto RETURN;
+ goto label_return;
}
- fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
+ malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
exit(1);
}
sz = sizeof(ap0);
- if ((err = JEMALLOC_P(mallctl)("thread.allocatedp", &ap0, &sz, NULL,
- 0))) {
+ if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) {
if (err == ENOENT) {
#ifdef JEMALLOC_STATS
assert(false);
#endif
- goto RETURN;
+ goto label_return;
}
- fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
+ malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
exit(1);
}
assert(*ap0 == a0);
sz = sizeof(d0);
- if ((err = JEMALLOC_P(mallctl)("thread.deallocated", &d0, &sz, NULL,
- 0))) {
+ if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) {
if (err == ENOENT) {
#ifdef JEMALLOC_STATS
assert(false);
#endif
- goto RETURN;
+ goto label_return;
}
- fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
+ malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
exit(1);
}
sz = sizeof(dp0);
- if ((err = JEMALLOC_P(mallctl)("thread.deallocatedp", &dp0, &sz, NULL,
- 0))) {
+ if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) {
if (err == ENOENT) {
#ifdef JEMALLOC_STATS
assert(false);
#endif
- goto RETURN;
+ goto label_return;
}
- fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
+ malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
exit(1);
}
assert(*dp0 == d0);
- p = JEMALLOC_P(malloc)(1);
+ p = malloc(1);
if (p == NULL) {
- fprintf(stderr, "%s(): Error in malloc()\n", __func__);
+ malloc_printf("%s(): Error in malloc()\n", __func__);
exit(1);
}
sz = sizeof(a1);
- JEMALLOC_P(mallctl)("thread.allocated", &a1, &sz, NULL, 0);
+ mallctl("thread.allocated", &a1, &sz, NULL, 0);
sz = sizeof(ap1);
- JEMALLOC_P(mallctl)("thread.allocatedp", &ap1, &sz, NULL, 0);
+ mallctl("thread.allocatedp", &ap1, &sz, NULL, 0);
assert(*ap1 == a1);
assert(ap0 == ap1);
- usize = JEMALLOC_P(malloc_usable_size)(p);
+ usize = malloc_usable_size(p);
assert(a0 + usize <= a1);
- JEMALLOC_P(free)(p);
+ free(p);
sz = sizeof(d1);
- JEMALLOC_P(mallctl)("thread.deallocated", &d1, &sz, NULL, 0);
+ mallctl("thread.deallocated", &d1, &sz, NULL, 0);
sz = sizeof(dp1);
- JEMALLOC_P(mallctl)("thread.deallocatedp", &dp1, &sz, NULL, 0);
+ mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0);
assert(*dp1 == d1);
assert(dp0 == dp1);
assert(d0 + usize <= d1);
-RETURN:
+label_return:
return (NULL);
}
@@ -110,33 +97,22 @@ int
main(void)
{
int ret = 0;
- pthread_t thread;
+ je_thread_t thread;
- fprintf(stderr, "Test begin\n");
+ malloc_printf("Test begin\n");
- thread_start(NULL);
+ je_thread_start(NULL);
- if (pthread_create(&thread, NULL, thread_start, NULL)
- != 0) {
- fprintf(stderr, "%s(): Error in pthread_create()\n", __func__);
- ret = 1;
- goto RETURN;
- }
- pthread_join(thread, (void *)&ret);
+ je_thread_create(&thread, je_thread_start, NULL);
+ je_thread_join(thread, (void *)&ret);
- thread_start(NULL);
+ je_thread_start(NULL);
- if (pthread_create(&thread, NULL, thread_start, NULL)
- != 0) {
- fprintf(stderr, "%s(): Error in pthread_create()\n", __func__);
- ret = 1;
- goto RETURN;
- }
- pthread_join(thread, (void *)&ret);
+ je_thread_create(&thread, je_thread_start, NULL);
+ je_thread_join(thread, (void *)&ret);
- thread_start(NULL);
+ je_thread_start(NULL);
-RETURN:
- fprintf(stderr, "Test end\n");
+ malloc_printf("Test end\n");
return (ret);
}
diff --git a/deps/jemalloc/test/allocm.c b/deps/jemalloc/test/allocm.c
index 59d0002e7..80be673b8 100644
--- a/deps/jemalloc/test/allocm.c
+++ b/deps/jemalloc/test/allocm.c
@@ -1,13 +1,9 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
#define CHUNK 0x400000
-/* #define MAXALIGN ((size_t)0x80000000000LLU) */
-#define MAXALIGN ((size_t)0x2000000LLU)
+/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
+#define MAXALIGN ((size_t)0x2000000LU)
#define NITER 4
int
@@ -15,79 +11,122 @@ main(void)
{
int r;
void *p;
- size_t sz, alignment, total, tsz;
+ size_t nsz, rsz, sz, alignment, total;
unsigned i;
void *ps[NITER];
- fprintf(stderr, "Test begin\n");
+ malloc_printf("Test begin\n");
- sz = 0;
- r = JEMALLOC_P(allocm)(&p, &sz, 42, 0);
+ sz = 42;
+ nsz = 0;
+ r = nallocm(&nsz, sz, 0);
if (r != ALLOCM_SUCCESS) {
- fprintf(stderr, "Unexpected allocm() error\n");
+ malloc_printf("Unexpected nallocm() error\n");
abort();
}
- if (sz < 42)
- fprintf(stderr, "Real size smaller than expected\n");
- if (JEMALLOC_P(dallocm)(p, 0) != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected dallocm() error\n");
+ rsz = 0;
+ r = allocm(&p, &rsz, sz, 0);
+ if (r != ALLOCM_SUCCESS) {
+ malloc_printf("Unexpected allocm() error\n");
+ abort();
+ }
+ if (rsz < sz)
+ malloc_printf("Real size smaller than expected\n");
+ if (nsz != rsz)
+ malloc_printf("nallocm()/allocm() rsize mismatch\n");
+ if (dallocm(p, 0) != ALLOCM_SUCCESS)
+ malloc_printf("Unexpected dallocm() error\n");
- r = JEMALLOC_P(allocm)(&p, NULL, 42, 0);
+ r = allocm(&p, NULL, sz, 0);
if (r != ALLOCM_SUCCESS) {
- fprintf(stderr, "Unexpected allocm() error\n");
+ malloc_printf("Unexpected allocm() error\n");
abort();
}
- if (JEMALLOC_P(dallocm)(p, 0) != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected dallocm() error\n");
+ if (dallocm(p, 0) != ALLOCM_SUCCESS)
+ malloc_printf("Unexpected dallocm() error\n");
- r = JEMALLOC_P(allocm)(&p, NULL, 42, ALLOCM_ZERO);
+ nsz = 0;
+ r = nallocm(&nsz, sz, ALLOCM_ZERO);
+ if (r != ALLOCM_SUCCESS) {
+ malloc_printf("Unexpected nallocm() error\n");
+ abort();
+ }
+ rsz = 0;
+ r = allocm(&p, &rsz, sz, ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) {
- fprintf(stderr, "Unexpected allocm() error\n");
+ malloc_printf("Unexpected allocm() error\n");
abort();
}
- if (JEMALLOC_P(dallocm)(p, 0) != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected dallocm() error\n");
+ if (nsz != rsz)
+ malloc_printf("nallocm()/allocm() rsize mismatch\n");
+ if (dallocm(p, 0) != ALLOCM_SUCCESS)
+ malloc_printf("Unexpected dallocm() error\n");
#if LG_SIZEOF_PTR == 3
- alignment = 0x8000000000000000LLU;
- sz = 0x8000000000000000LLU;
+ alignment = UINT64_C(0x8000000000000000);
+ sz = UINT64_C(0x8000000000000000);
#else
alignment = 0x80000000LU;
sz = 0x80000000LU;
#endif
- r = JEMALLOC_P(allocm)(&p, NULL, sz, ALLOCM_ALIGN(alignment));
+ nsz = 0;
+ r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
+ if (r == ALLOCM_SUCCESS) {
+ malloc_printf(
+ "Expected error for nallocm(&nsz, %zu, %#x)\n",
+ sz, ALLOCM_ALIGN(alignment));
+ }
+ rsz = 0;
+ r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) {
- fprintf(stderr,
- "Expected error for allocm(&p, %zu, 0x%x)\n",
+ malloc_printf(
+ "Expected error for allocm(&p, %zu, %#x)\n",
sz, ALLOCM_ALIGN(alignment));
}
+ if (nsz != rsz)
+ malloc_printf("nallocm()/allocm() rsize mismatch\n");
#if LG_SIZEOF_PTR == 3
- alignment = 0x4000000000000000LLU;
- sz = 0x8400000000000001LLU;
+ alignment = UINT64_C(0x4000000000000000);
+ sz = UINT64_C(0x8400000000000001);
#else
alignment = 0x40000000LU;
sz = 0x84000001LU;
#endif
- r = JEMALLOC_P(allocm)(&p, NULL, sz, ALLOCM_ALIGN(alignment));
+ nsz = 0;
+ r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
+ if (r != ALLOCM_SUCCESS)
+ malloc_printf("Unexpected nallocm() error\n");
+ rsz = 0;
+ r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) {
- fprintf(stderr,
- "Expected error for allocm(&p, %zu, 0x%x)\n",
+ malloc_printf(
+ "Expected error for allocm(&p, %zu, %#x)\n",
sz, ALLOCM_ALIGN(alignment));
}
- alignment = 0x10LLU;
+ alignment = 0x10LU;
#if LG_SIZEOF_PTR == 3
- sz = 0xfffffffffffffff0LLU;
+ sz = UINT64_C(0xfffffffffffffff0);
#else
- sz = 0xfffffff0LU;
+ sz = 0xfffffff0LU;
#endif
- r = JEMALLOC_P(allocm)(&p, NULL, sz, ALLOCM_ALIGN(alignment));
+ nsz = 0;
+ r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) {
- fprintf(stderr,
- "Expected error for allocm(&p, %zu, 0x%x)\n",
+ malloc_printf(
+ "Expected error for nallocm(&nsz, %zu, %#x)\n",
sz, ALLOCM_ALIGN(alignment));
}
+ rsz = 0;
+ r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
+ if (r == ALLOCM_SUCCESS) {
+ malloc_printf(
+ "Expected error for allocm(&p, %zu, %#x)\n",
+ sz, ALLOCM_ALIGN(alignment));
+ }
+ if (nsz != rsz)
+ malloc_printf("nallocm()/allocm() rsize mismatch\n");
for (i = 0; i < NITER; i++)
ps[i] = NULL;
@@ -96,38 +135,60 @@ main(void)
alignment <= MAXALIGN;
alignment <<= 1) {
total = 0;
- fprintf(stderr, "Alignment: %zu\n", alignment);
+ malloc_printf("Alignment: %zu\n", alignment);
for (sz = 1;
sz < 3 * alignment && sz < (1U << 31);
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
for (i = 0; i < NITER; i++) {
- r = JEMALLOC_P(allocm)(&ps[i], NULL, sz,
+ nsz = 0;
+ r = nallocm(&nsz, sz,
+ ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
+ if (r != ALLOCM_SUCCESS) {
+ malloc_printf(
+ "nallocm() error for size %zu"
+ " (%#zx): %d\n",
+ sz, sz, r);
+ exit(1);
+ }
+ rsz = 0;
+ r = allocm(&ps[i], &rsz, sz,
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) {
- fprintf(stderr,
- "Error for size %zu (0x%zx): %d\n",
+ malloc_printf(
+ "allocm() error for size %zu"
+ " (%#zx): %d\n",
sz, sz, r);
exit(1);
}
+ if (rsz < sz) {
+ malloc_printf(
+ "Real size smaller than"
+ " expected\n");
+ }
+ if (nsz != rsz) {
+ malloc_printf(
+ "nallocm()/allocm() rsize"
+ " mismatch\n");
+ }
if ((uintptr_t)p & (alignment-1)) {
- fprintf(stderr,
+ malloc_printf(
"%p inadequately aligned for"
" alignment: %zu\n", p, alignment);
}
- JEMALLOC_P(sallocm)(ps[i], &tsz, 0);
- total += tsz;
+ sallocm(ps[i], &rsz, 0);
+ total += rsz;
if (total >= (MAXALIGN << 1))
break;
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
- JEMALLOC_P(dallocm)(ps[i], 0);
+ dallocm(ps[i], 0);
ps[i] = NULL;
}
}
}
}
- fprintf(stderr, "Test end\n");
+ malloc_printf("Test end\n");
return (0);
}
diff --git a/deps/jemalloc/test/bitmap.c b/deps/jemalloc/test/bitmap.c
index adfaacfe5..b2cb63004 100644
--- a/deps/jemalloc/test/bitmap.c
+++ b/deps/jemalloc/test/bitmap.c
@@ -1,18 +1,6 @@
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
-/*
- * Avoid using the assert() from jemalloc_internal.h, since it requires
- * internal libjemalloc functionality.
- * */
-#include <assert.h>
-
-/*
- * Directly include the bitmap code, since it isn't exposed outside
- * libjemalloc.
- */
-#include "../src/bitmap.c"
-
#if (LG_BITMAP_MAXBITS > 12)
# define MAXBITS 4500
#else
@@ -42,11 +30,13 @@ test_bitmap_init(void)
bitmap_info_init(&binfo, i);
{
size_t j;
- bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
+ bitmap_t *bitmap = malloc(sizeof(bitmap_t) *
+ bitmap_info_ngroups(&binfo));
bitmap_init(bitmap, &binfo);
for (j = 0; j < i; j++)
assert(bitmap_get(bitmap, &binfo, j) == false);
+ free(bitmap);
}
}
@@ -62,12 +52,14 @@ test_bitmap_set(void)
bitmap_info_init(&binfo, i);
{
size_t j;
- bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
+ bitmap_t *bitmap = malloc(sizeof(bitmap_t) *
+ bitmap_info_ngroups(&binfo));
bitmap_init(bitmap, &binfo);
for (j = 0; j < i; j++)
bitmap_set(bitmap, &binfo, j);
assert(bitmap_full(bitmap, &binfo));
+ free(bitmap);
}
}
}
@@ -82,7 +74,8 @@ test_bitmap_unset(void)
bitmap_info_init(&binfo, i);
{
size_t j;
- bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
+ bitmap_t *bitmap = malloc(sizeof(bitmap_t) *
+ bitmap_info_ngroups(&binfo));
bitmap_init(bitmap, &binfo);
for (j = 0; j < i; j++)
@@ -93,6 +86,7 @@ test_bitmap_unset(void)
for (j = 0; j < i; j++)
bitmap_set(bitmap, &binfo, j);
assert(bitmap_full(bitmap, &binfo));
+ free(bitmap);
}
}
}
@@ -107,7 +101,8 @@ test_bitmap_sfu(void)
bitmap_info_init(&binfo, i);
{
ssize_t j;
- bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
+ bitmap_t *bitmap = malloc(sizeof(bitmap_t) *
+ bitmap_info_ngroups(&binfo));
bitmap_init(bitmap, &binfo);
/* Iteratively set bits starting at the beginning. */
@@ -137,6 +132,7 @@ test_bitmap_sfu(void)
}
assert(bitmap_sfu(bitmap, &binfo) == i - 1);
assert(bitmap_full(bitmap, &binfo));
+ free(bitmap);
}
}
}
@@ -144,7 +140,7 @@ test_bitmap_sfu(void)
int
main(void)
{
- fprintf(stderr, "Test begin\n");
+ malloc_printf("Test begin\n");
test_bitmap_size();
test_bitmap_init();
@@ -152,6 +148,6 @@ main(void)
test_bitmap_unset();
test_bitmap_sfu();
- fprintf(stderr, "Test end\n");
+ malloc_printf("Test end\n");
return (0);
}
diff --git a/deps/jemalloc/test/jemalloc_test.h.in b/deps/jemalloc/test/jemalloc_test.h.in
index 0c48895e7..e38b48efa 100644
--- a/deps/jemalloc/test/jemalloc_test.h.in
+++ b/deps/jemalloc/test/jemalloc_test.h.in
@@ -4,3 +4,50 @@
* have a different name.
*/
#include "jemalloc/jemalloc@install_suffix@.h"
+#include "jemalloc/internal/jemalloc_internal.h"
+
+/* Abstraction layer for threading in tests */
+#ifdef _WIN32
+#include <windows.h>
+
+typedef HANDLE je_thread_t;
+
+void
+je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
+{
+ LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc;
+ *thread = CreateThread(NULL, 0, routine, arg, 0, NULL);
+ if (*thread == NULL) {
+ malloc_printf("Error in CreateThread()\n");
+ exit(1);
+ }
+}
+
+void
+je_thread_join(je_thread_t thread, void **ret)
+{
+ WaitForSingleObject(thread, INFINITE);
+}
+
+#else
+#include <pthread.h>
+
+typedef pthread_t je_thread_t;
+
+void
+je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
+{
+
+ if (pthread_create(thread, NULL, proc, arg) != 0) {
+ malloc_printf("Error in pthread_create()\n");
+ exit(1);
+ }
+}
+
+void
+je_thread_join(je_thread_t thread, void **ret)
+{
+
+ pthread_join(thread, ret);
+}
+#endif
diff --git a/deps/jemalloc/test/mremap.c b/deps/jemalloc/test/mremap.c
index 146c66f42..47efa7c41 100644
--- a/deps/jemalloc/test/mremap.c
+++ b/deps/jemalloc/test/mremap.c
@@ -1,9 +1,3 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <errno.h>
-#include <string.h>
-
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
@@ -14,33 +8,32 @@ main(void)
size_t sz, lg_chunk, chunksize, i;
char *p, *q;
- fprintf(stderr, "Test begin\n");
+ malloc_printf("Test begin\n");
sz = sizeof(lg_chunk);
- if ((err = JEMALLOC_P(mallctl)("opt.lg_chunk", &lg_chunk, &sz, NULL,
- 0))) {
+ if ((err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0))) {
assert(err != ENOENT);
- fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
+ malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
ret = 1;
- goto RETURN;
+ goto label_return;
}
chunksize = ((size_t)1U) << lg_chunk;
p = (char *)malloc(chunksize);
if (p == NULL) {
- fprintf(stderr, "malloc(%zu) --> %p\n", chunksize, p);
+ malloc_printf("malloc(%zu) --> %p\n", chunksize, p);
ret = 1;
- goto RETURN;
+ goto label_return;
}
memset(p, 'a', chunksize);
q = (char *)realloc(p, chunksize * 2);
if (q == NULL) {
- fprintf(stderr, "realloc(%p, %zu) --> %p\n", p, chunksize * 2,
+ malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize * 2,
q);
ret = 1;
- goto RETURN;
+ goto label_return;
}
for (i = 0; i < chunksize; i++) {
assert(q[i] == 'a');
@@ -50,9 +43,9 @@ main(void)
q = (char *)realloc(p, chunksize);
if (q == NULL) {
- fprintf(stderr, "realloc(%p, %zu) --> %p\n", p, chunksize, q);
+ malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize, q);
ret = 1;
- goto RETURN;
+ goto label_return;
}
for (i = 0; i < chunksize; i++) {
assert(q[i] == 'a');
@@ -61,7 +54,7 @@ main(void)
free(q);
ret = 0;
-RETURN:
- fprintf(stderr, "Test end\n");
+label_return:
+ malloc_printf("Test end\n");
return (ret);
}
diff --git a/deps/jemalloc/test/posix_memalign.c b/deps/jemalloc/test/posix_memalign.c
index 3e306c01d..2185bcf76 100644
--- a/deps/jemalloc/test/posix_memalign.c
+++ b/deps/jemalloc/test/posix_memalign.c
@@ -1,15 +1,9 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
#define CHUNK 0x400000
-/* #define MAXALIGN ((size_t)0x80000000000LLU) */
-#define MAXALIGN ((size_t)0x2000000LLU)
+/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
+#define MAXALIGN ((size_t)0x2000000LU)
#define NITER 4
int
@@ -20,13 +14,13 @@ main(void)
int err;
void *p, *ps[NITER];
- fprintf(stderr, "Test begin\n");
+ malloc_printf("Test begin\n");
/* Test error conditions. */
for (alignment = 0; alignment < sizeof(void *); alignment++) {
- err = JEMALLOC_P(posix_memalign)(&p, alignment, 1);
+ err = posix_memalign(&p, alignment, 1);
if (err != EINVAL) {
- fprintf(stderr,
+ malloc_printf(
"Expected error for invalid alignment %zu\n",
alignment);
}
@@ -34,51 +28,51 @@ main(void)
for (alignment = sizeof(size_t); alignment < MAXALIGN;
alignment <<= 1) {
- err = JEMALLOC_P(posix_memalign)(&p, alignment + 1, 1);
+ err = posix_memalign(&p, alignment + 1, 1);
if (err == 0) {
- fprintf(stderr,
+ malloc_printf(
"Expected error for invalid alignment %zu\n",
alignment + 1);
}
}
#if LG_SIZEOF_PTR == 3
- alignment = 0x8000000000000000LLU;
- size = 0x8000000000000000LLU;
+ alignment = UINT64_C(0x8000000000000000);
+ size = UINT64_C(0x8000000000000000);
#else
alignment = 0x80000000LU;
size = 0x80000000LU;
#endif
- err = JEMALLOC_P(posix_memalign)(&p, alignment, size);
+ err = posix_memalign(&p, alignment, size);
if (err == 0) {
- fprintf(stderr,
+ malloc_printf(
"Expected error for posix_memalign(&p, %zu, %zu)\n",
alignment, size);
}
#if LG_SIZEOF_PTR == 3
- alignment = 0x4000000000000000LLU;
- size = 0x8400000000000001LLU;
+ alignment = UINT64_C(0x4000000000000000);
+ size = UINT64_C(0x8400000000000001);
#else
alignment = 0x40000000LU;
size = 0x84000001LU;
#endif
- err = JEMALLOC_P(posix_memalign)(&p, alignment, size);
+ err = posix_memalign(&p, alignment, size);
if (err == 0) {
- fprintf(stderr,
+ malloc_printf(
"Expected error for posix_memalign(&p, %zu, %zu)\n",
alignment, size);
}
- alignment = 0x10LLU;
+ alignment = 0x10LU;
#if LG_SIZEOF_PTR == 3
- size = 0xfffffffffffffff0LLU;
+ size = UINT64_C(0xfffffffffffffff0);
#else
size = 0xfffffff0LU;
#endif
- err = JEMALLOC_P(posix_memalign)(&p, alignment, size);
+ err = posix_memalign(&p, alignment, size);
if (err == 0) {
- fprintf(stderr,
+ malloc_printf(
"Expected error for posix_memalign(&p, %zu, %zu)\n",
alignment, size);
}
@@ -90,32 +84,32 @@ main(void)
alignment <= MAXALIGN;
alignment <<= 1) {
total = 0;
- fprintf(stderr, "Alignment: %zu\n", alignment);
+ malloc_printf("Alignment: %zu\n", alignment);
for (size = 1;
size < 3 * alignment && size < (1U << 31);
size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
for (i = 0; i < NITER; i++) {
- err = JEMALLOC_P(posix_memalign)(&ps[i],
+ err = posix_memalign(&ps[i],
alignment, size);
if (err) {
- fprintf(stderr,
- "Error for size %zu (0x%zx): %s\n",
+ malloc_printf(
+ "Error for size %zu (%#zx): %s\n",
size, size, strerror(err));
exit(1);
}
- total += JEMALLOC_P(malloc_usable_size)(ps[i]);
+ total += malloc_usable_size(ps[i]);
if (total >= (MAXALIGN << 1))
break;
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
- JEMALLOC_P(free)(ps[i]);
+ free(ps[i]);
ps[i] = NULL;
}
}
}
}
- fprintf(stderr, "Test end\n");
+ malloc_printf("Test end\n");
return (0);
}
diff --git a/deps/jemalloc/test/rallocm.c b/deps/jemalloc/test/rallocm.c
index ccf326bb5..c5dedf48d 100644
--- a/deps/jemalloc/test/rallocm.c
+++ b/deps/jemalloc/test/rallocm.c
@@ -1,9 +1,3 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <assert.h>
-
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
@@ -15,113 +9,119 @@ main(void)
size_t sz, tsz;
int r;
- fprintf(stderr, "Test begin\n");
+ malloc_printf("Test begin\n");
/* Get page size. */
{
+#ifdef _WIN32
+ SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ pagesize = (size_t)si.dwPageSize;
+#else
long result = sysconf(_SC_PAGESIZE);
assert(result != -1);
pagesize = (size_t)result;
+#endif
}
- r = JEMALLOC_P(allocm)(&p, &sz, 42, 0);
+ r = allocm(&p, &sz, 42, 0);
if (r != ALLOCM_SUCCESS) {
- fprintf(stderr, "Unexpected allocm() error\n");
+ malloc_printf("Unexpected allocm() error\n");
abort();
}
q = p;
- r = JEMALLOC_P(rallocm)(&q, &tsz, sz, 0, ALLOCM_NO_MOVE);
+ r = rallocm(&q, &tsz, sz, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected rallocm() error\n");
+ malloc_printf("Unexpected rallocm() error\n");
if (q != p)
- fprintf(stderr, "Unexpected object move\n");
+ malloc_printf("Unexpected object move\n");
if (tsz != sz) {
- fprintf(stderr, "Unexpected size change: %zu --> %zu\n",
+ malloc_printf("Unexpected size change: %zu --> %zu\n",
sz, tsz);
}
q = p;
- r = JEMALLOC_P(rallocm)(&q, &tsz, sz, 5, ALLOCM_NO_MOVE);
+ r = rallocm(&q, &tsz, sz, 5, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected rallocm() error\n");
+ malloc_printf("Unexpected rallocm() error\n");
if (q != p)
- fprintf(stderr, "Unexpected object move\n");
+ malloc_printf("Unexpected object move\n");
if (tsz != sz) {
- fprintf(stderr, "Unexpected size change: %zu --> %zu\n",
+ malloc_printf("Unexpected size change: %zu --> %zu\n",
sz, tsz);
}
q = p;
- r = JEMALLOC_P(rallocm)(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE);
+ r = rallocm(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_ERR_NOT_MOVED)
- fprintf(stderr, "Unexpected rallocm() result\n");
+ malloc_printf("Unexpected rallocm() result\n");
if (q != p)
- fprintf(stderr, "Unexpected object move\n");
+ malloc_printf("Unexpected object move\n");
if (tsz != sz) {
- fprintf(stderr, "Unexpected size change: %zu --> %zu\n",
+ malloc_printf("Unexpected size change: %zu --> %zu\n",
sz, tsz);
}
q = p;
- r = JEMALLOC_P(rallocm)(&q, &tsz, sz + 5, 0, 0);
+ r = rallocm(&q, &tsz, sz + 5, 0, 0);
if (r != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected rallocm() error\n");
+ malloc_printf("Unexpected rallocm() error\n");
if (q == p)
- fprintf(stderr, "Expected object move\n");
+ malloc_printf("Expected object move\n");
if (tsz == sz) {
- fprintf(stderr, "Expected size change: %zu --> %zu\n",
+ malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz);
}
p = q;
sz = tsz;
- r = JEMALLOC_P(rallocm)(&q, &tsz, pagesize*2, 0, 0);
+ r = rallocm(&q, &tsz, pagesize*2, 0, 0);
if (r != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected rallocm() error\n");
+ malloc_printf("Unexpected rallocm() error\n");
if (q == p)
- fprintf(stderr, "Expected object move\n");
+ malloc_printf("Expected object move\n");
if (tsz == sz) {
- fprintf(stderr, "Expected size change: %zu --> %zu\n",
+ malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz);
}
p = q;
sz = tsz;
- r = JEMALLOC_P(rallocm)(&q, &tsz, pagesize*4, 0, 0);
+ r = rallocm(&q, &tsz, pagesize*4, 0, 0);
if (r != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected rallocm() error\n");
+ malloc_printf("Unexpected rallocm() error\n");
if (tsz == sz) {
- fprintf(stderr, "Expected size change: %zu --> %zu\n",
+ malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz);
}
p = q;
sz = tsz;
- r = JEMALLOC_P(rallocm)(&q, &tsz, pagesize*2, 0, ALLOCM_NO_MOVE);
+ r = rallocm(&q, &tsz, pagesize*2, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected rallocm() error\n");
+ malloc_printf("Unexpected rallocm() error\n");
if (q != p)
- fprintf(stderr, "Unexpected object move\n");
+ malloc_printf("Unexpected object move\n");
if (tsz == sz) {
- fprintf(stderr, "Expected size change: %zu --> %zu\n",
+ malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz);
}
sz = tsz;
- r = JEMALLOC_P(rallocm)(&q, &tsz, pagesize*4, 0, ALLOCM_NO_MOVE);
+ r = rallocm(&q, &tsz, pagesize*4, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS)
- fprintf(stderr, "Unexpected rallocm() error\n");
+ malloc_printf("Unexpected rallocm() error\n");
if (q != p)
- fprintf(stderr, "Unexpected object move\n");
+ malloc_printf("Unexpected object move\n");
if (tsz == sz) {
- fprintf(stderr, "Expected size change: %zu --> %zu\n",
+ malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz);
}
sz = tsz;
- JEMALLOC_P(dallocm)(p, 0);
+ dallocm(p, 0);
- fprintf(stderr, "Test end\n");
+ malloc_printf("Test end\n");
return (0);
}
diff --git a/deps/jemalloc/test/thread_arena.c b/deps/jemalloc/test/thread_arena.c
index ef8d68175..2020d9948 100644
--- a/deps/jemalloc/test/thread_arena.c
+++ b/deps/jemalloc/test/thread_arena.c
@@ -1,16 +1,10 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <string.h>
-#include <assert.h>
-
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
#define NTHREADS 10
void *
-thread_start(void *arg)
+je_thread_start(void *arg)
{
unsigned main_arena_ind = *(unsigned *)arg;
void *p;
@@ -18,24 +12,24 @@ thread_start(void *arg)
size_t size;
int err;
- p = JEMALLOC_P(malloc)(1);
+ p = malloc(1);
if (p == NULL) {
- fprintf(stderr, "%s(): Error in malloc()\n", __func__);
+ malloc_printf("%s(): Error in malloc()\n", __func__);
return (void *)1;
}
size = sizeof(arena_ind);
- if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size,
- &main_arena_ind, sizeof(main_arena_ind)))) {
- fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
+ if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind,
+ sizeof(main_arena_ind)))) {
+ malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
return (void *)1;
}
size = sizeof(arena_ind);
- if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, NULL,
+ if ((err = mallctl("thread.arena", &arena_ind, &size, NULL,
0))) {
- fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
+ malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
return (void *)1;
}
@@ -52,41 +46,33 @@ main(void)
unsigned arena_ind;
size_t size;
int err;
- pthread_t threads[NTHREADS];
+ je_thread_t threads[NTHREADS];
unsigned i;
- fprintf(stderr, "Test begin\n");
+ malloc_printf("Test begin\n");
- p = JEMALLOC_P(malloc)(1);
+ p = malloc(1);
if (p == NULL) {
- fprintf(stderr, "%s(): Error in malloc()\n", __func__);
+ malloc_printf("%s(): Error in malloc()\n", __func__);
ret = 1;
- goto RETURN;
+ goto label_return;
}
size = sizeof(arena_ind);
- if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, NULL,
- 0))) {
- fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
+ if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) {
+ malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
ret = 1;
- goto RETURN;
+ goto label_return;
}
- for (i = 0; i < NTHREADS; i++) {
- if (pthread_create(&threads[i], NULL, thread_start,
- (void *)&arena_ind) != 0) {
- fprintf(stderr, "%s(): Error in pthread_create()\n",
- __func__);
- ret = 1;
- goto RETURN;
- }
- }
+ for (i = 0; i < NTHREADS; i++)
+ je_thread_create(&threads[i], je_thread_start, (void *)&arena_ind);
for (i = 0; i < NTHREADS; i++)
- pthread_join(threads[i], (void *)&ret);
+ je_thread_join(threads[i], (void *)&ret);
-RETURN:
- fprintf(stderr, "Test end\n");
+label_return:
+ malloc_printf("Test end\n");
return (ret);
}
diff --git a/deps/jemalloc/test/thread_tcache_enabled.c b/deps/jemalloc/test/thread_tcache_enabled.c
new file mode 100644
index 000000000..2061b7bba
--- /dev/null
+++ b/deps/jemalloc/test/thread_tcache_enabled.c
@@ -0,0 +1,91 @@
+#define JEMALLOC_MANGLE
+#include "jemalloc_test.h"
+
+void *
+je_thread_start(void *arg)
+{
+ int err;
+ size_t sz;
+ bool e0, e1;
+
+ sz = sizeof(bool);
+ if ((err = mallctl("thread.tcache.enabled", &e0, &sz, NULL, 0))) {
+ if (err == ENOENT) {
+#ifdef JEMALLOC_TCACHE
+ assert(false);
+#endif
+ }
+ goto label_return;
+ }
+
+ if (e0) {
+ e1 = false;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz)
+ == 0);
+ assert(e0);
+ }
+
+ e1 = true;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
+ assert(e0 == false);
+
+ e1 = true;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
+ assert(e0);
+
+ e1 = false;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
+ assert(e0);
+
+ e1 = false;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
+ assert(e0 == false);
+
+ free(malloc(1));
+ e1 = true;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
+ assert(e0 == false);
+
+ free(malloc(1));
+ e1 = true;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
+ assert(e0);
+
+ free(malloc(1));
+ e1 = false;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
+ assert(e0);
+
+ free(malloc(1));
+ e1 = false;
+ assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
+ assert(e0 == false);
+
+ free(malloc(1));
+label_return:
+ return (NULL);
+}
+
+int
+main(void)
+{
+ int ret = 0;
+ je_thread_t thread;
+
+ malloc_printf("Test begin\n");
+
+ je_thread_start(NULL);
+
+ je_thread_create(&thread, je_thread_start, NULL);
+ je_thread_join(thread, (void *)&ret);
+
+ je_thread_start(NULL);
+
+ je_thread_create(&thread, je_thread_start, NULL);
+ je_thread_join(thread, (void *)&ret);
+
+ je_thread_start(NULL);
+
+ malloc_printf("Test end\n");
+ return (ret);
+}
diff --git a/deps/jemalloc/test/thread_tcache_enabled.exp b/deps/jemalloc/test/thread_tcache_enabled.exp
new file mode 100644
index 000000000..369a88dd2
--- /dev/null
+++ b/deps/jemalloc/test/thread_tcache_enabled.exp
@@ -0,0 +1,2 @@
+Test begin
+Test end