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>
21 /* disabling gc assertions made no discernable difference to GC speed,
22 * last I tried it - dan 2003.12.21
24 * And it's unsafe to do so while things like gc_assert(0 ==
25 * thread_mutex_lock(&allocation_lock)) exist. - MG 2009-01-13
28 # define gc_assert(ex) \
30 if (!(ex)) gc_abort(); \
32 # define gc_assert_verbose(ex, fmt, ...) \
35 fprintf(stderr, fmt, ## __VA_ARGS__); \
40 # define gc_assert(ex)
41 # define gc_assert_verbose(ex, fmt, ...)
45 lose("GC invariant lost, file \"%s\", line %d\n", __FILE__, __LINE__)
47 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
49 static inline unsigned long
50 NWORDS(unsigned long x
, unsigned long n_bits
)
52 /* A good compiler should be able to constant-fold this whole thing,
53 even with the conditional. */
54 if(n_bits
<= N_WORD_BITS
) {
55 unsigned long elements_per_word
= N_WORD_BITS
/n_bits
;
57 return CEILING(x
, elements_per_word
)/elements_per_word
;
60 /* FIXME: should have some sort of assertion that N_WORD_BITS
61 evenly divides n_bits */
62 return x
* (n_bits
/N_WORD_BITS
);
66 /* FIXME: Shouldn't this be defined in sbcl.h? */
68 #if defined(LISP_FEATURE_SPARC)
69 #define FUN_RAW_ADDR_OFFSET 0
71 #define FUN_RAW_ADDR_OFFSET (offsetof(struct simple_fun, code) - FUN_POINTER_LOWTAG)
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 #define CODE_PAGE_FLAG (BOXED_PAGE_FLAG|UNBOXED_PAGE_FLAG)
82 #define ALLOC_UNBOXED 1
85 #ifdef LISP_FEATURE_GENCGC
86 #include "gencgc-alloc-region.h"
88 gc_alloc_with_region(long nbytes
,int page_type_flag
, struct alloc_region
*my_region
,
91 gc_general_alloc(long nbytes
, int page_type_flag
, int quick_p
)
93 struct alloc_region
*my_region
;
94 if (UNBOXED_PAGE_FLAG
== page_type_flag
) {
95 my_region
= &unboxed_region
;
96 } else if (BOXED_PAGE_FLAG
& page_type_flag
) {
97 my_region
= &boxed_region
;
99 lose("bad page type flag: %d", page_type_flag
);
101 return gc_alloc_with_region(nbytes
, page_type_flag
, my_region
, quick_p
);
104 extern void *gc_general_alloc(long nbytes
,int page_type_flag
,int quick_p
);
107 extern long (*scavtab
[256])(lispobj
*where
, lispobj object
);
108 extern lispobj (*transother
[256])(lispobj object
);
109 extern long (*sizetab
[256])(lispobj
*where
);
111 extern struct weak_pointer
*weak_pointers
; /* in gc-common.c */
112 extern struct hash_table
*weak_hash_tables
; /* in gc-common.c */
114 extern void scavenge(lispobj
*start
, long n_words
);
115 extern void scavenge_interrupt_contexts(void);
116 extern void scav_weak_hash_tables(void);
117 extern void scan_weak_hash_tables(void);
118 extern void scan_weak_pointers(void);
120 lispobj
copy_large_unboxed_object(lispobj object
, long nwords
);
121 lispobj
copy_unboxed_object(lispobj object
, long nwords
);
122 lispobj
copy_large_object(lispobj object
, long nwords
);
123 lispobj
copy_object(lispobj object
, long nwords
);
124 lispobj
copy_code_object(lispobj object
, long nwords
);
126 lispobj
*search_read_only_space(void *pointer
);
127 lispobj
*search_static_space(void *pointer
);
128 lispobj
*search_dynamic_space(void *pointer
);
130 lispobj
*gc_search_space(lispobj
*start
, size_t words
, lispobj
*pointer
);
134 #ifdef LISP_FEATURE_GENCGC
135 #include "gencgc-internal.h"
137 #include "cheneygc-internal.h"
140 #if N_WORD_BITS == 32
141 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
142 #elif N_WORD_BITS == 64
143 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
146 #endif /* _GC_INTERNAL_H_ */