From: Ivan Maidanski Date: Wed, 14 Feb 2018 08:48:57 +0000 (+0300) Subject: New API function (get_size_map_at) to get content of size_map table X-Git-Tag: v8.0.0~350 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9468065;p=gc New API function (get_size_map_at) to get content of size_map table * include/gc.h (GC_get_size_map_at): Declare public function. * misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED] (GC_get_size_map_at): Implement function * tests/test.c [!GC_GET_HEAP_USAGE_NOT_NEEDED] (check_heap_stats): Add dummy testing of GC_get_size_map_at. --- diff --git a/include/gc.h b/include/gc.h index e1f8fa7b..cf13c92c 100644 --- a/include/gc.h +++ b/include/gc.h @@ -770,6 +770,12 @@ GC_API size_t GC_CALL GC_get_prof_stats(struct GC_prof_stats_s *, size_t /* stats_sz */); #endif +/* Get the element value (converted to bytes) at a given index of */ +/* size_map table which provides requested-to-actual allocation size */ +/* mapping. Assumes the collector is initialized. Returns -1 if the */ +/* index is out of size_map table bounds. Does not use synchronization. */ +GC_API size_t GC_CALL GC_get_size_map_at(int i); + /* Count total memory use in bytes by all allocated blocks. Acquires */ /* the lock. */ GC_API size_t GC_CALL GC_get_memory_use(void); diff --git a/misc.c b/misc.c index 0c857cbb..9ff518a3 100644 --- a/misc.c +++ b/misc.c @@ -494,6 +494,13 @@ GC_API size_t GC_CALL GC_get_total_bytes(void) #ifndef GC_GET_HEAP_USAGE_NOT_NEEDED +GC_API size_t GC_CALL GC_get_size_map_at(int i) +{ + if ((unsigned)i > MAXOBJBYTES) + return (size_t)(signed_word)-1; + return GRANULES_TO_BYTES(GC_size_map[i]); +} + /* Return the heap usage information. This is a thread-safe (atomic) */ /* alternative for the five above getters. NULL pointer is allowed for */ /* any argument. Returned (filled in) values are of word type. */ diff --git a/tests/test.c b/tests/test.c index b2fff59e..4092701a 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1737,6 +1737,8 @@ void check_heap_stats(void) (void)GC_get_prof_stats_unsafe(&stats, sizeof(stats)); # endif } + (void)GC_get_size_map_at((size_t)(GC_signed_word)-1); + (void)GC_get_size_map_at(1); # endif # ifdef THREADS