]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Turn global 'ggc_force_collect' variable into 'force_collect' parameter to 'ggc_collect'
authorThomas Schwinge <thomas@codesourcery.com>
Tue, 17 Aug 2021 08:47:02 +0000 (10:47 +0200)
committerThomas Schwinge <thomas@codesourcery.com>
Tue, 17 Aug 2021 19:00:10 +0000 (21:00 +0200)
This simplifies the interface and gets us rid of a global variable.
No change in behavior.

Clean-up for 2004-09-02 CVS commit (Subversion r86974,
Git commit 0772402279c0161fe41784911b52c77e12803c42)
"Better memory statistics, take 2".

gcc/
* ggc.h (ggc_collect): Add 'force_collect' parameter.
* ggc-page.c (ggc_collect): Use that one instead of global
'ggc_force_collect'.  Adjust all users.
* doc/gty.texi (Invoking the garbage collector): Update.
* ggc-internal.h (ggc_force_collect): Remove.
* ggc-common.c (ggc_force_collect): Likewise.
* selftest.h (forcibly_ggc_collect): Remove.
* ggc-tests.c (selftest::forcibly_ggc_collect): Likewise.
* read-rtl-function.c (test_loading_labels): Adjust.
* selftest-run-tests.c (run_tests): Likewise.

gcc/doc/gty.texi
gcc/ggc-common.c
gcc/ggc-internal.h
gcc/ggc-page.c
gcc/ggc-tests.c
gcc/ggc.h
gcc/read-rtl-function.c
gcc/selftest-run-tests.c
gcc/selftest.h

index cf070c1f7f712efbb4c3876fd59d49fff114e86a..b667d1d19ba12b8814ec3e13e3d94f350fb83a46 100644 (file)
@@ -654,7 +654,10 @@ The GCC garbage collector GGC is only invoked explicitly. In contrast
 with many other garbage collectors, it is not implicitly invoked by
 allocation routines when a lot of memory has been consumed. So the
 only way to have GGC reclaim storage is to call the @code{ggc_collect}
-function explicitly.  This call is an expensive operation, as it may
+function explicitly.
+When the @var{force_collect} parameter is set or otherwise an internal
+heuristic decides whether to actually collect, this call is
+potentially an expensive operation, as it may
 have to scan the entire heap.  Beware that local variables (on the GCC
 call stack) are not followed by such an invocation (as many other
 garbage collectors do): you should reference all your data from static
index 357bda13f973f764de07ce4ea67b37f50a68fc39..f38e4d5020dca0c1d29863ccfcf91e70f223354f 100644 (file)
@@ -31,9 +31,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "plugin.h"
 #include "options.h"
 
-/* When set, ggc_collect will do collection.  */
-bool ggc_force_collect;
-
 /* When true, protect the contents of the identifier hash table.  */
 bool ggc_protect_identifiers = true;
 
@@ -965,12 +962,9 @@ dump_ggc_loc_statistics ()
   if (! GATHER_STATISTICS)
     return;
 
-  ggc_force_collect = true;
-  ggc_collect ();
+  ggc_collect (true);
 
   ggc_mem_desc.dump (GGC_ORIGIN);
-
-  ggc_force_collect = false;
 }
 
 /* Record ALLOCATED and OVERHEAD bytes to descriptor NAME:LINE (FUNCTION).  */
index 39850cd623012f388f758afc399fed19e8814f12..4dcfb4c008c113d9ad33e6d98b27e692041daa95 100644 (file)
@@ -88,9 +88,6 @@ extern void ggc_pch_read (FILE *, void *);
 
 /* Allocation and collection.  */
 
-/* When set, ggc_collect will do collection.  */
-extern bool ggc_force_collect;
-
 extern void ggc_record_overhead (size_t, size_t, void * FINAL_MEM_STAT_DECL);
 
 extern void ggc_free_overhead (void *);
index 1b09f0da94ff33c37cad8839e28b834189d16040..a6fbecaa1d84c45713ed008f677ca9125aad9930 100644 (file)
@@ -2184,7 +2184,7 @@ validate_free_objects (void)
 /* Top level mark-and-sweep routine.  */
 
 void
