2 * Generational Conservative Garbage Collector for SBCL x86
4 * inline functions that gc-common.c needs sight of
9 * This software is part of the SBCL system. See the README file for
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.
19 #ifndef _GENCGC_INTERNAL_H_
20 #define _GENCGC_INTERNAL_H_
24 #include "gencgc-alloc-region.h"
25 #include "genesis/code.h"
27 #define PAGE_BYTES GENCGC_PAGE_SIZE
29 void gc_free_heap(void);
30 inline page_index_t find_page_index(void *);
31 inline void *page_address(page_index_t);
32 int gencgc_handle_wp_violation(void *);
37 /* This is set when the page is write-protected. This should
38 * always reflect the actual write_protect status of a page.
39 * (If the page is written into, we catch the exception, make
40 * the page writable, and clear this flag.) */
42 /* This flag is set when the above write_protected flag is
43 * cleared by the SIGBUS handler (or SIGSEGV handler, for some
44 * OSes). This is useful for re-scavenging pages that are
45 * written during a GC. */
46 write_protected_cleared :1,
47 /* the region the page is allocated to: 0 for a free page; 1
48 * for boxed objects; 2 for unboxed objects. If the page is
49 * free the following slots are invalid (well the bytes_used
52 /* If this page should not be moved during a GC then this flag
53 * is set. It's only valid during a GC for allocated pages. */
55 /* If the page is part of a large object then this flag is
56 * set. No other objects should be allocated to these pages.
57 * This is only valid when the page is allocated. */
60 /* the generation that this page belongs to. This should be valid
61 * for all pages that may have objects allocated, even current
62 * allocation region pages - this allows the space of an object to
63 * be easily determined. */
64 generation_index_t gen;
66 /* the number of bytes of this page that are used. This may be less
67 * than the actual bytes used for pages within the current
68 * allocation regions. It should be 0 for all unallocated pages (not
69 * hard to achieve). */
72 /* The name of this field is not well-chosen for its actual use.
73 * This is the offset from the start of the page to the start
74 * of the alloc_region which contains/contained it. It's negative or 0
76 long first_object_offset;
79 /* values for the page.allocated field */
82 /* the number of pages needed for the dynamic space - rounding up */
83 #define NUM_PAGES ((page_index_t) ((DYNAMIC_SPACE_SIZE+PAGE_BYTES-1)/PAGE_BYTES))
85 extern struct page page_table[NUM_PAGES];
88 /* forward declarations */
90 void sniff_code_object(struct code *code, unsigned long displacement);
91 void gencgc_apply_code_fixups(struct code *old_code, struct code *new_code);
93 long update_dynamic_space_free_pointer(void);
94 void gc_alloc_update_page_tables(int unboxed,
95 struct alloc_region *alloc_region);
96 void gc_alloc_update_all_page_tables(void);
97 void gc_set_region_empty(struct alloc_region *region);
102 static inline boolean
103 space_matches_p(lispobj obj, generation_index_t space)
105 page_index_t page_index=(void*)obj - (void *)DYNAMIC_SPACE_START;
106 return ((page_index >= 0)
108 ((unsigned long)page_index)/PAGE_BYTES) < NUM_PAGES)
109 && (page_table[page_index].gen == space));
112 static inline boolean
113 from_space_p(lispobj obj)
115 return space_matches_p(obj,from_space);
118 static inline boolean
119 new_space_p(lispobj obj)
121 return space_matches_p(obj,new_space);
124 extern page_index_t last_free_page;
125 extern boolean gencgc_partial_pickup;