From 1589c86c45195c5d9059be0d34dbcd58bc03d7e7 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 21 Jul 2017 21:42:18 +0300 Subject: [PATCH] New API function (GC_is_incremental_mode) * alloc.c (GC_is_incremental_mode): New public function definition. * include/gc.h (GC_full_freq): Update comment. * include/gc.h (GC_is_incremental_mode): New public function declaration. * tests/test.c [!GC_WIN32_THREADS && !GC_PTHREADS] (main): Print "Switched to incremental mode" and friend messages only if GC_is_incremental_mode(). * tests/test.c [!GC_PTHREADS] (main): Likewise. --- alloc.c | 5 +++++ include/gc.h | 6 +++++- tests/test.c | 42 ++++++++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/alloc.c b/alloc.c index 885d6517..0f18301e 100644 --- a/alloc.c +++ b/alloc.c @@ -67,6 +67,11 @@ word GC_gc_no = 0; GC_INNER GC_bool GC_incremental = FALSE; /* By default, stop the world. */ #endif +GC_API int GC_CALL GC_is_incremental_mode(void) +{ + return (int)GC_incremental; +} + #ifdef THREADS int GC_parallel = FALSE; /* By default, parallel GC is off. */ #endif diff --git a/include/gc.h b/include/gc.h index ebabfb08..d3838697 100644 --- a/include/gc.h +++ b/include/gc.h @@ -272,7 +272,7 @@ GC_API GC_ATTR_DEPRECATED int GC_use_entire_heap; GC_API GC_ATTR_DEPRECATED int GC_full_freq; /* Number of partial collections between */ /* full collections. Matters only if */ - /* GC_incremental is set. */ + /* GC_is_incremental_mode(). */ /* Full collections are also triggered if */ /* the collector detects a substantial */ /* increase in the number of in-use heap */ @@ -773,6 +773,10 @@ GC_API void GC_CALL GC_enable(void); /* Safe to call before GC_INIT(). Includes a GC_init() call. */ GC_API void GC_CALL GC_enable_incremental(void); +/* Return non-zero (TRUE) if and only if the incremental mode is on. */ +/* Does not acquire the lock. */ +GC_API int GC_CALL GC_is_incremental_mode(void); + /* Does incremental mode write-protect pages? Returns zero or */ /* more of the following, or'ed together: */ #define GC_PROTECTS_POINTER_HEAP 1 /* May protect non-atomic objects. */ diff --git a/tests/test.c b/tests/test.c index ddbdd328..4604ca77 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1777,20 +1777,23 @@ void GC_CALLBACK warn_proc(char *msg, GC_word p) # endif GC_COND_INIT(); GC_set_warn_proc(warn_proc); -# if (defined(MPROTECT_VDB) || defined(PROC_VDB) || defined(GWW_VDB)) \ - && !defined(MAKE_BACK_GRAPH) && !defined(NO_INCREMENTAL) - GC_enable_incremental(); - GC_printf("Switched to incremental mode\n"); -# ifdef PROC_VDB - GC_printf("Reading dirty bits from /proc\n"); -# elif defined(GWW_VDB) - GC_printf("Using GetWriteWatch-based implementation\n"); -# ifdef MPROTECT_VDB - GC_printf("Or emulating dirty bits with mprotect/signals\n"); -# endif -# else /* MPROTECT_VDB && !GWW_VDB */ - GC_printf("Emulating dirty bits with mprotect/signals\n"); +# if defined(MPROTECT_VDB) || defined(PROC_VDB) || defined(GWW_VDB) +# if !defined(MAKE_BACK_GRAPH) && !defined(NO_INCREMENTAL) + GC_enable_incremental(); # endif + if (GC_is_incremental_mode()) { + GC_printf("Switched to incremental mode\n"); +# ifdef PROC_VDB + GC_printf("Reading dirty bits from /proc\n"); +# elif defined(GWW_VDB) + GC_printf("Using GetWriteWatch-based implementation\n"); +# ifdef MPROTECT_VDB + GC_printf("Or emulating dirty bits with mprotect/signals\n"); +# endif +# else /* MPROTECT_VDB && !GWW_VDB */ + GC_printf("Emulating dirty bits with mprotect/signals\n"); +# endif + } # endif run_one_test(); check_heap_stats(); @@ -2205,12 +2208,15 @@ int main(void) } # endif n_tests = 0; -# if defined(MPROTECT_VDB) && !defined(REDIRECT_MALLOC) \ - && !defined(MAKE_BACK_GRAPH) && !defined(USE_PROC_FOR_LIBRARIES) \ - && !defined(NO_INCREMENTAL) +# if defined(MPROTECT_VDB) +# if !defined(REDIRECT_MALLOC) && !defined(MAKE_BACK_GRAPH) \ + && !defined(USE_PROC_FOR_LIBRARIES) && !defined(NO_INCREMENTAL) GC_enable_incremental(); - GC_printf("Switched to incremental mode\n"); - GC_printf("Emulating dirty bits with mprotect/signals\n"); +# endif + if (GC_is_incremental_mode()) { + GC_printf("Switched to incremental mode\n" + "Emulating dirty bits with mprotect/signals\n"); + } # endif GC_set_warn_proc(warn_proc); if ((code = pthread_key_create(&fl_key, 0)) != 0) { -- 2.40.0