]> granicus.if.org Git - gc/commitdiff
Expose API to control the minimum bytes allocated before a GC occurs
authorJonathan Chambers <joncham@gmail.com>
Tue, 10 Apr 2018 17:07:41 +0000 (13:07 -0400)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 23 Apr 2018 07:06:44 +0000 (10:06 +0300)
(a cherry-pick of commit 4c0e58d from 'unity-release-7_4-incremental')

* alloc.c (min_bytes_allocd_minimum): New static variable.
* alloc.c (GC_set_min_bytes_allocd, GC_get_min_bytes_allocd): New API
function definition (to set/get min_bytes_allocd_minimum).
* alloc.c (min_bytes_allocd): Return min_bytes_allocd_minimum if
result is less than min_bytes_allocd_minimum.
* include/gc.h (GC_set_min_bytes_allocd, GC_get_min_bytes_allocd): New
API function declaration.
* tests/test.c [GC_PTHREADS] (main): Call GC_set_min_bytes_allocd()
and GC_get_min_bytes_allocd().

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

diff --git a/alloc.c b/alloc.c
index 14c1c53bd53a886e33125fee576fa249ece1a2c7..d26178af8a4e3e5f901df1f313f1907d60287400 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -230,6 +230,20 @@ GC_API GC_stop_func GC_CALL GC_get_stop_func(void)
   GC_INNER word GC_total_stacksize = 0; /* updated on every push_all_stacks */
 #endif
 
+static size_t min_bytes_allocd_minimum = 1;
+                        /* The lowest value returned by min_bytes_allocd(). */
+
+GC_API void GC_CALL GC_set_min_bytes_allocd(size_t value)
+{
+    GC_ASSERT(value > 0);
+    min_bytes_allocd_minimum = value;
+}
+
+GC_API size_t GC_CALL GC_get_min_bytes_allocd(void)
+{
+    return min_bytes_allocd_minimum;
+}
+
 /* Return the minimum number of bytes that must be allocated between    */
 /* collections to amortize the collection cost.  Should be non-zero.    */
 static word min_bytes_allocd(void)
@@ -270,7 +284,8 @@ static word min_bytes_allocd(void)
     if (GC_incremental) {
       result /= 2;
     }
-    return result > 0 ? result : 1;
+    return result > min_bytes_allocd_minimum
+            ? result : min_bytes_allocd_minimum;
 }
 
 STATIC word GC_non_gc_bytes_at_gc = 0;
index fbac4c3084bdcf209f9652110dedf836e50e3f5f..32f66f8c6bc3ccbe6b2b3e8de061f3fc604b4d36 100644 (file)
@@ -427,6 +427,12 @@ GC_API void GC_CALL GC_set_pages_executable(int);
 /* use or need synchronization (i.e. acquiring the allocator lock).     */
 GC_API int GC_CALL GC_get_pages_executable(void);
 
+/* The setter and getter of the minimum value returned by the internal  */
+/* min_bytes_allocd().  The value should not be zero; the default value */
+/* is one.  Not synchronized.                                           */
+GC_API void GC_CALL GC_set_min_bytes_allocd(size_t);
+GC_API size_t GC_CALL GC_get_min_bytes_allocd(void);
+
 /* Overrides the default handle-fork mode.  Non-zero value means GC     */
 /* should install proper pthread_atfork handlers.  Has effect only if   */
 /* called before GC_INIT.  Clients should invoke GC_set_handle_fork     */
index 64f8f3f6f4dae1be43a73a7ec822ef3b0734a66d..13fb90ea21d4e15b5df6d45aa6ad9ac27938fdba 100644 (file)
@@ -2261,6 +2261,9 @@ int main(void)
                   "Emulating dirty bits with mprotect/signals\n");
       }
 #   endif
+    GC_set_min_bytes_allocd(1);
+    if (GC_get_min_bytes_allocd() != 1)
+        FAIL;
     GC_set_warn_proc(warn_proc);
     if ((code = pthread_key_create(&fl_key, 0)) != 0) {
         GC_printf("Key creation failed %d\n", code);