michael@0: #define JEMALLOC_MANGLE michael@0: #include "jemalloc_test.h" michael@0: michael@0: void * michael@0: je_thread_start(void *arg) michael@0: { michael@0: int err; michael@0: void *p; michael@0: uint64_t a0, a1, d0, d1; michael@0: uint64_t *ap0, *ap1, *dp0, *dp1; michael@0: size_t sz, usize; michael@0: michael@0: sz = sizeof(a0); michael@0: if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) { michael@0: if (err == ENOENT) { michael@0: #ifdef JEMALLOC_STATS michael@0: assert(false); michael@0: #endif michael@0: goto label_return; michael@0: } michael@0: malloc_printf("%s(): Error in mallctl(): %s\n", __func__, michael@0: strerror(err)); michael@0: exit(1); michael@0: } michael@0: sz = sizeof(ap0); michael@0: if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) { michael@0: if (err == ENOENT) { michael@0: #ifdef JEMALLOC_STATS michael@0: assert(false); michael@0: #endif michael@0: goto label_return; michael@0: } michael@0: malloc_printf("%s(): Error in mallctl(): %s\n", __func__, michael@0: strerror(err)); michael@0: exit(1); michael@0: } michael@0: assert(*ap0 == a0); michael@0: michael@0: sz = sizeof(d0); michael@0: if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) { michael@0: if (err == ENOENT) { michael@0: #ifdef JEMALLOC_STATS michael@0: assert(false); michael@0: #endif michael@0: goto label_return; michael@0: } michael@0: malloc_printf("%s(): Error in mallctl(): %s\n", __func__, michael@0: strerror(err)); michael@0: exit(1); michael@0: } michael@0: sz = sizeof(dp0); michael@0: if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) { michael@0: if (err == ENOENT) { michael@0: #ifdef JEMALLOC_STATS michael@0: assert(false); michael@0: #endif michael@0: goto label_return; michael@0: } michael@0: malloc_printf("%s(): Error in mallctl(): %s\n", __func__, michael@0: strerror(err)); michael@0: exit(1); michael@0: } michael@0: assert(*dp0 == d0); michael@0: michael@0: p = malloc(1); michael@0: if (p == NULL) { michael@0: malloc_printf("%s(): Error in malloc()\n", __func__); michael@0: exit(1); michael@0: } michael@0: michael@0: sz = sizeof(a1); michael@0: mallctl("thread.allocated", &a1, &sz, NULL, 0); michael@0: sz = sizeof(ap1); michael@0: mallctl("thread.allocatedp", &ap1, &sz, NULL, 0); michael@0: assert(*ap1 == a1); michael@0: assert(ap0 == ap1); michael@0: michael@0: usize = malloc_usable_size(p); michael@0: assert(a0 + usize <= a1); michael@0: michael@0: free(p); michael@0: michael@0: sz = sizeof(d1); michael@0: mallctl("thread.deallocated", &d1, &sz, NULL, 0); michael@0: sz = sizeof(dp1); michael@0: mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0); michael@0: assert(*dp1 == d1); michael@0: assert(dp0 == dp1); michael@0: michael@0: assert(d0 + usize <= d1); michael@0: michael@0: label_return: michael@0: return (NULL); michael@0: } michael@0: michael@0: int michael@0: main(void) michael@0: { michael@0: int ret = 0; michael@0: je_thread_t thread; michael@0: michael@0: malloc_printf("Test begin\n"); michael@0: michael@0: je_thread_start(NULL); michael@0: michael@0: je_thread_create(&thread, je_thread_start, NULL); michael@0: je_thread_join(thread, (void *)&ret); michael@0: michael@0: je_thread_start(NULL); michael@0: michael@0: je_thread_create(&thread, je_thread_start, NULL); michael@0: je_thread_join(thread, (void *)&ret); michael@0: michael@0: je_thread_start(NULL); michael@0: michael@0: malloc_printf("Test end\n"); michael@0: return (ret); michael@0: }