1 | /* |
---|
2 | Copyright (C) 2009 Clozure Associates |
---|
3 | Copyright (C) 1994-2001 Digitool, Inc |
---|
4 | This file is part of Clozure CL. |
---|
5 | |
---|
6 | Clozure CL is licensed under the terms of the Lisp Lesser GNU Public |
---|
7 | License , known as the LLGPL and distributed with Clozure CL as the |
---|
8 | file "LICENSE". The LLGPL consists of a preamble and the LGPL, |
---|
9 | which is distributed with Clozure CL as the file "LGPL". Where these |
---|
10 | conflict, the preamble takes precedence. |
---|
11 | |
---|
12 | Clozure CL is referenced in the preamble as the "LIBRARY." |
---|
13 | |
---|
14 | The LLGPL is also available online at |
---|
15 | http://opensource.franz.com/preamble.html |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef __GC_H__ |
---|
19 | #define __GC_H__ 1 |
---|
20 | |
---|
21 | #include "lisp.h" |
---|
22 | #include "bits.h" |
---|
23 | #include "lisp-exceptions.h" |
---|
24 | #include "memprotect.h" |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | #ifdef PPC |
---|
29 | #define is_node_fulltag(f) ((1<<(f))&((1<<fulltag_cons)|(1<<fulltag_misc))) |
---|
30 | #ifdef PPC64 |
---|
31 | #define PPC64_CODE_VECTOR_PREFIX (('C'<< 24) | ('O' << 16) | ('D' << 8) | 'E') |
---|
32 | #else |
---|
33 | /* |
---|
34 | A code-vector's header can't look like a valid instruction or UUO: |
---|
35 | the low 8 bits must be subtag_code_vector, and the top 6 bits |
---|
36 | must be 0. That means that the maximum length of a code vector |
---|
37 | is 18 bits worth of elements (~1MB.) |
---|
38 | */ |
---|
39 | |
---|
40 | #define code_header_mask ((0x3f<<26) | subtag_code_vector) |
---|
41 | #endif |
---|
42 | #endif |
---|
43 | |
---|
44 | #ifdef X86 |
---|
45 | #ifdef X8664 |
---|
46 | #define is_node_fulltag(f) ((1<<(f))&((1<<fulltag_cons) | \ |
---|
47 | (1<<fulltag_tra_0) | \ |
---|
48 | (1<<fulltag_tra_1) | \ |
---|
49 | (1<<fulltag_misc) | \ |
---|
50 | (1<<fulltag_symbol) | \ |
---|
51 | (1<<fulltag_function))) |
---|
52 | #else |
---|
53 | #define is_node_fulltag(f) ((1<<(f))&((1<<fulltag_cons) | \ |
---|
54 | (1<<fulltag_misc) | \ |
---|
55 | (1<<fulltag_tra))) |
---|
56 | #endif |
---|
57 | #endif |
---|
58 | |
---|
59 | #ifdef ARM |
---|
60 | #define is_node_fulltag(f) ((1<<(f))&((1<<fulltag_cons)|(1<<fulltag_misc))) |
---|
61 | #endif |
---|
62 | |
---|
63 | extern void zero_memory_range(BytePtr,BytePtr); |
---|
64 | extern LispObj GCarealow, GCareadynamiclow; |
---|
65 | extern natural GCndnodes_in_area, GCndynamic_dnodes_in_area; |
---|
66 | extern bitvector GCmarkbits, GCdynamic_markbits,managed_static_refbits,global_refidx,dynamic_refidx,managed_static_refidx; |
---|
67 | LispObj *global_reloctab, *GCrelocptr; |
---|
68 | LispObj GCfirstunmarked; |
---|
69 | |
---|
70 | extern natural lisp_heap_gc_threshold; |
---|
71 | extern natural lisp_heap_notify_threshold; |
---|
72 | void mark_root(LispObj); |
---|
73 | void mark_pc_root(LispObj); |
---|
74 | void mark_locative_root(LispObj); |
---|
75 | void rmark(LispObj); |
---|
76 | LispObj *skip_over_ivector(LispObj, LispObj); |
---|
77 | void mark_simple_area_range(LispObj *,LispObj *); |
---|
78 | LispObj calculate_relocation(); |
---|
79 | LispObj locative_forwarding_address(LispObj); |
---|
80 | LispObj node_forwarding_address(LispObj); |
---|
81 | void forward_range(LispObj *, LispObj *); |
---|
82 | void forward_tcr_xframes(TCR *); |
---|
83 | void note_memoized_references(ExceptionInformation *,LogicalAddress, LogicalAddress, BytePtr *, BytePtr *); |
---|
84 | void gc(TCR *, signed_natural); |
---|
85 | int change_hons_area_size(TCR *, signed_natural); |
---|
86 | void delete_protected_area(protected_area_ptr); |
---|
87 | Boolean egc_control(Boolean, BytePtr); |
---|
88 | Boolean free_segments_zero_filled_by_OS; |
---|
89 | Boolean new_heap_segment(ExceptionInformation *, natural, Boolean , TCR *, Boolean *); |
---|
90 | void platform_new_heap_segment(ExceptionInformation *, TCR*, BytePtr, BytePtr); |
---|
91 | /* an type representing 1/4 of a natural word */ |
---|
92 | #if WORD_SIZE == 64 |
---|
93 | typedef unsigned short qnode; |
---|
94 | #else |
---|
95 | typedef unsigned char qnode; |
---|
96 | #endif |
---|
97 | |
---|
98 | |
---|
99 | #ifdef fulltag_symbol |
---|
100 | #define is_symbol_fulltag(x) (fulltag_of(x) == fulltag_symbol) |
---|
101 | #else |
---|
102 | #define is_symbol_fulltag(x) (fulltag_of(x) == fulltag_misc) |
---|
103 | #endif |
---|
104 | |
---|
105 | #define area_dnode(w,low) ((natural)(((ptr_to_lispobj(w)) - ptr_to_lispobj(low))>>dnode_shift)) |
---|
106 | #define gc_area_dnode(w) area_dnode(w,GCarealow) |
---|
107 | #define gc_dynamic_area_dnode(w) area_dnode(w,GCareadynamiclow) |
---|
108 | |
---|
109 | #if defined(PPC64) || defined(X8632) |
---|
110 | #define forward_marker subtag_forward_marker |
---|
111 | #else |
---|
112 | #ifdef ARM |
---|
113 | #define forward_marker (0xe7fffff0|uuo_format_unary) |
---|
114 | #else |
---|
115 | #define forward_marker fulltag_nil |
---|
116 | #endif |
---|
117 | #endif |
---|
118 | |
---|
119 | #ifdef PPC64 |
---|
120 | #define VOID_ALLOCPTR ((LispObj)(0x8000000000000000-dnode_size)) |
---|
121 | #else |
---|
122 | #define VOID_ALLOCPTR ((LispObj)(-dnode_size)) |
---|
123 | #endif |
---|
124 | |
---|
125 | #ifndef WINDOWS |
---|
126 | #include <sys/resource.h> |
---|
127 | typedef struct rusage paging_info; |
---|
128 | #else |
---|
129 | typedef natural paging_info; |
---|
130 | #endif |
---|
131 | |
---|
132 | #undef __argv |
---|
133 | #include <stdio.h> |
---|
134 | |
---|
135 | void sample_paging_info(paging_info *); |
---|
136 | void report_paging_info_delta(FILE*, paging_info *, paging_info *); |
---|
137 | |
---|
138 | |
---|
139 | #define GC_TRAP_FUNCTION_IMMEDIATE_GC (-1) |
---|
140 | #define GC_TRAP_FUNCTION_GC 0 |
---|
141 | #define GC_TRAP_FUNCTION_PURIFY 1 |
---|
142 | #define GC_TRAP_FUNCTION_IMPURIFY 2 |
---|
143 | #define GC_TRAP_FUNCTION_FLASH_FREEZE 4 |
---|
144 | #define GC_TRAP_FUNCTION_SAVE_APPLICATION 8 |
---|
145 | |
---|
146 | #define GC_TRAP_FUNCTION_GET_LISP_HEAP_THRESHOLD 16 |
---|
147 | #define GC_TRAP_FUNCTION_SET_LISP_HEAP_THRESHOLD 17 |
---|
148 | #define GC_TRAP_FUNCTION_USE_LISP_HEAP_THRESHOLD 18 |
---|
149 | #define GC_TRAP_FUNCTION_ENSURE_STATIC_CONSES 19 |
---|
150 | #define GC_TRAP_FUNCTION_GET_GC_NOTIFICATION_THRESHOLD 20 |
---|
151 | #define GC_TRAP_FUNCTION_SET_GC_NOTIFICATION_THRESHOLD 21 |
---|
152 | #define GC_TRAP_FUNCTION_ALLOCATION_CONTROL 22 |
---|
153 | #define GC_TRAP_FUNCTION_EGC_CONTROL 32 |
---|
154 | #define GC_TRAP_FUNCTION_CONFIGURE_EGC 64 |
---|
155 | #define GC_TRAP_FUNCTION_FREEZE 129 |
---|
156 | #define GC_TRAP_FUNCTION_THAW 130 |
---|
157 | |
---|
158 | Boolean GCDebug, GCverbose, just_purified_p; |
---|
159 | bitvector GCmarkbits, GCdynamic_markbits; |
---|
160 | LispObj GCarealow, GCareadynamiclow; |
---|
161 | natural GCndnodes_in_area, GCndynamic_dnodes_in_area; |
---|
162 | LispObj GCweakvll,GCdwsweakvll; |
---|
163 | LispObj GCephemeral_low; |
---|
164 | natural GCn_ephemeral_dnodes; |
---|
165 | natural GCstack_limit; |
---|
166 | |
---|
167 | #if WORD_SIZE == 64 |
---|
168 | unsigned short *_one_bits; |
---|
169 | #else |
---|
170 | const unsigned char _one_bits[256]; |
---|
171 | #endif |
---|
172 | |
---|
173 | #define one_bits(x) _one_bits[x] |
---|
174 | |
---|
175 | natural static_dnodes_for_area(area *a); |
---|
176 | void reapweakv(LispObj weakv); |
---|
177 | void reaphashv(LispObj hashv); |
---|
178 | Boolean mark_weak_hash_vector(hash_table_vector_header *hashp, natural elements); |
---|
179 | Boolean mark_weak_alist(LispObj weak_alist, int weak_type); |
---|
180 | void mark_tcr_tlb(TCR *); |
---|
181 | void mark_tcr_xframes(TCR *); |
---|
182 | void freeGCptrs(void); |
---|
183 | void reap_gcable_ptrs(void); |
---|
184 | unsigned short logcount16(unsigned short); |
---|
185 | void gc_init(void); |
---|
186 | LispObj node_forwarding_address(LispObj); |
---|
187 | Boolean update_noderef(LispObj *); |
---|
188 | void update_locref(LispObj *); |
---|
189 | void forward_gcable_ptrs(void); |
---|
190 | void forward_memoized_area(area *, natural, bitvector, bitvector); |
---|
191 | |
---|
192 | void forward_tcr_tlb(TCR *); |
---|
193 | void reclaim_static_dnodes(void); |
---|
194 | Boolean youngest_non_null_area_p(area *); |
---|
195 | void gc(TCR *, signed_natural); |
---|
196 | |
---|
197 | /* backend-interface */ |
---|
198 | |
---|
199 | typedef void (*weak_mark_fun) (LispObj); |
---|
200 | weak_mark_fun mark_weak_htabv, dws_mark_weak_htabv; |
---|
201 | |
---|
202 | typedef void (*weak_process_fun)(void); |
---|
203 | |
---|
204 | weak_process_fun markhtabvs; |
---|
205 | |
---|
206 | |
---|
207 | #define hash_table_vector_header_count (sizeof(hash_table_vector_header)/sizeof(LispObj)) |
---|
208 | |
---|
209 | void mark_root(LispObj); |
---|
210 | void rmark(LispObj); |
---|
211 | #ifdef X8632 |
---|
212 | void mark_xp(ExceptionInformation *, natural); |
---|
213 | #else |
---|
214 | void mark_xp(ExceptionInformation *); |
---|
215 | #endif |
---|
216 | LispObj dnode_forwarding_address(natural, int); |
---|
217 | LispObj locative_forwarding_address(LispObj); |
---|
218 | void check_refmap_consistency(LispObj *, LispObj *, bitvector, bitvector); |
---|
219 | void check_all_areas(TCR *); |
---|
220 | void mark_tstack_area(area *); |
---|
221 | void mark_vstack_area(area *); |
---|
222 | void mark_cstack_area(area *); |
---|
223 | void mark_simple_area_range(LispObj *, LispObj *); |
---|
224 | void mark_memoized_area(area *, natural, bitvector); |
---|
225 | LispObj calculate_relocation(void); |
---|
226 | void forward_range(LispObj *, LispObj *); |
---|
227 | void forward_tstack_area(area *); |
---|
228 | void forward_vstack_area(area *); |
---|
229 | void forward_cstack_area(area *); |
---|
230 | LispObj compact_dynamic_heap(void); |
---|
231 | signed_natural purify(TCR *, signed_natural); |
---|
232 | signed_natural impurify(TCR *, signed_natural); |
---|
233 | signed_natural gc_like_from_xp(ExceptionInformation *, signed_natural(*fun)(TCR *, signed_natural), signed_natural); |
---|
234 | Boolean mark_ephemeral_root(LispObj); |
---|
235 | |
---|
236 | |
---|
237 | typedef enum { |
---|
238 | xmacptr_flag_none = 0, /* Maybe already disposed by Lisp */ |
---|
239 | xmacptr_flag_recursive_lock, /* recursive-lock */ |
---|
240 | xmacptr_flag_ptr, /* malloc/free */ |
---|
241 | xmacptr_flag_rwlock, /* read/write lock */ |
---|
242 | xmacptr_flag_semaphore, /* semaphore */ |
---|
243 | xmacptr_flag_user_first = 8, /* first user-defined dispose fn */ |
---|
244 | xmacptr_flag_user_last = 16 /* exclusive upper bound */ |
---|
245 | } xmacptr_flag; |
---|
246 | |
---|
247 | |
---|
248 | typedef void (*xmacptr_dispose_fn)(void *); |
---|
249 | |
---|
250 | extern xmacptr_dispose_fn xmacptr_dispose_functions[]; |
---|
251 | |
---|
252 | extern bitvector global_mark_ref_bits, dynamic_mark_ref_bits, relocatable_mark_ref_bits; |
---|
253 | |
---|
254 | extern Boolean |
---|
255 | did_gc_notification_since_last_full_gc; |
---|
256 | |
---|
257 | extern BytePtr heap_dirty_limit; |
---|
258 | extern void zero_dnodes(void *,natural); |
---|
259 | |
---|
260 | |
---|
261 | #endif /* __GC_H__ */ |
---|