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"
39 #if defined(LISP_FEATURE_GENCGC)
40 /* this is another artifact of the poor integration between gencgc and
41 * the rest of the runtime: on cheney gc there is a global
42 * dynamic_space_free_pointer which is valid whenever foreign function
43 * call is active, but in gencgc there's no such variable and we have
46 static lispobj *dynamic_space_free_pointer;
48 extern unsigned long bytes_consed_between_gcs;
51 lose("GC invariant lost, file \"%s\", line %d", __FILE__, __LINE__)
54 #define gc_assert(ex) do { \
55 if (!(ex)) gc_abort(); \
62 /* These hold the original end of the read_only and static spaces so
63 * we can tell what are forwarding pointers. */
65 static lispobj *read_only_end, *static_end;
67 static lispobj *read_only_free, *static_free;
69 static lispobj *pscav(lispobj *addr, long nwords, boolean constant);
71 #define LATERBLOCKSIZE 1020
72 #define LATERMAXCOUNT 10
81 } *later_blocks = NULL;
82 static long later_count = 0;
85 #define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
86 #elif N_WORD_BITS == 64
87 #define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
90 /* FIXME: Shouldn't this be defined in sbcl.h? See also notes in
94 #define FUN_RAW_ADDR_OFFSET 0
96 #define FUN_RAW_ADDR_OFFSET (6*sizeof(lispobj) - FUN_POINTER_LOWTAG)
100 forwarding_pointer_p(lispobj obj)
102 lispobj *ptr = native_pointer(obj);
104 return ((static_end <= ptr && ptr <= static_free) ||
105 (read_only_end <= ptr && ptr <= read_only_free));
109 dynamic_pointer_p(lispobj ptr)
111 #ifndef LISP_FEATURE_GENCGC
112 return (ptr >= (lispobj)current_dynamic_space
114 ptr < (lispobj)dynamic_space_free_pointer);
116 /* Be more conservative, and remember, this is a maybe. */
117 return (ptr >= (lispobj)DYNAMIC_SPACE_START
119 ptr < (lispobj)dynamic_space_free_pointer);
123 static inline lispobj *
124 newspace_alloc(long nwords, int constantp)
127 nwords=CEILING(nwords,2);
130 read_only_free+=nwords;
140 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
142 #ifdef LISP_FEATURE_GENCGC
144 * enhanced x86/GENCGC stack scavenging by Douglas Crosher
146 * Scavenging the stack on the i386 is problematic due to conservative
147 * roots and raw return addresses. Here it is handled in two passes:
148 * the first pass runs before any objects are moved and tries to
149 * identify valid pointers and return address on the stack, the second
150 * pass scavenges these.
153 static unsigned pointer_filter_verbose = 0;
155 /* FIXME: This is substantially the same code as
156 * possibly_valid_dynamic_space_pointer in gencgc.c. The only
157 * relevant difference seems to be that the gencgc code also checks
158 * for raw pointers into Code objects, whereas in purify these are
159 * checked separately in setup_i386_stack_scav - they go onto
160 * valid_stack_ra_locations instead of just valid_stack_locations */
163 valid_dynamic_space_pointer(lispobj *pointer, lispobj *start_addr)
165 /* If it's not a return address then it needs to be a valid Lisp
167 if (!is_lisp_pointer((lispobj)pointer))
170 /* Check that the object pointed to is consistent with the pointer
172 switch (lowtag_of((lispobj)pointer)) {
173 case FUN_POINTER_LOWTAG:
174 /* Start_addr should be the enclosing code object, or a closure
176 switch (widetag_of(*start_addr)) {
177 case CODE_HEADER_WIDETAG:
178 /* This case is probably caught above. */
180 case CLOSURE_HEADER_WIDETAG:
181 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
182 if ((long)pointer != ((long)start_addr+FUN_POINTER_LOWTAG)) {
183 if (pointer_filter_verbose) {
184 fprintf(stderr,"*Wf2: %x %x %x\n",
185 (unsigned long) pointer,
186 (unsigned long) start_addr, *start_addr);
192 if (pointer_filter_verbose) {
193 fprintf(stderr,"*Wf3: %x %x %x\n", (unsigned long) pointer,
194 (unsigned long) start_addr, *start_addr);
199 case LIST_POINTER_LOWTAG:
200 if ((long)pointer != ((long)start_addr+LIST_POINTER_LOWTAG)) {
201 if (pointer_filter_verbose)
202 fprintf(stderr,"*Wl1: %x %x %x\n", (unsigned long) pointer,
203 (unsigned long) start_addr, *start_addr);
206 /* Is it plausible cons? */
207 if ((is_lisp_pointer(start_addr[0])
208 || ((start_addr[0] & FIXNUM_TAG_MASK) == 0) /* fixnum */
209 || (widetag_of(start_addr[0]) == CHARACTER_WIDETAG)
210 #if N_WORD_BITS == 64
211 || (widetag_of(start_addr[0]) == SINGLE_FLOAT_WIDETAG)
213 || (widetag_of(start_addr[0]) == UNBOUND_MARKER_WIDETAG))
214 && (is_lisp_pointer(start_addr[1])
215 || ((start_addr[1] & FIXNUM_TAG_MASK) == 0) /* fixnum */
216 || (widetag_of(start_addr[1]) == CHARACTER_WIDETAG)
217 #if N_WORD_BITS == 64
218 || (widetag_of(start_addr[1]) == SINGLE_FLOAT_WIDETAG)
220 || (widetag_of(start_addr[1]) == UNBOUND_MARKER_WIDETAG))) {
223 if (pointer_filter_verbose) {
224 fprintf(stderr,"*Wl2: %x %x %x\n", (unsigned long) pointer,
225 (unsigned long) start_addr, *start_addr);
229 case INSTANCE_POINTER_LOWTAG:
230 if ((long)pointer != ((long)start_addr+INSTANCE_POINTER_LOWTAG)) {
231 if (pointer_filter_verbose) {
232 fprintf(stderr,"*Wi1: %x %x %x\n", (unsigned long) pointer,
233 (unsigned long) start_addr, *start_addr);
237 if (widetag_of(start_addr[0]) != INSTANCE_HEADER_WIDETAG) {
238 if (pointer_filter_verbose) {
239 fprintf(stderr,"*Wi2: %x %x %x\n", (unsigned long) pointer,
240 (unsigned long) start_addr, *start_addr);
245 case OTHER_POINTER_LOWTAG:
246 if ((long)pointer != ((long)start_addr+OTHER_POINTER_LOWTAG)) {
247 if (pointer_filter_verbose) {
248 fprintf(stderr,"*Wo1: %x %x %x\n", (unsigned long) pointer,
249 (unsigned long) start_addr, *start_addr);
253 /* Is it plausible? Not a cons. XXX should check the headers. */
254 if (is_lisp_pointer(start_addr[0]) || ((start_addr[0] & FIXNUM_TAG_MASK) == 0)) {
255 if (pointer_filter_verbose) {
256 fprintf(stderr,"*Wo2: %x %x %x\n", (unsigned long) pointer,
257 (unsigned long) start_addr, *start_addr);
261 switch (widetag_of(start_addr[0])) {
262 case UNBOUND_MARKER_WIDETAG:
263 case CHARACTER_WIDETAG:
264 #if N_WORD_BITS == 64
265 case SINGLE_FLOAT_WIDETAG:
267 if (pointer_filter_verbose) {
268 fprintf(stderr,"*Wo3: %x %x %x\n", (unsigned long) pointer,
269 (unsigned long) start_addr, *start_addr);
273 /* only pointed to by function pointers? */
274 case CLOSURE_HEADER_WIDETAG:
275 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
276 if (pointer_filter_verbose) {
277 fprintf(stderr,"*Wo4: %x %x %x\n", (unsigned long) pointer,
278 (unsigned long) start_addr, *start_addr);
282 case INSTANCE_HEADER_WIDETAG:
283 if (pointer_filter_verbose) {
284 fprintf(stderr,"*Wo5: %x %x %x\n", (unsigned long) pointer,
285 (unsigned long) start_addr, *start_addr);
289 /* the valid other immediate pointer objects */
290 case SIMPLE_VECTOR_WIDETAG:
292 case COMPLEX_WIDETAG:
293 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
294 case COMPLEX_SINGLE_FLOAT_WIDETAG:
296 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
297 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
299 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
300 case COMPLEX_LONG_FLOAT_WIDETAG:
302 case SIMPLE_ARRAY_WIDETAG:
303 case COMPLEX_BASE_STRING_WIDETAG:
304 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
305 case COMPLEX_CHARACTER_STRING_WIDETAG:
307 case COMPLEX_VECTOR_NIL_WIDETAG:
308 case COMPLEX_BIT_VECTOR_WIDETAG:
309 case COMPLEX_VECTOR_WIDETAG:
310 case COMPLEX_ARRAY_WIDETAG:
311 case VALUE_CELL_HEADER_WIDETAG:
312 case SYMBOL_HEADER_WIDETAG:
314 case CODE_HEADER_WIDETAG:
316 #if N_WORD_BITS != 64
317 case SINGLE_FLOAT_WIDETAG:
319 case DOUBLE_FLOAT_WIDETAG:
320 #ifdef LONG_FLOAT_WIDETAG
321 case LONG_FLOAT_WIDETAG:
323 case SIMPLE_ARRAY_NIL_WIDETAG:
324 case SIMPLE_BASE_STRING_WIDETAG:
325 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
326 case SIMPLE_CHARACTER_STRING_WIDETAG:
328 case SIMPLE_BIT_VECTOR_WIDETAG:
329 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
330 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
331 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
332 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
333 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
334 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
335 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG
336 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
338 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
339 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
340 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
341 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
343 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
344 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
346 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
347 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
349 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
350 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
352 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
353 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
355 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
356 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
358 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
359 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
361 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
362 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
364 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
365 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
367 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
368 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
369 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
370 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
372 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
373 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
375 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
376 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
378 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
379 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
382 case WEAK_POINTER_WIDETAG:
386 if (pointer_filter_verbose) {
387 fprintf(stderr,"*Wo6: %x %x %x\n", (unsigned long) pointer,
388 (unsigned long) start_addr, *start_addr);
394 if (pointer_filter_verbose) {
395 fprintf(stderr,"*W?: %x %x %x\n", (unsigned long) pointer,
396 (unsigned long) start_addr, *start_addr);
405 #define MAX_STACK_POINTERS 256
406 lispobj *valid_stack_locations[MAX_STACK_POINTERS];
407 unsigned long num_valid_stack_locations;
409 #define MAX_STACK_RETURN_ADDRESSES 128
410 lispobj *valid_stack_ra_locations[MAX_STACK_RETURN_ADDRESSES];
411 lispobj *valid_stack_ra_code_objects[MAX_STACK_RETURN_ADDRESSES];
412 unsigned long num_valid_stack_ra_locations;
414 /* Identify valid stack slots. */
416 setup_i386_stack_scav(lispobj *lowaddr, lispobj *base)
418 lispobj *sp = lowaddr;
419 num_valid_stack_locations = 0;
420 num_valid_stack_ra_locations = 0;
421 for (sp = lowaddr; sp < base; sp++) {
423 /* Find the object start address */
424 lispobj *start_addr = search_dynamic_space((void *)thing);
426 /* We need to allow raw pointers into Code objects for
427 * return addresses. This will also pick up pointers to
428 * functions in code objects. */
429 if (widetag_of(*start_addr) == CODE_HEADER_WIDETAG) {
430 /* FIXME asserting here is a really dumb thing to do.
431 * If we've overflowed some arbitrary static limit, we
432 * should just refuse to purify, instead of killing
433 * the whole lisp session
435 gc_assert(num_valid_stack_ra_locations <
436 MAX_STACK_RETURN_ADDRESSES);
437 valid_stack_ra_locations[num_valid_stack_ra_locations] = sp;
438 valid_stack_ra_code_objects[num_valid_stack_ra_locations++] =
439 (lispobj *)((long)start_addr + OTHER_POINTER_LOWTAG);
441 if (valid_dynamic_space_pointer((void *)thing, start_addr)) {
442 gc_assert(num_valid_stack_locations < MAX_STACK_POINTERS);
443 valid_stack_locations[num_valid_stack_locations++] = sp;
448 if (pointer_filter_verbose) {
449 fprintf(stderr, "number of valid stack pointers = %d\n",
450 num_valid_stack_locations);
451 fprintf(stderr, "number of stack return addresses = %d\n",
452 num_valid_stack_ra_locations);
457 pscav_i386_stack(void)
461 for (i = 0; i < num_valid_stack_locations; i++)
462 pscav(valid_stack_locations[i], 1, 0);
464 for (i = 0; i < num_valid_stack_ra_locations; i++) {
465 lispobj code_obj = (lispobj)valid_stack_ra_code_objects[i];
466 pscav(&code_obj, 1, 0);
467 if (pointer_filter_verbose) {
468 fprintf(stderr,"*C moved RA %x to %x; for code object %x to %x\n",
469 *valid_stack_ra_locations[i],
470 (long)(*valid_stack_ra_locations[i])
471 - ((long)valid_stack_ra_code_objects[i] - (long)code_obj),
472 (unsigned long) valid_stack_ra_code_objects[i], code_obj);
474 *valid_stack_ra_locations[i] =
475 ((long)(*valid_stack_ra_locations[i])
476 - ((long)valid_stack_ra_code_objects[i] - (long)code_obj));
484 pscav_later(lispobj *where, long count)
488 if (count > LATERMAXCOUNT) {
489 while (count > LATERMAXCOUNT) {
490 pscav_later(where, LATERMAXCOUNT);
491 count -= LATERMAXCOUNT;
492 where += LATERMAXCOUNT;
496 if (later_blocks == NULL || later_count == LATERBLOCKSIZE ||
497 (later_count == LATERBLOCKSIZE-1 && count > 1)) {
498 new = (struct later *)malloc(sizeof(struct later));
499 new->next = later_blocks;
500 if (later_blocks && later_count < LATERBLOCKSIZE)
501 later_blocks->u[later_count].ptr = NULL;
507 later_blocks->u[later_count++].count = count;
508 later_blocks->u[later_count++].ptr = where;
513 ptrans_boxed(lispobj thing, lispobj header, boolean constant)
516 lispobj result, *new, *old;
518 nwords = CEILING(1 + HeaderValue(header), 2);
521 old = (lispobj *)native_pointer(thing);
522 new = newspace_alloc(nwords,constant);
525 bcopy(old, new, nwords * sizeof(lispobj));
527 /* Deposit forwarding pointer. */
528 result = make_lispobj(new, lowtag_of(thing));
532 pscav(new, nwords, constant);
537 /* We need to look at the layout to see whether it is a pure structure
538 * class, and only then can we transport as constant. If it is pure,
539 * we can ALWAYS transport as a constant. */
541 ptrans_instance(lispobj thing, lispobj header, boolean /* ignored */ constant)
543 lispobj layout = ((struct instance *)native_pointer(thing))->slots[0];
544 lispobj pure = ((struct instance *)native_pointer(layout))->slots[15];
548 return (ptrans_boxed(thing, header, 1));
550 return (ptrans_boxed(thing, header, 0));
553 /* Substructure: special case for the COMPACT-INFO-ENVs,
554 * where the instance may have a point to the dynamic
555 * space placed into it (e.g. the cache-name slot), but
556 * the lists and arrays at the time of a purify can be
557 * moved to the RO space. */
559 lispobj result, *new, *old;
561 nwords = CEILING(1 + HeaderValue(header), 2);
564 old = (lispobj *)native_pointer(thing);
565 new = newspace_alloc(nwords, 0); /* inconstant */
568 bcopy(old, new, nwords * sizeof(lispobj));
570 /* Deposit forwarding pointer. */
571 result = make_lispobj(new, lowtag_of(thing));
575 pscav(new, nwords, 1);
581 return NIL; /* dummy value: return something ... */
586 ptrans_fdefn(lispobj thing, lispobj header)
589 lispobj result, *new, *old, oldfn;
592 nwords = CEILING(1 + HeaderValue(header), 2);
595 old = (lispobj *)native_pointer(thing);
596 new = newspace_alloc(nwords, 0); /* inconstant */
599 bcopy(old, new, nwords * sizeof(lispobj));
601 /* Deposit forwarding pointer. */
602 result = make_lispobj(new, lowtag_of(thing));
605 /* Scavenge the function. */
606 fdefn = (struct fdefn *)new;
608 pscav(&fdefn->fun, 1, 0);
609 if ((char *)oldfn + FUN_RAW_ADDR_OFFSET == fdefn->raw_addr)
610 fdefn->raw_addr = (char *)fdefn->fun + FUN_RAW_ADDR_OFFSET;
616 ptrans_unboxed(lispobj thing, lispobj header)
619 lispobj result, *new, *old;
621 nwords = CEILING(1 + HeaderValue(header), 2);
624 old = (lispobj *)native_pointer(thing);
625 new = newspace_alloc(nwords,1); /* always constant */
628 bcopy(old, new, nwords * sizeof(lispobj));
630 /* Deposit forwarding pointer. */
631 result = make_lispobj(new , lowtag_of(thing));
638 ptrans_vector(lispobj thing, long bits, long extra,
639 boolean boxed, boolean constant)
641 struct vector *vector;
643 lispobj result, *new;
646 vector = (struct vector *)native_pointer(thing);
647 length = fixnum_value(vector->length)+extra;
648 // Argh, handle simple-vector-nil separately.
652 nwords = CEILING(NWORDS(length, bits) + 2, 2);
655 new=newspace_alloc(nwords, (constant || !boxed));
656 bcopy(vector, new, nwords * sizeof(lispobj));
658 result = make_lispobj(new, lowtag_of(thing));
659 vector->header = result;
662 pscav(new, nwords, constant);
667 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
669 apply_code_fixups_during_purify(struct code *old_code, struct code *new_code)
671 long nheader_words, ncode_words, nwords;
672 void *constants_start_addr, *constants_end_addr;
673 void *code_start_addr, *code_end_addr;
674 lispobj fixups = NIL;
675 unsigned displacement = (unsigned)new_code - (unsigned)old_code;
676 struct vector *fixups_vector;
678 ncode_words = fixnum_value(new_code->code_size);
679 nheader_words = HeaderValue(*(lispobj *)new_code);
680 nwords = ncode_words + nheader_words;
682 constants_start_addr = (void *)new_code + 5 * N_WORD_BYTES;
683 constants_end_addr = (void *)new_code + nheader_words*N_WORD_BYTES;
684 code_start_addr = (void *)new_code + nheader_words*N_WORD_BYTES;
685 code_end_addr = (void *)new_code + nwords*N_WORD_BYTES;
687 /* The first constant should be a pointer to the fixups for this
688 * code objects. Check. */
689 fixups = new_code->constants[0];
691 /* It will be 0 or the unbound-marker if there are no fixups, and
692 * will be an other-pointer to a vector if it is valid. */
694 (fixups==UNBOUND_MARKER_WIDETAG) ||
695 !is_lisp_pointer(fixups)) {
696 #ifdef LISP_FEATURE_GENCGC
697 /* Check for a possible errors. */
698 sniff_code_object(new_code,displacement);
703 fixups_vector = (struct vector *)native_pointer(fixups);
705 /* Could be pointing to a forwarding pointer. */
706 if (is_lisp_pointer(fixups) && (dynamic_pointer_p(fixups))
707 && forwarding_pointer_p(*(lispobj *)fixups_vector)) {
708 /* If so then follow it. */
710 (struct vector *)native_pointer(*(lispobj *)fixups_vector);
713 if (widetag_of(fixups_vector->header) == SIMPLE_ARRAY_WORD_WIDETAG) {
714 /* We got the fixups for the code block. Now work through the
715 * vector, and apply a fixup at each address. */
716 long length = fixnum_value(fixups_vector->length);
718 for (i=0; i<length; i++) {
719 unsigned offset = fixups_vector->data[i];
720 /* Now check the current value of offset. */
722 *(unsigned *)((unsigned)code_start_addr + offset);
724 /* If it's within the old_code object then it must be an
725 * absolute fixup (relative ones are not saved) */
726 if ((old_value>=(unsigned)old_code)
727 && (old_value<((unsigned)old_code + nwords * N_WORD_BYTES)))
728 /* So add the dispacement. */
729 *(unsigned *)((unsigned)code_start_addr + offset) = old_value
732 /* It is outside the old code object so it must be a relative
733 * fixup (absolute fixups are not saved). So subtract the
735 *(unsigned *)((unsigned)code_start_addr + offset) = old_value
740 /* No longer need the fixups. */
741 new_code->constants[0] = 0;
743 #ifdef LISP_FEATURE_GENCGC
744 /* Check for possible errors. */
745 sniff_code_object(new_code,displacement);
751 ptrans_code(lispobj thing)
753 struct code *code, *new;
755 lispobj func, result;
757 code = (struct code *)native_pointer(thing);
758 nwords = CEILING(HeaderValue(code->header) + fixnum_value(code->code_size),
761 new = (struct code *)newspace_alloc(nwords,1); /* constant */
763 bcopy(code, new, nwords * sizeof(lispobj));
765 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
766 apply_code_fixups_during_purify(code,new);
769 result = make_lispobj(new, OTHER_POINTER_LOWTAG);
771 /* Stick in a forwarding pointer for the code object. */
772 *(lispobj *)code = result;
774 /* Put in forwarding pointers for all the functions. */
775 for (func = code->entry_points;
777 func = ((struct simple_fun *)native_pointer(func))->next) {
779 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
781 *(lispobj *)native_pointer(func) = result + (func - thing);
784 /* Arrange to scavenge the debug info later. */
785 pscav_later(&new->debug_info, 1);
787 /* FIXME: why would this be a fixnum? */
788 /* "why" is a hard word, but apparently for compiled functions the
789 trace_table_offset contains the length of the instructions, as
790 a fixnum. See CODE-INST-AREA-LENGTH in
791 src/compiler/target-disassem.lisp. -- CSR, 2004-01-08 */
792 if (!(fixnump(new->trace_table_offset)))
794 pscav(&new->trace_table_offset, 1, 0);
796 new->trace_table_offset = NIL; /* limit lifetime */
799 /* Scavenge the constants. */
800 pscav(new->constants, HeaderValue(new->header)-5, 1);
802 /* Scavenge all the functions. */
803 pscav(&new->entry_points, 1, 1);
804 for (func = new->entry_points;
806 func = ((struct simple_fun *)native_pointer(func))->next) {
807 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
808 gc_assert(!dynamic_pointer_p(func));
810 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
811 /* Temporarily convert the self pointer to a real function pointer. */
812 ((struct simple_fun *)native_pointer(func))->self
813 -= FUN_RAW_ADDR_OFFSET;
815 pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
816 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
817 ((struct simple_fun *)native_pointer(func))->self
818 += FUN_RAW_ADDR_OFFSET;
820 pscav_later(&((struct simple_fun *)native_pointer(func))->name, 3);
827 ptrans_func(lispobj thing, lispobj header)
830 lispobj code, *new, *old, result;
831 struct simple_fun *function;
833 /* Thing can either be a function header, a closure function
834 * header, a closure, or a funcallable-instance. If it's a closure
835 * or a funcallable-instance, we do the same as ptrans_boxed.
836 * Otherwise we have to do something strange, 'cause it is buried
837 * inside a code object. */
839 if (widetag_of(header) == SIMPLE_FUN_HEADER_WIDETAG) {
841 /* We can only end up here if the code object has not been
842 * scavenged, because if it had been scavenged, forwarding pointers
843 * would have been left behind for all the entry points. */
845 function = (struct simple_fun *)native_pointer(thing);
848 ((native_pointer(thing) -
849 (HeaderValue(function->header))), OTHER_POINTER_LOWTAG);
851 /* This will cause the function's header to be replaced with a
852 * forwarding pointer. */
856 /* So we can just return that. */
857 return function->header;
860 /* It's some kind of closure-like thing. */
861 nwords = CEILING(1 + HeaderValue(header), 2);
862 old = (lispobj *)native_pointer(thing);
864 /* Allocate the new one. FINs *must* not go in read_only
865 * space. Closures can; they never change */
868 (nwords,(widetag_of(header)!=FUNCALLABLE_INSTANCE_HEADER_WIDETAG));
871 bcopy(old, new, nwords * sizeof(lispobj));
873 /* Deposit forwarding pointer. */
874 result = make_lispobj(new, lowtag_of(thing));
878 pscav(new, nwords, 0);
885 ptrans_returnpc(lispobj thing, lispobj header)
889 /* Find the corresponding code object. */
890 code = thing - HeaderValue(header)*sizeof(lispobj);
892 /* Make sure it's been transported. */
893 new = *(lispobj *)native_pointer(code);
894 if (!forwarding_pointer_p(new))
895 new = ptrans_code(code);
897 /* Maintain the offset: */
898 return new + (thing - code);
901 #define WORDS_PER_CONS CEILING(sizeof(struct cons) / sizeof(lispobj), 2)
904 ptrans_list(lispobj thing, boolean constant)
906 struct cons *old, *new, *orig;
909 orig = (struct cons *) newspace_alloc(0,constant);
913 /* Allocate a new cons cell. */
914 old = (struct cons *)native_pointer(thing);
915 new = (struct cons *) newspace_alloc(WORDS_PER_CONS,constant);
917 /* Copy the cons cell and keep a pointer to the cdr. */
919 thing = new->cdr = old->cdr;
921 /* Set up the forwarding pointer. */
922 *(lispobj *)old = make_lispobj(new, LIST_POINTER_LOWTAG);
924 /* And count this cell. */
926 } while (lowtag_of(thing) == LIST_POINTER_LOWTAG &&
927 dynamic_pointer_p(thing) &&
928 !(forwarding_pointer_p(*(lispobj *)native_pointer(thing))));
930 /* Scavenge the list we just copied. */
931 pscav((lispobj *)orig, length * WORDS_PER_CONS, constant);
933 return make_lispobj(orig, LIST_POINTER_LOWTAG);
937 ptrans_otherptr(lispobj thing, lispobj header, boolean constant)
939 switch (widetag_of(header)) {
940 /* FIXME: this needs a reindent */
942 case SINGLE_FLOAT_WIDETAG:
943 case DOUBLE_FLOAT_WIDETAG:
944 #ifdef LONG_FLOAT_WIDETAG
945 case LONG_FLOAT_WIDETAG:
947 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
948 case COMPLEX_SINGLE_FLOAT_WIDETAG:
950 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
951 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
953 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
954 case COMPLEX_LONG_FLOAT_WIDETAG:
957 return ptrans_unboxed(thing, header);
960 case COMPLEX_WIDETAG:
961 case SIMPLE_ARRAY_WIDETAG:
962 case COMPLEX_BASE_STRING_WIDETAG:
963 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
964 case COMPLEX_CHARACTER_STRING_WIDETAG:
966 case COMPLEX_BIT_VECTOR_WIDETAG:
967 case COMPLEX_VECTOR_NIL_WIDETAG:
968 case COMPLEX_VECTOR_WIDETAG:
969 case COMPLEX_ARRAY_WIDETAG:
970 return ptrans_boxed(thing, header, constant);
972 case VALUE_CELL_HEADER_WIDETAG:
973 case WEAK_POINTER_WIDETAG:
974 return ptrans_boxed(thing, header, 0);
976 case SYMBOL_HEADER_WIDETAG:
977 return ptrans_boxed(thing, header, 0);
979 case SIMPLE_ARRAY_NIL_WIDETAG:
980 return ptrans_vector(thing, 0, 0, 0, constant);
982 case SIMPLE_BASE_STRING_WIDETAG:
983 return ptrans_vector(thing, 8, 1, 0, constant);
985 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
986 case SIMPLE_CHARACTER_STRING_WIDETAG:
987 return ptrans_vector(thing, 32, 1, 0, constant);
990 case SIMPLE_BIT_VECTOR_WIDETAG:
991 return ptrans_vector(thing, 1, 0, 0, constant);
993 case SIMPLE_VECTOR_WIDETAG:
994 return ptrans_vector(thing, N_WORD_BITS, 0, 1, constant);
996 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
997 return ptrans_vector(thing, 2, 0, 0, constant);
999 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
1000 return ptrans_vector(thing, 4, 0, 0, constant);
1002 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
1003 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
1004 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
1005 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
1007 return ptrans_vector(thing, 8, 0, 0, constant);
1009 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
1010 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
1011 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
1012 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
1014 return ptrans_vector(thing, 16, 0, 0, constant);
1016 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
1017 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1018 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
1019 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
1021 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1022 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
1023 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
1025 return ptrans_vector(thing, 32, 0, 0, constant);
1027 #if N_WORD_BITS == 64
1028 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
1029 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
1031 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
1032 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
1034 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
1035 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
1037 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1038 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
1040 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1041 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
1043 return ptrans_vector(thing, 64, 0, 0, constant);
1046 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
1047 return ptrans_vector(thing, 32, 0, 0, constant);
1049 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
1050 return ptrans_vector(thing, 64, 0, 0, constant);
1052 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1053 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
1054 #ifdef LISP_FEATURE_X86
1055 return ptrans_vector(thing, 96, 0, 0, constant);
1058 return ptrans_vector(thing, 128, 0, 0, constant);
1062 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1063 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
1064 return ptrans_vector(thing, 64, 0, 0, constant);
1067 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1068 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
1069 return ptrans_vector(thing, 128, 0, 0, constant);
1072 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1073 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
1074 #ifdef LISP_FEATURE_X86
1075 return ptrans_vector(thing, 192, 0, 0, constant);
1078 return ptrans_vector(thing, 256, 0, 0, constant);
1082 case CODE_HEADER_WIDETAG:
1083 return ptrans_code(thing);
1085 case RETURN_PC_HEADER_WIDETAG:
1086 return ptrans_returnpc(thing, header);
1089 return ptrans_fdefn(thing, header);
1092 fprintf(stderr, "Invalid widetag: %d\n", widetag_of(header));
1093 /* Should only come across other pointers to the above stuff. */
1100 pscav_fdefn(struct fdefn *fdefn)
1104 fix_func = ((char *)(fdefn->fun+FUN_RAW_ADDR_OFFSET) == fdefn->raw_addr);
1105 pscav(&fdefn->name, 1, 1);
1106 pscav(&fdefn->fun, 1, 0);
1108 fdefn->raw_addr = (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET);
1109 return sizeof(struct fdefn) / sizeof(lispobj);
1112 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1113 /* now putting code objects in static space */
1115 pscav_code(struct code*code)
1119 nwords = CEILING(HeaderValue(code->header) + fixnum_value(code->code_size),
1122 /* Arrange to scavenge the debug info later. */
1123 pscav_later(&code->debug_info, 1);
1125 /* Scavenge the constants. */
1126 pscav(code->constants, HeaderValue(code->header)-5, 1);
1128 /* Scavenge all the functions. */
1129 pscav(&code->entry_points, 1, 1);
1130 for (func = code->entry_points;
1132 func = ((struct simple_fun *)native_pointer(func))->next) {
1133 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
1134 gc_assert(!dynamic_pointer_p(func));
1136 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1137 /* Temporarily convert the self pointer to a real function
1139 ((struct simple_fun *)native_pointer(func))->self
1140 -= FUN_RAW_ADDR_OFFSET;
1142 pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
1143 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1144 ((struct simple_fun *)native_pointer(func))->self
1145 += FUN_RAW_ADDR_OFFSET;
1147 pscav_later(&((struct simple_fun *)native_pointer(func))->name, 3);
1150 return CEILING(nwords,2);
1155 pscav(lispobj *addr, long nwords, boolean constant)
1157 lispobj thing, *thingp, header;
1158 long count = 0; /* (0 = dummy init value to stop GCC warning) */
1159 struct vector *vector;
1161 while (nwords > 0) {
1163 if (is_lisp_pointer(thing)) {
1164 /* It's a pointer. Is it something we might have to move? */
1165 if (dynamic_pointer_p(thing)) {
1166 /* Maybe. Have we already moved it? */
1167 thingp = (lispobj *)native_pointer(thing);
1169 if (is_lisp_pointer(header) && forwarding_pointer_p(header))
1170 /* Yep, so just copy the forwarding pointer. */
1173 /* Nope, copy the object. */
1174 switch (lowtag_of(thing)) {
1175 case FUN_POINTER_LOWTAG:
1176 thing = ptrans_func(thing, header);
1179 case LIST_POINTER_LOWTAG:
1180 thing = ptrans_list(thing, constant);
1183 case INSTANCE_POINTER_LOWTAG:
1184 thing = ptrans_instance(thing, header, constant);
1187 case OTHER_POINTER_LOWTAG:
1188 thing = ptrans_otherptr(thing, header, constant);
1192 /* It was a pointer, but not one of them? */
1200 #if N_WORD_BITS == 64
1201 else if (widetag_of(thing) == SINGLE_FLOAT_WIDETAG) {
1205 else if (thing & FIXNUM_TAG_MASK) {
1206 /* It's an other immediate. Maybe the header for an unboxed */
1208 switch (widetag_of(thing)) {
1209 case BIGNUM_WIDETAG:
1210 case SINGLE_FLOAT_WIDETAG:
1211 case DOUBLE_FLOAT_WIDETAG:
1212 #ifdef LONG_FLOAT_WIDETAG
1213 case LONG_FLOAT_WIDETAG:
1216 /* It's an unboxed simple object. */
1217 count = CEILING(HeaderValue(thing)+1, 2);
1220 case SIMPLE_VECTOR_WIDETAG:
1221 if (HeaderValue(thing) == subtype_VectorValidHashing) {
1222 *addr = (subtype_VectorMustRehash << N_WIDETAG_BITS) |
1223 SIMPLE_VECTOR_WIDETAG;
1228 case SIMPLE_ARRAY_NIL_WIDETAG:
1232 case SIMPLE_BASE_STRING_WIDETAG:
1233 vector = (struct vector *)addr;
1234 count = CEILING(NWORDS(fixnum_value(vector->length)+1,8)+2,2);
1237 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
1238 case SIMPLE_CHARACTER_STRING_WIDETAG:
1239 vector = (struct vector *)addr;
1240 count = CEILING(NWORDS(fixnum_value(vector->length)+1,32)+2,2);
1244 case SIMPLE_BIT_VECTOR_WIDETAG:
1245 vector = (struct vector *)addr;
1246 count = CEILING(NWORDS(fixnum_value(vector->length),1)+2,2);
1249 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
1250 vector = (struct vector *)addr;
1251 count = CEILING(NWORDS(fixnum_value(vector->length),2)+2,2);
1254 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
1255 vector = (struct vector *)addr;
1256 count = CEILING(NWORDS(fixnum_value(vector->length),4)+2,2);
1259 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
1260 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
1261 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
1262 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
1264 vector = (struct vector *)addr;
1265 count = CEILING(NWORDS(fixnum_value(vector->length),8)+2,2);
1268 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
1269 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
1270 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
1271 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
1273 vector = (struct vector *)addr;
1274 count = CEILING(NWORDS(fixnum_value(vector->length),16)+2,2);
1277 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
1278 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1279 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
1280 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
1282 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1283 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
1284 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
1286 vector = (struct vector *)addr;
1287 count = CEILING(NWORDS(fixnum_value(vector->length),32)+2,2);
1290 #if N_WORD_BITS == 64
1291 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
1292 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1293 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
1294 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
1296 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1297 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
1298 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
1300 vector = (struct vector *)addr;
1301 count = CEILING(NWORDS(fixnum_value(vector->length),64)+2,2);
1305 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
1306 vector = (struct vector *)addr;
1307 count = CEILING(NWORDS(fixnum_value(vector->length), 32) + 2,
1311 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
1312 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1313 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
1315 vector = (struct vector *)addr;
1316 count = CEILING(NWORDS(fixnum_value(vector->length), 64) + 2,
1320 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1321 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
1322 vector = (struct vector *)addr;
1323 #ifdef LISP_FEATURE_X86
1324 count = fixnum_value(vector->length)*3+2;
1327 count = fixnum_value(vector->length)*4+2;
1332 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1333 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
1334 vector = (struct vector *)addr;
1335 count = CEILING(NWORDS(fixnum_value(vector->length), 128) + 2,
1340 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1341 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
1342 vector = (struct vector *)addr;
1343 #ifdef LISP_FEATURE_X86
1344 count = fixnum_value(vector->length)*6+2;
1347 count = fixnum_value(vector->length)*8+2;
1352 case CODE_HEADER_WIDETAG:
1353 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1354 gc_abort(); /* no code headers in static space */
1356 count = pscav_code((struct code*)addr);
1360 case SIMPLE_FUN_HEADER_WIDETAG:
1361 case RETURN_PC_HEADER_WIDETAG:
1362 /* We should never hit any of these, 'cause they occur
1363 * buried in the middle of code objects. */
1367 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1368 case CLOSURE_HEADER_WIDETAG:
1369 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
1370 /* The function self pointer needs special care on the
1371 * x86 because it is the real entry point. */
1373 lispobj fun = ((struct closure *)addr)->fun
1374 - FUN_RAW_ADDR_OFFSET;
1375 pscav(&fun, 1, constant);
1376 ((struct closure *)addr)->fun = fun + FUN_RAW_ADDR_OFFSET;
1382 case WEAK_POINTER_WIDETAG:
1383 /* Weak pointers get preserved during purify, 'cause I
1384 * don't feel like figuring out how to break them. */
1385 pscav(addr+1, 2, constant);
1390 /* We have to handle fdefn objects specially, so we
1391 * can fix up the raw function address. */
1392 count = pscav_fdefn((struct fdefn *)addr);
1401 /* It's a fixnum. */
1413 purify(lispobj static_roots, lispobj read_only_roots)
1417 struct later *laters, *next;
1418 struct thread *thread;
1420 if(all_threads->next) {
1421 /* FIXME: there should be _some_ sensible error reporting
1422 * convention. See following comment too */
1423 fprintf(stderr,"Can't purify when more than one thread exists\n");
1429 printf("[doing purification:");
1432 #ifdef LISP_FEATURE_GENCGC
1433 gc_alloc_update_all_page_tables();
1435 for_each_thread(thread)
1436 if (fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,thread)) != 0) {
1437 /* FIXME: 1. What does this mean? 2. It shouldn't be reporting
1438 * its error simply by a. printing a string b. to stdout instead
1440 printf(" Ack! Can't purify interrupt contexts. ");
1445 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1446 dynamic_space_free_pointer =
1447 (lispobj*)SymbolValue(ALLOCATION_POINTER,0);
1450 read_only_end = read_only_free =
1451 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER,0);
1452 static_end = static_free =
1453 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER,0);
1460 #if defined(LISP_FEATURE_GENCGC) && (defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
1461 /* note this expects only one thread to be active. We'd have to
1462 * stop all the others in the same way as GC does if we wanted
1463 * PURIFY to work when >1 thread exists */
1464 setup_i386_stack_scav(((&static_roots)-2),
1465 ((void *)all_threads->control_stack_end));
1468 pscav(&static_roots, 1, 0);
1469 pscav(&read_only_roots, 1, 1);
1472 printf(" handlers");
1475 pscav((lispobj *) all_threads->interrupt_data->interrupt_handlers,
1476 sizeof(all_threads->interrupt_data->interrupt_handlers)
1484 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1485 pscav((lispobj *)all_threads->control_stack_start,
1486 current_control_stack_pointer -
1487 all_threads->control_stack_start,
1490 #ifdef LISP_FEATURE_GENCGC
1496 printf(" bindings");
1499 #if !(defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
1500 pscav( (lispobj *)all_threads->binding_stack_start,
1501 (lispobj *)current_binding_stack_pointer -
1502 all_threads->binding_stack_start,
1505 for_each_thread(thread) {
1506 pscav( (lispobj *)thread->binding_stack_start,
1507 (lispobj *)SymbolValue(BINDING_STACK_POINTER,thread) -
1508 (lispobj *)thread->binding_stack_start,
1510 pscav( (lispobj *) (thread+1),
1511 fixnum_value(SymbolValue(FREE_TLS_INDEX,0)) -
1512 (sizeof (struct thread))/(sizeof (lispobj)),
1519 /* The original CMU CL code had scavenge-read-only-space code
1520 * controlled by the Lisp-level variable
1521 * *SCAVENGE-READ-ONLY-SPACE*. It was disabled by default, and it
1522 * wasn't documented under what circumstances it was useful or
1523 * safe to turn it on, so it's been turned off in SBCL. If you
1524 * want/need this functionality, and can test and document it,
1525 * please submit a patch. */
1527 if (SymbolValue(SCAVENGE_READ_ONLY_SPACE) != UNBOUND_MARKER_WIDETAG
1528 && SymbolValue(SCAVENGE_READ_ONLY_SPACE) != NIL) {
1529 unsigned read_only_space_size =
1530 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER) -
1531 (lispobj *)READ_ONLY_SPACE_START;
1533 "scavenging read only space: %d bytes\n",
1534 read_only_space_size * sizeof(lispobj));
1535 pscav( (lispobj *)READ_ONLY_SPACE_START, read_only_space_size, 0);
1543 clean = (lispobj *)STATIC_SPACE_START;
1545 while (clean != static_free)
1546 clean = pscav(clean, static_free - clean, 0);
1547 laters = later_blocks;
1548 count = later_count;
1549 later_blocks = NULL;
1551 while (laters != NULL) {
1552 for (i = 0; i < count; i++) {
1553 if (laters->u[i].count == 0) {
1555 } else if (laters->u[i].count <= LATERMAXCOUNT) {
1556 pscav(laters->u[i+1].ptr, laters->u[i].count, 1);
1559 pscav(laters->u[i].ptr, 1, 1);
1562 next = laters->next;
1565 count = LATERBLOCKSIZE;
1567 } while (clean != static_free || later_blocks != NULL);
1574 os_zero((os_vm_address_t) current_dynamic_space,
1575 (os_vm_size_t) DYNAMIC_SPACE_SIZE);
1577 /* Zero the stack. Note that the stack is also zeroed by SUB-GC
1578 * calling SCRUB-CONTROL-STACK - this zeros the stack on the x86. */
1579 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1580 os_zero((os_vm_address_t) current_control_stack_pointer,
1582 ((all_threads->control_stack_end -
1583 current_control_stack_pointer) * sizeof(lispobj)));
1586 /* It helps to update the heap free pointers so that free_heap can
1587 * verify after it's done. */
1588 SetSymbolValue(READ_ONLY_SPACE_FREE_POINTER, (lispobj)read_only_free,0);
1589 SetSymbolValue(STATIC_SPACE_FREE_POINTER, (lispobj)static_free,0);
1591 #if !defined(ALLOCATION_POINTER)
1592 dynamic_space_free_pointer = current_dynamic_space;
1593 set_auto_gc_trigger(bytes_consed_between_gcs);
1595 #if defined LISP_FEATURE_GENCGC
1598 #error unsupported case /* in CMU CL, was "ibmrt using GC" */