f04bf6e38b1e494877878da5a42208f3a202552f
[sbcl.git] / src / runtime / gc-internal.h
1 /*
2  * garbage collection - shared definitions for modules "inside" the GC system
3  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
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.
14  */
15
16 #ifndef _GC_INTERNAL_H_
17 #define _GC_INTERNAL_H_
18
19 /* disabling gc assertions made no discernable difference to GC speed,
20  * last I tried it - dan 2003.12.21 */
21 #if 1
22 # define gc_assert(ex)                                                 \
23 do {                                                                   \
24     if (!(ex)) gc_abort();                                             \
25 } while (0)
26 # define gc_assert_verbose(ex, fmt, ...)                               \
27 do {                                                                   \
28     if (!(ex)) {                                                       \
29         fprintf(stderr, fmt, ## __VA_ARGS__);                          \
30         gc_abort();                                                    \
31     }                                                                  \
32 } while (0)
33 #else
34 # define gc_assert(ex)
35 # define gc_assert_verbose(ex, fmt, ...)
36 #endif
37
38 #define gc_abort()                                                     \
39   lose("GC invariant lost, file \"%s\", line %d\n", __FILE__, __LINE__)
40
41 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
42
43 static inline unsigned long
44 NWORDS(unsigned long x, unsigned long n_bits)
45 {
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;
50
51         return CEILING(x, elements_per_word)/elements_per_word;
52     }
53     else {
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);
57     }
58 }
59
60 /* FIXME: Shouldn't this be defined in sbcl.h? */
61
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
67
68  * FIXME (2) it also appears in purify.c, and it has a different value
69  * for SPARC users in that bit
70  */
71
72 #define FUN_RAW_ADDR_OFFSET (6*sizeof(lispobj) - FUN_POINTER_LOWTAG)
73
74 /* values for the *_alloc_* parameters */
75 #define FREE_PAGE_FLAG 0
76 #define BOXED_PAGE_FLAG 1
77 #define UNBOXED_PAGE_FLAG 2
78 #define OPEN_REGION_PAGE_FLAG 4
79
80 #define ALLOC_BOXED 0
81 #define ALLOC_UNBOXED 1
82 #define ALLOC_QUICK 1
83
84 void *gc_general_alloc(long nbytes,int unboxed_p,int quick_p);
85
86 extern long (*scavtab[256])(lispobj *where, lispobj object);
87 extern lispobj (*transother[256])(lispobj object);
88 extern long (*sizetab[256])(lispobj *where);
89
90 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
91
92 extern void scavenge(lispobj *start, long n_words);
93 extern void scan_weak_pointers(void);
94
95 lispobj  copy_large_unboxed_object(lispobj object, long nwords);
96 lispobj  copy_unboxed_object(lispobj object, long nwords);
97 lispobj  copy_large_object(lispobj object, long nwords);
98 lispobj  copy_object(lispobj object, long nwords);
99
100 lispobj *search_read_only_space(void *pointer);
101 lispobj *search_static_space(void *pointer);
102 lispobj *search_dynamic_space(void *pointer);
103
104 lispobj *gc_search_space(lispobj *start, size_t words, lispobj *pointer);
105
106 #include "fixnump.h"
107
108 #ifdef LISP_FEATURE_GENCGC
109 #include "gencgc-internal.h"
110 #else
111 #include "cheneygc-internal.h"
112 #endif
113
114 #endif /* _GC_INTERNAL_H_ */