]> granicus.if.org Git - gc/commitdiff
New API function (get_size_map_at) to get content of size_map table
authorIvan Maidanski <ivmai@mail.ru>
Wed, 14 Feb 2018 08:48:57 +0000 (11:48 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 14 Feb 2018 08:48:57 +0000 (11:48 +0300)
* 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.

include/gc.h
misc.c
tests/test.c

index e1f8fa7b907a7625a8d3c967dc8713e26e34924e..cf13c92cd2654f635f64327a37847f2d4ffac82d 100644 (file)
@@ -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 0c857cbb637373e051bb52aa39fa97fc26887f80..9ff518a3b03bb119d66884226767a2678b2387c1 100644 (file)
--- 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.         */
index b2fff59ec696ff7a84d0b17911dbd986e4dfd60e..4092701a60ce5ada48636faffb1b25b8ce838021 100644 (file)
@@ -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