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 static lispobj *dynamic_space_purify_pointer;
43 /* These hold the original end of the read_only and static spaces so
44 * we can tell what are forwarding pointers. */
46 static lispobj *read_only_end, *static_end;
48 static lispobj *read_only_free, *static_free;
50 static lispobj *pscav(lispobj *addr, long nwords, boolean constant);
52 #define LATERBLOCKSIZE 1020
53 #define LATERMAXCOUNT 10
62 } *later_blocks = NULL;
63 static long later_count = 0;
66 #define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
67 #elif N_WORD_BITS == 64
68 #define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
73 forwarding_pointer_p(lispobj obj)
75 lispobj *ptr = native_pointer(obj);
77 return ((static_end <= ptr && ptr <= static_free) ||
78 (read_only_end <= ptr && ptr <= read_only_free));
82 dynamic_pointer_p(lispobj ptr)
84 #ifndef LISP_FEATURE_GENCGC
85 return (ptr >= (lispobj)current_dynamic_space
87 ptr < (lispobj)dynamic_space_purify_pointer);
89 /* Be more conservative, and remember, this is a maybe. */
90 return (ptr >= (lispobj)DYNAMIC_SPACE_START
92 ptr < (lispobj)dynamic_space_purify_pointer);
96 static inline lispobj *
97 newspace_alloc(long nwords, int constantp)
100 nwords=CEILING(nwords,2);
102 if(read_only_free + nwords >= (lispobj *)READ_ONLY_SPACE_END) {
103 lose("Ran out of read-only space while purifying!\n");
106 read_only_free+=nwords;
108 if(static_free + nwords >= (lispobj *)STATIC_SPACE_END) {
109 lose("Ran out of static space while purifying!\n");
119 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
121 #ifdef LISP_FEATURE_GENCGC
123 * enhanced x86/GENCGC stack scavenging by Douglas Crosher
125 * Scavenging the stack on the i386 is problematic due to conservative
126 * roots and raw return addresses. Here it is handled in two passes:
127 * the first pass runs before any objects are moved and tries to
128 * identify valid pointers and return address on the stack, the second
129 * pass scavenges these.
132 static unsigned pointer_filter_verbose = 0;
134 /* FIXME: This is substantially the same code as
135 * possibly_valid_dynamic_space_pointer in gencgc.c. The only
136 * relevant difference seems to be that the gencgc code also checks
137 * for raw pointers into Code objects, whereas in purify these are
138 * checked separately in setup_i386_stack_scav - they go onto
139 * valid_stack_ra_locations instead of just valid_stack_locations */
142 valid_dynamic_space_pointer(lispobj *pointer, lispobj *start_addr)
144 /* If it's not a return address then it needs to be a valid Lisp
146 if (!is_lisp_pointer((lispobj)pointer))
149 /* Check that the object pointed to is consistent with the pointer
151 switch (lowtag_of((lispobj)pointer)) {
152 case FUN_POINTER_LOWTAG:
153 /* Start_addr should be the enclosing code object, or a closure
155 switch (widetag_of(*start_addr)) {
156 case CODE_HEADER_WIDETAG:
157 /* This case is probably caught above. */
159 case CLOSURE_HEADER_WIDETAG:
160 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
161 if ((long)pointer != ((long)start_addr+FUN_POINTER_LOWTAG)) {
162 if (pointer_filter_verbose) {
163 fprintf(stderr,"*Wf2: %p %p %p\n",
164 pointer, start_addr, (void *)*start_addr);
170 if (pointer_filter_verbose) {
171 fprintf(stderr,"*Wf3: %p %p %p\n",
172 pointer, start_addr, (void *)*start_addr);
177 case LIST_POINTER_LOWTAG:
178 if ((long)pointer != ((long)start_addr+LIST_POINTER_LOWTAG)) {
179 if (pointer_filter_verbose)
180 fprintf(stderr,"*Wl1: %p %p %p\n",
181 pointer, start_addr, (void *)*start_addr);
184 /* Is it plausible cons? */
185 if ((is_lisp_pointer(start_addr[0])
186 || ((start_addr[0] & FIXNUM_TAG_MASK) == 0) /* fixnum */
187 || (widetag_of(start_addr[0]) == CHARACTER_WIDETAG)
188 #if N_WORD_BITS == 64
189 || (widetag_of(start_addr[0]) == SINGLE_FLOAT_WIDETAG)
191 || (widetag_of(start_addr[0]) == UNBOUND_MARKER_WIDETAG))
192 && (is_lisp_pointer(start_addr[1])
193 || ((start_addr[1] & FIXNUM_TAG_MASK) == 0) /* fixnum */
194 || (widetag_of(start_addr[1]) == CHARACTER_WIDETAG)
195 #if N_WORD_BITS == 64
196 || (widetag_of(start_addr[1]) == SINGLE_FLOAT_WIDETAG)
198 || (widetag_of(start_addr[1]) == UNBOUND_MARKER_WIDETAG))) {
201 if (pointer_filter_verbose) {
202 fprintf(stderr,"*Wl2: %p %p %p\n",
203 pointer, start_addr, (void *)*start_addr);
207 case INSTANCE_POINTER_LOWTAG:
208 if ((long)pointer != ((long)start_addr+INSTANCE_POINTER_LOWTAG)) {
209 if (pointer_filter_verbose) {
210 fprintf(stderr,"*Wi1: %p %p %p\n",
211 pointer, start_addr, (void *)*start_addr);
215 if (widetag_of(start_addr[0]) != INSTANCE_HEADER_WIDETAG) {
216 if (pointer_filter_verbose) {
217 fprintf(stderr,"*Wi2: %p %p %p\n",
218 pointer, start_addr, (void *)*start_addr);
223 case OTHER_POINTER_LOWTAG:
224 if ((long)pointer != ((long)start_addr+OTHER_POINTER_LOWTAG)) {
225 if (pointer_filter_verbose) {
226 fprintf(stderr,"*Wo1: %p %p %p\n",
227 pointer, start_addr, (void *)*start_addr);
231 /* Is it plausible? Not a cons. XXX should check the headers. */
232 if (is_lisp_pointer(start_addr[0]) || ((start_addr[0] & FIXNUM_TAG_MASK) == 0)) {
233 if (pointer_filter_verbose) {
234 fprintf(stderr,"*Wo2: %p %p %p\n",
235 pointer, start_addr, (void *)*start_addr);
239 switch (widetag_of(start_addr[0])) {
240 case UNBOUND_MARKER_WIDETAG:
241 case CHARACTER_WIDETAG:
242 #if N_WORD_BITS == 64
243 case SINGLE_FLOAT_WIDETAG:
245 if (pointer_filter_verbose) {
246 fprintf(stderr,"*Wo3: %p %p %p\n",
247 pointer, start_addr, (void *)*start_addr);
251 /* only pointed to by function pointers? */
252 case CLOSURE_HEADER_WIDETAG:
253 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
254 if (pointer_filter_verbose) {
255 fprintf(stderr,"*Wo4: %p %p %p\n",
256 pointer, start_addr, (void *)*start_addr);
260 case INSTANCE_HEADER_WIDETAG:
261 if (pointer_filter_verbose) {
262 fprintf(stderr,"*Wo5: %p %p %p\n",
263 pointer, start_addr, (void *)*start_addr);
267 /* the valid other immediate pointer objects */
268 case SIMPLE_VECTOR_WIDETAG:
270 case COMPLEX_WIDETAG:
271 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
272 case COMPLEX_SINGLE_FLOAT_WIDETAG:
274 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
275 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
277 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
278 case COMPLEX_LONG_FLOAT_WIDETAG:
280 case SIMPLE_ARRAY_WIDETAG:
281 case COMPLEX_BASE_STRING_WIDETAG:
282 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
283 case COMPLEX_CHARACTER_STRING_WIDETAG:
285 case COMPLEX_VECTOR_NIL_WIDETAG:
286 case COMPLEX_BIT_VECTOR_WIDETAG:
287 case COMPLEX_VECTOR_WIDETAG:
288 case COMPLEX_ARRAY_WIDETAG:
289 case VALUE_CELL_HEADER_WIDETAG:
290 case SYMBOL_HEADER_WIDETAG:
292 case CODE_HEADER_WIDETAG:
294 #if N_WORD_BITS != 64
295 case SINGLE_FLOAT_WIDETAG:
297 case DOUBLE_FLOAT_WIDETAG:
298 #ifdef LONG_FLOAT_WIDETAG
299 case LONG_FLOAT_WIDETAG:
301 case SIMPLE_ARRAY_NIL_WIDETAG:
302 case SIMPLE_BASE_STRING_WIDETAG:
303 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
304 case SIMPLE_CHARACTER_STRING_WIDETAG:
306 case SIMPLE_BIT_VECTOR_WIDETAG:
307 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
308 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
309 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
310 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
311 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
312 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
313 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG
314 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
316 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
317 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
318 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
319 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
321 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
322 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
324 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
325 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
327 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
328 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
330 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
331 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
333 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
334 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
336 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
337 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
339 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
340 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
342 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
343 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
345 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
346 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
347 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
348 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
350 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
351 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
353 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
354 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
356 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
357 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
360 case WEAK_POINTER_WIDETAG:
367 if (pointer_filter_verbose) {
368 fprintf(stderr,"*Wo6: %p %p %p\n",
369 pointer, start_addr, (void *)*start_addr);
375 if (pointer_filter_verbose) {
376 fprintf(stderr,"*W?: %p %p %p\n",
377 pointer, start_addr, (void *)*start_addr);
386 #define MAX_STACK_POINTERS 256
387 lispobj *valid_stack_locations[MAX_STACK_POINTERS];
388 unsigned long num_valid_stack_locations;
390 #define MAX_STACK_RETURN_ADDRESSES 128
391 lispobj *valid_stack_ra_locations[MAX_STACK_RETURN_ADDRESSES];
392 lispobj *valid_stack_ra_code_objects[MAX_STACK_RETURN_ADDRESSES];
393 unsigned long num_valid_stack_ra_locations;
395 /* Identify valid stack slots. */
397 setup_i386_stack_scav(lispobj *lowaddr, lispobj *base)
399 lispobj *sp = lowaddr;
400 num_valid_stack_locations = 0;
401 num_valid_stack_ra_locations = 0;
402 for (sp = lowaddr; sp < base; sp++) {
404 /* Find the object start address */
405 lispobj *start_addr = search_dynamic_space((void *)thing);
407 /* We need to allow raw pointers into Code objects for
408 * return addresses. This will also pick up pointers to
409 * functions in code objects. */
410 if (widetag_of(*start_addr) == CODE_HEADER_WIDETAG) {
411 /* FIXME asserting here is a really dumb thing to do.
412 * If we've overflowed some arbitrary static limit, we
413 * should just refuse to purify, instead of killing
414 * the whole lisp session
416 gc_assert(num_valid_stack_ra_locations <
417 MAX_STACK_RETURN_ADDRESSES);
418 valid_stack_ra_locations[num_valid_stack_ra_locations] = sp;
419 valid_stack_ra_code_objects[num_valid_stack_ra_locations++] =
420 (lispobj *)((long)start_addr + OTHER_POINTER_LOWTAG);
422 if (valid_dynamic_space_pointer((void *)thing, start_addr)) {
423 gc_assert(num_valid_stack_locations < MAX_STACK_POINTERS);
424 valid_stack_locations[num_valid_stack_locations++] = sp;
429 if (pointer_filter_verbose) {
430 fprintf(stderr, "number of valid stack pointers = %ld\n",
431 num_valid_stack_locations);
432 fprintf(stderr, "number of stack return addresses = %ld\n",
433 num_valid_stack_ra_locations);
438 pscav_i386_stack(void)
442 for (i = 0; i < num_valid_stack_locations; i++)
443 pscav(valid_stack_locations[i], 1, 0);
445 for (i = 0; i < num_valid_stack_ra_locations; i++) {
446 lispobj code_obj = (lispobj)valid_stack_ra_code_objects[i];
447 pscav(&code_obj, 1, 0);
448 if (pointer_filter_verbose) {
449 fprintf(stderr,"*C moved RA %p to %p; for code object %p to %p\n",
450 (void *)*valid_stack_ra_locations[i],
451 (void *)(*valid_stack_ra_locations[i]) -
452 ((void *)valid_stack_ra_code_objects[i] -
454 valid_stack_ra_code_objects[i], (void *)code_obj);
456 *valid_stack_ra_locations[i] =
457 ((long)(*valid_stack_ra_locations[i])
458 - ((long)valid_stack_ra_code_objects[i] - (long)code_obj));
466 pscav_later(lispobj *where, long count)
470 if (count > LATERMAXCOUNT) {
471 while (count > LATERMAXCOUNT) {
472 pscav_later(where, LATERMAXCOUNT);
473 count -= LATERMAXCOUNT;
474 where += LATERMAXCOUNT;
478 if (later_blocks == NULL || later_count == LATERBLOCKSIZE ||
479 (later_count == LATERBLOCKSIZE-1 && count > 1)) {
480 new = (struct later *)malloc(sizeof(struct later));
481 new->next = later_blocks;
482 if (later_blocks && later_count < LATERBLOCKSIZE)
483 later_blocks->u[later_count].ptr = NULL;
489 later_blocks->u[later_count++].count = count;
490 later_blocks->u[later_count++].ptr = where;
495 ptrans_boxed(lispobj thing, lispobj header, boolean constant)
498 lispobj result, *new, *old;
500 nwords = CEILING(1 + HeaderValue(header), 2);
503 old = (lispobj *)native_pointer(thing);
504 new = newspace_alloc(nwords,constant);
507 bcopy(old, new, nwords * sizeof(lispobj));
509 /* Deposit forwarding pointer. */
510 result = make_lispobj(new, lowtag_of(thing));
514 pscav(new, nwords, constant);
519 /* We need to look at the layout to see whether it is a pure structure
520 * class, and only then can we transport as constant. If it is pure,
521 * we can ALWAYS transport as a constant. */
523 ptrans_instance(lispobj thing, lispobj header, boolean /* ignored */ constant)
525 struct layout *layout =
526 (struct layout *) native_pointer(((struct instance *)native_pointer(thing))->slots[0]);
527 lispobj pure = layout->pure;
531 return (ptrans_boxed(thing, header, 1));
533 return (ptrans_boxed(thing, header, 0));
536 /* Substructure: special case for the COMPACT-INFO-ENVs,
537 * where the instance may have a point to the dynamic
538 * space placed into it (e.g. the cache-name slot), but
539 * the lists and arrays at the time of a purify can be
540 * moved to the RO space. */
542 lispobj result, *new, *old;
544 nwords = CEILING(1 + HeaderValue(header), 2);
547 old = (lispobj *)native_pointer(thing);
548 new = newspace_alloc(nwords, 0); /* inconstant */
551 bcopy(old, new, nwords * sizeof(lispobj));
553 /* Deposit forwarding pointer. */
554 result = make_lispobj(new, lowtag_of(thing));
558 pscav(new, nwords, 1);
564 return NIL; /* dummy value: return something ... */
569 ptrans_fdefn(lispobj thing, lispobj header)
572 lispobj result, *new, *old, oldfn;
575 nwords = CEILING(1 + HeaderValue(header), 2);
578 old = (lispobj *)native_pointer(thing);
579 new = newspace_alloc(nwords, 0); /* inconstant */
582 bcopy(old, new, nwords * sizeof(lispobj));
584 /* Deposit forwarding pointer. */
585 result = make_lispobj(new, lowtag_of(thing));
588 /* Scavenge the function. */
589 fdefn = (struct fdefn *)new;
591 pscav(&fdefn->fun, 1, 0);
592 if ((char *)oldfn + FUN_RAW_ADDR_OFFSET == fdefn->raw_addr)
593 fdefn->raw_addr = (char *)fdefn->fun + FUN_RAW_ADDR_OFFSET;
599 ptrans_unboxed(lispobj thing, lispobj header)
602 lispobj result, *new, *old;
604 nwords = CEILING(1 + HeaderValue(header), 2);
607 old = (lispobj *)native_pointer(thing);
608 new = newspace_alloc(nwords,1); /* always constant */
611 bcopy(old, new, nwords * sizeof(lispobj));
613 /* Deposit forwarding pointer. */
614 result = make_lispobj(new , lowtag_of(thing));
621 ptrans_vector(lispobj thing, long bits, long extra,
622 boolean boxed, boolean constant)
624 struct vector *vector;
626 lispobj result, *new;
629 vector = (struct vector *)native_pointer(thing);
630 length = fixnum_value(vector->length)+extra;
631 // Argh, handle simple-vector-nil separately.
635 nwords = CEILING(NWORDS(length, bits) + 2, 2);
638 new=newspace_alloc(nwords, (constant || !boxed));
639 bcopy(vector, new, nwords * sizeof(lispobj));
641 result = make_lispobj(new, lowtag_of(thing));
642 vector->header = result;
645 pscav(new, nwords, constant);
650 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
652 apply_code_fixups_during_purify(struct code *old_code, struct code *new_code)
654 long nheader_words, ncode_words, nwords;
655 void *constants_start_addr, *constants_end_addr;
656 void *code_start_addr, *code_end_addr;
657 lispobj fixups = NIL;
658 unsigned long displacement = (unsigned long)new_code - (unsigned long)old_code;
659 struct vector *fixups_vector;
661 ncode_words = fixnum_value(new_code->code_size);
662 nheader_words = HeaderValue(*(lispobj *)new_code);
663 nwords = ncode_words + nheader_words;
665 constants_start_addr = (void *)new_code + 5 * N_WORD_BYTES;
666 constants_end_addr = (void *)new_code + nheader_words*N_WORD_BYTES;
667 code_start_addr = (void *)new_code + nheader_words*N_WORD_BYTES;
668 code_end_addr = (void *)new_code + nwords*N_WORD_BYTES;
670 /* The first constant should be a pointer to the fixups for this
671 * code objects. Check. */
672 fixups = new_code->constants[0];
674 /* It will be 0 or the unbound-marker if there are no fixups, and
675 * will be an other-pointer to a vector if it is valid. */
677 (fixups==UNBOUND_MARKER_WIDETAG) ||
678 !is_lisp_pointer(fixups)) {
679 #ifdef LISP_FEATURE_GENCGC
680 /* Check for a possible errors. */
681 sniff_code_object(new_code,displacement);
686 fixups_vector = (struct vector *)native_pointer(fixups);
688 /* Could be pointing to a forwarding pointer. */
689 if (is_lisp_pointer(fixups) && (dynamic_pointer_p(fixups))
690 && forwarding_pointer_p(*(lispobj *)fixups_vector)) {
691 /* If so then follow it. */
693 (struct vector *)native_pointer(*(lispobj *)fixups_vector);
696 if (widetag_of(fixups_vector->header) == SIMPLE_ARRAY_WORD_WIDETAG) {
697 /* We got the fixups for the code block. Now work through the
698 * vector, and apply a fixup at each address. */
699 long length = fixnum_value(fixups_vector->length);
701 for (i=0; i<length; i++) {
702 unsigned offset = fixups_vector->data[i];
703 /* Now check the current value of offset. */
704 unsigned long old_value =
705 *(unsigned long *)((unsigned long)code_start_addr + offset);
707 /* If it's within the old_code object then it must be an
708 * absolute fixup (relative ones are not saved) */
709 if ((old_value>=(unsigned long)old_code)
710 && (old_value<((unsigned long)old_code + nwords * N_WORD_BYTES)))
711 /* So add the dispacement. */
712 *(unsigned long *)((unsigned long)code_start_addr + offset) = old_value
715 /* It is outside the old code object so it must be a relative
716 * fixup (absolute fixups are not saved). So subtract the
718 *(unsigned long *)((unsigned long)code_start_addr + offset) = old_value
723 /* No longer need the fixups. */
724 new_code->constants[0] = 0;
726 #ifdef LISP_FEATURE_GENCGC
727 /* Check for possible errors. */
728 sniff_code_object(new_code,displacement);
734 ptrans_code(lispobj thing)
736 struct code *code, *new;
738 lispobj func, result;
740 code = (struct code *)native_pointer(thing);
741 nwords = CEILING(HeaderValue(code->header) + fixnum_value(code->code_size),
744 new = (struct code *)newspace_alloc(nwords,1); /* constant */
746 bcopy(code, new, nwords * sizeof(lispobj));
748 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
749 apply_code_fixups_during_purify(code,new);
752 result = make_lispobj(new, OTHER_POINTER_LOWTAG);
754 /* Stick in a forwarding pointer for the code object. */
755 *(lispobj *)code = result;
757 /* Put in forwarding pointers for all the functions. */
758 for (func = code->entry_points;
760 func = ((struct simple_fun *)native_pointer(func))->next) {
762 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
764 *(lispobj *)native_pointer(func) = result + (func - thing);
767 /* Arrange to scavenge the debug info later. */
768 pscav_later(&new->debug_info, 1);
770 /* FIXME: why would this be a fixnum? */
771 /* "why" is a hard word, but apparently for compiled functions the
772 trace_table_offset contains the length of the instructions, as
773 a fixnum. See CODE-INST-AREA-LENGTH in
774 src/compiler/target-disassem.lisp. -- CSR, 2004-01-08 */
775 if (!(fixnump(new->trace_table_offset)))
777 pscav(&new->trace_table_offset, 1, 0);
779 new->trace_table_offset = NIL; /* limit lifetime */
782 /* Scavenge the constants. */
783 pscav(new->constants, HeaderValue(new->header)-5, 1);
785 /* Scavenge all the functions. */
786 pscav(&new->entry_points, 1, 1);
787 for (func = new->entry_points;
789 func = ((struct simple_fun *)native_pointer(func))->next) {
790 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
791 gc_assert(!dynamic_pointer_p(func));
793 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
794 /* Temporarily convert the self pointer to a real function pointer. */
795 ((struct simple_fun *)native_pointer(func))->self
796 -= FUN_RAW_ADDR_OFFSET;
798 pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
799 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
800 ((struct simple_fun *)native_pointer(func))->self
801 += FUN_RAW_ADDR_OFFSET;
803 pscav_later(&((struct simple_fun *)native_pointer(func))->name, 4);
810 ptrans_func(lispobj thing, lispobj header)
813 lispobj code, *new, *old, result;
814 struct simple_fun *function;
816 /* Thing can either be a function header, a closure function
817 * header, a closure, or a funcallable-instance. If it's a closure
818 * or a funcallable-instance, we do the same as ptrans_boxed.
819 * Otherwise we have to do something strange, 'cause it is buried
820 * inside a code object. */
822 if (widetag_of(header) == SIMPLE_FUN_HEADER_WIDETAG) {
824 /* We can only end up here if the code object has not been
825 * scavenged, because if it had been scavenged, forwarding pointers
826 * would have been left behind for all the entry points. */
828 function = (struct simple_fun *)native_pointer(thing);
831 ((native_pointer(thing) -
832 (HeaderValue(function->header))), OTHER_POINTER_LOWTAG);
834 /* This will cause the function's header to be replaced with a
835 * forwarding pointer. */
839 /* So we can just return that. */
840 return function->header;
843 /* It's some kind of closure-like thing. */
844 nwords = CEILING(1 + HeaderValue(header), 2);
845 old = (lispobj *)native_pointer(thing);
847 /* Allocate the new one. FINs *must* not go in read_only
848 * space. Closures can; they never change */
851 (nwords,(widetag_of(header)!=FUNCALLABLE_INSTANCE_HEADER_WIDETAG));
854 bcopy(old, new, nwords * sizeof(lispobj));
856 /* Deposit forwarding pointer. */
857 result = make_lispobj(new, lowtag_of(thing));
861 pscav(new, nwords, 0);
868 ptrans_returnpc(lispobj thing, lispobj header)
872 /* Find the corresponding code object. */
873 code = thing - HeaderValue(header)*sizeof(lispobj);
875 /* Make sure it's been transported. */
876 new = *(lispobj *)native_pointer(code);
877 if (!forwarding_pointer_p(new))
878 new = ptrans_code(code);
880 /* Maintain the offset: */
881 return new + (thing - code);
884 #define WORDS_PER_CONS CEILING(sizeof(struct cons) / sizeof(lispobj), 2)
887 ptrans_list(lispobj thing, boolean constant)
889 struct cons *old, *new, *orig;
892 orig = (struct cons *) newspace_alloc(0,constant);
896 /* Allocate a new cons cell. */
897 old = (struct cons *)native_pointer(thing);
898 new = (struct cons *) newspace_alloc(WORDS_PER_CONS,constant);
900 /* Copy the cons cell and keep a pointer to the cdr. */
902 thing = new->cdr = old->cdr;
904 /* Set up the forwarding pointer. */
905 *(lispobj *)old = make_lispobj(new, LIST_POINTER_LOWTAG);
907 /* And count this cell. */
909 } while (lowtag_of(thing) == LIST_POINTER_LOWTAG &&
910 dynamic_pointer_p(thing) &&
911 !(forwarding_pointer_p(*(lispobj *)native_pointer(thing))));
913 /* Scavenge the list we just copied. */
914 pscav((lispobj *)orig, length * WORDS_PER_CONS, constant);
916 return make_lispobj(orig, LIST_POINTER_LOWTAG);
920 ptrans_otherptr(lispobj thing, lispobj header, boolean constant)
922 switch (widetag_of(header)) {
923 /* FIXME: this needs a reindent */
925 case SINGLE_FLOAT_WIDETAG:
926 case DOUBLE_FLOAT_WIDETAG:
927 #ifdef LONG_FLOAT_WIDETAG
928 case LONG_FLOAT_WIDETAG:
930 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
931 case COMPLEX_SINGLE_FLOAT_WIDETAG:
933 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
934 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
936 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
937 case COMPLEX_LONG_FLOAT_WIDETAG:
940 return ptrans_unboxed(thing, header);
943 gencgc_unregister_lutex(native_pointer(thing));
944 return ptrans_unboxed(thing, header);
948 case COMPLEX_WIDETAG:
949 case SIMPLE_ARRAY_WIDETAG:
950 case COMPLEX_BASE_STRING_WIDETAG:
951 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
952 case COMPLEX_CHARACTER_STRING_WIDETAG:
954 case COMPLEX_BIT_VECTOR_WIDETAG:
955 case COMPLEX_VECTOR_NIL_WIDETAG:
956 case COMPLEX_VECTOR_WIDETAG:
957 case COMPLEX_ARRAY_WIDETAG:
958 return ptrans_boxed(thing, header, constant);
960 case VALUE_CELL_HEADER_WIDETAG:
961 case WEAK_POINTER_WIDETAG:
962 return ptrans_boxed(thing, header, 0);
964 case SYMBOL_HEADER_WIDETAG:
965 return ptrans_boxed(thing, header, 0);
967 case SIMPLE_ARRAY_NIL_WIDETAG:
968 return ptrans_vector(thing, 0, 0, 0, constant);
970 case SIMPLE_BASE_STRING_WIDETAG:
971 return ptrans_vector(thing, 8, 1, 0, constant);
973 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
974 case SIMPLE_CHARACTER_STRING_WIDETAG:
975 return ptrans_vector(thing, 32, 1, 0, constant);
978 case SIMPLE_BIT_VECTOR_WIDETAG:
979 return ptrans_vector(thing, 1, 0, 0, constant);
981 case SIMPLE_VECTOR_WIDETAG:
982 return ptrans_vector(thing, N_WORD_BITS, 0, 1, constant);
984 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
985 return ptrans_vector(thing, 2, 0, 0, constant);
987 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
988 return ptrans_vector(thing, 4, 0, 0, constant);
990 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
991 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
992 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
993 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
995 return ptrans_vector(thing, 8, 0, 0, constant);
997 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
998 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
999 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
1000 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
1002 return ptrans_vector(thing, 16, 0, 0, constant);
1004 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
1005 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1006 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
1007 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
1009 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1010 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
1011 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
1013 return ptrans_vector(thing, 32, 0, 0, constant);
1015 #if N_WORD_BITS == 64
1016 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
1017 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
1019 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
1020 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
1022 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
1023 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
1025 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1026 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
1028 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1029 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
1031 return ptrans_vector(thing, 64, 0, 0, constant);
1034 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
1035 return ptrans_vector(thing, 32, 0, 0, constant);
1037 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
1038 return ptrans_vector(thing, 64, 0, 0, constant);
1040 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1041 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
1042 #ifdef LISP_FEATURE_X86
1043 return ptrans_vector(thing, 96, 0, 0, constant);
1045 #ifdef LISP_FEATURE_SPARC
1046 return ptrans_vector(thing, 128, 0, 0, constant);
1050 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1051 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
1052 return ptrans_vector(thing, 64, 0, 0, constant);
1055 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1056 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
1057 return ptrans_vector(thing, 128, 0, 0, constant);
1060 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1061 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
1062 #ifdef LISP_FEATURE_X86
1063 return ptrans_vector(thing, 192, 0, 0, constant);
1065 #ifdef LISP_FEATURE_SPARC
1066 return ptrans_vector(thing, 256, 0, 0, constant);
1070 case CODE_HEADER_WIDETAG:
1071 return ptrans_code(thing);
1073 case RETURN_PC_HEADER_WIDETAG:
1074 return ptrans_returnpc(thing, header);
1077 return ptrans_fdefn(thing, header);
1080 fprintf(stderr, "Invalid widetag: %d\n", widetag_of(header));
1081 /* Should only come across other pointers to the above stuff. */
1088 pscav_fdefn(struct fdefn *fdefn)
1092 fix_func = ((char *)(fdefn->fun+FUN_RAW_ADDR_OFFSET) == fdefn->raw_addr);
1093 pscav(&fdefn->name, 1, 1);
1094 pscav(&fdefn->fun, 1, 0);
1096 fdefn->raw_addr = (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET);
1097 return sizeof(struct fdefn) / sizeof(lispobj);
1100 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1101 /* now putting code objects in static space */
1103 pscav_code(struct code*code)
1107 nwords = CEILING(HeaderValue(code->header) + fixnum_value(code->code_size),
1110 /* Arrange to scavenge the debug info later. */
1111 pscav_later(&code->debug_info, 1);
1113 /* Scavenge the constants. */
1114 pscav(code->constants, HeaderValue(code->header)-5, 1);
1116 /* Scavenge all the functions. */
1117 pscav(&code->entry_points, 1, 1);
1118 for (func = code->entry_points;
1120 func = ((struct simple_fun *)native_pointer(func))->next) {
1121 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
1122 gc_assert(!dynamic_pointer_p(func));
1124 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1125 /* Temporarily convert the self pointer to a real function
1127 ((struct simple_fun *)native_pointer(func))->self
1128 -= FUN_RAW_ADDR_OFFSET;
1130 pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
1131 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1132 ((struct simple_fun *)native_pointer(func))->self
1133 += FUN_RAW_ADDR_OFFSET;
1135 pscav_later(&((struct simple_fun *)native_pointer(func))->name, 4);
1138 return CEILING(nwords,2);
1143 pscav(lispobj *addr, long nwords, boolean constant)
1145 lispobj thing, *thingp, header;
1146 long count = 0; /* (0 = dummy init value to stop GCC warning) */
1147 struct vector *vector;
1149 while (nwords > 0) {
1151 if (is_lisp_pointer(thing)) {
1152 /* It's a pointer. Is it something we might have to move? */
1153 if (dynamic_pointer_p(thing)) {
1154 /* Maybe. Have we already moved it? */
1155 thingp = (lispobj *)native_pointer(thing);
1157 if (is_lisp_pointer(header) && forwarding_pointer_p(header))
1158 /* Yep, so just copy the forwarding pointer. */
1161 /* Nope, copy the object. */
1162 switch (lowtag_of(thing)) {
1163 case FUN_POINTER_LOWTAG:
1164 thing = ptrans_func(thing, header);
1167 case LIST_POINTER_LOWTAG:
1168 thing = ptrans_list(thing, constant);
1171 case INSTANCE_POINTER_LOWTAG:
1172 thing = ptrans_instance(thing, header, constant);
1175 case OTHER_POINTER_LOWTAG:
1176 thing = ptrans_otherptr(thing, header, constant);
1180 /* It was a pointer, but not one of them? */
1188 #if N_WORD_BITS == 64
1189 else if (widetag_of(thing) == SINGLE_FLOAT_WIDETAG) {
1193 else if (thing & FIXNUM_TAG_MASK) {
1194 /* It's an other immediate. Maybe the header for an unboxed */
1196 switch (widetag_of(thing)) {
1197 case BIGNUM_WIDETAG:
1198 case SINGLE_FLOAT_WIDETAG:
1199 case DOUBLE_FLOAT_WIDETAG:
1200 #ifdef LONG_FLOAT_WIDETAG
1201 case LONG_FLOAT_WIDETAG:
1204 /* It's an unboxed simple object. */
1205 count = CEILING(HeaderValue(thing)+1, 2);
1208 case SIMPLE_VECTOR_WIDETAG:
1209 if (HeaderValue(thing) == subtype_VectorValidHashing) {
1210 *addr = (subtype_VectorMustRehash << N_WIDETAG_BITS) |
1211 SIMPLE_VECTOR_WIDETAG;
1216 case SIMPLE_ARRAY_NIL_WIDETAG:
1220 case SIMPLE_BASE_STRING_WIDETAG:
1221 vector = (struct vector *)addr;
1222 count = CEILING(NWORDS(fixnum_value(vector->length)+1,8)+2,2);
1225 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
1226 case SIMPLE_CHARACTER_STRING_WIDETAG:
1227 vector = (struct vector *)addr;
1228 count = CEILING(NWORDS(fixnum_value(vector->length)+1,32)+2,2);
1232 case SIMPLE_BIT_VECTOR_WIDETAG:
1233 vector = (struct vector *)addr;
1234 count = CEILING(NWORDS(fixnum_value(vector->length),1)+2,2);
1237 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
1238 vector = (struct vector *)addr;
1239 count = CEILING(NWORDS(fixnum_value(vector->length),2)+2,2);
1242 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
1243 vector = (struct vector *)addr;
1244 count = CEILING(NWORDS(fixnum_value(vector->length),4)+2,2);
1247 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
1248 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
1249 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
1250 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
1252 vector = (struct vector *)addr;
1253 count = CEILING(NWORDS(fixnum_value(vector->length),8)+2,2);
1256 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
1257 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
1258 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
1259 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
1261 vector = (struct vector *)addr;
1262 count = CEILING(NWORDS(fixnum_value(vector->length),16)+2,2);
1265 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
1266 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1267 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
1268 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
1270 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1271 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
1272 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
1274 vector = (struct vector *)addr;
1275 count = CEILING(NWORDS(fixnum_value(vector->length),32)+2,2);
1278 #if N_WORD_BITS == 64
1279 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
1280 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1281 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
1282 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
1284 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1285 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
1286 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
1288 vector = (struct vector *)addr;
1289 count = CEILING(NWORDS(fixnum_value(vector->length),64)+2,2);
1293 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
1294 vector = (struct vector *)addr;
1295 count = CEILING(NWORDS(fixnum_value(vector->length), 32) + 2,
1299 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
1300 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1301 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
1303 vector = (struct vector *)addr;
1304 count = CEILING(NWORDS(fixnum_value(vector->length), 64) + 2,
1308 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1309 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
1310 vector = (struct vector *)addr;
1311 #ifdef LISP_FEATURE_X86
1312 count = fixnum_value(vector->length)*3+2;
1314 #ifdef LISP_FEATURE_SPARC
1315 count = fixnum_value(vector->length)*4+2;
1320 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1321 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
1322 vector = (struct vector *)addr;
1323 count = CEILING(NWORDS(fixnum_value(vector->length), 128) + 2,
1328 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1329 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
1330 vector = (struct vector *)addr;
1331 #ifdef LISP_FEATURE_X86
1332 count = fixnum_value(vector->length)*6+2;
1334 #ifdef LISP_FEATURE_SPARC
1335 count = fixnum_value(vector->length)*8+2;
1340 case CODE_HEADER_WIDETAG:
1341 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1342 gc_abort(); /* no code headers in static space */
1344 count = pscav_code((struct code*)addr);
1348 case SIMPLE_FUN_HEADER_WIDETAG:
1349 case RETURN_PC_HEADER_WIDETAG:
1350 /* We should never hit any of these, 'cause they occur
1351 * buried in the middle of code objects. */
1355 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1356 case CLOSURE_HEADER_WIDETAG:
1357 /* The function self pointer needs special care on the
1358 * x86 because it is the real entry point. */
1360 lispobj fun = ((struct closure *)addr)->fun
1361 - FUN_RAW_ADDR_OFFSET;
1362 pscav(&fun, 1, constant);
1363 ((struct closure *)addr)->fun = fun + FUN_RAW_ADDR_OFFSET;
1369 case WEAK_POINTER_WIDETAG:
1370 /* Weak pointers get preserved during purify, 'cause I
1371 * don't feel like figuring out how to break them. */
1372 pscav(addr+1, 2, constant);
1377 /* We have to handle fdefn objects specially, so we
1378 * can fix up the raw function address. */
1379 count = pscav_fdefn((struct fdefn *)addr);
1382 case INSTANCE_HEADER_WIDETAG:
1384 struct instance *instance = (struct instance *) addr;
1385 struct layout *layout
1386 = (struct layout *) native_pointer(instance->slots[0]);
1387 long nuntagged = fixnum_value(layout->n_untagged_slots);
1388 long nslots = HeaderValue(*addr);
1389 pscav(addr + 1, nslots - nuntagged, constant);
1390 count = CEILING(1 + nslots, 2);
1400 /* It's a fixnum. */
1412 purify(lispobj static_roots, lispobj read_only_roots)
1416 struct later *laters, *next;
1417 struct thread *thread;
1419 if(all_threads->next) {
1420 /* FIXME: there should be _some_ sensible error reporting
1421 * convention. See following comment too */
1422 fprintf(stderr,"Can't purify when more than one thread exists\n");
1428 printf("[doing purification:");
1431 #ifdef LISP_FEATURE_GENCGC
1432 gc_alloc_update_all_page_tables();
1434 for_each_thread(thread)
1435 if (fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,thread)) != 0) {
1436 /* FIXME: 1. What does this mean? 2. It shouldn't be reporting
1437 * its error simply by a. printing a string b. to stdout instead
1439 printf(" Ack! Can't purify interrupt contexts. ");
1444 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1445 dynamic_space_purify_pointer =
1446 (lispobj*)SymbolValue(ALLOCATION_POINTER,0);
1448 #if defined(LISP_FEATURE_GENCGC)
1449 dynamic_space_purify_pointer = get_alloc_pointer();
1451 dynamic_space_purify_pointer = dynamic_space_free_pointer;
1455 read_only_end = read_only_free =
1456 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER,0);
1457 static_end = static_free =
1458 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER,0);
1465 #if defined(LISP_FEATURE_GENCGC) && (defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
1466 /* note this expects only one thread to be active. We'd have to
1467 * stop all the others in the same way as GC does if we wanted
1468 * PURIFY to work when >1 thread exists */
1469 setup_i386_stack_scav(((&static_roots)-2),
1470 ((void *)all_threads->control_stack_end));
1473 pscav(&static_roots, 1, 0);
1474 pscav(&read_only_roots, 1, 1);
1477 printf(" handlers");
1480 pscav((lispobj *) interrupt_handlers,
1481 sizeof(interrupt_handlers) / sizeof(lispobj),
1488 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1489 pscav((lispobj *)all_threads->control_stack_start,
1490 current_control_stack_pointer -
1491 all_threads->control_stack_start,
1494 #ifdef LISP_FEATURE_GENCGC
1500 printf(" bindings");
1503 #if !(defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
1504 pscav( (lispobj *)all_threads->binding_stack_start,
1505 (lispobj *)current_binding_stack_pointer -
1506 all_threads->binding_stack_start,
1509 for_each_thread(thread) {
1510 pscav( (lispobj *)thread->binding_stack_start,
1511 (lispobj *)SymbolValue(BINDING_STACK_POINTER,thread) -
1512 (lispobj *)thread->binding_stack_start,
1514 #ifdef LISP_FEATURE_SB_THREAD
1515 pscav( (lispobj *) (thread+1),
1516 fixnum_value(SymbolValue(FREE_TLS_INDEX,0)) -
1517 (sizeof (struct thread))/(sizeof (lispobj)),
1525 /* The original CMU CL code had scavenge-read-only-space code
1526 * controlled by the Lisp-level variable
1527 * *SCAVENGE-READ-ONLY-SPACE*. It was disabled by default, and it
1528 * wasn't documented under what circumstances it was useful or
1529 * safe to turn it on, so it's been turned off in SBCL. If you
1530 * want/need this functionality, and can test and document it,
1531 * please submit a patch. */
1533 if (SymbolValue(SCAVENGE_READ_ONLY_SPACE) != UNBOUND_MARKER_WIDETAG
1534 && SymbolValue(SCAVENGE_READ_ONLY_SPACE) != NIL) {
1535 unsigned read_only_space_size =
1536 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER) -
1537 (lispobj *)READ_ONLY_SPACE_START;
1539 "scavenging read only space: %d bytes\n",
1540 read_only_space_size * sizeof(lispobj));
1541 pscav( (lispobj *)READ_ONLY_SPACE_START, read_only_space_size, 0);
1549 clean = (lispobj *)STATIC_SPACE_START;
1551 while (clean != static_free)
1552 clean = pscav(clean, static_free - clean, 0);
1553 laters = later_blocks;
1554 count = later_count;
1555 later_blocks = NULL;
1557 while (laters != NULL) {
1558 for (i = 0; i < count; i++) {
1559 if (laters->u[i].count == 0) {
1561 } else if (laters->u[i].count <= LATERMAXCOUNT) {
1562 pscav(laters->u[i+1].ptr, laters->u[i].count, 1);
1565 pscav(laters->u[i].ptr, 1, 1);
1568 next = laters->next;
1571 count = LATERBLOCKSIZE;
1573 } while (clean != static_free || later_blocks != NULL);
1580 os_zero((os_vm_address_t) current_dynamic_space,
1581 (os_vm_size_t) dynamic_space_size);
1583 /* Zero the stack. Note that the stack is also zeroed by SUB-GC
1584 * calling SCRUB-CONTROL-STACK - this zeros the stack on the x86. */
1585 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
1586 os_zero((os_vm_address_t) current_control_stack_pointer,
1588 ((all_threads->control_stack_end -
1589 current_control_stack_pointer) * sizeof(lispobj)));
1592 /* It helps to update the heap free pointers so that free_heap can
1593 * verify after it's done. */
1594 SetSymbolValue(READ_ONLY_SPACE_FREE_POINTER, (lispobj)read_only_free,0);
1595 SetSymbolValue(STATIC_SPACE_FREE_POINTER, (lispobj)static_free,0);
1597 #if defined LISP_FEATURE_GENCGC
1600 dynamic_space_free_pointer = current_dynamic_space;
1601 set_auto_gc_trigger(bytes_consed_between_gcs);
1604 /* Blast away instruction cache */
1605 os_flush_icache((os_vm_address_t)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
1606 os_flush_icache((os_vm_address_t)STATIC_SPACE_START, STATIC_SPACE_SIZE);