1 Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
2 Copyright (c) 1991-1996 by Xerox Corporation. All rights reserved.
3 Copyright (c) 1996-1998 by Silicon Graphics. All rights reserved.
5 [ This version of the collector modified by Cygnus Solutions.
6 See the file ChangeLog for details ]
8 THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
11 Permission is hereby granted to use or copy this program
12 for any purpose, provided the above notices are retained on all copies.
13 Permission to modify the code and to distribute modified code is granted,
14 provided the above notices are retained, and a notice that the code was
15 modified is included with the above copyright notice.
17 This is version 4.13alpha2 of a conservative garbage collector for C and C++.
19 You might find a more recent version of this at
21 http://reality.sgi.com/boehm/gc.html
25 Early versions of this collector were developed as a part of research
26 projects supported in part by the National Science Foundation
27 and the Defense Advance Research Projects Agency.
28 Much of the code was rewritten by Hans-J. Boehm at Xerox PARC.
29 The SPARC specific code was contributed by Mark Weiser
30 (weiser@parc.xerox.com). The Encore Multimax modifications were supplied by
31 Kevin Kenny (kenny@m.cs.uiuc.edu). The adaptation to the RT is largely due
32 to Vernon Lee (scorpion@rice.edu), on machines made available by IBM.
33 Much of the HP specific code and a number of good suggestions for improving the
34 generic code are due to Walter Underwood (wunder@hp-ses.sde.hp.com).
35 Robert Brazile (brazile@diamond.bbn.com) originally supplied the ULTRIX code.
36 Al Dosser (dosser@src.dec.com) and Regis Cridlig (Regis.Cridlig@cl.cam.ac.uk)
37 subsequently provided updates and information on variation between ULTRIX
38 systems. Parag Patel (parag@netcom.com) supplied the A/UX code.
39 Jesper Peterson(jep@mtiame.mtia.oz.au) and
40 Michel Schinz supplied the Amiga port.
41 Thomas Funke (thf@zelator.in-berlin.de(?)) and
42 Brian D.Carlstrom (bdc@clark.lcs.mit.edu) supplied the NeXT ports.
43 Douglas Steel (doug@wg.icl.co.uk) provided ICL DRS6000 code.
44 Bill Janssen (janssen@parc.xerox.com) supplied the SunOS dynamic loader
45 specific code. Manuel Serrano (serrano@cornas.inria.fr) supplied linux and
46 Sony News specific code. Al Dosser provided Alpha/OSF/1 code. He and
47 Dave Detlefs(detlefs@src.dec.com) also provided several generic bug fixes.
48 Alistair G. Crooks(agc@uts.amdahl.com) supplied the NetBSD and 386BSD ports.
49 Jeffrey Hsu (hsu@soda.berkeley.edu) provided the FreeBSD port.
50 Brent Benson (brent@jade.ssd.csd.harris.com) ported the collector to
51 a Motorola 88K processor running CX/UX (Harris NightHawk).
52 Ari Huttunen (Ari.Huttunen@hut.fi) generalized the OS/2 port to
53 nonIBM development environments (a nontrivial task).
54 Patrick Beard (beard@cs.ucdavis.edu) provided the initial MacOS port.
55 David Chase, then at Olivetti Research, suggested several improvements.
56 Scott Schwartz (schwartz@groucho.cse.psu.edu) supplied some of the
57 code to save and print call stacks for leak detection on a SPARC.
58 Jesse Hull and John Ellis supplied the C++ interface code.
59 Zhong Shao performed much of the experimentation that led to the
60 current typed allocation facility. (His dynamic type inference code hasn't
61 made it into the released version of the collector, yet.)
62 (Blame for misinstallation of these modifications goes to the first author,
65 Credits for some more recent modifications are given in the modification
66 history at the end of this file.
68 This is intended to be a general purpose, garbage collecting storage
69 allocator. The algorithms used are described in:
71 Boehm, H., and M. Weiser, "Garbage Collection in an Uncooperative Environment",
72 Software Practice & Experience, September 1988, pp. 807-820.
74 Boehm, H., A. Demers, and S. Shenker, "Mostly Parallel Garbage Collection",
75 Proceedings of the ACM SIGPLAN '91 Conference on Programming Language Design
76 and Implementation, SIGPLAN Notices 26, 6 (June 1991), pp. 157-164.
78 Boehm, H., "Space Efficient Conservative Garbage Collection", Proceedings
79 of the ACM SIGPLAN '91 Conference on Programming Language Design and
80 Implementation, SIGPLAN Notices 28, 6 (June 1993), pp. 197-206.
82 Possible interactions between the collector and optimizing compilers are
85 Boehm, H., and D. Chase, "A Proposal for GC-safe C Compilation",
86 The Journal of C Language Translation 4, 2 (December 1992).
90 Boehm H., "Simple GC-safe Compilation", Proceedings
91 of the ACM SIGPLAN '96 Conference on Programming Language Design and
94 (Both are also available from
95 http://reality.sgi.com/employees/boehm_mti/papers/, among other places.)
97 Unlike the collector described in the second reference, this collector
98 operates either with the mutator stopped during the entire collection
99 (default) or incrementally during allocations. (The latter is supported
100 on only a few machines.) It does not rely on threads, but is intended
103 Some of the ideas underlying the collector have previously been explored
104 by others. (Doug McIlroy wrote a vaguely similar collector that is part of
105 version 8 UNIX (tm).) However none of this work appears to have been widely
108 Rudimentary tools for use of the collector as a leak detector are included, as
109 is a fairly sophisticated string package "cord" that makes use of the collector.
115 This is a garbage collecting storage allocator that is intended to be
116 used as a plug-in replacement for C's malloc.
118 Since the collector does not require pointers to be tagged, it does not
119 attempt to ensure that all inaccessible storage is reclaimed. However,
120 in our experience, it is typically more successful at reclaiming unused
121 memory than most C programs using explicit deallocation. Unlike manually
122 introduced leaks, the amount of unreclaimed memory typically stays
125 In the following, an "object" is defined to be a region of memory allocated
126 by the routines described below.
128 Any objects not intended to be collected must be pointed to either
129 from other such accessible objects, or from the registers,
130 stack, data, or statically allocated bss segments. Pointers from
131 the stack or registers may point to anywhere inside an object.
132 The same is true for heap pointers if the collector is compiled with
133 ALL_INTERIOR_POINTERS defined, as is now the default.
135 Compiling without ALL_INTERIOR_POINTERS may reduce accidental retention
136 of garbage objects, by requiring pointers from the heap to to the beginning
137 of an object. But this no longer appears to be a significant
138 issue for most programs.
140 There are a number of routines which modify the pointer recognition
141 algorithm. GC_register_displacement allows certain interior pointers
142 to be recognized even if ALL_INTERIOR_POINTERS is nor defined.
143 GC_malloc_ignore_off_page allows some pointers into the middle of large objects
144 to be disregarded, greatly reducing the probablility of accidental
145 retention of large objects. For most purposes it seems best to compile
146 with ALL_INTERIOR_POINTERS and to use GC_malloc_ignore_off_page if
147 you get collector warnings from allocations of very large objects.
148 See README.debugging for details.
150 Note that pointers inside memory allocated by the standard "malloc" are not
151 seen by the garbage collector. Thus objects pointed to only from such a
152 region may be prematurely deallocated. It is thus suggested that the
153 standard "malloc" be used only for memory regions, such as I/O buffers, that
154 are guaranteed not to contain pointers to garbage collectable memory.
155 Pointers in C language automatic, static, or register variables,
156 are correctly recognized. (Note that GC_malloc_uncollectable has semantics
157 similar to standard malloc, but allocates objects that are traced by the
160 The collector does not always know how to find pointers in data
161 areas that are associated with dynamic libraries. This is easy to
162 remedy IF you know how to find those data areas on your operating
163 system (see GC_add_roots). Code for doing this under SunOS, IRIX 5.X and 6.X,
164 HP/UX, Alpha OSF/1, Linux, and win32 is included and used by default. (See
165 README.win32 for win32 details.) On other systems pointers from dynamic
166 library data areas may not be considered by the collector.
168 Note that the garbage collector does not need to be informed of shared
169 read-only data. However if the shared library mechanism can introduce
170 discontiguous data areas that may contain pointers, then the collector does
173 Signal processing for most signals may be deferred during collection,
174 and during uninterruptible parts of the allocation process. Unlike
175 standard ANSI C mallocs, it can be safe to invoke malloc
176 from a signal handler while another malloc is in progress, provided
177 the original malloc is not restarted. (Empirically, many UNIX
178 applications already assume this.) To obtain this level of signal
179 safety, remove the definition of -DNO_SIGNALS in Makefile. This incurs
180 a minor performance penalty, and hence is no longer the default.
182 The allocator/collector can also be configured for thread-safe operation.
183 (Full signal safety can also be achieved, but only at the cost of two system
184 calls per malloc, which is usually unacceptable.)
186 INSTALLATION AND PORTABILITY
188 As distributed, the macro SILENT is defined in Makefile.
189 In the event of problems, this can be removed to obtain a moderate
190 amount of descriptive output for each collection.
191 (The given statistics exhibit a few peculiarities.
192 Things don't appear to add up for a variety of reasons, most notably
193 fragmentation losses. These are probably much more significant for the
194 contrived program "test.c" than for your application.)
196 Note that typing "make test" will automatically build the collector
197 and then run setjmp_test and gctest. Setjmp_test will give you information
198 about configuring the collector, which is useful primarily if you have
199 a machine that's not already supported. Gctest is a somewhat superficial
200 test of collector functionality. Failure is indicated by a core dump or
201 a message to the effect that the collector is broken. Gctest takes about
202 35 seconds to run on a SPARCstation 2. On a slower machine,
203 expect it to take a while. It may use up to 8 MB of memory. (The
204 multi-threaded version will use more.) "Make test" will also, as
205 its last step, attempt to build and test the "cord" string library.
206 This will fail without an ANSI C compiler.
208 The Makefile will generate a library gc.a which you should link against.
209 Typing "make cords" will add the cord library to gc.a.
210 Note that this requires an ANSI C compiler.
212 It is suggested that if you need to replace a piece of the collector
213 (e.g. GC_mark_rts.c) you simply list your version ahead of gc.a on the
215 ld command line, rather than replacing the one in gc.a. (This will
216 generate numerous warnings under some versions of AIX, but it still
219 All include files that need to be used by clients will be put in the
220 include subdirectory. (Normally this is just gc.h. "Make cords" adds
221 "cord.h" and "ec.h".)
223 The collector currently is designed to run essentially unmodified on
224 machines that use a flat 32-bit or 64-bit address space.
225 That includes the vast majority of Workstations and X86 (X >= 3) PCs.
226 (The list here was deleted because it was getting too long and constantly
228 It does NOT run under plain 16-bit DOS or Windows 3.X. There are however
229 various packages (e.g. win32s, djgpp) that allow flat 32-bit address
230 applications to run under those systemsif the have at least an 80386 processor,
231 and several of those are compatible with the collector.
233 In a few cases (Amiga, OS/2, Win32, MacOS) a separate makefile
234 or equivalent is supplied. Many of these have separate README.system
237 Dynamic libraries are completely supported only under SunOS
238 (and even that support is not functional on the last Sun 3 release),
239 IRIX 5&6, HP-PA, Win32 (not Win32S) and OSF/1 on DEC AXP machines.
240 On other machines we recommend that you do one of the following:
242 1) Add dynamic library support (and send us the code).
243 2) Use static versions of the libraries.
244 3) Arrange for dynamic libraries to use the standard malloc.
245 This is still dangerous if the library stores a pointer to a
246 garbage collected object. But nearly all standard interfaces
247 prohibit this, because they deal correctly with pointers
248 to stack allocated objects. (Strtok is an exception. Don't
251 In all cases we assume that pointer alignment is consistent with that
252 enforced by the standard C compilers. If you use a nonstandard compiler
253 you may have to adjust the alignment parameters defined in gc_priv.h.
255 A port to a machine that is not byte addressed, or does not use 32 bit
256 or 64 bit addresses will require a major effort. A port to plain MSDOS
259 For machines not already mentioned, or for nonstandard compilers, the
260 following are likely to require change:
262 1. The parameters in config.h.
263 The parameters that will usually require adjustment are
264 STACKBOTTOM, ALIGNMENT and DATASTART. Setjmp_test
265 prints its guesses of the first two.
266 DATASTART should be an expression for computing the
267 address of the beginning of the data segment. This can often be
268 &etext. But some memory management units require that there be
269 some unmapped space between the text and the data segment. Thus
270 it may be more complicated. On UNIX systems, this is rarely
271 documented. But the adb "$m" command may be helpful. (Note
272 that DATASTART will usually be a function of &etext. Thus a
273 single experiment is usually insufficient.)
274 STACKBOTTOM is used to initialize GC_stackbottom, which
275 should be a sufficient approximation to the coldest stack address.
276 On some machines, it is difficult to obtain such a value that is
277 valid across a variety of MMUs, OS releases, etc. A number of
278 alternatives exist for using the collector in spite of this. See the
279 discussion in config.h immediately preceding the various
280 definitions of STACKBOTTOM.
283 The most important routine here is one to mark from registers.
284 The distributed file includes a generic hack (based on setjmp) that
285 happens to work on many machines, and may work on yours. Try
286 compiling and running setjmp_t.c to see whether it has a chance of
287 working. (This is not correct C, so don't blame your compiler if it
288 doesn't work. Based on limited experience, register window machines
289 are likely to cause trouble. If your version of setjmp claims that
290 all accessible variables, including registers, have the value they
291 had at the time of the longjmp, it also will not work. Vanilla 4.2 BSD
292 on Vaxen makes such a claim. SunOS does not.)
293 If your compiler does not allow in-line assembly code, or if you prefer
294 not to use such a facility, mach_dep.c may be replaced by a .s file
295 (as we did for the MIPS machine and the PC/RT).
296 At this point enough architectures are supported by mach_dep.c
297 that you will rarely need to do more than adjust for assembler
300 3. os_dep.c (and gc_priv.h).
301 Several kinds of operating system dependent routines reside here.
302 Many are optional. Several are invoked only through corresponding
303 macros in gc_priv.h, which may also be redefined as appropriate.
304 The routine GC_register_data_segments is crucial. It registers static
305 data areas that must be traversed by the collector. (User calls to
306 GC_add_roots may sometimes be used for similar effect.)
307 Routines to obtain memory from the OS also reside here.
308 Alternatively this can be done entirely by the macro GET_MEM
309 defined in gc_priv.h. Routines to disable and reenable signals
310 also reside here if they are need by the macros DISABLE_SIGNALS
311 and ENABLE_SIGNALS defined in gc_priv.h.
312 In a multithreaded environment, the macros LOCK and UNLOCK
313 in gc_priv.h will need to be suitably redefined.
314 The incremental collector requires page dirty information, which
315 is acquired through routines defined in os_dep.c. Unless directed
316 otherwise by config.h, these are implemented as stubs that simply
317 treat all pages as dirty. (This of course makes the incremental
318 collector much less useful.)
321 This provides a routine that allows the collector to scan data
322 segments associated with dynamic libraries. Often it is not
323 necessary to provide this routine unless user-written dynamic
326 For a different version of UN*X or different machines using the
327 Motorola 68000, Vax, SPARC, 80386, NS 32000, PC/RT, or MIPS architecture,
328 it should frequently suffice to change definitions in config.h.
331 THE C INTERFACE TO THE ALLOCATOR
333 The following routines are intended to be directly called by the user.
334 Note that usually only GC_malloc is necessary. GC_clear_roots and GC_add_roots
335 calls may be required if the collector has to trace from nonstandard places
336 (e.g. from dynamic library data areas on a machine on which the
337 collector doesn't already understand them.) On some machines, it may
338 be desirable to set GC_stacktop to a good approximation of the stack base.
339 (This enhances code portability on HP PA machines, since there is no
340 good way for the collector to compute this value.) Client code may include
341 "gc.h", which defines all of the following, plus many others.
344 - allocate an object of size nbytes. Unlike malloc, the object is
345 cleared before being returned to the user. Gc_malloc will
346 invoke the garbage collector when it determines this to be appropriate.
347 GC_malloc may return 0 if it is unable to acquire sufficient
348 space from the operating system. This is the most probable
349 consequence of running out of space. Other possible consequences
350 are that a function call will fail due to lack of stack space,
351 or that the collector will fail in other ways because it cannot
352 maintain its internal data structures, or that a crucial system
353 process will fail and take down the machine. Most of these
354 possibilities are independent of the malloc implementation.
356 2) GC_malloc_atomic(nbytes)
357 - allocate an object of size nbytes that is guaranteed not to contain any
358 pointers. The returned object is not guaranteed to be cleared.
359 (Can always be replaced by GC_malloc, but results in faster collection
360 times. The collector will probably run faster if large character
361 arrays, etc. are allocated with GC_malloc_atomic than if they are
362 statically allocated.)
364 3) GC_realloc(object, new_size)
365 - change the size of object to be new_size. Returns a pointer to the
366 new object, which may, or may not, be the same as the pointer to
367 the old object. The new object is taken to be atomic iff the old one
368 was. If the new object is composite and larger than the original object,
369 then the newly added bytes are cleared (we hope). This is very likely
370 to allocate a new object, unless MERGE_SIZES is defined in gc_priv.h.
371 Even then, it is likely to recycle the old object only if the object
372 is grown in small additive increments (which, we claim, is generally bad
376 - explicitly deallocate an object returned by GC_malloc or
377 GC_malloc_atomic. Not necessary, but can be used to minimize
378 collections if performance is critical. Probably a performance
379 loss for very small objects (<= 8 bytes).
381 5) GC_expand_hp(bytes)
382 - Explicitly increase the heap size. (This is normally done automatically
383 if a garbage collection failed to GC_reclaim enough memory. Explicit
384 calls to GC_expand_hp may prevent unnecessarily frequent collections at
387 6) GC_malloc_ignore_off_page(bytes)
388 - identical to GC_malloc, but the client promises to keep a pointer to
389 the somewhere within the first 256 bytes of the object while it is
390 live. (This pointer should nortmally be declared volatile to prevent
391 interference from compiler optimizations.) This is the recommended
392 way to allocate anything that is likely to be larger than 100Kbytes
393 or so. (GC_malloc may result in failure to reclaim such objects.)
395 7) GC_set_warn_proc(proc)
396 - Can be used to redirect warnings from the collector. Such warnings
397 should be rare, and should not be ignored during code development.
399 8) GC_enable_incremental()
400 - Enables generational and incremental collection. Useful for large
401 heaps on machines that provide access to page dirty information.
402 Some dirty bit implementations may interfere with debugging
403 (by catching address faults) and place restrictions on heap arguments
404 to system calls (since write faults inside a system call may not be
407 9) Several routines to allow for registration of finalization code.
408 User supplied finalization code may be invoked when an object becomes
409 unreachable. To call (*f)(obj, x) when obj becomes inaccessible, use
410 GC_register_finalizer(obj, f, x, 0, 0);
411 For more sophisticated uses, and for finalization ordering issues,
414 The global variable GC_free_space_divisor may be adjusted up from its
415 default value of 4 to use less space and more collection time, or down for
416 the opposite effect. Setting it to 1 or 0 will effectively disable collections
417 and cause all allocations to simply grow the heap.
419 The variable GC_non_gc_bytes, which is normally 0, may be changed to reflect
420 the amount of memory allocated by the above routines that should not be
421 considered as a candidate for collection. Careless use may, of course, result
422 in excessive memory consumption.
424 Some additional tuning is possible through the parameters defined
425 near the top of gc_priv.h.
427 If only GC_malloc is intended to be used, it might be appropriate to define:
429 #define malloc(n) GC_malloc(n)
430 #define calloc(m,n) GC_malloc((m)*(n))
432 For small pieces of VERY allocation intensive code, gc_inl.h
433 includes some allocation macros that may be used in place of GC_malloc
436 All externally visible names in the garbage collector start with "GC_".
437 To avoid name conflicts, client code should avoid this prefix, except when
438 accessing garbage collector routines or variables.
440 There are provisions for allocation with explicit type information.
441 This is rarely necessary. Details can be found in gc_typed.h.
443 THE C++ INTERFACE TO THE ALLOCATOR:
445 The Ellis-Hull C++ interface to the collector is included in
446 the collector distribution. If you intend to use this, type
447 "make c++" after the initial build of the collector is complete.
448 See gc_cpp.h for the definition of the interface. This interface
449 tries to approximate the Ellis-Detlefs C++ garbage collection
450 proposal without compiler changes.
453 1. Arrays allocated without new placement syntax are
454 allocated as uncollectable objects. They are traced by the
455 collector, but will not be reclaimed.
457 2. Failure to use "make c++" in combination with (1) will
458 result in arrays allocated using the default new operator.
459 This is likely to result in disaster without linker warnings.
461 3. If your compiler supports an overloaded new[] operator,
462 then gc_cpp.cc and gc_cpp.h should be suitably modified.
464 4. Many current C++ compilers have deficiencies that
465 break some of the functionality. See the comments in gc_cpp.h
466 for suggested workarounds.
468 USE AS LEAK DETECTOR:
470 The collector may be used to track down leaks in C programs that are
471 intended to run with malloc/free (e.g. code with extreme real-time or
472 portability constraints). To do so define FIND_LEAK in Makefile
473 This will cause the collector to invoke the report_leak
474 routine defined near the top of reclaim.c whenever an inaccessible
475 object is found that has not been explicitly freed. The collector will
476 no longer reclaim inaccessible memory; in this form it is purely a
478 Productive use of this facility normally involves redefining report_leak
479 to do something more intelligent. This typically requires annotating
480 objects with additional information (e.g. creation time stack trace) that
481 identifies their origin. Such code is typically not very portable, and is
482 not included here, except on SPARC machines.
483 If all objects are allocated with GC_DEBUG_MALLOC (see next section),
484 then the default version of report_leak will report the source file
485 and line number at which the leaked object was allocated. This may
486 sometimes be sufficient. (On SPARC/SUNOS4 machines, it will also report
487 a cryptic stack trace. This can often be turned into a sympolic stack
488 trace by invoking program "foo" with "callprocs foo". Callprocs is
489 a short shell script that invokes adb to expand program counter values
490 to symbolic addresses. It was largely supplied by Scott Schwartz.)
491 Note that the debugging facilities described in the next section can
492 sometimes be slightly LESS effective in leak finding mode, since in
493 leak finding mode, GC_debug_free actually results in reuse of the object.
494 (Otherwise the object is simply marked invalid.) Also note that the test
495 program is not designed to run meaningfully in FIND_LEAK mode.
496 Use "make gc.a" to build the collector.
498 DEBUGGING FACILITIES:
500 The routines GC_debug_malloc, GC_debug_malloc_atomic, GC_debug_realloc,
501 and GC_debug_free provide an alternate interface to the collector, which
502 provides some help with memory overwrite errors, and the like.
503 Objects allocated in this way are annotated with additional
504 information. Some of this information is checked during garbage
505 collections, and detected inconsistencies are reported to stderr.
507 Simple cases of writing past the end of an allocated object should
508 be caught if the object is explicitly deallocated, or if the
509 collector is invoked while the object is live. The first deallocation
510 of an object will clear the debugging info associated with an
511 object, so accidentally repeated calls to GC_debug_free will report the
512 deallocation of an object without debugging information. Out of
513 memory errors will be reported to stderr, in addition to returning
516 GC_debug_malloc checking during garbage collection is enabled
517 with the first call to GC_debug_malloc. This will result in some
518 slowdown during collections. If frequent heap checks are desired,
519 this can be achieved by explicitly invoking GC_gcollect, e.g. from
522 GC_debug_malloc allocated objects should not be passed to GC_realloc
523 or GC_free, and conversely. It is however acceptable to allocate only
524 some objects with GC_debug_malloc, and to use GC_malloc for other objects,
525 provided the two pools are kept distinct. In this case, there is a very
526 low probablility that GC_malloc allocated objects may be misidentified as
527 having been overwritten. This should happen with probability at most
528 one in 2**32. This probability is zero if GC_debug_malloc is never called.
530 GC_debug_malloc, GC_malloc_atomic, and GC_debug_realloc take two
531 additional trailing arguments, a string and an integer. These are not
532 interpreted by the allocator. They are stored in the object (the string is
533 not copied). If an error involving the object is detected, they are printed.
535 The macros GC_MALLOC, GC_MALLOC_ATOMIC, GC_REALLOC, GC_FREE, and
536 GC_REGISTER_FINALIZER are also provided. These require the same arguments
537 as the corresponding (nondebugging) routines. If gc.h is included
538 with GC_DEBUG defined, they call the debugging versions of these
539 functions, passing the current file name and line number as the two
540 extra arguments, where appropriate. If gc.h is included without GC_DEBUG
541 defined, then all these macros will instead be defined to their nondebugging
542 equivalents. (GC_REGISTER_FINALIZER is necessary, since pointers to
543 objects with debugging information are really pointers to a displacement
544 of 16 bytes form the object beginning, and some translation is necessary
545 when finalization routines are invoked. For details, about what's stored
546 in the header, see the definition of the type oh in debug_malloc.c)
548 INCREMENTAL/GENERATIONAL COLLECTION:
550 The collector normally interrupts client code for the duration of
551 a garbage collection mark phase. This may be unacceptable if interactive
552 response is needed for programs with large heaps. The collector
553 can also run in a "generational" mode, in which it usually attempts to
554 collect only objects allocated since the last garbage collection.
555 Furthermore, in this mode, garbage collections run mostly incrementally,
556 with a small amount of work performed in response to each of a large number of
559 This mode is enabled by a call to GC_enable_incremental().
561 Incremental and generational collection is effective in reducing
562 pause times only if the collector has some way to tell which objects
563 or pages have been recently modified. The collector uses two sources
566 1. Information provided by the VM system. This may be provided in
567 one of several forms. Under Solaris 2.X (and potentially under other
568 similar systems) information on dirty pages can be read from the
569 /proc file system. Under other systems (currently SunOS4.X) it is
570 possible to write-protect the heap, and catch the resulting faults.
571 On these systems we require that system calls writing to the heap
572 (other than read) be handled specially by client code.
573 See os_dep.c for details.
575 2. Information supplied by the programmer. We define "stubborn"
576 objects to be objects that are rarely changed. Such an object
577 can be allocated (and enabled for writing) with GC_malloc_stubborn.
578 Once it has been initialized, the collector should be informed with
579 a call to GC_end_stubborn_change. Subsequent writes that store
580 pointers into the object must be preceded by a call to
583 This mechanism performs best for objects that are written only for
584 initialization, and such that only one stubborn object is writable
585 at once. It is typically not worth using for short-lived
586 objects. Stubborn objects are treated less efficiently than pointerfree
589 A rough rule of thumb is that, in the absence of VM information, garbage
590 collection pauses are proportional to the amount of pointerful storage
591 plus the amount of modified "stubborn" storage that is reachable during
594 Initial allocation of stubborn objects takes longer than allocation
595 of other objects, since other data structures need to be maintained.
597 We recommend against random use of stubborn objects in client
598 code, since bugs caused by inappropriate writes to stubborn objects
599 are likely to be very infrequently observed and hard to trace.
600 However, their use may be appropriate in a few carefully written
601 library routines that do not make the objects themselves available
602 for writing by client code.
607 Any memory that does not have a recognizable pointer to it will be
608 reclaimed. Exclusive-or'ing forward and backward links in a list
610 Some C optimizers may lose the last undisguised pointer to a memory
611 object as a consequence of clever optimizations. This has almost
612 never been observed in practice. Send mail to boehm@mti.sgi.com
613 for suggestions on how to fix your compiler.
614 This is not a real-time collector. In the standard configuration,
615 percentage of time required for collection should be constant across
616 heap sizes. But collection pauses will increase for larger heaps.
617 (On SPARCstation 2s collection times will be on the order of 300 msecs
618 per MB of accessible memory that needs to be scanned. Your mileage
619 may vary.) The incremental/generational collection facility helps,
620 but is portable only if "stubborn" allocation is used.
621 Please address bug reports to boehm@mti.sgi.com. If you are
622 contemplating a major addition, you might also send mail to ask whether
623 it's already been done (or whether we tried and discarded it).
627 Version 1.3 and immediately preceding versions contained spurious
628 assembly language assignments to TMP_SP. Only the assignment in the PC/RT
629 code is necessary. On other machines, with certain compiler options,
630 the assignments can lead to an unsaved register being overwritten.
631 Known to cause problems under SunOS 3.5 WITHOUT the -O option. (With
632 -O the compiler recognizes it as dead code. It probably shouldn't,
633 but that's another story.)
635 Version 1.4 and earlier versions used compile time determined values
636 for the stack base. This no longer works on Sun 3s, since Sun 3/80s use
637 a different stack base. We now use a straightforward heuristic on all
638 machines on which it is known to work (incl. Sun 3s) and compile-time
639 determined values for the rest. There should really be library calls
640 to determine such values.
642 Version 1.5 and earlier did not ensure 8 byte alignment for objects
643 allocated on a sparc based machine.
645 Version 1.8 added ULTRIX support in gc_private.h.
647 Version 1.9 fixed a major bug in gc_realloc.
649 Version 2.0 introduced a consistent naming convention for collector
650 routines and added support for registering dynamic library data segments
651 in the standard mark_roots.c. Most of the data structures were revamped.
652 The treatment of interior pointers was completely changed. Finalization
653 was added. Support for locking was added. Object kinds were added.
654 We added a black listing facility to avoid allocating at addresses known
655 to occur as integers somewhere in the address space. Much of this
656 was accomplished by adapting ideas and code from the PCR collector.
657 The test program was changed and expanded.
659 Version 2.1 was the first stable version since 1.9, and added support
662 Version 2.2 added debugging allocation, and fixed various bugs. Among them:
663 - GC_realloc could fail to extend the size of the object for certain large object sizes.
664 - A blatant subscript range error in GC_printf, which unfortunately
665 wasn't exercised on machines with sufficient stack alignment constraints.
666 - GC_register_displacement did the wrong thing if it was called after
667 any allocation had taken place.
668 - The leak finding code would eventually break after 2048 byte
670 - interface.c didn't compile.
671 - The heap size remained much too small for large stacks.
672 - The stack clearing code behaved badly for large stacks, and perhaps
675 Version 2.3 added ALL_INTERIOR_POINTERS and fixed the following bugs:
676 - Missing declaration of etext in the A/UX version.
677 - Some PCR root-finding problems.
678 - Blacklisting was not 100% effective, because the plausible future
679 heap bounds were being miscalculated.
680 - GC_realloc didn't handle out-of-memory correctly.
681 - GC_base could return a nonzero value for addresses inside free blocks.
682 - test.c wasn't really thread safe, and could erroneously report failure
683 in a multithreaded environment. (The locking primitives need to be
684 replaced for other threads packages.)
685 - GC_CONS was thoroughly broken.
686 - On a SPARC with dynamic linking, signals stayed diabled while the
687 client code was running.
688 (Thanks to Manuel Serrano at INRIA for reporting the last two.)
690 Version 2.4 added GC_free_space_divisor as a tuning knob, added
691 support for OS/2 and linux, and fixed the following bugs:
692 - On machines with unaligned pointers (e.g. Sun 3), every 128th word could
693 fail to be considered for marking.
694 - Dynamic_load.c erroneously added 4 bytes to the length of the data and
695 bss sections of the dynamic library. This could result in a bad memory
696 reference if the actual length was a multiple of a page. (Observed on
697 Sun 3. Can probably also happen on a Sun 4.)
698 (Thanks to Robert Brazile for pointing out that the Sun 3 version
699 was broken. Dynamic library handling is still broken on Sun 3s
700 under 4.1.1U1, but apparently not 4.1.1. If you have such a machine,
703 Version 2.5 fixed the following bugs:
704 - Removed an explicit call to exit(1)
705 - Fixed calls to GC_printf and GC_err_printf, so the correct number of
706 arguments are always supplied. The OS/2 C compiler gets confused if
707 the number of actuals and the number of formals differ. (ANSI C
708 doesn't require this to work. The ANSI sanctioned way of doing things
709 causes too many compatibility problems.)
711 Version 3.0 added generational/incremental collection and stubborn
714 Version 3.1 added the following features:
715 - A workaround for a SunOS 4.X SPARC C compiler
716 misfeature that caused problems when the collector was turned into
718 - A fix for a bug in GC_base that could result in a memory fault.
719 - A fix for a performance bug (and several other misfeatures) pointed
720 out by Dave Detlefs and Al Dosser.
721 - Use of dirty bit information for static data under Solaris 2.X.
722 - DEC Alpha/OSF1 support (thanks to Al Dosser).
723 - Incremental collection on more platforms.
724 - A more refined heap expansion policy. Less space usage by default.
725 - Various minor enhancements to reduce space usage, and to reduce
726 the amount of memory scanned by the collector.
727 - Uncollectable allocation without per object overhead.
728 - More conscientious handling of out-of-memory conditions.
729 - Fixed a bug in debugging stubborn allocation.
730 - Fixed a bug that resulted in occasional erroneous reporting of smashed
731 objects with debugging allocation.
732 - Fixed bogus leak reports of size 4096 blocks with FIND_LEAK.
734 Version 3.2 fixed a serious and not entirely repeatable bug in
735 the incremental collector. It appeared only when dirty bit info
736 on the roots was available, which is normally only under Solaris.
737 It also added GC_general_register_disappearing_link, and some
738 testing code. Interface.c disappeared.
740 Version 3.3 fixes several bugs and adds new ports:
742 - Missing locking in GC_free, redundant FASTUNLOCK
743 in GC_malloc_stubborn, and 2 bugs in
744 GC_unregister_disappearing_link.
745 All of the above were pointed out by Neil Sharman
747 - Common symbols allocated by the SunOS4.X dynamic loader
748 were not included in the root set.
749 - Bug in GC_finalize (reported by Brian Beuning and Al Dosser)
750 - Merged Amiga port from Jesper Peterson (untested)
751 - Merged NeXT port from Thomas Funke (significantly
752 modified and untested)
755 - Fixed a performance bug in GC_realloc.
756 - Updated the amiga port.
757 - Added NetBSD and 386BSD ports.
758 - Added cord library.
759 - Added trivial performance enhancement for
760 ALL_INTERIOR_POINTERS. (Don't scan last word.)
763 - Minor collections now mark from roots only once, if that
764 doesn't cause an excessive pause.
765 - The stack clearing heuristic was refined to prevent anomalies
766 with very heavily recursive programs and sparse stacks.
767 - Fixed a bug that prevented mark stack growth in some cases.
768 GC_objects_are_marked should be set to TRUE after a call
769 to GC_push_roots and as part of GC_push_marked, since
770 both can now set mark bits. I think this is only a performance
771 bug, but I wouldn't bet on it. It's certainly very hard to argue
772 that the old version was correct.
773 - Fixed an incremental collection bug that prevented it from
774 working at all when HBLKSIZE != getpagesize()
775 - Changed dynamic_loading.c to include gc_priv.h before testing
776 DYNAMIC_LOADING. SunOS dynamic library scanning
777 must have been broken in 3.4.
778 - Object size rounding now adapts to program behavior.
779 - Added a workaround (provided by Manuel Serrano and
780 colleagues) to a long-standing SunOS 4.X (and 3.X?) ld bug
781 that I had incorrectly assumed to have been squished.
782 The collector was broken if the text segment size was within
783 32 bytes of a multiple of 8K bytes, and if the beginning of
784 the data segment contained interesting roots. The workaround
785 assumes a demand-loadable executable. The original may have
786 have "worked" in some other cases.
787 - Added dynamic library support under IRIX5.
788 - Added support for EMX under OS/2 (thanks to Ari Huttunen).
791 - fixed a bug in the mark stack growth code that was introduced
793 - fixed Makefile to work around DEC AXP compiler tail recursion
797 - Added a workaround for an HP/UX compiler bug.
798 - Fixed another stack clearing performance bug. Reworked
802 - Added support for Solaris threads (which was possible
803 only by reimplementing some fraction of Solaris threads,
804 since Sun doesn't currently make the thread debugging
805 interface available).
806 - Added non-threads win32 and win32S support.
807 - (Grudgingly, with suitable muttering of obscenities) renamed
808 files so that the collector distribution could live on a FAT
809 file system. Files that are guaranteed to be useless on
810 a PC still have long names. Gc_inline.h and gc_private.h
811 still exist, but now just include gc_inl.h and gc_priv.h.
812 - Fixed a really obscure bug in finalization that could cause
813 undetected mark stack overflows. (I would be surprised if
814 any real code ever tickled this one.)
815 - Changed finalization code to dynamically resize the hash
816 tables it maintains. (This probably does not matter for well-
817 -written code. It no doubt does for C++ code that overuses
819 - Added typed allocation primitives. Rewrote the marker to
820 accommodate them with more reasonable efficiency. This
821 change should also speed up marking for GC_malloc allocated
822 objects a little. See gc_typed.h for new primitives.
823 - Improved debugging facilities slightly. Allocation time
824 stack traces are now kept by default on SPARC/SUNOS4.
825 (Thanks to Scott Schwartz.)
826 - Added better support for small heap applications.
827 - Significantly extended cord package. Fixed a bug in the
828 implementation of lazily read files. Printf and friends now
829 have cord variants. Cord traversals are a bit faster.
830 - Made ALL_INTERIOR_POINTERS recognition the default.
831 - Fixed de so that it can run in constant space, independent
832 of file size. Added simple string searching to cords and de.
833 - Added the Hull-Ellis C++ interface.
834 - Added dynamic library support for OSF/1.
835 (Thanks to Al Dosser and Tim Bingham at DEC.)
836 - Changed argument to GC_expand_hp to be expressed
837 in units of bytes instead of heap blocks. (Necessary
838 since the heap block size now varies depending on
839 configuration. The old version was never very clean.)
840 - Added GC_get_heap_size(). The previous "equivalent"
842 - Restructured the Makefile a bit.
845 - Changed finalization implementation to guarantee that
846 finalization procedures are called outside of the allocation
847 lock, making direct use of the interface a little less dangerous.
848 MAY BREAK EXISTING CLIENTS that assume finalizers
849 are protected by a lock. Since there seem to be few multithreaded
850 clients that use finalization, this is hopefully not much of
852 - Fixed a gross bug in CORD_prev.
853 - Fixed a bug in blacklst.c that could result in unbounded
854 heap growth during startup on machines that do not clear
855 memory obtained from the OS (e.g. win32S).
856 - Ported de editor to win32/win32S. (This is now the only
857 version with a mouse-sensitive UI.)
858 - Added GC_malloc_ignore_off_page to allocate large arrays
859 in the presence of ALL_INTERIOR_POINTERS.
860 - Changed GC_call_with_alloc_lock to not disable signals in
861 the single-threaded case.
862 - Reduced retry count in GC_collect_or_expand for garbage
863 collecting when out of memory.
864 - Made uncollectable allocations bypass black-listing, as they
866 - Fixed a bug in typed_test in test.c that could cause (legitimate)
868 - Fixed some potential synchronization problems in finalize.c
869 - Fixed a real locking problem in typd_mlc.c.
870 - Worked around an AIX 3.2 compiler feature that results in
871 out of bounds memory references.
872 - Partially worked around an IRIX5.2 beta problem (which may
873 or may not persist to the final release).
874 - Fixed a bug in the heap integrity checking code that could
875 result in explicitly deallocated objects being identified as
876 smashed. Fixed a bug in the dbg_mlc stack saving code
877 that caused old argument pointers to be considered live.
878 - Fixed a bug in CORD_ncmp (and hence CORD_str).
879 - Repaired the OS2 port, which had suffered from bit rot
880 in 4.0. Worked around what appears to be CSet/2 V1.0
882 - Fixed a Makefile bug for target "c++".
885 - Multiple bug fixes/workarounds in the Solaris threads version.
886 (It occasionally failed to locate some register contents for
887 marking. It also turns out that thr_suspend and friends are
888 unreliable in Solaris 2.3. Dirty bit reads appear
889 to be unreliable under some weird
890 circumstances. My stack marking code
891 contained a serious performance bug. The new code is
892 extremely defensive, and has not failed in several cpu
893 hours of testing. But no guarantees ...)
894 - Added MacOS support (thanks to Patrick Beard.)
895 - Fixed several syntactic bugs in gc_c++.h and friends. (These
896 didn't bother g++, but did bother most other compilers.)
897 Fixed gc_c++.h finalization interface. (It didn't.)
898 - 64 bit alignment for allocated objects was not guaranteed in a
899 few cases in which it should have been.
900 - Added GC_malloc_atomic_ignore_off_page.
901 - Added GC_collect_a_little.
902 - Added some prototypes to gc.h.
903 - Some other minor bug fixes (notably in Makefile).
904 - Fixed OS/2 / EMX port (thanks to Ari Huttunen).
905 - Fixed AmigaDOS port. (thanks to Michel Schinz).
906 - Fixed the DATASTART definition under Solaris. There
907 was a 1 in 16K chance of the collector missing the first
908 64K of static data (and thus crashing).
909 - Fixed some blatant anachronisms in the README file.
910 - Fixed PCR-Makefile for upcoming PPCR release.
913 - Fixed SPARC alignment problem with GC_DEBUG.
914 - Fixed Solaris threads /proc workaround. The real
915 problem was an interaction with mprotect.
916 - Incorporated fix from Patrick Beard for gc_c++.h (now gc_cpp.h).
917 - Slightly improved allocator space utilization by
918 fixing the GC_size_map mechanism.
919 - Integrated some Sony News and MIPS RISCos 4.51
920 patches. (Thanks to Nobuyuki Hikichi of
921 Software Research Associates, Inc. Japan)
922 - Fixed HP_PA alignment problem. (Thanks to
923 xjam@cork.cs.berkeley.edu.)
924 - Added GC_same_obj and friends. Changed GC_base
925 to return 0 for pointers past the end of large objects.
926 Improved GC_base performance with ALL_INTERIOR_POINTERS
927 on machines with a slow integer mod operation.
928 Added GC_PTR_ADD, GC_PTR_STORE, etc. to prepare
930 - changed the default on most UNIX machines to be that
931 signals are not disabled during critical GC operations.
932 This is still ANSI-conforming, though somewhat dangerous
933 in the presence of signal handlers. But the performance
934 cost of the alternative is sometimes problematic.
935 Can be changed back with a minor Makefile edit.
936 - renamed IS_STRING in gc.h, to CORD_IS_STRING, thus
937 following my own naming convention. Added the function
938 CORD_to_const_char_star.
939 - Fixed a gross bug in GC_finalize. Symptom: occasional
940 address faults in that function. (Thanks to Anselm
941 Baird-Smith (Anselm.BairdSmith@inria.fr)
942 - Added port to ICL DRS6000 running DRS/NX. Restructured
943 things a bit to factor out common code, and remove obsolete
944 code. Collector should now run under SUNOS5 with either
945 mprotect or /proc dirty bits. (Thanks to Douglas Steel
946 (doug@wg.icl.co.uk)).
947 - More bug fixes and workarounds for Solaris 2.X. (These were
948 mostly related to putting the collector in a dynamic library,
949 which didn't really work before. Also SOLARIS_THREADS
950 didn't interact well with dl_open.) Thanks to btlewis@eng.sun.com.
951 - Fixed a serious performance bug on the DEC Alpha. The text
952 segment was getting registered as part of the root set.
953 (Amazingly, the result was still fast enough that the bug
954 was not conspicuous.) The fix works on OSF/1, version 1.3.
955 Hopefully it also works on other versions of OSF/1 ...
956 - Fixed a bug in GC_clear_roots.
957 - Fixed a bug in GC_generic_malloc_words_small that broke
958 gc_inl.h. (Reported by Antoine de Maricourt. I broke it
959 in trying to tweak the Mac port.)
960 - Fixed some problems with cord/de under Linux.
961 - Fixed some cord problems, notably with CORD_riter4.
963 Thanks to Ben A. Mesander (ben@piglet.cr.usgs.gov)
964 - Added finalization registration routines with weaker ordering
965 constraints. (This is necessary for C++ finalization with
966 multiple inheritance, since the compiler often adds self-cycles.)
967 - Filled the holes in the SCO port. (Thanks to Michael Arnoldus
969 - John Ellis' additions to the C++ support: From John:
971 * I completely rewrote the documentation in the interface gc_c++.h
972 (later renamed gc_cpp.h). I've tried to make it both clearer and more
975 * The definition of accessibility now ignores pointers from an
976 finalizable object (an object with a clean-up function) to itself.
977 This allows objects with virtual base classes to be finalizable by the
978 collector. Compilers typically implement virtual base classes using
979 pointers from an object to itself, which under the old definition of
980 accessibility prevented objects with virtual base classes from ever
981 being collected or finalized.
983 * gc_cleanup now includes gc as a virtual base. This was enabled by
984 the change in the definition of accessibility.
986 * I added support for operator new[]. Since most (all?) compilers
987 don't yet support operator new[], it is conditionalized on
988 -DOPERATOR_NEW_ARRAY. The code is untested, but its trivial and looks
991 * The test program test_gc_c++ (later renamed test_cpp.cc)
992 tries to test for the C++-specific functionality not tested by the
994 - Added <unistd.h> include to misc.c. (Needed for ppcr.)
995 - Added PowerMac port. (Thanks to Patrick Beard again.)
996 - Fixed "srcdir"-related Makefile problems. Changed things so
997 that all externally visible include files always appear in the
998 include subdirectory of the source. Made gc.h directly
999 includable from C++ code. (These were at Per
1000 Bothner's suggestion.)
1001 - Changed Intel code to also mark from ebp (Kevin Warne's
1003 - Renamed C++ related files so they could live in a FAT
1004 file system. (Charles Fiterman's suggestion.)
1005 - Changed Windows NT Makefile to include C++ support in
1006 gc.lib. Added C++ test as Makefile target.
1009 - ASM_CLEAR_CODE was erroneously defined for HP
1010 PA machines, resulting in a compile error.
1011 - Fixed OS/2 Makefile to create a library. (Thanks to
1012 Mark Boulter (mboulter@vnet.ibm.com)).
1013 - Gc_cleanup objects didn't work if they were created on
1015 - One copy of Gc_cpp.h in the distribution was out of
1016 synch, and failed to document some known compiler
1017 problems with explicit destructor invocation. Partially
1018 fixed. There are probably other compilers on which
1019 gc_cleanup is miscompiled.
1020 - Fixed Makefile to pass C compiler flags to C++ compiler.
1022 - Fixed os_dep.c to work around what appears to be
1023 a new and different VirtualQuery bug under newer
1025 - GC_non_gc_bytes was not correctly maintained by
1026 GC_free. Fixed. Thanks to James Clark (jjc@jclark.com).
1027 - Added GC_set_max_heap_size.
1028 - Changed allocation code to ignore blacklisting if it is preventing
1029 use of a very large block of memory. This has the advantage
1030 that naive code allocating very large objects is much more
1031 likely to work. The downside is you might no
1032 longer find out that such code should really use
1033 GC_malloc_ignore_off_page.
1034 - Changed GC_printf under win32 to close and reopen the file
1035 between calls. FAT file systems otherwise make the log file
1036 useless for debugging.
1037 - Added GC_try_to_collect and GC_get_bytes_since_gc. These
1038 allow starting an abortable collection during idle times.
1039 This facility does not require special OS support. (Thanks to
1040 Michael Spertus of Geodesic Systems for suggesting this. It was
1041 actually an easy addition. Kumar Srikantan previously added a similar
1042 facility to a now ancient version of the collector. At the time
1043 this was much harder, and the result was less convincing.)
1044 - Added some support for the Borland development environment. (Thanks
1045 to John Ellis and Michael Spertus.)
1046 - Removed a misfeature from checksums.c that caused unexpected
1047 heap growth. (Thanks to Scott Schwartz.)
1048 - Changed finalize.c to call WARN if it encounters a finalization cycle.
1049 WARN is defined in gc_priv.h to write a message, usually to stdout.
1050 In many environments, this may be inappropriate.
1051 - Renamed NO_PARAMS in gc.h to GC_NO_PARAMS, thus adhering to my own
1053 - Added GC_set_warn_proc to intercept warnings.
1054 - Fixed Amiga port. (Thanks to Michel Schinz (schinz@alphanet.ch).)
1055 - Fixed a bug in mark.c that could result in an access to unmapped
1056 memory from GC_mark_from_mark_stack on machines with unaligned
1058 - Fixed a win32 specific performance bug that could result in scanning of
1059 objects allocated with the system malloc.
1060 - Added REDIRECT_MALLOC.
1063 - Fixed many minor and one major README bugs. (Thanks to Franklin Chen
1064 (chen@adi.com) for pointing out many of them.)
1065 - Fixed ALPHA/OSF/1 dynamic library support. (Thanks to Jonathan Bachrach
1066 (jonathan@harlequin.com)).
1067 - Added incremental GC support (MPROTECT_VDB) for Linux (with some
1068 help from Bruno Haible).
1069 - Altered SPARC recognition tests in gc.h and config.h (mostly as
1070 suggested by Fergus Henderson).
1071 - Added basic incremental GC support for win32, as implemented by
1072 Windows NT and Windows 95. GC_enable_incremental is a noop
1073 under win32s, which doesn't implement enough of the VM interface.
1074 - Added -DLARGE_CONFIG.
1075 - Fixed GC_..._ignore_off_page to also function without
1076 -DALL_INTERIOR_POINTERS.
1077 - (Hopefully) fixed RS/6000 port. (Only the test was broken.)
1078 - Fixed a performance bug in the nonincremental collector running
1079 on machines supporting incremental collection with MPROTECT_VDB
1080 (e.g. SunOS 4, DEC AXP). This turned into a correctness bug under
1081 win32s with win32 incremental collection. (Not all memory protection
1083 - Fixed some ppcr related bit rot.
1084 - Caused dynamic libraries to be unregistered before reregistering.
1085 The old way turned out to be a performance bug on some machines.
1086 - GC_root_size was not properly maintained under MSWIN32.
1087 - Added -DNO_DEBUGGING and GC_dump.
1088 - Fixed a couple of bugs arising with SOLARIS_THREADS +
1090 - Added NetBSD/M68K port. (Thanks to Peter Seebach
1091 <seebs@taniemarie.solon.com>.)
1092 - Fixed a serious realloc bug. For certain object sizes, the collector
1093 wouldn't scan the expanded part of the object. (Thanks to Clay Spence
1094 (cds@peanut.sarnoff.com) for noticing the problem, and helping me to
1098 - Added Linux ELF support. (Thanks to Arrigo Triulzi <arrigo@ic.ac.uk>.)
1099 - GC_base crashed if it was called before any other GC_ routines.
1100 This could happen if a gc_cleanup object was allocated outside the heap
1101 before any heap allocation.
1102 - The heap expansion heuristic was not stable if all objects had finalization
1103 enabled. Fixed finalize.c to count memory in finalization queue and
1104 avoid explicit deallocation. Changed alloc.c to also consider this count.
1105 (This is still not recommended. It's expensive if nothing else.) Thanks
1106 to John Ellis for pointing this out.
1107 - GC_malloc_uncollectable(0) was broken. Thanks to Phong Vo for pointing
1109 - The collector didn't compile under Linux 1.3.X. (Thanks to Fred Gilham for
1110 pointing this out.) The current workaround is ugly, but expected to be
1112 - Fixed a formatting problem for SPARC stack traces.
1113 - Fixed some '=='s in os_dep.c that should have been assignments.
1114 Fortunately these were in code that should never be executed anyway.
1115 (Thanks to Fergus Henderson.)
1116 - Fixed the heap block allocator to only drop blacklisted blocks in small
1117 chunks. Made BL_LIMIT self adjusting. (Both of these were in response
1118 to heap growth observed by Paul Graham.)
1119 - Fixed the Metrowerks/68K Mac code to also mark from a6. (Thanks
1121 - Significantly updated README.debugging.
1122 - Fixed some problems with longjmps out of signal handlers, especially under
1123 Solaris. Added a workaround for the fact that siglongjmp doesn't appear to
1124 do the right thing with -lthread under Solaris.
1125 - Added MSDOS/djgpp port. (Thanks to Mitch Harris (maharri@uiuc.edu).)
1126 - Added "make reserved_namespace" and "make user_namespace". The
1127 first renames ALL "GC_xxx" identifiers as "_GC_xxx". The second is the
1128 inverse transformation. Note that doing this is guaranteed to break all
1129 clients written for the other names.
1130 - descriptor field for kind NORMAL in GC_obj_kinds with ADD_BYTE_AT_END
1131 defined should be -ALIGNMENT not WORDS_TO_BYTES(-1). This is
1132 a serious bug on machines with pointer alignment of less than a word.
1133 - GC_ignore_self_finalize_mark_proc didn't handle pointers to very near the
1134 end of the object correctly. Caused failures of the C++ test on a DEC Alpha
1136 - gc_inl.h still had problems. Partially fixed. Added warnings at the
1137 beginning to hopefully specify the remaining dangers.
1138 - Added DATAEND definition to config.h.
1139 - Fixed some of the .h file organization. Fixed "make floppy".
1142 - Fixed some compilation problems with -DCHECKSUMS (thanks to Ian Searle)
1143 - Updated some Mac specific files to synchronize with Patrick Beard.
1144 - Fixed a serious bug for machines with non-word-aligned pointers.
1145 (Thanks to Patrick Beard for pointing out the problem. The collector
1146 should fail almost any conceivable test immediately on such machines.)
1149 - Changed a "comment" in a MacOS specific part of mach-dep.c that caused
1150 gcc to fail on other platforms.
1153 - More README.debugging fixes.
1154 - Objects ready for finalization, but not finalized in the same GC
1155 cycle, could be prematurely collected. This occasionally happened
1157 - Too little memory was obtained from the system for very large
1158 objects. That could cause a heap explosion if these objects were
1159 not contiguous (e.g. under PCR), and too much of them was blacklisted.
1160 - Due to an improper initialization, the collector was too hesitant to
1161 allocate blacklisted objects immediately after system startup.
1162 - Moved GC_arrays from the data into the bss segment by not explicitly
1163 initializing it to zero. This significantly
1164 reduces the size of executables, and probably avoids some disk accesses
1165 on program startup. It's conceivable that it might break a port that I
1167 - Fixed EMX_MAKEFILE to reflect the gc_c++.h to gc_cpp.h renaming which
1168 occurred a while ago.
1171 - Fixed a typo around a call to GC_collect_or_expand in alloc.c. It broke
1172 handling of out of memory. (Thanks to Patrick Beard for noticing.)
1175 - Rationalized (hopefully) GC_try_to_collect in an incremental collection
1176 environment. It appeared to not handle a call while a collection was in
1177 progress, and was otherwise too conservative.
1178 - Merged GC_reclaim_or_delete_all into GC_reclaim_all to get rid of some
1180 - Added Patrick Beard's Mac fixes, with substantial completely untested
1182 - Fixed the MPROTECT_VDB code to deal with large pages and imprecise
1183 fault addresses (as on an UltraSPARC running Solaris 2.5). Note that this
1184 was not a problem in the default configuration, which uses PROC_VDB.
1185 - The DEC Alpha assembly code needed to restore $gp between calls.
1186 Thanks to Fergus Henderson for tracking this down and supplying a
1188 - The write command for "de" was completely broken for large files.
1189 I used the easiest portable fix, which involved changing the semantics
1190 so that f.new is written instead of overwriting f. That's safer anyway.
1191 - Added README.solaris2 with a discussion of the possible problems of
1192 mixing the collector's sbrk allocation with malloc/realloc.
1193 - Changed the data segment starting address for SGI machines. The
1194 old code failed under IRIX6.
1195 - Required double word alignment for MIPS.
1196 - Various minor fixes to remove warnings.
1197 - Attempted to fix some Solaris threads problems reported by Zhiying Chen.
1198 In particular, the collector could try to fork a thread with the
1199 world stopped as part of GC_thr_init. It also failed to deal with
1200 the case in which the original thread terminated before the whole
1202 - Added -DNO_EXECUTE_PERMISSION. This has a major performance impact
1203 on the incremental collector under Irix, and perhaps under other
1205 - Added some code to support allocating the heap with mmap. This may
1206 be preferable under some circumstances.
1207 - Integrated dynamic library support for HP.
1208 (Thanks to Knut Tvedten <knuttv@ifi.uio.no>.)
1209 - Integrated James Clark's win32 threads support, and made a number
1210 of changes to it, many of which were suggested by Pontus Rydin.
1211 This is still not 100% solid.
1212 - Integrated Alistair Crooks' support for UTS4 running on an Amdahl
1214 - Fixed a serious bug in explicitly typed allocation. Objects requiring
1215 large descriptors where handled in a way that usually resulted in
1216 a segmentation fault in the marker. (Thanks to Jeremy Fitzhardinge
1217 for helping to track this down.)
1218 - Added partial support for GNU win32 development. (Thanks to Fergus
1220 - Added optional support for Java-style finalization semantics. (Thanks
1221 to Patrick Bridges.) This is recommended only for Java implementations.
1222 - GC_malloc_uncollectable faulted instead of returning 0 when out of
1223 memory. (Thanks to dan@math.uiuc.edu for noticing.)
1224 - Calls to GC_base before the collector was initialized failed on a
1225 DEC Alpha. (Thanks to Matthew Flatt.)
1226 - Added base pointer checking to GC_REGISTER_FINALIZER in debugging
1227 mode, at the suggestion of Jeremy Fitzhardinge.
1228 - GC_debug_realloc failed for uncollectable objects. (Thanks to
1229 Jeremy Fitzhardinge.)
1230 - Explicitly typed allocation could crash if it ran out of memory.
1231 (Thanks to Jeremy Fitzhardinge.)
1232 - Added minimal support for a DEC Alpha running Linux.
1233 - Fixed a problem with allocation of objects whose size overflowed
1234 ptrdiff_t. (This now fails unconditionally, as it should.)
1235 - Added the beginning of Irix pthread support.
1236 - Integrated Xiaokun Zhu's fixes for djgpp 2.01.
1237 - Added SGI-style STL allocator support (gc_alloc.h).
1238 - Fixed a serious bug in README.solaris2. Multithreaded programs must include
1239 gc.h with SOLARIS_THREADS defined.
1240 - Changed GC_free so it actually deallocates uncollectable objects.
1241 (Thanks to Peter Chubb for pointing out the problem.)
1242 - Added Linux ELF support for dynamic libararies. (Thanks again to
1244 - Changed the Borland cc configuration so that the assembler is not
1246 - Fixed a bug in the C++ test that caused it to fail in 64-bit
1250 - Fixed ElfW definition in dyn_load.c. (Thanks to Fergus Henderson.)
1251 This prevented the dynamic library support from compiling on some
1252 older ELF Linux systems.
1253 - Fixed UTS4 port (which I apparently mangled during the integration)
1254 (Thanks to again to Alistair Crooks.)
1255 - "Make C++" failed on Suns with SC4.0, due to a problem with "bool".
1257 - Added more pieces for GNU win32. (Thanks to Timothy N. Newsham.)
1258 The current state of things should suffice for at least some
1260 - Changed the out of memory retry count handling as suggested by
1261 Kenjiro Taura. (This matters only if GC_max_retries > 0, which
1262 is no longer the default.)
1263 - If a /proc read failed repeatedly, GC_written_pages was not updated
1264 correctly. (Thanks to Peter Chubb for diagnosing this.)
1265 - Under unlikely circumstances, the allocator could infinite loop in
1266 an out of memory situation. (Thanks again to Kenjiro Taura for
1267 identifying the problem and supplying a fix.)
1268 - Fixed a syntactic error in the DJGPP code. (Thanks to Fergus
1269 Henderson for finding this by inspection.) Also fixed a test program
1270 problem with DJGPP (Thanks to Peter Monks.)
1271 - Atomic uncollectable objects were not treated correctly by the
1272 incremental collector. This resulted in weird log statistics and
1273 occasional performance problems. (Thanks to Peter Chubb for pointing
1275 - Fixed some problems resulting from compilers that dont define
1276 __STDC__. In this case void * and char * were used inconsistently
1277 in some cases. (Void * should not have been used at all. If
1278 you have an ANSI superset compiler that does not define __STDC__,
1279 please compile with -D__STDC__=0. Thanks to Manuel Serrano and others
1280 for pointing out the problem.)
1281 - Fixed a compilation problem on Irix with -n32 and -DIRIX_THREADS.
1282 Also fixed some other IRIX_THREADS problems which may or may not have
1283 had observable symptoms.
1284 - Fixed an HP PA compilation problem in dyn_load.c. (Thanks to
1286 - SEGV fault handlers sometimes did not get reset correctly. (Thanks
1288 - Added a fix for SOLARIS_THREADS on Intel. (Thanks again to David
1289 Pickens.) This probably needs more work to become functional.
1290 - Fixed struct sigcontext_struct in os_dep.c for compilation under
1291 Linux 2.1.X. (Thanks to Fergus Henderson.)
1292 - Changed the DJGPP STACKBOTTOM and DATASTART values to those suggested
1293 by Kristian Kristensen. These may still not be right, but it is
1294 it is likely to work more often than what was there before. They may
1295 even be exactly right.
1296 - Added a #include <string.h> to test_cpp.cc. This appears to help
1297 with HP/UX and gcc. (Thanks to assar@sics.se.)
1298 - Version 4.11 failed to run in incremental mode on recent 64-bit Irix
1299 kernels. This was a problem related to page unaligned heap segments.
1300 Changed the code to page align heap sections on all platforms.
1301 (I had mistakenly identified this as a kernel problem earlier.
1303 - Version 4.11 did not make allocated storage executable, except on
1304 one or two platforms, due to a bug in a #if test. (Thanks to Dave
1305 Grove for pointing this out.)
1306 - Added sparc_sunos4_mach_dep.s to support Sun's compilers under SunOS4.
1307 - Added GC_exclude_static_roots.
1308 - Fixed the object size mapping algorithm. This shouldn't matter,
1309 but the old code was ugly.
1310 - Heap checking code could die if one of the allocated objects was
1311 larger than its base address. (Unsigned underflow problem. Thanks
1312 to Clay Spence for isolating the problem.)
1313 - Added RS6000 (AIX) dynamic library support and fixed STACK_BOTTOM.
1314 (Thanks to Fred Stearns.)
1315 - Added Fergus Henderson's patches for improved robustness with large
1316 heaps and lots of blacklisting.
1317 - Added Peter Chubb's changes to support Solaris Pthreads, to support
1318 MMAP allocation in Solaris, to allow Solaris to find dynamic libraries
1319 through /proc, to add malloc_typed_ignore_off_page, and a few other
1320 minor features and bug fixes.
1321 - The Solaris 2 port should not use sbrk. I received confirmation from
1322 Sun that the use of sbrk and malloc in the same program is not
1323 supported. The collector now defines USE_MMAP by default on Solaris.
1324 - Replaced the djgpp makefile with Gary Leavens' version.
1325 - Fixed MSWIN32 detection test.
1326 - Added Fergus Henderson's patches to allow putting the collector into
1327 a DLL under GNU win32.
1328 - Added Ivan V. Demakov's port to Watcom C on X86.
1329 - Added Ian Piumarta's Linux/PowerPC port.
1330 - On Brian Burton's suggestion added PointerFreeGC to the placement
1331 options in gc_cpp.h. This is of course unsafe, and may be controversial.
1332 On the other hand, it seems to be needed often enough that it's worth
1333 adding as a standard facility.
1336 - Fixed a crucial bug in the Watcom port. There was a redundant decl
1337 of GC_push_one in gc_priv.h.
1338 - Added FINALIZE_ON_DEMAND.
1339 - Fixed some pre-ANSI cc problems in test.c.
1340 - Removed getpagesize() use for Solaris. It seems to be missing in one
1342 - Fixed bool handling for SPARCCompiler version 4.2.
1343 - Fixed some files in include that had gotten unlinked from the main
1345 - Some RS/6000 fixes (missing casts). Thanks to Toralf Foerster.
1346 - Fixed several problems in GC_debug_realloc, affecting mostly the
1348 - GC_exclude_static_roots contained a buggy unsigned comparison to
1349 terminate a loop. (Thanks to Wilson Ho.)
1350 - CORD_str failed if the substring occurred at the last possible position.
1351 (Only affects cord users.)
1352 - Fixed Linux code to deal with RedHat 5.0 and integrated Peter Bigot's
1353 os_dep.c code for dealing with various Linux versions.
1354 - Added workaround for Irix pthreads sigaction bug and possible signal
1355 misdirection problems.
1357 - Changed RS6000 STACKBOTTOM.
1358 - Integrated Patrick Beard's Mac changes.
1359 - Alpha1 didn't compile on Irix m.n, m < 6.
1360 - Replaced Makefile.dj with a new one from Gary Leavens.
1361 - Added Andrew Stitcher's changes to support SCO OpenServer.
1362 - Added PRINT_BLACK_LIST, to allow debugging of high densities of false
1364 - Added code to debug allocator to keep track of return address
1365 in GC_malloc caller, thus giving a bit more context.
1366 - Changed default behavior of large block allocator to more
1367 aggressively avoid fragmentation. This is likely to slow down the
1368 collector when it succeeds at reducing space cost.
1369 - Integrated Fergus Henderson's CYGWIN32 changes. They are untested,
1370 but needed for newer versions.
1371 - USE_MMAP had some serious bugs. This caused the collector to fail
1372 consistently on Solaris with -DSMALL_CONFIG.
1373 - Added Linux threads support, thanks largely to Fergus Henderson.
1376 - I have a backlog of unintegrated contributed platform-specific changes.
1377 - Very large root set sizes (> 16 MB or so) could cause the collector
1378 to abort with an unexpected mark stack overflow. (Thanks again to
1379 Peter Chubb.) NOT YET FIXED. Workaround is to increase the initial
1381 - The SGI version of the collector marks from mmapped pages, even
1382 if they are not part of dynamic library static data areas. This
1383 causes performance problems with some SGI libraries that use mmap
1384 as a bitmap allocator. NOT YET FIXED. It may be possible to turn
1385 off DYNAMIC_LOADING in the collector as a workaround. It may also
1386 be possible to conditionally intercept mmap and use GC_exclude_static_roots.
1387 The real fix is to walk rld data structures, which looks possible.
1388 - Integrate MIT and DEC pthreads ports.