1.0.23.7: introduce page type flags
[sbcl.git] / src / runtime / gencgc-internal.h
1 /*
2  * Generational Conservative Garbage Collector for SBCL x86
3  *
4  * inline functions that gc-common.c needs sight of
5  */
6
7
8 /*
9  * This software is part of the SBCL system. See the README file for
10  * more information.
11  *
12  * This software is derived from the CMU CL system, which was
13  * written at Carnegie Mellon University and released into the
14  * public domain. The software is in the public domain and is
15  * provided with absolutely no warranty. See the COPYING and CREDITS
16  * files for more information.
17  */
18
19 #ifndef _GENCGC_INTERNAL_H_
20 #define _GENCGC_INTERNAL_H_
21
22 #include <limits.h>
23 #include "gc.h"
24 #include "gencgc-alloc-region.h"
25 #include "genesis/code.h"
26
27 void gc_free_heap(void);
28 inline page_index_t find_page_index(void *);
29 inline void *page_address(page_index_t);
30 int gencgc_handle_wp_violation(void *);
31 \f
32
33 /* Note that this structure is also used from Lisp-side in
34  * src/code/room.lisp, and the Lisp-side structure layout is currently
35  * not groveled from C code but hardcoded. Any changes to the
36  * structure layout need to be also made there.
37  *
38  * FIXME: We should probably just define this structure in Lisp, and
39  * output the C version in genesis. -- JES, 2006-12-30.
40  */
41 struct page {
42     /* This is the offset from the start of the page to the start of
43      * the alloc_region which contains/contained it.
44      */
45     unsigned long region_start_offset;
46
47     /* the number of bytes of this page that are used. This may be less
48      * than the actual bytes used for pages within the current
49      * allocation regions. It should be 0 for all unallocated pages (not
50      * hard to achieve).
51      */
52 #if PAGE_BYTES > USHRT_MAX
53     unsigned int bytes_used;
54 #else
55     unsigned short bytes_used;
56 #endif
57
58     unsigned
59         /* This is set when the page is write-protected. This should
60          * always reflect the actual write_protect status of a page.
61          * (If the page is written into, we catch the exception, make
62          * the page writable, and clear this flag.) */
63         write_protected :1,
64         /* This flag is set when the above write_protected flag is
65          * cleared by the SIGBUS handler (or SIGSEGV handler, for some
66          * OSes). This is useful for re-scavenging pages that are
67          * written during a GC. */
68         write_protected_cleared :1,
69         /* the region the page is allocated to: 0 for a free page; 1
70          * for boxed objects; 2 for unboxed objects. If the page is
71          * free the following slots are invalid (well the bytes_used
72          * must be 0). */
73         allocated :3,
74         /* If this page should not be moved during a GC then this flag
75          * is set. It's only valid during a GC for allocated pages. */
76         dont_move :1,
77         /* If the page is part of a large object then this flag is
78          * set. No other objects should be allocated to these pages.
79          * This is only valid when the page is allocated. */
80         large_object :1,
81         /* True if the page is known to contain only zeroes. */
82         need_to_zero :1;
83
84     /* the generation that this page belongs to. This should be valid
85      * for all pages that may have objects allocated, even current
86      * allocation region pages - this allows the space of an object to
87      * be easily determined. */
88     generation_index_t gen;
89 };
90
91
92 /* values for the page.allocated field */
93
94 \f
95 extern page_index_t page_table_pages;
96 extern struct page *page_table;
97
98 \f
99 /* forward declarations */
100
101 void sniff_code_object(struct code *code, unsigned long displacement);
102 void gencgc_apply_code_fixups(struct code *old_code, struct code *new_code);
103
104 long update_dynamic_space_free_pointer(void);
105 void gc_alloc_update_page_tables(int page_type_flag,
106                                  struct alloc_region *alloc_region);
107 void gc_alloc_update_all_page_tables(void);
108 void gc_set_region_empty(struct alloc_region *region);
109
110 /*
111  * predicates
112  */
113
114 static inline boolean
115 space_matches_p(lispobj obj, generation_index_t space)
116 {
117     if (obj >= DYNAMIC_SPACE_START) {
118         page_index_t page_index=((pointer_sized_uint_t)obj
119                                  - DYNAMIC_SPACE_START) / PAGE_BYTES;
120         return ((page_index < page_table_pages) &&
121                 (page_table[page_index].gen == space));
122     } else {
123         return 0;
124     }
125 }
126
127 static inline boolean
128 from_space_p(lispobj obj)
129 {
130     return space_matches_p(obj,from_space);
131 }
132
133 static inline boolean
134 new_space_p(lispobj obj)
135 {
136     return space_matches_p(obj,new_space);
137 }
138
139 extern page_index_t last_free_page;
140 extern boolean gencgc_partial_pickup;
141
142 #endif