General Information

Status Reports

  1. GCPerformanceTests

  2. BoehmGCForGCC

Please make corrections if you see mistakes here!

How to Add New Garbage Collector to GCC

Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac    (revision 113493)
+++ gcc/configure.ac    (working copy)
@@ -3213,9 +3213,12 @@
 # Find out what GC implementation we want, or may, use.
 AC_ARG_WITH(gc,
-[  --with-gc={page,zone}   choose the garbage collection mechanism to use
+[  --with-gc={boehm,page,zone}   choose the garbage collection mechanism to use
                           with the compiler],
 [case "$withval" in
+  boehm)
+    GGC=ggc-$withval
+    ;;
   page)
     GGC=ggc-$withval
     ;;

When to collect?

void
init_ggc_heuristics (void)
{
#if !defined ENABLE_GC_CHECKING && !defined ENABLE_GC_ALWAYS_COLLECT
 set_param_value ("ggc-min-expand", ggc_min_expand_heuristic());
 set_param_value ("ggc-min-heapsize", ggc_min_heapsize_heuristic());
#endif
}

So any time both "gc" and "gcac" checking are turned off we alter the heuristic so that GCC probes the system's RAM and uses more memory before collecting. When either of those checking styles are turned on (as is the case on mainline where "gc" is on) then we default to smaller values that simulate a machine with less RAM (32MB IIRC) and collect more often.

In practice this has uncovered collection bugs more reliably. Developers often have boxes with lots of RAM and their patches would get tested in situations where no collection was done. Then when the patch was installed on mainline someone would see a problem on a small RAM machine. With everyone pretending they have small RAM boxes, developers more often catch GC errors before installing anything.

Anyway, the lower parameters are set with checking on to: GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096

You can see this by compiling an actual file with -v. By that I mean you have to invoke cc1, not just run "gcc -v" without an input file. You can add these --params flags to a --disable-checking bootstrap to restore collection behavior to that found in a checking compiler.

With checking turned off then the parameters depend on the machine's configuration. For example on my box with --disable-checking I see:

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

GTY Documentation Notes

Following if_marked arguments are actually used in GCC sources:

  1. ggc_marked_p() - checks if given object is already marked.

  2. tree_map_marked_p(),

  3. tree_int_map_marked_p(),

  4. type_hash_marked_p() - these all contain optimizations for special cases.

PCH Notes

All you should need to do to support PCH is implement the ggc_pch_* routines, specified and declared in ggc.h, for your garbage collector. Only ggc_pch_write_object actually requires you to do something, everything else is to help your implementation know what's going on. For performance, it is necessary that you don't write too many objects in the PCH file (and so freeing and re-using them is a bad idea). You need to be able to mark the pointers placed in objects read from a PCH as they may refer to newly-allocated memory.

Random GGC (short for GCC GC) Notes

None: Garbage_collection_tuning (last edited 2008-01-10 19:38:41 by localhost)