x86-64: Integrate Paul Khuong's interleaved raw slot feature.
[sbcl.git] / src / runtime / gc-internal.h
blob4a873ef3aade6c763abc149e1320837770f02b76
1 /*
2 * garbage collection - shared definitions for modules "inside" the GC system
3 */
5 /*
6 * This software is part of the SBCL system. See the README file for
7 * more information.
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 #include <genesis/simple-fun.h>
20 #include "thread.h"
21 #include "interr.h"
23 #ifdef LISP_FEATURE_GENCGC
24 #include "gencgc-internal.h"
25 #else
26 #include "cheneygc-internal.h"
27 #endif
29 /* disabling gc assertions made no discernable difference to GC speed,
30 * last I tried it - dan 2003.12.21
32 * And it's unsafe to do so while things like gc_assert(0 ==
33 * thread_mutex_lock(&allocation_lock)) exist. - MG 2009-01-13
35 #if 1
36 # define gc_assert(ex) \
37 do { \
38 if (!(ex)) gc_abort(); \
39 } while (0)
40 # define gc_assert_verbose(ex, fmt, ...) \
41 do { \
42 if (!(ex)) { \
43 fprintf(stderr, fmt, ## __VA_ARGS__); \
44 gc_abort(); \
45 } \
46 } while (0)
47 #else
48 # define gc_assert(ex)
49 # define gc_assert_verbose(ex, fmt, ...)
50 #endif
52 #define gc_abort() \
53 lose("GC invariant lost, file \"%s\", line %d\n", __FILE__, __LINE__)
55 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
57 static inline uword_t
58 NWORDS(uword_t x, uword_t n_bits)
60 /* A good compiler should be able to constant-fold this whole thing,
61 even with the conditional. */
62 if(n_bits <= N_WORD_BITS) {
63 uword_t elements_per_word = N_WORD_BITS/n_bits;
65 return CEILING(x, elements_per_word)/elements_per_word;
67 else {
68 /* FIXME: should have some sort of assertion that N_WORD_BITS
69 evenly divides n_bits */
70 return x * (n_bits/N_WORD_BITS);
74 /* FIXME: Shouldn't this be defined in sbcl.h? */
76 #if defined(LISP_FEATURE_SPARC) || defined(LISP_FEATURE_ARM)
77 #define FUN_RAW_ADDR_OFFSET 0
78 #else
79 #define FUN_RAW_ADDR_OFFSET (offsetof(struct simple_fun, code) - FUN_POINTER_LOWTAG)
80 #endif
82 /* values for the *_alloc_* parameters, also see the commentary for
83 * struct page in gencgc-internal.h. FIXME: Perhaps these constants
84 * should be there, or at least defined on gencgc only? */
85 #define FREE_PAGE_FLAG 0
86 #define BOXED_PAGE_FLAG 1
87 #define UNBOXED_PAGE_FLAG 2
88 #define OPEN_REGION_PAGE_FLAG 4
89 #define CODE_PAGE_FLAG (BOXED_PAGE_FLAG|UNBOXED_PAGE_FLAG)
91 #define ALLOC_BOXED 0
92 #define ALLOC_UNBOXED 1
93 #define ALLOC_QUICK 1
95 #ifdef LISP_FEATURE_GENCGC
96 #include "gencgc-alloc-region.h"
97 void *
98 gc_alloc_with_region(sword_t nbytes,int page_type_flag, struct alloc_region *my_region,
99 int quick_p);
100 static inline void *
101 gc_general_alloc(sword_t nbytes, int page_type_flag, int quick_p)
103 struct alloc_region *my_region;
104 if (UNBOXED_PAGE_FLAG == page_type_flag) {
105 my_region = &unboxed_region;
106 } else if (BOXED_PAGE_FLAG & page_type_flag) {
107 my_region = &boxed_region;
108 } else {
109 lose("bad page type flag: %d", page_type_flag);
111 return gc_alloc_with_region(nbytes, page_type_flag, my_region, quick_p);
113 #else
114 extern void *gc_general_alloc(word_t nbytes,int page_type_flag,int quick_p);
115 #endif
117 static inline lispobj
118 gc_general_copy_object(lispobj object, long nwords, int page_type_flag)
120 lispobj *new;
122 gc_assert(is_lisp_pointer(object));
123 gc_assert(from_space_p(object));
124 gc_assert((nwords & 0x01) == 0);
126 /* Allocate space. */
127 new = gc_general_alloc(nwords*N_WORD_BYTES, page_type_flag, ALLOC_QUICK);
129 /* Copy the object. */
130 memcpy(new,native_pointer(object),nwords*N_WORD_BYTES);
132 return make_lispobj(new, lowtag_of(object));
135 extern sword_t (*scavtab[256])(lispobj *where, lispobj object);
136 extern lispobj (*transother[256])(lispobj object);
137 extern sword_t (*sizetab[256])(lispobj *where);
139 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
140 extern struct hash_table *weak_hash_tables; /* in gc-common.c */
142 extern void scavenge(lispobj *start, sword_t n_words);
143 extern void scavenge_interrupt_contexts(struct thread *thread);
144 extern void scav_weak_hash_tables(void);
145 extern void scan_weak_hash_tables(void);
146 extern void scan_weak_pointers(void);
148 lispobj copy_large_unboxed_object(lispobj object, sword_t nwords);
149 lispobj copy_unboxed_object(lispobj object, sword_t nwords);
150 lispobj copy_large_object(lispobj object, sword_t nwords);
151 lispobj copy_object(lispobj object, sword_t nwords);
152 lispobj copy_code_object(lispobj object, sword_t nwords);
154 lispobj *search_read_only_space(void *pointer);
155 lispobj *search_static_space(void *pointer);
156 lispobj *search_dynamic_space(void *pointer);
158 lispobj *gc_search_space(lispobj *start, size_t words, lispobj *pointer);
160 extern int looks_like_valid_lisp_pointer_p(lispobj pointer, lispobj *start_addr);
162 extern void scavenge_control_stack(struct thread *th);
163 extern void scrub_control_stack(void);
164 extern void scrub_thread_control_stack(struct thread *);
166 #include "fixnump.h"
168 #ifdef LISP_FEATURE_GENCGC
169 #include "gencgc-internal.h"
170 #else
171 #include "cheneygc-internal.h"
172 #endif
174 #if N_WORD_BITS == 32
175 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
176 #elif N_WORD_BITS == 64
177 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
178 #endif
180 #ifdef LISP_FEATURE_INTERLEAVED_RAW_SLOTS
181 extern void
182 instance_scan_interleaved(void (*proc)(),
183 lispobj *instance_ptr,
184 sword_t n_words,
185 lispobj *layout_obj);
186 #endif
188 #endif /* _GC_INTERNAL_H_ */