De-export test-only helpers via JET_EXTERN / #ifdef JEMALLOC_JET; declare in unit tests, not headers

This commit is contained in:
Slobodan Predolac 2026-06-08 13:26:02 -07:00
parent 6db4d0c468
commit 4de3a4c3d1
46 changed files with 123 additions and 59 deletions

View file

@ -8,6 +8,8 @@
#include "jemalloc/internal/mutex.h"
#include "jemalloc/internal/sz.h"
JET_EXTERN ehooks_t *base_ehooks_get_for_metadata(base_t *base);
/*
* In auto mode, arenas switch to huge pages for the base allocator on the
* second base block. a0 switches to thp on the 5th block (after 20 megabytes
@ -545,7 +547,7 @@ base_ehooks_get(base_t *base) {
return &base->ehooks;
}
ehooks_t *
JET_EXTERN ehooks_t *
base_ehooks_get_for_metadata(base_t *base) {
return &base->ehooks_base;
}

View file

@ -69,7 +69,7 @@ bin_postfork_child(tsdn_t *tsdn, bin_t *bin) {
malloc_mutex_postfork_child(tsdn, &bin->lock);
}
void *
JET_EXTERN void *
bin_slab_reg_alloc(edata_t *slab, const bin_info_t *bin_info) {
void *ret;
slab_data_t *slab_data = edata_slab_data_get(slab);
@ -134,7 +134,7 @@ bin_slab_reg_alloc_batch(
edata_nfree_sub(slab, cnt);
}
void
JET_EXTERN void
bin_slabs_nonfull_insert(bin_t *bin, edata_t *slab) {
assert(edata_nfree_get(slab) > 0);
edata_heap_insert(&bin->slabs_nonfull, slab);
@ -143,7 +143,7 @@ bin_slabs_nonfull_insert(bin_t *bin, edata_t *slab) {
}
}
void
JET_EXTERN void
bin_slabs_nonfull_remove(bin_t *bin, edata_t *slab) {
edata_heap_remove(&bin->slabs_nonfull, slab);
if (config_stats) {
@ -151,7 +151,7 @@ bin_slabs_nonfull_remove(bin_t *bin, edata_t *slab) {
}
}
edata_t *
JET_EXTERN edata_t *
bin_slabs_nonfull_tryget(bin_t *bin) {
edata_t *slab = edata_heap_remove_first(&bin->slabs_nonfull);
if (slab == NULL) {
@ -164,7 +164,7 @@ bin_slabs_nonfull_tryget(bin_t *bin) {
return slab;
}
void
JET_EXTERN void
bin_slabs_full_insert(bool is_auto, bin_t *bin, edata_t *slab) {
assert(edata_nfree_get(slab) == 0);
/*
@ -186,7 +186,7 @@ bin_slabs_full_remove(bool is_auto, bin_t *bin, edata_t *slab) {
edata_list_active_remove(&bin->slabs_full, slab);
}
void
JET_EXTERN void
bin_dissociate_slab(bool is_auto, edata_t *slab, bin_t *bin) {
/* Dissociate slab from bin. */
if (slab == bin->slabcur) {
@ -208,7 +208,7 @@ bin_dissociate_slab(bool is_auto, edata_t *slab, bin_t *bin) {
}
}
void
JET_EXTERN void
bin_lower_slab(tsdn_t *tsdn, bool is_auto, edata_t *slab, bin_t *bin) {
assert(edata_nfree_get(slab) > 0);
@ -234,7 +234,7 @@ bin_lower_slab(tsdn_t *tsdn, bool is_auto, edata_t *slab, bin_t *bin) {
}
}
void
JET_EXTERN void
bin_dalloc_slab_prepare(tsdn_t *tsdn, edata_t *slab, bin_t *bin) {
malloc_mutex_assert_owner(tsdn, &bin->lock);

View file

@ -5,8 +5,11 @@
/******************************************************************************/
JET_EXTERN size_t bitmap_size(const bitmap_info_t *binfo);
#ifdef BITMAP_USE_TREE
#ifdef JEMALLOC_JET
void
bitmap_info_init(bitmap_info_t *binfo, size_t nbits) {
unsigned i;
@ -34,6 +37,7 @@ bitmap_info_init(bitmap_info_t *binfo, size_t nbits) {
binfo->nlevels = i;
binfo->nbits = nbits;
}
#endif
static size_t
bitmap_info_ngroups(const bitmap_info_t *binfo) {
@ -82,6 +86,7 @@ bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo, bool fill) {
#else /* BITMAP_USE_TREE */
#ifdef JEMALLOC_JET
void
bitmap_info_init(bitmap_info_t *binfo, size_t nbits) {
assert(nbits > 0);
@ -90,6 +95,7 @@ bitmap_info_init(bitmap_info_t *binfo, size_t nbits) {
binfo->ngroups = BITMAP_BITS2GROUPS(nbits);
binfo->nbits = nbits;
}
#endif
static size_t
bitmap_info_ngroups(const bitmap_info_t *binfo) {
@ -115,7 +121,7 @@ bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo, bool fill) {
#endif /* BITMAP_USE_TREE */
size_t
JET_EXTERN size_t
bitmap_size(const bitmap_info_t *binfo) {
return (bitmap_info_ngroups(binfo) << LG_SIZEOF_BITMAP);
}

View file

@ -68,7 +68,7 @@ buf_writer_init(tsdn_t *tsdn, buf_writer_t *buf_writer, write_cb_t *write_cb,
return buf_writer->buf == NULL;
}
void
JET_EXTERN void
buf_writer_flush(buf_writer_t *buf_writer) {
buf_writer_assert(buf_writer);
if (buf_writer->buf == NULL) {

View file

@ -541,6 +541,7 @@ ckh_search(ckh_t *ckh, const void *searchkey, void **key, void **data) {
return true;
}
#ifdef JEMALLOC_JET
void
ckh_string_hash(const void *key, size_t r_hash[2]) {
hash(key, strlen((const char *)key), 0x94122f33U, r_hash);
@ -570,3 +571,4 @@ bool
ckh_pointer_keycomp(const void *k1, const void *k2) {
return (k1 == k2);
}
#endif

View file

@ -14,7 +14,7 @@ const char *const hpa_hugify_style_names[] = {"auto", "none", "eager", "lazy"};
bool opt_experimental_hpa_start_huge_if_thp_always = true;
bool opt_experimental_hpa_enforce_hugify = false;
bool
JET_EXTERN bool
hpa_hugepage_size_exceeds_limit(void) {
return HUGEPAGE > HUGEPAGE_MAX_EXPECTED_SIZE;
}

View file

@ -46,6 +46,7 @@ ph_gen(, hpdata_age_heap, hpdata_t, age_link, hpdata_age_comp)
hpdata_assert_consistent(hpdata);
}
#ifdef JEMALLOC_JET
void *
hpdata_reserve_alloc(hpdata_t *hpdata, size_t sz) {
hpdata_assert_consistent(hpdata);
@ -138,6 +139,7 @@ hpdata_reserve_alloc(hpdata_t *hpdata, size_t sz) {
return (
void *)((byte_t *)hpdata_addr_get(hpdata) + (result << LG_PAGE));
}
#endif
void
hpdata_unreserve(hpdata_t *hpdata, void *addr, size_t sz) {

View file

@ -60,11 +60,13 @@ nstime_ns(const nstime_t *time) {
return time->ns;
}
#ifdef JEMALLOC_JET
uint64_t
nstime_ms(const nstime_t *time) {
nstime_assert_initialized(time);
return time->ns / MILLION;
}
#endif
uint64_t
nstime_sec(const nstime_t *time) {
@ -119,6 +121,7 @@ nstime_subtract(nstime_t *time, const nstime_t *subtrahend) {
time->ns -= subtrahend->ns;
}
#ifdef JEMALLOC_JET
void
nstime_isubtract(nstime_t *time, uint64_t subtrahend) {
nstime_assert_initialized(time);
@ -127,6 +130,7 @@ nstime_isubtract(nstime_t *time, uint64_t subtrahend) {
/* No initialize operand -- subtraction must be initialized. */
time->ns -= subtrahend;
}
#endif
void
nstime_imultiply(nstime_t *time, uint64_t multiplier) {

View file

@ -249,7 +249,7 @@ prof_tctx_create(tsd_t *tsd) {
* (e.g.
* -mno-sse) in order for the workaround to be complete.
*/
uint64_t
JET_EXTERN uint64_t
prof_sample_new_event_wait(tsd_t *tsd) {
#ifdef JEMALLOC_PROF
if (lg_prof_sample == 0) {

View file

@ -404,6 +404,7 @@ prof_lookup(tsd_t *tsd, prof_bt_t *bt) {
return ret.p;
}
#ifdef JEMALLOC_JET
/* Used in unit tests. */
static prof_tdata_t *
prof_tdata_count_iter(
@ -449,6 +450,7 @@ prof_bt_count(void) {
return bt_count;
}
#endif
static void
prof_thread_name_write_tdata(prof_tdata_t *tdata, const char *thread_name) {
@ -1105,6 +1107,7 @@ prof_dump_impl(tsd_t *tsd, write_cb_t *prof_dump_write, void *cbopaque,
}
}
#ifdef JEMALLOC_JET
/* Used in unit tests. */
void
prof_cnt_all(prof_cnt_t *cnt_all) {
@ -1119,6 +1122,7 @@ prof_cnt_all(prof_cnt_t *cnt_all) {
prof_gctx_finish(tsd, &gctxs);
}
}
#endif
void
prof_bt_hash(const void *key, size_t r_hash[2]) {

View file

@ -309,6 +309,7 @@ prof_thr_node_keycomp(const void *k1, const void *k2) {
return thr_node1->thr_uid == thr_node2->thr_uid;
}
#ifdef JEMALLOC_JET
/* Used in unit tests. */
size_t
prof_log_bt_count(void) {
@ -413,6 +414,7 @@ prof_log_dummy_set(bool new_value) {
cassert(config_prof);
prof_log_dummy = new_value;
}
#endif
/* Used as an atexit function to stop logging on exit. */
static void

View file

@ -108,11 +108,13 @@ prof_recent_alloc_edata_get_no_lock(const prof_recent_t *n) {
return (edata_t *)atomic_load_p(&n->alloc_edata, ATOMIC_ACQUIRE);
}
#ifdef JEMALLOC_JET
edata_t *
prof_recent_alloc_edata_get_no_lock_test(const prof_recent_t *n) {
cassert(config_prof);
return prof_recent_alloc_edata_get_no_lock(n);
}
#endif
static inline edata_t *
prof_recent_alloc_edata_get(tsd_t *tsd, const prof_recent_t *n) {
@ -138,11 +140,13 @@ edata_prof_recent_alloc_get_no_lock(const edata_t *edata) {
return edata_prof_recent_alloc_get_dont_call_directly(edata);
}
#ifdef JEMALLOC_JET
prof_recent_t *
edata_prof_recent_alloc_get_no_lock_test(const edata_t *edata) {
cassert(config_prof);
return edata_prof_recent_alloc_get_no_lock(edata);
}
#endif
static inline prof_recent_t *
edata_prof_recent_alloc_get(tsd_t *tsd, const edata_t *edata) {

View file

@ -13,7 +13,7 @@
* at least the damage is compartmentalized to this file.
*/
size_t
JET_EXTERN size_t
reg_size_compute(int lg_base, int lg_delta, int ndelta) {
return (ZU(1) << lg_base) + (ZU(ndelta) << lg_delta);
}