Avoid unexpected heap growth in gctest caused by GC_disable
authorIvan Maidanski <ivmai@mail.ru>
Fri, 15 Feb 2019 20:40:49 +0000 (23:40 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 15 Feb 2019 20:40:49 +0000 (23:40 +0300)
(fix of commit 8fc1ebf6d)

Issue #264 (bdwgc).

This commit eliminates the scenario when one thread disables garbage
collections while other threads intensively allocate memory objects.

* tests/test.c (run_one_test): Do not call GC_disable and GC_enable.
* tests/test.c (run_single_threaded_test): New function (which tests
GC_disable and GC_enable).
* tests/test.c (main): Call run_single_threaded_test() (before
check_heap_stats).

tests/test.c

index 9935135..6bcff15 100644 (file)
@@ -1473,9 +1473,7 @@ void run_one_test(void)
              test_generic_malloc_or_special(GC_malloc_atomic(1));
              AO_fetch_and_add1(&atomic_count);
              GC_FREE(GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(1));
-             GC_disable();
              GC_FREE(GC_MALLOC_IGNORE_OFF_PAGE(2));
-             GC_enable();
            }
          }
 #   ifdef GC_GCJ_SUPPORT
@@ -1600,6 +1598,13 @@ void run_one_test(void)
 #   endif
 }
 
+/* Execute some tests after termination of other test threads (if any). */
+void run_single_threaded_test(void) {
+    GC_disable();
+    GC_FREE(GC_MALLOC(100));
+    GC_enable();
+}
+
 void GC_CALLBACK reachable_objs_counter(void *obj, size_t size,
                                         void *pcounter)
 {
@@ -1920,6 +1925,7 @@ void GC_CALLBACK warn_proc(char *msg, GC_word p)
 #   endif
     set_print_procs();
     run_one_test();
+    run_single_threaded_test();
     check_heap_stats();
 #   ifndef MSWINCE
       fflush(stdout);
@@ -2230,6 +2236,7 @@ DWORD __stdcall thr_window(void * arg GC_ATTR_UNUSED)
     if (WaitForSingleObject(win_thr_h, INFINITE) != WAIT_OBJECT_0)
       FAIL;
 # endif
+  run_single_threaded_test();
   check_heap_stats();
 # if defined(CPPCHECK) && defined(GC_WIN32_THREADS)
     UNTESTED(GC_ExitThread);
@@ -2271,6 +2278,7 @@ int test(void)
         != PCR_ERes_okay || code != 0) {
         GC_printf("Thread 2 failed\n");
     }
+    run_single_threaded_test();
     check_heap_stats();
     return(0);
 }
@@ -2383,6 +2391,7 @@ int main(void)
         }
       }
 #   endif
+    run_single_threaded_test();
     check_heap_stats();
     (void)fflush(stdout);
     (void)pthread_attr_destroy(&attr);