2 * garbage collection - shared definitions for modules "inside" the GC system
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
16 #ifndef _GC_INTERNAL_H_
17 #define _GC_INTERNAL_H_
19 /* disabling gc assertions made no discernable difference to GC speed,
20 * last I tried it - dan 2003.12.21 */
22 #define gc_assert(ex) do { \
23 if (!(ex)) gc_abort(); \
28 #define gc_abort() lose("GC invariant lost, file \"%s\", line %d", \
31 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
33 static inline unsigned long
34 NWORDS(unsigned long x, unsigned long n_bits)
36 /* A good compiler should be able to constant-fold this whole thing,
37 even with the conditional. */
38 if(n_bits <= N_WORD_BITS) {
39 unsigned long elements_per_word = N_WORD_BITS/n_bits;
41 return CEILING(x, elements_per_word)/elements_per_word;
44 /* FIXME: should have some sort of assertion that N_WORD_BITS
45 evenly divides n_bits */
46 return x * (n_bits/N_WORD_BITS);
50 /* FIXME: Shouldn't this be defined in sbcl.h? */
52 /* FIXME (1) this could probably be defined using something like
53 * sizeof(lispobj)*floor(sizeof(struct simple_fun)/sizeof(lispobj))
54 * - FUN_POINTER_LOWTAG
55 * as I'm reasonably sure that simple_fun->code must always be the
56 * last slot in the object
58 * FIXME (2) it also appears in purify.c, and it has a different value
59 * for SPARC users in that bit
62 #define FUN_RAW_ADDR_OFFSET (6*sizeof(lispobj) - FUN_POINTER_LOWTAG)
64 /* values for the *_alloc_* parameters */
65 #define FREE_PAGE_FLAG 0
66 #define BOXED_PAGE_FLAG 1
67 #define UNBOXED_PAGE_FLAG 2
68 #define OPEN_REGION_PAGE_FLAG 4
71 #define ALLOC_UNBOXED 1
74 void *gc_general_alloc(long nbytes,int unboxed_p,int quick_p);
76 extern long (*scavtab[256])(lispobj *where, lispobj object);
77 extern lispobj (*transother[256])(lispobj object);
78 extern long (*sizetab[256])(lispobj *where);
80 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
82 extern void scavenge(lispobj *start, long n_words);
83 extern void scan_weak_pointers(void);
85 lispobj copy_large_unboxed_object(lispobj object, long nwords);
86 lispobj copy_unboxed_object(lispobj object, long nwords);
87 lispobj copy_large_object(lispobj object, long nwords);
88 lispobj copy_object(lispobj object, long nwords);
90 lispobj *search_read_only_space(void *pointer);
91 lispobj *search_static_space(void *pointer);
92 lispobj *search_dynamic_space(void *pointer);
96 /* Scan an area looking for an object which encloses the given pointer.
97 * Return the object start on success or NULL on failure. */
99 search_space(lispobj *start, size_t words, lispobj *pointer)
103 lispobj thing = *start;
105 /* If thing is an immediate then this is a cons. */
106 if (is_lisp_pointer(thing)
108 || (widetag_of(thing) == CHARACTER_WIDETAG)
109 #if N_WORD_BITS == 64
110 || (widetag_of(thing) == SINGLE_FLOAT_WIDETAG)
112 || (widetag_of(thing) == UNBOUND_MARKER_WIDETAG))
115 count = (sizetab[widetag_of(thing)])(start);
117 /* Check whether the pointer is within this object. */
118 if ((pointer >= start) && (pointer < (start+count))) {
120 /*FSHOW((stderr,"/found %x in %x %x\n", pointer, start, thing));*/
124 /* Round up the count. */
125 count = CEILING(count,2);
133 #ifdef LISP_FEATURE_GENCGC
134 #include "gencgc-internal.h"
136 #include "cheneygc-internal.h"
139 #endif /* _GC_INTERNAL_H_ */