mirror of
https://github.com/fluencelabs/redis
synced 2025-06-23 05:51:34 +00:00
Jemalloc upgraded to version 5.0.1.
This commit is contained in:
76
deps/jemalloc/test/src/SFMT.c
vendored
76
deps/jemalloc/test/src/SFMT.c
vendored
@ -33,7 +33,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
/**
|
||||
* @file SFMT.c
|
||||
* @brief SIMD oriented Fast Mersenne Twister(SFMT)
|
||||
*
|
||||
@ -45,7 +45,7 @@
|
||||
*
|
||||
* The new BSD License is applied to this software, see LICENSE.txt
|
||||
*/
|
||||
#define SFMT_C_
|
||||
#define SFMT_C_
|
||||
#include "test/jemalloc_test.h"
|
||||
#include "test/SFMT-params.h"
|
||||
|
||||
@ -108,7 +108,7 @@ struct sfmt_s {
|
||||
|
||||
/*--------------------------------------
|
||||
FILE GLOBAL VARIABLES
|
||||
internal state, index counter and flag
|
||||
internal state, index counter and flag
|
||||
--------------------------------------*/
|
||||
|
||||
/** a parity check vector which certificate the period of 2^{MEXP} */
|
||||
@ -117,18 +117,18 @@ static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
|
||||
/*----------------
|
||||
STATIC FUNCTIONS
|
||||
----------------*/
|
||||
JEMALLOC_INLINE_C int idxof(int i);
|
||||
static inline int idxof(int i);
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
JEMALLOC_INLINE_C void rshift128(w128_t *out, w128_t const *in, int shift);
|
||||
JEMALLOC_INLINE_C void lshift128(w128_t *out, w128_t const *in, int shift);
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift);
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift);
|
||||
#endif
|
||||
JEMALLOC_INLINE_C void gen_rand_all(sfmt_t *ctx);
|
||||
JEMALLOC_INLINE_C void gen_rand_array(sfmt_t *ctx, w128_t *array, int size);
|
||||
JEMALLOC_INLINE_C uint32_t func1(uint32_t x);
|
||||
JEMALLOC_INLINE_C uint32_t func2(uint32_t x);
|
||||
static inline void gen_rand_all(sfmt_t *ctx);
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size);
|
||||
static inline uint32_t func1(uint32_t x);
|
||||
static inline uint32_t func2(uint32_t x);
|
||||
static void period_certification(sfmt_t *ctx);
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
JEMALLOC_INLINE_C void swap(w128_t *array, int size);
|
||||
static inline void swap(w128_t *array, int size);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ALTIVEC)
|
||||
@ -138,15 +138,15 @@ JEMALLOC_INLINE_C void swap(w128_t *array, int size);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function simulate a 64-bit index of LITTLE ENDIAN
|
||||
* This function simulate a 64-bit index of LITTLE ENDIAN
|
||||
* in BIG ENDIAN machine.
|
||||
*/
|
||||
#ifdef ONLY64
|
||||
JEMALLOC_INLINE_C int idxof(int i) {
|
||||
static inline int idxof(int i) {
|
||||
return i ^ 1;
|
||||
}
|
||||
#else
|
||||
JEMALLOC_INLINE_C int idxof(int i) {
|
||||
static inline int idxof(int i) {
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
@ -160,7 +160,7 @@ JEMALLOC_INLINE_C int idxof(int i) {
|
||||
*/
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
#ifdef ONLY64
|
||||
JEMALLOC_INLINE_C void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
@ -175,7 +175,7 @@ JEMALLOC_INLINE_C void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
out->u[3] = (uint32_t)oh;
|
||||
}
|
||||
#else
|
||||
JEMALLOC_INLINE_C void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
@ -199,7 +199,7 @@ JEMALLOC_INLINE_C void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
* @param shift the shift value
|
||||
*/
|
||||
#ifdef ONLY64
|
||||
JEMALLOC_INLINE_C void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
@ -214,7 +214,7 @@ JEMALLOC_INLINE_C void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
out->u[3] = (uint32_t)oh;
|
||||
}
|
||||
#else
|
||||
JEMALLOC_INLINE_C void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
@ -241,37 +241,37 @@ JEMALLOC_INLINE_C void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
*/
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
#ifdef ONLY64
|
||||
JEMALLOC_INLINE_C void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
static inline void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0]
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1]
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2]
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3]
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
}
|
||||
#else
|
||||
JEMALLOC_INLINE_C void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
static inline void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0]
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1]
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2]
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3]
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
}
|
||||
#endif
|
||||
@ -282,7 +282,7 @@ JEMALLOC_INLINE_C void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
* This function fills the internal state array with pseudorandom
|
||||
* integers.
|
||||
*/
|
||||
JEMALLOC_INLINE_C void gen_rand_all(sfmt_t *ctx) {
|
||||
static inline void gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
w128_t *r1, *r2;
|
||||
|
||||
@ -306,10 +306,10 @@ JEMALLOC_INLINE_C void gen_rand_all(sfmt_t *ctx) {
|
||||
* This function fills the user-specified array with pseudorandom
|
||||
* integers.
|
||||
*
|
||||
* @param array an 128-bit array to be filled by pseudorandom numbers.
|
||||
* @param array an 128-bit array to be filled by pseudorandom numbers.
|
||||
* @param size number of 128-bit pseudorandom numbers to be generated.
|
||||
*/
|
||||
JEMALLOC_INLINE_C void gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
w128_t *r1, *r2;
|
||||
|
||||
@ -343,7 +343,7 @@ JEMALLOC_INLINE_C void gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
#endif
|
||||
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64) && !defined(HAVE_ALTIVEC)
|
||||
JEMALLOC_INLINE_C void swap(w128_t *array, int size) {
|
||||
static inline void swap(w128_t *array, int size) {
|
||||
int i;
|
||||
uint32_t x, y;
|
||||
|
||||
@ -476,7 +476,7 @@ uint32_t gen_rand32_range(sfmt_t *ctx, uint32_t limit) {
|
||||
* This function generates and returns 64-bit pseudorandom number.
|
||||
* init_gen_rand or init_by_array must be called before this function.
|
||||
* The function gen_rand64 should not be called after gen_rand32,
|
||||
* unless an initialization is again executed.
|
||||
* unless an initialization is again executed.
|
||||
* @return 64-bit pseudorandom number
|
||||
*/
|
||||
uint64_t gen_rand64(sfmt_t *ctx) {
|
||||
@ -618,7 +618,7 @@ sfmt_t *init_gen_rand(uint32_t seed) {
|
||||
|
||||
psfmt32[idxof(0)] = seed;
|
||||
for (i = 1; i < N32; i++) {
|
||||
psfmt32[idxof(i)] = 1812433253UL * (psfmt32[idxof(i - 1)]
|
||||
psfmt32[idxof(i)] = 1812433253UL * (psfmt32[idxof(i - 1)]
|
||||
^ (psfmt32[idxof(i - 1)] >> 30))
|
||||
+ i;
|
||||
}
|
||||
@ -668,7 +668,7 @@ sfmt_t *init_by_array(uint32_t *init_key, int key_length) {
|
||||
} else {
|
||||
count = N32;
|
||||
}
|
||||
r = func1(psfmt32[idxof(0)] ^ psfmt32[idxof(mid)]
|
||||
r = func1(psfmt32[idxof(0)] ^ psfmt32[idxof(mid)]
|
||||
^ psfmt32[idxof(N32 - 1)]);
|
||||
psfmt32[idxof(mid)] += r;
|
||||
r += key_length;
|
||||
@ -677,7 +677,7 @@ sfmt_t *init_by_array(uint32_t *init_key, int key_length) {
|
||||
|
||||
count--;
|
||||
for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += init_key[j] + i;
|
||||
@ -686,7 +686,7 @@ sfmt_t *init_by_array(uint32_t *init_key, int key_length) {
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (; j < count; j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += i;
|
||||
@ -695,7 +695,7 @@ sfmt_t *init_by_array(uint32_t *init_key, int key_length) {
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (j = 0; j < N32; j++) {
|
||||
r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)]
|
||||
r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)]
|
||||
+ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] ^= r;
|
||||
r -= i;
|
||||
|
6
deps/jemalloc/test/src/btalloc.c
vendored
6
deps/jemalloc/test/src/btalloc.c
vendored
@ -1,8 +1,6 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
void *
|
||||
btalloc(size_t size, unsigned bits)
|
||||
{
|
||||
|
||||
return (btalloc_0(size, bits));
|
||||
btalloc(size_t size, unsigned bits) {
|
||||
return btalloc_0(size, bits);
|
||||
}
|
||||
|
2
deps/jemalloc/test/src/math.c
vendored
2
deps/jemalloc/test/src/math.c
vendored
@ -1,2 +1,2 @@
|
||||
#define MATH_C_
|
||||
#define MATH_C_
|
||||
#include "test/jemalloc_test.h"
|
||||
|
4
deps/jemalloc/test/src/mq.c
vendored
4
deps/jemalloc/test/src/mq.c
vendored
@ -5,9 +5,7 @@
|
||||
* time is guaranteed.
|
||||
*/
|
||||
void
|
||||
mq_nanosleep(unsigned ns)
|
||||
{
|
||||
|
||||
mq_nanosleep(unsigned ns) {
|
||||
assert(ns <= 1000*1000*1000);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
40
deps/jemalloc/test/src/mtx.c
vendored
40
deps/jemalloc/test/src/mtx.c
vendored
@ -1,38 +1,40 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#ifndef _CRT_SPINCOUNT
|
||||
#define _CRT_SPINCOUNT 4000
|
||||
#define _CRT_SPINCOUNT 4000
|
||||
#endif
|
||||
|
||||
bool
|
||||
mtx_init(mtx_t *mtx)
|
||||
{
|
||||
|
||||
mtx_init(mtx_t *mtx) {
|
||||
#ifdef _WIN32
|
||||
if (!InitializeCriticalSectionAndSpinCount(&mtx->lock, _CRT_SPINCOUNT))
|
||||
return (true);
|
||||
if (!InitializeCriticalSectionAndSpinCount(&mtx->lock,
|
||||
_CRT_SPINCOUNT)) {
|
||||
return true;
|
||||
}
|
||||
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
|
||||
mtx->lock = OS_UNFAIR_LOCK_INIT;
|
||||
#elif (defined(JEMALLOC_OSSPIN))
|
||||
mtx->lock = 0;
|
||||
#else
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return (true);
|
||||
if (pthread_mutexattr_init(&attr) != 0) {
|
||||
return true;
|
||||
}
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT);
|
||||
if (pthread_mutex_init(&mtx->lock, &attr) != 0) {
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
return (true);
|
||||
return true;
|
||||
}
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
#endif
|
||||
return (false);
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
mtx_fini(mtx_t *mtx)
|
||||
{
|
||||
|
||||
mtx_fini(mtx_t *mtx) {
|
||||
#ifdef _WIN32
|
||||
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
|
||||
#elif (defined(JEMALLOC_OSSPIN))
|
||||
#else
|
||||
pthread_mutex_destroy(&mtx->lock);
|
||||
@ -40,11 +42,11 @@ mtx_fini(mtx_t *mtx)
|
||||
}
|
||||
|
||||
void
|
||||
mtx_lock(mtx_t *mtx)
|
||||
{
|
||||
|
||||
mtx_lock(mtx_t *mtx) {
|
||||
#ifdef _WIN32
|
||||
EnterCriticalSection(&mtx->lock);
|
||||
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
|
||||
os_unfair_lock_lock(&mtx->lock);
|
||||
#elif (defined(JEMALLOC_OSSPIN))
|
||||
OSSpinLockLock(&mtx->lock);
|
||||
#else
|
||||
@ -53,11 +55,11 @@ mtx_lock(mtx_t *mtx)
|
||||
}
|
||||
|
||||
void
|
||||
mtx_unlock(mtx_t *mtx)
|
||||
{
|
||||
|
||||
mtx_unlock(mtx_t *mtx) {
|
||||
#ifdef _WIN32
|
||||
LeaveCriticalSection(&mtx->lock);
|
||||
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
|
||||
os_unfair_lock_unlock(&mtx->lock);
|
||||
#elif (defined(JEMALLOC_OSSPIN))
|
||||
OSSpinLockUnlock(&mtx->lock);
|
||||
#else
|
||||
|
180
deps/jemalloc/test/src/test.c
vendored
180
deps/jemalloc/test/src/test.c
vendored
@ -1,14 +1,70 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
/* Test status state. */
|
||||
|
||||
static unsigned test_count = 0;
|
||||
static test_status_t test_counts[test_status_count] = {0, 0, 0};
|
||||
static test_status_t test_status = test_status_pass;
|
||||
static const char * test_name = "";
|
||||
|
||||
/* Reentrancy testing helpers. */
|
||||
|
||||
#define NUM_REENTRANT_ALLOCS 20
|
||||
typedef enum {
|
||||
non_reentrant = 0,
|
||||
libc_reentrant = 1,
|
||||
arena_new_reentrant = 2
|
||||
} reentrancy_t;
|
||||
static reentrancy_t reentrancy;
|
||||
|
||||
static bool libc_hook_ran = false;
|
||||
static bool arena_new_hook_ran = false;
|
||||
|
||||
static const char *
|
||||
reentrancy_t_str(reentrancy_t r) {
|
||||
switch (r) {
|
||||
case non_reentrant:
|
||||
return "non-reentrant";
|
||||
case libc_reentrant:
|
||||
return "libc-reentrant";
|
||||
case arena_new_reentrant:
|
||||
return "arena_new-reentrant";
|
||||
default:
|
||||
unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_hook(bool *hook_ran, void (**hook)()) {
|
||||
*hook_ran = true;
|
||||
*hook = NULL;
|
||||
|
||||
size_t alloc_size = 1;
|
||||
for (int i = 0; i < NUM_REENTRANT_ALLOCS; i++) {
|
||||
free(malloc(alloc_size));
|
||||
alloc_size *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
libc_reentrancy_hook() {
|
||||
do_hook(&libc_hook_ran, &hooks_libc_hook);
|
||||
}
|
||||
|
||||
static void
|
||||
arena_new_reentrancy_hook() {
|
||||
do_hook(&arena_new_hook_ran, &hooks_arena_new_hook);
|
||||
}
|
||||
|
||||
/* Actual test infrastructure. */
|
||||
bool
|
||||
test_is_reentrant() {
|
||||
return reentrancy != non_reentrant;
|
||||
}
|
||||
|
||||
JEMALLOC_FORMAT_PRINTF(1, 2)
|
||||
void
|
||||
test_skip(const char *format, ...)
|
||||
{
|
||||
test_skip(const char *format, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
@ -20,8 +76,7 @@ test_skip(const char *format, ...)
|
||||
|
||||
JEMALLOC_FORMAT_PRINTF(1, 2)
|
||||
void
|
||||
test_fail(const char *format, ...)
|
||||
{
|
||||
test_fail(const char *format, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
@ -32,9 +87,7 @@ test_fail(const char *format, ...)
|
||||
}
|
||||
|
||||
static const char *
|
||||
test_status_string(test_status_t test_status)
|
||||
{
|
||||
|
||||
test_status_string(test_status_t test_status) {
|
||||
switch (test_status) {
|
||||
case test_status_pass: return "pass";
|
||||
case test_status_skip: return "skip";
|
||||
@ -44,48 +97,64 @@ test_status_string(test_status_t test_status)
|
||||
}
|
||||
|
||||
void
|
||||
p_test_init(const char *name)
|
||||
{
|
||||
|
||||
p_test_init(const char *name) {
|
||||
test_count++;
|
||||
test_status = test_status_pass;
|
||||
test_name = name;
|
||||
}
|
||||
|
||||
void
|
||||
p_test_fini(void)
|
||||
{
|
||||
|
||||
p_test_fini(void) {
|
||||
test_counts[test_status]++;
|
||||
malloc_printf("%s: %s\n", test_name, test_status_string(test_status));
|
||||
malloc_printf("%s (%s): %s\n", test_name, reentrancy_t_str(reentrancy),
|
||||
test_status_string(test_status));
|
||||
}
|
||||
|
||||
test_status_t
|
||||
p_test(test_t *t, ...)
|
||||
{
|
||||
static test_status_t
|
||||
p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
|
||||
/*
|
||||
* Make sure initialization occurs prior to running tests. Tests are
|
||||
* special because they may use internal facilities prior to triggering
|
||||
* initialization as a side effect of calling into the public API. This
|
||||
* is a final safety that works even if jemalloc_constructor() doesn't
|
||||
* run, as for MSVC builds.
|
||||
*/
|
||||
if (nallocx(1, 0) == 0) {
|
||||
malloc_printf("Initialization error");
|
||||
return (test_status_fail);
|
||||
if (do_malloc_init) {
|
||||
/*
|
||||
* Make sure initialization occurs prior to running tests.
|
||||
* Tests are special because they may use internal facilities
|
||||
* prior to triggering initialization as a side effect of
|
||||
* calling into the public API.
|
||||
*/
|
||||
if (nallocx(1, 0) == 0) {
|
||||
malloc_printf("Initialization error");
|
||||
return test_status_fail;
|
||||
}
|
||||
}
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
for (; t != NULL; t = va_arg(ap, test_t *)) {
|
||||
/* Non-reentrant run. */
|
||||
reentrancy = non_reentrant;
|
||||
hooks_arena_new_hook = hooks_libc_hook = NULL;
|
||||
t();
|
||||
if (test_status > ret)
|
||||
if (test_status > ret) {
|
||||
ret = test_status;
|
||||
}
|
||||
/* Reentrant run. */
|
||||
if (do_reentrant) {
|
||||
reentrancy = libc_reentrant;
|
||||
hooks_arena_new_hook = NULL;
|
||||
hooks_libc_hook = &libc_reentrancy_hook;
|
||||
t();
|
||||
if (test_status > ret) {
|
||||
ret = test_status;
|
||||
}
|
||||
|
||||
reentrancy = arena_new_reentrant;
|
||||
hooks_libc_hook = NULL;
|
||||
hooks_arena_new_hook = &arena_new_reentrancy_hook;
|
||||
t();
|
||||
if (test_status > ret) {
|
||||
ret = test_status;
|
||||
}
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
malloc_printf("--- %s: %u/%u, %s: %u/%u, %s: %u/%u ---\n",
|
||||
test_status_string(test_status_pass),
|
||||
@ -95,13 +164,54 @@ p_test(test_t *t, ...)
|
||||
test_status_string(test_status_fail),
|
||||
test_counts[test_status_fail], test_count);
|
||||
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
test_status_t
|
||||
p_test(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
ret = p_test_impl(true, true, t, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
test_status_t
|
||||
p_test_no_reentrancy(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
ret = p_test_impl(true, false, t, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
test_status_t
|
||||
p_test_no_malloc_init(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
/*
|
||||
* We also omit reentrancy from bootstrapping tests, since we don't
|
||||
* (yet) care about general reentrancy during bootstrapping.
|
||||
*/
|
||||
ret = p_test_impl(false, false, t, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
p_test_fail(const char *prefix, const char *message)
|
||||
{
|
||||
|
||||
p_test_fail(const char *prefix, const char *message) {
|
||||
malloc_cprintf(NULL, NULL, "%s%s\n", prefix, message);
|
||||
test_status = test_status_fail;
|
||||
}
|
||||
|
21
deps/jemalloc/test/src/thd.c
vendored
21
deps/jemalloc/test/src/thd.c
vendored
@ -2,18 +2,16 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
void
|
||||
thd_create(thd_t *thd, void *(*proc)(void *), void *arg)
|
||||
{
|
||||
thd_create(thd_t *thd, void *(*proc)(void *), void *arg) {
|
||||
LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc;
|
||||
*thd = CreateThread(NULL, 0, routine, arg, 0, NULL);
|
||||
if (*thd == NULL)
|
||||
if (*thd == NULL) {
|
||||
test_fail("Error in CreateThread()\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
thd_join(thd_t thd, void **ret)
|
||||
{
|
||||
|
||||
thd_join(thd_t thd, void **ret) {
|
||||
if (WaitForSingleObject(thd, INFINITE) == WAIT_OBJECT_0 && ret) {
|
||||
DWORD exit_code;
|
||||
GetExitCodeThread(thd, (LPDWORD) &exit_code);
|
||||
@ -23,17 +21,14 @@ thd_join(thd_t thd, void **ret)
|
||||
|
||||
#else
|
||||
void
|
||||
thd_create(thd_t *thd, void *(*proc)(void *), void *arg)
|
||||
{
|
||||
|
||||
if (pthread_create(thd, NULL, proc, arg) != 0)
|
||||
thd_create(thd_t *thd, void *(*proc)(void *), void *arg) {
|
||||
if (pthread_create(thd, NULL, proc, arg) != 0) {
|
||||
test_fail("Error in pthread_create()\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
thd_join(thd_t thd, void **ret)
|
||||
{
|
||||
|
||||
thd_join(thd_t thd, void **ret) {
|
||||
pthread_join(thd, ret);
|
||||
}
|
||||
#endif
|
||||
|
65
deps/jemalloc/test/src/timer.c
vendored
65
deps/jemalloc/test/src/timer.c
vendored
@ -1,73 +1,44 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
void
|
||||
timer_start(timedelta_t *timer)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
GetSystemTimeAsFileTime(&timer->ft0);
|
||||
#elif JEMALLOC_CLOCK_GETTIME
|
||||
if (sysconf(_SC_MONOTONIC_CLOCK) <= 0)
|
||||
timer->clock_id = CLOCK_REALTIME;
|
||||
else
|
||||
timer->clock_id = CLOCK_MONOTONIC;
|
||||
clock_gettime(timer->clock_id, &timer->ts0);
|
||||
#else
|
||||
gettimeofday(&timer->tv0, NULL);
|
||||
#endif
|
||||
timer_start(timedelta_t *timer) {
|
||||
nstime_init(&timer->t0, 0);
|
||||
nstime_update(&timer->t0);
|
||||
}
|
||||
|
||||
void
|
||||
timer_stop(timedelta_t *timer)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
GetSystemTimeAsFileTime(&timer->ft0);
|
||||
#elif JEMALLOC_CLOCK_GETTIME
|
||||
clock_gettime(timer->clock_id, &timer->ts1);
|
||||
#else
|
||||
gettimeofday(&timer->tv1, NULL);
|
||||
#endif
|
||||
timer_stop(timedelta_t *timer) {
|
||||
nstime_copy(&timer->t1, &timer->t0);
|
||||
nstime_update(&timer->t1);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
timer_usec(const timedelta_t *timer)
|
||||
{
|
||||
timer_usec(const timedelta_t *timer) {
|
||||
nstime_t delta;
|
||||
|
||||
#ifdef _WIN32
|
||||
uint64_t t0, t1;
|
||||
t0 = (((uint64_t)timer->ft0.dwHighDateTime) << 32) |
|
||||
timer->ft0.dwLowDateTime;
|
||||
t1 = (((uint64_t)timer->ft1.dwHighDateTime) << 32) |
|
||||
timer->ft1.dwLowDateTime;
|
||||
return ((t1 - t0) / 10);
|
||||
#elif JEMALLOC_CLOCK_GETTIME
|
||||
return (((timer->ts1.tv_sec - timer->ts0.tv_sec) * 1000000) +
|
||||
(timer->ts1.tv_nsec - timer->ts0.tv_nsec) / 1000);
|
||||
#else
|
||||
return (((timer->tv1.tv_sec - timer->tv0.tv_sec) * 1000000) +
|
||||
timer->tv1.tv_usec - timer->tv0.tv_usec);
|
||||
#endif
|
||||
nstime_copy(&delta, &timer->t1);
|
||||
nstime_subtract(&delta, &timer->t0);
|
||||
return nstime_ns(&delta) / 1000;
|
||||
}
|
||||
|
||||
void
|
||||
timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen)
|
||||
{
|
||||
timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) {
|
||||
uint64_t t0 = timer_usec(a);
|
||||
uint64_t t1 = timer_usec(b);
|
||||
uint64_t mult;
|
||||
unsigned i = 0;
|
||||
unsigned j;
|
||||
int n;
|
||||
size_t i = 0;
|
||||
size_t j, n;
|
||||
|
||||
/* Whole. */
|
||||
n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1);
|
||||
i += n;
|
||||
if (i >= buflen)
|
||||
if (i >= buflen) {
|
||||
return;
|
||||
}
|
||||
mult = 1;
|
||||
for (j = 0; j < n; j++)
|
||||
for (j = 0; j < n; j++) {
|
||||
mult *= 10;
|
||||
}
|
||||
|
||||
/* Decimal. */
|
||||
n = malloc_snprintf(&buf[i], buflen-i, ".");
|
||||
|
Reference in New Issue
Block a user