• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

build/s60v3/H28-Sep-2021-9072

cord/H28-Sep-2021-3,6092,782

doc/H03-May-2022-5,1124,065

extra/H28-Sep-2021-1,5711,079

include/H03-May-2022-14,7618,824

m4/H28-Sep-2021-9,0988,222

tests/H03-May-2022-4,9364,093

tools/H28-Sep-2021-344258

AUTHORSH A D28-Sep-202115.7 KiB436429

BCC_MAKEFILEH A D28-Sep-20212.3 KiB8264

ChangeLogH A D28-Sep-2021476.8 KiB10,1179,186

Makefile.amH A D28-Sep-20216.5 KiB228112

Makefile.directH A D28-Sep-202117.2 KiB419253

Makefile.inH A D03-May-2022109.8 KiB2,5932,282

NT_MAKEFILEH A D28-Sep-20215.4 KiB144113

OS2_MAKEFILEH A D28-Sep-20212.1 KiB4632

PCR-MakefileH A D28-Sep-20211.2 KiB4831

README.QUICKH A D28-Sep-20213.8 KiB8567

README.mdH A D28-Sep-202128 KiB598469

SMakefile.amigaH A D28-Sep-20213.9 KiB173109

WCC_MAKEFILEH A D28-Sep-20214 KiB167141

aclocal.m4H A D28-Sep-202143.7 KiB1,2151,103

allchblk.cH A D28-Sep-202136.8 KiB1,007707

alloc.cH A D28-Sep-202151.3 KiB1,5581,111

autogen.shH A D28-Sep-2021706 194

backgraph.cH A D28-Sep-202118.8 KiB555393

bdw-gc.pc.inH A D03-May-2022303 119

blacklst.cH A D28-Sep-202110.7 KiB302197

checksums.cH A D28-Sep-20215.1 KiB179134

compileH A D28-Sep-20217.2 KiB348258

config.guessH A D28-Sep-202141.9 KiB1,4221,230

config.subH A D28-Sep-202135.1 KiB1,8081,670

configureH A D03-May-2022628.3 KiB20,71717,390

configure.acH A D28-Sep-202137.9 KiB1,1471,043

darwin_stop_world.cH A D28-Sep-202125.7 KiB770588

dbg_mlc.cH A D28-Sep-202139 KiB1,208980

depcompH A D28-Sep-202123 KiB792502

digimars.makH A D28-Sep-20212.3 KiB9581

dyn_load.cH A D28-Sep-202154.6 KiB1,5851,162

finalize.cH A D28-Sep-202148.6 KiB1,4141,106

fnlz_mlc.cH A D28-Sep-20214.2 KiB11569

gc.makH A D28-Sep-202153.7 KiB2,2401,623

gc_cpp.ccH A D28-Sep-20213.9 KiB13288

gc_cpp.cppH A D28-Sep-202175 31

gc_dlopen.cH A D28-Sep-20213.8 KiB10149

gcj_mlc.cH A D28-Sep-20219.6 KiB281200

headers.cH A D28-Sep-202112.6 KiB417310

ia64_save_regs_in_stack.sH A D28-Sep-2021255 1211

install-shH A D28-Sep-202114.3 KiB502327

ltmain.shH A D28-Sep-2021316.5 KiB11,1487,979

mach_dep.cH A D28-Sep-202111.6 KiB338239

malloc.cH A D28-Sep-202123.2 KiB698526

mallocx.cH A D28-Sep-202121.3 KiB636466

mark.cH A D28-Sep-202176.5 KiB2,0631,509

mark_rts.cH A D28-Sep-202133.6 KiB961659

misc.cH A D28-Sep-202179.2 KiB2,5862,025

missingH A D28-Sep-20216.7 KiB216143

new_hblk.cH A D28-Sep-20216.2 KiB192117

obj_map.cH A D28-Sep-20213 KiB9157

os_dep.cH A D28-Sep-2021172.1 KiB4,9163,693

pthread_start.cH A D28-Sep-20212.9 KiB7230

pthread_stop_world.cH A D28-Sep-202144 KiB1,290973

pthread_support.cH A D28-Sep-202178.2 KiB2,3241,725

ptr_chck.cH A D28-Sep-20219.5 KiB281203

reclaim.cH A D28-Sep-202126.8 KiB859630

sparc_mach_dep.SH A D28-Sep-20211.9 KiB6259

sparc_netbsd_mach_dep.sH A D28-Sep-2021906 3531

