1.0.9.63: Disallow (:not) in #+/#- expressions.
[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 #include <genesis/simple-fun.h>
20
21 /* disabling gc assertions made no discernable difference to GC speed,
22  * last I tried it - dan 2003.12.21 */
23 #if 1
24 # define gc_assert(ex)                                                 \
25 do {                                                                   \
26     if (!(ex)) gc_abort();                                             \
27 } while (0)
28 # define gc_assert_verbose(ex, fmt, ...)                               \
29 do {                                                                   \
30     if (!(ex)) {                                                       \
31         fprintf(stderr, fmt, ## __VA_ARGS__);                          \
32         gc_abort();                                                    \
33     }                                                                  \
34 } while (0)
35 #else
36 # define gc_assert(ex)
37 # define gc_assert_verbose(ex, fmt, ...)
38 #endif
39
40 #define gc_abort()                                                     \
41   lose("GC invariant lost, file \"%s\", line %d\n", __FILE__, __LINE__)
42
43 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
44
45 static inline unsigned long
46 NWORDS(unsigned long x, unsigned long n_bits)
47 {
48     /* A good compiler should be able to constant-fold this whole thing,
49        even with the conditional. */
50     if(n_bits <= N_WORD_BITS) {
51         unsigned long elements_per_word = N_WORD_BITS/n_bits;
52
53         return CEILING(x, elements_per_word)/elements_per_word;
54     }
55     else {
56         /* FIXME: should have some sort of assertion that N_WORD_BITS
57            evenly divides n_bits */
58         return x * (n_bits/N_WORD_BITS);
59     }
60 }
61
62 /* FIXME: Shouldn't this be defined in sbcl.h? */
63
64 #if defined(LISP_FEATURE_SPARC)
65 #define FUN_RAW_ADDR_OFFSET 0
66 #else
67 #define FUN_RAW_ADDR_OFFSET (offsetof(struct simple_fun, code) - FUN_POINTER_LOWTAG)
68 #endif
69
70 /* values for the *_alloc_* parameters */
71 #define FREE_PAGE_FLAG 0
72 #define BOXED_PAGE_FLAG 1
73 #define UNBOXED_PAGE_FLAG 2
74 #define OPEN_REGION_PAGE_FLAG 4
75
76 #define ALLOC_BOXED 0
77 #define ALLOC_UNBOXED 1
78 #define ALLOC_QUICK 1
79
80 void *gc_general_alloc(long nbytes,int unboxed_p,int quick_p);
81
82 extern long (*scavtab[256])(lispobj *where, lispobj object);
83 extern lispobj (*transother[256])(lispobj object);
84 extern long (*sizetab[256])(lispobj *where);
85
86 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
87 extern struct hash_table *weak_hash_tables; /* in gc-common.c */
88
89 extern void scavenge(lispobj *start, long n_words);
90 extern void scavenge_interrupt_contexts(void);
91 extern void scav_weak_hash_tables(void);
92 extern void scan_weak_hash_tables(void);
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 #if N_WORD_BITS == 32
115 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
116 #elif N_WORD_BITS == 64
117 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
118 #endif
119
120 #endif /* _GC_INTERNAL_H_ */