mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-06-19 18:35:39 +03:00
Reformat the codebase with the clang-format 18.
This commit is contained in:
parent
0a6215c171
commit
f1bba4a87c
346 changed files with 18286 additions and 17770 deletions
|
|
@ -10,9 +10,9 @@ static size_t miblen = MIBLEN;
|
|||
#define HUGE_BATCH (1000 * 1000)
|
||||
#define HUGE_BATCH_ITER 100
|
||||
#define LEN (100 * 1000 * 1000)
|
||||
static void *batch_ptrs[LEN];
|
||||
static void *batch_ptrs[LEN];
|
||||
static size_t batch_ptrs_next = 0;
|
||||
static void *item_ptrs[LEN];
|
||||
static void *item_ptrs[LEN];
|
||||
static size_t item_ptrs_next = 0;
|
||||
|
||||
#define SIZE 7
|
||||
|
|
@ -22,17 +22,18 @@ struct batch_alloc_packet_s {
|
|||
void **ptrs;
|
||||
size_t num;
|
||||
size_t size;
|
||||
int flags;
|
||||
int flags;
|
||||
};
|
||||
|
||||
static void
|
||||
batch_alloc_wrapper(size_t batch) {
|
||||
batch_alloc_packet_t batch_alloc_packet =
|
||||
{batch_ptrs + batch_ptrs_next, batch, SIZE, 0};
|
||||
batch_alloc_packet_t batch_alloc_packet = {
|
||||
batch_ptrs + batch_ptrs_next, batch, SIZE, 0};
|
||||
size_t filled;
|
||||
size_t len = sizeof(size_t);
|
||||
assert_d_eq(mallctlbymib(mib, miblen, &filled, &len,
|
||||
&batch_alloc_packet, sizeof(batch_alloc_packet)), 0, "");
|
||||
&batch_alloc_packet, sizeof(batch_alloc_packet)),
|
||||
0, "");
|
||||
assert_zu_eq(filled, batch, "");
|
||||
}
|
||||
|
||||
|
|
@ -94,9 +95,9 @@ compare_without_free(size_t batch, size_t iter,
|
|||
batch_ptrs_next = 0;
|
||||
release_and_clear(item_ptrs, item_ptrs_next);
|
||||
item_ptrs_next = 0;
|
||||
compare_funcs(0, iter,
|
||||
"batch allocation", batch_alloc_without_free_func,
|
||||
"item allocation", item_alloc_without_free_func);
|
||||
compare_funcs(0, iter, "batch allocation",
|
||||
batch_alloc_without_free_func, "item allocation",
|
||||
item_alloc_without_free_func);
|
||||
release_and_clear(batch_ptrs, batch_ptrs_next);
|
||||
batch_ptrs_next = 0;
|
||||
release_and_clear(item_ptrs, item_ptrs_next);
|
||||
|
|
@ -116,8 +117,7 @@ compare_with_free(size_t batch, size_t iter,
|
|||
}
|
||||
batch_ptrs_next = 0;
|
||||
item_ptrs_next = 0;
|
||||
compare_funcs(0, iter,
|
||||
"batch allocation", batch_alloc_with_free_func,
|
||||
compare_funcs(0, iter, "batch allocation", batch_alloc_with_free_func,
|
||||
"item allocation", item_alloc_with_free_func);
|
||||
batch_ptrs_next = 0;
|
||||
item_ptrs_next = 0;
|
||||
|
|
@ -187,12 +187,11 @@ TEST_BEGIN(test_huge_batch_with_free) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
int main(void) {
|
||||
assert_d_eq(mallctlnametomib("experimental.batch_alloc", mib, &miblen),
|
||||
0, "");
|
||||
return test_no_reentrancy(
|
||||
test_tiny_batch_without_free,
|
||||
test_tiny_batch_with_free,
|
||||
test_huge_batch_without_free,
|
||||
int
|
||||
main(void) {
|
||||
assert_d_eq(
|
||||
mallctlnametomib("experimental.batch_alloc", mib, &miblen), 0, "");
|
||||
return test_no_reentrancy(test_tiny_batch_without_free,
|
||||
test_tiny_batch_with_free, test_huge_batch_without_free,
|
||||
test_huge_batch_with_free);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
static void
|
||||
malloc_free(void) {
|
||||
void* p = malloc(1);
|
||||
void *p = malloc(1);
|
||||
expect_ptr_not_null((void *)p, "Unexpected malloc failure");
|
||||
p = no_opt_ptr(p);
|
||||
free((void *)p);
|
||||
|
|
@ -11,7 +11,7 @@ malloc_free(void) {
|
|||
|
||||
static void
|
||||
new_delete(void) {
|
||||
void* p = ::operator new(1);
|
||||
void *p = ::operator new(1);
|
||||
expect_ptr_not_null((void *)p, "Unexpected new failure");
|
||||
p = no_opt_ptr(p);
|
||||
::operator delete((void *)p);
|
||||
|
|
@ -19,7 +19,7 @@ new_delete(void) {
|
|||
|
||||
static void
|
||||
malloc_free_array(void) {
|
||||
void* p = malloc(sizeof(int)*8);
|
||||
void *p = malloc(sizeof(int) * 8);
|
||||
expect_ptr_not_null((void *)p, "Unexpected malloc failure");
|
||||
p = no_opt_ptr(p);
|
||||
free((void *)p);
|
||||
|
|
@ -27,7 +27,7 @@ malloc_free_array(void) {
|
|||
|
||||
static void
|
||||
new_delete_array(void) {
|
||||
int* p = new int[8];
|
||||
int *p = new int[8];
|
||||
expect_ptr_not_null((void *)p, "Unexpected new[] failure");
|
||||
p = (int *)no_opt_ptr((void *)p);
|
||||
delete[] (int *)p;
|
||||
|
|
@ -36,7 +36,7 @@ new_delete_array(void) {
|
|||
#if __cpp_sized_deallocation >= 201309
|
||||
static void
|
||||
new_sized_delete(void) {
|
||||
void* p = ::operator new(1);
|
||||
void *p = ::operator new(1);
|
||||
expect_ptr_not_null((void *)p, "Unexpected new failure");
|
||||
p = no_opt_ptr(p);
|
||||
::operator delete((void *)p, 1);
|
||||
|
|
@ -44,45 +44,41 @@ new_sized_delete(void) {
|
|||
|
||||
static void
|
||||
malloc_sdallocx(void) {
|
||||
void* p = malloc(1);
|
||||
void *p = malloc(1);
|
||||
expect_ptr_not_null((void *)p, "Unexpected malloc failure");
|
||||
p = no_opt_ptr(p);
|
||||
sdallocx((void *)p, 1, 0);
|
||||
sdallocx((void *)p, 1, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_BEGIN(test_free_vs_delete) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000,
|
||||
"malloc_free", (void *)malloc_free,
|
||||
"new_delete", (void *)new_delete);
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "malloc_free",
|
||||
(void *)malloc_free, "new_delete", (void *)new_delete);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_free_array_vs_delete_array) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000,
|
||||
"malloc_free_array", (void *)malloc_free_array,
|
||||
"delete_array", (void *)new_delete_array);
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "malloc_free_array",
|
||||
(void *)malloc_free_array, "delete_array",
|
||||
(void *)new_delete_array);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
TEST_BEGIN(test_sized_delete_vs_sdallocx) {
|
||||
#if __cpp_sized_deallocation >= 201309
|
||||
compare_funcs(10*1000*1000, 100*1000*1000,
|
||||
"new_size_delete", (void *)new_sized_delete,
|
||||
"malloc_sdallocx", (void *)malloc_sdallocx);
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "new_size_delete",
|
||||
(void *)new_sized_delete, "malloc_sdallocx",
|
||||
(void *)malloc_sdallocx);
|
||||
#else
|
||||
malloc_printf("Skipping test_sized_delete_vs_sdallocx since \
|
||||
malloc_printf(
|
||||
"Skipping test_sized_delete_vs_sdallocx since \
|
||||
sized deallocation is not enabled.\n");
|
||||
#endif
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
int
|
||||
main() {
|
||||
return test_no_reentrancy(
|
||||
test_free_vs_delete,
|
||||
test_free_array_vs_delete_array,
|
||||
test_sized_delete_vs_sdallocx);
|
||||
return test_no_reentrancy(test_free_vs_delete,
|
||||
test_free_array_vs_delete_array, test_sized_delete_vs_sdallocx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ item_alloc_dalloc_small(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_array_vs_item_small) {
|
||||
compare_funcs(1 * 1000, 10 * 1000,
|
||||
"array of small allocations", array_alloc_dalloc_small,
|
||||
"small item allocation", item_alloc_dalloc_small);
|
||||
compare_funcs(1 * 1000, 10 * 1000, "array of small allocations",
|
||||
array_alloc_dalloc_small, "small item allocation",
|
||||
item_alloc_dalloc_small);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -64,14 +64,14 @@ item_alloc_dalloc_large(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_array_vs_item_large) {
|
||||
compare_funcs(100, 1000,
|
||||
"array of large allocations", array_alloc_dalloc_large,
|
||||
"large item allocation", item_alloc_dalloc_large);
|
||||
compare_funcs(100, 1000, "array of large allocations",
|
||||
array_alloc_dalloc_large, "large item allocation",
|
||||
item_alloc_dalloc_large);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int main(void) {
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_array_vs_item_small,
|
||||
test_array_vs_item_large);
|
||||
test_array_vs_item_small, test_array_vs_item_large);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,16 @@
|
|||
|
||||
static void
|
||||
noop_alloc_hook(void *extra, hook_alloc_t type, void *result,
|
||||
uintptr_t result_raw, uintptr_t args_raw[3]) {
|
||||
}
|
||||
uintptr_t result_raw, uintptr_t args_raw[3]) {}
|
||||
|
||||
static void
|
||||
noop_dalloc_hook(void *extra, hook_dalloc_t type, void *address,
|
||||
uintptr_t args_raw[3]) {
|
||||
}
|
||||
noop_dalloc_hook(
|
||||
void *extra, hook_dalloc_t type, void *address, uintptr_t args_raw[3]) {}
|
||||
|
||||
static void
|
||||
noop_expand_hook(void *extra, hook_expand_t type, void *address,
|
||||
size_t old_usize, size_t new_usize, uintptr_t result_raw,
|
||||
uintptr_t args_raw[4]) {
|
||||
}
|
||||
uintptr_t args_raw[4]) {}
|
||||
|
||||
static void
|
||||
malloc_free_loop(int iters) {
|
||||
|
|
@ -26,23 +23,23 @@ malloc_free_loop(int iters) {
|
|||
|
||||
static void
|
||||
test_hooked(int iters) {
|
||||
hooks_t hooks = {&noop_alloc_hook, &noop_dalloc_hook, &noop_expand_hook,
|
||||
NULL};
|
||||
hooks_t hooks = {
|
||||
&noop_alloc_hook, &noop_dalloc_hook, &noop_expand_hook, NULL};
|
||||
|
||||
int err;
|
||||
void *handles[HOOK_MAX];
|
||||
int err;
|
||||
void *handles[HOOK_MAX];
|
||||
size_t sz = sizeof(handles[0]);
|
||||
|
||||
for (int i = 0; i < HOOK_MAX; i++) {
|
||||
err = mallctl("experimental.hooks.install", &handles[i],
|
||||
&sz, &hooks, sizeof(hooks));
|
||||
err = mallctl("experimental.hooks.install", &handles[i], &sz,
|
||||
&hooks, sizeof(hooks));
|
||||
assert(err == 0);
|
||||
|
||||
timedelta_t timer;
|
||||
timer_start(&timer);
|
||||
malloc_free_loop(iters);
|
||||
timer_stop(&timer);
|
||||
malloc_printf("With %d hook%s: %"FMTu64"us\n", i + 1,
|
||||
malloc_printf("With %d hook%s: %" FMTu64 "us\n", i + 1,
|
||||
i + 1 == 1 ? "" : "s", timer_usec(&timer));
|
||||
}
|
||||
for (int i = 0; i < HOOK_MAX; i++) {
|
||||
|
|
@ -59,7 +56,7 @@ test_unhooked(int iters) {
|
|||
malloc_free_loop(iters);
|
||||
timer_stop(&timer);
|
||||
|
||||
malloc_printf("Without hooks: %"FMTu64"us\n", timer_usec(&timer));
|
||||
malloc_printf("Without hooks: %" FMTu64 "us\n", timer_usec(&timer));
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
|
|
@ -22,14 +22,12 @@ small_mallocx_free(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_large_vs_small) {
|
||||
compare_funcs(100*1000, 1*1000*1000, "large mallocx",
|
||||
compare_funcs(100 * 1000, 1 * 1000 * 1000, "large mallocx",
|
||||
large_mallocx_free, "small mallocx", small_mallocx_free);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_large_vs_small);
|
||||
return test_no_reentrancy(test_large_vs_small);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
static void
|
||||
mallctl_short(void) {
|
||||
const char *version;
|
||||
size_t sz = sizeof(version);
|
||||
int err = mallctl("version", &version, &sz, NULL, 0);
|
||||
size_t sz = sizeof(version);
|
||||
int err = mallctl("version", &version, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "mallctl failure");
|
||||
}
|
||||
|
||||
|
|
@ -13,19 +13,19 @@ size_t mib_short[1];
|
|||
|
||||
static void
|
||||
mallctlbymib_short(void) {
|
||||
size_t miblen = sizeof(mib_short)/sizeof(mib_short[0]);
|
||||
size_t miblen = sizeof(mib_short) / sizeof(mib_short[0]);
|
||||
const char *version;
|
||||
size_t sz = sizeof(version);
|
||||
size_t sz = sizeof(version);
|
||||
int err = mallctlbymib(mib_short, miblen, &version, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "mallctlbymib failure");
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_mallctl_vs_mallctlbymib_short) {
|
||||
size_t miblen = sizeof(mib_short)/sizeof(mib_short[0]);
|
||||
size_t miblen = sizeof(mib_short) / sizeof(mib_short[0]);
|
||||
|
||||
int err = mallctlnametomib("version", mib_short, &miblen);
|
||||
assert_d_eq(err, 0, "mallctlnametomib failure");
|
||||
compare_funcs(10*1000*1000, 10*1000*1000, "mallctl_short",
|
||||
compare_funcs(10 * 1000 * 1000, 10 * 1000 * 1000, "mallctl_short",
|
||||
mallctl_short, "mallctlbymib_short", mallctlbymib_short);
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -33,9 +33,9 @@ TEST_END
|
|||
static void
|
||||
mallctl_long(void) {
|
||||
uint64_t nmalloc;
|
||||
size_t sz = sizeof(nmalloc);
|
||||
int err = mallctl("stats.arenas.0.bins.0.nmalloc", &nmalloc, &sz, NULL,
|
||||
0);
|
||||
size_t sz = sizeof(nmalloc);
|
||||
int err = mallctl(
|
||||
"stats.arenas.0.bins.0.nmalloc", &nmalloc, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "mallctl failure");
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +43,10 @@ size_t mib_long[6];
|
|||
|
||||
static void
|
||||
mallctlbymib_long(void) {
|
||||
size_t miblen = sizeof(mib_long)/sizeof(mib_long[0]);
|
||||
size_t miblen = sizeof(mib_long) / sizeof(mib_long[0]);
|
||||
uint64_t nmalloc;
|
||||
size_t sz = sizeof(nmalloc);
|
||||
int err = mallctlbymib(mib_long, miblen, &nmalloc, &sz, NULL, 0);
|
||||
size_t sz = sizeof(nmalloc);
|
||||
int err = mallctlbymib(mib_long, miblen, &nmalloc, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "mallctlbymib failure");
|
||||
}
|
||||
|
||||
|
|
@ -57,18 +57,17 @@ TEST_BEGIN(test_mallctl_vs_mallctlbymib_long) {
|
|||
*/
|
||||
test_skip_if(!config_stats);
|
||||
|
||||
size_t miblen = sizeof(mib_long)/sizeof(mib_long[0]);
|
||||
int err = mallctlnametomib("stats.arenas.0.bins.0.nmalloc", mib_long,
|
||||
&miblen);
|
||||
size_t miblen = sizeof(mib_long) / sizeof(mib_long[0]);
|
||||
int err = mallctlnametomib(
|
||||
"stats.arenas.0.bins.0.nmalloc", mib_long, &miblen);
|
||||
assert_d_eq(err, 0, "mallctlnametomib failure");
|
||||
compare_funcs(10*1000*1000, 10*1000*1000, "mallctl_long",
|
||||
compare_funcs(10 * 1000 * 1000, 10 * 1000 * 1000, "mallctl_long",
|
||||
mallctl_long, "mallctlbymib_long", mallctlbymib_long);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_mallctl_vs_mallctlbymib_short,
|
||||
return test_no_reentrancy(test_mallctl_vs_mallctlbymib_short,
|
||||
test_mallctl_vs_mallctlbymib_long);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ mallocx_free(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_malloc_vs_mallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "malloc",
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "malloc",
|
||||
malloc_free, "mallocx", mallocx_free);
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -53,14 +53,14 @@ malloc_sdallocx(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_free_vs_dallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "free", malloc_free,
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "free", malloc_free,
|
||||
"dallocx", malloc_dallocx);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_dallocx_vs_sdallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "dallocx", malloc_dallocx,
|
||||
"sdallocx", malloc_sdallocx);
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "dallocx",
|
||||
malloc_dallocx, "sdallocx", malloc_sdallocx);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ malloc_sallocx_free(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_mus_vs_sallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "malloc_usable_size",
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "malloc_usable_size",
|
||||
malloc_mus_free, "sallocx", malloc_sallocx_free);
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -116,17 +116,14 @@ malloc_nallocx_free(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_sallocx_vs_nallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "sallocx",
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "sallocx",
|
||||
malloc_sallocx_free, "nallocx", malloc_nallocx_free);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_malloc_vs_mallocx,
|
||||
test_free_vs_dallocx,
|
||||
test_dallocx_vs_sdallocx,
|
||||
test_mus_vs_sallocx,
|
||||
return test_no_reentrancy(test_malloc_vs_mallocx, test_free_vs_dallocx,
|
||||
test_dallocx_vs_sdallocx, test_mus_vs_sallocx,
|
||||
test_sallocx_vs_nallocx);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue