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 void gc_free_heap(void);
28 extern page_index_t
find_page_index(void *);
29 extern void *page_address(page_index_t
);
30 int gencgc_handle_wp_violation(void *);
33 #if GENCGC_CARD_BYTES > USHRT_MAX
34 # if GENCGC_CARD_BYTES > UINT_MAX
35 # error "GENCGC_CARD_BYTES unexpectedly large."
37 # define PAGE_BYTES_FMT "u"
38 typedef unsigned int page_bytes_t
;
41 # define PAGE_BYTES_FMT "hu"
42 typedef unsigned short page_bytes_t
;
45 typedef char in_use_marker_t
;
47 /* Note that this structure is also used from Lisp-side in
48 * src/code/room.lisp, and the Lisp-side structure layout is currently
49 * not groveled from C code but hardcoded. Any changes to the
50 * structure layout need to be also made there.
52 * FIXME: We should probably just define this structure in Lisp, and
53 * output the C version in genesis. -- JES, 2006-12-30.
56 /* This is the offset from the first byte of some object in memory
57 * prior to and no closer than the start of the page to the start
58 * of the page. Lower values here are better, 0 is ideal. This
59 * is useful for determining where to start when scanning forward
60 * through a heap page (either for conservative root validation or
63 os_vm_size_t scan_start_offset
;
65 /* the number of bytes of this page that are used. This may be less
66 * than the actual bytes used for pages within the current
67 * allocation regions. It should be 0 for all unallocated pages (not
70 page_bytes_t bytes_used
;
73 /* This is set when the page is write-protected. This should
74 * always reflect the actual write_protect status of a page.
75 * (If the page is written into, we catch the exception, make
76 * the page writable, and clear this flag.) */
78 /* This flag is set when the above write_protected flag is
79 * cleared by the SIGBUS handler (or SIGSEGV handler, for some
80 * OSes). This is useful for re-scavenging pages that are
81 * written during a GC. */
82 write_protected_cleared
:1,
89 * Constants for this field are defined in gc-internal.h, the
90 * xxx_PAGE_FLAG definitions.
92 * If the page is free the following slots are invalid, except
93 * for the bytes_used which must be zero. */
95 /* If this page should not be moved during a GC then this flag
96 * is set. It's only valid during a GC for allocated pages. */
98 /* If the page is part of a large object then this flag is
99 * set. No other objects should be allocated to these pages.
100 * This is only valid when the page is allocated. */
102 /* Cleared if the page is known to contain only zeroes. */
105 /* If a page has a conservative pointer to it it will have
106 an associated map of words that are in use, for wiping.
107 This bit can differ from dont_move because not all pages
108 that are pinned are going through word-wise wiping,
109 at this time those are multi-page object's pages. */
110 /* I am starting a new 8-bit word here because 32 bit overflew the old
111 one. Might be worth reviting by somebody with lots of platforms
114 signed char has_dontmove_dwords
;
115 /* the generation that this page belongs to. This should be valid
116 * for all pages that may have objects allocated, even current
117 * allocation region pages - this allows the space of an object to
118 * be easily determined. */
119 generation_index_t gen
;
123 /* values for the page.allocated field */
126 extern page_index_t page_table_pages
;
127 extern struct page
*page_table
;
130 /* forward declarations */
131 #ifdef LISP_FEATURE_X86
132 void sniff_code_object(struct code
*code
, os_vm_size_t displacement
);
133 void gencgc_apply_code_fixups(struct code
*old_code
, struct code
*new_code
);
136 sword_t
update_dynamic_space_free_pointer(void);
137 void gc_alloc_update_page_tables(int page_type_flag
, struct alloc_region
*alloc_region
);
138 void gc_alloc_update_all_page_tables(void);
139 void gc_set_region_empty(struct alloc_region
*region
);
145 static inline boolean
146 space_matches_p(lispobj obj
, generation_index_t space
,
147 page_index_t
*store_page_index_here
)
149 if (obj
>= DYNAMIC_SPACE_START
) {
150 page_index_t page_index
=((pointer_sized_uint_t
)obj
151 - DYNAMIC_SPACE_START
) / GENCGC_CARD_BYTES
;
152 if (store_page_index_here
) {
153 *store_page_index_here
= page_index
;
155 return ((page_index
< page_table_pages
) &&
156 (page_table
[page_index
].gen
== space
));
162 static boolean
__attribute__((unused
))
163 from_space_p(lispobj obj
)
165 extern boolean
in_dontmove_nativeptr_p(page_index_t
, lispobj
*);
166 page_index_t page_index
;
168 if (space_matches_p(obj
, from_space
, &page_index
)) {
169 lispobj
*native
= native_pointer(obj
);
170 if (in_dontmove_nativeptr_p(page_index
, native
)) {
171 // pretend it is not in oldspace to protect it from being moved
180 static inline boolean
181 new_space_p(lispobj obj
)
183 return space_matches_p(obj
, new_space
, NULL
);
186 boolean
in_dontmove_nativeptr_p(page_index_t page_index
, lispobj
*native_ptr
);
188 extern page_index_t last_free_page
;
189 extern boolean gencgc_partial_pickup
;