1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
#ifndef __mzscheme_gc_2__
#define __mzscheme_gc_2__
/***************************************************************************/
/*** See README for a general overview of the interface architecture. ***/
/***************************************************************************/
#ifndef GC2_JUST_MACROS
typedef int (*Size_Proc)(void *obj);
typedef int (*Mark_Proc)(void *obj);
typedef int (*Fixup_Proc)(void *obj);
/*
Types of the traversal procs (supplied by MzScheme); see overview in README
for information about traversals. The return value is the size of
the object in words. */
# ifdef GC2_JUST_MACROS_AND_TYPEDEFS
# define GC2_JUST_MACROS
# endif
#endif
#ifndef GC2_JUST_MACROS
#include <stddef.h>
#ifndef GC2_EXTERN
# ifdef GC2_AS_EXPORT
# define GC2_EXTERN __declspec(dllexport)
# endif
# ifdef GC2_AS_IMPORT
# define GC2_EXTERN __declspec(dllimport)
# endif
# ifndef GC2_EXTERN
# define GC2_EXTERN extern
# endif
#endif
# ifdef __cplusplus
extern "C" {
# endif
/***************************************************************************/
/* Administration */
/***************************************************************************/
GC2_EXTERN unsigned long (*GC_get_thread_stack_base)(void);
/*
Called by GC to get the base for stack traversal in the current
thread (see README). The returned address must not be in the middle
of a variable-stack record. */
GC2_EXTERN void GC_set_stack_base(void *base);
GC2_EXTERN unsigned long GC_get_stack_base(void);
/*
Called by MzScheme to set/get value used for stack base when
GC_get_thread_stack_base is null. This is mainly useful for getting
MzScheme started, before it has multiple threads. */
GC2_EXTERN void GC_add_roots(void *start, void *end);
/*
Called by MzScheme to install roots. The memory between
`start' (inclusive) and `end' (exclusive) contains pointers. */
GC2_EXTERN void GC_init_type_tags(int count, int weakbox);
/*
Called by MzScheme to indicate the number of different type tags it
uses, starting from 0. `count' is always less than 256. The weakbox
argument is the value to be used for tagging weak box. (The GC has
some freedom in the layout of a weak box, so it performs weak box
traversals itself, but MzScheme gets to choose the tag.) */
GC2_EXTERN void GC_register_thread(void *, void *);
/*
Indicates that a just-allocated point is for a thread record
owned by a particular custodian. */
GC2_EXTERN void (*GC_collect_start_callback)(void);
GC2_EXTERN void (*GC_collect_end_callback)(void);
/*
Called by GC before/after performing a collection. Used by MzScheme
to zero out some data and record collection times. The end
procedure should be called before finalizations are performed. */
GC2_EXTERN void (*GC_out_of_memory)(void);
/*
Called by GC when it can't satify a memory request. GC_out_of_memory()
might perform a longjmp. */
GC2_EXTERN void GC_dump(void);
/*
Dumps memory state info to stderr. */
GC2_EXTERN long GC_get_memory_use(void *c);
/*
Returns the number of currently-allocated bytes (speficilly for
custodian c, as much as the GC's accounting makes possible). */
#define MZACCT_REQUIRE 0
#define MZACCT_LIMIT 1
GC2_EXTERN int GC_set_account_hook(int type, void *c1, unsigned long b, void *c2);
/*
Set a memory-accounting property. Returns 0 for failure (i.e., not
supported). */
GC2_EXTERN void GC_gcollect(void);
/*
Performs an immediate (full) collection. */
/***************************************************************************/
/* Allocation */
/***************************************************************************/
GC2_EXTERN void *GC_malloc(size_t size_in_bytes);
/*
Alloc an array of pointers, initially zeroed. */
GC2_EXTERN void *GC_malloc_one_tagged(size_t);
/*
Alloc a tagged item, initially zeroed. MzScheme sets the tag
before a collection. */
GC2_EXTERN void *GC_malloc_one_xtagged(size_t);
/*
Alloc an item, initially zeroed. Rather than having a specific tag,
all objects allocated this way are marked/fixedup via the function
in GC_mark_xtagged and GC_fixup_xtagged. MzScheme sets
GC_{mark,fixup}_xtagged. */
GC2_EXTERN void (*GC_mark_xtagged)(void *obj);
GC2_EXTERN void (*GC_fixup_xtagged)(void *obj);
/*
Mark and fixup functions for memory allocated with
GC_malloc_one_xtagged(). */
GC2_EXTERN void *GC_malloc_array_tagged(size_t);
/*
Alloc an array of tagged items. MzScheme sets the tag in the first
item before a collection, by maybe not all items. When traversing,
use the first one for size. */
GC2_EXTERN void *GC_malloc_atomic(size_t size_in_bytes);
/*
Alloc pointerless memory (not necessarily zeroed). */
#define GC_malloc_atomic_tagged GC_malloc_one_tagged
/*
Alloc pointer-free tagged memory (not necessarily zeroed).
MzScheme sets the tag before a collection. */
GC2_EXTERN void *GC_malloc_atomic_uncollectable(size_t size_in_bytes);
/*
Like plain malloc: pointer-free, never collected. */
GC2_EXTERN void *GC_malloc_allow_interior(size_t size_in_bytes);
/*
Alloc an array of pointers (typically large), and recognize
pointers into the middle of the array, or just past the end of the
array. */
GC2_EXTERN void *GC_malloc_weak_array(size_t size_in_bytes, void *replace_val);
/*
Alloc an array of weak pointers, initially zeroed. When a value in
the array is collected, it's replaced by `replace-val'. The
precense of a pointer in the array doesn't keep the referenced
memory from being collected. See also README for information about
the structure of the array. */
GC2_EXTERN void GC_free(void *);
/*
Lets the collector optionally reverse an allocation immediately.
[Generally a no-op.] */
GC2_EXTERN void *GC_malloc_weak_box(void *p, void **secondary, int soffset);
/*
Allocate a weak box. See README for details. */
GC2_EXTERN void **GC_malloc_immobile_box(void *p);
GC2_EXTERN void GC_free_immobile_box(void **b);
/*
Allocate (or free) a non-GCed box containing a pointer to a GCed
value. The pointer is stored as the first longword of the box. */
/***************************************************************************/
/* Memory tracing */
/***************************************************************************/
GC2_EXTERN int GC_mtrace_new_id(void *f);
GC2_EXTERN int GC_mtrace_union_current_with(int newval);
/***************************************************************************/
/* Finalization */
/***************************************************************************/
typedef void (*GC_finalization_proc)(void *p, void *data);
/*
Type of a finalization procedure. */
GC2_EXTERN void GC_set_finalizer(void *p, int tagged, int level,
GC_finalization_proc f, void *data,
GC_finalization_proc *oldf, void **olddata);
/*
See README for details. */
GC2_EXTERN void GC_finalization_weak_ptr(void **p, int offset);
/*
See README for details. */
/***************************************************************************/
/* Cooperative GC */
/***************************************************************************/
GC2_EXTERN void **GC_variable_stack;
/*
See the general overview in README. */
GC2_EXTERN void GC_register_traversers(short tag, Size_Proc size, Mark_Proc mark, Fixup_Proc fixup,
int is_constant_size, int is_atomic);
/*
Registers a traversal procedure for a tag. Obviously, a traversal
procedure must be installed for each tag before a collection
happens where an instance of the tag as been allocated. If objects
using the tag are always of the same size, is_constant_size can be
non-zero, and `size' must return the right size given a null
pointer. If objects using the tag are atomic, is_atomic can be
non-zero. */
/* #define gcMARK(x) ... see below ... */
/* #define gcMARK_TYPED(t, x) ... see below ... */
/* #define gcMARK_TYPED_NOW(t, x) ... see below ... */
/* #define gcFIXUP(x) ... see below ... */
/* #define gcFIXUP_TYPED(t, x) ... see below ... */
/* #define gcFIXUP_TYPED_NOW(t, x) ... see below ... */
/* Macros that, given an l-value and optional type, marks the
referenced memory as live and updates the pointer as necessary
(i.e., if it's GCable memory that is moving). The `x' argument can
appear in the macro's output multiple times, and the output can be
a statement rather than a expression.
The NOW versions force the mark or fixup to happen immediately. The
other forms can queue the mark or fixup to happen later. */
/* #define gcBYTES_TO_WORDS(x) ((x + 3) >> 2) */
/*
Helpful macro for computing the return value in a traversal proc,
which must be in words. */
GC2_EXTERN void *GC_resolve(void *p);
/*
Can be called by a traversal proc to get the current address of a
object that might have been moved already. This is necessary, for
example, if the size or structure of an object depends on the
content of an object it references. For example, the size of a
class instance usually depends on a field count that is stored in
the class. */
/* INTERNAL for the current implemenation (used by macros): */
GC2_EXTERN void GC_mark(const void *p);
GC2_EXTERN void GC_fixup(void *p);
/*
Used in the expansion of gcMARK and gcFIXUP.
These procedures and variables are internal to the current
implementation, and are *not* part of the "official" interface. */
GC2_EXTERN void GC_mark_variable_stack(void **var_stack,
long delta,
void *limit);
GC2_EXTERN void GC_fixup_variable_stack(void **var_stack,
long delta,
void *limit);
/*
Can be called by a mark or fixup traversal proc to traverse and
update a chunk of (atomically-allocated) memory containing an image
of the stack.
The `var_stack' argument corresponds to the value of GC_var_stack
for the copied stack (see the overview at the top of this
file). The `var_stack' pointer refers to the address of the chain
in the original stack, not in the heap copy. The `delta' argument
specifies the difference heap_copy_address - stack_address (where
stack_address is the numerically lower bound for the copied stack
region, regardless of which direction the stack grows). The `limit'
argument corresponds to the value that would have been returned by
GC_get_thread_stack_base() at the time the stack was copied. */
# ifdef __cplusplus
};
# endif
#endif
/* Macros (implementation-specific): */
#define gcMARK(x) GC_mark(x)
#define gcMARK_TYPED(t, x) gcMARK(x)
#define gcMARK_TYPED_NOW(t, x) gcMARK(x)
#define gcFIXUP_TYPED_NOW(t, x) GC_fixup(&(x))
#define gcFIXUP_TYPED(t, x) gcFIXUP_TYPED_NOW(void*, x)
#define gcFIXUP(x) gcFIXUP_TYPED(void*, x)
#define gcBYTES_TO_WORDS(x) ((x + 3) >> 2)
#define gcWORDS_TO_BYTES(x) (x << 2)
#define GC_INTERIORABLES_NEVER_MOVE 1
#endif /* __mzscheme_gc_2__ */
|