d9d480458eb2d916a6a2ab063d0399871689fb3b
[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 #include "genesis/code.h"
20
21 void gc_free_heap(void);
22 inline int find_page_index(void *);
23 inline void *page_address(int);
24 int gencgc_handle_wp_violation(void *);
25 lispobj *search_dynamic_space(lispobj *);
26 \f
27 struct page {
28
29     unsigned
30         /* This is set when the page is write-protected. This should
31          * always reflect the actual write_protect status of a page.
32          * (If the page is written into, we catch the exception, make
33          * the page writable, and clear this flag.) */
34         write_protected :1,
35         /* This flag is set when the above write_protected flag is 
36          * cleared by the SIGBUS handler (or SIGSEGV handler, for some
37          * OSes). This is useful for re-scavenging pages that are
38          * written during a GC. */
39         write_protected_cleared :1,
40         /* the region the page is allocated to: 0 for a free page; 1
41          * for boxed objects; 2 for unboxed objects. If the page is
42          * free the following slots are invalid (well the bytes_used
43          * must be 0). */
44         allocated :2,
45         /* If this page should not be moved during a GC then this flag
46          * is set. It's only valid during a GC for allocated pages. */
47         dont_move :1,
48         /* If the page is part of a large object then this flag is
49          * set. No other objects should be allocated to these pages.
50          * This is only valid when the page is allocated. */
51         large_object :1;
52
53     /* the generation that this page belongs to. This should be valid
54      * for all pages that may have objects allocated, even current
55      * allocation region pages - this allows the space of an object to
56      * be easily determined. */
57     int  gen;
58
59     /* the number of bytes of this page that are used. This may be less
60      * than the actual bytes used for pages within the current
61      * allocation regions. It should be 0 for all unallocated pages (not
62      * hard to achieve). */
63     int  bytes_used;
64
65     /* It is important to know the offset to the first object in the
66      * page. Currently it's only important to know if an object starts
67      * at the beginning of the page in which case the offset would be 0. */
68     int  first_object_offset;
69 };
70
71 /* values for the page.allocated field */
72 #define FREE_PAGE 0
73 #define BOXED_PAGE 1
74 #define UNBOXED_PAGE 2
75
76 /* values for the *_alloc_* parameters */
77 #define ALLOC_BOXED 0
78 #define ALLOC_UNBOXED 1
79 #define ALLOC_QUICK 1
80
81 \f
82 /* the number of pages needed for the dynamic space - rounding up */
83 #define NUM_PAGES ((DYNAMIC_SPACE_SIZE+4095)/4096)
84 extern struct page page_table[NUM_PAGES];
85 \f
86 \f
87 void  gencgc_pickup_dynamic(void);
88
89 void sniff_code_object(struct code *code, unsigned displacement);
90
91 int  update_x86_dynamic_space_free_pointer(void);
92 void  gc_alloc_update_page_tables(int unboxed,
93                                   struct alloc_region *alloc_region);
94 void gc_alloc_update_all_page_tables(void);
95 void gc_set_region_empty(struct alloc_region *region);
96 #endif _GENCGC_H_