85304fe4f187c6bf30bb9225fc739bd65abced28
[sbcl.git] / src / runtime / gencgc.h
1 /*
2  * Generational Conservative Garbage Collector for SBCL x86
3  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
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.
14  */
15
16 #ifndef _GENCGC_H_
17 #define _GENCGC_H_
18
19 void gc_free_heap(void);
20 inline int find_page_index(void *);
21 inline void *page_address(int);
22 int gencgc_handle_wp_violation(void *);
23 lispobj *search_dynamic_space(lispobj *);
24 \f
25 struct page {
26
27     unsigned
28         /* This is set when the page is write-protected. This should
29          * always reflect the actual write_protect status of a page.
30          * (If the page is written into, we catch the exception, make
31          * the page writable, and clear this flag.) */
32         write_protected :1,
33         /* This flag is set when the above write_protected flag is
34          * cleared by the sigbus handler. This is useful for
35          * re-scavenging pages that are written during a GC. */
36         write_protected_cleared :1,
37         /* The region the page is allocated to: 0 for a free page; 1
38          * for boxed objects; 2 for unboxed objects. If the page is
39          * free the following slots are invalid (well the bytes_used
40          * must be 0). */
41         allocated :2,
42         /* If this page should not be moved during a GC then this flag
43          * is set. It's only valid during a GC for allocated pages. */
44         dont_move :1,
45         /* If the page is part of a large object then this flag is
46          * set. No other objects should be allocated to these pages.
47          * This is only valid when the page is allocated. */
48         large_object :1;
49
50     /* the generation that this page belongs to. This should be valid
51      * for all pages that may have objects allocated, even current
52      * allocation region pages - this allows the space of an object to
53      * be easily determined. */
54     int  gen;
55
56     /* the number of bytes of this page that are used. This may be less
57      * than the actual bytes used for pages within the current
58      * allocation regions. It should be 0 for all unallocated pages (not
59      * hard to achieve). */
60     int  bytes_used;
61
62     /* It is important to know the offset to the first object in the
63      * page. Currently it's only important to know if an object starts
64      * at the beginning of the page in which case the offset would be 0. */
65     int  first_object_offset;
66 };
67
68 #define FREE_PAGE 0
69 #define BOXED_PAGE 1
70 #define UNBOXED_PAGE 2
71 \f
72 /* the number of pages needed for the dynamic space - rounding up */
73 #define NUM_PAGES ((DYNAMIC_SPACE_SIZE+4095)/4096)
74 extern struct page page_table[NUM_PAGES];
75 \f
76 /* Abstract out the data for an allocation region allowing a single
77  * routine to be used for allocation and closing. */
78 struct alloc_region {
79
80     /* These two are needed for quick allocation. */
81     void  *free_pointer;
82     void  *end_addr; /* pointer to the byte after the last usable byte */
83
84     /* needed when closing the region */
85     int  first_page;
86     int  last_page;
87     void  *start_addr;
88 };
89
90 extern struct alloc_region  boxed_region;
91 extern struct alloc_region  unboxed_region;
92 \f
93 void  gencgc_pickup_dynamic(void);
94
95 void sniff_code_object(struct code *code, unsigned displacement);
96
97 int  update_x86_dynamic_space_free_pointer(void);
98 void  gc_alloc_update_page_tables(int unboxed,
99                                   struct alloc_region *alloc_region);
100
101 #endif _GENCGC_H_