1.0.23.10: allocate code objects using allocation CODE_PAGE_FLAG
[sbcl/tcr.git] / src / runtime / gc-internal.h
blob276c9c3fb63ca8146b45ffbe884478c7e2607e17
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>
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
40 #define gc_abort() \
41 lose("GC invariant lost, file \"%s\", line %d\n", __FILE__, __LINE__)
43 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
45 static inline unsigned long
46 NWORDS(unsigned long x, unsigned long n_bits)
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;
53 return CEILING(x, elements_per_word)/elements_per_word;
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);
62 /* FIXME: Shouldn't this be defined in sbcl.h? */
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
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 #define CODE_PAGE_FLAG (BOXED_PAGE_FLAG|UNBOXED_PAGE_FLAG)
77 #define ALLOC_BOXED 0
78 #define ALLOC_UNBOXED 1
79 #define ALLOC_QUICK 1
81 #ifdef LISP_FEATURE_GENCGC
82 #include "gencgc-alloc-region.h"
83 void *
84 gc_alloc_with_region(long nbytes,int page_type_flag, struct alloc_region *my_region,
85 int quick_p);
86 static inline void *
87 gc_general_alloc(long nbytes, int page_type_flag, int quick_p)
89 struct alloc_region *my_region;
90 if (UNBOXED_PAGE_FLAG == page_type_flag) {
91 my_region = &unboxed_region;
92 } else if (BOXED_PAGE_FLAG & page_type_flag) {
93 my_region = &boxed_region;
94 } else {
95 lose("bad page type flag: %d", page_type_flag);
97 return gc_alloc_with_region(nbytes, page_type_flag, my_region, quick_p);
99 #else
100 void *gc_general_alloc(long nbytes,int page_type_flag,int quick_p);
101 #endif
103 extern long (*scavtab[256])(lispobj *where, lispobj object);
104 extern lispobj (*transother[256])(lispobj object);
105 extern long (*sizetab[256])(lispobj *where);
107 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
108 extern struct hash_table *weak_hash_tables; /* in gc-common.c */
110 extern void scavenge(lispobj *start, long n_words);
111 extern void scavenge_interrupt_contexts(void);
112 extern void scav_weak_hash_tables(void);
113 extern void scan_weak_hash_tables(void);
114 extern void scan_weak_pointers(void);
116 lispobj copy_large_unboxed_object(lispobj object, long nwords);
117 lispobj copy_unboxed_object(lispobj object, long nwords);
118 lispobj copy_large_object(lispobj object, long nwords);
119 lispobj copy_object(lispobj object, long nwords);
120 lispobj copy_code_object(lispobj object, long nwords);
122 lispobj *search_read_only_space(void *pointer);
123 lispobj *search_static_space(void *pointer);
124 lispobj *search_dynamic_space(void *pointer);
126 lispobj *gc_search_space(lispobj *start, size_t words, lispobj *pointer);
128 #include "fixnump.h"
130 #ifdef LISP_FEATURE_GENCGC
131 #include "gencgc-internal.h"
132 #else
133 #include "cheneygc-internal.h"
134 #endif
136 #if N_WORD_BITS == 32
137 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
138 #elif N_WORD_BITS == 64
139 # define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
140 #endif
142 #endif /* _GC_INTERNAL_H_ */