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 #include <genesis/simple-fun.h>
22 /* disabling gc assertions made no discernable difference to GC speed,
23 * last I tried it - dan 2003.12.21
25 * And it's unsafe to do so while things like gc_assert(0 ==
26 * thread_mutex_lock(&allocation_lock)) exist. - MG 2009-01-13
29 # define gc_assert(ex) \
31 if (!(ex)) gc_abort(); \
33 # define gc_assert_verbose(ex, fmt, ...) \
36 fprintf(stderr, fmt, ## __VA_ARGS__); \
41 # define gc_assert(ex)
42 # define gc_assert_verbose(ex, fmt, ...)
46 lose("GC invariant lost, file \"%s\", line %d\n", __FILE__, __LINE__)
48 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
50 static inline unsigned long
51 NWORDS(unsigned long x, unsigned long n_bits)
53 /* A good compiler should be able to constant-fold this whole thing,
54 even with the conditional. */
55 if(n_bits <= N_WORD_BITS) {
56 unsigned long elements_per_word = N_WORD_BITS/n_bits;
58 return CEILING(x, elements_per_word)/elements_per_word;
61 /* FIXME: should have some sort of assertion that N_WORD_BITS
62 evenly divides n_bits */
63 return x * (n_bits/N_WORD_BITS);
67 /* FIXME: Shouldn't this be defined in sbcl.h? */
69 #if defined(LISP_FEATURE_SPARC)
70 #define FUN_RAW_ADDR_OFFSET 0
72 #define FUN_RAW_ADDR_OFFSET (offsetof(struct simple_fun, code) - FUN_POINTER_LOWTAG)
75 /* values for the *_alloc_* parameters */
76 #define FREE_PAGE_FLAG 0
77 #define BOXED_PAGE_FLAG 1
78 #define UNBOXED_PAGE_FLAG 2
79 #define OPEN_REGION_PAGE_FLAG 4
80 #define CODE_PAGE_FLAG (BOXED_PAGE_FLAG|UNBOXED_PAGE_FLAG)
83 #define ALLOC_UNBOXED 1
86 #ifdef LISP_FEATURE_GENCGC
87 #include "gencgc-alloc-region.h"
89 gc_alloc_with_region(long nbytes,int page_type_flag, struct alloc_region *my_region,
92 gc_general_alloc(long nbytes, int page_type_flag, int quick_p)
94 struct alloc_region *my_region;
95 if (UNBOXED_PAGE_FLAG == page_type_flag) {
96 my_region = &unboxed_region;
97 } else if (BOXED_PAGE_FLAG & page_type_flag) {
98 my_region = &boxed_region;
100 lose("bad page type flag: %d", page_type_flag);
102 return gc_alloc_with_region(nbytes, page_type_flag, my_region, quick_p);
105 extern void *gc_general_alloc(long nbytes,int page_type_flag,int quick_p);
108 extern long (*scavtab[256])(lispobj *where, lispobj object);
109 extern lispobj (*transother[256])(lispobj object);
110 extern long (*sizetab[256])(lispobj *where);
112 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
113 extern struct hash_table *weak_hash_tables; /* in gc-common.c */
115 extern void scavenge(lispobj *start, long n_words);
116 extern void scavenge_interrupt_contexts(struct thread *thread);
117 extern void scav_weak_hash_tables(void);
118 extern void scan_weak_hash_tables(void);
119 extern void scan_weak_pointers(void);
121 lispobj copy_large_unboxed_object(lispobj object, long nwords);
122 lispobj copy_unboxed_object(lispobj object, long nwords);
123 lispobj copy_large_object(lispobj object, long nwords);
124 lispobj copy_object(lispobj object, long nwords);
125 lispobj copy_code_object(lispobj object, long nwords);
127 lispobj *search_read_only_space(void *pointer);
128 lispobj *search_static_space(void *pointer);
129 lispobj *search_dynamic_space(void *pointer);
131 lispobj *gc_search_space(lispobj *start, size_t words, lispobj *pointer);
133 extern void scrub_control_stack();
137 #ifdef LISP_FEATURE_GENCGC
138 #include "gencgc-internal.h"
140 #include "cheneygc-internal.h"
143 #if N_WORD_BITS == 32
144 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
145 #elif N_WORD_BITS == 64
146 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
149 #endif /* _GC_INTERNAL_H_ */