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) \
24 if (!(ex)) gc_abort(); \
26 # define gc_assert_verbose(ex, fmt, ...) \
29 fprintf(stderr, fmt, ## __VA_ARGS__); \
34 # define gc_assert(ex)
35 # define gc_assert_verbose(ex, fmt, ...)
39 lose("GC invariant lost, file \"%s\", line %d\n", __FILE__, __LINE__)
41 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
43 static inline unsigned long
44 NWORDS(unsigned long x, unsigned long n_bits)
46 /* A good compiler should be able to constant-fold this whole thing,
47 even with the conditional. */
48 if(n_bits <= N_WORD_BITS) {
49 unsigned long elements_per_word = N_WORD_BITS/n_bits;
51 return CEILING(x, elements_per_word)/elements_per_word;
54 /* FIXME: should have some sort of assertion that N_WORD_BITS
55 evenly divides n_bits */
56 return x * (n_bits/N_WORD_BITS);
60 /* FIXME: Shouldn't this be defined in sbcl.h? */
62 /* FIXME (1) this could probably be defined using something like
63 * sizeof(lispobj)*floor(sizeof(struct simple_fun)/sizeof(lispobj))
64 * - FUN_POINTER_LOWTAG
65 * as I'm reasonably sure that simple_fun->code must always be the
66 * last slot in the object
68 * FIXME (2) it also appears in purify.c, and it has a different value
69 * for SPARC users in that bit
72 #if defined(LISP_FEATURE_SPARC)
73 #define FUN_RAW_ADDR_OFFSET 0
75 #define FUN_RAW_ADDR_OFFSET (6*sizeof(lispobj) - FUN_POINTER_LOWTAG)
78 /* values for the *_alloc_* parameters */
79 #define FREE_PAGE_FLAG 0
80 #define BOXED_PAGE_FLAG 1
81 #define UNBOXED_PAGE_FLAG 2
82 #define OPEN_REGION_PAGE_FLAG 4
85 #define ALLOC_UNBOXED 1
88 void *gc_general_alloc(long nbytes,int unboxed_p,int quick_p);
90 extern long (*scavtab[256])(lispobj *where, lispobj object);
91 extern lispobj (*transother[256])(lispobj object);
92 extern long (*sizetab[256])(lispobj *where);
94 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
95 extern struct hash_table *weak_hash_tables; /* in gc-common.c */
97 extern void scavenge(lispobj *start, long n_words);
98 extern void scavenge_interrupt_contexts(void);
99 extern void scav_weak_hash_tables(void);
100 extern void scan_weak_hash_tables(void);
101 extern void scan_weak_pointers(void);
103 lispobj copy_large_unboxed_object(lispobj object, long nwords);
104 lispobj copy_unboxed_object(lispobj object, long nwords);
105 lispobj copy_large_object(lispobj object, long nwords);
106 lispobj copy_object(lispobj object, long nwords);
108 lispobj *search_read_only_space(void *pointer);
109 lispobj *search_static_space(void *pointer);
110 lispobj *search_dynamic_space(void *pointer);
112 lispobj *gc_search_space(lispobj *start, size_t words, lispobj *pointer);
116 #ifdef LISP_FEATURE_GENCGC
117 #include "gencgc-internal.h"
119 #include "cheneygc-internal.h"
122 #if N_WORD_BITS == 32
123 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
124 #elif N_WORD_BITS == 64
125 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
128 #endif /* _GC_INTERNAL_H_ */