sparc_sunos4_mach_dep.sH A D28-Sep-2021830 3330

specific.cH A D28-Sep-20217 KiB191119

test-driverH A D28-Sep-20214.5 KiB14987

thread_local_alloc.cH A D28-Sep-202111.3 KiB303193

typd_mlc.cH A D28-Sep-202126.8 KiB721542

win32_threads.cH A D28-Sep-2021108.9 KiB3,1512,278

README.QUICK

1Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
2Copyright (c) 1991-1995 by Xerox Corporation.  All rights reserved.
3Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
4Copyright (c) 1999-2001 by Hewlett-Packard. All rights reserved.
5Copyright (c) 2009-2019 Ivan Maidanski
6
7THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
9
10Permission is hereby granted to use or copy this program
11for any purpose,  provided the above notices are retained on all copies.
12Permission to modify the code and to distribute modified code is granted,
13provided the above notices are retained, and a notice that the code was
14modified is included with the above copyright notice.
15
16A few files have other copyright holders. A few of the files needed
17to use the GNU-style build procedure come with a modified GPL license
18that appears not to significantly restrict use of the collector, though
19use of those files for a purpose other than building the collector may
20require the resulting code to be covered by the GPL.
21
22For more details and the names of other contributors, see the README.md,
23doc/README.*, AUTHORS and include/gc.h files.  These files describe typical
24use of the collector on a machine that is already supported.
25
26For the version number, see README.md or include/gc_version.h files.
27
28INSTALLATION:
29Under UN*X, Linux:
30Alternative 1 (the old way): type "make -f Makefile.direct check".
31        Link against gc.a.
32
33Alternative 2 (the new way): type
34        "./configure --prefix=<dir>; make; make check; make install".
35        Link against <dir>/lib/libgc.a or <dir>/lib/libgc.so.
36        See doc/README.autoconf for details
37
38Under Windows 95, 98, Me, NT, or 2000:
39copy the appropriate makefile to MAKEFILE, read it, and type "nmake test".
40(Under Windows, this assumes you have Microsoft command-line tools
41installed, and suitably configured.)
42Read the machine specific README.XXX in the doc directory if one exists.
43
44If you need thread support, you should define GC_THREADS as described in
45doc/README.macros (configure defines this implicitly unless --disable-threads
46option is given).
47
48If you wish to use the cord (structured string) library with the stand-alone
49Makefile.direct, type "make -f Makefile.direct cords".  (You may need to
50override CC specified in the Makefile. The CORD_printf implementation in
51cordprnt.c is known to be less than perfectly portable.  The rest of the
52package should still work.)  See include/cord.h for the API.
53
54If you wish to use the collector from C++, type "make c++", or use
55--enable-cplusplus with the configure script.   With Makefile.direct,
56these ones add further files to gc.a and to the include subdirectory.
57With the alternate build process, this generates libgccpp.
58See include/gc_cpp.h.
59
60TYPICAL USE:
61Include "gc.h" from the include subdirectory.  Link against the
62appropriate library ("gc.a" under UN*X).  Replace calls to malloc
63by calls to GC_MALLOC, and calls to realloc by calls to GC_REALLOC.
64If the object is known to never contain pointers, use GC_MALLOC_ATOMIC
65instead of GC_MALLOC.
66
67Define GC_DEBUG before including gc.h for additional checking.
68
69More documentation on the collector interface can be found in README.md,
70doc/gcinterface.md, include/gc.h, and other files in the doc directory.
71
72WARNINGS:
73
74Do not store the only pointer to an object in memory allocated
75with system malloc, since the collector usually does not scan
76memory allocated in this way.
77
78Use with threads may be supported on your system, but requires the
79collector to be built with thread support.  See Makefile.  The collector
80does not guarantee to scan thread-local storage (e.g. of the kind
81accessed with pthread_getspecific()).  The collector does scan
82thread stacks though, so generally the best solution is to ensure that
83any pointers stored in thread-local storage are also stored on the
84thread's stack for the duration of their lifetime.
85

README.md

