cca1602ce9cb876588a30bfcb101591695d17a42
[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 "gencgc-alloc-region.h"
23 #include "genesis/code.h"
24
25 /* Size of a page, in bytes. FIXME: needs to be conditionalized per
26  * architecture, preferably by someone with a clue as to what page
27  * sizes are on archs other than x86 and PPC - Patrik */
28 #define PAGE_BYTES 4096
29
30
31 void gc_free_heap(void);
32 inline int find_page_index(void *);
33 inline void *page_address(int);
34 int gencgc_handle_wp_violation(void *);
35 \f
36 struct page {
37
38     unsigned
39         /* This is set when the page is write-protected. This should
40          * always reflect the actual write_protect status of a page.
41          * (If the page is written into, we catch the exception, make
42          * the page writable, and clear this flag.) */
43         write_protected :1,
44         /* This flag is set when the above write_protected flag is 
45          * cleared by the SIGBUS handler (or SIGSEGV handler, for some
46          * OSes). This is useful for re-scavenging pages that are
47          * written during a GC. */
48         write_protected_cleared :1,
49         /* the region the page is allocated to: 0 for a free page; 1
50          * for boxed objects; 2 for unboxed objects. If the page is
51          * free the following slots are invalid (well the bytes_used
52          * must be 0). */
53         allocated :3,
54         /* If this page should not be moved during a GC then this flag
55          * is set. It's only valid during a GC for allocated pages. */
56         dont_move :1,
57         /* If the page is part of a large object then this flag is
58          * set. No other objects should be allocated to these pages.
59          * This is only valid when the page is allocated. */
60         large_object :1;
61
62     /* the generation that this page belongs to. This should be valid
63      * for all pages that may have objects allocated, even current
64      * allocation region pages - this allows the space of an object to
65      * be easily determined. */
66     int  gen;
67
68     /* the number of bytes of this page that are used. This may be less
69      * than the actual bytes used for pages within the current
70      * allocation regions. It should be 0 for all unallocated pages (not
71      * hard to achieve). */
72     int  bytes_used;
73
74     /* The name of this field is not well-chosen for its actual use.
75      * This is the offset from the start of the page to the start 
76      * of the alloc_region which contains/contained it.  It's negative or 0
77      */
78     int  first_object_offset;
79 };
80
81 /* values for the page.allocated field */
82
83 \f
84 /* the number of pages needed for the dynamic space - rounding up */
85 #define NUM_PAGES ((DYNAMIC_SPACE_SIZE+PAGE_BYTES-1)/PAGE_BYTES)
86
87 extern struct page page_table[NUM_PAGES];
88
89 \f
90 /* forward declarations */
91
92 void sniff_code_object(struct code *code, unsigned displacement);
93 void gencgc_apply_code_fixups(struct code *old_code, struct code *new_code);
94
95 int  update_x86_dynamic_space_free_pointer(void);
96 void  gc_alloc_update_page_tables(int unboxed,
97                                   struct alloc_region *alloc_region);
98 void gc_alloc_update_all_page_tables(void);
99 void gc_set_region_empty(struct alloc_region *region);
100
101 /*
102  * predicates
103  */
104 static inline int 
105 space_matches_p(lispobj obj, int space)
106 {
107     int page_index=(void*)obj - (void *)DYNAMIC_SPACE_START;
108     return ((page_index >= 0)
109             && ((page_index =
110                  ((unsigned int)page_index)/PAGE_BYTES) < NUM_PAGES)
111             && (page_table[page_index].gen == space));
112 }
113
114 static inline boolean
115 from_space_p(lispobj obj)
116 {
117     return space_matches_p(obj,from_space);
118 }
119
120 static inline boolean
121 new_space_p(lispobj obj)
122 {
123     return space_matches_p(obj,new_space);
124 }
125
126
127
128 #endif