2 * C-level stuff to implement Lisp-level PURIFY
6 * This software is part of the SBCL system. See the README file for
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.
17 #include <sys/types.h>
27 #include "interrupt.h"
32 #include "gc-internal.h"
34 #include "genesis/primitive-objects.h"
35 #include "genesis/static-symbols.h"
36 #include "genesis/layout.h"
40 extern unsigned long bytes_consed_between_gcs;
42 static lispobj *dynamic_space_purify_pointer;
45 /* These hold the original end of the read_only and static spaces so
46 * we can tell what are forwarding pointers. */
48 static lispobj *read_only_end, *static_end;
50 static lispobj *read_only_free, *static_free;
52 static lispobj *pscav(lispobj *addr, long nwords, boolean constant);
54 #define LATERBLOCKSIZE 1020
55 #define LATERMAXCOUNT 10
64 } *later_blocks = NULL;
65 static long later_count = 0;
68 #define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
69 #elif N_WORD_BITS == 64
70 #define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
73 /* FIXME: Shouldn't this be defined in sbcl.h? See also notes in
76 #ifdef LISP_FEATURE_SPARC
77 #define FUN_RAW_ADDR_OFFSET 0
79 #define FUN_RAW_ADDR_OFFSET (6*sizeof(lispobj) - FUN_POINTER_LOWTAG)
83 forwarding_pointer_p(lispobj obj)
85 lispobj *ptr = native_pointer(obj);
87 return ((static_end <= ptr && ptr <= static_free) ||
88 (read_only_end <= ptr && ptr <= read_only_free));
92 dynamic_pointer_p(lispobj ptr)
94 #ifndef LISP_FEATURE_GENCGC
95 return (ptr >= (lispobj)current_dynamic_space
97 ptr < (lispobj)dynamic_space_purify_pointer);
99 /* Be more conservative, and remember, this is a maybe. */
100 return (ptr >= (lispobj)DYNAMIC_SPACE_START
102 ptr < (lispobj)dynamic_space_purify_pointer);
106 static inline lispobj *
107 newspace_alloc(long nwords, int constantp)
110 nwords=CEILING(nwords,2);
112 if(read_only_free + nwords >= (lispobj *)READ_ONLY_SPACE_END) {
113 lose("Ran out of read-only space while purifying!\n");
116 read_only_free+=nwords;
118 if(static_free + nwords >= (lispobj *)STATIC_SPACE_END) {
119 lose("Ran out of static space while purifying!\n");
129 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
131 #ifdef LISP_FEATURE_GENCGC
133 * enhanced x86/GENCGC stack scavenging by Douglas Crosher
135 * Scavenging the stack on the i386 is problematic due to conservative
136 * roots and raw return addresses. Here it is handled in two passes:
137 * the first pass runs before any objects are moved and tries to
138 * identify valid pointers and return address on the stack, the second
139 * pass scavenges these.
142 static unsigned pointer_filter_verbose = 0;
144 /* FIXME: This is substantially the same code as
145 * possibly_valid_dynamic_space_pointer in gencgc.c. The only
146 * relevant difference seems to be that the gencgc code also checks
147 * for raw pointers into Code objects, whereas in purify these are
148 * checked separately in setup_i386_stack_scav - they go onto
149 * valid_stack_ra_locations instead of just valid_stack_locations */
152 valid_dynamic_space_pointer(lispobj *pointer, lispobj *start_addr)
154 /* If it's not a return address then it needs to be a valid Lisp
156 if (!is_lisp_pointer((lispobj)pointer))
159 /* Check that the object pointed to is consistent with the pointer
161 switch (lowtag_of((lispobj)pointer)) {
162 case FUN_POINTER_LOWTAG:
163 /* Start_addr should be the enclosing code object, or a closure
165 switch (widetag_of(*start_addr)) {
166 case CODE_HEADER_WIDETAG:
167 /* This case is probably caught above. */
169 case CLOSURE_HEADER_WIDETAG:
170 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
171 if ((long)pointer != ((long)start_addr+FUN_POINTER_LOWTAG)) {
172 if (pointer_filter_verbose) {
173 fprintf(stderr,"*Wf2: %p %p %p\n",
174 pointer, start_addr, (void *)*start_addr);
180 if (pointer_filter_verbose) {
181 fprintf(stderr,"*Wf3: %p %p %p\n",
182 pointer, start_addr, (void *)*start_addr);
187 case LIST_POINTER_LOWTAG:
188 if ((long)pointer != ((long)start_addr+LIST_POINTER_LOWTAG)) {
189 if (pointer_filter_verbose)
190 fprintf(stderr,"*Wl1: %p %p %p\n",
191 pointer, start_addr, (void *)*start_addr);
194 /* Is it plausible cons? */
195 if ((is_lisp_pointer(start_addr[0])
196 || ((start_addr[0] & FIXNUM_TAG_MASK) == 0) /* fixnum */
197 || (widetag_of(start_addr[0]) == CHARACTER_WIDETAG)
198 #if N_WORD_BITS == 64
199 || (widetag_of(start_addr[0]) == SINGLE_FLOAT_WIDETAG)
201 || (widetag_of(start_addr[0]) == UNBOUND_MARKER_WIDETAG))
202 && (is_lisp_pointer(start_addr[1])
203 || ((start_addr[1] & FIXNUM_TAG_MASK) == 0) /* fixnum */
204 || (widetag_of(start_addr[1]) == CHARACTER_WIDETAG)
205 #if N_WORD_BITS == 64
206 || (widetag_of(start_addr[1]) == SINGLE_FLOAT_WIDETAG)
208 || (widetag_of(start_addr[1]) == UNBOUND_MARKER_WIDETAG))) {
211 if (pointer_filter_verbose) {
212 fprintf(stderr,"*Wl2: %p %p %p\n",
213 pointer, start_addr, (void *)*start_addr);
217 case INSTANCE_POINTER_LOWTAG:
218 if ((long)pointer != ((long)start_addr+INSTANCE_POINTER_LOWTAG)) {
219 if (pointer_filter_verbose) {
220 fprintf(stderr,"*Wi1: %p %p %p\n",
221 pointer, start_addr, (void *)*start_addr);
225 if (widetag_of(start_addr[0]) != INSTANCE_HEADER_WIDETAG) {
226 if (pointer_filter_verbose) {
227 fprintf(stderr,"*Wi2: %p %p %p\n",
228 pointer, start_addr, (void *)*start_addr);
233 case OTHER_POINTER_LOWTAG:
234 if ((long)pointer != ((long)start_addr+OTHER_POINTER_LOWTAG)) {
235 if (pointer_filter_verbose) {
236 fprintf(stderr,"*Wo1: %p %p %p\n",
237 pointer, start_addr, (void *)*start_addr);
241 /* Is it plausible? Not a cons. XXX should check the headers. */
242 if (is_lisp_pointer(start_addr[0]) || ((start_addr[0] & FIXNUM_TAG_MASK) == 0)) {
243 if (pointer_filter_verbose) {
244 fprintf(stderr,"*Wo2: %p %p %p\n",
245 pointer, start_addr, (void *)*start_addr);
249 switch (widetag_of(start_addr[0])) {
250 case UNBOUND_MARKER_WIDETAG:
251 case CHARACTER_WIDETAG:
252 #if N_WORD_BITS == 64
253 case SINGLE_FLOAT_WIDETAG:
255 if (pointer_filter_verbose) {
256 fprintf(stderr,"*Wo3: %p %p %p\n",
257 pointer, start_addr, (void *)*start_addr);
261 /* only pointed to by function pointers? */
262 case CLOSURE_HEADER_WIDETAG:
263 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
264 if (pointer_filter_verbose) {
265 fprintf(stderr,"*Wo4: %p %p %p\n",
266 pointer, start_addr, (void *)*start_addr);
270 case INSTANCE_HEADER_WIDETAG:
271 if (pointer_filter_verbose) {
272 fprintf(stderr,"*Wo5: %p %p %p\n",
273 pointer, start_addr, (void *)*start_addr);
277 /* the valid other immediate pointer objects */
278 case SIMPLE_VECTOR_WIDETAG:
280 case COMPLEX_WIDETAG:
281 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
282 case COMPLEX_SINGLE_FLOAT_WIDETAG:
284 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
285 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
287 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
288 case COMPLEX_LONG_FLOAT_WIDETAG:
290 case SIMPLE_ARRAY_WIDETAG:
291 case COMPLEX_BASE_STRING_WIDETAG:
292 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
293 case COMPLEX_CHARACTER_STRING_WIDETAG:
295 case COMPLEX_VECTOR_NIL_WIDETAG:
296 case COMPLEX_BIT_VECTOR_WIDETAG:
297 case COMPLEX_VECTOR_WIDETAG:
298 case COMPLEX_ARRAY_WIDETAG:
299 case VALUE_CELL_HEADER_WIDETAG:
300 case SYMBOL_HEADER_WIDETAG:
302 case CODE_HEADER_WIDETAG:
304 #if N_WORD_BITS != 64
305 case SINGLE_FLOAT_WIDETAG:
307 case DOUBLE_FLOAT_WIDETAG:
308 #ifdef LONG_FLOAT_WIDETAG
309 case LONG_FLOAT_WIDETAG:
311 case SIMPLE_ARRAY_NIL_WIDETAG:
312 case SIMPLE_BASE_STRING_WIDETAG:
313 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
314 case SIMPLE_CHARACTER_STRING_WIDETAG:
316 case SIMPLE_BIT_VECTOR_WIDETAG:
317 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
318 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
319 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
320 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
321 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
322 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
323 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG
324 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
326 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
327 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
328 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
329 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
331 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
332 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
334 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
335 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
337 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
338 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
340 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
341 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
343 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
344 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
346 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
347 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
349 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
350 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
352 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
353 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
355 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
356 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
357 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
358 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
360 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
361 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
363 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
364 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
366 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
367 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
370 case WEAK_POINTER_WIDETAG:
374 if (pointer_filter_verbose) {
375 fprintf(stderr,"*Wo6: %p %p %p\n",
376 pointer, start_addr, (void *)*start_addr);
382 if (pointer_filter_verbose) {
383 fprintf(stderr,"*W?: %p %p %p\n",
384 pointer, start_addr, (void *)*start_addr);
393 #define MAX_STACK_POINTERS 256
394 lispobj *valid_stack_locations[MAX_STACK_POINTERS];
395 unsigned long num_valid_stack_locations;
397 #define MAX_STACK_RETURN_ADDRESSES 128
398 lispobj *valid_stack_ra_locations[MAX_STACK_RETURN_ADDRESSES];
399 lispobj *valid_stack_ra_code_objects[MAX_STACK_RETURN_ADDRESSES];
400 unsigned long num_valid_stack_ra_locations;
402 /* Identify valid stack slots. */
404 setup_i386_stack_scav(lispobj *lowaddr, lispobj *base)
406 lispobj *sp = lowaddr;
407 num_valid_stack_locations = 0;
408 num_valid_stack_ra_locations = 0;
409 for (sp = lowaddr; sp < base; sp++) {
411 /* Find the object start address */
412 lispobj *start_addr = search_dynamic_space((void *)thing);
414 /* We need to allow raw pointers into Code objects for
415 * return addresses. This will also pick up pointers to
416 * functions in code objects. */
417 if (widetag_of(*start_addr) == CODE_HEADER_WIDETAG) {
418 /* FIXME asserting here is a really dumb thing to do.
419 * If we've overflowed some arbitrary static limit, we
420 * should just refuse to purify, instead of killing
421 * the whole lisp session
423 gc_assert(num_valid_stack_ra_locations <
424 MAX_STACK_RETURN_ADDRESSES);
425 valid_stack_ra_locations[num_valid_stack_ra_locations] = sp;
426 valid_stack_ra_code_objects[num_valid_stack_ra_locations++] =
427 (lispobj *)((long)start_addr + OTHER_POINTER_LOWTAG);
429 if (valid_dynamic_space_pointer((void *)thing, start_addr)) {
430 gc_assert(num_valid_stack_locations < MAX_STACK_POINTERS);
431 valid_stack_locations[num_valid_stack_locations++] = sp;
436 if (pointer_filter_verbose) {
437 fprintf(stderr, "number of valid stack pointers = %ld\n",
438 num_valid_stack_locations);
439 fprintf(stderr, "number of stack return addresses = %ld\n",
440 num_valid_stack_ra_locations);
445 pscav_i386_stack(void)
449 for (i = 0; i < num_valid_stack_locations; i++)
450 pscav(valid_stack_locations[i], 1, 0);
452 for (i = 0; i < num_valid_stack_ra_locations; i++) {
453 lispobj code_obj = (lispobj)valid_stack_ra_code_objects[i];
454 pscav(&code_obj, 1, 0);
455 if (pointer_filter_verbose) {
456 fprintf(stderr,"*C moved RA %p to %p; for code object %p to %p\n",
457 (void *)*valid_stack_ra_locations[i],
458 (void *)(*valid_stack_ra_locations[i]) -
459 ((void *)valid_stack_ra_code_objects[i] -
461 valid_stack_ra_code_objects[i], (void *)code_obj);
463 *valid_stack_ra_locations[i] =
464 ((long)(*valid_stack_ra_locations[i])
465 - ((long)valid_stack_ra_code_objects[i] - (long)code_obj));
473 pscav_later(lispobj *where, long count)
477 if (count > LATERMAXCOUNT) {
478 while (count > LATERMAXCOUNT) {
479 pscav_later(where, LATERMAXCOUNT);
480 count -= LATERMAXCOUNT;
481 where += LATERMAXCOUNT;
485 if (later_blocks == NULL || later_count == LATERBLOCKSIZE ||
486 (later_count == LATERBLOCKSIZE-1 && count > 1)) {
487 new = (struct later *)malloc(sizeof(struct later));
488 new->next = later_blocks;
489 if (later_blocks && later_count < LATERBLOCKSIZE)
490 later_blocks->u[later_count].ptr = NULL;
496 later_blocks->u[later_count++].count = count;
497 later_blocks->u[later_count++].ptr = where;
502 ptrans_boxed(lispobj thing, lispobj header, boolean constant)
505 lispobj result, *new, *old;
507 nwords = CEILING(1 + HeaderValue(header), 2);
510 old = (lispobj *)native_pointer(thing);
511 new = newspace_alloc(nwords,constant);
514 bcopy(old, new, nwords * sizeof(lispobj));
516 /* Deposit forwarding pointer. */
517 result = make_lispobj(new, lowtag_of(thing));
521 pscav(new, nwords, constant);
526 /* We need to look at the layout to see whether it is a pure structure
527 * class, and only then can we transport as constant. If it is pure,
528 * we can ALWAYS transport as a constant. */
530 ptrans_instance(lispobj thing, lispobj header, boolean /* ignored */ constant)
532 struct layout *layout =
533 (struct layout *) native_pointer(((struct instance *)native_pointer(thing))->slots[0]);
534 lispobj pure = layout->pure;
538 return (ptrans_boxed(thing, header, 1));
540 return (ptrans_boxed(thing, header, 0));
543 /* Substructure: special case for the COMPACT-INFO-ENVs,
544 * where the instance may have a point to the dynamic
545 * space placed into it (e.g. the cache-name slot), but
546 * the lists and arrays at the time of a purify can be
547 * moved to the RO space. */
549 lispobj result, *new, *old;
551 nwords = CEILING(1 + HeaderValue(header), 2);
554 old = (lispobj *)native_pointer(thing);
555 new = newspace_alloc(nwords, 0); /* inconstant */
558 bcopy(old, new, nwords * sizeof(lispobj));
560 /* Deposit forwarding pointer. */
561 result = make_lispobj(new, lowtag_of(thing));
565 pscav(new, nwords, 1);
571 return NIL; /* dummy value: return something ... */
576 ptrans_fdefn(lispobj thing, lispobj header)
579 lispobj result, *new, *old, oldfn;
582 nwords = CEILING(1 + HeaderValue(header), 2);
585 old = (lispobj *)native_pointer(thing);
586 new = newspace_alloc(nwords, 0); /* inconstant */
589 bcopy(old, new, nwords * sizeof(lispobj));
591 /* Deposit forwarding pointer. */
592 result = make_lispobj(new, lowtag_of(thing));
595 /* Scavenge the function. */
596 fdefn = (struct fdefn *)new;
598 pscav(&fdefn->fun, 1, 0);
599 if ((char *)oldfn + FUN_RAW_ADDR_OFFSET == fdefn->raw_addr)
600 fdefn->raw_addr = (char *)fdefn->fun + FUN_RAW_ADDR_OFFSET;
606 ptrans_unboxed(lispobj thing, lispobj header)
609 lispobj result, *new, *old;
611 nwords = CEILING(1 + HeaderValue(header), 2);
614 old = (lispobj *)native_pointer(thing);
615 new = newspace_alloc(nwords,1); /* always constant */
618 bcopy(old, new, nwords * sizeof(lispobj));
620 /* Deposit forwarding pointer. */
621 result = make_lispobj(new , lowtag_of(thing));
628 ptrans_vector(lispobj thing, long bits, long extra,
629 boolean boxed, boolean constant)
631 struct vector *vector;
633 lispobj result, *new;
636 vector = (struct vector *)native_pointer(thing);
637 length = fixnum_value(vector->length)+extra;
638 // Argh, handle simple-vector-nil separately.
642 nwords = CEILING(NWORDS(length, bits) + 2, 2);
645 new=newspace_alloc(nwords, (constant || !boxed));
646 bcopy(vector, new, nwords * sizeof(lispobj));
648 result = make_lispobj(new, lowtag_of(thing));
649 vector->header = result;
652 pscav(new, nwords, constant);
657 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
659 apply_code_fixups_during_purify(struct code *old_code, struct code *new_code)
661 long nheader_words, ncode_words, nwords;
662 void *constants_start_addr, *constants_end_addr;
663 void *code_start_addr, *code_end_addr;
664 lispobj fixups = NIL;
665 unsigned displacement = (unsigned)new_code - (unsigned)old_code;
666 struct vector *fixups_vector;
668 ncode_words = fixnum_value(new_code->code_size);
669 nheader_words = HeaderValue(*(lispobj *)new_code);
670 nwords = ncode_words + nheader_words;
672 constants_start_addr = (void *)new_code + 5 * N_WORD_BYTES;
673 constants_end_addr = (void *)new_code + nheader_words*N_WORD_BYTES;
674 code_start_addr = (void *)new_code + nheader_words*N_WORD_BYTES;
675 code_end_addr = (void *)new_code + nwords*N_WORD_BYTES;
677 /* The first constant should be a pointer to the fixups for this
678 * code objects. Check. */
679 fixups = new_code->constants[0];
681 /* It will be 0 or the unbound-marker if there are no fixups, and
682 * will be an other-pointer to a vector if it is valid. */
684 (fixups==UNBOUND_MARKER_WIDETAG) ||
685 !is_lisp_pointer(fixups)) {
686 #ifdef LISP_FEATURE_GENCGC
687 /* Check for a possible errors. */
688 sniff_code_object(new_code,displacement);
693 fixups_vector = (struct vector *)native_pointer(fixups);
695 /* Could be pointing to a forwarding pointer. */
696 if (is_lisp_pointer(fixups) && (dynamic_pointer_p(fixups))
697 && forwarding_pointer_p(*(lispobj *)fixups_vector)) {
698 /* If so then follow it. */
700 (struct vector *)native_pointer(*(lispobj *)fixups_vector);
703 if (widetag_of(fixups_vector->header) == SIMPLE_ARRAY_WORD_WIDETAG) {
704 /* We got the fixups for the code block. Now work through the
705 * vector, and apply a fixup at each address. */
706 long length = fixnum_value(fixups_vector->length);
708 for (i=0; i<length; i++) {
709 unsigned offset = fixups_vector->data[i];
710 /* Now check the current value of offset. */
712 *(unsigned *)((unsigned)code_start_addr + offset);
714 /* If it's within the old_code object then it must be an
715 * absolute fixup (relative ones are not saved) */
716 if ((old_value>=(unsigned)old_code)
717 && (old_value<((unsigned)old_code + nwords * N_WORD_BYTES)))
718 /* So add the dispacement. */
719 *(unsigned *)((unsigned)code_start_addr + offset) = old_value
722 /* It is outside the old code object so it must be a relative
723 * fixup (absolute fixups are not saved). So subtract the
725 *(unsigned *)((unsigned)code_start_addr + offset) = old_value
730 /* No longer need the fixups. */
731 new_code->constants[0] = 0;
733 #ifdef LISP_FEATURE_GENCGC
734 /* Check for possible errors. */
735 sniff_code_object(new_code,displacement);
741 ptrans_code(lispobj thing)
743 struct code *code, *new;
745 lispobj func, result;
747 code = (struct code *)native_pointer(thing);
748 nwords = CEILING(HeaderValue(code->header) + fixnum_value(code->code_size),
751 new = (struct code *)newspace_alloc(nwords,1); /* constant */
753 bcopy(code, new, nwords * sizeof(lispobj));
755 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
756 apply_code_fixups_during_purify(code,new);
759 result = make_lispobj(new, OTHER_POINTER_LOWTAG);
761 /* Stick in a forwarding pointer for the code object. */
762 *(lispobj *)code = result;
764 /* Put in forwarding pointers for all the functions. */
765 for (func = code->entry_points;
767 func = ((struct simple_fun *)native_pointer(func))->next) {
769 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
771 *(lispobj *)native_pointer(func) = result + (func - thing);
774 /* Arrange to scavenge the debug info later. */
775 pscav_later(&new->debug_info, 1);
777 /* FIXME: why would this be a fixnum? */
778 /* "why" is a hard word, but apparently for compiled functions the
779 trace_table_offset contains the length of the instructions, as
780 a fixnum. See CODE-INST-AREA-LENGTH in
781 src/compiler/target-disassem.lisp. -- CSR, 2004-01-08 */
782 if (!(fixnump(new->trace_table_offset)))
784 pscav(&new->trace_table_offset, 1, 0);
786 new->trace_table_offset = NIL; /* limit lifetime */
789 /* Scavenge the constants. */
790 pscav(new->constants, HeaderValue(new->header)-5, 1);
792 /* Scavenge all the functions. */
793 pscav(&new->entry_points, 1, 1);
794 for (func = new->entry_points;
796 func = ((struct simple_fun *)native_pointer(func))->next) {
797 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
798 gc_assert(!dynamic_pointer_p(func));
800 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
801 /* Temporarily convert the self pointer to a real function pointer. */
802 ((struct simple_fun *)native_pointer(func))->self
803 -= FUN_RAW_ADDR_OFFSET;
805 pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
806 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
807 ((struct simple_fun *)native_pointer(func))->self
808 += FUN_RAW_ADDR_OFFSET;
810 pscav_later(&((struct simple_fun *)native_pointer(func))->name, 3);
817 ptrans_func(lispobj thing, lispobj header)
820 lispobj code, *new, *old, result;
821 struct simple_fun *function;
823 /* Thing can either be a function header, a closure function
824 * header, a closure, or a funcallable-instance. If it's a closure
825 * or a funcallable-instance, we do the same as ptrans_boxed.
826 * Otherwise we have to do something strange, 'cause it is buried
827 * inside a code object. */
829 if (widetag_of(header) == SIMPLE_FUN_HEADER_WIDETAG) {
831 /* We can only end up here if the code object has not been
832 * scavenged, because if it had been scavenged, forwarding pointers
833 * would have been left behind for all the entry points. */
835 function = (struct simple_fun *)native_pointer(thing);
838 ((native_pointer(thing) -
839 (HeaderValue(function->header))), OTHER_POINTER_LOWTAG);
841 /* This will cause the function's header to be replaced with a
842 * forwarding pointer. */
846 /* So we can just return that. */
847 return function->header;
850 /* It's some kind of closure-like thing. */
851 nwords = CEILING(1 + HeaderValue(header), 2);
852 old = (lispobj *)native_pointer(thing);
854 /* Allocate the new one. FINs *must* not go in read_only
855 * space. Closures can; they never change */
858 (nwords,(widetag_of(header)!=FUNCALLABLE_INSTANCE_HEADER_WIDETAG));
861 bcopy(old, new, nwords * sizeof(lispobj));
863 /* Deposit forwarding pointer. */
864 result = make_lispobj(new, lowtag_of(thing));
868 pscav(new, nwords, 0);
875 ptrans_returnpc(lispobj thing, lispobj header)
879 /* Find the corresponding code object. */
880 code = thing - HeaderValue(header)*sizeof(lispobj);
882 /* Make sure it's been transported. */
883 new = *(lispobj *)native_pointer(code);
884 if (!forwarding_pointer_p(new))
885 new = ptrans_code(code);
887 /* Maintain the offset: */
888 return new + (thing - code);
891 #define WORDS_PER_CONS CEILING(sizeof(struct cons) / sizeof(lispobj), 2)
894 ptrans_list(lispobj thing, boolean constant)
896 struct cons *old, *new, *orig;
899 orig = (struct cons *) newspace_alloc(0,constant);
903 /* Allocate a new cons cell. */
904 old = (struct cons *)native_pointer(thing);
905 new = (struct cons *) newspace_alloc(WORDS_PER_CONS,constant);
907 /* Copy the cons cell and keep a pointer to the cdr. */
909 thing = new->cdr = old->cdr;
911 /* Set up the forwarding pointer. */
912 *(lispobj *)old = make_lispobj(new, LIST_POINTER_LOWTAG);
914 /* And count this cell. */
916 } while (lowtag_of(thing) == LIST_POINTER_LOWTAG &&
917 dynamic_pointer_p(thing) &&
918 !(forwarding_pointer_p(*(lispobj *)native_pointer(thing))));
920 /* Scavenge the list we just copied. */
921 pscav((lispobj *)orig, length * WORDS_PER_CONS, constant);
923 return make_lispobj(orig, LIST_POINTER_LOWTAG);
927 ptrans_otherptr(lispobj thing, lispobj header, boolean constant)
929 switch (widetag_of(header)) {
930 /* FIXME: this needs a reindent */
932 case SINGLE_FLOAT_WIDETAG:
933 case DOUBLE_FLOAT_WIDETAG:
934 #ifdef LONG_FLOAT_WIDETAG
935 case LONG_FLOAT_WIDETAG:
937 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
938 case COMPLEX_SINGLE_FLOAT_WIDETAG:
940 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
941 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
943 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
944 case COMPLEX_LONG_FLOAT_WIDETAG:
947 return ptrans_unboxed(thing, header);
950 case COMPLEX_WIDETAG:
951 case SIMPLE_ARRAY_WIDETAG:
952 case COMPLEX_BASE_STRING_WIDETAG:
953 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
954 case COMPLEX_CHARACTER_STRING_WIDETAG:
956 case COMPLEX_BIT_VECTOR_WIDETAG:
957 case COMPLEX_VECTOR_NIL_WIDETAG:
958 case COMPLEX_VECTOR_WIDETAG:
959 case COMPLEX_ARRAY_WIDETAG:
960 return ptrans_boxed(thing, header, constant);
962 case VALUE_CELL_HEADER_WIDETAG:
963 case WEAK_POINTER_WIDETAG:
964 return ptrans_boxed(thing, header, 0);
966 case SYMBOL_HEADER_WIDETAG:
967 return ptrans_boxed(thing, header, 0);
969 case SIMPLE_ARRAY_NIL_WIDETAG:
970 return ptrans_vector(thing, 0, 0, 0, constant);
972 case SIMPLE_BASE_STRING_WIDETAG:
973 return ptrans_vector(thing, 8, 1, 0, constant);
975 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
976 case SIMPLE_CHARACTER_STRING_WIDETAG:
977 return ptrans_vector(thing, 32, 1, 0, constant);
980 case SIMPLE_BIT_VECTOR_WIDETAG:
981 return ptrans_vector(thing, 1, 0, 0, constant);
983 case SIMPLE_VECTOR_WIDETAG:
984 return ptrans_vector(thing, N_WORD_BITS, 0, 1, constant);
986 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
987 return ptrans_vector(thing, 2, 0, 0, constant);
989 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
990 return ptrans_vector(thing, 4, 0, 0, constant);
992 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
993 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
994 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
995 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
997 return ptrans_vector(thing, 8, 0, 0, constant);
999 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
1000 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
1001 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
1002 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
1004 return ptrans_vector(thing, 16, 0, 0, constant);
1006 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
1007 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1008 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
1009 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
1011 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1012 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
1013 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
1015 return ptrans_vector(thing, 32, 0, 0, constant);
1017 #if N_WORD_BITS == 64
1018 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
1019 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
1021 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
1022 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
1024 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
1025 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
1027 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1028 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
1030 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1031 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
1033 return ptrans_vector(thing, 64, 0, 0, constant);
1036 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
1037 return ptrans_vector(thing, 32, 0, 0, constant);
1039 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
1040 return ptrans_vector(thing, 64, 0, 0, constant);
1042 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1043 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
1044 #ifdef LISP_FEATURE_X86
1045 return ptrans_vector(thing, 96, 0, 0, constant);
1047 #ifdef LISP_FEATURE_SPARC
1048 return ptrans_vector(thing, 128, 0, 0, constant);
1052 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1053 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
1054 return ptrans_vector(thing, 64, 0, 0, constant);
1057 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1058 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
1059 return ptrans_vector(thing, 128, 0, 0, constant);
1062 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1063 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
1064 #ifdef LISP_FEATURE_X86
1065 return ptrans_vector(thing, 192, 0, 0, constant);
1067 #ifdef LISP_FEATURE_SPARC
1068 return ptrans_vector(thing, 256, 0, 0, constant);
1072 case CODE_HEADER_WIDETAG:
1073 return ptrans_code(thing);
1075 case RETURN_PC_HEADER_WIDETAG:
1076 return ptrans_returnpc(thing, header);
1079 return ptrans_fdefn(thing, header);
1082 fprintf(stderr, "Invalid widetag: %d\n", widetag_of(header));
1083 /* Should only come across other pointers to the above stuff. */
1090 pscav_fdefn(struct fdefn *fdefn)
1094 fix_func = ((char *)(fdefn->fun+FUN_RAW_ADDR_OFFSET) == fdefn->raw_addr);
1095 pscav(&fdefn->name, 1, 1);
1096 pscav(&fdefn->fun, 1, 0);
1098 fdefn->raw_addr = (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET);
1099 return sizeof(struct fdefn) / sizeof(lispobj);
1102 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1103 /* now putting code objects in static space */
1105 pscav_code(struct code*code)
1109 nwords = CEILING(HeaderValue(code->header) + fixnum_value(code->code_size),
1112 /* Arrange to scavenge the debug info later. */
1113 pscav_later(&code->debug_info, 1);
1115 /* Scavenge the constants. */
1116 pscav(code->constants, HeaderValue(code->header)-5, 1);
1118 /* Scavenge all the functions. */
1119 pscav(&code->entry_points, 1, 1);
1120 for (func = code->entry_points;
1122 func = ((struct simple_fun *)native_pointer(func))->next) {
1123 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
1124 gc_assert(!dynamic_pointer_p(func));
1126 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1127 /* Temporarily convert the self pointer to a real function
1129 ((struct simple_fun *)native_pointer(func))->self
1130 -= FUN_RAW_ADDR_OFFSET;
1132 pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
1133 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1134 ((struct simple_fun *)native_pointer(func))->self
1135 += FUN_RAW_ADDR_OFFSET;
1137 pscav_later(&((struct simple_fun *)native_pointer(func))->name, 3);
1140 return CEILING(nwords,2);
1145 pscav(lispobj *addr, long nwords, boolean constant)
1147 lispobj thing, *thingp, header;
1148 long count = 0; /* (0 = dummy init value to stop GCC warning) */
1149 struct vector *vector;
1151 while (nwords > 0) {
1153 if (is_lisp_pointer(thing)) {
1154 /* It's a pointer. Is it something we might have to move? */
1155 if (dynamic_pointer_p(thing)) {
1156 /* Maybe. Have we already moved it? */
1157 thingp = (lispobj *)native_pointer(thing);
1159 if (is_lisp_pointer(header) && forwarding_pointer_p(header))
1160 /* Yep, so just copy the forwarding pointer. */
1163 /* Nope, copy the object. */
1164 switch (lowtag_of(thing)) {
1165 case FUN_POINTER_LOWTAG:
1166 thing = ptrans_func(thing, header);
1169 case LIST_POINTER_LOWTAG:
1170 thing = ptrans_list(thing, constant);
1173 case INSTANCE_POINTER_LOWTAG:
1174 thing = ptrans_instance(thing, header, constant);
1177 case OTHER_POINTER_LOWTAG:
1178 thing = ptrans_otherptr(thing, header, constant);
1182 /* It was a pointer, but not one of them? */
1190 #if N_WORD_BITS == 64
1191 else if (widetag_of(thing) == SINGLE_FLOAT_WIDETAG) {
1195 else if (thing & FIXNUM_TAG_MASK) {
1196 /* It's an other immediate. Maybe the header for an unboxed */
1198 switch (widetag_of(thing)) {
1199 case BIGNUM_WIDETAG:
1200 case SINGLE_FLOAT_WIDETAG:
1201 case DOUBLE_FLOAT_WIDETAG:
1202 #ifdef LONG_FLOAT_WIDETAG
1203 case LONG_FLOAT_WIDETAG:
1206 /* It's an unboxed simple object. */
1207 count = CEILING(HeaderValue(thing)+1, 2);
1210 case SIMPLE_VECTOR_WIDETAG:
1211 if (HeaderValue(thing) == subtype_VectorValidHashing) {
1212 *addr = (subtype_VectorMustRehash << N_WIDETAG_BITS) |
1213 SIMPLE_VECTOR_WIDETAG;
1218 case SIMPLE_ARRAY_NIL_WIDETAG:
1222 case SIMPLE_BASE_STRING_WIDETAG:
1223 vector = (struct vector *)addr;
1224 count = CEILING(NWORDS(fixnum_value(vector->length)+1,8)+2,2);
1227 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
1228 case SIMPLE_CHARACTER_STRING_WIDETAG:
1229 vector = (struct vector *)addr;
1230 count = CEILING(NWORDS(fixnum_value(vector->length)+1,32)+2,2);
1234 case SIMPLE_BIT_VECTOR_WIDETAG:
1235 vector = (struct vector *)addr;
1236 count = CEILING(NWORDS(fixnum_value(vector->length),1)+2,2);
1239 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
1240 vector = (struct vector *)addr;
1241 count = CEILING(NWORDS(fixnum_value(vector->length),2)+2,2);
1244 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
1245 vector = (struct vector *)addr;
1246 count = CEILING(NWORDS(fixnum_value(vector->length),4)+2,2);
1249 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
1250 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
1251 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
1252 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
1254 vector = (struct vector *)addr;
1255 count = CEILING(NWORDS(fixnum_value(vector->length),8)+2,2);
1258 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
1259 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
1260 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
1261 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
1263 vector = (struct vector *)addr;
1264 count = CEILING(NWORDS(fixnum_value(vector->length),16)+2,2);
1267 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
1268 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1269 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
1270 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
1272 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1273 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
1274 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
1276 vector = (struct vector *)addr;
1277 count = CEILING(NWORDS(fixnum_value(vector->length),32)+2,2);
1280 #if N_WORD_BITS == 64
1281 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
1282 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1283 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
1284 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
1286 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1287 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
1288 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
1290 vector = (struct vector *)addr;
1291 count = CEILING(NWORDS(fixnum_value(vector->length),64)+2,2);
1295 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
1296 vector = (struct vector *)addr;
1297 count = CEILING(NWORDS(fixnum_value(vector->length), 32) + 2,
1301 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
1302 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1303 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
1305 vector = (struct vector *)addr;
1306 count = CEILING(NWORDS(fixnum_value(vector->length), 64) + 2,
1310 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1311 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
1312 vector = (struct vector *)addr;
1313 #ifdef LISP_FEATURE_X86
1314 count = fixnum_value(vector->length)*3+2;
1316 #ifdef LISP_FEATURE_SPARC
1317 count = fixnum_value(vector->length)*4+2;
1322 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1323 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
1324 vector = (struct vector *)addr;
1325 count = CEILING(NWORDS(fixnum_value(vector->length), 128) + 2,
1330 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1331 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
1332 vector = (struct vector *)addr;
1333 #ifdef LISP_FEATURE_X86
1334 count = fixnum_value(vector->length)*6+2;
1336 #ifdef LISP_FEATURE_SPARC
1337 count = fixnum_value(vector->length)*8+2;
1342 case CODE_HEADER_WIDETAG:
1343 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1344 gc_abort(); /* no code headers in static space */
1346 count = pscav_code((struct code*)addr);
1350 case SIMPLE_FUN_HEADER_WIDETAG:
1351 case RETURN_PC_HEADER_WIDETAG:
1352 /* We should never hit any of these, 'cause they occur
1353 * buried in the middle of code objects. */
1357 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1358 case CLOSURE_HEADER_WIDETAG:
1359 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
1360 /* The function self pointer needs special care on the
1361 * x86 because it is the real entry point. */
1363 lispobj fun = ((struct closure *)addr)->fun
1364 - FUN_RAW_ADDR_OFFSET;
1365 pscav(&fun, 1, constant);
1366 ((struct closure *)addr)->fun = fun + FUN_RAW_ADDR_OFFSET;
1372 case WEAK_POINTER_WIDETAG:
1373 /* Weak pointers get preserved during purify, 'cause I
1374 * don't feel like figuring out how to break them. */
1375 pscav(addr+1, 2, constant);
1380 /* We have to handle fdefn objects specially, so we
1381 * can fix up the raw function address. */
1382 count = pscav_fdefn((struct fdefn *)addr);
1385 case INSTANCE_HEADER_WIDETAG:
1387 struct instance *instance = (struct instance *) addr;
1388 struct layout *layout
1389 = (struct layout *) native_pointer(instance->slots[0]);
1390 long nuntagged = fixnum_value(layout->n_untagged_slots);
1391 long nslots = HeaderValue(*addr);
1392 pscav(addr + 1, nslots - nuntagged, constant);
1393 count = CEILING(1 + nslots, 2);
1403 /* It's a fixnum. */
1415 purify(lispobj static_roots, lispobj read_only_roots)
1419 struct later *laters, *next;
1420 struct thread *thread;
1422 if(all_threads->next) {
1423 /* FIXME: there should be _some_ sensible error reporting
1424 * convention. See following comment too */
1425 fprintf(stderr,"Can't purify when more than one thread exists\n");
1431 printf("[doing purification:");
1434 #ifdef LISP_FEATURE_GENCGC
1435 gc_alloc_update_all_page_tables();
1437 for_each_thread(thread)
1438 if (fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,thread)) != 0) {
1439 /* FIXME: 1. What does this mean? 2. It shouldn't be reporting
1440 * its error simply by a. printing a string b. to stdout instead
1442 printf(" Ack! Can't purify interrupt contexts. ");
1447 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1448 dynamic_space_purify_pointer =
1449 (lispobj*)SymbolValue(ALLOCATION_POINTER,0);
1451 #if defined(LISP_FEATURE_GENCGC)
1452 dynamic_space_purify_pointer = get_alloc_pointer();
1454 dynamic_space_purify_pointer = dynamic_space_free_pointer;
1458 read_only_end = read_only_free =
1459 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER,0);
1460 static_end = static_free =
1461 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER,0);
1468 #if defined(LISP_FEATURE_GENCGC) && (defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
1469 /* note this expects only one thread to be active. We'd have to
1470 * stop all the others in the same way as GC does if we wanted
1471 * PURIFY to work when >1 thread exists */
1472 setup_i386_stack_scav(((&static_roots)-2),
1473 ((void *)all_threads->control_stack_end));
1476 pscav(&static_roots, 1, 0);
1477 pscav(&read_only_roots, 1, 1);
1480 printf(" handlers");
1483 pscav((lispobj *) interrupt_handlers,
1484 sizeof(interrupt_handlers) / sizeof(lispobj),
1491 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1492 pscav((lispobj *)all_threads->control_stack_start,
1493 current_control_stack_pointer -
1494 all_threads->control_stack_start,
1497 #ifdef LISP_FEATURE_GENCGC
1503 printf(" bindings");
1506 #if !(defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
1507 pscav( (lispobj *)all_threads->binding_stack_start,
1508 (lispobj *)current_binding_stack_pointer -
1509 all_threads->binding_stack_start,
1512 for_each_thread(thread) {
1513 pscav( (lispobj *)thread->binding_stack_start,
1514 (lispobj *)SymbolValue(BINDING_STACK_POINTER,thread) -
1515 (lispobj *)thread->binding_stack_start,
1517 pscav( (lispobj *) (thread+1),
1518 fixnum_value(SymbolValue(FREE_TLS_INDEX,0)) -
1519 (sizeof (struct thread))/(sizeof (lispobj)),
1526 /* The original CMU CL code had scavenge-read-only-space code
1527 * controlled by the Lisp-level variable
1528 * *SCAVENGE-READ-ONLY-SPACE*. It was disabled by default, and it
1529 * wasn't documented under what circumstances it was useful or
1530 * safe to turn it on, so it's been turned off in SBCL. If you
1531 * want/need this functionality, and can test and document it,
1532 * please submit a patch. */
1534 if (SymbolValue(SCAVENGE_READ_ONLY_SPACE) != UNBOUND_MARKER_WIDETAG
1535 && SymbolValue(SCAVENGE_READ_ONLY_SPACE) != NIL) {
1536 unsigned read_only_space_size =
1537 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER) -
1538 (lispobj *)READ_ONLY_SPACE_START;
1540 "scavenging read only space: %d bytes\n",
1541 read_only_space_size * sizeof(lispobj));
1542 pscav( (lispobj *)READ_ONLY_SPACE_START, read_only_space_size, 0);
1550 clean = (lispobj *)STATIC_SPACE_START;
1552 while (clean != static_free)
1553 clean = pscav(clean, static_free - clean, 0);
1554 laters = later_blocks;
1555 count = later_count;
1556 later_blocks = NULL;
1558 while (laters != NULL) {
1559 for (i = 0; i < count; i++) {
1560 if (laters->u[i].count == 0) {
1562 } else if (laters->u[i].count <= LATERMAXCOUNT) {
1563 pscav(laters->u[i+1].ptr, laters->u[i].count, 1);
1566 pscav(laters->u[i].ptr, 1, 1);
1569 next = laters->next;
1572 count = LATERBLOCKSIZE;
1574 } while (clean != static_free || later_blocks != NULL);
1581 os_zero((os_vm_address_t) current_dynamic_space,
1582 (os_vm_size_t) DYNAMIC_SPACE_SIZE);
1584 /* Zero the stack. Note that the stack is also zeroed by SUB-GC
1585 * calling SCRUB-CONTROL-STACK - this zeros the stack on the x86. */
1586 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1587 os_zero((os_vm_address_t) current_control_stack_pointer,
1589 ((all_threads->control_stack_end -
1590 current_control_stack_pointer) * sizeof(lispobj)));
1593 /* It helps to update the heap free pointers so that free_heap can
1594 * verify after it's done. */
1595 SetSymbolValue(READ_ONLY_SPACE_FREE_POINTER, (lispobj)read_only_free,0);
1596 SetSymbolValue(STATIC_SPACE_FREE_POINTER, (lispobj)static_free,0);
1598 #if defined LISP_FEATURE_GENCGC
1601 dynamic_space_free_pointer = current_dynamic_space;
1602 set_auto_gc_trigger(bytes_consed_between_gcs);
1605 /* Blast away instruction cache */
1606 os_flush_icache((os_vm_address_t)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
1607 os_flush_icache((os_vm_address_t)STATIC_SPACE_START, STATIC_SPACE_SIZE);