From 6a7aa46ef753108f9b0c065572abff14c33eb5d2 Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Mon, 2 Mar 2020 18:07:19 -0800 Subject: [PATCH] Cache bin: Add a debug method for init checking. --- include/jemalloc/internal/cache_bin.h | 7 +++++++ include/jemalloc/internal/jemalloc_internal_inlines_a.h | 4 ++-- src/cache_bin.c | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/jemalloc/internal/cache_bin.h b/include/jemalloc/internal/cache_bin.h index 42504edc..461b20be 100644 --- a/include/jemalloc/internal/cache_bin.h +++ b/include/jemalloc/internal/cache_bin.h @@ -354,4 +354,11 @@ void cache_bin_postincrement(cache_bin_info_t *infos, szind_t ninfos, void cache_bin_init(cache_bin_t *bin, cache_bin_info_t *info, void *alloc, size_t *cur_offset); +/* + * If a cache bin was zero initialized (either because it lives in static or + * thread-local storage, or was memset to 0), this function indicates whether or + * not cache_bin_init was called on it. + */ +bool cache_bin_still_zero_initialized(cache_bin_t *bin); + #endif /* JEMALLOC_INTERNAL_CACHE_BIN_H */ diff --git a/include/jemalloc/internal/jemalloc_internal_inlines_a.h b/include/jemalloc/internal/jemalloc_internal_inlines_a.h index f079e853..cc5e3595 100644 --- a/include/jemalloc/internal/jemalloc_internal_inlines_a.h +++ b/include/jemalloc/internal/jemalloc_internal_inlines_a.h @@ -130,8 +130,8 @@ tcache_available(tsd_t *tsd) { if (likely(tsd_tcache_enabled_get(tsd))) { /* Associated arena == NULL implies tcache init in progress. */ assert(tsd_tcachep_get(tsd)->arena == NULL || - tcache_small_bin_get(tsd_tcachep_get(tsd), 0)->cur_ptr.ptr - != NULL); + !cache_bin_still_zero_initialized( + tcache_small_bin_get(tsd_tcachep_get(tsd), 0))); return true; } diff --git a/src/cache_bin.c b/src/cache_bin.c index 260c1b77..94f3b32e 100644 --- a/src/cache_bin.c +++ b/src/cache_bin.c @@ -102,3 +102,8 @@ cache_bin_init(cache_bin_t *bin, cache_bin_info_t *info, void *alloc, assert(cache_bin_ncached_get(bin, info) == 0); assert(cache_bin_empty_position_get(bin, info) == empty_position); } + +bool +cache_bin_still_zero_initialized(cache_bin_t *bin) { + return bin->cur_ptr.ptr == NULL; +}