2 * Garbage Collection common functions for scavenging, moving and sizing
3 * objects. These are for use with both GC (stop & copy GC) and GENCGC
7 * This software is part of the SBCL system. See the README file for
10 * This software is derived from the CMU CL system, which was
11 * written at Carnegie Mellon University and released into the
12 * public domain. The software is in the public domain and is
13 * provided with absolutely no warranty. See the COPYING and CREDITS
14 * files for more information.
18 * For a review of garbage collection techniques (e.g. generational
19 * GC) and terminology (e.g. "scavenging") see Paul R. Wilson,
20 * "Uniprocessor Garbage Collection Techniques". As of 20000618, this
21 * had been accepted for _ACM Computing Surveys_ and was available
22 * as a PostScript preprint through
23 * <http://www.cs.utexas.edu/users/oops/papers.html>
25 * <ftp://ftp.cs.utexas.edu/pub/garbage/bigsurv.ps>.
36 #include "interrupt.h"
41 #include "genesis/primitive-objects.h"
42 #include "genesis/static-symbols.h"
43 #include "genesis/layout.h"
44 #include "genesis/hash-table.h"
45 #include "gc-internal.h"
47 #ifdef LISP_FEATURE_SPARC
48 #define LONG_FLOAT_SIZE 4
50 #ifdef LISP_FEATURE_X86
51 #define LONG_FLOAT_SIZE 3
55 os_vm_size_t dynamic_space_size = DEFAULT_DYNAMIC_SPACE_SIZE;
56 os_vm_size_t thread_control_stack_size = DEFAULT_CONTROL_STACK_SIZE;
59 forwarding_pointer_p(lispobj *pointer) {
60 lispobj first_word=*pointer;
61 #ifdef LISP_FEATURE_GENCGC
62 return (first_word == 0x01);
64 return (is_lisp_pointer(first_word)
65 && new_space_p(first_word));
69 static inline lispobj *
70 forwarding_pointer_value(lispobj *pointer) {
71 #ifdef LISP_FEATURE_GENCGC
72 return (lispobj *) ((pointer_sized_uint_t) pointer[1]);
74 return (lispobj *) ((pointer_sized_uint_t) pointer[0]);
78 set_forwarding_pointer(lispobj * pointer, lispobj newspace_copy) {
79 #ifdef LISP_FEATURE_GENCGC
81 pointer[1]=newspace_copy;
83 pointer[0]=newspace_copy;
88 long (*scavtab[256])(lispobj *where, lispobj object);
89 lispobj (*transother[256])(lispobj object);
90 long (*sizetab[256])(lispobj *where);
91 struct weak_pointer *weak_pointers;
93 os_vm_size_t bytes_consed_between_gcs = 12*1024*1024;
100 gc_general_copy_object(lispobj object, long nwords, int page_type_flag)
105 gc_assert(is_lisp_pointer(object));
106 gc_assert(from_space_p(object));
107 gc_assert((nwords & 0x01) == 0);
109 /* Get tag of object. */
110 tag = lowtag_of(object);
112 /* Allocate space. */
113 new = gc_general_alloc(nwords*N_WORD_BYTES, page_type_flag, ALLOC_QUICK);
115 /* Copy the object. */
116 memcpy(new,native_pointer(object),nwords*N_WORD_BYTES);
117 return make_lispobj(new,tag);
120 /* to copy a boxed object */
122 copy_object(lispobj object, long nwords)
124 return gc_general_copy_object(object, nwords, BOXED_PAGE_FLAG);
128 copy_code_object(lispobj object, long nwords)
130 return gc_general_copy_object(object, nwords, CODE_PAGE_FLAG);
133 static long scav_lose(lispobj *where, lispobj object); /* forward decl */
135 /* FIXME: Most calls end up going to some trouble to compute an
136 * 'n_words' value for this function. The system might be a little
137 * simpler if this function used an 'end' parameter instead. */
139 scavenge(lispobj *start, long n_words)
141 lispobj *end = start + n_words;
143 long n_words_scavenged;
145 for (object_ptr = start;
147 object_ptr += n_words_scavenged) {
149 lispobj object = *object_ptr;
150 #ifdef LISP_FEATURE_GENCGC
151 if (forwarding_pointer_p(object_ptr))
152 lose("unexpect forwarding pointer in scavenge: %p, start=%p, n=%l\n",
153 object_ptr, start, n_words);
155 if (is_lisp_pointer(object)) {
156 if (from_space_p(object)) {
157 /* It currently points to old space. Check for a
158 * forwarding pointer. */
159 lispobj *ptr = native_pointer(object);
160 if (forwarding_pointer_p(ptr)) {
161 /* Yes, there's a forwarding pointer. */
162 *object_ptr = LOW_WORD(forwarding_pointer_value(ptr));
163 n_words_scavenged = 1;
165 /* Scavenge that pointer. */
167 (scavtab[widetag_of(object)])(object_ptr, object);
170 /* It points somewhere other than oldspace. Leave it
172 n_words_scavenged = 1;
175 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
176 /* This workaround is probably not needed for those ports
177 which don't have a partitioned register set (and therefore
178 scan the stack conservatively for roots). */
179 else if (n_words == 1) {
180 /* there are some situations where an other-immediate may
181 end up in a descriptor register. I'm not sure whether
182 this is supposed to happen, but if it does then we
183 don't want to (a) barf or (b) scavenge over the
184 data-block, because there isn't one. So, if we're
185 checking a single word and it's anything other than a
186 pointer, just hush it up */
187 int widetag = widetag_of(object);
188 n_words_scavenged = 1;
190 if ((scavtab[widetag] == scav_lose) ||
191 (((sizetab[widetag])(object_ptr)) > 1)) {
192 fprintf(stderr,"warning: \
193 attempted to scavenge non-descriptor value %x at %p.\n\n\
194 If you can reproduce this warning, please send a bug report\n\
195 (see manual page for details).\n",
200 else if (fixnump(object)) {
201 /* It's a fixnum: really easy.. */
202 n_words_scavenged = 1;
204 /* It's some sort of header object or another. */
206 (scavtab[widetag_of(object)])(object_ptr, object);
209 gc_assert_verbose(object_ptr == end, "Final object pointer %p, start %p, end %p\n",
210 object_ptr, start, end);
213 static lispobj trans_fun_header(lispobj object); /* forward decls */
214 static lispobj trans_boxed(lispobj object);
217 scav_fun_pointer(lispobj *where, lispobj object)
219 lispobj *first_pointer;
222 gc_assert(is_lisp_pointer(object));
224 /* Object is a pointer into from_space - not a FP. */
225 first_pointer = (lispobj *) native_pointer(object);
227 /* must transport object -- object may point to either a function
228 * header, a closure function header, or to a closure header. */
230 switch (widetag_of(*first_pointer)) {
231 case SIMPLE_FUN_HEADER_WIDETAG:
232 copy = trans_fun_header(object);
235 copy = trans_boxed(object);
239 if (copy != object) {
240 /* Set forwarding pointer */
241 set_forwarding_pointer(first_pointer,copy);
244 gc_assert(is_lisp_pointer(copy));
245 gc_assert(!from_space_p(copy));
254 trans_code(struct code *code)
256 struct code *new_code;
257 lispobj first, l_code, l_new_code;
258 long nheader_words, ncode_words, nwords;
259 unsigned long displacement;
260 lispobj fheaderl, *prev_pointer;
262 /* if object has already been transported, just return pointer */
263 first = code->header;
264 if (forwarding_pointer_p((lispobj *)code)) {
266 printf("Was already transported\n");
268 return (struct code *) forwarding_pointer_value
269 ((lispobj *)((pointer_sized_uint_t) code));
272 gc_assert(widetag_of(first) == CODE_HEADER_WIDETAG);
274 /* prepare to transport the code vector */
275 l_code = (lispobj) LOW_WORD(code) | OTHER_POINTER_LOWTAG;
277 ncode_words = fixnum_value(code->code_size);
278 nheader_words = HeaderValue(code->header);
279 nwords = ncode_words + nheader_words;
280 nwords = CEILING(nwords, 2);
282 l_new_code = copy_code_object(l_code, nwords);
283 new_code = (struct code *) native_pointer(l_new_code);
285 #if defined(DEBUG_CODE_GC)
286 printf("Old code object at 0x%08x, new code object at 0x%08x.\n",
287 (unsigned long) code, (unsigned long) new_code);
288 printf("Code object is %d words long.\n", nwords);
291 #ifdef LISP_FEATURE_GENCGC
292 if (new_code == code)
296 displacement = l_new_code - l_code;
298 set_forwarding_pointer((lispobj *)code, l_new_code);
300 /* set forwarding pointers for all the function headers in the */
301 /* code object. also fix all self pointers */
303 fheaderl = code->entry_points;
304 prev_pointer = &new_code->entry_points;
306 while (fheaderl != NIL) {
307 struct simple_fun *fheaderp, *nfheaderp;
310 fheaderp = (struct simple_fun *) native_pointer(fheaderl);
311 gc_assert(widetag_of(fheaderp->header) == SIMPLE_FUN_HEADER_WIDETAG);
313 /* Calculate the new function pointer and the new */
314 /* function header. */
315 nfheaderl = fheaderl + displacement;
316 nfheaderp = (struct simple_fun *) native_pointer(nfheaderl);
319 printf("fheaderp->header (at %x) <- %x\n",
320 &(fheaderp->header) , nfheaderl);
322 set_forwarding_pointer((lispobj *)fheaderp, nfheaderl);
324 /* fix self pointer. */
326 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
327 FUN_RAW_ADDR_OFFSET +
331 *prev_pointer = nfheaderl;
333 fheaderl = fheaderp->next;
334 prev_pointer = &nfheaderp->next;
336 #ifdef LISP_FEATURE_GENCGC
337 /* Cheneygc doesn't need this os_flush_icache, it flushes the whole
338 spaces once when all copying is done. */
339 os_flush_icache((os_vm_address_t) (((long *)new_code) + nheader_words),
340 ncode_words * sizeof(long));
344 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
345 gencgc_apply_code_fixups(code, new_code);
352 scav_code_header(lispobj *where, lispobj object)
355 long n_header_words, n_code_words, n_words;
356 lispobj entry_point; /* tagged pointer to entry point */
357 struct simple_fun *function_ptr; /* untagged pointer to entry point */
359 code = (struct code *) where;
360 n_code_words = fixnum_value(code->code_size);
361 n_header_words = HeaderValue(object);
362 n_words = n_code_words + n_header_words;
363 n_words = CEILING(n_words, 2);
365 /* Scavenge the boxed section of the code data block. */
366 scavenge(where + 1, n_header_words - 1);
368 /* Scavenge the boxed section of each function object in the
369 * code data block. */
370 for (entry_point = code->entry_points;
372 entry_point = function_ptr->next) {
374 gc_assert_verbose(is_lisp_pointer(entry_point),
375 "Entry point %lx\n is not a lisp pointer.",
378 function_ptr = (struct simple_fun *) native_pointer(entry_point);
379 gc_assert(widetag_of(function_ptr->header)==SIMPLE_FUN_HEADER_WIDETAG);
381 scavenge(&function_ptr->name, 1);
382 scavenge(&function_ptr->arglist, 1);
383 scavenge(&function_ptr->type, 1);
384 scavenge(&function_ptr->info, 1);
391 trans_code_header(lispobj object)
395 ncode = trans_code((struct code *) native_pointer(object));
396 return (lispobj) LOW_WORD(ncode) | OTHER_POINTER_LOWTAG;
401 size_code_header(lispobj *where)
404 long nheader_words, ncode_words, nwords;
406 code = (struct code *) where;
408 ncode_words = fixnum_value(code->code_size);
409 nheader_words = HeaderValue(code->header);
410 nwords = ncode_words + nheader_words;
411 nwords = CEILING(nwords, 2);
416 #if !defined(LISP_FEATURE_X86) && ! defined(LISP_FEATURE_X86_64)
418 scav_return_pc_header(lispobj *where, lispobj object)
420 lose("attempted to scavenge a return PC header where=0x%08x object=0x%08x\n",
421 (unsigned long) where,
422 (unsigned long) object);
423 return 0; /* bogus return value to satisfy static type checking */
425 #endif /* LISP_FEATURE_X86 */
428 trans_return_pc_header(lispobj object)
430 struct simple_fun *return_pc;
431 unsigned long offset;
432 struct code *code, *ncode;
434 return_pc = (struct simple_fun *) native_pointer(object);
435 /* FIXME: was times 4, should it really be N_WORD_BYTES? */
436 offset = HeaderValue(return_pc->header) * N_WORD_BYTES;
438 /* Transport the whole code object */
439 code = (struct code *) ((unsigned long) return_pc - offset);
440 ncode = trans_code(code);
442 return ((lispobj) LOW_WORD(ncode) + offset) | OTHER_POINTER_LOWTAG;
445 /* On the 386, closures hold a pointer to the raw address instead of the
446 * function object, so we can use CALL [$FDEFN+const] to invoke
447 * the function without loading it into a register. Given that code
448 * objects don't move, we don't need to update anything, but we do
449 * have to figure out that the function is still live. */
451 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
453 scav_closure_header(lispobj *where, lispobj object)
455 struct closure *closure;
458 closure = (struct closure *)where;
459 fun = closure->fun - FUN_RAW_ADDR_OFFSET;
461 #ifdef LISP_FEATURE_GENCGC
462 /* The function may have moved so update the raw address. But
463 * don't write unnecessarily. */
464 if (closure->fun != fun + FUN_RAW_ADDR_OFFSET)
465 closure->fun = fun + FUN_RAW_ADDR_OFFSET;
471 #if !(defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
473 scav_fun_header(lispobj *where, lispobj object)
475 lose("attempted to scavenge a function header where=0x%08x object=0x%08x\n",
476 (unsigned long) where,
477 (unsigned long) object);
478 return 0; /* bogus return value to satisfy static type checking */
480 #endif /* LISP_FEATURE_X86 */
483 trans_fun_header(lispobj object)
485 struct simple_fun *fheader;
486 unsigned long offset;
487 struct code *code, *ncode;
489 fheader = (struct simple_fun *) native_pointer(object);
490 /* FIXME: was times 4, should it really be N_WORD_BYTES? */
491 offset = HeaderValue(fheader->header) * N_WORD_BYTES;
493 /* Transport the whole code object */
494 code = (struct code *) ((unsigned long) fheader - offset);
495 ncode = trans_code(code);
497 return ((lispobj) LOW_WORD(ncode) + offset) | FUN_POINTER_LOWTAG;
506 scav_instance_pointer(lispobj *where, lispobj object)
508 lispobj copy, *first_pointer;
510 /* Object is a pointer into from space - not a FP. */
511 copy = trans_boxed(object);
513 #ifdef LISP_FEATURE_GENCGC
514 gc_assert(copy != object);
517 first_pointer = (lispobj *) native_pointer(object);
518 set_forwarding_pointer(first_pointer,copy);
529 static lispobj trans_list(lispobj object);
532 scav_list_pointer(lispobj *where, lispobj object)
534 lispobj first, *first_pointer;
536 gc_assert(is_lisp_pointer(object));
538 /* Object is a pointer into from space - not FP. */
539 first_pointer = (lispobj *) native_pointer(object);
541 first = trans_list(object);
542 gc_assert(first != object);
544 /* Set forwarding pointer */
545 set_forwarding_pointer(first_pointer, first);
547 gc_assert(is_lisp_pointer(first));
548 gc_assert(!from_space_p(first));
556 trans_list(lispobj object)
558 lispobj new_list_pointer;
559 struct cons *cons, *new_cons;
562 cons = (struct cons *) native_pointer(object);
565 new_cons = (struct cons *)
566 gc_general_alloc(sizeof(struct cons), BOXED_PAGE_FLAG, ALLOC_QUICK);
567 new_cons->car = cons->car;
568 new_cons->cdr = cons->cdr; /* updated later */
569 new_list_pointer = make_lispobj(new_cons,lowtag_of(object));
571 /* Grab the cdr: set_forwarding_pointer will clobber it in GENCGC */
574 set_forwarding_pointer((lispobj *)cons, new_list_pointer);
576 /* Try to linearize the list in the cdr direction to help reduce
580 struct cons *cdr_cons, *new_cdr_cons;
582 if(lowtag_of(cdr) != LIST_POINTER_LOWTAG ||
583 !from_space_p(cdr) ||
584 forwarding_pointer_p((lispobj *)native_pointer(cdr)))
587 cdr_cons = (struct cons *) native_pointer(cdr);
590 new_cdr_cons = (struct cons*)
591 gc_general_alloc(sizeof(struct cons), BOXED_PAGE_FLAG, ALLOC_QUICK);
592 new_cdr_cons->car = cdr_cons->car;
593 new_cdr_cons->cdr = cdr_cons->cdr;
594 new_cdr = make_lispobj(new_cdr_cons, lowtag_of(cdr));
596 /* Grab the cdr before it is clobbered. */
598 set_forwarding_pointer((lispobj *)cdr_cons, new_cdr);
600 /* Update the cdr of the last cons copied into new space to
601 * keep the newspace scavenge from having to do it. */
602 new_cons->cdr = new_cdr;
604 new_cons = new_cdr_cons;
607 return new_list_pointer;
612 * scavenging and transporting other pointers
616 scav_other_pointer(lispobj *where, lispobj object)
618 lispobj first, *first_pointer;
620 gc_assert(is_lisp_pointer(object));
622 /* Object is a pointer into from space - not FP. */
623 first_pointer = (lispobj *) native_pointer(object);
624 first = (transother[widetag_of(*first_pointer)])(object);
626 if (first != object) {
627 set_forwarding_pointer(first_pointer, first);
628 #ifdef LISP_FEATURE_GENCGC
632 #ifndef LISP_FEATURE_GENCGC
635 gc_assert(is_lisp_pointer(first));
636 gc_assert(!from_space_p(first));
642 * immediate, boxed, and unboxed objects
646 size_pointer(lispobj *where)
652 scav_immediate(lispobj *where, lispobj object)
658 trans_immediate(lispobj object)
660 lose("trying to transport an immediate\n");
661 return NIL; /* bogus return value to satisfy static type checking */
665 size_immediate(lispobj *where)
672 scav_boxed(lispobj *where, lispobj object)
678 scav_instance(lispobj *where, lispobj object)
681 long ntotal = HeaderValue(object);
682 lispobj layout = ((struct instance *)where)->slots[0];
686 if (forwarding_pointer_p(native_pointer(layout)))
687 layout = (lispobj) forwarding_pointer_value(native_pointer(layout));
689 nuntagged = ((struct layout *)native_pointer(layout))->n_untagged_slots;
690 scavenge(where + 1, ntotal - fixnum_value(nuntagged));
696 trans_boxed(lispobj object)
699 unsigned long length;
701 gc_assert(is_lisp_pointer(object));
703 header = *((lispobj *) native_pointer(object));
704 length = HeaderValue(header) + 1;
705 length = CEILING(length, 2);
707 return copy_object(object, length);
712 size_boxed(lispobj *where)
715 unsigned long length;
718 length = HeaderValue(header) + 1;
719 length = CEILING(length, 2);
724 /* Note: on the sparc we don't have to do anything special for fdefns, */
725 /* 'cause the raw-addr has a function lowtag. */
726 #if !defined(LISP_FEATURE_SPARC)
728 scav_fdefn(lispobj *where, lispobj object)
732 fdefn = (struct fdefn *)where;
734 /* FSHOW((stderr, "scav_fdefn, function = %p, raw_addr = %p\n",
735 fdefn->fun, fdefn->raw_addr)); */
737 if ((char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET) == fdefn->raw_addr) {
738 scavenge(where + 1, sizeof(struct fdefn)/sizeof(lispobj) - 1);
740 /* Don't write unnecessarily. */
741 if (fdefn->raw_addr != (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET))
742 fdefn->raw_addr = (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET);
743 /* gc.c has more casts here, which may be relevant or alternatively
744 may be compiler warning defeaters. try
745 fdefn->raw_addr = ((char *) LOW_WORD(fdefn->fun)) + FUN_RAW_ADDR_OFFSET;
747 return sizeof(struct fdefn) / sizeof(lispobj);
755 scav_unboxed(lispobj *where, lispobj object)
757 unsigned long length;
759 length = HeaderValue(object) + 1;
760 length = CEILING(length, 2);
766 trans_unboxed(lispobj object)
769 unsigned long length;
772 gc_assert(is_lisp_pointer(object));
774 header = *((lispobj *) native_pointer(object));
775 length = HeaderValue(header) + 1;
776 length = CEILING(length, 2);
778 return copy_unboxed_object(object, length);
782 size_unboxed(lispobj *where)
785 unsigned long length;
788 length = HeaderValue(header) + 1;
789 length = CEILING(length, 2);
795 /* vector-like objects */
797 scav_base_string(lispobj *where, lispobj object)
799 struct vector *vector;
802 /* NOTE: Strings contain one more byte of data than the length */
803 /* slot indicates. */
805 vector = (struct vector *) where;
806 length = fixnum_value(vector->length) + 1;
807 nwords = CEILING(NWORDS(length, 8) + 2, 2);
812 trans_base_string(lispobj object)
814 struct vector *vector;
817 gc_assert(is_lisp_pointer(object));
819 /* NOTE: A string contains one more byte of data (a terminating
820 * '\0' to help when interfacing with C functions) than indicated
821 * by the length slot. */
823 vector = (struct vector *) native_pointer(object);
824 length = fixnum_value(vector->length) + 1;
825 nwords = CEILING(NWORDS(length, 8) + 2, 2);
827 return copy_large_unboxed_object(object, nwords);
831 size_base_string(lispobj *where)
833 struct vector *vector;
836 /* NOTE: A string contains one more byte of data (a terminating
837 * '\0' to help when interfacing with C functions) than indicated
838 * by the length slot. */
840 vector = (struct vector *) where;
841 length = fixnum_value(vector->length) + 1;
842 nwords = CEILING(NWORDS(length, 8) + 2, 2);
848 scav_character_string(lispobj *where, lispobj object)
850 struct vector *vector;
853 /* NOTE: Strings contain one more byte of data than the length */
854 /* slot indicates. */
856 vector = (struct vector *) where;
857 length = fixnum_value(vector->length) + 1;
858 nwords = CEILING(NWORDS(length, 32) + 2, 2);
863 trans_character_string(lispobj object)
865 struct vector *vector;
868 gc_assert(is_lisp_pointer(object));
870 /* NOTE: A string contains one more byte of data (a terminating
871 * '\0' to help when interfacing with C functions) than indicated
872 * by the length slot. */
874 vector = (struct vector *) native_pointer(object);
875 length = fixnum_value(vector->length) + 1;
876 nwords = CEILING(NWORDS(length, 32) + 2, 2);
878 return copy_large_unboxed_object(object, nwords);
882 size_character_string(lispobj *where)
884 struct vector *vector;
887 /* NOTE: A string contains one more byte of data (a terminating
888 * '\0' to help when interfacing with C functions) than indicated
889 * by the length slot. */
891 vector = (struct vector *) where;
892 length = fixnum_value(vector->length) + 1;
893 nwords = CEILING(NWORDS(length, 32) + 2, 2);
899 trans_vector(lispobj object)
901 struct vector *vector;
904 gc_assert(is_lisp_pointer(object));
906 vector = (struct vector *) native_pointer(object);
908 length = fixnum_value(vector->length);
909 nwords = CEILING(length + 2, 2);
911 return copy_large_object(object, nwords);
915 size_vector(lispobj *where)
917 struct vector *vector;
920 vector = (struct vector *) where;
921 length = fixnum_value(vector->length);
922 nwords = CEILING(length + 2, 2);
928 scav_vector_nil(lispobj *where, lispobj object)
934 trans_vector_nil(lispobj object)
936 gc_assert(is_lisp_pointer(object));
937 return copy_unboxed_object(object, 2);
941 size_vector_nil(lispobj *where)
943 /* Just the header word and the length word */
948 scav_vector_bit(lispobj *where, lispobj object)
950 struct vector *vector;
953 vector = (struct vector *) where;
954 length = fixnum_value(vector->length);
955 nwords = CEILING(NWORDS(length, 1) + 2, 2);
961 trans_vector_bit(lispobj object)
963 struct vector *vector;
966 gc_assert(is_lisp_pointer(object));
968 vector = (struct vector *) native_pointer(object);
969 length = fixnum_value(vector->length);
970 nwords = CEILING(NWORDS(length, 1) + 2, 2);
972 return copy_large_unboxed_object(object, nwords);
976 size_vector_bit(lispobj *where)
978 struct vector *vector;
981 vector = (struct vector *) where;
982 length = fixnum_value(vector->length);
983 nwords = CEILING(NWORDS(length, 1) + 2, 2);
989 scav_vector_unsigned_byte_2(lispobj *where, lispobj object)
991 struct vector *vector;
994 vector = (struct vector *) where;
995 length = fixnum_value(vector->length);
996 nwords = CEILING(NWORDS(length, 2) + 2, 2);
1002 trans_vector_unsigned_byte_2(lispobj object)
1004 struct vector *vector;
1005 long length, nwords;
1007 gc_assert(is_lisp_pointer(object));
1009 vector = (struct vector *) native_pointer(object);
1010 length = fixnum_value(vector->length);
1011 nwords = CEILING(NWORDS(length, 2) + 2, 2);
1013 return copy_large_unboxed_object(object, nwords);
1017 size_vector_unsigned_byte_2(lispobj *where)
1019 struct vector *vector;
1020 long length, nwords;
1022 vector = (struct vector *) where;
1023 length = fixnum_value(vector->length);
1024 nwords = CEILING(NWORDS(length, 2) + 2, 2);
1030 scav_vector_unsigned_byte_4(lispobj *where, lispobj object)
1032 struct vector *vector;
1033 long length, nwords;
1035 vector = (struct vector *) where;
1036 length = fixnum_value(vector->length);
1037 nwords = CEILING(NWORDS(length, 4) + 2, 2);
1043 trans_vector_unsigned_byte_4(lispobj object)
1045 struct vector *vector;
1046 long length, nwords;
1048 gc_assert(is_lisp_pointer(object));
1050 vector = (struct vector *) native_pointer(object);
1051 length = fixnum_value(vector->length);
1052 nwords = CEILING(NWORDS(length, 4) + 2, 2);
1054 return copy_large_unboxed_object(object, nwords);
1057 size_vector_unsigned_byte_4(lispobj *where)
1059 struct vector *vector;
1060 long length, nwords;
1062 vector = (struct vector *) where;
1063 length = fixnum_value(vector->length);
1064 nwords = CEILING(NWORDS(length, 4) + 2, 2);
1071 scav_vector_unsigned_byte_8(lispobj *where, lispobj object)
1073 struct vector *vector;
1074 long length, nwords;
1076 vector = (struct vector *) where;
1077 length = fixnum_value(vector->length);
1078 nwords = CEILING(NWORDS(length, 8) + 2, 2);
1083 /*********************/
1088 trans_vector_unsigned_byte_8(lispobj object)
1090 struct vector *vector;
1091 long length, nwords;
1093 gc_assert(is_lisp_pointer(object));
1095 vector = (struct vector *) native_pointer(object);
1096 length = fixnum_value(vector->length);
1097 nwords = CEILING(NWORDS(length, 8) + 2, 2);
1099 return copy_large_unboxed_object(object, nwords);
1103 size_vector_unsigned_byte_8(lispobj *where)
1105 struct vector *vector;
1106 long length, nwords;
1108 vector = (struct vector *) where;
1109 length = fixnum_value(vector->length);
1110 nwords = CEILING(NWORDS(length, 8) + 2, 2);
1117 scav_vector_unsigned_byte_16(lispobj *where, lispobj object)
1119 struct vector *vector;
1120 long length, nwords;
1122 vector = (struct vector *) where;
1123 length = fixnum_value(vector->length);
1124 nwords = CEILING(NWORDS(length, 16) + 2, 2);
1130 trans_vector_unsigned_byte_16(lispobj object)
1132 struct vector *vector;
1133 long length, nwords;
1135 gc_assert(is_lisp_pointer(object));
1137 vector = (struct vector *) native_pointer(object);
1138 length = fixnum_value(vector->length);
1139 nwords = CEILING(NWORDS(length, 16) + 2, 2);
1141 return copy_large_unboxed_object(object, nwords);
1145 size_vector_unsigned_byte_16(lispobj *where)
1147 struct vector *vector;
1148 long length, nwords;
1150 vector = (struct vector *) where;
1151 length = fixnum_value(vector->length);
1152 nwords = CEILING(NWORDS(length, 16) + 2, 2);
1158 scav_vector_unsigned_byte_32(lispobj *where, lispobj object)
1160 struct vector *vector;
1161 long length, nwords;
1163 vector = (struct vector *) where;
1164 length = fixnum_value(vector->length);
1165 nwords = CEILING(NWORDS(length, 32) + 2, 2);
1171 trans_vector_unsigned_byte_32(lispobj object)
1173 struct vector *vector;
1174 long length, nwords;
1176 gc_assert(is_lisp_pointer(object));
1178 vector = (struct vector *) native_pointer(object);
1179 length = fixnum_value(vector->length);
1180 nwords = CEILING(NWORDS(length, 32) + 2, 2);
1182 return copy_large_unboxed_object(object, nwords);
1186 size_vector_unsigned_byte_32(lispobj *where)
1188 struct vector *vector;
1189 long length, nwords;
1191 vector = (struct vector *) where;
1192 length = fixnum_value(vector->length);
1193 nwords = CEILING(NWORDS(length, 32) + 2, 2);
1198 #if N_WORD_BITS == 64
1200 scav_vector_unsigned_byte_64(lispobj *where, lispobj object)
1202 struct vector *vector;
1203 long length, nwords;
1205 vector = (struct vector *) where;
1206 length = fixnum_value(vector->length);
1207 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1213 trans_vector_unsigned_byte_64(lispobj object)
1215 struct vector *vector;
1216 long length, nwords;
1218 gc_assert(is_lisp_pointer(object));
1220 vector = (struct vector *) native_pointer(object);
1221 length = fixnum_value(vector->length);
1222 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1224 return copy_large_unboxed_object(object, nwords);
1228 size_vector_unsigned_byte_64(lispobj *where)
1230 struct vector *vector;
1231 long length, nwords;
1233 vector = (struct vector *) where;
1234 length = fixnum_value(vector->length);
1235 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1242 scav_vector_single_float(lispobj *where, lispobj object)
1244 struct vector *vector;
1245 long length, nwords;
1247 vector = (struct vector *) where;
1248 length = fixnum_value(vector->length);
1249 nwords = CEILING(NWORDS(length, 32) + 2, 2);
1255 trans_vector_single_float(lispobj object)
1257 struct vector *vector;
1258 long length, nwords;
1260 gc_assert(is_lisp_pointer(object));
1262 vector = (struct vector *) native_pointer(object);
1263 length = fixnum_value(vector->length);
1264 nwords = CEILING(NWORDS(length, 32) + 2, 2);
1266 return copy_large_unboxed_object(object, nwords);
1270 size_vector_single_float(lispobj *where)
1272 struct vector *vector;
1273 long length, nwords;
1275 vector = (struct vector *) where;
1276 length = fixnum_value(vector->length);
1277 nwords = CEILING(NWORDS(length, 32) + 2, 2);
1283 scav_vector_double_float(lispobj *where, lispobj object)
1285 struct vector *vector;
1286 long length, nwords;
1288 vector = (struct vector *) where;
1289 length = fixnum_value(vector->length);
1290 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1296 trans_vector_double_float(lispobj object)
1298 struct vector *vector;
1299 long length, nwords;
1301 gc_assert(is_lisp_pointer(object));
1303 vector = (struct vector *) native_pointer(object);
1304 length = fixnum_value(vector->length);
1305 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1307 return copy_large_unboxed_object(object, nwords);
1311 size_vector_double_float(lispobj *where)
1313 struct vector *vector;
1314 long length, nwords;
1316 vector = (struct vector *) where;
1317 length = fixnum_value(vector->length);
1318 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1323 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1325 scav_vector_long_float(lispobj *where, lispobj object)
1327 struct vector *vector;
1328 long length, nwords;
1330 vector = (struct vector *) where;
1331 length = fixnum_value(vector->length);
1332 nwords = CEILING(length *
1339 trans_vector_long_float(lispobj object)
1341 struct vector *vector;
1342 long length, nwords;
1344 gc_assert(is_lisp_pointer(object));
1346 vector = (struct vector *) native_pointer(object);
1347 length = fixnum_value(vector->length);
1348 nwords = CEILING(length * LONG_FLOAT_SIZE + 2, 2);
1350 return copy_large_unboxed_object(object, nwords);
1354 size_vector_long_float(lispobj *where)
1356 struct vector *vector;
1357 long length, nwords;
1359 vector = (struct vector *) where;
1360 length = fixnum_value(vector->length);
1361 nwords = CEILING(length * LONG_FLOAT_SIZE + 2, 2);
1368 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1370 scav_vector_complex_single_float(lispobj *where, lispobj object)
1372 struct vector *vector;
1373 long length, nwords;
1375 vector = (struct vector *) where;
1376 length = fixnum_value(vector->length);
1377 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1383 trans_vector_complex_single_float(lispobj object)
1385 struct vector *vector;
1386 long length, nwords;
1388 gc_assert(is_lisp_pointer(object));
1390 vector = (struct vector *) native_pointer(object);
1391 length = fixnum_value(vector->length);
1392 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1394 return copy_large_unboxed_object(object, nwords);
1398 size_vector_complex_single_float(lispobj *where)
1400 struct vector *vector;
1401 long length, nwords;
1403 vector = (struct vector *) where;
1404 length = fixnum_value(vector->length);
1405 nwords = CEILING(NWORDS(length, 64) + 2, 2);
1411 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1413 scav_vector_complex_double_float(lispobj *where, lispobj object)
1415 struct vector *vector;
1416 long length, nwords;
1418 vector = (struct vector *) where;
1419 length = fixnum_value(vector->length);
1420 nwords = CEILING(NWORDS(length, 128) + 2, 2);
1426 trans_vector_complex_double_float(lispobj object)
1428 struct vector *vector;
1429 long length, nwords;
1431 gc_assert(is_lisp_pointer(object));
1433 vector = (struct vector *) native_pointer(object);
1434 length = fixnum_value(vector->length);
1435 nwords = CEILING(NWORDS(length, 128) + 2, 2);
1437 return copy_large_unboxed_object(object, nwords);
1441 size_vector_complex_double_float(lispobj *where)
1443 struct vector *vector;
1444 long length, nwords;
1446 vector = (struct vector *) where;
1447 length = fixnum_value(vector->length);
1448 nwords = CEILING(NWORDS(length, 128) + 2, 2);
1455 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1457 scav_vector_complex_long_float(lispobj *where, lispobj object)
1459 struct vector *vector;
1460 long length, nwords;
1462 vector = (struct vector *) where;
1463 length = fixnum_value(vector->length);
1464 nwords = CEILING(length * (2* LONG_FLOAT_SIZE) + 2, 2);
1470 trans_vector_complex_long_float(lispobj object)
1472 struct vector *vector;
1473 long length, nwords;
1475 gc_assert(is_lisp_pointer(object));
1477 vector = (struct vector *) native_pointer(object);
1478 length = fixnum_value(vector->length);
1479 nwords = CEILING(length * (2*LONG_FLOAT_SIZE) + 2, 2);
1481 return copy_large_unboxed_object(object, nwords);
1485 size_vector_complex_long_float(lispobj *where)
1487 struct vector *vector;
1488 long length, nwords;
1490 vector = (struct vector *) where;
1491 length = fixnum_value(vector->length);
1492 nwords = CEILING(length * (2*LONG_FLOAT_SIZE) + 2, 2);
1498 #define WEAK_POINTER_NWORDS \
1499 CEILING((sizeof(struct weak_pointer) / sizeof(lispobj)), 2)
1502 trans_weak_pointer(lispobj object)
1505 #ifndef LISP_FEATURE_GENCGC
1506 struct weak_pointer *wp;
1508 gc_assert(is_lisp_pointer(object));
1510 #if defined(DEBUG_WEAK)
1511 printf("Transporting weak pointer from 0x%08x\n", object);
1514 /* Need to remember where all the weak pointers are that have */
1515 /* been transported so they can be fixed up in a post-GC pass. */
1517 copy = copy_object(object, WEAK_POINTER_NWORDS);
1518 #ifndef LISP_FEATURE_GENCGC
1519 wp = (struct weak_pointer *) native_pointer(copy);
1521 gc_assert(widetag_of(wp->header)==WEAK_POINTER_WIDETAG);
1522 /* Push the weak pointer onto the list of weak pointers. */
1523 wp->next = (struct weak_pointer *)LOW_WORD(weak_pointers);
1530 size_weak_pointer(lispobj *where)
1532 return WEAK_POINTER_NWORDS;
1536 void scan_weak_pointers(void)
1538 struct weak_pointer *wp, *next_wp;
1539 for (wp = weak_pointers, next_wp = NULL; wp != NULL; wp = next_wp) {
1540 lispobj value = wp->value;
1541 lispobj *first_pointer;
1542 gc_assert(widetag_of(wp->header)==WEAK_POINTER_WIDETAG);
1546 if (next_wp == wp) /* gencgc uses a ref to self for end of list */
1549 if (!(is_lisp_pointer(value) && from_space_p(value)))
1552 /* Now, we need to check whether the object has been forwarded. If
1553 * it has been, the weak pointer is still good and needs to be
1554 * updated. Otherwise, the weak pointer needs to be nil'ed
1557 first_pointer = (lispobj *)native_pointer(value);
1559 if (forwarding_pointer_p(first_pointer)) {
1561 (lispobj)LOW_WORD(forwarding_pointer_value(first_pointer));
1573 #if N_WORD_BITS == 32
1574 #define EQ_HASH_MASK 0x1fffffff
1575 #elif N_WORD_BITS == 64
1576 #define EQ_HASH_MASK 0x1fffffffffffffff
1579 /* Compute the EQ-hash of KEY. This must match POINTER-HASH in
1580 * target-hash-table.lisp. */
1581 #define EQ_HASH(key) ((key) & EQ_HASH_MASK)
1583 /* List of weak hash tables chained through their NEXT-WEAK-HASH-TABLE
1584 * slot. Set to NULL at the end of a collection.
1586 * This is not optimal because, when a table is tenured, it won't be
1587 * processed automatically; only the yougest generation is GC'd by
1588 * default. On the other hand, all applications will need an
1589 * occasional full GC anyway, so it's not that bad either. */
1590 struct hash_table *weak_hash_tables = NULL;
1592 /* Return true if OBJ has already survived the current GC. */
1594 survived_gc_yet (lispobj obj)
1596 return (!is_lisp_pointer(obj) || !from_space_p(obj) ||
1597 forwarding_pointer_p(native_pointer(obj)));
1601 weak_hash_entry_alivep (lispobj weakness, lispobj key, lispobj value)
1605 return survived_gc_yet(key);
1607 return survived_gc_yet(value);
1609 return (survived_gc_yet(key) || survived_gc_yet(value));
1611 return (survived_gc_yet(key) && survived_gc_yet(value));
1614 /* Shut compiler up. */
1619 /* Return the beginning of data in ARRAY (skipping the header and the
1620 * length) or NULL if it isn't an array of the specified widetag after
1622 static inline lispobj *
1623 get_array_data (lispobj array, int widetag, unsigned long *length)
1625 if (is_lisp_pointer(array) &&
1626 (widetag_of(*(lispobj *)native_pointer(array)) == widetag)) {
1628 *length = fixnum_value(((lispobj *)native_pointer(array))[1]);
1629 return ((lispobj *)native_pointer(array)) + 2;
1635 /* Only need to worry about scavenging the _real_ entries in the
1636 * table. Phantom entries such as the hash table itself at index 0 and
1637 * the empty marker at index 1 were scavenged by scav_vector that
1638 * either called this function directly or arranged for it to be
1639 * called later by pushing the hash table onto weak_hash_tables. */
1641 scav_hash_table_entries (struct hash_table *hash_table)
1644 unsigned long kv_length;
1645 lispobj *index_vector;
1646 unsigned long length;
1647 lispobj *next_vector;
1648 unsigned long next_vector_length;
1649 lispobj *hash_vector;
1650 unsigned long hash_vector_length;
1651 lispobj empty_symbol;
1652 lispobj weakness = hash_table->weakness;
1655 kv_vector = get_array_data(hash_table->table,
1656 SIMPLE_VECTOR_WIDETAG, &kv_length);
1657 if (kv_vector == NULL)
1658 lose("invalid kv_vector %x\n", hash_table->table);
1660 index_vector = get_array_data(hash_table->index_vector,
1661 SIMPLE_ARRAY_WORD_WIDETAG, &length);
1662 if (index_vector == NULL)
1663 lose("invalid index_vector %x\n", hash_table->index_vector);
1665 next_vector = get_array_data(hash_table->next_vector,
1666 SIMPLE_ARRAY_WORD_WIDETAG,
1667 &next_vector_length);
1668 if (next_vector == NULL)
1669 lose("invalid next_vector %x\n", hash_table->next_vector);
1671 hash_vector = get_array_data(hash_table->hash_vector,
1672 SIMPLE_ARRAY_WORD_WIDETAG,
1673 &hash_vector_length);
1674 if (hash_vector != NULL)
1675 gc_assert(hash_vector_length == next_vector_length);
1677 /* These lengths could be different as the index_vector can be a
1678 * different length from the others, a larger index_vector could
1679 * help reduce collisions. */
1680 gc_assert(next_vector_length*2 == kv_length);
1682 empty_symbol = kv_vector[1];
1683 /* fprintf(stderr,"* empty_symbol = %x\n", empty_symbol);*/
1684 if (widetag_of(*(lispobj *)native_pointer(empty_symbol)) !=
1685 SYMBOL_HEADER_WIDETAG) {
1686 lose("not a symbol where empty-hash-table-slot symbol expected: %x\n",
1687 *(lispobj *)native_pointer(empty_symbol));
1690 /* Work through the KV vector. */
1691 for (i = 1; i < next_vector_length; i++) {
1692 lispobj old_key = kv_vector[2*i];
1693 lispobj value = kv_vector[2*i+1];
1694 if ((weakness == NIL) ||
1695 weak_hash_entry_alivep(weakness, old_key, value)) {
1697 /* Scavenge the key and value. */
1698 scavenge(&kv_vector[2*i],2);
1700 /* If an EQ-based key has moved, mark the hash-table for
1702 if (!hash_vector || hash_vector[i] == MAGIC_HASH_VECTOR_VALUE) {
1703 lispobj new_key = kv_vector[2*i];
1705 if (old_key != new_key && new_key != empty_symbol) {
1706 hash_table->needs_rehash_p = T;
1714 scav_vector (lispobj *where, lispobj object)
1716 unsigned long kv_length;
1718 struct hash_table *hash_table;
1720 /* SB-VM:VECTOR-VALID-HASHING-SUBTYPE is set for EQ-based and weak
1721 * hash tables in the Lisp HASH-TABLE code to indicate need for
1722 * special GC support. */
1723 if (HeaderValue(object) == subtype_VectorNormal)
1726 kv_length = fixnum_value(where[1]);
1727 kv_vector = where + 2; /* Skip the header and length. */
1728 /*FSHOW((stderr,"/kv_length = %d\n", kv_length));*/
1730 /* Scavenge element 0, which may be a hash-table structure. */
1731 scavenge(where+2, 1);
1732 if (!is_lisp_pointer(where[2])) {
1733 /* This'll happen when REHASH clears the header of old-kv-vector
1734 * and fills it with zero, but some other thread simulatenously
1735 * sets the header in %%PUTHASH.
1738 "Warning: no pointer at %lx in hash table: this indicates "
1739 "non-fatal corruption caused by concurrent access to a "
1740 "hash-table from multiple threads. Any accesses to "
1741 "hash-tables shared between threads should be protected "
1742 "by locks.\n", (unsigned long)&where[2]);
1743 // We've scavenged three words.
1746 hash_table = (struct hash_table *)native_pointer(where[2]);
1747 /*FSHOW((stderr,"/hash_table = %x\n", hash_table));*/
1748 if (widetag_of(hash_table->header) != INSTANCE_HEADER_WIDETAG) {
1749 lose("hash table not instance (%x at %x)\n",
1754 /* Scavenge element 1, which should be some internal symbol that
1755 * the hash table code reserves for marking empty slots. */
1756 scavenge(where+3, 1);
1757 if (!is_lisp_pointer(where[3])) {
1758 lose("not empty-hash-table-slot symbol pointer: %x\n", where[3]);
1761 /* Scavenge hash table, which will fix the positions of the other
1762 * needed objects. */
1763 scavenge((lispobj *)hash_table,
1764 sizeof(struct hash_table) / sizeof(lispobj));
1766 /* Cross-check the kv_vector. */
1767 if (where != (lispobj *)native_pointer(hash_table->table)) {
1768 lose("hash_table table!=this table %x\n", hash_table->table);
1771 if (hash_table->weakness == NIL) {
1772 scav_hash_table_entries(hash_table);
1774 /* Delay scavenging of this table by pushing it onto
1775 * weak_hash_tables (if it's not there already) for the weak
1777 if (hash_table->next_weak_hash_table == NIL) {
1778 hash_table->next_weak_hash_table = (lispobj)weak_hash_tables;
1779 weak_hash_tables = hash_table;
1783 return (CEILING(kv_length + 2, 2));
1787 scav_weak_hash_tables (void)
1789 struct hash_table *table;
1791 /* Scavenge entries whose triggers are known to survive. */
1792 for (table = weak_hash_tables; table != NULL;
1793 table = (struct hash_table *)table->next_weak_hash_table) {
1794 scav_hash_table_entries(table);
1798 /* Walk through the chain whose first element is *FIRST and remove
1799 * dead weak entries. */
1801 scan_weak_hash_table_chain (struct hash_table *hash_table, lispobj *prev,
1802 lispobj *kv_vector, lispobj *index_vector,
1803 lispobj *next_vector, lispobj *hash_vector,
1804 lispobj empty_symbol, lispobj weakness)
1806 unsigned index = *prev;
1808 unsigned next = next_vector[index];
1809 lispobj key = kv_vector[2 * index];
1810 lispobj value = kv_vector[2 * index + 1];
1811 gc_assert(key != empty_symbol);
1812 gc_assert(value != empty_symbol);
1813 if (!weak_hash_entry_alivep(weakness, key, value)) {
1814 unsigned count = fixnum_value(hash_table->number_entries);
1815 gc_assert(count > 0);
1817 hash_table->number_entries = make_fixnum(count - 1);
1818 next_vector[index] = fixnum_value(hash_table->next_free_kv);
1819 hash_table->next_free_kv = make_fixnum(index);
1820 kv_vector[2 * index] = empty_symbol;
1821 kv_vector[2 * index + 1] = empty_symbol;
1823 hash_vector[index] = MAGIC_HASH_VECTOR_VALUE;
1825 prev = &next_vector[index];
1832 scan_weak_hash_table (struct hash_table *hash_table)
1835 lispobj *index_vector;
1836 unsigned long length = 0; /* prevent warning */
1837 lispobj *next_vector;
1838 unsigned long next_vector_length = 0; /* prevent warning */
1839 lispobj *hash_vector;
1840 lispobj empty_symbol;
1841 lispobj weakness = hash_table->weakness;
1844 kv_vector = get_array_data(hash_table->table,
1845 SIMPLE_VECTOR_WIDETAG, NULL);
1846 index_vector = get_array_data(hash_table->index_vector,
1847 SIMPLE_ARRAY_WORD_WIDETAG, &length);
1848 next_vector = get_array_data(hash_table->next_vector,
1849 SIMPLE_ARRAY_WORD_WIDETAG,
1850 &next_vector_length);
1851 hash_vector = get_array_data(hash_table->hash_vector,
1852 SIMPLE_ARRAY_WORD_WIDETAG, NULL);
1853 empty_symbol = kv_vector[1];
1855 for (i = 0; i < length; i++) {
1856 scan_weak_hash_table_chain(hash_table, &index_vector[i],
1857 kv_vector, index_vector, next_vector,
1858 hash_vector, empty_symbol, weakness);
1862 /* Remove dead entries from weak hash tables. */
1864 scan_weak_hash_tables (void)
1866 struct hash_table *table, *next;
1868 for (table = weak_hash_tables; table != NULL; table = next) {
1869 next = (struct hash_table *)table->next_weak_hash_table;
1870 table->next_weak_hash_table = NIL;
1871 scan_weak_hash_table(table);
1874 weak_hash_tables = NULL;
1883 scav_lose(lispobj *where, lispobj object)
1885 lose("no scavenge function for object 0x%08x (widetag 0x%x)\n",
1886 (unsigned long)object,
1887 widetag_of(*where));
1889 return 0; /* bogus return value to satisfy static type checking */
1893 trans_lose(lispobj object)
1895 lose("no transport function for object 0x%08x (widetag 0x%x)\n",
1896 (unsigned long)object,
1897 widetag_of(*(lispobj*)native_pointer(object)));
1898 return NIL; /* bogus return value to satisfy static type checking */
1902 size_lose(lispobj *where)
1904 lose("no size function for object at 0x%08x (widetag 0x%x)\n",
1905 (unsigned long)where,
1906 widetag_of(*where));
1907 return 1; /* bogus return value to satisfy static type checking */
1916 gc_init_tables(void)
1920 /* Set default value in all slots of scavenge table. FIXME
1921 * replace this gnarly sizeof with something based on
1923 for (i = 0; i < ((sizeof scavtab)/(sizeof scavtab[0])); i++) {
1924 scavtab[i] = scav_lose;
1927 /* For each type which can be selected by the lowtag alone, set
1928 * multiple entries in our widetag scavenge table (one for each
1929 * possible value of the high bits).
1932 for (i = 0; i < (1<<(N_WIDETAG_BITS-N_LOWTAG_BITS)); i++) {
1933 for (j = 0; j < (1<<N_LOWTAG_BITS); j++) {
1935 scavtab[j|(i<<N_LOWTAG_BITS)] = scav_immediate;
1938 scavtab[FUN_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_fun_pointer;
1939 /* skipping OTHER_IMMEDIATE_0_LOWTAG */
1940 scavtab[LIST_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_list_pointer;
1941 scavtab[INSTANCE_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] =
1942 scav_instance_pointer;
1943 /* skipping OTHER_IMMEDIATE_1_LOWTAG */
1944 scavtab[OTHER_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_other_pointer;
1947 /* Other-pointer types (those selected by all eight bits of the
1948 * tag) get one entry each in the scavenge table. */
1949 scavtab[BIGNUM_WIDETAG] = scav_unboxed;
1950 scavtab[RATIO_WIDETAG] = scav_boxed;
1951 #if N_WORD_BITS == 64
1952 scavtab[SINGLE_FLOAT_WIDETAG] = scav_immediate;
1954 scavtab[SINGLE_FLOAT_WIDETAG] = scav_unboxed;
1956 scavtab[DOUBLE_FLOAT_WIDETAG] = scav_unboxed;
1957 #ifdef LONG_FLOAT_WIDETAG
1958 scavtab[LONG_FLOAT_WIDETAG] = scav_unboxed;
1960 scavtab[COMPLEX_WIDETAG] = scav_boxed;
1961 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
1962 scavtab[COMPLEX_SINGLE_FLOAT_WIDETAG] = scav_unboxed;
1964 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
1965 scavtab[COMPLEX_DOUBLE_FLOAT_WIDETAG] = scav_unboxed;
1967 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
1968 scavtab[COMPLEX_LONG_FLOAT_WIDETAG] = scav_unboxed;
1970 scavtab[SIMPLE_ARRAY_WIDETAG] = scav_boxed;
1971 scavtab[SIMPLE_BASE_STRING_WIDETAG] = scav_base_string;
1972 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
1973 scavtab[SIMPLE_CHARACTER_STRING_WIDETAG] = scav_character_string;
1975 scavtab[SIMPLE_BIT_VECTOR_WIDETAG] = scav_vector_bit;
1976 scavtab[SIMPLE_ARRAY_NIL_WIDETAG] = scav_vector_nil;
1977 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG] =
1978 scav_vector_unsigned_byte_2;
1979 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG] =
1980 scav_vector_unsigned_byte_4;
1981 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG] =
1982 scav_vector_unsigned_byte_8;
1983 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG] =
1984 scav_vector_unsigned_byte_8;
1985 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG] =
1986 scav_vector_unsigned_byte_16;
1987 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
1988 scav_vector_unsigned_byte_16;
1989 #if (N_WORD_BITS == 32)
1990 scavtab[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG] =
1991 scav_vector_unsigned_byte_32;
1993 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
1994 scav_vector_unsigned_byte_32;
1995 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
1996 scav_vector_unsigned_byte_32;
1997 #if (N_WORD_BITS == 64)
1998 scavtab[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG] =
1999 scav_vector_unsigned_byte_64;
2001 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
2002 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG] =
2003 scav_vector_unsigned_byte_64;
2005 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
2006 scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
2007 scav_vector_unsigned_byte_64;
2009 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
2010 scavtab[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] = scav_vector_unsigned_byte_8;
2012 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
2013 scavtab[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG] =
2014 scav_vector_unsigned_byte_16;
2016 #if (N_WORD_BITS == 32)
2017 scavtab[SIMPLE_ARRAY_FIXNUM_WIDETAG] =
2018 scav_vector_unsigned_byte_32;
2020 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
2021 scavtab[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
2022 scav_vector_unsigned_byte_32;
2024 #if (N_WORD_BITS == 64)
2025 scavtab[SIMPLE_ARRAY_FIXNUM_WIDETAG] =
2026 scav_vector_unsigned_byte_64;
2028 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
2029 scavtab[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
2030 scav_vector_unsigned_byte_64;
2032 scavtab[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] = scav_vector_single_float;
2033 scavtab[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] = scav_vector_double_float;
2034 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
2035 scavtab[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG] = scav_vector_long_float;
2037 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
2038 scavtab[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG] =
2039 scav_vector_complex_single_float;
2041 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
2042 scavtab[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG] =
2043 scav_vector_complex_double_float;
2045 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
2046 scavtab[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG] =
2047 scav_vector_complex_long_float;
2049 scavtab[COMPLEX_BASE_STRING_WIDETAG] = scav_boxed;
2050 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
2051 scavtab[COMPLEX_CHARACTER_STRING_WIDETAG] = scav_boxed;
2053 scavtab[COMPLEX_VECTOR_NIL_WIDETAG] = scav_boxed;
2054 scavtab[COMPLEX_BIT_VECTOR_WIDETAG] = scav_boxed;
2055 scavtab[COMPLEX_VECTOR_WIDETAG] = scav_boxed;
2056 scavtab[COMPLEX_ARRAY_WIDETAG] = scav_boxed;
2057 scavtab[CODE_HEADER_WIDETAG] = scav_code_header;
2058 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
2059 scavtab[SIMPLE_FUN_HEADER_WIDETAG] = scav_fun_header;
2060 scavtab[RETURN_PC_HEADER_WIDETAG] = scav_return_pc_header;
2062 scavtab[FUNCALLABLE_INSTANCE_HEADER_WIDETAG] = scav_boxed;
2063 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
2064 scavtab[CLOSURE_HEADER_WIDETAG] = scav_closure_header;
2066 scavtab[CLOSURE_HEADER_WIDETAG] = scav_boxed;
2068 scavtab[VALUE_CELL_HEADER_WIDETAG] = scav_boxed;
2069 scavtab[SYMBOL_HEADER_WIDETAG] = scav_boxed;
2070 scavtab[CHARACTER_WIDETAG] = scav_immediate;
2071 scavtab[SAP_WIDETAG] = scav_unboxed;
2072 scavtab[UNBOUND_MARKER_WIDETAG] = scav_immediate;
2073 scavtab[NO_TLS_VALUE_MARKER_WIDETAG] = scav_immediate;
2074 scavtab[INSTANCE_HEADER_WIDETAG] = scav_instance;
2075 #if defined(LISP_FEATURE_SPARC)
2076 scavtab[FDEFN_WIDETAG] = scav_boxed;
2078 scavtab[FDEFN_WIDETAG] = scav_fdefn;
2080 scavtab[SIMPLE_VECTOR_WIDETAG] = scav_vector;
2082 /* transport other table, initialized same way as scavtab */
2083 for (i = 0; i < ((sizeof transother)/(sizeof transother[0])); i++)
2084 transother[i] = trans_lose;
2085 transother[BIGNUM_WIDETAG] = trans_unboxed;
2086 transother[RATIO_WIDETAG] = trans_boxed;
2088 #if N_WORD_BITS == 64
2089 transother[SINGLE_FLOAT_WIDETAG] = trans_immediate;
2091 transother[SINGLE_FLOAT_WIDETAG] = trans_unboxed;
2093 transother[DOUBLE_FLOAT_WIDETAG] = trans_unboxed;
2094 #ifdef LONG_FLOAT_WIDETAG
2095 transother[LONG_FLOAT_WIDETAG] = trans_unboxed;
2097 transother[COMPLEX_WIDETAG] = trans_boxed;
2098 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
2099 transother[COMPLEX_SINGLE_FLOAT_WIDETAG] = trans_unboxed;
2101 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
2102 transother[COMPLEX_DOUBLE_FLOAT_WIDETAG] = trans_unboxed;
2104 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
2105 transother[COMPLEX_LONG_FLOAT_WIDETAG] = trans_unboxed;
2107 transother[SIMPLE_ARRAY_WIDETAG] = trans_boxed; /* but not GENCGC */
2108 transother[SIMPLE_BASE_STRING_WIDETAG] = trans_base_string;
2109 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
2110 transother[SIMPLE_CHARACTER_STRING_WIDETAG] = trans_character_string;
2112 transother[SIMPLE_BIT_VECTOR_WIDETAG] = trans_vector_bit;
2113 transother[SIMPLE_VECTOR_WIDETAG] = trans_vector;
2114 transother[SIMPLE_ARRAY_NIL_WIDETAG] = trans_vector_nil;
2115 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG] =
2116 trans_vector_unsigned_byte_2;
2117 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG] =
2118 trans_vector_unsigned_byte_4;
2119 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG] =
2120 trans_vector_unsigned_byte_8;
2121 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG] =
2122 trans_vector_unsigned_byte_8;
2123 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG] =
2124 trans_vector_unsigned_byte_16;
2125 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
2126 trans_vector_unsigned_byte_16;
2127 #if (N_WORD_BITS == 32)
2128 transother[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG] =
2129 trans_vector_unsigned_byte_32;
2131 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
2132 trans_vector_unsigned_byte_32;
2133 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
2134 trans_vector_unsigned_byte_32;
2135 #if (N_WORD_BITS == 64)
2136 transother[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG] =
2137 trans_vector_unsigned_byte_64;
2139 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
2140 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG] =
2141 trans_vector_unsigned_byte_64;
2143 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
2144 transother[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
2145 trans_vector_unsigned_byte_64;
2147 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
2148 transother[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] =
2149 trans_vector_unsigned_byte_8;
2151 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
2152 transother[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG] =
2153 trans_vector_unsigned_byte_16;
2155 #if (N_WORD_BITS == 32)
2156 transother[SIMPLE_ARRAY_FIXNUM_WIDETAG] =
2157 trans_vector_unsigned_byte_32;
2159 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
2160 transother[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
2161 trans_vector_unsigned_byte_32;
2163 #if (N_WORD_BITS == 64)
2164 transother[SIMPLE_ARRAY_FIXNUM_WIDETAG] =
2165 trans_vector_unsigned_byte_64;
2167 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
2168 transother[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
2169 trans_vector_unsigned_byte_64;
2171 transother[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] =
2172 trans_vector_single_float;
2173 transother[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] =
2174 trans_vector_double_float;
2175 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
2176 transother[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG] =
2177 trans_vector_long_float;
2179 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
2180 transother[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG] =
2181 trans_vector_complex_single_float;
2183 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
2184 transother[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG] =
2185 trans_vector_complex_double_float;
2187 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
2188 transother[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG] =
2189 trans_vector_complex_long_float;
2191 transother[COMPLEX_BASE_STRING_WIDETAG] = trans_boxed;
2192 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
2193 transother[COMPLEX_CHARACTER_STRING_WIDETAG] = trans_boxed;
2195 transother[COMPLEX_BIT_VECTOR_WIDETAG] = trans_boxed;
2196 transother[COMPLEX_VECTOR_NIL_WIDETAG] = trans_boxed;
2197 transother[COMPLEX_VECTOR_WIDETAG] = trans_boxed;
2198 transother[COMPLEX_ARRAY_WIDETAG] = trans_boxed;
2199 transother[CODE_HEADER_WIDETAG] = trans_code_header;
2200 transother[SIMPLE_FUN_HEADER_WIDETAG] = trans_fun_header;
2201 transother[RETURN_PC_HEADER_WIDETAG] = trans_return_pc_header;
2202 transother[CLOSURE_HEADER_WIDETAG] = trans_boxed;
2203 transother[FUNCALLABLE_INSTANCE_HEADER_WIDETAG] = trans_boxed;
2204 transother[VALUE_CELL_HEADER_WIDETAG] = trans_boxed;
2205 transother[SYMBOL_HEADER_WIDETAG] = trans_boxed;
2206 transother[CHARACTER_WIDETAG] = trans_immediate;
2207 transother[SAP_WIDETAG] = trans_unboxed;
2208 transother[UNBOUND_MARKER_WIDETAG] = trans_immediate;
2209 transother[NO_TLS_VALUE_MARKER_WIDETAG] = trans_immediate;
2210 transother[WEAK_POINTER_WIDETAG] = trans_weak_pointer;
2211 transother[INSTANCE_HEADER_WIDETAG] = trans_boxed;
2212 transother[FDEFN_WIDETAG] = trans_boxed;
2214 /* size table, initialized the same way as scavtab */
2215 for (i = 0; i < ((sizeof sizetab)/(sizeof sizetab[0])); i++)
2216 sizetab[i] = size_lose;
2217 for (i = 0; i < (1<<(N_WIDETAG_BITS-N_LOWTAG_BITS)); i++) {
2218 for (j = 0; j < (1<<N_LOWTAG_BITS); j++) {
2220 sizetab[j|(i<<N_LOWTAG_BITS)] = size_immediate;
2223 sizetab[FUN_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
2224 /* skipping OTHER_IMMEDIATE_0_LOWTAG */
2225 sizetab[LIST_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
2226 sizetab[INSTANCE_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
2227 /* skipping OTHER_IMMEDIATE_1_LOWTAG */
2228 sizetab[OTHER_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
2230 sizetab[BIGNUM_WIDETAG] = size_unboxed;
2231 sizetab[RATIO_WIDETAG] = size_boxed;
2232 #if N_WORD_BITS == 64
2233 sizetab[SINGLE_FLOAT_WIDETAG] = size_immediate;
2235 sizetab[SINGLE_FLOAT_WIDETAG] = size_unboxed;
2237 sizetab[DOUBLE_FLOAT_WIDETAG] = size_unboxed;
2238 #ifdef LONG_FLOAT_WIDETAG
2239 sizetab[LONG_FLOAT_WIDETAG] = size_unboxed;
2241 sizetab[COMPLEX_WIDETAG] = size_boxed;
2242 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
2243 sizetab[COMPLEX_SINGLE_FLOAT_WIDETAG] = size_unboxed;
2245 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
2246 sizetab[COMPLEX_DOUBLE_FLOAT_WIDETAG] = size_unboxed;
2248 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
2249 sizetab[COMPLEX_LONG_FLOAT_WIDETAG] = size_unboxed;
2251 sizetab[SIMPLE_ARRAY_WIDETAG] = size_boxed;
2252 sizetab[SIMPLE_BASE_STRING_WIDETAG] = size_base_string;
2253 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
2254 sizetab[SIMPLE_CHARACTER_STRING_WIDETAG] = size_character_string;
2256 sizetab[SIMPLE_BIT_VECTOR_WIDETAG] = size_vector_bit;
2257 sizetab[SIMPLE_VECTOR_WIDETAG] = size_vector;
2258 sizetab[SIMPLE_ARRAY_NIL_WIDETAG] = size_vector_nil;
2259 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG] =
2260 size_vector_unsigned_byte_2;
2261 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG] =
2262 size_vector_unsigned_byte_4;
2263 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG] =
2264 size_vector_unsigned_byte_8;
2265 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG] =
2266 size_vector_unsigned_byte_8;
2267 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG] =
2268 size_vector_unsigned_byte_16;
2269 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
2270 size_vector_unsigned_byte_16;
2271 #if (N_WORD_BITS == 32)
2272 sizetab[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG] =
2273 size_vector_unsigned_byte_32;
2275 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
2276 size_vector_unsigned_byte_32;
2277 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
2278 size_vector_unsigned_byte_32;
2279 #if (N_WORD_BITS == 64)
2280 sizetab[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG] =
2281 size_vector_unsigned_byte_64;
2283 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
2284 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG] =
2285 size_vector_unsigned_byte_64;
2287 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
2288 sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
2289 size_vector_unsigned_byte_64;
2291 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
2292 sizetab[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] = size_vector_unsigned_byte_8;
2294 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
2295 sizetab[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG] =
2296 size_vector_unsigned_byte_16;
2298 #if (N_WORD_BITS == 32)
2299 sizetab[SIMPLE_ARRAY_FIXNUM_WIDETAG] =
2300 size_vector_unsigned_byte_32;
2302 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
2303 sizetab[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
2304 size_vector_unsigned_byte_32;
2306 #if (N_WORD_BITS == 64)
2307 sizetab[SIMPLE_ARRAY_FIXNUM_WIDETAG] =
2308 size_vector_unsigned_byte_64;
2310 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
2311 sizetab[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
2312 size_vector_unsigned_byte_64;
2314 sizetab[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] = size_vector_single_float;
2315 sizetab[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] = size_vector_double_float;
2316 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
2317 sizetab[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG] = size_vector_long_float;
2319 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
2320 sizetab[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG] =
2321 size_vector_complex_single_float;
2323 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
2324 sizetab[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG] =
2325 size_vector_complex_double_float;
2327 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
2328 sizetab[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG] =
2329 size_vector_complex_long_float;
2331 sizetab[COMPLEX_BASE_STRING_WIDETAG] = size_boxed;
2332 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
2333 sizetab[COMPLEX_CHARACTER_STRING_WIDETAG] = size_boxed;
2335 sizetab[COMPLEX_VECTOR_NIL_WIDETAG] = size_boxed;
2336 sizetab[COMPLEX_BIT_VECTOR_WIDETAG] = size_boxed;
2337 sizetab[COMPLEX_VECTOR_WIDETAG] = size_boxed;
2338 sizetab[COMPLEX_ARRAY_WIDETAG] = size_boxed;
2339 sizetab[CODE_HEADER_WIDETAG] = size_code_header;
2341 /* We shouldn't see these, so just lose if it happens. */
2342 sizetab[SIMPLE_FUN_HEADER_WIDETAG] = size_function_header;
2343 sizetab[RETURN_PC_HEADER_WIDETAG] = size_return_pc_header;
2345 sizetab[CLOSURE_HEADER_WIDETAG] = size_boxed;
2346 sizetab[FUNCALLABLE_INSTANCE_HEADER_WIDETAG] = size_boxed;
2347 sizetab[VALUE_CELL_HEADER_WIDETAG] = size_boxed;
2348 sizetab[SYMBOL_HEADER_WIDETAG] = size_boxed;
2349 sizetab[CHARACTER_WIDETAG] = size_immediate;
2350 sizetab[SAP_WIDETAG] = size_unboxed;
2351 sizetab[UNBOUND_MARKER_WIDETAG] = size_immediate;
2352 sizetab[NO_TLS_VALUE_MARKER_WIDETAG] = size_immediate;
2353 sizetab[WEAK_POINTER_WIDETAG] = size_weak_pointer;
2354 sizetab[INSTANCE_HEADER_WIDETAG] = size_boxed;
2355 sizetab[FDEFN_WIDETAG] = size_boxed;
2359 /* Find the code object for the given pc, or return NULL on
2362 component_ptr_from_pc(lispobj *pc)
2364 lispobj *object = NULL;
2366 if ( (object = search_read_only_space(pc)) )
2368 else if ( (object = search_static_space(pc)) )
2371 object = search_dynamic_space(pc);
2373 if (object) /* if we found something */
2374 if (widetag_of(*object) == CODE_HEADER_WIDETAG)
2380 /* Scan an area looking for an object which encloses the given pointer.
2381 * Return the object start on success or NULL on failure. */
2383 gc_search_space(lispobj *start, size_t words, lispobj *pointer)
2387 lispobj thing = *start;
2389 /* If thing is an immediate then this is a cons. */
2390 if (is_lisp_pointer(thing) || is_lisp_immediate(thing))
2393 count = (sizetab[widetag_of(thing)])(start);
2395 /* Check whether the pointer is within this object. */
2396 if ((pointer >= start) && (pointer < (start+count))) {
2398 /*FSHOW((stderr,"/found %x in %x %x\n", pointer, start, thing));*/
2402 /* Round up the count. */
2403 count = CEILING(count,2);
2411 /* Helper for valid_lisp_pointer_p (below) and
2412 * possibly_valid_dynamic_space_pointer (gencgc).
2414 * pointer is the pointer to validate, and start_addr is the address
2415 * of the enclosing object.
2418 looks_like_valid_lisp_pointer_p(lispobj pointer, lispobj *start_addr)
2420 if (!is_lisp_pointer(pointer)) {
2424 /* Check that the object pointed to is consistent with the pointer
2426 switch (lowtag_of(pointer)) {
2427 case FUN_POINTER_LOWTAG:
2428 /* Start_addr should be the enclosing code object, or a closure
2430 switch (widetag_of(*start_addr)) {
2431 case CODE_HEADER_WIDETAG:
2432 /* Make sure we actually point to a function in the code object,
2433 * as opposed to a random point there. */
2434 if (SIMPLE_FUN_HEADER_WIDETAG==widetag_of(native_pointer(pointer)[0]))
2438 case CLOSURE_HEADER_WIDETAG:
2439 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
2440 if (pointer != make_lispobj(start_addr, FUN_POINTER_LOWTAG)) {
2448 case LIST_POINTER_LOWTAG:
2449 if (pointer != make_lispobj(start_addr, LIST_POINTER_LOWTAG)) {
2452 /* Is it plausible cons? */
2453 if ((is_lisp_pointer(start_addr[0]) ||
2454 is_lisp_immediate(start_addr[0])) &&
2455 (is_lisp_pointer(start_addr[1]) ||
2456 is_lisp_immediate(start_addr[1])))
2461 case INSTANCE_POINTER_LOWTAG:
2462 if (pointer != make_lispobj(start_addr, INSTANCE_POINTER_LOWTAG)) {
2465 if (widetag_of(start_addr[0]) != INSTANCE_HEADER_WIDETAG) {
2469 case OTHER_POINTER_LOWTAG:
2471 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
2472 /* The all-architecture test below is good as far as it goes,
2473 * but an LRA object is similar to a FUN-POINTER: It is
2474 * embedded within a CODE-OBJECT pointed to by start_addr, and
2475 * cannot be found by simply walking the heap, therefore we
2476 * need to check for it. -- AB, 2010-Jun-04 */
2477 if ((widetag_of(start_addr[0]) == CODE_HEADER_WIDETAG)) {
2478 lispobj *potential_lra = native_pointer(pointer);
2479 if ((widetag_of(potential_lra[0]) == RETURN_PC_HEADER_WIDETAG) &&
2480 ((potential_lra - HeaderValue(potential_lra[0])) == start_addr)) {
2481 return 1; /* It's as good as we can verify. */
2486 if (pointer != make_lispobj(start_addr, OTHER_POINTER_LOWTAG)) {
2489 /* Is it plausible? Not a cons. XXX should check the headers. */
2490 if (is_lisp_pointer(start_addr[0]) || ((start_addr[0] & 3) == 0)) {
2493 switch (widetag_of(start_addr[0])) {
2494 case UNBOUND_MARKER_WIDETAG:
2495 case NO_TLS_VALUE_MARKER_WIDETAG:
2496 case CHARACTER_WIDETAG:
2497 #if N_WORD_BITS == 64
2498 case SINGLE_FLOAT_WIDETAG:
2502 /* only pointed to by function pointers? */
2503 case CLOSURE_HEADER_WIDETAG:
2504 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
2507 case INSTANCE_HEADER_WIDETAG:
2510 /* the valid other immediate pointer objects */
2511 case SIMPLE_VECTOR_WIDETAG:
2513 case COMPLEX_WIDETAG:
2514 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
2515 case COMPLEX_SINGLE_FLOAT_WIDETAG:
2517 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
2518 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
2520 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
2521 case COMPLEX_LONG_FLOAT_WIDETAG:
2523 case SIMPLE_ARRAY_WIDETAG:
2524 case COMPLEX_BASE_STRING_WIDETAG:
2525 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
2526 case COMPLEX_CHARACTER_STRING_WIDETAG:
2528 case COMPLEX_VECTOR_NIL_WIDETAG:
2529 case COMPLEX_BIT_VECTOR_WIDETAG:
2530 case COMPLEX_VECTOR_WIDETAG:
2531 case COMPLEX_ARRAY_WIDETAG:
2532 case VALUE_CELL_HEADER_WIDETAG:
2533 case SYMBOL_HEADER_WIDETAG:
2535 case CODE_HEADER_WIDETAG:
2536 case BIGNUM_WIDETAG:
2537 #if N_WORD_BITS != 64
2538 case SINGLE_FLOAT_WIDETAG:
2540 case DOUBLE_FLOAT_WIDETAG:
2541 #ifdef LONG_FLOAT_WIDETAG
2542 case LONG_FLOAT_WIDETAG:
2544 case SIMPLE_BASE_STRING_WIDETAG:
2545 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
2546 case SIMPLE_CHARACTER_STRING_WIDETAG:
2548 case SIMPLE_BIT_VECTOR_WIDETAG:
2549 case SIMPLE_ARRAY_NIL_WIDETAG:
2550 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
2551 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
2552 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
2553 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
2554 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
2555 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
2557 case SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG:
2559 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
2560 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
2561 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
2562 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
2564 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
2565 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
2567 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
2568 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
2570 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
2571 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
2574 case SIMPLE_ARRAY_FIXNUM_WIDETAG:
2576 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
2577 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
2579 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
2580 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
2582 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
2583 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
2584 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
2585 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
2587 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
2588 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
2590 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
2591 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
2593 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
2594 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
2597 case WEAK_POINTER_WIDETAG:
2612 /* Used by the debugger to validate possibly bogus pointers before
2613 * calling MAKE-LISP-OBJ on them.
2615 * FIXME: We would like to make this perfect, because if the debugger
2616 * constructs a reference to a bugs lisp object, and it ends up in a
2617 * location scavenged by the GC all hell breaks loose.
2619 * Whereas possibly_valid_dynamic_space_pointer has to be conservative
2620 * and return true for all valid pointers, this could actually be eager
2621 * and lie about a few pointers without bad results... but that should
2622 * be reflected in the name.
2625 valid_lisp_pointer_p(lispobj *pointer)
2628 if (((start=search_dynamic_space(pointer))!=NULL) ||
2629 ((start=search_static_space(pointer))!=NULL) ||
2630 ((start=search_read_only_space(pointer))!=NULL))
2631 return looks_like_valid_lisp_pointer_p((lispobj)pointer, start);
2637 maybe_gc(os_context_t *context)
2639 lispobj gc_happened;
2640 struct thread *thread = arch_os_get_current_thread();
2642 fake_foreign_function_call(context);
2643 /* SUB-GC may return without GCing if *GC-INHIBIT* is set, in
2644 * which case we will be running with no gc trigger barrier
2645 * thing for a while. But it shouldn't be long until the end
2648 * FIXME: It would be good to protect the end of dynamic space for
2649 * CheneyGC and signal a storage condition from there.
2652 /* Restore the signal mask from the interrupted context before
2653 * calling into Lisp if interrupts are enabled. Why not always?
2655 * Suppose there is a WITHOUT-INTERRUPTS block far, far out. If an
2656 * interrupt hits while in SUB-GC, it is deferred and the
2657 * os_context_sigmask of that interrupt is set to block further
2658 * deferrable interrupts (until the first one is
2659 * handled). Unfortunately, that context refers to this place and
2660 * when we return from here the signals will not be blocked.
2662 * A kludgy alternative is to propagate the sigmask change to the
2665 #ifndef LISP_FEATURE_WIN32
2666 check_gc_signals_unblocked_or_lose(os_context_sigmask_addr(context));
2667 unblock_gc_signals(0, 0);
2669 FSHOW((stderr, "/maybe_gc: calling SUB_GC\n"));
2670 /* FIXME: Nothing must go wrong during GC else we end up running
2671 * the debugger, error handlers, and user code in general in a
2672 * potentially unsafe place. Running out of the control stack or
2673 * the heap in SUB-GC are ways to lose. Of course, deferrables
2674 * cannot be unblocked because there may be a pending handler, or
2675 * we may even be in a WITHOUT-INTERRUPTS. */
2676 gc_happened = funcall0(StaticSymbolFunction(SUB_GC));
2677 FSHOW((stderr, "/maybe_gc: gc_happened=%s\n",
2678 (gc_happened == NIL) ? "NIL" : "T"));
2679 if ((gc_happened != NIL) &&
2680 /* See if interrupts are enabled or it's possible to enable
2681 * them. POST-GC has a similar check, but we don't want to
2682 * unlock deferrables in that case and get a pending interrupt
2684 ((SymbolValue(INTERRUPTS_ENABLED,thread) != NIL) ||
2685 (SymbolValue(ALLOW_WITH_INTERRUPTS,thread) != NIL))) {
2686 #ifndef LISP_FEATURE_WIN32
2687 sigset_t *context_sigmask = os_context_sigmask_addr(context);
2688 if (!deferrables_blocked_p(context_sigmask)) {
2689 thread_sigmask(SIG_SETMASK, context_sigmask, 0);
2690 check_gc_signals_unblocked_or_lose(0);
2692 FSHOW((stderr, "/maybe_gc: calling POST_GC\n"));
2693 funcall0(StaticSymbolFunction(POST_GC));
2694 #ifndef LISP_FEATURE_WIN32
2696 FSHOW((stderr, "/maybe_gc: punting on POST_GC due to blockage\n"));
2700 undo_fake_foreign_function_call(context);
2701 FSHOW((stderr, "/maybe_gc: returning\n"));
2702 return (gc_happened != NIL);
2705 #define BYTES_ZERO_BEFORE_END (1<<12)
2707 /* There used to be a similar function called SCRUB-CONTROL-STACK in
2708 * Lisp and another called zero_stack() in cheneygc.c, but since it's
2709 * shorter to express in, and more often called from C, I keep only
2710 * the C one after fixing it. -- MG 2009-03-25 */
2712 /* Zero the unused portion of the control stack so that old objects
2713 * are not kept alive because of uninitialized stack variables.
2715 * "To summarize the problem, since not all allocated stack frame
2716 * slots are guaranteed to be written by the time you call an another
2717 * function or GC, there may be garbage pointers retained in your dead
2718 * stack locations. The stack scrubbing only affects the part of the
2719 * stack from the SP to the end of the allocated stack." - ram, on
2720 * cmucl-imp, Tue, 25 Sep 2001
2722 * So, as an (admittedly lame) workaround, from time to time we call
2723 * scrub-control-stack to zero out all the unused portion. This is
2724 * supposed to happen when the stack is mostly empty, so that we have
2725 * a chance of clearing more of it: callers are currently (2002.07.18)
2726 * REPL, SUB-GC and sig_stop_for_gc_handler. */
2728 /* Take care not to tread on the guard page and the hard guard page as
2729 * it would be unkind to sig_stop_for_gc_handler. Touching the return
2730 * guard page is not dangerous. For this to work the guard page must
2731 * be zeroed when protected. */
2733 /* FIXME: I think there is no guarantee that once
2734 * BYTES_ZERO_BEFORE_END bytes are zero the rest are also zero. This
2735 * may be what the "lame" adjective in the above comment is for. In
2736 * this case, exact gc may lose badly. */
2738 scrub_control_stack(void)
2740 struct thread *th = arch_os_get_current_thread();
2741 os_vm_address_t guard_page_address = CONTROL_STACK_GUARD_PAGE(th);
2742 os_vm_address_t hard_guard_page_address = CONTROL_STACK_HARD_GUARD_PAGE(th);
2743 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
2744 /* On these targets scrubbing from C is a bad idea, so we punt to
2745 * a routine in $ARCH-assem.S. */
2746 extern void arch_scrub_control_stack(struct thread *, os_vm_address_t, os_vm_address_t);
2747 arch_scrub_control_stack(th, guard_page_address, hard_guard_page_address);
2749 lispobj *sp = access_control_stack_pointer(th);
2751 if ((((os_vm_address_t)sp < (hard_guard_page_address + os_vm_page_size)) &&
2752 ((os_vm_address_t)sp >= hard_guard_page_address)) ||
2753 (((os_vm_address_t)sp < (guard_page_address + os_vm_page_size)) &&
2754 ((os_vm_address_t)sp >= guard_page_address) &&
2755 (th->control_stack_guard_page_protected != NIL)))
2757 #ifdef LISP_FEATURE_STACK_GROWS_DOWNWARD_NOT_UPWARD
2760 } while (((unsigned long)sp--) & (BYTES_ZERO_BEFORE_END - 1));
2761 if ((os_vm_address_t)sp < (hard_guard_page_address + os_vm_page_size))
2766 } while (((unsigned long)sp--) & (BYTES_ZERO_BEFORE_END - 1));
2770 } while (((unsigned long)++sp) & (BYTES_ZERO_BEFORE_END - 1));
2771 if ((os_vm_address_t)sp >= hard_guard_page_address)
2776 } while (((unsigned long)++sp) & (BYTES_ZERO_BEFORE_END - 1));
2778 #endif /* LISP_FEATURE_C_STACK_IS_CONTROL_STACK */
2781 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
2783 /* Scavenging Interrupt Contexts */
2785 static int boxed_registers[] = BOXED_REGISTERS;
2787 /* The GC has a notion of an "interior pointer" register, an unboxed
2788 * register that typically contains a pointer to inside an object
2789 * referenced by another pointer. The most obvious of these is the
2790 * program counter, although many compiler backends define a "Lisp
2791 * Interior Pointer" register known to the runtime as reg_LIP, and
2792 * various CPU architectures have other registers that also partake of
2793 * the interior-pointer nature. As the code for pairing an interior
2794 * pointer value up with its "base" register, and fixing it up after
2795 * scavenging is complete is horribly repetitive, a few macros paper
2796 * over the monotony. --AB, 2010-Jul-14 */
2798 /* These macros are only ever used over a lexical environment which
2799 * defines a pointer to an os_context_t called context, thus we don't
2800 * bother to pass that context in as a parameter. */
2802 /* Define how to access a given interior pointer. */
2803 #define ACCESS_INTERIOR_POINTER_pc \
2804 *os_context_pc_addr(context)
2805 #define ACCESS_INTERIOR_POINTER_lip \
2806 *os_context_register_addr(context, reg_LIP)
2807 #define ACCESS_INTERIOR_POINTER_lr \
2808 *os_context_lr_addr(context)
2809 #define ACCESS_INTERIOR_POINTER_npc \
2810 *os_context_npc_addr(context)
2811 #define ACCESS_INTERIOR_POINTER_ctr \
2812 *os_context_ctr_addr(context)
2814 #define INTERIOR_POINTER_VARS(name) \
2815 unsigned long name##_offset; \
2816 int name##_register_pair
2818 #define PAIR_INTERIOR_POINTER(name) \
2819 pair_interior_pointer(context, \
2820 ACCESS_INTERIOR_POINTER_##name, \
2822 &name##_register_pair)
2824 /* One complexity here is that if a paired register is not found for
2825 * an interior pointer, then that pointer does not get updated.
2826 * Originally, there was some commentary about using an index of -1
2827 * when calling os_context_register_addr() on SPARC referring to the
2828 * program counter, but the real reason is to allow an interior
2829 * pointer register to point to the runtime, read-only space, or
2830 * static space without problems. */
2831 #define FIXUP_INTERIOR_POINTER(name) \
2833 if (name##_register_pair >= 0) { \
2834 ACCESS_INTERIOR_POINTER_##name = \
2835 (*os_context_register_addr(context, \
2836 name##_register_pair) \
2844 pair_interior_pointer(os_context_t *context, unsigned long pointer,
2845 unsigned long *saved_offset, int *register_pair)
2850 * I (RLT) think this is trying to find the boxed register that is
2851 * closest to the LIP address, without going past it. Usually, it's
2852 * reg_CODE or reg_LRA. But sometimes, nothing can be found.
2854 /* 0x7FFFFFFF on 32-bit platforms;
2855 0x7FFFFFFFFFFFFFFF on 64-bit platforms */
2856 *saved_offset = (((unsigned long)1) << (N_WORD_BITS - 1)) - 1;
2857 *register_pair = -1;
2858 for (i = 0; i < (sizeof(boxed_registers) / sizeof(int)); i++) {
2863 index = boxed_registers[i];
2864 reg = *os_context_register_addr(context, index);
2866 /* An interior pointer is never relative to a non-pointer
2867 * register (an oversight in the original implementation).
2868 * The simplest argument for why this is true is to consider
2869 * the fixnum that happens by coincide to be the word-index in
2870 * memory of the header for some object plus two. This is
2871 * happenstance would cause the register containing the fixnum
2872 * to be selected as the register_pair if the interior pointer
2873 * is to anywhere after the first two words of the object.
2874 * The fixnum won't be changed during GC, but the object might
2875 * move, thus destroying the interior pointer. --AB,
2878 if (is_lisp_pointer(reg) &&
2879 ((reg & ~LOWTAG_MASK) <= pointer)) {
2880 offset = pointer - (reg & ~LOWTAG_MASK);
2881 if (offset < *saved_offset) {
2882 *saved_offset = offset;
2883 *register_pair = index;
2890 scavenge_interrupt_context(os_context_t * context)
2894 /* FIXME: The various #ifdef noise here is precisely that: noise.
2895 * Is it possible to fold it into the macrology so that we have
2896 * one set of #ifdefs and then INTERIOR_POINTER_VARS /et alia/
2897 * compile out for the registers that don't exist on a given
2900 INTERIOR_POINTER_VARS(pc);
2902 INTERIOR_POINTER_VARS(lip);
2904 #ifdef ARCH_HAS_LINK_REGISTER
2905 INTERIOR_POINTER_VARS(lr);
2907 #ifdef ARCH_HAS_NPC_REGISTER
2908 INTERIOR_POINTER_VARS(npc);
2910 #ifdef LISP_FEATURE_PPC
2911 INTERIOR_POINTER_VARS(ctr);
2914 PAIR_INTERIOR_POINTER(pc);
2916 PAIR_INTERIOR_POINTER(lip);
2918 #ifdef ARCH_HAS_LINK_REGISTER
2919 PAIR_INTERIOR_POINTER(lr);
2921 #ifdef ARCH_HAS_NPC_REGISTER
2922 PAIR_INTERIOR_POINTER(npc);
2924 #ifdef LISP_FEATURE_PPC
2925 PAIR_INTERIOR_POINTER(ctr);
2928 /* Scavenge all boxed registers in the context. */
2929 for (i = 0; i < (sizeof(boxed_registers) / sizeof(int)); i++) {
2933 index = boxed_registers[i];
2934 foo = *os_context_register_addr(context, index);
2936 *os_context_register_addr(context, index) = foo;
2938 /* this is unlikely to work as intended on bigendian
2939 * 64 bit platforms */
2941 scavenge((lispobj *) os_context_register_addr(context, index), 1);
2944 /* Now that the scavenging is done, repair the various interior
2946 FIXUP_INTERIOR_POINTER(pc);
2948 FIXUP_INTERIOR_POINTER(lip);
2950 #ifdef ARCH_HAS_LINK_REGISTER
2951 FIXUP_INTERIOR_POINTER(lr);
2953 #ifdef ARCH_HAS_NPC_REGISTER
2954 FIXUP_INTERIOR_POINTER(npc);
2956 #ifdef LISP_FEATURE_PPC
2957 FIXUP_INTERIOR_POINTER(ctr);
2962 scavenge_interrupt_contexts(struct thread *th)
2965 os_context_t *context;
2967 index = fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,th));
2969 #if defined(DEBUG_PRINT_CONTEXT_INDEX)
2970 printf("Number of active contexts: %d\n", index);
2973 for (i = 0; i < index; i++) {
2974 context = th->interrupt_contexts[i];
2975 scavenge_interrupt_context(context);
2978 #endif /* x86oid targets */