diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 1999-11-01 20:48:50 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 1999-11-01 20:48:50 +0000 |
commit | fd6a6309db035c41f8a280d7acc75437cb7d5e43 (patch) | |
tree | f27124748edbed386955ef2ec344e832258663ca /boehm-gc/include | |
parent | d9bba9c3ed159dda315f6536cf3da2739bd55e5e (diff) | |
download | gcc-fd6a6309db035c41f8a280d7acc75437cb7d5e43.zip gcc-fd6a6309db035c41f8a280d7acc75437cb7d5e43.tar.gz gcc-fd6a6309db035c41f8a280d7acc75437cb7d5e43.tar.bz2 |
Initial revision
From-SVN: r30324
Diffstat (limited to 'boehm-gc/include')
-rw-r--r-- | boehm-gc/include/backptr.h | 56 | ||||
-rw-r--r-- | boehm-gc/include/gc_copy_descr.h | 26 | ||||
-rw-r--r-- | boehm-gc/include/gc_nursery.h | 90 | ||||
-rw-r--r-- | boehm-gc/include/leak_detector.h | 7 |
4 files changed, 179 insertions, 0 deletions
diff --git a/boehm-gc/include/backptr.h b/boehm-gc/include/backptr.h new file mode 100644 index 0000000..d34224e --- /dev/null +++ b/boehm-gc/include/backptr.h @@ -0,0 +1,56 @@ +/* + * This is a simple API to implement pointer back tracing, i.e. + * to answer questions such as "who is pointing to this" or + * "why is this object being retained by the collector" + * + * This API assumes that we have an ANSI C compiler. + * + * Most of these calls yield useful information on only after + * a garbage collection. Usually the client will first force + * a full collection and then gather information, preferably + * before much intervening allocation. + * + * The implementation of the interface is only about 99.9999% + * correct. It is intended to be good enough for profiling, + * but is not intended to be used with production code. + * + * Results are likely to be much more useful if all allocation is + * accomplished through the debugging allocators. + * + * The implementation idea is due to A. Demers. + */ + +/* Store information about the object referencing dest in *base_p */ +/* and *offset_p. */ +/* If multiple objects or roots point to dest, the one reported */ +/* will be the last on used by the garbage collector to trace the */ +/* object. */ +/* source is root ==> *base_p = address, *offset_p = 0 */ +/* source is heap object ==> *base_p != 0, *offset_p = offset */ +/* Returns 1 on success, 0 if source couldn't be determined. */ +/* Dest can be any address within a heap object. */ +typedef enum { GC_UNREFERENCED, /* No refence info available. */ + GC_NO_SPACE, /* Dest not allocated with debug alloc */ + GC_REFD_FROM_ROOT, /* Referenced directly by root *base_p */ + GC_REFD_FROM_HEAP, /* Referenced from another heap obj. */ + GC_FINALIZER_REFD /* Finalizable and hence accessible. */ +} GC_ref_kind; + +GC_ref_kind GC_get_back_ptr_info(void *dest, void **base_p, size_t *offset_p); + +/* Generate a random heap address. */ +/* The resulting address is in the heap, but */ +/* not necessarily inside a valid object. */ +void * GC_generate_random_heap_address(void); + +/* Generate a random address inside a valid marked heap object. */ +void * GC_generate_random_valid_address(void); + +/* Force a garbage collection and generate a backtrace from a */ +/* random heap address. */ +/* This uses the GC logging mechanism (GC_printf) to produce */ +/* output. It can often be called from a debugger. The */ +/* source in dbg_mlc.c also serves as a sample client. */ +void GC_generate_random_backtrace(void); + + diff --git a/boehm-gc/include/gc_copy_descr.h b/boehm-gc/include/gc_copy_descr.h new file mode 100644 index 0000000..212c99e --- /dev/null +++ b/boehm-gc/include/gc_copy_descr.h @@ -0,0 +1,26 @@ + +/* + * Copyright (c) 1999 by Silicon Graphics. All rights reserved. + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ +/* Descriptor for allocation request. May be redefined by client. */ +typedef struct { + GC_word bitmap; /* Bitmap describing pointer locations. */ + /* High order bit correspond to 0th */ + /* word. 2 lsbs must be 0. */ + size_t length; /* In bytes, must be multiple of word */ + /* size. Must be >0, <= 512 */ +} * GC_copy_descriptor; + +/* The collector accesses descriptors only through these two macros. */ +#define GC_SIZE_FROM_DESCRIPTOR(d) ((d) -> length) +#define GC_BIT_MAP_FROM_DESCRIPTOR(d) ((d) -> bitmap) + diff --git a/boehm-gc/include/gc_nursery.h b/boehm-gc/include/gc_nursery.h new file mode 100644 index 0000000..d109ff0 --- /dev/null +++ b/boehm-gc/include/gc_nursery.h @@ -0,0 +1,90 @@ + +/* + * Copyright (c) 1999 by Silicon Graphics. All rights reserved. + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +/* + * THIS IMPLEMENTATION FOR THIS INTERFACE IS INCOMPLETE. + * NONE OF THIS HAS BEEN TESTED. DO NOT USE. + * + * Comments on the interface are appreciated, especially from + * potential users of the interface. + * + * This is a Bartlett style copying collector for young objects. + * We assume for now that all objects allocated through this + * mechanism have pointers only in the first BITMAP_BITS words. + * (On a 32-bit machine, BITMAP_BITS is 30.) + * Objects allocated in this manner should be rarely referenced + * by objects not allocated either through this interface, or through + * the typed allocation interface. + * If this interface is used, we assume that type information provided + * through either this or the typed allocation interface is valid + * in a stronger sense: + * + * 1) No pointers are stored in fields not marked as such. + * (Otherwise it is only necessary that objects referenced by + * fields marked as nonpointers are also reachable via another + * path.) + * 2) Values stored in pointer fields are either not addresses in + * the heap, or they really are pointers. In the latter case, it + * is acceptable to move the object they refer to, and to update + * the pointer. + * + * GC_free may not be invoked on objects allocated with GC_copying_malloc. + * + * No extra space is added to the end of objects allocated through this + * interface. If the client needs to maintain pointers past the + * end, the size should be explicitly padded. + * + * We assume that calls to this will usually be compiler generated. + * Hence the interface is allowed to be a bit ugly in return for speed. + */ + +#include "gc_copy_descr.h" + +/* GC_copy_descr.h must define */ +/* GC_SIZE_FROM_DESCRIPTOR(descr) and */ +/* GC_BIT_MAP_FROM_DESCRIPTOR(descr). */ +/* It may either be the GC supplied version of the header file, or a */ +/* client specific one that derives the information from a client- */ +/* specific type descriptor. */ + +typedef GC_PTR GC_copy_alloc_state; + /* Current allocator state. */ + /* Multiple allocation states */ + /* may be used for concurrent */ + /* allocation, or to enhance */ + /* locality. */ + /* Should be treated as opaque. */ + +/* Allocate a memory block of size given in the descriptor, and with */ +/* pointer layout given by the descriptor. The resulting block may not */ +/* be cleared, and should immediately be initialized by the client. */ +/* (A concurrent GC may see an uninitialized pointer field. If it */ +/* points outside the nursery, that's fine. If it points inside, it */ +/* may retain an object, and be relocated. But that's also fine, since */ +/* the new value will be immediately overwritten. */ +/* This variant acquires the allocation lock, and uses a default */ +/* global allocation state. */ +GC_PTR GC_copying_malloc(GC_copy_descriptor); + +/* A variant of the above that does no locking on the fast path, */ +/* and passes an explicit pointer to an allocation state. */ +/* The allocation state is updated. */ +/* There will eventually need to be a macro or inline function version */ +/* of this. */ +GC_PTR GC_copying_malloc2(GC_copy_descriptor, GC_copy_alloc_state *); + +/* Initialize an allocation state so that it can be used for */ +/* allocation. This implicitly reserves a small section of the */ +/* nursery for use with this allocator. */ +void GC_init_copy_alloc_state(GC_copy_alloc_state *); diff --git a/boehm-gc/include/leak_detector.h b/boehm-gc/include/leak_detector.h new file mode 100644 index 0000000..6786825 --- /dev/null +++ b/boehm-gc/include/leak_detector.h @@ -0,0 +1,7 @@ +#define GC_DEBUG +#include "gc.h" +#define malloc(n) GC_MALLOC(n) +#define calloc(m,n) GC_MALLOC(m*n) +#define free(p) GC_FREE(p) +#define realloc(p,n) GC_REALLOC(n) +#define CHECK_LEAKS() GC_gcollect() |