0.9.9.36:
[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 #if defined(LISP_FEATURE_SPARC)
73 #define FUN_RAW_ADDR_OFFSET 0
74 #else
75 #define FUN_RAW_ADDR_OFFSET (6*sizeof(lispobj) - FUN_POINTER_LOWTAG)
76 #endif
77
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
83
84 #define ALLOC_BOXED 0
85 #define ALLOC_UNBOXED 1
86 #define ALLOC_QUICK 1
87
88 void *gc_general_alloc(long nbytes,int unboxed_p,int quick_p);
89
90 extern long (*scavtab[256])(lispobj *where, lispobj object);
91 extern lispobj (*transother[256])(lispobj object);
92 extern long (*sizetab[256])(lispobj *where);
93
94 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
95
96 extern void scavenge(lispobj *start, long n_words);
97 extern void scavenge_interrupt_contexts(void);
98 extern void scan_weak_pointers(void);
99
100 lispobj  copy_large_unboxed_object(lispobj object, long nwords);
101 lispobj  copy_unboxed_object(lispobj object, long nwords);
102 lispobj  copy_large_object(lispobj object, long nwords);
103 lispobj  copy_object(lispobj object, long nwords);
104
105 lispobj *search_read_only_space(void *pointer);
106 lispobj *search_static_space(void *pointer);
107 lispobj *search_dynamic_space(void *pointer);
108
109 lispobj *gc_search_space(lispobj *start, size_t words, lispobj *pointer);
110
111 #include "fixnump.h"
112
113 #ifdef LISP_FEATURE_GENCGC
114 #include "gencgc-internal.h"
115 #else
116 #include "cheneygc-internal.h"
117 #endif
118
119 #endif /* _GC_INTERNAL_H_ */