0.9.4.53:
[sbcl.git] / src / runtime / gc-common.c
1 /*
2  * Garbage Collection common functions for scavenging, moving and sizing
3  * objects.  These are for use with both GC (stop & copy GC) and GENCGC
4  */
5
6 /*
7  * This software is part of the SBCL system. See the README file for
8  * more information.
9  *
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.
15  */
16
17 /*
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>
24  * as
25  *   <ftp://ftp.cs.utexas.edu/pub/garbage/bigsurv.ps>.
26  */
27
28 #include <stdio.h>
29 #include <signal.h>
30 #include <string.h>
31 #include "sbcl.h"
32 #include "runtime.h"
33 #include "os.h"
34 #include "interr.h"
35 #include "globals.h"
36 #include "interrupt.h"
37 #include "validate.h"
38 #include "lispregs.h"
39 #include "arch.h"
40 #include "fixnump.h"
41 #include "gc.h"
42 #include "genesis/primitive-objects.h"
43 #include "genesis/static-symbols.h"
44 #include "genesis/layout.h"
45 #include "gc-internal.h"
46
47 #ifdef LISP_FEATURE_SPARC
48 #define LONG_FLOAT_SIZE 4
49 #else
50 #ifdef LISP_FEATURE_X86
51 #define LONG_FLOAT_SIZE 3
52 #endif
53 #endif
54
55 inline static boolean
56 forwarding_pointer_p(lispobj *pointer) {
57     lispobj first_word=*pointer;
58 #ifdef LISP_FEATURE_GENCGC
59     return (first_word == 0x01);
60 #else
61     return (is_lisp_pointer(first_word)
62             && new_space_p(first_word));
63 #endif
64 }
65
66 static inline lispobj *
67 forwarding_pointer_value(lispobj *pointer) {
68 #ifdef LISP_FEATURE_GENCGC
69     return (lispobj *) ((pointer_sized_uint_t) pointer[1]);
70 #else
71     return (lispobj *) ((pointer_sized_uint_t) pointer[0]);
72 #endif
73 }
74 static inline lispobj
75 set_forwarding_pointer(lispobj * pointer, lispobj newspace_copy) {
76 #ifdef LISP_FEATURE_GENCGC
77     pointer[0]=0x01;
78     pointer[1]=newspace_copy;
79 #else
80     pointer[0]=newspace_copy;
81 #endif
82     return newspace_copy;
83 }
84
85 long (*scavtab[256])(lispobj *where, lispobj object);
86 lispobj (*transother[256])(lispobj object);
87 long (*sizetab[256])(lispobj *where);
88 struct weak_pointer *weak_pointers;
89
90 unsigned long bytes_consed_between_gcs = 12*1024*1024;
91
92
93 /*
94  * copying objects
95  */
96
97 /* to copy a boxed object */
98 lispobj
99 copy_object(lispobj object, long nwords)
100 {
101     int tag;
102     lispobj *new;
103
104     gc_assert(is_lisp_pointer(object));
105     gc_assert(from_space_p(object));
106     gc_assert((nwords & 0x01) == 0);
107
108     /* Get tag of object. */
109     tag = lowtag_of(object);
110
111     /* Allocate space. */
112     new = gc_general_alloc(nwords*N_WORD_BYTES,ALLOC_BOXED,ALLOC_QUICK);
113
114     /* Copy the object. */
115     memcpy(new,native_pointer(object),nwords*N_WORD_BYTES);
116     return make_lispobj(new,tag);
117 }
118
119 static long scav_lose(lispobj *where, lispobj object); /* forward decl */
120
121 /* FIXME: Most calls end up going to some trouble to compute an
122  * 'n_words' value for this function. The system might be a little
123  * simpler if this function used an 'end' parameter instead. */
124 void
125 scavenge(lispobj *start, long n_words)
126 {
127     lispobj *end = start + n_words;
128     lispobj *object_ptr;
129     long n_words_scavenged;
130     for (object_ptr = start;
131
132          object_ptr < end;
133          object_ptr += n_words_scavenged) {
134
135         lispobj object = *object_ptr;
136 #ifdef LISP_FEATURE_GENCGC
137         gc_assert(!forwarding_pointer_p(object_ptr));
138 #endif
139         if (is_lisp_pointer(object)) {
140             if (from_space_p(object)) {
141                 /* It currently points to old space. Check for a
142                  * forwarding pointer. */
143                 lispobj *ptr = native_pointer(object);
144                 if (forwarding_pointer_p(ptr)) {
145                     /* Yes, there's a forwarding pointer. */
146                     *object_ptr = LOW_WORD(forwarding_pointer_value(ptr));
147                     n_words_scavenged = 1;
148                 } else {
149                     /* Scavenge that pointer. */
150                     n_words_scavenged =
151                         (scavtab[widetag_of(object)])(object_ptr, object);
152                 }
153             } else {
154                 /* It points somewhere other than oldspace. Leave it
155                  * alone. */
156                 n_words_scavenged = 1;
157             }
158         }
159 #ifndef LISP_FEATURE_GENCGC
160         /* this workaround is probably not necessary for gencgc; at least, the
161          * behaviour it describes has never been reported */
162         else if (n_words==1) {
163             /* there are some situations where an
164                other-immediate may end up in a descriptor
165                register.  I'm not sure whether this is
166                supposed to happen, but if it does then we
167                don't want to (a) barf or (b) scavenge over the
168                data-block, because there isn't one.  So, if
169                we're checking a single word and it's anything
170                other than a pointer, just hush it up */
171             int type=widetag_of(object);
172             n_words_scavenged=1;
173
174             if ((scavtab[type]==scav_lose) ||
175                 (((scavtab[type])(start,object))>1)) {
176                 fprintf(stderr,"warning: attempted to scavenge non-descriptor value %x at %p.  If you can\nreproduce this warning, send a bug report (see manual page for details)\n",
177                         object,start);
178             }
179         }
180 #endif
181         else if (fixnump(object)) {
182             /* It's a fixnum: really easy.. */
183             n_words_scavenged = 1;
184         } else {
185             /* It's some sort of header object or another. */
186             n_words_scavenged =
187                 (scavtab[widetag_of(object)])(object_ptr, object);
188         }
189     }
190     gc_assert(object_ptr == end);
191 }
192
193 static lispobj trans_fun_header(lispobj object); /* forward decls */
194 static lispobj trans_boxed(lispobj object);
195
196 static long
197 scav_fun_pointer(lispobj *where, lispobj object)
198 {
199     lispobj *first_pointer;
200     lispobj copy;
201
202     gc_assert(is_lisp_pointer(object));
203
204     /* Object is a pointer into from_space - not a FP. */
205     first_pointer = (lispobj *) native_pointer(object);
206
207     /* must transport object -- object may point to either a function
208      * header, a closure function header, or to a closure header. */
209
210     switch (widetag_of(*first_pointer)) {
211     case SIMPLE_FUN_HEADER_WIDETAG:
212         copy = trans_fun_header(object);
213         break;
214     default:
215         copy = trans_boxed(object);
216         break;
217     }
218
219     if (copy != object) {
220         /* Set forwarding pointer */
221         set_forwarding_pointer(first_pointer,copy);
222     }
223
224     gc_assert(is_lisp_pointer(copy));
225     gc_assert(!from_space_p(copy));
226
227     *where = copy;
228
229     return 1;
230 }
231
232
233 static struct code *
234 trans_code(struct code *code)
235 {
236     struct code *new_code;
237     lispobj first, l_code, l_new_code;
238     long nheader_words, ncode_words, nwords;
239     unsigned long displacement;
240     lispobj fheaderl, *prev_pointer;
241
242     /* if object has already been transported, just return pointer */
243     first = code->header;
244     if (forwarding_pointer_p((lispobj *)code)) {
245 #ifdef DEBUG_CODE_GC
246         printf("Was already transported\n");
247 #endif
248         return (struct code *) forwarding_pointer_value
249             ((lispobj *)((pointer_sized_uint_t) code));
250     }
251
252     gc_assert(widetag_of(first) == CODE_HEADER_WIDETAG);
253
254     /* prepare to transport the code vector */
255     l_code = (lispobj) LOW_WORD(code) | OTHER_POINTER_LOWTAG;
256
257     ncode_words = fixnum_value(code->code_size);
258     nheader_words = HeaderValue(code->header);
259     nwords = ncode_words + nheader_words;
260     nwords = CEILING(nwords, 2);
261
262     l_new_code = copy_object(l_code, nwords);
263     new_code = (struct code *) native_pointer(l_new_code);
264
265 #if defined(DEBUG_CODE_GC)
266     printf("Old code object at 0x%08x, new code object at 0x%08x.\n",
267            (unsigned long) code, (unsigned long) new_code);
268     printf("Code object is %d words long.\n", nwords);
269 #endif
270
271 #ifdef LISP_FEATURE_GENCGC
272     if (new_code == code)
273         return new_code;
274 #endif
275
276     displacement = l_new_code - l_code;
277
278     set_forwarding_pointer((lispobj *)code, l_new_code);
279
280     /* set forwarding pointers for all the function headers in the */
281     /* code object.  also fix all self pointers */
282
283     fheaderl = code->entry_points;
284     prev_pointer = &new_code->entry_points;
285
286     while (fheaderl != NIL) {
287         struct simple_fun *fheaderp, *nfheaderp;
288         lispobj nfheaderl;
289
290         fheaderp = (struct simple_fun *) native_pointer(fheaderl);
291         gc_assert(widetag_of(fheaderp->header) == SIMPLE_FUN_HEADER_WIDETAG);
292
293         /* Calculate the new function pointer and the new */
294         /* function header. */
295         nfheaderl = fheaderl + displacement;
296         nfheaderp = (struct simple_fun *) native_pointer(nfheaderl);
297
298 #ifdef DEBUG_CODE_GC
299         printf("fheaderp->header (at %x) <- %x\n",
300                &(fheaderp->header) , nfheaderl);
301 #endif
302         set_forwarding_pointer((lispobj *)fheaderp, nfheaderl);
303
304         /* fix self pointer. */
305         nfheaderp->self =
306 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
307             FUN_RAW_ADDR_OFFSET +
308 #endif
309             nfheaderl;
310
311         *prev_pointer = nfheaderl;
312
313         fheaderl = fheaderp->next;
314         prev_pointer = &nfheaderp->next;
315     }
316     os_flush_icache((os_vm_address_t) (((long *)new_code) + nheader_words),
317                     ncode_words * sizeof(long));
318 #ifdef LISP_FEATURE_GENCGC
319     gencgc_apply_code_fixups(code, new_code);
320 #endif
321     return new_code;
322 }
323
324 static long
325 scav_code_header(lispobj *where, lispobj object)
326 {
327     struct code *code;
328     long n_header_words, n_code_words, n_words;
329     lispobj entry_point;        /* tagged pointer to entry point */
330     struct simple_fun *function_ptr; /* untagged pointer to entry point */
331
332     code = (struct code *) where;
333     n_code_words = fixnum_value(code->code_size);
334     n_header_words = HeaderValue(object);
335     n_words = n_code_words + n_header_words;
336     n_words = CEILING(n_words, 2);
337
338     /* Scavenge the boxed section of the code data block. */
339     scavenge(where + 1, n_header_words - 1);
340
341     /* Scavenge the boxed section of each function object in the
342      * code data block. */
343     for (entry_point = code->entry_points;
344          entry_point != NIL;
345          entry_point = function_ptr->next) {
346
347         gc_assert(is_lisp_pointer(entry_point));
348
349         function_ptr = (struct simple_fun *) native_pointer(entry_point);
350         gc_assert(widetag_of(function_ptr->header)==SIMPLE_FUN_HEADER_WIDETAG);
351
352         scavenge(&function_ptr->name, 1);
353         scavenge(&function_ptr->arglist, 1);
354         scavenge(&function_ptr->type, 1);
355     }
356
357     return n_words;
358 }
359
360 static lispobj
361 trans_code_header(lispobj object)
362 {
363     struct code *ncode;
364
365     ncode = trans_code((struct code *) native_pointer(object));
366     return (lispobj) LOW_WORD(ncode) | OTHER_POINTER_LOWTAG;
367 }
368
369
370 static long
371 size_code_header(lispobj *where)
372 {
373     struct code *code;
374     long nheader_words, ncode_words, nwords;
375
376     code = (struct code *) where;
377
378     ncode_words = fixnum_value(code->code_size);
379     nheader_words = HeaderValue(code->header);
380     nwords = ncode_words + nheader_words;
381     nwords = CEILING(nwords, 2);
382
383     return nwords;
384 }
385
386 #if !defined(LISP_FEATURE_X86) && ! defined(LISP_FEATURE_X86_64)
387 static long
388 scav_return_pc_header(lispobj *where, lispobj object)
389 {
390     lose("attempted to scavenge a return PC header where=0x%08x object=0x%08x",
391          (unsigned long) where,
392          (unsigned long) object);
393     return 0; /* bogus return value to satisfy static type checking */
394 }
395 #endif /* LISP_FEATURE_X86 */
396
397 static lispobj
398 trans_return_pc_header(lispobj object)
399 {
400     struct simple_fun *return_pc;
401     unsigned long offset;
402     struct code *code, *ncode;
403
404     return_pc = (struct simple_fun *) native_pointer(object);
405     /* FIXME: was times 4, should it really be N_WORD_BYTES? */
406     offset = HeaderValue(return_pc->header) * N_WORD_BYTES;
407
408     /* Transport the whole code object */
409     code = (struct code *) ((unsigned long) return_pc - offset);
410     ncode = trans_code(code);
411
412     return ((lispobj) LOW_WORD(ncode) + offset) | OTHER_POINTER_LOWTAG;
413 }
414
415 /* On the 386, closures hold a pointer to the raw address instead of the
416  * function object, so we can use CALL [$FDEFN+const] to invoke
417  * the function without loading it into a register. Given that code
418  * objects don't move, we don't need to update anything, but we do
419  * have to figure out that the function is still live. */
420
421 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
422 static long
423 scav_closure_header(lispobj *where, lispobj object)
424 {
425     struct closure *closure;
426     lispobj fun;
427
428     closure = (struct closure *)where;
429     fun = closure->fun - FUN_RAW_ADDR_OFFSET;
430     scavenge(&fun, 1);
431 #ifdef LISP_FEATURE_GENCGC
432     /* The function may have moved so update the raw address. But
433      * don't write unnecessarily. */
434     if (closure->fun != fun + FUN_RAW_ADDR_OFFSET)
435         closure->fun = fun + FUN_RAW_ADDR_OFFSET;
436 #endif
437     return 2;
438 }
439 #endif
440
441 #if !(defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
442 static long
443 scav_fun_header(lispobj *where, lispobj object)
444 {
445     lose("attempted to scavenge a function header where=0x%08x object=0x%08x",
446          (unsigned long) where,
447          (unsigned long) object);
448     return 0; /* bogus return value to satisfy static type checking */
449 }
450 #endif /* LISP_FEATURE_X86 */
451
452 static lispobj
453 trans_fun_header(lispobj object)
454 {
455     struct simple_fun *fheader;
456     unsigned long offset;
457     struct code *code, *ncode;
458
459     fheader = (struct simple_fun *) native_pointer(object);
460     /* FIXME: was times 4, should it really be N_WORD_BYTES? */
461     offset = HeaderValue(fheader->header) * N_WORD_BYTES;
462
463     /* Transport the whole code object */
464     code = (struct code *) ((unsigned long) fheader - offset);
465     ncode = trans_code(code);
466
467     return ((lispobj) LOW_WORD(ncode) + offset) | FUN_POINTER_LOWTAG;
468 }
469
470 \f
471 /*
472  * instances
473  */
474
475 static long
476 scav_instance_pointer(lispobj *where, lispobj object)
477 {
478     lispobj copy, *first_pointer;
479
480     /* Object is a pointer into from space - not a FP. */
481     copy = trans_boxed(object);
482
483 #ifdef LISP_FEATURE_GENCGC
484     gc_assert(copy != object);
485 #endif
486
487     first_pointer = (lispobj *) native_pointer(object);
488     set_forwarding_pointer(first_pointer,copy);
489     *where = copy;
490
491     return 1;
492 }
493
494 \f
495 /*
496  * lists and conses
497  */
498
499 static lispobj trans_list(lispobj object);
500
501 static long
502 scav_list_pointer(lispobj *where, lispobj object)
503 {
504     lispobj first, *first_pointer;
505
506     gc_assert(is_lisp_pointer(object));
507
508     /* Object is a pointer into from space - not FP. */
509     first_pointer = (lispobj *) native_pointer(object);
510
511     first = trans_list(object);
512     gc_assert(first != object);
513
514     /* Set forwarding pointer */
515     set_forwarding_pointer(first_pointer, first);
516
517     gc_assert(is_lisp_pointer(first));
518     gc_assert(!from_space_p(first));
519
520     *where = first;
521     return 1;
522 }
523
524
525 static lispobj
526 trans_list(lispobj object)
527 {
528     lispobj new_list_pointer;
529     struct cons *cons, *new_cons;
530     lispobj cdr;
531
532     cons = (struct cons *) native_pointer(object);
533
534     /* Copy 'object'. */
535     new_cons = (struct cons *)
536         gc_general_alloc(sizeof(struct cons),ALLOC_BOXED,ALLOC_QUICK);
537     new_cons->car = cons->car;
538     new_cons->cdr = cons->cdr; /* updated later */
539     new_list_pointer = make_lispobj(new_cons,lowtag_of(object));
540
541     /* Grab the cdr: set_forwarding_pointer will clobber it in GENCGC  */
542     cdr = cons->cdr;
543
544     set_forwarding_pointer((lispobj *)cons, new_list_pointer);
545
546     /* Try to linearize the list in the cdr direction to help reduce
547      * paging. */
548     while (1) {
549         lispobj  new_cdr;
550         struct cons *cdr_cons, *new_cdr_cons;
551
552         if(lowtag_of(cdr) != LIST_POINTER_LOWTAG ||
553            !from_space_p(cdr) ||
554            forwarding_pointer_p((lispobj *)native_pointer(cdr)))
555             break;
556
557         cdr_cons = (struct cons *) native_pointer(cdr);
558
559         /* Copy 'cdr'. */
560         new_cdr_cons = (struct cons*)
561             gc_general_alloc(sizeof(struct cons),ALLOC_BOXED,ALLOC_QUICK);
562         new_cdr_cons->car = cdr_cons->car;
563         new_cdr_cons->cdr = cdr_cons->cdr;
564         new_cdr = make_lispobj(new_cdr_cons, lowtag_of(cdr));
565
566         /* Grab the cdr before it is clobbered. */
567         cdr = cdr_cons->cdr;
568         set_forwarding_pointer((lispobj *)cdr_cons, new_cdr);
569
570         /* Update the cdr of the last cons copied into new space to
571          * keep the newspace scavenge from having to do it. */
572         new_cons->cdr = new_cdr;
573
574         new_cons = new_cdr_cons;
575     }
576
577     return new_list_pointer;
578 }
579
580 \f
581 /*
582  * scavenging and transporting other pointers
583  */
584
585 static long
586 scav_other_pointer(lispobj *where, lispobj object)
587 {
588     lispobj first, *first_pointer;
589
590     gc_assert(is_lisp_pointer(object));
591
592     /* Object is a pointer into from space - not FP. */
593     first_pointer = (lispobj *) native_pointer(object);
594     first = (transother[widetag_of(*first_pointer)])(object);
595
596     if (first != object) {
597         set_forwarding_pointer(first_pointer, first);
598 #ifdef LISP_FEATURE_GENCGC
599         *where = first;
600 #endif
601     }
602 #ifndef LISP_FEATURE_GENCGC
603     *where = first;
604 #endif
605     gc_assert(is_lisp_pointer(first));
606     gc_assert(!from_space_p(first));
607
608     return 1;
609 }
610 \f
611 /*
612  * immediate, boxed, and unboxed objects
613  */
614
615 static long
616 size_pointer(lispobj *where)
617 {
618     return 1;
619 }
620
621 static long
622 scav_immediate(lispobj *where, lispobj object)
623 {
624     return 1;
625 }
626
627 static lispobj
628 trans_immediate(lispobj object)
629 {
630     lose("trying to transport an immediate");
631     return NIL; /* bogus return value to satisfy static type checking */
632 }
633
634 static long
635 size_immediate(lispobj *where)
636 {
637     return 1;
638 }
639
640
641 static long
642 scav_boxed(lispobj *where, lispobj object)
643 {
644     return 1;
645 }
646
647 static long
648 scav_instance(lispobj *where, lispobj object)
649 {
650     lispobj nuntagged;
651     long ntotal = HeaderValue(object);
652     lispobj layout = ((struct instance *)where)->slots[0];
653
654     if (!layout)
655         return 1;
656     if (forwarding_pointer_p(native_pointer(layout)))
657         layout = (lispobj) forwarding_pointer_value(native_pointer(layout));
658
659     nuntagged = ((struct layout *)native_pointer(layout))->n_untagged_slots;
660     scavenge(where + 1, ntotal - fixnum_value(nuntagged));
661
662     return ntotal + 1;
663 }
664
665 static lispobj
666 trans_boxed(lispobj object)
667 {
668     lispobj header;
669     unsigned long length;
670
671     gc_assert(is_lisp_pointer(object));
672
673     header = *((lispobj *) native_pointer(object));
674     length = HeaderValue(header) + 1;
675     length = CEILING(length, 2);
676
677     return copy_object(object, length);
678 }
679
680
681 static long
682 size_boxed(lispobj *where)
683 {
684     lispobj header;
685     unsigned long length;
686
687     header = *where;
688     length = HeaderValue(header) + 1;
689     length = CEILING(length, 2);
690
691     return length;
692 }
693
694 /* Note: on the sparc we don't have to do anything special for fdefns, */
695 /* 'cause the raw-addr has a function lowtag. */
696 #ifndef LISP_FEATURE_SPARC
697 static long
698 scav_fdefn(lispobj *where, lispobj object)
699 {
700     struct fdefn *fdefn;
701
702     fdefn = (struct fdefn *)where;
703
704     /* FSHOW((stderr, "scav_fdefn, function = %p, raw_addr = %p\n",
705        fdefn->fun, fdefn->raw_addr)); */
706
707     if ((char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET)
708         == (char *)((unsigned long)(fdefn->raw_addr))) {
709         scavenge(where + 1, sizeof(struct fdefn)/sizeof(lispobj) - 1);
710
711         /* Don't write unnecessarily. */
712         if (fdefn->raw_addr != (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET))
713             fdefn->raw_addr = (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET);
714         /* gc.c has more casts here, which may be relevant or alternatively
715            may be compiler warning defeaters.  try
716         fdefn->raw_addr = ((char *) LOW_WORD(fdefn->fun)) + FUN_RAW_ADDR_OFFSET;
717         */
718         return sizeof(struct fdefn) / sizeof(lispobj);
719     } else {
720         return 1;
721     }
722 }
723 #endif
724
725 static long
726 scav_unboxed(lispobj *where, lispobj object)
727 {
728     unsigned long length;
729
730     length = HeaderValue(object) + 1;
731     length = CEILING(length, 2);
732
733     return length;
734 }
735
736 static lispobj
737 trans_unboxed(lispobj object)
738 {
739     lispobj header;
740     unsigned long length;
741
742
743     gc_assert(is_lisp_pointer(object));
744
745     header = *((lispobj *) native_pointer(object));
746     length = HeaderValue(header) + 1;
747     length = CEILING(length, 2);
748
749     return copy_unboxed_object(object, length);
750 }
751
752 static long
753 size_unboxed(lispobj *where)
754 {
755     lispobj header;
756     unsigned long length;
757
758     header = *where;
759     length = HeaderValue(header) + 1;
760     length = CEILING(length, 2);
761
762     return length;
763 }
764
765 \f
766 /* vector-like objects */
767 static long
768 scav_base_string(lispobj *where, lispobj object)
769 {
770     struct vector *vector;
771     long length, nwords;
772
773     /* NOTE: Strings contain one more byte of data than the length */
774     /* slot indicates. */
775
776     vector = (struct vector *) where;
777     length = fixnum_value(vector->length) + 1;
778     nwords = CEILING(NWORDS(length, 8) + 2, 2);
779
780     return nwords;
781 }
782 static lispobj
783 trans_base_string(lispobj object)
784 {
785     struct vector *vector;
786     long length, nwords;
787
788     gc_assert(is_lisp_pointer(object));
789
790     /* NOTE: A string contains one more byte of data (a terminating
791      * '\0' to help when interfacing with C functions) than indicated
792      * by the length slot. */
793
794     vector = (struct vector *) native_pointer(object);
795     length = fixnum_value(vector->length) + 1;
796     nwords = CEILING(NWORDS(length, 8) + 2, 2);
797
798     return copy_large_unboxed_object(object, nwords);
799 }
800
801 static long
802 size_base_string(lispobj *where)
803 {
804     struct vector *vector;
805     long length, nwords;
806
807     /* NOTE: A string contains one more byte of data (a terminating
808      * '\0' to help when interfacing with C functions) than indicated
809      * by the length slot. */
810
811     vector = (struct vector *) where;
812     length = fixnum_value(vector->length) + 1;
813     nwords = CEILING(NWORDS(length, 8) + 2, 2);
814
815     return nwords;
816 }
817
818 static long
819 scav_character_string(lispobj *where, lispobj object)
820 {
821     struct vector *vector;
822     int length, nwords;
823
824     /* NOTE: Strings contain one more byte of data than the length */
825     /* slot indicates. */
826
827     vector = (struct vector *) where;
828     length = fixnum_value(vector->length) + 1;
829     nwords = CEILING(NWORDS(length, 32) + 2, 2);
830
831     return nwords;
832 }
833 static lispobj
834 trans_character_string(lispobj object)
835 {
836     struct vector *vector;
837     int length, nwords;
838
839     gc_assert(is_lisp_pointer(object));
840
841     /* NOTE: A string contains one more byte of data (a terminating
842      * '\0' to help when interfacing with C functions) than indicated
843      * by the length slot. */
844
845     vector = (struct vector *) native_pointer(object);
846     length = fixnum_value(vector->length) + 1;
847     nwords = CEILING(NWORDS(length, 32) + 2, 2);
848
849     return copy_large_unboxed_object(object, nwords);
850 }
851
852 static long
853 size_character_string(lispobj *where)
854 {
855     struct vector *vector;
856     int length, nwords;
857
858     /* NOTE: A string contains one more byte of data (a terminating
859      * '\0' to help when interfacing with C functions) than indicated
860      * by the length slot. */
861
862     vector = (struct vector *) where;
863     length = fixnum_value(vector->length) + 1;
864     nwords = CEILING(NWORDS(length, 32) + 2, 2);
865
866     return nwords;
867 }
868
869 static lispobj
870 trans_vector(lispobj object)
871 {
872     struct vector *vector;
873     long length, nwords;
874
875     gc_assert(is_lisp_pointer(object));
876
877     vector = (struct vector *) native_pointer(object);
878
879     length = fixnum_value(vector->length);
880     nwords = CEILING(length + 2, 2);
881
882     return copy_large_object(object, nwords);
883 }
884
885 static long
886 size_vector(lispobj *where)
887 {
888     struct vector *vector;
889     long length, nwords;
890
891     vector = (struct vector *) where;
892     length = fixnum_value(vector->length);
893     nwords = CEILING(length + 2, 2);
894
895     return nwords;
896 }
897
898 static long
899 scav_vector_nil(lispobj *where, lispobj object)
900 {
901     return 2;
902 }
903
904 static lispobj
905 trans_vector_nil(lispobj object)
906 {
907     gc_assert(is_lisp_pointer(object));
908     return copy_unboxed_object(object, 2);
909 }
910
911 static long
912 size_vector_nil(lispobj *where)
913 {
914     /* Just the header word and the length word */
915     return 2;
916 }
917
918 static long
919 scav_vector_bit(lispobj *where, lispobj object)
920 {
921     struct vector *vector;
922     long length, nwords;
923
924     vector = (struct vector *) where;
925     length = fixnum_value(vector->length);
926     nwords = CEILING(NWORDS(length, 1) + 2, 2);
927
928     return nwords;
929 }
930
931 static lispobj
932 trans_vector_bit(lispobj object)
933 {
934     struct vector *vector;
935     long length, nwords;
936
937     gc_assert(is_lisp_pointer(object));
938
939     vector = (struct vector *) native_pointer(object);
940     length = fixnum_value(vector->length);
941     nwords = CEILING(NWORDS(length, 1) + 2, 2);
942
943     return copy_large_unboxed_object(object, nwords);
944 }
945
946 static long
947 size_vector_bit(lispobj *where)
948 {
949     struct vector *vector;
950     long length, nwords;
951
952     vector = (struct vector *) where;
953     length = fixnum_value(vector->length);
954     nwords = CEILING(NWORDS(length, 1) + 2, 2);
955
956     return nwords;
957 }
958
959 static long
960 scav_vector_unsigned_byte_2(lispobj *where, lispobj object)
961 {
962     struct vector *vector;
963     long length, nwords;
964
965     vector = (struct vector *) where;
966     length = fixnum_value(vector->length);
967     nwords = CEILING(NWORDS(length, 2) + 2, 2);
968
969     return nwords;
970 }
971
972 static lispobj
973 trans_vector_unsigned_byte_2(lispobj object)
974 {
975     struct vector *vector;
976     long length, nwords;
977
978     gc_assert(is_lisp_pointer(object));
979
980     vector = (struct vector *) native_pointer(object);
981     length = fixnum_value(vector->length);
982     nwords = CEILING(NWORDS(length, 2) + 2, 2);
983
984     return copy_large_unboxed_object(object, nwords);
985 }
986
987 static long
988 size_vector_unsigned_byte_2(lispobj *where)
989 {
990     struct vector *vector;
991     long length, nwords;
992
993     vector = (struct vector *) where;
994     length = fixnum_value(vector->length);
995     nwords = CEILING(NWORDS(length, 2) + 2, 2);
996
997     return nwords;
998 }
999
1000 static long
1001 scav_vector_unsigned_byte_4(lispobj *where, lispobj object)
1002 {
1003     struct vector *vector;
1004     long length, nwords;
1005
1006     vector = (struct vector *) where;
1007     length = fixnum_value(vector->length);
1008     nwords = CEILING(NWORDS(length, 4) + 2, 2);
1009
1010     return nwords;
1011 }
1012
1013 static lispobj
1014 trans_vector_unsigned_byte_4(lispobj object)
1015 {
1016     struct vector *vector;
1017     long length, nwords;
1018
1019     gc_assert(is_lisp_pointer(object));
1020
1021     vector = (struct vector *) native_pointer(object);
1022     length = fixnum_value(vector->length);
1023     nwords = CEILING(NWORDS(length, 4) + 2, 2);
1024
1025     return copy_large_unboxed_object(object, nwords);
1026 }
1027 static long
1028 size_vector_unsigned_byte_4(lispobj *where)
1029 {
1030     struct vector *vector;
1031     long length, nwords;
1032
1033     vector = (struct vector *) where;
1034     length = fixnum_value(vector->length);
1035     nwords = CEILING(NWORDS(length, 4) + 2, 2);
1036
1037     return nwords;
1038 }
1039
1040
1041 static long
1042 scav_vector_unsigned_byte_8(lispobj *where, lispobj object)
1043 {
1044     struct vector *vector;
1045     long length, nwords;
1046
1047     vector = (struct vector *) where;
1048     length = fixnum_value(vector->length);
1049     nwords = CEILING(NWORDS(length, 8) + 2, 2);
1050
1051     return nwords;
1052 }
1053
1054 /*********************/
1055
1056
1057
1058 static lispobj
1059 trans_vector_unsigned_byte_8(lispobj object)
1060 {
1061     struct vector *vector;
1062     long length, nwords;
1063
1064     gc_assert(is_lisp_pointer(object));
1065
1066     vector = (struct vector *) native_pointer(object);
1067     length = fixnum_value(vector->length);
1068     nwords = CEILING(NWORDS(length, 8) + 2, 2);
1069
1070     return copy_large_unboxed_object(object, nwords);
1071 }
1072
1073 static long
1074 size_vector_unsigned_byte_8(lispobj *where)
1075 {
1076     struct vector *vector;
1077     long length, nwords;
1078
1079     vector = (struct vector *) where;
1080     length = fixnum_value(vector->length);
1081     nwords = CEILING(NWORDS(length, 8) + 2, 2);
1082
1083     return nwords;
1084 }
1085
1086
1087 static long
1088 scav_vector_unsigned_byte_16(lispobj *where, lispobj object)
1089 {
1090     struct vector *vector;
1091     long length, nwords;
1092
1093     vector = (struct vector *) where;
1094     length = fixnum_value(vector->length);
1095     nwords = CEILING(NWORDS(length, 16) + 2, 2);
1096
1097     return nwords;
1098 }
1099
1100 static lispobj
1101 trans_vector_unsigned_byte_16(lispobj object)
1102 {
1103     struct vector *vector;
1104     long length, nwords;
1105
1106     gc_assert(is_lisp_pointer(object));
1107
1108     vector = (struct vector *) native_pointer(object);
1109     length = fixnum_value(vector->length);
1110     nwords = CEILING(NWORDS(length, 16) + 2, 2);
1111
1112     return copy_large_unboxed_object(object, nwords);
1113 }
1114
1115 static long
1116 size_vector_unsigned_byte_16(lispobj *where)
1117 {
1118     struct vector *vector;
1119     long length, nwords;
1120
1121     vector = (struct vector *) where;
1122     length = fixnum_value(vector->length);
1123     nwords = CEILING(NWORDS(length, 16) + 2, 2);
1124
1125     return nwords;
1126 }
1127
1128 static long
1129 scav_vector_unsigned_byte_32(lispobj *where, lispobj object)
1130 {
1131     struct vector *vector;
1132     long length, nwords;
1133
1134     vector = (struct vector *) where;
1135     length = fixnum_value(vector->length);
1136     nwords = CEILING(NWORDS(length, 32) + 2, 2);
1137
1138     return nwords;
1139 }
1140
1141 static lispobj
1142 trans_vector_unsigned_byte_32(lispobj object)
1143 {
1144     struct vector *vector;
1145     long length, nwords;
1146
1147     gc_assert(is_lisp_pointer(object));
1148
1149     vector = (struct vector *) native_pointer(object);
1150     length = fixnum_value(vector->length);
1151     nwords = CEILING(NWORDS(length, 32) + 2, 2);
1152
1153     return copy_large_unboxed_object(object, nwords);
1154 }
1155
1156 static long
1157 size_vector_unsigned_byte_32(lispobj *where)
1158 {
1159     struct vector *vector;
1160     long length, nwords;
1161
1162     vector = (struct vector *) where;
1163     length = fixnum_value(vector->length);
1164     nwords = CEILING(NWORDS(length, 32) + 2, 2);
1165
1166     return nwords;
1167 }
1168
1169 #if N_WORD_BITS == 64
1170 static long
1171 scav_vector_unsigned_byte_64(lispobj *where, lispobj object)
1172 {
1173     struct vector *vector;
1174     long length, nwords;
1175
1176     vector = (struct vector *) where;
1177     length = fixnum_value(vector->length);
1178     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1179
1180     return nwords;
1181 }
1182
1183 static lispobj
1184 trans_vector_unsigned_byte_64(lispobj object)
1185 {
1186     struct vector *vector;
1187     long length, nwords;
1188
1189     gc_assert(is_lisp_pointer(object));
1190
1191     vector = (struct vector *) native_pointer(object);
1192     length = fixnum_value(vector->length);
1193     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1194
1195     return copy_large_unboxed_object(object, nwords);
1196 }
1197
1198 static long
1199 size_vector_unsigned_byte_64(lispobj *where)
1200 {
1201     struct vector *vector;
1202     long length, nwords;
1203
1204     vector = (struct vector *) where;
1205     length = fixnum_value(vector->length);
1206     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1207
1208     return nwords;
1209 }
1210 #endif
1211
1212 static long
1213 scav_vector_single_float(lispobj *where, lispobj object)
1214 {
1215     struct vector *vector;
1216     long length, nwords;
1217
1218     vector = (struct vector *) where;
1219     length = fixnum_value(vector->length);
1220     nwords = CEILING(NWORDS(length, 32) + 2, 2);
1221
1222     return nwords;
1223 }
1224
1225 static lispobj
1226 trans_vector_single_float(lispobj object)
1227 {
1228     struct vector *vector;
1229     long length, nwords;
1230
1231     gc_assert(is_lisp_pointer(object));
1232
1233     vector = (struct vector *) native_pointer(object);
1234     length = fixnum_value(vector->length);
1235     nwords = CEILING(NWORDS(length, 32) + 2, 2);
1236
1237     return copy_large_unboxed_object(object, nwords);
1238 }
1239
1240 static long
1241 size_vector_single_float(lispobj *where)
1242 {
1243     struct vector *vector;
1244     long length, nwords;
1245
1246     vector = (struct vector *) where;
1247     length = fixnum_value(vector->length);
1248     nwords = CEILING(NWORDS(length, 32) + 2, 2);
1249
1250     return nwords;
1251 }
1252
1253 static long
1254 scav_vector_double_float(lispobj *where, lispobj object)
1255 {
1256     struct vector *vector;
1257     long length, nwords;
1258
1259     vector = (struct vector *) where;
1260     length = fixnum_value(vector->length);
1261     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1262
1263     return nwords;
1264 }
1265
1266 static lispobj
1267 trans_vector_double_float(lispobj object)
1268 {
1269     struct vector *vector;
1270     long length, nwords;
1271
1272     gc_assert(is_lisp_pointer(object));
1273
1274     vector = (struct vector *) native_pointer(object);
1275     length = fixnum_value(vector->length);
1276     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1277
1278     return copy_large_unboxed_object(object, nwords);
1279 }
1280
1281 static long
1282 size_vector_double_float(lispobj *where)
1283 {
1284     struct vector *vector;
1285     long length, nwords;
1286
1287     vector = (struct vector *) where;
1288     length = fixnum_value(vector->length);
1289     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1290
1291     return nwords;
1292 }
1293
1294 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1295 static long
1296 scav_vector_long_float(lispobj *where, lispobj object)
1297 {
1298     struct vector *vector;
1299     long length, nwords;
1300
1301     vector = (struct vector *) where;
1302     length = fixnum_value(vector->length);
1303     nwords = CEILING(length *
1304                      LONG_FLOAT_SIZE
1305                      + 2, 2);
1306     return nwords;
1307 }
1308
1309 static lispobj
1310 trans_vector_long_float(lispobj object)
1311 {
1312     struct vector *vector;
1313     long length, nwords;
1314
1315     gc_assert(is_lisp_pointer(object));
1316
1317     vector = (struct vector *) native_pointer(object);
1318     length = fixnum_value(vector->length);
1319     nwords = CEILING(length * LONG_FLOAT_SIZE + 2, 2);
1320
1321     return copy_large_unboxed_object(object, nwords);
1322 }
1323
1324 static long
1325 size_vector_long_float(lispobj *where)
1326 {
1327     struct vector *vector;
1328     long length, nwords;
1329
1330     vector = (struct vector *) where;
1331     length = fixnum_value(vector->length);
1332     nwords = CEILING(length * LONG_FLOAT_SIZE + 2, 2);
1333
1334     return nwords;
1335 }
1336 #endif
1337
1338
1339 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1340 static long
1341 scav_vector_complex_single_float(lispobj *where, lispobj object)
1342 {
1343     struct vector *vector;
1344     long length, nwords;
1345
1346     vector = (struct vector *) where;
1347     length = fixnum_value(vector->length);
1348     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1349
1350     return nwords;
1351 }
1352
1353 static lispobj
1354 trans_vector_complex_single_float(lispobj object)
1355 {
1356     struct vector *vector;
1357     long length, nwords;
1358
1359     gc_assert(is_lisp_pointer(object));
1360
1361     vector = (struct vector *) native_pointer(object);
1362     length = fixnum_value(vector->length);
1363     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1364
1365     return copy_large_unboxed_object(object, nwords);
1366 }
1367
1368 static long
1369 size_vector_complex_single_float(lispobj *where)
1370 {
1371     struct vector *vector;
1372     long length, nwords;
1373
1374     vector = (struct vector *) where;
1375     length = fixnum_value(vector->length);
1376     nwords = CEILING(NWORDS(length, 64) + 2, 2);
1377
1378     return nwords;
1379 }
1380 #endif
1381
1382 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1383 static long
1384 scav_vector_complex_double_float(lispobj *where, lispobj object)
1385 {
1386     struct vector *vector;
1387     long length, nwords;
1388
1389     vector = (struct vector *) where;
1390     length = fixnum_value(vector->length);
1391     nwords = CEILING(NWORDS(length, 128) + 2, 2);
1392
1393     return nwords;
1394 }
1395
1396 static lispobj
1397 trans_vector_complex_double_float(lispobj object)
1398 {
1399     struct vector *vector;
1400     long length, nwords;
1401
1402     gc_assert(is_lisp_pointer(object));
1403
1404     vector = (struct vector *) native_pointer(object);
1405     length = fixnum_value(vector->length);
1406     nwords = CEILING(NWORDS(length, 128) + 2, 2);
1407
1408     return copy_large_unboxed_object(object, nwords);
1409 }
1410
1411 static long
1412 size_vector_complex_double_float(lispobj *where)
1413 {
1414     struct vector *vector;
1415     long length, nwords;
1416
1417     vector = (struct vector *) where;
1418     length = fixnum_value(vector->length);
1419     nwords = CEILING(NWORDS(length, 128) + 2, 2);
1420
1421     return nwords;
1422 }
1423 #endif
1424
1425
1426 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1427 static long
1428 scav_vector_complex_long_float(lispobj *where, lispobj object)
1429 {
1430     struct vector *vector;
1431     long length, nwords;
1432
1433     vector = (struct vector *) where;
1434     length = fixnum_value(vector->length);
1435     nwords = CEILING(length * (2* LONG_FLOAT_SIZE) + 2, 2);
1436
1437     return nwords;
1438 }
1439
1440 static lispobj
1441 trans_vector_complex_long_float(lispobj object)
1442 {
1443     struct vector *vector;
1444     long length, nwords;
1445
1446     gc_assert(is_lisp_pointer(object));
1447
1448     vector = (struct vector *) native_pointer(object);
1449     length = fixnum_value(vector->length);
1450     nwords = CEILING(length * (2*LONG_FLOAT_SIZE) + 2, 2);
1451
1452     return copy_large_unboxed_object(object, nwords);
1453 }
1454
1455 static long
1456 size_vector_complex_long_float(lispobj *where)
1457 {
1458     struct vector *vector;
1459     long length, nwords;
1460
1461     vector = (struct vector *) where;
1462     length = fixnum_value(vector->length);
1463     nwords = CEILING(length * (2*LONG_FLOAT_SIZE) + 2, 2);
1464
1465     return nwords;
1466 }
1467 #endif
1468
1469 #define WEAK_POINTER_NWORDS \
1470         CEILING((sizeof(struct weak_pointer) / sizeof(lispobj)), 2)
1471
1472 static lispobj
1473 trans_weak_pointer(lispobj object)
1474 {
1475     lispobj copy;
1476 #ifndef LISP_FEATURE_GENCGC
1477     struct weak_pointer *wp;
1478 #endif
1479     gc_assert(is_lisp_pointer(object));
1480
1481 #if defined(DEBUG_WEAK)
1482     printf("Transporting weak pointer from 0x%08x\n", object);
1483 #endif
1484
1485     /* Need to remember where all the weak pointers are that have */
1486     /* been transported so they can be fixed up in a post-GC pass. */
1487
1488     copy = copy_object(object, WEAK_POINTER_NWORDS);
1489 #ifndef LISP_FEATURE_GENCGC
1490     wp = (struct weak_pointer *) native_pointer(copy);
1491
1492     gc_assert(widetag_of(wp->header)==WEAK_POINTER_WIDETAG);
1493     /* Push the weak pointer onto the list of weak pointers. */
1494     wp->next = (struct weak_pointer *)LOW_WORD(weak_pointers);
1495     weak_pointers = wp;
1496 #endif
1497     return copy;
1498 }
1499
1500 static long
1501 size_weak_pointer(lispobj *where)
1502 {
1503     return WEAK_POINTER_NWORDS;
1504 }
1505
1506
1507 void scan_weak_pointers(void)
1508 {
1509     struct weak_pointer *wp;
1510     for (wp = weak_pointers; wp != NULL; wp=wp->next) {
1511         lispobj value = wp->value;
1512         lispobj *first_pointer;
1513         gc_assert(widetag_of(wp->header)==WEAK_POINTER_WIDETAG);
1514         if (!(is_lisp_pointer(value) && from_space_p(value)))
1515             continue;
1516
1517         /* Now, we need to check whether the object has been forwarded. If
1518          * it has been, the weak pointer is still good and needs to be
1519          * updated. Otherwise, the weak pointer needs to be nil'ed
1520          * out. */
1521
1522         first_pointer = (lispobj *)native_pointer(value);
1523
1524         if (forwarding_pointer_p(first_pointer)) {
1525             wp->value=
1526                 (lispobj)LOW_WORD(forwarding_pointer_value(first_pointer));
1527         } else {
1528             /* Break it. */
1529             wp->value = NIL;
1530             wp->broken = T;
1531         }
1532     }
1533 }
1534
1535
1536 \f
1537 /*
1538  * initialization
1539  */
1540
1541 static long
1542 scav_lose(lispobj *where, lispobj object)
1543 {
1544     lose("no scavenge function for object 0x%08x (widetag 0x%x)",
1545          (unsigned long)object,
1546          widetag_of(*(lispobj*)native_pointer(object)));
1547
1548     return 0; /* bogus return value to satisfy static type checking */
1549 }
1550
1551 static lispobj
1552 trans_lose(lispobj object)
1553 {
1554     lose("no transport function for object 0x%08x (widetag 0x%x)",
1555          (unsigned long)object,
1556          widetag_of(*(lispobj*)native_pointer(object)));
1557     return NIL; /* bogus return value to satisfy static type checking */
1558 }
1559
1560 static long
1561 size_lose(lispobj *where)
1562 {
1563     lose("no size function for object at 0x%08x (widetag 0x%x)",
1564          (unsigned long)where,
1565          widetag_of(LOW_WORD(where)));
1566     return 1; /* bogus return value to satisfy static type checking */
1567 }
1568
1569 \f
1570 /*
1571  * initialization
1572  */
1573
1574 void
1575 gc_init_tables(void)
1576 {
1577     long i;
1578
1579     /* Set default value in all slots of scavenge table.  FIXME
1580      * replace this gnarly sizeof with something based on
1581      * N_WIDETAG_BITS */
1582     for (i = 0; i < ((sizeof scavtab)/(sizeof scavtab[0])); i++) {
1583         scavtab[i] = scav_lose;
1584     }
1585
1586     /* For each type which can be selected by the lowtag alone, set
1587      * multiple entries in our widetag scavenge table (one for each
1588      * possible value of the high bits).
1589      */
1590
1591     for (i = 0; i < (1<<(N_WIDETAG_BITS-N_LOWTAG_BITS)); i++) {
1592         scavtab[EVEN_FIXNUM_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_immediate;
1593         scavtab[FUN_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_fun_pointer;
1594         /* skipping OTHER_IMMEDIATE_0_LOWTAG */
1595         scavtab[LIST_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_list_pointer;
1596         scavtab[ODD_FIXNUM_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_immediate;
1597         scavtab[INSTANCE_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_instance_pointer;
1598         /* skipping OTHER_IMMEDIATE_1_LOWTAG */
1599         scavtab[OTHER_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = scav_other_pointer;
1600     }
1601
1602     /* Other-pointer types (those selected by all eight bits of the
1603      * tag) get one entry each in the scavenge table. */
1604     scavtab[BIGNUM_WIDETAG] = scav_unboxed;
1605     scavtab[RATIO_WIDETAG] = scav_boxed;
1606 #if N_WORD_BITS == 64
1607     scavtab[SINGLE_FLOAT_WIDETAG] = scav_immediate;
1608 #else
1609     scavtab[SINGLE_FLOAT_WIDETAG] = scav_unboxed;
1610 #endif
1611     scavtab[DOUBLE_FLOAT_WIDETAG] = scav_unboxed;
1612 #ifdef LONG_FLOAT_WIDETAG
1613     scavtab[LONG_FLOAT_WIDETAG] = scav_unboxed;
1614 #endif
1615     scavtab[COMPLEX_WIDETAG] = scav_boxed;
1616 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
1617     scavtab[COMPLEX_SINGLE_FLOAT_WIDETAG] = scav_unboxed;
1618 #endif
1619 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
1620     scavtab[COMPLEX_DOUBLE_FLOAT_WIDETAG] = scav_unboxed;
1621 #endif
1622 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
1623     scavtab[COMPLEX_LONG_FLOAT_WIDETAG] = scav_unboxed;
1624 #endif
1625     scavtab[SIMPLE_ARRAY_WIDETAG] = scav_boxed;
1626     scavtab[SIMPLE_BASE_STRING_WIDETAG] = scav_base_string;
1627 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
1628     scavtab[SIMPLE_CHARACTER_STRING_WIDETAG] = scav_character_string;
1629 #endif
1630     scavtab[SIMPLE_BIT_VECTOR_WIDETAG] = scav_vector_bit;
1631     scavtab[SIMPLE_ARRAY_NIL_WIDETAG] = scav_vector_nil;
1632     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG] =
1633         scav_vector_unsigned_byte_2;
1634     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG] =
1635         scav_vector_unsigned_byte_4;
1636     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG] =
1637         scav_vector_unsigned_byte_8;
1638     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG] =
1639         scav_vector_unsigned_byte_8;
1640     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG] =
1641         scav_vector_unsigned_byte_16;
1642     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
1643         scav_vector_unsigned_byte_16;
1644 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG
1645     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG] =
1646         scav_vector_unsigned_byte_32;
1647 #endif
1648     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
1649         scav_vector_unsigned_byte_32;
1650     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
1651         scav_vector_unsigned_byte_32;
1652 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
1653     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG] =
1654         scav_vector_unsigned_byte_64;
1655 #endif
1656 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
1657     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG] =
1658         scav_vector_unsigned_byte_64;
1659 #endif
1660 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
1661     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
1662         scav_vector_unsigned_byte_64;
1663 #endif
1664 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
1665     scavtab[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] = scav_vector_unsigned_byte_8;
1666 #endif
1667 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
1668     scavtab[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG] =
1669         scav_vector_unsigned_byte_16;
1670 #endif
1671 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1672     scavtab[SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG] =
1673         scav_vector_unsigned_byte_32;
1674 #endif
1675 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1676     scavtab[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
1677         scav_vector_unsigned_byte_32;
1678 #endif
1679 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1680     scavtab[SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG] =
1681         scav_vector_unsigned_byte_64;
1682 #endif
1683 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1684     scavtab[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
1685         scav_vector_unsigned_byte_64;
1686 #endif
1687     scavtab[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] = scav_vector_single_float;
1688     scavtab[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] = scav_vector_double_float;
1689 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1690     scavtab[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG] = scav_vector_long_float;
1691 #endif
1692 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1693     scavtab[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG] =
1694         scav_vector_complex_single_float;
1695 #endif
1696 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1697     scavtab[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG] =
1698         scav_vector_complex_double_float;
1699 #endif
1700 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1701     scavtab[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG] =
1702         scav_vector_complex_long_float;
1703 #endif
1704     scavtab[COMPLEX_BASE_STRING_WIDETAG] = scav_boxed;
1705 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
1706     scavtab[COMPLEX_CHARACTER_STRING_WIDETAG] = scav_boxed;
1707 #endif
1708     scavtab[COMPLEX_VECTOR_NIL_WIDETAG] = scav_boxed;
1709     scavtab[COMPLEX_BIT_VECTOR_WIDETAG] = scav_boxed;
1710     scavtab[COMPLEX_VECTOR_WIDETAG] = scav_boxed;
1711     scavtab[COMPLEX_ARRAY_WIDETAG] = scav_boxed;
1712     scavtab[CODE_HEADER_WIDETAG] = scav_code_header;
1713 #ifndef LISP_FEATURE_GENCGC     /* FIXME ..._X86 ? */
1714     scavtab[SIMPLE_FUN_HEADER_WIDETAG] = scav_fun_header;
1715     scavtab[RETURN_PC_HEADER_WIDETAG] = scav_return_pc_header;
1716 #endif
1717 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
1718     scavtab[CLOSURE_HEADER_WIDETAG] = scav_closure_header;
1719     scavtab[FUNCALLABLE_INSTANCE_HEADER_WIDETAG] = scav_closure_header;
1720 #else
1721     scavtab[CLOSURE_HEADER_WIDETAG] = scav_boxed;
1722     scavtab[FUNCALLABLE_INSTANCE_HEADER_WIDETAG] = scav_boxed;
1723 #endif
1724     scavtab[VALUE_CELL_HEADER_WIDETAG] = scav_boxed;
1725     scavtab[SYMBOL_HEADER_WIDETAG] = scav_boxed;
1726     scavtab[CHARACTER_WIDETAG] = scav_immediate;
1727     scavtab[SAP_WIDETAG] = scav_unboxed;
1728     scavtab[UNBOUND_MARKER_WIDETAG] = scav_immediate;
1729     scavtab[NO_TLS_VALUE_MARKER_WIDETAG] = scav_immediate;
1730     scavtab[INSTANCE_HEADER_WIDETAG] = scav_instance;
1731 #ifdef LISP_FEATURE_SPARC
1732     scavtab[FDEFN_WIDETAG] = scav_boxed;
1733 #else
1734     scavtab[FDEFN_WIDETAG] = scav_fdefn;
1735 #endif
1736
1737     /* transport other table, initialized same way as scavtab */
1738     for (i = 0; i < ((sizeof transother)/(sizeof transother[0])); i++)
1739         transother[i] = trans_lose;
1740     transother[BIGNUM_WIDETAG] = trans_unboxed;
1741     transother[RATIO_WIDETAG] = trans_boxed;
1742
1743 #if N_WORD_BITS == 64
1744     transother[SINGLE_FLOAT_WIDETAG] = trans_immediate;
1745 #else
1746     transother[SINGLE_FLOAT_WIDETAG] = trans_unboxed;
1747 #endif
1748     transother[DOUBLE_FLOAT_WIDETAG] = trans_unboxed;
1749 #ifdef LONG_FLOAT_WIDETAG
1750     transother[LONG_FLOAT_WIDETAG] = trans_unboxed;
1751 #endif
1752     transother[COMPLEX_WIDETAG] = trans_boxed;
1753 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
1754     transother[COMPLEX_SINGLE_FLOAT_WIDETAG] = trans_unboxed;
1755 #endif
1756 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
1757     transother[COMPLEX_DOUBLE_FLOAT_WIDETAG] = trans_unboxed;
1758 #endif
1759 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
1760     transother[COMPLEX_LONG_FLOAT_WIDETAG] = trans_unboxed;
1761 #endif
1762     transother[SIMPLE_ARRAY_WIDETAG] = trans_boxed; /* but not GENCGC */
1763     transother[SIMPLE_BASE_STRING_WIDETAG] = trans_base_string;
1764 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
1765     transother[SIMPLE_CHARACTER_STRING_WIDETAG] = trans_character_string;
1766 #endif
1767     transother[SIMPLE_BIT_VECTOR_WIDETAG] = trans_vector_bit;
1768     transother[SIMPLE_VECTOR_WIDETAG] = trans_vector;
1769     transother[SIMPLE_ARRAY_NIL_WIDETAG] = trans_vector_nil;
1770     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG] =
1771         trans_vector_unsigned_byte_2;
1772     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG] =
1773         trans_vector_unsigned_byte_4;
1774     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG] =
1775         trans_vector_unsigned_byte_8;
1776     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG] =
1777         trans_vector_unsigned_byte_8;
1778     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG] =
1779         trans_vector_unsigned_byte_16;
1780     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
1781         trans_vector_unsigned_byte_16;
1782 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG
1783     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG] =
1784         trans_vector_unsigned_byte_32;
1785 #endif
1786     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
1787         trans_vector_unsigned_byte_32;
1788     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
1789         trans_vector_unsigned_byte_32;
1790 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
1791     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG] =
1792         trans_vector_unsigned_byte_64;
1793 #endif
1794 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
1795     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG] =
1796         trans_vector_unsigned_byte_64;
1797 #endif
1798 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
1799     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
1800         trans_vector_unsigned_byte_64;
1801 #endif
1802 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
1803     transother[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] =
1804         trans_vector_unsigned_byte_8;
1805 #endif
1806 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
1807     transother[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG] =
1808         trans_vector_unsigned_byte_16;
1809 #endif
1810 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1811     transother[SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG] =
1812         trans_vector_unsigned_byte_32;
1813 #endif
1814 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1815     transother[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
1816         trans_vector_unsigned_byte_32;
1817 #endif
1818 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1819     transother[SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG] =
1820         trans_vector_unsigned_byte_64;
1821 #endif
1822 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1823     transother[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
1824         trans_vector_unsigned_byte_64;
1825 #endif
1826     transother[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] =
1827         trans_vector_single_float;
1828     transother[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] =
1829         trans_vector_double_float;
1830 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1831     transother[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG] =
1832         trans_vector_long_float;
1833 #endif
1834 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1835     transother[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG] =
1836         trans_vector_complex_single_float;
1837 #endif
1838 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1839     transother[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG] =
1840         trans_vector_complex_double_float;
1841 #endif
1842 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1843     transother[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG] =
1844         trans_vector_complex_long_float;
1845 #endif
1846     transother[COMPLEX_BASE_STRING_WIDETAG] = trans_boxed;
1847 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
1848     transother[COMPLEX_CHARACTER_STRING_WIDETAG] = trans_boxed;
1849 #endif
1850     transother[COMPLEX_BIT_VECTOR_WIDETAG] = trans_boxed;
1851     transother[COMPLEX_VECTOR_NIL_WIDETAG] = trans_boxed;
1852     transother[COMPLEX_VECTOR_WIDETAG] = trans_boxed;
1853     transother[COMPLEX_ARRAY_WIDETAG] = trans_boxed;
1854     transother[CODE_HEADER_WIDETAG] = trans_code_header;
1855     transother[SIMPLE_FUN_HEADER_WIDETAG] = trans_fun_header;
1856     transother[RETURN_PC_HEADER_WIDETAG] = trans_return_pc_header;
1857     transother[CLOSURE_HEADER_WIDETAG] = trans_boxed;
1858     transother[FUNCALLABLE_INSTANCE_HEADER_WIDETAG] = trans_boxed;
1859     transother[VALUE_CELL_HEADER_WIDETAG] = trans_boxed;
1860     transother[SYMBOL_HEADER_WIDETAG] = trans_boxed;
1861     transother[CHARACTER_WIDETAG] = trans_immediate;
1862     transother[SAP_WIDETAG] = trans_unboxed;
1863     transother[UNBOUND_MARKER_WIDETAG] = trans_immediate;
1864     transother[NO_TLS_VALUE_MARKER_WIDETAG] = trans_immediate;
1865     transother[WEAK_POINTER_WIDETAG] = trans_weak_pointer;
1866     transother[INSTANCE_HEADER_WIDETAG] = trans_boxed;
1867     transother[FDEFN_WIDETAG] = trans_boxed;
1868
1869     /* size table, initialized the same way as scavtab */
1870     for (i = 0; i < ((sizeof sizetab)/(sizeof sizetab[0])); i++)
1871         sizetab[i] = size_lose;
1872     for (i = 0; i < (1<<(N_WIDETAG_BITS-N_LOWTAG_BITS)); i++) {
1873         sizetab[EVEN_FIXNUM_LOWTAG|(i<<N_LOWTAG_BITS)] = size_immediate;
1874         sizetab[FUN_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
1875         /* skipping OTHER_IMMEDIATE_0_LOWTAG */
1876         sizetab[LIST_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
1877         sizetab[ODD_FIXNUM_LOWTAG|(i<<N_LOWTAG_BITS)] = size_immediate;
1878         sizetab[INSTANCE_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
1879         /* skipping OTHER_IMMEDIATE_1_LOWTAG */
1880         sizetab[OTHER_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
1881     }
1882     sizetab[BIGNUM_WIDETAG] = size_unboxed;
1883     sizetab[RATIO_WIDETAG] = size_boxed;
1884 #if N_WORD_BITS == 64
1885     sizetab[SINGLE_FLOAT_WIDETAG] = size_immediate;
1886 #else
1887     sizetab[SINGLE_FLOAT_WIDETAG] = size_unboxed;
1888 #endif
1889     sizetab[DOUBLE_FLOAT_WIDETAG] = size_unboxed;
1890 #ifdef LONG_FLOAT_WIDETAG
1891     sizetab[LONG_FLOAT_WIDETAG] = size_unboxed;
1892 #endif
1893     sizetab[COMPLEX_WIDETAG] = size_boxed;
1894 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
1895     sizetab[COMPLEX_SINGLE_FLOAT_WIDETAG] = size_unboxed;
1896 #endif
1897 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
1898     sizetab[COMPLEX_DOUBLE_FLOAT_WIDETAG] = size_unboxed;
1899 #endif
1900 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
1901     sizetab[COMPLEX_LONG_FLOAT_WIDETAG] = size_unboxed;
1902 #endif
1903     sizetab[SIMPLE_ARRAY_WIDETAG] = size_boxed;
1904     sizetab[SIMPLE_BASE_STRING_WIDETAG] = size_base_string;
1905 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
1906     sizetab[SIMPLE_CHARACTER_STRING_WIDETAG] = size_character_string;
1907 #endif
1908     sizetab[SIMPLE_BIT_VECTOR_WIDETAG] = size_vector_bit;
1909     sizetab[SIMPLE_VECTOR_WIDETAG] = size_vector;
1910     sizetab[SIMPLE_ARRAY_NIL_WIDETAG] = size_vector_nil;
1911     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG] =
1912         size_vector_unsigned_byte_2;
1913     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG] =
1914         size_vector_unsigned_byte_4;
1915     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG] =
1916         size_vector_unsigned_byte_8;
1917     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG] =
1918         size_vector_unsigned_byte_8;
1919     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG] =
1920         size_vector_unsigned_byte_16;
1921     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
1922         size_vector_unsigned_byte_16;
1923 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG
1924     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG] =
1925         size_vector_unsigned_byte_32;
1926 #endif
1927     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
1928         size_vector_unsigned_byte_32;
1929     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
1930         size_vector_unsigned_byte_32;
1931 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
1932     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG] =
1933         size_vector_unsigned_byte_64;
1934 #endif
1935 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
1936     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG] =
1937         size_vector_unsigned_byte_64;
1938 #endif
1939 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
1940     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
1941         size_vector_unsigned_byte_64;
1942 #endif
1943 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
1944     sizetab[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] = size_vector_unsigned_byte_8;
1945 #endif
1946 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
1947     sizetab[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG] =
1948         size_vector_unsigned_byte_16;
1949 #endif
1950 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG
1951     sizetab[SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG] =
1952         size_vector_unsigned_byte_32;
1953 #endif
1954 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
1955     sizetab[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
1956         size_vector_unsigned_byte_32;
1957 #endif
1958 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
1959     sizetab[SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG] =
1960         size_vector_unsigned_byte_64;
1961 #endif
1962 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
1963     sizetab[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
1964         size_vector_unsigned_byte_64;
1965 #endif
1966     sizetab[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] = size_vector_single_float;
1967     sizetab[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] = size_vector_double_float;
1968 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1969     sizetab[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG] = size_vector_long_float;
1970 #endif
1971 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1972     sizetab[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG] =
1973         size_vector_complex_single_float;
1974 #endif
1975 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1976     sizetab[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG] =
1977         size_vector_complex_double_float;
1978 #endif
1979 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1980     sizetab[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG] =
1981         size_vector_complex_long_float;
1982 #endif
1983     sizetab[COMPLEX_BASE_STRING_WIDETAG] = size_boxed;
1984 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
1985     sizetab[COMPLEX_CHARACTER_STRING_WIDETAG] = size_boxed;
1986 #endif
1987     sizetab[COMPLEX_VECTOR_NIL_WIDETAG] = size_boxed;
1988     sizetab[COMPLEX_BIT_VECTOR_WIDETAG] = size_boxed;
1989     sizetab[COMPLEX_VECTOR_WIDETAG] = size_boxed;
1990     sizetab[COMPLEX_ARRAY_WIDETAG] = size_boxed;
1991     sizetab[CODE_HEADER_WIDETAG] = size_code_header;
1992 #if 0
1993     /* We shouldn't see these, so just lose if it happens. */
1994     sizetab[SIMPLE_FUN_HEADER_WIDETAG] = size_function_header;
1995     sizetab[RETURN_PC_HEADER_WIDETAG] = size_return_pc_header;
1996 #endif
1997     sizetab[CLOSURE_HEADER_WIDETAG] = size_boxed;
1998     sizetab[FUNCALLABLE_INSTANCE_HEADER_WIDETAG] = size_boxed;
1999     sizetab[VALUE_CELL_HEADER_WIDETAG] = size_boxed;
2000     sizetab[SYMBOL_HEADER_WIDETAG] = size_boxed;
2001     sizetab[CHARACTER_WIDETAG] = size_immediate;
2002     sizetab[SAP_WIDETAG] = size_unboxed;
2003     sizetab[UNBOUND_MARKER_WIDETAG] = size_immediate;
2004     sizetab[NO_TLS_VALUE_MARKER_WIDETAG] = size_immediate;
2005     sizetab[WEAK_POINTER_WIDETAG] = size_weak_pointer;
2006     sizetab[INSTANCE_HEADER_WIDETAG] = size_boxed;
2007     sizetab[FDEFN_WIDETAG] = size_boxed;
2008 }
2009
2010 \f
2011 /* Find the code object for the given pc, or return NULL on
2012    failure. */
2013 lispobj *
2014 component_ptr_from_pc(lispobj *pc)
2015 {
2016     lispobj *object = NULL;
2017
2018     if ( (object = search_read_only_space(pc)) )
2019         ;
2020     else if ( (object = search_static_space(pc)) )
2021         ;
2022     else
2023         object = search_dynamic_space(pc);
2024
2025     if (object) /* if we found something */
2026         if (widetag_of(*object) == CODE_HEADER_WIDETAG)
2027             return(object);
2028
2029     return (NULL);
2030 }
2031
2032 /* Scan an area looking for an object which encloses the given pointer.
2033  * Return the object start on success or NULL on failure. */
2034 lispobj *
2035 gc_search_space(lispobj *start, size_t words, lispobj *pointer)
2036 {
2037     while (words > 0) {
2038         size_t count = 1;
2039         lispobj thing = *start;
2040
2041         /* If thing is an immediate then this is a cons. */
2042         if (is_lisp_pointer(thing)
2043             || (fixnump(thing))
2044             || (widetag_of(thing) == CHARACTER_WIDETAG)
2045 #if N_WORD_BITS == 64
2046             || (widetag_of(thing) == SINGLE_FLOAT_WIDETAG)
2047 #endif
2048             || (widetag_of(thing) == UNBOUND_MARKER_WIDETAG))
2049             count = 2;
2050         else
2051             count = (sizetab[widetag_of(thing)])(start);
2052
2053         /* Check whether the pointer is within this object. */
2054         if ((pointer >= start) && (pointer < (start+count))) {
2055             /* found it! */
2056             /*FSHOW((stderr,"/found %x in %x %x\n", pointer, start, thing));*/
2057             return(start);
2058         }
2059
2060         /* Round up the count. */
2061         count = CEILING(count,2);
2062
2063         start += count;
2064         words -= count;
2065     }
2066     return (NULL);
2067 }