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_
22 #include "gencgc-alloc-region.h"
23 #include "genesis/code.h"
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
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 *);
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.) */
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
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. */
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. */
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. */
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). */
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
78 int first_object_offset;
81 /* values for the page.allocated field */
84 /* the number of pages needed for the dynamic space - rounding up */
85 #define NUM_PAGES ((DYNAMIC_SPACE_SIZE+PAGE_BYTES-1)/PAGE_BYTES)
87 extern struct page page_table[NUM_PAGES];
90 /* forward declarations */
92 void sniff_code_object(struct code *code, unsigned displacement);
93 void gencgc_apply_code_fixups(struct code *old_code, struct code *new_code);
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);
105 space_matches_p(lispobj obj, int space)
107 int page_index=(void*)obj - (void *)DYNAMIC_SPACE_START;
108 return ((page_index >= 0)
110 ((unsigned int)page_index)/PAGE_BYTES) < NUM_PAGES)
111 && (page_table[page_index].gen == space));
114 static inline boolean
115 from_space_p(lispobj obj)
117 return space_matches_p(obj,from_space);
120 static inline boolean
121 new_space_p(lispobj obj)
123 return space_matches_p(obj,new_space);