1# Boehm-Demers-Weiser Garbage Collector
2
3This is version 8.0.6 of a conservative garbage
4collector for C and C++.
5
6
7## Download
8
9You might find a more recent/stable version on the
10[Download](https://github.com/ivmai/bdwgc/wiki/Download) page, or
11[BDWGC site](http://www.hboehm.info/gc/).
12
13Also, the latest bug fixes and new features are available in the
14[development repository](https://github.com/ivmai/bdwgc).
15
16
17## Overview
18
19This is intended to be a general purpose, garbage collecting storage
20allocator.  The algorithms used are described in:
21
22 * Boehm, H., and M. Weiser, "Garbage Collection in an Uncooperative
23   Environment", Software Practice & Experience, September 1988, pp. 807-820.
24
25 * Boehm, H., A. Demers, and S. Shenker, "Mostly Parallel Garbage Collection",
26   Proceedings of the ACM SIGPLAN '91 Conference on Programming Language Design
27   and Implementation, SIGPLAN Notices 26, 6 (June 1991), pp. 157-164.
28
29 * Boehm, H., "Space Efficient Conservative Garbage Collection", Proceedings
30   of the ACM SIGPLAN '91 Conference on Programming Language Design and
31   Implementation, SIGPLAN Notices 28, 6 (June 1993), pp. 197-206.
32
33 * Boehm H., "Reducing Garbage Collector Cache Misses", Proceedings of the
34   2000 International Symposium on Memory Management.
35
36Possible interactions between the collector and optimizing compilers are
37discussed in
38
39 * Boehm, H., and D. Chase, "A Proposal for GC-safe C Compilation",
40   The Journal of C Language Translation 4, 2 (December 1992).
41
42and
43
44 * Boehm H., "Simple GC-safe Compilation", Proceedings of the ACM SIGPLAN '96
45   Conference on Programming Language Design and Implementation.
46
47Unlike the collector described in the second reference, this collector
48operates either with the mutator stopped during the entire collection
49(default) or incrementally during allocations.  (The latter is supported
50on fewer machines.)  On the most common platforms, it can be built
51with or without thread support.  On a few platforms, it can take advantage
52of a multiprocessor to speed up garbage collection.
53
54Many of the ideas underlying the collector have previously been explored
55by others.  Notably, some of the run-time systems developed at Xerox PARC
56in the early 1980s conservatively scanned thread stacks to locate possible
57pointers (cf. Paul Rovner, "On Adding Garbage Collection and Runtime Types
58to a Strongly-Typed Statically Checked, Concurrent Language"  Xerox PARC
59CSL 84-7).  Doug McIlroy wrote a simpler fully conservative collector that
60was part of version 8 UNIX (tm), but appears to not have received
61widespread use.
62
63Rudimentary tools for use of the collector as a
64[leak detector](doc/leak.md) are included,
65as is a fairly sophisticated string package "cord" that makes use of the
66collector.  (See doc/README.cords and H.-J. Boehm, R. Atkinson, and M. Plass,
67"Ropes: An Alternative to Strings", Software Practice and Experience 25, 12
68(December 1995), pp. 1315-1330.  This is very similar to the "rope" package
69in Xerox Cedar, or the "rope" package in the SGI STL or the g++ distribution.)
70
71Further collector documentation can be found in the
72[overview](doc/overview.md).
73
74
75## General Description
76
77This is a garbage collecting storage allocator that is intended to be
78used as a plug-in replacement for C's malloc.
79
80Since the collector does not require pointers to be tagged, it does not
81attempt to ensure that all inaccessible storage is reclaimed.  However,
82in our experience, it is typically more successful at reclaiming unused
83memory than most C programs using explicit deallocation.  Unlike manually
84introduced leaks, the amount of unreclaimed memory typically stays
85bounded.
86
87In the following, an "object" is defined to be a region of memory allocated
88by the routines described below.
89
90Any objects not intended to be collected must be pointed to either
91from other such accessible objects, or from the registers,
92stack, data, or statically allocated bss segments.  Pointers from
93the stack or registers may point to anywhere inside an object.
94The same is true for heap pointers if the collector is compiled with
95`ALL_INTERIOR_POINTERS` defined, or `GC_all_interior_pointers` is otherwise
96set, as is now the default.
97
98Compiling without `ALL_INTERIOR_POINTERS` may reduce accidental retention
99of garbage objects, by requiring pointers from the heap to the beginning
100of an object.  But this no longer appears to be a significant
101issue for most programs occupying a small fraction of the possible
102address space.
103
104There are a number of routines which modify the pointer recognition
105algorithm.  `GC_register_displacement` allows certain interior pointers
106to be recognized even if `ALL_INTERIOR_POINTERS` is not defined.
107`GC_malloc_ignore_off_page` allows some pointers into the middle of
108large objects to be disregarded, greatly reducing the probability of
109accidental retention of large objects.  For most purposes it seems
110best to compile with `ALL_INTERIOR_POINTERS` and to use
111`GC_malloc_ignore_off_page` if you get collector warnings from
112allocations of very large objects.  See [here](doc/debugging.md) for details.
113
114_WARNING_: pointers inside memory allocated by the standard `malloc` are not
115seen by the garbage collector.  Thus objects pointed to only from such a
116region may be prematurely deallocated.  It is thus suggested that the
117standard `malloc` be used only for memory regions, such as I/O buffers, that
118are guaranteed not to contain pointers to garbage collectible memory.
119Pointers in C language automatic, static, or register variables,
120are correctly recognized.  (Note that `GC_malloc_uncollectable` has
121semantics similar to standard malloc, but allocates objects that are
122traced by the collector.)
123
124_WARNING_: the collector does not always know how to find pointers in data
125areas that are associated with dynamic libraries.  This is easy to
126remedy IF you know how to find those data areas on your operating
127system (see `GC_add_roots`).  Code for doing this under SunOS, IRIX
1285.X and 6.X, HP/UX, Alpha OSF/1, Linux, and win32 is included and used
129by default.  (See doc/README.win32 for Win32 details.)  On other systems
130pointers from dynamic library data areas may not be considered by the
131collector.  If you're writing a program that depends on the collector
132scanning dynamic library data areas, it may be a good idea to include
133at least one call to `GC_is_visible` to ensure that those areas are
134visible to the collector.
135
136Note that the garbage collector does not need to be informed of shared
137read-only data.  However if the shared library mechanism can introduce
138discontiguous data areas that may contain pointers, then the collector does
139need to be informed.
140
141Signal processing for most signals may be deferred during collection,
142and during uninterruptible parts of the allocation process.
143Like standard ANSI C mallocs, by default it is unsafe to invoke
144malloc (and other GC routines) from a signal handler while another
145malloc call may be in progress.
146
147The allocator/collector can also be configured for thread-safe operation.
148(Full signal safety can also be achieved, but only at the cost of two system
149calls per malloc, which is usually unacceptable.)
150
151_WARNING_: the collector does not guarantee to scan thread-local storage
152(e.g. of the kind accessed with `pthread_getspecific`).  The collector
153does scan thread stacks, though, so generally the best solution is to
154ensure that any pointers stored in thread-local storage are also
155stored on the thread's stack for the duration of their lifetime.
156(This is arguably a longstanding bug, but it hasn't been fixed yet.)
157
158
159## Installation and Portability
160
161As distributed, the collector operates silently
162In the event of problems, this can usually be changed by defining the
163`GC_PRINT_STATS` or `GC_PRINT_VERBOSE_STATS` environment variables.  This
164will result in a few lines of descriptive output for each collection.
165(The given statistics exhibit a few peculiarities.
166Things don't appear to add up for a variety of reasons, most notably
167fragmentation losses.  These are probably much more significant for the
168contrived program "test.c" than for your application.)
169
170On most Unix-like platforms, the collector can be built either using a
171GNU autoconf-based build infrastructure (type `./configure; make` in the
172simplest case), or with a classic makefile by itself (type
173`make -f Makefile.direct`).
174
175Please note that the collector source repository does not contain configure
176and similar auto-generated files, thus the full procedure of autoconf-based
177build of `master` branch of the collector could look like:
178
179    git clone git://github.com/ivmai/bdwgc.git
180    cd bdwgc
181    git clone git://github.com/ivmai/libatomic_ops.git
182    ./autogen.sh
183    ./configure
184    make -j
185    make check
186
187Cloning of `libatomic_ops` is now optional provided the compiler supports
188atomic intrinsics.
189
190Below we focus on the collector build using classic makefile.
191For the Makefile.direct-based process, typing `make check` instead of `make`
192will automatically build the collector and then run `setjmp_test` and `gctest`.
193`Setjmp_test` will give you information about configuring the collector, which is
194useful primarily if you have a machine that's not already supported.  Gctest is
195a somewhat superficial test of collector functionality.  Failure is indicated
196by a core dump or a message to the effect that the collector is broken.  Gctest
197takes about a second to two to run on reasonable 2007 vintage desktops.  It may
198use up to about 30MB of memory.  (The multi-threaded version will use more.
19964-bit versions may use more.) `make test` will also, as its last step, attempt
200to build and test the "cord" string library.)
201
202Makefile.direct will generate a library gc.a which you should link against.
203Typing "make cords" will add the cord library to gc.a.
204
205The GNU style build process understands the usual targets.  `make check`
206runs a number of tests.  `make install` installs at least libgc, and libcord.
207Try `./configure --help` to see the configuration options.  It is currently
208not possible to exercise all combinations of build options this way.
209
210It is suggested that if you need to replace a piece of the collector
211(e.g. GC_mark_rts.c) you simply list your version ahead of gc.a on the
212ld command line, rather than replacing the one in gc.a.  (This will
213generate numerous warnings under some versions of AIX, but it still
214works.)
215
216All include files that need to be used by clients will be put in the
217include subdirectory.  (Normally this is just gc.h.  `make cords` adds
218"cord.h" and "ec.h".)
219
220The collector currently is designed to run essentially unmodified on
221machines that use a flat 32-bit or 64-bit address space.
222That includes the vast majority of Workstations and X86 (X >= 3) PCs.
223(The list here was deleted because it was getting too long and constantly
224out of date.)
225
226In a few cases (Amiga, OS/2, Win32, MacOS) a separate makefile
227or equivalent is supplied.  Many of these have separate README.system
228files.
229
230Dynamic libraries are completely supported only under SunOS/Solaris,
231(and even that support is not functional on the last Sun 3 release),
232Linux, FreeBSD, NetBSD, IRIX 5&6, HP/UX, Win32 (not Win32S) and OSF/1
233on DEC AXP machines plus perhaps a few others listed near the top
234of dyn_load.c.  On other machines we recommend that you do one of
235the following:
236
237 1) Add dynamic library support (and send us the code).
238 2) Use static versions of the libraries.
239 3) Arrange for dynamic libraries to use the standard malloc.
240    This is still dangerous if the library stores a pointer to a
241    garbage collected object.  But nearly all standard interfaces
242    prohibit this, because they deal correctly with pointers
243    to stack allocated objects.  (Strtok is an exception.  Don't
244    use it.)
245
246In all cases we assume that pointer alignment is consistent with that
247enforced by the standard C compilers.  If you use a nonstandard compiler
248you may have to adjust the alignment parameters defined in gc_priv.h.
249Note that this may also be an issue with packed records/structs, if those
250enforce less alignment for pointers.
251
252A port to a machine that is not byte addressed, or does not use 32 bit
253or 64 bit addresses will require a major effort.  A port to plain MSDOS
254or win16 is hard.
255
256For machines not already mentioned, or for nonstandard compilers,
257some porting suggestions are provided [here](doc/porting.md).
258
259
260## The C Interface to the Allocator
261
262The following routines are intended to be directly called by the user.
263Note that usually only `GC_malloc` is necessary.  `GC_clear_roots` and
264`GC_add_roots` calls may be required if the collector has to trace
265from nonstandard places (e.g. from dynamic library data areas on a
266machine on which the collector doesn't already understand them.)  On
267some machines, it may be desirable to set `GC_stackbottom` to a good
268approximation of the stack base.  (This enhances code portability on
269HP PA machines, since there is no good way for the collector to
270compute this value.)  Client code may include "gc.h", which defines
271all of the following, plus many others.
272
273 1) `GC_malloc(nbytes)`
274    - Allocate an object of size nbytes.  Unlike malloc, the object is
275      cleared before being returned to the user.  `GC_malloc` will
276      invoke the garbage collector when it determines this to be appropriate.
277      GC_malloc may return 0 if it is unable to acquire sufficient
278      space from the operating system.  This is the most probable
279      consequence of running out of space.  Other possible consequences
280      are that a function call will fail due to lack of stack space,
281      or that the collector will fail in other ways because it cannot
282      maintain its internal data structures, or that a crucial system
283      process will fail and take down the machine.  Most of these
284      possibilities are independent of the malloc implementation.
285
286 2) `GC_malloc_atomic(nbytes)`
287     - Allocate an object of size nbytes that is guaranteed not to contain any
288       pointers.  The returned object is not guaranteed to be cleared.
289       (Can always be replaced by `GC_malloc`, but results in faster collection
290       times.  The collector will probably run faster if large character
291       arrays, etc. are allocated with `GC_malloc_atomic` than if they are
292       statically allocated.)
293
294 3) `GC_realloc(object, new_size)`
295    - Change the size of object to be `new_size`.  Returns a pointer to the
296      new object, which may, or may not, be the same as the pointer to
297      the old object.  The new object is taken to be atomic if and only if the
298      old one was.  If the new object is composite and larger than the original
299      object,then the newly added bytes are cleared (we hope).  This is very
300      likely to allocate a new object, unless `MERGE_SIZES` is defined in
301      gc_priv.h.  Even then, it is likely to recycle the old object only if the
302      object is grown in small additive increments (which, we claim, is
303      generally bad coding practice.)
304
305 4) `GC_free(object)`
306    - Explicitly deallocate an object returned by `GC_malloc` or
307      `GC_malloc_atomic`.  Not necessary, but can be used to minimize
308      collections if performance is critical.  Probably a performance
309      loss for very small objects (<= 8 bytes).
310
311 5) `GC_expand_hp(bytes)`
312     - Explicitly increase the heap size.  (This is normally done automatically
313       if a garbage collection failed to `GC_reclaim` enough memory.  Explicit
314       calls to `GC_expand_hp` may prevent unnecessarily frequent collections at
315       program startup.)
316
317 6) `GC_malloc_ignore_off_page(bytes)`
318     - Identical to `GC_malloc`, but the client promises to keep a pointer to
319       the somewhere within the first 256 bytes of the object while it is
320       live.  (This pointer should normally be declared volatile to prevent
321       interference from compiler optimizations.)  This is the recommended
322       way to allocate anything that is likely to be larger than 100 Kbytes
323       or so.  (`GC_malloc` may result in failure to reclaim such objects.)
324
325 7) `GC_set_warn_proc(proc)`
326     - Can be used to redirect warnings from the collector.  Such warnings
327       should be rare, and should not be ignored during code development.
328
329 8) `GC_enable_incremental()`
330     - Enables generational and incremental collection.  Useful for large
331       heaps on machines that provide access to page dirty information.
332       Some dirty bit implementations may interfere with debugging
333       (by catching address faults) and place restrictions on heap arguments
334       to system calls (since write faults inside a system call may not be
335       handled well).
336
337 9) Several routines to allow for registration of finalization code.
338    User supplied finalization code may be invoked when an object becomes
339    unreachable.  To call `(*f)(obj, x)` when obj becomes inaccessible, use
340    `GC_register_finalizer(obj, f, x, 0, 0);`
341    For more sophisticated uses, and for finalization ordering issues,
342    see gc.h.
343
344The global variable `GC_free_space_divisor` may be adjusted up from it
345default value of 3 to use less space and more collection time, or down for
346the opposite effect.  Setting it to 1 will almost disable collections
347and cause all allocations to simply grow the heap.
348
349The variable `GC_non_gc_bytes`, which is normally 0, may be changed to reflect
350the amount of memory allocated by the above routines that should not be
351considered as a candidate for collection.  Careless use may, of course, result
352in excessive memory consumption.
353
354Some additional tuning is possible through the parameters defined
355near the top of gc_priv.h.
356
357If only `GC_malloc` is intended to be used, it might be appropriate to define:
358
359    #define malloc(n) GC_malloc(n)
360    #define calloc(m,n) GC_malloc((m)*(n))
361
362For small pieces of VERY allocation intensive code, gc_inline.h includes
363some allocation macros that may be used in place of `GC_malloc` and
364friends.
365
366All externally visible names in the garbage collector start with `GC_`.
367To avoid name conflicts, client code should avoid this prefix, except when
368accessing garbage collector routines or variables.
369
370There are provisions for allocation with explicit type information.
371This is rarely necessary.  Details can be found in gc_typed.h.
372
373
374## The C++ Interface to the Allocator
375
376The Ellis-Hull C++ interface to the collector is included in
377the collector distribution.  If you intend to use this, type
378`make c++` after the initial build of the collector is complete.
379See gc_cpp.h for the definition of the interface.  This interface
380tries to approximate the Ellis-Detlefs C++ garbage collection
381proposal without compiler changes.
382
383Very often it will also be necessary to use gc_allocator.h and the
384allocator declared there to construct STL data structures.  Otherwise
385subobjects of STL data structures will be allocated using a system
386allocator, and objects they refer to may be prematurely collected.
387
388
389## Use as Leak Detector
390
391The collector may be used to track down leaks in C programs that are
392intended to run with malloc/free (e.g. code with extreme real-time or
393portability constraints).  To do so define `FIND_LEAK` in Makefile.
394This will cause the collector to invoke the `report_leak`
395routine defined near the top of reclaim.c whenever an inaccessible
396object is found that has not been explicitly freed.  Such objects will
397also be automatically reclaimed.
398
399If all objects are allocated with `GC_DEBUG_MALLOC` (see next section), then
400the default version of report_leak will report at least the source file and
401line number at which the leaked object was allocated.  This may sometimes be
402sufficient.  (On a few machines, it will also report a cryptic stack trace.
403If this is not symbolic, it can sometimes be called into a symbolic stack
404trace by invoking program "foo" with "tools/callprocs.sh foo".  It is a short
405shell script that invokes adb to expand program counter values to symbolic
406addresses.  It was largely supplied by Scott Schwartz.)
407
408Note that the debugging facilities described in the next section can
409sometimes be slightly LESS effective in leak finding mode, since in
410leak finding mode, `GC_debug_free` actually results in reuse of the object.
411(Otherwise the object is simply marked invalid.)  Also note that the test
412program is not designed to run meaningfully in `FIND_LEAK` mode.
413Use "make gc.a" to build the collector.
414
415
416## Debugging Facilities
417
418The routines `GC_debug_malloc`, `GC_debug_malloc_atomic`, `GC_debug_realloc`,
419and `GC_debug_free` provide an alternate interface to the collector, which
420provides some help with memory overwrite errors, and the like.
421Objects allocated in this way are annotated with additional
422information.  Some of this information is checked during garbage
423collections, and detected inconsistencies are reported to stderr.
424
425Simple cases of writing past the end of an allocated object should
426be caught if the object is explicitly deallocated, or if the
427collector is invoked while the object is live.  The first deallocation
428of an object will clear the debugging info associated with an
429object, so accidentally repeated calls to `GC_debug_free` will report the
430deallocation of an object without debugging information.  Out of
431memory errors will be reported to stderr, in addition to returning `NULL`.
432
433`GC_debug_malloc` checking  during garbage collection is enabled
434with the first call to `GC_debug_malloc`.  This will result in some
435slowdown during collections.  If frequent heap checks are desired,
436this can be achieved by explicitly invoking `GC_gcollect`, e.g. from
437the debugger.
438
439`GC_debug_malloc` allocated objects should not be passed to `GC_realloc`
440or `GC_free`, and conversely.  It is however acceptable to allocate only
441some objects with `GC_debug_malloc`, and to use `GC_malloc` for other objects,
442provided the two pools are kept distinct.  In this case, there is a very
443low probability that `GC_malloc` allocated objects may be misidentified as
444having been overwritten.  This should happen with probability at most
445one in 2**32.  This probability is zero if `GC_debug_malloc` is never called.
446
447`GC_debug_malloc`, `GC_malloc_atomic`, and `GC_debug_realloc` take two
448additional trailing arguments, a string and an integer.  These are not
449interpreted by the allocator.  They are stored in the object (the string is
450not copied).  If an error involving the object is detected, they are printed.
451
452The macros `GC_MALLOC`, `GC_MALLOC_ATOMIC`, `GC_REALLOC`, `GC_FREE`, and
453`GC_REGISTER_FINALIZER` are also provided.  These require the same arguments
454as the corresponding (nondebugging) routines.  If gc.h is included
455with `GC_DEBUG` defined, they call the debugging versions of these
456functions, passing the current file name and line number as the two
457extra arguments, where appropriate.  If gc.h is included without `GC_DEBUG`
458defined, then all these macros will instead be defined to their nondebugging
459equivalents.  (`GC_REGISTER_FINALIZER` is necessary, since pointers to
460objects with debugging information are really pointers to a displacement
461of 16 bytes from the object beginning, and some translation is necessary
462when finalization routines are invoked.  For details, about what's stored
463in the header, see the definition of the type oh in dbg_mlc.c file.)
464
465
466## Incremental/Generational Collection
467
468The collector normally interrupts client code for the duration of
469a garbage collection mark phase.  This may be unacceptable if interactive
470response is needed for programs with large heaps.  The collector
471can also run in a "generational" mode, in which it usually attempts to
472collect only objects allocated since the last garbage collection.
473Furthermore, in this mode, garbage collections run mostly incrementally,
474with a small amount of work performed in response to each of a large number of
475`GC_malloc` requests.
476
477This mode is enabled by a call to `GC_enable_incremental`.
478
479Incremental and generational collection is effective in reducing
480pause times only if the collector has some way to tell which objects
481or pages have been recently modified.  The collector uses two sources
482of information:
483
4841. Information provided by the VM system.  This may be provided in
485   one of several forms.  Under Solaris 2.X (and potentially under other
486   similar systems) information on dirty pages can be read from the
487   /proc file system.  Under other systems (currently SunOS4.X) it is
488   possible to write-protect the heap, and catch the resulting faults.
489   On these systems we require that system calls writing to the heap
490   (other than read) be handled specially by client code.
491   See os_dep.c for details.
492
4932. Information supplied by the programmer.  The object is considered dirty
494   after a call to `GC_end_stubborn_change` provided the library has been
495   compiled suitably. It is typically not worth using for short-lived objects.
496   Note that bugs caused by a missing `GC_end_stubborn_change` or
497   `GC_reachable_here` call are likely to be observed very infrequently and
498   hard to trace.
499
500
501## Bugs
502
503Any memory that does not have a recognizable pointer to it will be
504reclaimed.  Exclusive-or'ing forward and backward links in a list
505doesn't cut it.
506
507Some C optimizers may lose the last undisguised pointer to a memory
508object as a consequence of clever optimizations.  This has almost
509never been observed in practice.
510
511This is not a real-time collector.  In the standard configuration,
512percentage of time required for collection should be constant across
513heap sizes.  But collection pauses will increase for larger heaps.
514They will decrease with the number of processors if parallel marking
515is enabled.
516
517(On 2007 vintage machines, GC times may be on the order of 5 msecs
518per MB of accessible memory that needs to be scanned and processed.
519Your mileage may vary.)  The incremental/generational collection facility
520may help in some cases.
521
522
523## Feedback, Contribution, Questions and Notifications
524
525Please address bug reports and new feature ideas to
526[GitHub issues](https://github.com/ivmai/bdwgc/issues).  Before the
527submission please check that it has not been done yet by someone else.
528
529If you want to contribute, submit
530a [pull request](https://github.com/ivmai/bdwgc/pulls) to GitHub.
531
532If you need help, use
533[Stack Overflow](https://stackoverflow.com/questions/tagged/boehm-gc).
534Older technical discussions are available in `bdwgc` mailing list archive - it
535can be downloaded as a
536[compressed file](https://github.com/ivmai/bdwgc/files/1038163/bdwgc-mailing-list-archive-2017_04.tar.gz)
537or browsed at [Narkive](http://bdwgc.opendylan.narkive.com).
538
539To get new release announcements, subscribe to
540[RSS feed](https://github.com/ivmai/bdwgc/releases.atom).
541(To receive the notifications by email, a 3rd-party free service like
542[IFTTT RSS Feed](https://ifttt.com/feed) can be setup.)
543To be notified on all issues, please
544[watch](https://github.com/ivmai/bdwgc/watchers) the project on
545GitHub.
546
547
548## Copyright & Warranty
549
550 * Copyright (c) 1988, 1989 Hans-J. Boehm, Alan J. Demers
551 * Copyright (c) 1991-1996 by Xerox Corporation.  All rights reserved.
552 * Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
553 * Copyright (c) 1999-2011 by Hewlett-Packard Development Company.
554 * Copyright (c) 2008-2019 Ivan Maidanski
555
556The files pthread_stop_world.c, pthread_support.c and some others are also
557
558 * Copyright (c) 1998 by Fergus Henderson.  All rights reserved.
559
560The file include/gc.h is also
561
562 * Copyright (c) 2007 Free Software Foundation, Inc
563
564The files Makefile.am and configure.ac are
565
566 * Copyright (c) 2001 by Red Hat Inc. All rights reserved.
567
568The files extra/msvc_dbg.c and include/private/msvc_dbg.h are
569
570 * Copyright (c) 2004-2005 Andrei Polushin
571
572The file tests/initsecondarythread.c is
573
574 * Copyright (c) 2011 Ludovic Courtes
575
576The file tests/disclaim_weakmap_test.c is
577
578 * Copyright (c) 2018 Petter A. Urkedal
579
580Several files supporting GNU-style builds are copyrighted by the Free
581Software Foundation, and carry a different license from that given
582below.
583
584THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
585OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
586
587Permission is hereby granted to use or copy this program
588for any purpose,  provided the above notices are retained on all copies.
589Permission to modify the code and to distribute modified code is granted,
590provided the above notices are retained, and a notice that the code was
591modified is included with the above copyright notice.
592
593A few of the files needed to use the GNU-style build procedure come with
594slightly different licenses, though they are all similar in spirit.  A few
595are GPL'ed, but with an exception that should cover all uses in the
596collector. (If you are concerned about such things, I recommend you look
597at the notice in config.guess or ltmain.sh.)
598