-ggc_collect (void)
+ggc_collect (bool force_collect)
 {
   /* Avoid frequent unnecessary work by skipping collection if the
      total allocations haven't expanded much since the last
@@ -2196,7 +2196,7 @@ ggc_collect (void)
   memory_block_pool::trim ();
 
   float min_expand = allocated_last_gc * param_ggc_min_expand / 100;
-  if (G.allocated < allocated_last_gc + min_expand && !ggc_force_collect)
+  if (G.allocated < allocated_last_gc + min_expand && !force_collect)
     return;
 
   timevar_push (TV_GC);
index 4ee955066252d3180622215970001d4e7811c2d3..2891c20ceac22a03b2042422894560a0ccfa375c 100644 (file)
@@ -22,21 +22,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tree-core.h"
 #include "tree.h"
-#include "ggc-internal.h" /* (for ggc_force_collect).  */
 #include "selftest.h"
 
 #if CHECKING_P
 
-/* A helper function for writing ggc tests.  */
-
-void
-selftest::forcibly_ggc_collect ()
-{
-  ggc_force_collect = true;
-  ggc_collect ();
-  ggc_force_collect = false;
-}
-
 /* The various GTY markers must be outside of a namespace to be seen by
    gengtype, so we don't put this file within the selftest namespace.  */
 
@@ -58,7 +47,7 @@ test_basic_struct ()
   root_test_struct = ggc_cleared_alloc <test_struct> ();
   root_test_struct->other = ggc_cleared_alloc <test_struct> ();
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   ASSERT_TRUE (ggc_marked_p (root_test_struct));
   ASSERT_TRUE (ggc_marked_p (root_test_struct->other));
@@ -88,7 +77,7 @@ test_length ()
   for (int i = 0; i < count; i++)
     root_test_of_length->elem[i] = ggc_cleared_alloc <test_of_length> ();
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   ASSERT_TRUE (ggc_marked_p (root_test_of_length));
   for (int i = 0; i < count; i++)
@@ -162,7 +151,7 @@ test_union ()
   test_struct *referenced_by_other = ggc_cleared_alloc <test_struct> ();
   other->m_ptr = referenced_by_other;
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   ASSERT_TRUE (ggc_marked_p (root_test_of_union_1));
   ASSERT_TRUE (ggc_marked_p (ts));
@@ -203,7 +192,7 @@ test_finalization ()
 
   test_struct_with_dtor::dtor_call_count = 0;
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   /* Verify that the destructor was run for each instance.  */
   ASSERT_EQ (count, test_struct_with_dtor::dtor_call_count);
@@ -221,7 +210,7 @@ test_deletable_global ()
   test_of_deletable = ggc_cleared_alloc <test_struct> ();
   ASSERT_TRUE (test_of_deletable != NULL);
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   ASSERT_EQ (NULL, test_of_deletable);
 }
@@ -294,7 +283,7 @@ test_inheritance ()
   test_some_subclass_as_base_ptr = new some_subclass ();
   test_some_other_subclass_as_base_ptr = new some_other_subclass ();
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   /* Verify that the roots and everything referenced by them got marked
      (both for fields in the base class and those in subclasses).  */
@@ -373,7 +362,7 @@ test_chain_next ()
       tail_node = new_node;
     }
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   /* If we got here, we survived.  */
 
@@ -440,7 +429,7 @@ test_user_struct ()
 
   num_calls_to_user_gt_ggc_mx = 0;
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   ASSERT_TRUE (ggc_marked_p (root_user_struct_ptr));
   ASSERT_TRUE (ggc_marked_p (referenced));
@@ -458,7 +447,7 @@ test_tree_marking ()
 {
   dummy_unittesting_tree = build_int_cst (integer_type_node, 1066);
 
-  selftest::forcibly_ggc_collect ();
+  ggc_collect (true);
 
   ASSERT_TRUE (ggc_marked_p (dummy_unittesting_tree));
 }
index 92884717f5c72435f6febcb06f926b7a7261e569..0f640b255e8ee5dbad623dd6ea19c0bf6a17a536 100644 (file)
--- a/gcc/ggc.h
+++ b/gcc/ggc.h
@@ -262,8 +262,10 @@ extern const char *ggc_alloc_string (const char *contents, int length
 #define ggc_strdup(S) ggc_alloc_string ((S), -1 MEM_STAT_INFO)
 
 /* Invoke the collector.  Garbage collection occurs only when this
-   function is called, not during allocations.  */
-extern void ggc_collect        (void);
+   function is called, not during allocations.
+   Unless FORCE_COLLECT, an internal heuristic decides whether to actually
+   collect.  */
+extern void ggc_collect (bool force_collect = false);
 
 /* Return unused memory pages to the system.  */
 extern void ggc_trim (void);
index ca580d3f71ebec22d1c66722a2fcfd973bdb84ad..0badfb98f9d8643c20a1b5b0db8823e0d9a81e17 100644 (file)
@@ -1861,7 +1861,7 @@ test_loading_labels ()
 
   /* Ensure that label names read from a dump are GC-managed
      and are found through the insn.  */
-  forcibly_ggc_collect ();
+  ggc_collect (true);
   ASSERT_TRUE (ggc_marked_p (insn_200));
   ASSERT_TRUE (ggc_marked_p (LABEL_NAME (insn_200)));
 }
index 1b5583e476aa3c8fc1d84601778ba7b3ad291efb..10881fce2301d5cd844ec42c1c72a0bb18673928 100644 (file)
@@ -128,7 +128,7 @@ selftest::run_tests ()
      issues.  For example, if any GC-managed items have buggy (or missing)
      finalizers, this last collection will ensure that things that were
      failed to be finalized can be detected by valgrind.  */
-  forcibly_ggc_collect ();
+  ggc_collect (true);
 
   /* Finished running tests; the test_runner dtor will print a summary.  */
 }
index 80459d63a39e7cc52cf14990e2bc130cfecbfb5e..58d8d383cee31507f409d8c982769db36e7864f4 100644 (file)
@@ -190,11 +190,6 @@ for_each_line_table_case (void (*testcase) (const line_table_case &));
 
 extern char *read_file (const location &loc, const char *path);
 
-/* A helper function for writing tests that interact with the
-   garbage collector.  */
-
-extern void forcibly_ggc_collect ();
-
 /* Convert a path relative to SRCDIR/gcc/testsuite/selftests
    to a real path (either absolute, or relative to pwd).
    The result should be freed by the caller.  */