Skip to content

Commit 4aee3e4

Browse files
committed
Change jemalloc prefix from je_ to je_umf_
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 7ae3029 commit 4aee3e4

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ else()
146146
add_custom_command(
147147
COMMAND
148148
./configure --prefix=${jemalloc_targ_BINARY_DIR}
149-
--with-jemalloc-prefix=je_ --disable-initial-exec-tls CFLAGS=-fPIC
150-
CXXFLAGS=-fPIC
149+
--with-jemalloc-prefix=je_umf_ --disable-initial-exec-tls
150+
CFLAGS=-fPIC CXXFLAGS=-fPIC
151151
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
152152
OUTPUT ${jemalloc_targ_SOURCE_DIR}/Makefile
153153
DEPENDS ${jemalloc_targ_SOURCE_DIR}/configure)

src/pool/pool_jemalloc.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424

2525
#define MALLOCX_ARENA_MAX (MALLCTL_ARENAS_ALL - 1)
2626

27+
#ifdef _WIN32
28+
#define je_umf_mallocx je_mallocx
29+
#define je_umf_dallocx je_dallocx
30+
#define je_umf_rallocx je_rallocx
31+
#define je_umf_mallctl je_mallctl
32+
#define je_umf_malloc_usable_size je_malloc_usable_size
33+
#endif
34+
2735
typedef struct jemalloc_memory_pool_t {
2836
umf_memory_provider_handle_t provider;
2937
unsigned int arena_index; // index of jemalloc arena
@@ -349,7 +357,7 @@ static void *op_malloc(void *pool, size_t size) {
349357
// MALLOCX_TCACHE_NONE is set, because jemalloc can mix objects from different arenas inside
350358
// the tcache, so we wouldn't be able to guarantee isolation of different providers.
351359
int flags = MALLOCX_ARENA(je_pool->arena_index) | MALLOCX_TCACHE_NONE;
352-
void *ptr = je_mallocx(size, flags);
360+
void *ptr = je_umf_mallocx(size, flags);
353361
if (ptr == NULL) {
354362
TLS_last_allocation_error = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
355363
return NULL;
@@ -366,7 +374,7 @@ static umf_result_t op_free(void *pool, void *ptr) {
366374

367375
if (ptr != NULL) {
368376
VALGRIND_DO_MEMPOOL_FREE(pool, ptr);
369-
je_dallocx(ptr, MALLOCX_TCACHE_NONE);
377+
je_umf_dallocx(ptr, MALLOCX_TCACHE_NONE);
370378
}
371379

372380
return UMF_RESULT_SUCCESS;
@@ -390,7 +398,7 @@ static void *op_calloc(void *pool, size_t num, size_t size) {
390398
static void *op_realloc(void *pool, void *ptr, size_t size) {
391399
assert(pool);
392400
if (size == 0 && ptr != NULL) {
393-
je_dallocx(ptr, MALLOCX_TCACHE_NONE);
401+
je_umf_dallocx(ptr, MALLOCX_TCACHE_NONE);
394402
TLS_last_allocation_error = UMF_RESULT_SUCCESS;
395403
VALGRIND_DO_MEMPOOL_FREE(pool, ptr);
396404
return NULL;
@@ -402,7 +410,7 @@ static void *op_realloc(void *pool, void *ptr, size_t size) {
402410
// MALLOCX_TCACHE_NONE is set, because jemalloc can mix objects from different arenas inside
403411
// the tcache, so we wouldn't be able to guarantee isolation of different providers.
404412
int flags = MALLOCX_ARENA(je_pool->arena_index) | MALLOCX_TCACHE_NONE;
405-
void *new_ptr = je_rallocx(ptr, size, flags);
413+
void *new_ptr = je_umf_rallocx(ptr, size, flags);
406414
if (new_ptr == NULL) {
407415
TLS_last_allocation_error = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
408416
return NULL;
@@ -427,7 +435,7 @@ static void *op_aligned_alloc(void *pool, size_t size, size_t alignment) {
427435
// the tcache, so we wouldn't be able to guarantee isolation of different providers.
428436
int flags =
429437
MALLOCX_ALIGN(alignment) | MALLOCX_ARENA(arena) | MALLOCX_TCACHE_NONE;
430-
void *ptr = je_mallocx(size, flags);
438+
void *ptr = je_umf_mallocx(size, flags);
431439
if (ptr == NULL) {
432440
TLS_last_allocation_error = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
433441
return NULL;
@@ -465,8 +473,8 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
465473
}
466474

467475
unsigned arena_index;
468-
err = je_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
469-
NULL, 0);
476+
err = je_umf_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
477+
NULL, 0);
470478
if (err) {
471479
LOG_ERR("Could not create arena.");
472480
goto err_free_pool;
@@ -475,10 +483,10 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
475483
// setup extent_hooks for newly created arena
476484
char cmd[64];
477485
snprintf(cmd, sizeof(cmd), "arena.%u.extent_hooks", arena_index);
478-
err = je_mallctl(cmd, NULL, NULL, (void *)&pHooks, sizeof(void *));
486+
err = je_umf_mallctl(cmd, NULL, NULL, (void *)&pHooks, sizeof(void *));
479487
if (err) {
480488
snprintf(cmd, sizeof(cmd), "arena.%u.destroy", arena_index);
481-
je_mallctl(cmd, NULL, 0, NULL, 0);
489+
je_umf_mallctl(cmd, NULL, 0, NULL, 0);
482490
LOG_ERR("Could not setup extent_hooks for newly created arena.");
483491
goto err_free_pool;
484492
}
@@ -502,7 +510,7 @@ static void op_finalize(void *pool) {
502510
jemalloc_memory_pool_t *je_pool = (jemalloc_memory_pool_t *)pool;
503511
char cmd[64];
504512
snprintf(cmd, sizeof(cmd), "arena.%u.destroy", je_pool->arena_index);
505-
je_mallctl(cmd, NULL, 0, NULL, 0);
513+
je_umf_mallctl(cmd, NULL, 0, NULL, 0);
506514
pool_by_arena_index[je_pool->arena_index] = NULL;
507515
umf_ba_global_free(je_pool);
508516

@@ -511,7 +519,7 @@ static void op_finalize(void *pool) {
511519

512520
static size_t op_malloc_usable_size(void *pool, void *ptr) {
513521
(void)pool; // not used
514-
return je_malloc_usable_size(ptr);
522+
return je_umf_malloc_usable_size(ptr);
515523
}
516524

517525
static umf_result_t op_get_last_allocation_error(void *pool) {

0 commit comments

Comments
 (0)