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"
38 /* We don't ever do purification with GENCGC as of 1.0.5.*. There was
39 * a lot of hairy and fragile ifdeffage in here to support purify on
40 * x86oids, which has now been removed. So this code can't even be
41 * compiled with GENCGC any more. -- JES, 2007-04-30.
43 #ifndef LISP_FEATURE_GENCGC
47 static lispobj *dynamic_space_purify_pointer;
50 /* These hold the original end of the read_only and static spaces so
51 * we can tell what are forwarding pointers. */
53 static lispobj *read_only_end, *static_end;
55 static lispobj *read_only_free, *static_free;
57 static lispobj *pscav(lispobj *addr, long nwords, boolean constant);
59 #define LATERBLOCKSIZE 1020
60 #define LATERMAXCOUNT 10
69 } *later_blocks = NULL;
70 static long later_count = 0;
73 #define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
74 #elif N_WORD_BITS == 64
75 #define SIMPLE_ARRAY_WORD_WIDETAG SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
80 forwarding_pointer_p(lispobj obj)
82 lispobj *ptr = native_pointer(obj);
84 return ((static_end <= ptr && ptr <= static_free) ||
85 (read_only_end <= ptr && ptr <= read_only_free));
89 dynamic_pointer_p(lispobj ptr)
91 return (ptr >= (lispobj)current_dynamic_space
93 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 pscav_later(lispobj *where, long count)
123 if (count > LATERMAXCOUNT) {
124 while (count > LATERMAXCOUNT) {
125 pscav_later(where, LATERMAXCOUNT);
126 count -= LATERMAXCOUNT;
127 where += LATERMAXCOUNT;
131 if (later_blocks == NULL || later_count == LATERBLOCKSIZE ||
132 (later_count == LATERBLOCKSIZE-1 && count > 1)) {
133 new = (struct later *)malloc(sizeof(struct later));
134 new->next = later_blocks;
135 if (later_blocks && later_count < LATERBLOCKSIZE)
136 later_blocks->u[later_count].ptr = NULL;
142 later_blocks->u[later_count++].count = count;
143 later_blocks->u[later_count++].ptr = where;
148 ptrans_boxed(lispobj thing, lispobj header, boolean constant)
151 lispobj result, *new, *old;
153 nwords = CEILING(1 + HeaderValue(header), 2);
156 old = (lispobj *)native_pointer(thing);
157 new = newspace_alloc(nwords,constant);
160 bcopy(old, new, nwords * sizeof(lispobj));
162 /* Deposit forwarding pointer. */
163 result = make_lispobj(new, lowtag_of(thing));
167 pscav(new, nwords, constant);
172 /* We need to look at the layout to see whether it is a pure structure
173 * class, and only then can we transport as constant. If it is pure,
174 * we can ALWAYS transport as a constant. */
176 ptrans_instance(lispobj thing, lispobj header, boolean /* ignored */ constant)
178 struct layout *layout =
179 (struct layout *) native_pointer(((struct instance *)native_pointer(thing))->slots[0]);
180 lispobj pure = layout->pure;
184 return (ptrans_boxed(thing, header, 1));
186 return (ptrans_boxed(thing, header, 0));
189 /* Substructure: special case for the COMPACT-INFO-ENVs,
190 * where the instance may have a point to the dynamic
191 * space placed into it (e.g. the cache-name slot), but
192 * the lists and arrays at the time of a purify can be
193 * moved to the RO space. */
195 lispobj result, *new, *old;
197 nwords = CEILING(1 + HeaderValue(header), 2);
200 old = (lispobj *)native_pointer(thing);
201 new = newspace_alloc(nwords, 0); /* inconstant */
204 bcopy(old, new, nwords * sizeof(lispobj));
206 /* Deposit forwarding pointer. */
207 result = make_lispobj(new, lowtag_of(thing));
211 pscav(new, nwords, 1);
217 return NIL; /* dummy value: return something ... */
222 ptrans_fdefn(lispobj thing, lispobj header)
225 lispobj result, *new, *old, oldfn;
228 nwords = CEILING(1 + HeaderValue(header), 2);
231 old = (lispobj *)native_pointer(thing);
232 new = newspace_alloc(nwords, 0); /* inconstant */
235 bcopy(old, new, nwords * sizeof(lispobj));
237 /* Deposit forwarding pointer. */
238 result = make_lispobj(new, lowtag_of(thing));
241 /* Scavenge the function. */
242 fdefn = (struct fdefn *)new;
244 pscav(&fdefn->fun, 1, 0);
245 if ((char *)oldfn + FUN_RAW_ADDR_OFFSET == fdefn->raw_addr)
246 fdefn->raw_addr = (char *)fdefn->fun + FUN_RAW_ADDR_OFFSET;
252 ptrans_unboxed(lispobj thing, lispobj header)
255 lispobj result, *new, *old;
257 nwords = CEILING(1 + HeaderValue(header), 2);
260 old = (lispobj *)native_pointer(thing);
261 new = newspace_alloc(nwords,1); /* always constant */
264 bcopy(old, new, nwords * sizeof(lispobj));
266 /* Deposit forwarding pointer. */
267 result = make_lispobj(new , lowtag_of(thing));
274 ptrans_vector(lispobj thing, long bits, long extra,
275 boolean boxed, boolean constant)
277 struct vector *vector;
279 lispobj result, *new;
282 vector = (struct vector *)native_pointer(thing);
283 length = fixnum_value(vector->length)+extra;
284 // Argh, handle simple-vector-nil separately.
288 nwords = CEILING(NWORDS(length, bits) + 2, 2);
291 new=newspace_alloc(nwords, (constant || !boxed));
292 bcopy(vector, new, nwords * sizeof(lispobj));
294 result = make_lispobj(new, lowtag_of(thing));
295 vector->header = result;
298 pscav(new, nwords, constant);
304 ptrans_code(lispobj thing)
306 struct code *code, *new;
308 lispobj func, result;
310 code = (struct code *)native_pointer(thing);
311 nwords = CEILING(HeaderValue(code->header) + fixnum_value(code->code_size),
314 new = (struct code *)newspace_alloc(nwords,1); /* constant */
316 bcopy(code, new, nwords * sizeof(lispobj));
318 result = make_lispobj(new, OTHER_POINTER_LOWTAG);
320 /* Stick in a forwarding pointer for the code object. */
321 *(lispobj *)code = result;
323 /* Put in forwarding pointers for all the functions. */
324 for (func = code->entry_points;
326 func = ((struct simple_fun *)native_pointer(func))->next) {
328 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
330 *(lispobj *)native_pointer(func) = result + (func - thing);
333 /* Arrange to scavenge the debug info later. */
334 pscav_later(&new->debug_info, 1);
336 /* FIXME: why would this be a fixnum? */
337 /* "why" is a hard word, but apparently for compiled functions the
338 trace_table_offset contains the length of the instructions, as
339 a fixnum. See CODE-INST-AREA-LENGTH in
340 src/compiler/target-disassem.lisp. -- CSR, 2004-01-08 */
341 if (!(fixnump(new->trace_table_offset)))
343 pscav(&new->trace_table_offset, 1, 0);
345 new->trace_table_offset = NIL; /* limit lifetime */
348 /* Scavenge the constants. */
349 pscav(new->constants, HeaderValue(new->header)-5, 1);
351 /* Scavenge all the functions. */
352 pscav(&new->entry_points, 1, 1);
353 for (func = new->entry_points;
355 func = ((struct simple_fun *)native_pointer(func))->next) {
356 gc_assert(lowtag_of(func) == FUN_POINTER_LOWTAG);
357 gc_assert(!dynamic_pointer_p(func));
359 pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
360 pscav_later(&((struct simple_fun *)native_pointer(func))->name, 4);
367 ptrans_func(lispobj thing, lispobj header)
370 lispobj code, *new, *old, result;
371 struct simple_fun *function;
373 /* Thing can either be a function header, a closure function
374 * header, a closure, or a funcallable-instance. If it's a closure
375 * or a funcallable-instance, we do the same as ptrans_boxed.
376 * Otherwise we have to do something strange, 'cause it is buried
377 * inside a code object. */
379 if (widetag_of(header) == SIMPLE_FUN_HEADER_WIDETAG) {
381 /* We can only end up here if the code object has not been
382 * scavenged, because if it had been scavenged, forwarding pointers
383 * would have been left behind for all the entry points. */
385 function = (struct simple_fun *)native_pointer(thing);
388 ((native_pointer(thing) -
389 (HeaderValue(function->header))), OTHER_POINTER_LOWTAG);
391 /* This will cause the function's header to be replaced with a
392 * forwarding pointer. */
396 /* So we can just return that. */
397 return function->header;
400 /* It's some kind of closure-like thing. */
401 nwords = CEILING(1 + HeaderValue(header), 2);
402 old = (lispobj *)native_pointer(thing);
404 /* Allocate the new one. FINs *must* not go in read_only
405 * space. Closures can; they never change */
408 (nwords,(widetag_of(header)!=FUNCALLABLE_INSTANCE_HEADER_WIDETAG));
411 bcopy(old, new, nwords * sizeof(lispobj));
413 /* Deposit forwarding pointer. */
414 result = make_lispobj(new, lowtag_of(thing));
418 pscav(new, nwords, 0);
425 ptrans_returnpc(lispobj thing, lispobj header)
429 /* Find the corresponding code object. */
430 code = thing - HeaderValue(header)*sizeof(lispobj);
432 /* Make sure it's been transported. */
433 new = *(lispobj *)native_pointer(code);
434 if (!forwarding_pointer_p(new))
435 new = ptrans_code(code);
437 /* Maintain the offset: */
438 return new + (thing - code);
441 #define WORDS_PER_CONS CEILING(sizeof(struct cons) / sizeof(lispobj), 2)
444 ptrans_list(lispobj thing, boolean constant)
446 struct cons *old, *new, *orig;
449 orig = (struct cons *) newspace_alloc(0,constant);
453 /* Allocate a new cons cell. */
454 old = (struct cons *)native_pointer(thing);
455 new = (struct cons *) newspace_alloc(WORDS_PER_CONS,constant);
457 /* Copy the cons cell and keep a pointer to the cdr. */
459 thing = new->cdr = old->cdr;
461 /* Set up the forwarding pointer. */
462 *(lispobj *)old = make_lispobj(new, LIST_POINTER_LOWTAG);
464 /* And count this cell. */
466 } while (lowtag_of(thing) == LIST_POINTER_LOWTAG &&
467 dynamic_pointer_p(thing) &&
468 !(forwarding_pointer_p(*(lispobj *)native_pointer(thing))));
470 /* Scavenge the list we just copied. */
471 pscav((lispobj *)orig, length * WORDS_PER_CONS, constant);
473 return make_lispobj(orig, LIST_POINTER_LOWTAG);
477 ptrans_otherptr(lispobj thing, lispobj header, boolean constant)
479 switch (widetag_of(header)) {
480 /* FIXME: this needs a reindent */
482 case SINGLE_FLOAT_WIDETAG:
483 case DOUBLE_FLOAT_WIDETAG:
484 #ifdef LONG_FLOAT_WIDETAG
485 case LONG_FLOAT_WIDETAG:
487 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
488 case COMPLEX_SINGLE_FLOAT_WIDETAG:
490 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
491 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
493 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
494 case COMPLEX_LONG_FLOAT_WIDETAG:
497 return ptrans_unboxed(thing, header);
500 gencgc_unregister_lutex(native_pointer(thing));
501 return ptrans_unboxed(thing, header);
505 case COMPLEX_WIDETAG:
506 case SIMPLE_ARRAY_WIDETAG:
507 case COMPLEX_BASE_STRING_WIDETAG:
508 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
509 case COMPLEX_CHARACTER_STRING_WIDETAG:
511 case COMPLEX_BIT_VECTOR_WIDETAG:
512 case COMPLEX_VECTOR_NIL_WIDETAG:
513 case COMPLEX_VECTOR_WIDETAG:
514 case COMPLEX_ARRAY_WIDETAG:
515 return ptrans_boxed(thing, header, constant);
517 case VALUE_CELL_HEADER_WIDETAG:
518 case WEAK_POINTER_WIDETAG:
519 return ptrans_boxed(thing, header, 0);
521 case SYMBOL_HEADER_WIDETAG:
522 return ptrans_boxed(thing, header, 0);
524 case SIMPLE_ARRAY_NIL_WIDETAG:
525 return ptrans_vector(thing, 0, 0, 0, constant);
527 case SIMPLE_BASE_STRING_WIDETAG:
528 return ptrans_vector(thing, 8, 1, 0, constant);
530 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
531 case SIMPLE_CHARACTER_STRING_WIDETAG:
532 return ptrans_vector(thing, 32, 1, 0, constant);
535 case SIMPLE_BIT_VECTOR_WIDETAG:
536 return ptrans_vector(thing, 1, 0, 0, constant);
538 case SIMPLE_VECTOR_WIDETAG:
539 return ptrans_vector(thing, N_WORD_BITS, 0, 1, constant);
541 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
542 return ptrans_vector(thing, 2, 0, 0, constant);
544 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
545 return ptrans_vector(thing, 4, 0, 0, constant);
547 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
548 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
549 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
550 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
552 return ptrans_vector(thing, 8, 0, 0, constant);
554 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
555 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
556 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
557 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
559 return ptrans_vector(thing, 16, 0, 0, constant);
561 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
562 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
563 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
564 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
566 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
567 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
568 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
570 return ptrans_vector(thing, 32, 0, 0, constant);
572 #if N_WORD_BITS == 64
573 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
574 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
576 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
577 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
579 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
580 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
582 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
583 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
585 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
586 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
588 return ptrans_vector(thing, 64, 0, 0, constant);
591 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
592 return ptrans_vector(thing, 32, 0, 0, constant);
594 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
595 return ptrans_vector(thing, 64, 0, 0, constant);
597 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
598 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
599 #ifdef LISP_FEATURE_SPARC
600 return ptrans_vector(thing, 128, 0, 0, constant);
604 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
605 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
606 return ptrans_vector(thing, 64, 0, 0, constant);
609 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
610 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
611 return ptrans_vector(thing, 128, 0, 0, constant);
614 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
615 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
616 #ifdef LISP_FEATURE_SPARC
617 return ptrans_vector(thing, 256, 0, 0, constant);
621 case CODE_HEADER_WIDETAG:
622 return ptrans_code(thing);
624 case RETURN_PC_HEADER_WIDETAG:
625 return ptrans_returnpc(thing, header);
628 return ptrans_fdefn(thing, header);
631 fprintf(stderr, "Invalid widetag: %d\n", widetag_of(header));
632 /* Should only come across other pointers to the above stuff. */
639 pscav_fdefn(struct fdefn *fdefn)
643 fix_func = ((char *)(fdefn->fun+FUN_RAW_ADDR_OFFSET) == fdefn->raw_addr);
644 pscav(&fdefn->name, 1, 1);
645 pscav(&fdefn->fun, 1, 0);
647 fdefn->raw_addr = (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET);
648 return sizeof(struct fdefn) / sizeof(lispobj);
652 pscav(lispobj *addr, long nwords, boolean constant)
654 lispobj thing, *thingp, header;
655 long count = 0; /* (0 = dummy init value to stop GCC warning) */
656 struct vector *vector;
660 if (is_lisp_pointer(thing)) {
661 /* It's a pointer. Is it something we might have to move? */
662 if (dynamic_pointer_p(thing)) {
663 /* Maybe. Have we already moved it? */
664 thingp = (lispobj *)native_pointer(thing);
666 if (is_lisp_pointer(header) && forwarding_pointer_p(header))
667 /* Yep, so just copy the forwarding pointer. */
670 /* Nope, copy the object. */
671 switch (lowtag_of(thing)) {
672 case FUN_POINTER_LOWTAG:
673 thing = ptrans_func(thing, header);
676 case LIST_POINTER_LOWTAG:
677 thing = ptrans_list(thing, constant);
680 case INSTANCE_POINTER_LOWTAG:
681 thing = ptrans_instance(thing, header, constant);
684 case OTHER_POINTER_LOWTAG:
685 thing = ptrans_otherptr(thing, header, constant);
689 /* It was a pointer, but not one of them? */
697 #if N_WORD_BITS == 64
698 else if (widetag_of(thing) == SINGLE_FLOAT_WIDETAG) {
702 else if (thing & FIXNUM_TAG_MASK) {
703 /* It's an other immediate. Maybe the header for an unboxed */
705 switch (widetag_of(thing)) {
707 case SINGLE_FLOAT_WIDETAG:
708 case DOUBLE_FLOAT_WIDETAG:
709 #ifdef LONG_FLOAT_WIDETAG
710 case LONG_FLOAT_WIDETAG:
713 /* It's an unboxed simple object. */
714 count = CEILING(HeaderValue(thing)+1, 2);
717 case SIMPLE_VECTOR_WIDETAG:
718 if (HeaderValue(thing) == subtype_VectorValidHashing) {
719 *addr = (subtype_VectorMustRehash << N_WIDETAG_BITS) |
720 SIMPLE_VECTOR_WIDETAG;
725 case SIMPLE_ARRAY_NIL_WIDETAG:
729 case SIMPLE_BASE_STRING_WIDETAG:
730 vector = (struct vector *)addr;
731 count = CEILING(NWORDS(fixnum_value(vector->length)+1,8)+2,2);
734 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
735 case SIMPLE_CHARACTER_STRING_WIDETAG:
736 vector = (struct vector *)addr;
737 count = CEILING(NWORDS(fixnum_value(vector->length)+1,32)+2,2);
741 case SIMPLE_BIT_VECTOR_WIDETAG:
742 vector = (struct vector *)addr;
743 count = CEILING(NWORDS(fixnum_value(vector->length),1)+2,2);
746 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
747 vector = (struct vector *)addr;
748 count = CEILING(NWORDS(fixnum_value(vector->length),2)+2,2);
751 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
752 vector = (struct vector *)addr;
753 count = CEILING(NWORDS(fixnum_value(vector->length),4)+2,2);
756 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
757 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
758 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
759 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
761 vector = (struct vector *)addr;
762 count = CEILING(NWORDS(fixnum_value(vector->length),8)+2,2);
765 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
766 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
767 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
768 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
770 vector = (struct vector *)addr;
771 count = CEILING(NWORDS(fixnum_value(vector->length),16)+2,2);
774 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
775 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
776 case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG:
777 case SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG:
779 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
780 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
781 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
783 vector = (struct vector *)addr;
784 count = CEILING(NWORDS(fixnum_value(vector->length),32)+2,2);
787 #if N_WORD_BITS == 64
788 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
789 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
790 case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
791 case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
793 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
794 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
795 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
797 vector = (struct vector *)addr;
798 count = CEILING(NWORDS(fixnum_value(vector->length),64)+2,2);
802 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
803 vector = (struct vector *)addr;
804 count = CEILING(NWORDS(fixnum_value(vector->length), 32) + 2,
808 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
809 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
810 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
812 vector = (struct vector *)addr;
813 count = CEILING(NWORDS(fixnum_value(vector->length), 64) + 2,
817 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
818 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
819 vector = (struct vector *)addr;
820 #ifdef LISP_FEATURE_SPARC
821 count = fixnum_value(vector->length)*4+2;
826 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
827 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
828 vector = (struct vector *)addr;
829 count = CEILING(NWORDS(fixnum_value(vector->length), 128) + 2,
834 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
835 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
836 vector = (struct vector *)addr;
837 #ifdef LISP_FEATURE_SPARC
838 count = fixnum_value(vector->length)*8+2;
843 case CODE_HEADER_WIDETAG:
844 gc_abort(); /* no code headers in static space */
847 case SIMPLE_FUN_HEADER_WIDETAG:
848 case RETURN_PC_HEADER_WIDETAG:
849 /* We should never hit any of these, 'cause they occur
850 * buried in the middle of code objects. */
854 case WEAK_POINTER_WIDETAG:
855 /* Weak pointers get preserved during purify, 'cause I
856 * don't feel like figuring out how to break them. */
857 pscav(addr+1, 2, constant);
862 /* We have to handle fdefn objects specially, so we
863 * can fix up the raw function address. */
864 count = pscav_fdefn((struct fdefn *)addr);
867 case INSTANCE_HEADER_WIDETAG:
869 struct instance *instance = (struct instance *) addr;
870 struct layout *layout
871 = (struct layout *) native_pointer(instance->slots[0]);
872 long nuntagged = fixnum_value(layout->n_untagged_slots);
873 long nslots = HeaderValue(*addr);
874 pscav(addr + 1, nslots - nuntagged, constant);
875 count = CEILING(1 + nslots, 2);
897 purify(lispobj static_roots, lispobj read_only_roots)
901 struct later *laters, *next;
902 struct thread *thread;
904 if(all_threads->next) {
905 /* FIXME: there should be _some_ sensible error reporting
906 * convention. See following comment too */
907 fprintf(stderr,"Can't purify when more than one thread exists\n");
913 printf("[doing purification:");
917 for_each_thread(thread)
918 if (fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,thread)) != 0) {
919 /* FIXME: 1. What does this mean? 2. It shouldn't be reporting
920 * its error simply by a. printing a string b. to stdout instead
922 printf(" Ack! Can't purify interrupt contexts. ");
927 dynamic_space_purify_pointer = dynamic_space_free_pointer;
929 read_only_end = read_only_free =
930 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER,0);
931 static_end = static_free =
932 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER,0);
939 pscav(&static_roots, 1, 0);
940 pscav(&read_only_roots, 1, 1);
946 pscav((lispobj *) interrupt_handlers,
947 sizeof(interrupt_handlers) / sizeof(lispobj),
954 pscav((lispobj *)all_threads->control_stack_start,
955 current_control_stack_pointer -
956 all_threads->control_stack_start,
964 pscav( (lispobj *)all_threads->binding_stack_start,
965 (lispobj *)current_binding_stack_pointer -
966 all_threads->binding_stack_start,
969 /* The original CMU CL code had scavenge-read-only-space code
970 * controlled by the Lisp-level variable
971 * *SCAVENGE-READ-ONLY-SPACE*. It was disabled by default, and it
972 * wasn't documented under what circumstances it was useful or
973 * safe to turn it on, so it's been turned off in SBCL. If you
974 * want/need this functionality, and can test and document it,
975 * please submit a patch. */
977 if (SymbolValue(SCAVENGE_READ_ONLY_SPACE) != UNBOUND_MARKER_WIDETAG
978 && SymbolValue(SCAVENGE_READ_ONLY_SPACE) != NIL) {
979 unsigned read_only_space_size =
980 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER) -
981 (lispobj *)READ_ONLY_SPACE_START;
983 "scavenging read only space: %d bytes\n",
984 read_only_space_size * sizeof(lispobj));
985 pscav( (lispobj *)READ_ONLY_SPACE_START, read_only_space_size, 0);
993 clean = (lispobj *)STATIC_SPACE_START;
995 while (clean != static_free)
996 clean = pscav(clean, static_free - clean, 0);
997 laters = later_blocks;
1001 while (laters != NULL) {
1002 for (i = 0; i < count; i++) {
1003 if (laters->u[i].count == 0) {
1005 } else if (laters->u[i].count <= LATERMAXCOUNT) {
1006 pscav(laters->u[i+1].ptr, laters->u[i].count, 1);
1009 pscav(laters->u[i].ptr, 1, 1);
1012 next = laters->next;
1015 count = LATERBLOCKSIZE;
1017 } while (clean != static_free || later_blocks != NULL);
1024 os_zero((os_vm_address_t) current_dynamic_space,
1025 (os_vm_size_t) dynamic_space_size);
1027 /* Zero the stack. */
1028 os_zero((os_vm_address_t) current_control_stack_pointer,
1030 ((all_threads->control_stack_end -
1031 current_control_stack_pointer) * sizeof(lispobj)));
1033 /* It helps to update the heap free pointers so that free_heap can
1034 * verify after it's done. */
1035 SetSymbolValue(READ_ONLY_SPACE_FREE_POINTER, (lispobj)read_only_free,0);
1036 SetSymbolValue(STATIC_SPACE_FREE_POINTER, (lispobj)static_free,0);
1038 dynamic_space_free_pointer = current_dynamic_space;
1039 set_auto_gc_trigger(bytes_consed_between_gcs);
1041 /* Blast away instruction cache */
1042 os_flush_icache((os_vm_address_t)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
1043 os_flush_icache((os_vm_address_t)STATIC_SPACE_START, STATIC_SPACE_SIZE);
1051 #else /* LISP_FEATURE_GENCGC */
1053 purify(lispobj static_roots, lispobj read_only_roots)
1055 lose("purify called for GENCGC. This should not happen.");
1057 #endif /* LISP_FEATURE_GENCGC */