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
;
58 #ifndef LISP_FEATURE_GENCGC
61 return current_dynamic_space
== from_space
;
66 forwarding_pointer_p(lispobj
*pointer
) {
67 lispobj first_word
=*pointer
;
68 #ifdef LISP_FEATURE_GENCGC
69 return (first_word
== 0x01);
71 return (is_lisp_pointer(first_word
)
72 && in_gc_p() /* cheneygc new_space_p() is broken when not in gc */
73 && new_space_p(first_word
));
77 static inline lispobj
*
78 forwarding_pointer_value(lispobj
*pointer
) {
79 #ifdef LISP_FEATURE_GENCGC
80 return (lispobj
*) ((pointer_sized_uint_t
) pointer
[1]);
82 return (lispobj
*) ((pointer_sized_uint_t
) pointer
[0]);
86 set_forwarding_pointer(lispobj
* pointer
, lispobj newspace_copy
) {
87 #ifdef LISP_FEATURE_GENCGC
89 pointer
[1]=newspace_copy
;
91 pointer
[0]=newspace_copy
;
96 sword_t (*scavtab
[256])(lispobj
*where
, lispobj object
);
97 lispobj (*transother
[256])(lispobj object
);
98 sword_t (*sizetab
[256])(lispobj
*where
);
99 struct weak_pointer
*weak_pointers
;
101 os_vm_size_t bytes_consed_between_gcs
= 12*1024*1024;
107 /* gc_general_copy_object is inline from gc-internal.h */
109 /* to copy a boxed object */
111 copy_object(lispobj object
, sword_t nwords
)
113 return gc_general_copy_object(object
, nwords
, BOXED_PAGE_FLAG
);
117 copy_code_object(lispobj object
, sword_t nwords
)
119 return gc_general_copy_object(object
, nwords
, CODE_PAGE_FLAG
);
122 static sword_t
scav_lose(lispobj
*where
, lispobj object
); /* forward decl */
124 /* FIXME: Most calls end up going to some trouble to compute an
125 * 'n_words' value for this function. The system might be a little
126 * simpler if this function used an 'end' parameter instead. */
128 scavenge(lispobj
*start
, sword_t n_words
)
130 lispobj
*end
= start
+ n_words
;
133 for (object_ptr
= start
; object_ptr
< end
;) {
134 lispobj object
= *object_ptr
;
135 #ifdef LISP_FEATURE_GENCGC
136 if (forwarding_pointer_p(object_ptr
))
137 lose("unexpect forwarding pointer in scavenge: %p, start=%p, n=%ld\n",
138 object_ptr
, start
, n_words
);
140 if (is_lisp_pointer(object
)) {
141 if (from_space_p(object
)) {
142 /* It currently points to old space. Check for a
143 * forwarding pointer. */
144 lispobj
*ptr
= native_pointer(object
);
145 if (forwarding_pointer_p(ptr
)) {
146 /* Yes, there's a forwarding pointer. */
147 *object_ptr
= LOW_WORD(forwarding_pointer_value(ptr
));
150 /* Scavenge that pointer. */
152 (scavtab
[widetag_of(object
)])(object_ptr
, object
);
155 /* It points somewhere other than oldspace. Leave it
160 else if (fixnump(object
)) {
161 /* It's a fixnum: really easy.. */
164 /* It's some sort of header object or another. */
165 object_ptr
+= (scavtab
[widetag_of(object
)])(object_ptr
, object
);
168 gc_assert_verbose(object_ptr
== end
, "Final object pointer %p, start %p, end %p\n",
169 object_ptr
, start
, end
);
172 static lispobj
trans_fun_header(lispobj object
); /* forward decls */
173 static lispobj
trans_boxed(lispobj object
);
176 scav_fun_pointer(lispobj
*where
, lispobj object
)
178 lispobj
*first_pointer
;
181 gc_assert(is_lisp_pointer(object
));
183 /* Object is a pointer into from_space - not a FP. */
184 first_pointer
= (lispobj
*) native_pointer(object
);
186 /* must transport object -- object may point to either a function
187 * header, a closure function header, or to a closure header. */
189 switch (widetag_of(*first_pointer
)) {
190 case SIMPLE_FUN_HEADER_WIDETAG
:
191 copy
= trans_fun_header(object
);
194 copy
= trans_boxed(object
);
198 if (copy
!= object
) {
199 /* Set forwarding pointer */
200 set_forwarding_pointer(first_pointer
,copy
);
203 gc_assert(is_lisp_pointer(copy
));
204 gc_assert(!from_space_p(copy
));
213 trans_code(struct code
*code
)
215 struct code
*new_code
;
216 lispobj l_code
, l_new_code
;
217 uword_t nheader_words
, ncode_words
, nwords
;
218 uword_t displacement
;
219 lispobj fheaderl
, *prev_pointer
;
221 /* if object has already been transported, just return pointer */
222 if (forwarding_pointer_p((lispobj
*)code
)) {
224 printf("Was already transported\n");
226 return (struct code
*) forwarding_pointer_value
227 ((lispobj
*)((pointer_sized_uint_t
) code
));
230 gc_assert(widetag_of(code
->header
) == CODE_HEADER_WIDETAG
);
232 /* prepare to transport the code vector */
233 l_code
= (lispobj
) LOW_WORD(code
) | OTHER_POINTER_LOWTAG
;
235 ncode_words
= code_instruction_words(code
->code_size
);
236 nheader_words
= code_header_words(code
->header
);
237 nwords
= ncode_words
+ nheader_words
;
238 nwords
= CEILING(nwords
, 2);
240 l_new_code
= copy_code_object(l_code
, nwords
);
241 new_code
= (struct code
*) native_pointer(l_new_code
);
243 #if defined(DEBUG_CODE_GC)
244 printf("Old code object at 0x%08x, new code object at 0x%08x.\n",
245 (uword_t
) code
, (uword_t
) new_code
);
246 printf("Code object is %d words long.\n", nwords
);
249 #ifdef LISP_FEATURE_GENCGC
250 if (new_code
== code
)
254 displacement
= l_new_code
- l_code
;
256 set_forwarding_pointer((lispobj
*)code
, l_new_code
);
258 /* set forwarding pointers for all the function headers in the */
259 /* code object. also fix all self pointers */
261 fheaderl
= code
->entry_points
;
262 prev_pointer
= &new_code
->entry_points
;
264 while (fheaderl
!= NIL
) {
265 struct simple_fun
*fheaderp
, *nfheaderp
;
268 fheaderp
= (struct simple_fun
*) native_pointer(fheaderl
);
269 gc_assert(widetag_of(fheaderp
->header
) == SIMPLE_FUN_HEADER_WIDETAG
);
271 /* Calculate the new function pointer and the new */
272 /* function header. */
273 nfheaderl
= fheaderl
+ displacement
;
274 nfheaderp
= (struct simple_fun
*) native_pointer(nfheaderl
);
277 printf("fheaderp->header (at %x) <- %x\n",
278 &(fheaderp
->header
) , nfheaderl
);
280 set_forwarding_pointer((lispobj
*)fheaderp
, nfheaderl
);
282 /* fix self pointer. */
284 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
285 FUN_RAW_ADDR_OFFSET
+
289 *prev_pointer
= nfheaderl
;
291 fheaderl
= fheaderp
->next
;
292 prev_pointer
= &nfheaderp
->next
;
294 #ifdef LISP_FEATURE_GENCGC
295 /* Cheneygc doesn't need this os_flush_icache, it flushes the whole
296 spaces once when all copying is done. */
297 os_flush_icache((os_vm_address_t
) (((sword_t
*)new_code
) + nheader_words
),
298 ncode_words
* sizeof(sword_t
));
302 #ifdef LISP_FEATURE_X86
303 gencgc_apply_code_fixups(code
, new_code
);
310 scav_code_header(lispobj
*where
, lispobj object
)
313 sword_t n_header_words
, n_code_words
, n_words
;
314 lispobj entry_point
; /* tagged pointer to entry point */
315 struct simple_fun
*function_ptr
; /* untagged pointer to entry point */
317 code
= (struct code
*) where
;
318 n_code_words
= code_instruction_words(code
->code_size
);
319 n_header_words
= code_header_words(object
);
320 n_words
= n_code_words
+ n_header_words
;
321 n_words
= CEILING(n_words
, 2);
323 /* Scavenge the boxed section of the code data block. */
324 scavenge(where
+ 1, n_header_words
- 1);
326 /* Scavenge the boxed section of each function object in the
327 * code data block. */
328 for (entry_point
= code
->entry_points
;
330 entry_point
= function_ptr
->next
) {
332 gc_assert_verbose(is_lisp_pointer(entry_point
),
333 "Entry point %lx\n is not a lisp pointer.",
334 (sword_t
)entry_point
);
336 function_ptr
= (struct simple_fun
*) native_pointer(entry_point
);
337 gc_assert(widetag_of(function_ptr
->header
)==SIMPLE_FUN_HEADER_WIDETAG
);
338 scavenge(SIMPLE_FUN_SCAV_START(function_ptr
),
339 SIMPLE_FUN_SCAV_NWORDS(function_ptr
));
346 trans_code_header(lispobj object
)
350 ncode
= trans_code((struct code
*) native_pointer(object
));
351 return (lispobj
) LOW_WORD(ncode
) | OTHER_POINTER_LOWTAG
;
356 size_code_header(lispobj
*where
)
359 sword_t nheader_words
, ncode_words
, nwords
;
361 code
= (struct code
*) where
;
363 ncode_words
= code_instruction_words(code
->code_size
);
364 nheader_words
= code_header_words(code
->header
);
365 nwords
= ncode_words
+ nheader_words
;
366 nwords
= CEILING(nwords
, 2);
371 #if !defined(LISP_FEATURE_X86) && ! defined(LISP_FEATURE_X86_64)
373 scav_return_pc_header(lispobj
*where
, lispobj object
)
375 lose("attempted to scavenge a return PC header where=0x%08x object=0x%08x\n",
378 return 0; /* bogus return value to satisfy static type checking */
380 #endif /* LISP_FEATURE_X86 */
383 trans_return_pc_header(lispobj object
)
385 struct simple_fun
*return_pc
;
387 struct code
*code
, *ncode
;
389 return_pc
= (struct simple_fun
*) native_pointer(object
);
390 /* FIXME: was times 4, should it really be N_WORD_BYTES? */
391 offset
= HeaderValue(return_pc
->header
) * N_WORD_BYTES
;
393 /* Transport the whole code object */
394 code
= (struct code
*) ((uword_t
) return_pc
- offset
);
395 ncode
= trans_code(code
);
397 return ((lispobj
) LOW_WORD(ncode
) + offset
) | OTHER_POINTER_LOWTAG
;
400 /* On the 386, closures hold a pointer to the raw address instead of the
401 * function object, so we can use CALL [$FDEFN+const] to invoke
402 * the function without loading it into a register. Given that code
403 * objects don't move, we don't need to update anything, but we do
404 * have to figure out that the function is still live. */
406 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
408 scav_closure_header(lispobj
*where
, lispobj object
)
410 struct closure
*closure
;
413 closure
= (struct closure
*)where
;
414 fun
= closure
->fun
- FUN_RAW_ADDR_OFFSET
;
416 #ifdef LISP_FEATURE_GENCGC
417 /* The function may have moved so update the raw address. But
418 * don't write unnecessarily. */
419 if (closure
->fun
!= fun
+ FUN_RAW_ADDR_OFFSET
)
420 closure
->fun
= fun
+ FUN_RAW_ADDR_OFFSET
;
426 #if !(defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
428 scav_fun_header(lispobj
*where
, lispobj object
)
430 lose("attempted to scavenge a function header where=0x%08x object=0x%08x\n",
433 return 0; /* bogus return value to satisfy static type checking */
435 #endif /* LISP_FEATURE_X86 */
438 trans_fun_header(lispobj object
)
440 struct simple_fun
*fheader
;
442 struct code
*code
, *ncode
;
444 fheader
= (struct simple_fun
*) native_pointer(object
);
445 /* FIXME: was times 4, should it really be N_WORD_BYTES? */
446 offset
= HeaderValue(fheader
->header
) * N_WORD_BYTES
;
448 /* Transport the whole code object */
449 code
= (struct code
*) ((uword_t
) fheader
- offset
);
450 ncode
= trans_code(code
);
452 return ((lispobj
) LOW_WORD(ncode
) + offset
) | FUN_POINTER_LOWTAG
;
461 trans_instance(lispobj object
)
466 gc_assert(is_lisp_pointer(object
));
468 header
= *((lispobj
*) native_pointer(object
));
469 length
= instance_length(header
) + 1;
470 length
= CEILING(length
, 2);
472 return copy_object(object
, length
);
476 size_instance(lispobj
*where
)
482 length
= instance_length(header
) + 1;
483 length
= CEILING(length
, 2);
489 scav_instance_pointer(lispobj
*where
, lispobj object
)
491 lispobj copy
, *first_pointer
;
493 /* Object is a pointer into from space - not a FP. */
494 copy
= trans_instance(object
);
496 #ifdef LISP_FEATURE_GENCGC
497 gc_assert(copy
!= object
);
500 first_pointer
= (lispobj
*) native_pointer(object
);
501 set_forwarding_pointer(first_pointer
,copy
);
512 static lispobj
trans_list(lispobj object
);
515 scav_list_pointer(lispobj
*where
, lispobj object
)
517 lispobj first
, *first_pointer
;
519 gc_assert(is_lisp_pointer(object
));
521 /* Object is a pointer into from space - not FP. */
522 first_pointer
= (lispobj
*) native_pointer(object
);
524 first
= trans_list(object
);
525 gc_assert(first
!= object
);
527 /* Set forwarding pointer */
528 set_forwarding_pointer(first_pointer
, first
);
530 gc_assert(is_lisp_pointer(first
));
531 gc_assert(!from_space_p(first
));
539 trans_list(lispobj object
)
541 lispobj new_list_pointer
;
542 struct cons
*cons
, *new_cons
;
545 cons
= (struct cons
*) native_pointer(object
);
548 new_cons
= (struct cons
*)
549 gc_general_alloc(sizeof(struct cons
), BOXED_PAGE_FLAG
, ALLOC_QUICK
);
550 new_cons
->car
= cons
->car
;
551 new_cons
->cdr
= cons
->cdr
; /* updated later */
552 new_list_pointer
= make_lispobj(new_cons
,lowtag_of(object
));
554 /* Grab the cdr: set_forwarding_pointer will clobber it in GENCGC */
557 set_forwarding_pointer((lispobj
*)cons
, new_list_pointer
);
559 /* Try to linearize the list in the cdr direction to help reduce
563 struct cons
*cdr_cons
, *new_cdr_cons
;
565 if(lowtag_of(cdr
) != LIST_POINTER_LOWTAG
||
566 !from_space_p(cdr
) ||
567 forwarding_pointer_p((lispobj
*)native_pointer(cdr
)))
570 cdr_cons
= (struct cons
*) native_pointer(cdr
);
573 new_cdr_cons
= (struct cons
*)
574 gc_general_alloc(sizeof(struct cons
), BOXED_PAGE_FLAG
, ALLOC_QUICK
);
575 new_cdr_cons
->car
= cdr_cons
->car
;
576 new_cdr_cons
->cdr
= cdr_cons
->cdr
;
577 new_cdr
= make_lispobj(new_cdr_cons
, lowtag_of(cdr
));
579 /* Grab the cdr before it is clobbered. */
581 set_forwarding_pointer((lispobj
*)cdr_cons
, new_cdr
);
583 /* Update the cdr of the last cons copied into new space to
584 * keep the newspace scavenge from having to do it. */
585 new_cons
->cdr
= new_cdr
;
587 new_cons
= new_cdr_cons
;
590 return new_list_pointer
;
595 * scavenging and transporting other pointers
599 scav_other_pointer(lispobj
*where
, lispobj object
)
601 lispobj first
, *first_pointer
;
603 gc_assert(is_lisp_pointer(object
));
605 /* Object is a pointer into from space - not FP. */
606 first_pointer
= (lispobj
*) native_pointer(object
);
607 first
= (transother
[widetag_of(*first_pointer
)])(object
);
609 if (first
!= object
) {
610 set_forwarding_pointer(first_pointer
, first
);
611 #ifdef LISP_FEATURE_GENCGC
615 #ifndef LISP_FEATURE_GENCGC
618 gc_assert(is_lisp_pointer(first
));
619 gc_assert(!from_space_p(first
));
625 * immediate, boxed, and unboxed objects
629 size_pointer(lispobj
*where
)
635 scav_immediate(lispobj
*where
, lispobj object
)
641 trans_immediate(lispobj object
)
643 lose("trying to transport an immediate\n");
644 return NIL
; /* bogus return value to satisfy static type checking */
648 size_immediate(lispobj
*where
)
655 scav_boxed(lispobj
*where
, lispobj object
)
660 boolean
positive_bignum_logbitp(int index
, struct bignum
* bignum
)
662 /* If the bignum in the layout has another pointer to it (besides the layout)
663 acting as a root, and which is scavenged first, then transporting the
664 bignum causes the layout to see a FP, as would copying an instance whose
665 layout that is. This is a nearly impossible scenario to create organically
666 in Lisp, because mostly nothing ever looks again at that exact (EQ) bignum
667 except for a few things that would cause it to be pinned anyway,
668 such as it being kept in a local variable during structure manipulation.
669 See 'interleaved-raw.impure.lisp' for a way to trigger this */
670 if (forwarding_pointer_p((lispobj
*)bignum
)) {
671 lispobj
*forwarded
= forwarding_pointer_value((lispobj
*)bignum
);
673 fprintf(stderr
, "GC bignum_logbitp(): fwd from %p to %p\n",
674 (void*)bignum
, (void*)forwarded
);
676 bignum
= (struct bignum
*)native_pointer((lispobj
)forwarded
);
679 int len
= HeaderValue(bignum
->header
);
680 int word_index
= index
/ N_WORD_BITS
;
681 int bit_index
= index
% N_WORD_BITS
;
682 if (word_index
>= len
) {
683 // just return 0 since the marking logic does not allow negative bignums
686 return (bignum
->digits
[word_index
] >> bit_index
) & 1;
690 // Helper function for stepping through the tagged slots of an instance in
691 // scav_instance and verify_space (which, as it happens, is not useful).
693 instance_scan_interleaved(void (*proc
)(lispobj
*, sword_t
),
694 lispobj
*instance_ptr
,
698 struct layout
*layout
= (struct layout
*)layout_obj
;
699 lispobj layout_bitmap
= layout
->bitmap
;
702 /* This code would be more efficient if the Lisp stored an additional format
703 of the same metadata - a vector of ranges of slot offsets to scan.
704 Each pair of vector elements would demarcate the start and end of a range
705 of offsets to be passed to the proc(). The vector could be either
706 (unsigned-byte 8) or (unsigned-byte 16) for compactness.
707 On the other hand, this may not be a bottleneck as-is */
709 ++instance_ptr
; // was supplied as the address of the header word
710 if (layout_bitmap
== 0) {
711 proc(instance_ptr
, n_words
);
712 } else if (fixnump(layout_bitmap
)) {
713 unsigned long bitmap
= fixnum_value(layout_bitmap
);
714 for (index
= 0; index
< n_words
; index
++, bitmap
>>= 1)
716 proc(instance_ptr
+ index
, 1);
717 } else { /* huge bitmap */
718 struct bignum
* bitmap
;
719 bitmap
= (struct bignum
*)native_pointer(layout_bitmap
);
720 for (index
= 0; index
< n_words
; index
++)
721 if (!positive_bignum_logbitp(index
, bitmap
))
722 proc(instance_ptr
+ index
, 1);
727 scav_instance(lispobj
*where
, lispobj header
)
729 // instance_length() is the number of words following the header including
730 // the layout. If this is an even number, it should be made odd so that
731 // scav_instance() always consumes an even number of words in total.
732 sword_t ntotal
= instance_length(header
) | 1;
733 lispobj
* layout
= (lispobj
*)instance_layout(where
);
737 layout
= native_pointer((lispobj
)layout
);
738 if (forwarding_pointer_p(layout
))
739 layout
= native_pointer((lispobj
)forwarding_pointer_value(layout
));
741 instance_scan_interleaved(scavenge
, where
, ntotal
, layout
);
747 trans_boxed(lispobj object
)
752 gc_assert(is_lisp_pointer(object
));
754 header
= *((lispobj
*) native_pointer(object
));
755 length
= HeaderValue(header
) + 1;
756 length
= CEILING(length
, 2);
758 return copy_object(object
, length
);
762 size_boxed(lispobj
*where
)
768 length
= HeaderValue(header
) + 1;
769 length
= CEILING(length
, 2);
775 trans_tiny_boxed(lispobj object
)
780 gc_assert(is_lisp_pointer(object
));
782 header
= *((lispobj
*) native_pointer(object
));
783 length
= (HeaderValue(header
) & 0xFF) + 1;
784 length
= CEILING(length
, 2);
786 return copy_object(object
, length
);
790 size_tiny_boxed(lispobj
*where
)
796 length
= (HeaderValue(header
) & 0xFF) + 1;
797 length
= CEILING(length
, 2);
802 /* Note: on the sparc we don't have to do anything special for fdefns, */
803 /* 'cause the raw-addr has a function lowtag. */
804 #if !defined(LISP_FEATURE_SPARC) && !defined(LISP_FEATURE_ARM)
806 scav_fdefn(lispobj
*where
, lispobj object
)
810 fdefn
= (struct fdefn
*)where
;
812 /* FSHOW((stderr, "scav_fdefn, function = %p, raw_addr = %p\n",
813 fdefn->fun, fdefn->raw_addr)); */
815 if ((char *)(fdefn
->fun
+ FUN_RAW_ADDR_OFFSET
) == fdefn
->raw_addr
) {
816 scavenge(where
+ 1, sizeof(struct fdefn
)/sizeof(lispobj
) - 1);
818 /* Don't write unnecessarily. */
819 if (fdefn
->raw_addr
!= (char *)(fdefn
->fun
+ FUN_RAW_ADDR_OFFSET
))
820 fdefn
->raw_addr
= (char *)(fdefn
->fun
+ FUN_RAW_ADDR_OFFSET
);
821 /* gc.c has more casts here, which may be relevant or alternatively
822 may be compiler warning defeaters. try
823 fdefn->raw_addr = ((char *) LOW_WORD(fdefn->fun)) + FUN_RAW_ADDR_OFFSET;
825 return sizeof(struct fdefn
) / sizeof(lispobj
);
833 scav_unboxed(lispobj
*where
, lispobj object
)
837 length
= HeaderValue(object
) + 1;
838 length
= CEILING(length
, 2);
844 trans_unboxed(lispobj object
)
850 gc_assert(is_lisp_pointer(object
));
852 header
= *((lispobj
*) native_pointer(object
));
853 length
= HeaderValue(header
) + 1;
854 length
= CEILING(length
, 2);
856 return copy_unboxed_object(object
, length
);
860 size_unboxed(lispobj
*where
)
866 length
= HeaderValue(header
) + 1;
867 length
= CEILING(length
, 2);
873 /* vector-like objects */
875 scav_base_string(lispobj
*where
, lispobj object
)
877 struct vector
*vector
;
878 sword_t length
, nwords
;
880 /* NOTE: Strings contain one more byte of data than the length */
881 /* slot indicates. */
883 vector
= (struct vector
*) where
;
884 length
= fixnum_value(vector
->length
) + 1;
885 nwords
= CEILING(NWORDS(length
, 8) + 2, 2);
890 trans_base_string(lispobj object
)
892 struct vector
*vector
;
893 sword_t length
, nwords
;
895 gc_assert(is_lisp_pointer(object
));
897 /* NOTE: A string contains one more byte of data (a terminating
898 * '\0' to help when interfacing with C functions) than indicated
899 * by the length slot. */
901 vector
= (struct vector
*) native_pointer(object
);
902 length
= fixnum_value(vector
->length
) + 1;
903 nwords
= CEILING(NWORDS(length
, 8) + 2, 2);
905 return copy_large_unboxed_object(object
, nwords
);
909 size_base_string(lispobj
*where
)
911 struct vector
*vector
;
912 sword_t length
, nwords
;
914 /* NOTE: A string contains one more byte of data (a terminating
915 * '\0' to help when interfacing with C functions) than indicated
916 * by the length slot. */
918 vector
= (struct vector
*) where
;
919 length
= fixnum_value(vector
->length
) + 1;
920 nwords
= CEILING(NWORDS(length
, 8) + 2, 2);
925 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
927 scav_character_string(lispobj
*where
, lispobj object
)
929 struct vector
*vector
;
932 /* NOTE: Strings contain one more byte of data than the length */
933 /* slot indicates. */
935 vector
= (struct vector
*) where
;
936 length
= fixnum_value(vector
->length
) + 1;
937 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
942 trans_character_string(lispobj object
)
944 struct vector
*vector
;
947 gc_assert(is_lisp_pointer(object
));
949 /* NOTE: A string contains one more byte of data (a terminating
950 * '\0' to help when interfacing with C functions) than indicated
951 * by the length slot. */
953 vector
= (struct vector
*) native_pointer(object
);
954 length
= fixnum_value(vector
->length
) + 1;
955 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
957 return copy_large_unboxed_object(object
, nwords
);
961 size_character_string(lispobj
*where
)
963 struct vector
*vector
;
966 /* NOTE: A string contains one more byte of data (a terminating
967 * '\0' to help when interfacing with C functions) than indicated
968 * by the length slot. */
970 vector
= (struct vector
*) where
;
971 length
= fixnum_value(vector
->length
) + 1;
972 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
979 trans_vector(lispobj object
)
981 struct vector
*vector
;
982 sword_t length
, nwords
;
984 gc_assert(is_lisp_pointer(object
));
986 vector
= (struct vector
*) native_pointer(object
);
988 length
= fixnum_value(vector
->length
);
989 nwords
= CEILING(length
+ 2, 2);
991 return copy_large_object(object
, nwords
);
995 size_vector(lispobj
*where
)
997 struct vector
*vector
;
998 sword_t length
, nwords
;
1000 vector
= (struct vector
*) where
;
1001 length
= fixnum_value(vector
->length
);
1002 nwords
= CEILING(length
+ 2, 2);
1008 scav_vector_nil(lispobj
*where
, lispobj object
)
1014 trans_vector_nil(lispobj object
)
1016 gc_assert(is_lisp_pointer(object
));
1017 return copy_unboxed_object(object
, 2);
1021 size_vector_nil(lispobj
*where
)
1023 /* Just the header word and the length word */
1028 scav_vector_bit(lispobj
*where
, lispobj object
)
1030 struct vector
*vector
;
1031 sword_t length
, nwords
;
1033 vector
= (struct vector
*) where
;
1034 length
= fixnum_value(vector
->length
);
1035 nwords
= CEILING(NWORDS(length
, 1) + 2, 2);
1041 trans_vector_bit(lispobj object
)
1043 struct vector
*vector
;
1044 sword_t length
, nwords
;
1046 gc_assert(is_lisp_pointer(object
));
1048 vector
= (struct vector
*) native_pointer(object
);
1049 length
= fixnum_value(vector
->length
);
1050 nwords
= CEILING(NWORDS(length
, 1) + 2, 2);
1052 return copy_large_unboxed_object(object
, nwords
);
1056 size_vector_bit(lispobj
*where
)
1058 struct vector
*vector
;
1059 sword_t length
, nwords
;
1061 vector
= (struct vector
*) where
;
1062 length
= fixnum_value(vector
->length
);
1063 nwords
= CEILING(NWORDS(length
, 1) + 2, 2);
1069 scav_vector_unsigned_byte_2(lispobj
*where
, lispobj object
)
1071 struct vector
*vector
;
1072 sword_t length
, nwords
;
1074 vector
= (struct vector
*) where
;
1075 length
= fixnum_value(vector
->length
);
1076 nwords
= CEILING(NWORDS(length
, 2) + 2, 2);
1082 trans_vector_unsigned_byte_2(lispobj object
)
1084 struct vector
*vector
;
1085 sword_t length
, nwords
;
1087 gc_assert(is_lisp_pointer(object
));
1089 vector
= (struct vector
*) native_pointer(object
);
1090 length
= fixnum_value(vector
->length
);
1091 nwords
= CEILING(NWORDS(length
, 2) + 2, 2);
1093 return copy_large_unboxed_object(object
, nwords
);
1097 size_vector_unsigned_byte_2(lispobj
*where
)
1099 struct vector
*vector
;
1100 sword_t length
, nwords
;
1102 vector
= (struct vector
*) where
;
1103 length
= fixnum_value(vector
->length
);
1104 nwords
= CEILING(NWORDS(length
, 2) + 2, 2);
1110 scav_vector_unsigned_byte_4(lispobj
*where
, lispobj object
)
1112 struct vector
*vector
;
1113 sword_t length
, nwords
;
1115 vector
= (struct vector
*) where
;
1116 length
= fixnum_value(vector
->length
);
1117 nwords
= CEILING(NWORDS(length
, 4) + 2, 2);
1123 trans_vector_unsigned_byte_4(lispobj object
)
1125 struct vector
*vector
;
1126 sword_t length
, nwords
;
1128 gc_assert(is_lisp_pointer(object
));
1130 vector
= (struct vector
*) native_pointer(object
);
1131 length
= fixnum_value(vector
->length
);
1132 nwords
= CEILING(NWORDS(length
, 4) + 2, 2);
1134 return copy_large_unboxed_object(object
, nwords
);
1137 size_vector_unsigned_byte_4(lispobj
*where
)
1139 struct vector
*vector
;
1140 sword_t length
, nwords
;
1142 vector
= (struct vector
*) where
;
1143 length
= fixnum_value(vector
->length
);
1144 nwords
= CEILING(NWORDS(length
, 4) + 2, 2);
1151 scav_vector_unsigned_byte_8(lispobj
*where
, lispobj object
)
1153 struct vector
*vector
;
1154 sword_t length
, nwords
;
1156 vector
= (struct vector
*) where
;
1157 length
= fixnum_value(vector
->length
);
1158 nwords
= CEILING(NWORDS(length
, 8) + 2, 2);
1163 /*********************/
1168 trans_vector_unsigned_byte_8(lispobj object
)
1170 struct vector
*vector
;
1171 sword_t length
, nwords
;
1173 gc_assert(is_lisp_pointer(object
));
1175 vector
= (struct vector
*) native_pointer(object
);
1176 length
= fixnum_value(vector
->length
);
1177 nwords
= CEILING(NWORDS(length
, 8) + 2, 2);
1179 return copy_large_unboxed_object(object
, nwords
);
1183 size_vector_unsigned_byte_8(lispobj
*where
)
1185 struct vector
*vector
;
1186 sword_t length
, nwords
;
1188 vector
= (struct vector
*) where
;
1189 length
= fixnum_value(vector
->length
);
1190 nwords
= CEILING(NWORDS(length
, 8) + 2, 2);
1197 scav_vector_unsigned_byte_16(lispobj
*where
, lispobj object
)
1199 struct vector
*vector
;
1200 sword_t length
, nwords
;
1202 vector
= (struct vector
*) where
;
1203 length
= fixnum_value(vector
->length
);
1204 nwords
= CEILING(NWORDS(length
, 16) + 2, 2);
1210 trans_vector_unsigned_byte_16(lispobj object
)
1212 struct vector
*vector
;
1213 sword_t length
, nwords
;
1215 gc_assert(is_lisp_pointer(object
));
1217 vector
= (struct vector
*) native_pointer(object
);
1218 length
= fixnum_value(vector
->length
);
1219 nwords
= CEILING(NWORDS(length
, 16) + 2, 2);
1221 return copy_large_unboxed_object(object
, nwords
);
1225 size_vector_unsigned_byte_16(lispobj
*where
)
1227 struct vector
*vector
;
1228 sword_t length
, nwords
;
1230 vector
= (struct vector
*) where
;
1231 length
= fixnum_value(vector
->length
);
1232 nwords
= CEILING(NWORDS(length
, 16) + 2, 2);
1238 scav_vector_unsigned_byte_32(lispobj
*where
, lispobj object
)
1240 struct vector
*vector
;
1241 sword_t length
, nwords
;
1243 vector
= (struct vector
*) where
;
1244 length
= fixnum_value(vector
->length
);
1245 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
1251 trans_vector_unsigned_byte_32(lispobj object
)
1253 struct vector
*vector
;
1254 sword_t length
, nwords
;
1256 gc_assert(is_lisp_pointer(object
));
1258 vector
= (struct vector
*) native_pointer(object
);
1259 length
= fixnum_value(vector
->length
);
1260 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
1262 return copy_large_unboxed_object(object
, nwords
);
1266 size_vector_unsigned_byte_32(lispobj
*where
)
1268 struct vector
*vector
;
1269 sword_t length
, nwords
;
1271 vector
= (struct vector
*) where
;
1272 length
= fixnum_value(vector
->length
);
1273 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
1278 #if N_WORD_BITS == 64
1280 scav_vector_unsigned_byte_64(lispobj
*where
, lispobj object
)
1282 struct vector
*vector
;
1283 sword_t length
, nwords
;
1285 vector
= (struct vector
*) where
;
1286 length
= fixnum_value(vector
->length
);
1287 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1293 trans_vector_unsigned_byte_64(lispobj object
)
1295 struct vector
*vector
;
1296 sword_t length
, nwords
;
1298 gc_assert(is_lisp_pointer(object
));
1300 vector
= (struct vector
*) native_pointer(object
);
1301 length
= fixnum_value(vector
->length
);
1302 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1304 return copy_large_unboxed_object(object
, nwords
);
1308 size_vector_unsigned_byte_64(lispobj
*where
)
1310 struct vector
*vector
;
1311 sword_t length
, nwords
;
1313 vector
= (struct vector
*) where
;
1314 length
= fixnum_value(vector
->length
);
1315 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1322 scav_vector_single_float(lispobj
*where
, lispobj object
)
1324 struct vector
*vector
;
1325 sword_t length
, nwords
;
1327 vector
= (struct vector
*) where
;
1328 length
= fixnum_value(vector
->length
);
1329 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
1335 trans_vector_single_float(lispobj object
)
1337 struct vector
*vector
;
1338 sword_t length
, nwords
;
1340 gc_assert(is_lisp_pointer(object
));
1342 vector
= (struct vector
*) native_pointer(object
);
1343 length
= fixnum_value(vector
->length
);
1344 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
1346 return copy_large_unboxed_object(object
, nwords
);
1350 size_vector_single_float(lispobj
*where
)
1352 struct vector
*vector
;
1353 sword_t length
, nwords
;
1355 vector
= (struct vector
*) where
;
1356 length
= fixnum_value(vector
->length
);
1357 nwords
= CEILING(NWORDS(length
, 32) + 2, 2);
1363 scav_vector_double_float(lispobj
*where
, lispobj object
)
1365 struct vector
*vector
;
1366 sword_t length
, nwords
;
1368 vector
= (struct vector
*) where
;
1369 length
= fixnum_value(vector
->length
);
1370 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1376 trans_vector_double_float(lispobj object
)
1378 struct vector
*vector
;
1379 sword_t length
, nwords
;
1381 gc_assert(is_lisp_pointer(object
));
1383 vector
= (struct vector
*) native_pointer(object
);
1384 length
= fixnum_value(vector
->length
);
1385 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1387 return copy_large_unboxed_object(object
, nwords
);
1391 size_vector_double_float(lispobj
*where
)
1393 struct vector
*vector
;
1394 sword_t length
, nwords
;
1396 vector
= (struct vector
*) where
;
1397 length
= fixnum_value(vector
->length
);
1398 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1403 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
1405 scav_vector_long_float(lispobj
*where
, lispobj object
)
1407 struct vector
*vector
;
1408 long length
, nwords
;
1410 vector
= (struct vector
*) where
;
1411 length
= fixnum_value(vector
->length
);
1412 nwords
= CEILING(length
*
1419 trans_vector_long_float(lispobj object
)
1421 struct vector
*vector
;
1422 long length
, nwords
;
1424 gc_assert(is_lisp_pointer(object
));
1426 vector
= (struct vector
*) native_pointer(object
);
1427 length
= fixnum_value(vector
->length
);
1428 nwords
= CEILING(length
* LONG_FLOAT_SIZE
+ 2, 2);
1430 return copy_large_unboxed_object(object
, nwords
);
1434 size_vector_long_float(lispobj
*where
)
1436 struct vector
*vector
;
1437 sword_t length
, nwords
;
1439 vector
= (struct vector
*) where
;
1440 length
= fixnum_value(vector
->length
);
1441 nwords
= CEILING(length
* LONG_FLOAT_SIZE
+ 2, 2);
1448 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
1450 scav_vector_complex_single_float(lispobj
*where
, lispobj object
)
1452 struct vector
*vector
;
1453 sword_t length
, nwords
;
1455 vector
= (struct vector
*) where
;
1456 length
= fixnum_value(vector
->length
);
1457 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1463 trans_vector_complex_single_float(lispobj object
)
1465 struct vector
*vector
;
1466 sword_t length
, nwords
;
1468 gc_assert(is_lisp_pointer(object
));
1470 vector
= (struct vector
*) native_pointer(object
);
1471 length
= fixnum_value(vector
->length
);
1472 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1474 return copy_large_unboxed_object(object
, nwords
);
1478 size_vector_complex_single_float(lispobj
*where
)
1480 struct vector
*vector
;
1481 sword_t length
, nwords
;
1483 vector
= (struct vector
*) where
;
1484 length
= fixnum_value(vector
->length
);
1485 nwords
= CEILING(NWORDS(length
, 64) + 2, 2);
1491 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
1493 scav_vector_complex_double_float(lispobj
*where
, lispobj object
)
1495 struct vector
*vector
;
1496 sword_t length
, nwords
;
1498 vector
= (struct vector
*) where
;
1499 length
= fixnum_value(vector
->length
);
1500 nwords
= CEILING(NWORDS(length
, 128) + 2, 2);
1506 trans_vector_complex_double_float(lispobj object
)
1508 struct vector
*vector
;
1509 sword_t length
, nwords
;
1511 gc_assert(is_lisp_pointer(object
));
1513 vector
= (struct vector
*) native_pointer(object
);
1514 length
= fixnum_value(vector
->length
);
1515 nwords
= CEILING(NWORDS(length
, 128) + 2, 2);
1517 return copy_large_unboxed_object(object
, nwords
);
1521 size_vector_complex_double_float(lispobj
*where
)
1523 struct vector
*vector
;
1524 sword_t length
, nwords
;
1526 vector
= (struct vector
*) where
;
1527 length
= fixnum_value(vector
->length
);
1528 nwords
= CEILING(NWORDS(length
, 128) + 2, 2);
1535 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
1537 scav_vector_complex_long_float(lispobj
*where
, lispobj object
)
1539 struct vector
*vector
;
1540 sword_t length
, nwords
;
1542 vector
= (struct vector
*) where
;
1543 length
= fixnum_value(vector
->length
);
1544 nwords
= CEILING(length
* (2* LONG_FLOAT_SIZE
) + 2, 2);
1550 trans_vector_complex_long_float(lispobj object
)
1552 struct vector
*vector
;
1553 long length
, nwords
;
1555 gc_assert(is_lisp_pointer(object
));
1557 vector
= (struct vector
*) native_pointer(object
);
1558 length
= fixnum_value(vector
->length
);
1559 nwords
= CEILING(length
* (2*LONG_FLOAT_SIZE
) + 2, 2);
1561 return copy_large_unboxed_object(object
, nwords
);
1565 size_vector_complex_long_float(lispobj
*where
)
1567 struct vector
*vector
;
1568 long length
, nwords
;
1570 vector
= (struct vector
*) where
;
1571 length
= fixnum_value(vector
->length
);
1572 nwords
= CEILING(length
* (2*LONG_FLOAT_SIZE
) + 2, 2);
1578 #define WEAK_POINTER_NWORDS \
1579 CEILING((sizeof(struct weak_pointer) / sizeof(lispobj)), 2)
1582 trans_weak_pointer(lispobj object
)
1585 #ifndef LISP_FEATURE_GENCGC
1586 struct weak_pointer
*wp
;
1588 gc_assert(is_lisp_pointer(object
));
1590 #if defined(DEBUG_WEAK)
1591 printf("Transporting weak pointer from 0x%08x\n", object
);
1594 /* Need to remember where all the weak pointers are that have */
1595 /* been transported so they can be fixed up in a post-GC pass. */
1597 copy
= copy_object(object
, WEAK_POINTER_NWORDS
);
1598 #ifndef LISP_FEATURE_GENCGC
1599 wp
= (struct weak_pointer
*) native_pointer(copy
);
1601 gc_assert(widetag_of(wp
->header
)==WEAK_POINTER_WIDETAG
);
1602 /* Push the weak pointer onto the list of weak pointers. */
1603 wp
->next
= (struct weak_pointer
*)LOW_WORD(weak_pointers
);
1610 size_weak_pointer(lispobj
*where
)
1612 return WEAK_POINTER_NWORDS
;
1616 void scan_weak_pointers(void)
1618 struct weak_pointer
*wp
, *next_wp
;
1619 for (wp
= weak_pointers
, next_wp
= NULL
; wp
!= NULL
; wp
= next_wp
) {
1620 lispobj value
= wp
->value
;
1621 lispobj
*first_pointer
;
1622 gc_assert(widetag_of(wp
->header
)==WEAK_POINTER_WIDETAG
);
1626 if (next_wp
== wp
) /* gencgc uses a ref to self for end of list */
1629 if (!(is_lisp_pointer(value
) && from_space_p(value
)))
1632 /* Now, we need to check whether the object has been forwarded. If
1633 * it has been, the weak pointer is still good and needs to be
1634 * updated. Otherwise, the weak pointer needs to be nil'ed
1637 first_pointer
= (lispobj
*)native_pointer(value
);
1639 if (forwarding_pointer_p(first_pointer
)) {
1641 (lispobj
)LOW_WORD(forwarding_pointer_value(first_pointer
));
1653 #if N_WORD_BITS == 32
1654 #define EQ_HASH_MASK 0x1fffffff
1655 #elif N_WORD_BITS == 64
1656 #define EQ_HASH_MASK 0x1fffffffffffffff
1659 /* Compute the EQ-hash of KEY. This must match POINTER-HASH in
1660 * target-hash-table.lisp. */
1661 #define EQ_HASH(key) ((key) & EQ_HASH_MASK)
1663 /* List of weak hash tables chained through their NEXT-WEAK-HASH-TABLE
1664 * slot. Set to NULL at the end of a collection.
1666 * This is not optimal because, when a table is tenured, it won't be
1667 * processed automatically; only the yougest generation is GC'd by
1668 * default. On the other hand, all applications will need an
1669 * occasional full GC anyway, so it's not that bad either. */
1670 struct hash_table
*weak_hash_tables
= NULL
;
1672 /* Return true if OBJ has already survived the current GC. */
1674 survived_gc_yet (lispobj obj
)
1676 return (!is_lisp_pointer(obj
) || !from_space_p(obj
) ||
1677 forwarding_pointer_p(native_pointer(obj
)));
1681 weak_hash_entry_alivep (lispobj weakness
, lispobj key
, lispobj value
)
1685 return survived_gc_yet(key
);
1687 return survived_gc_yet(value
);
1689 return (survived_gc_yet(key
) || survived_gc_yet(value
));
1691 return (survived_gc_yet(key
) && survived_gc_yet(value
));
1694 /* Shut compiler up. */
1699 /* Return the beginning of data in ARRAY (skipping the header and the
1700 * length) or NULL if it isn't an array of the specified widetag after
1702 static inline lispobj
*
1703 get_array_data (lispobj array
, int widetag
, uword_t
*length
)
1705 if (is_lisp_pointer(array
) &&
1706 (widetag_of(*(lispobj
*)native_pointer(array
)) == widetag
)) {
1708 *length
= fixnum_value(((lispobj
*)native_pointer(array
))[1]);
1709 return ((lispobj
*)native_pointer(array
)) + 2;
1715 /* Only need to worry about scavenging the _real_ entries in the
1716 * table. Phantom entries such as the hash table itself at index 0 and
1717 * the empty marker at index 1 were scavenged by scav_vector that
1718 * either called this function directly or arranged for it to be
1719 * called later by pushing the hash table onto weak_hash_tables. */
1721 scav_hash_table_entries (struct hash_table
*hash_table
)
1725 lispobj
*index_vector
;
1727 lispobj
*next_vector
;
1728 uword_t next_vector_length
;
1729 lispobj
*hash_vector
;
1730 uword_t hash_vector_length
;
1731 lispobj empty_symbol
;
1732 lispobj weakness
= hash_table
->weakness
;
1735 kv_vector
= get_array_data(hash_table
->table
,
1736 SIMPLE_VECTOR_WIDETAG
, &kv_length
);
1737 if (kv_vector
== NULL
)
1738 lose("invalid kv_vector %x\n", hash_table
->table
);
1740 index_vector
= get_array_data(hash_table
->index_vector
,
1741 SIMPLE_ARRAY_WORD_WIDETAG
, &length
);
1742 if (index_vector
== NULL
)
1743 lose("invalid index_vector %x\n", hash_table
->index_vector
);
1745 next_vector
= get_array_data(hash_table
->next_vector
,
1746 SIMPLE_ARRAY_WORD_WIDETAG
,
1747 &next_vector_length
);
1748 if (next_vector
== NULL
)
1749 lose("invalid next_vector %x\n", hash_table
->next_vector
);
1751 hash_vector
= get_array_data(hash_table
->hash_vector
,
1752 SIMPLE_ARRAY_WORD_WIDETAG
,
1753 &hash_vector_length
);
1754 if (hash_vector
!= NULL
)
1755 gc_assert(hash_vector_length
== next_vector_length
);
1757 /* These lengths could be different as the index_vector can be a
1758 * different length from the others, a larger index_vector could
1759 * help reduce collisions. */
1760 gc_assert(next_vector_length
*2 == kv_length
);
1762 empty_symbol
= kv_vector
[1];
1763 /* fprintf(stderr,"* empty_symbol = %x\n", empty_symbol);*/
1764 if (widetag_of(*(lispobj
*)native_pointer(empty_symbol
)) !=
1765 SYMBOL_HEADER_WIDETAG
) {
1766 lose("not a symbol where empty-hash-table-slot symbol expected: %x\n",
1767 *(lispobj
*)native_pointer(empty_symbol
));
1770 /* Work through the KV vector. */
1771 for (i
= 1; i
< next_vector_length
; i
++) {
1772 lispobj old_key
= kv_vector
[2*i
];
1773 lispobj value
= kv_vector
[2*i
+1];
1774 if ((weakness
== NIL
) ||
1775 weak_hash_entry_alivep(weakness
, old_key
, value
)) {
1777 /* Scavenge the key and value. */
1778 scavenge(&kv_vector
[2*i
],2);
1780 /* If an EQ-based key has moved, mark the hash-table for
1782 if (!hash_vector
|| hash_vector
[i
] == MAGIC_HASH_VECTOR_VALUE
) {
1783 lispobj new_key
= kv_vector
[2*i
];
1784 // FIXME: many EQ-based sxhash values are insensitive
1785 // to object movement. The most important one is SYMBOL,
1786 // but others also carry around a hash value: LAYOUT, CLASSOID,
1787 // and STANDARD-[FUNCALLABLE-]INSTANCE.
1788 // If old_key is any of those, don't set needs_rehash_p.
1789 if (old_key
!= new_key
&& new_key
!= empty_symbol
) {
1790 hash_table
->needs_rehash_p
= T
;
1798 scav_vector (lispobj
*where
, lispobj object
)
1801 struct hash_table
*hash_table
;
1803 /* SB-VM:VECTOR-VALID-HASHING-SUBTYPE is set for EQ-based and weak
1804 * hash tables in the Lisp HASH-TABLE code to indicate need for
1805 * special GC support. */
1806 if (HeaderValue(object
) == subtype_VectorNormal
)
1809 kv_length
= fixnum_value(where
[1]);
1810 /*FSHOW((stderr,"/kv_length = %d\n", kv_length));*/
1812 /* Scavenge element 0, which may be a hash-table structure. */
1813 scavenge(where
+2, 1);
1814 if (!is_lisp_pointer(where
[2])) {
1815 /* This'll happen when REHASH clears the header of old-kv-vector
1816 * and fills it with zero, but some other thread simulatenously
1817 * sets the header in %%PUTHASH.
1820 "Warning: no pointer at %p in hash table: this indicates "
1821 "non-fatal corruption caused by concurrent access to a "
1822 "hash-table from multiple threads. Any accesses to "
1823 "hash-tables shared between threads should be protected "
1824 "by locks.\n", (void*)&where
[2]);
1825 // We've scavenged three words.
1828 hash_table
= (struct hash_table
*)native_pointer(where
[2]);
1829 /*FSHOW((stderr,"/hash_table = %x\n", hash_table));*/
1830 if (widetag_of(hash_table
->header
) != INSTANCE_HEADER_WIDETAG
) {
1831 lose("hash table not instance (%x at %x)\n",
1836 /* Scavenge element 1, which should be some internal symbol that
1837 * the hash table code reserves for marking empty slots. */
1838 scavenge(where
+3, 1);
1839 if (!is_lisp_pointer(where
[3])) {
1840 lose("not empty-hash-table-slot symbol pointer: %x\n", where
[3]);
1843 /* Scavenge hash table, which will fix the positions of the other
1844 * needed objects. */
1845 scavenge((lispobj
*)hash_table
,
1846 CEILING(sizeof(struct hash_table
) / sizeof(lispobj
), 2));
1848 /* Cross-check the kv_vector. */
1849 if (where
!= (lispobj
*)native_pointer(hash_table
->table
)) {
1850 lose("hash_table table!=this table %x\n", hash_table
->table
);
1853 if (hash_table
->weakness
== NIL
) {
1854 scav_hash_table_entries(hash_table
);
1856 /* Delay scavenging of this table by pushing it onto
1857 * weak_hash_tables (if it's not there already) for the weak
1859 if (hash_table
->next_weak_hash_table
== NIL
) {
1860 hash_table
->next_weak_hash_table
= (lispobj
)weak_hash_tables
;
1861 weak_hash_tables
= hash_table
;
1865 return (CEILING(kv_length
+ 2, 2));
1869 scav_weak_hash_tables (void)
1871 struct hash_table
*table
;
1873 /* Scavenge entries whose triggers are known to survive. */
1874 for (table
= weak_hash_tables
; table
!= NULL
;
1875 table
= (struct hash_table
*)table
->next_weak_hash_table
) {
1876 scav_hash_table_entries(table
);
1880 /* Walk through the chain whose first element is *FIRST and remove
1881 * dead weak entries. */
1883 scan_weak_hash_table_chain (struct hash_table
*hash_table
, lispobj
*prev
,
1884 lispobj
*kv_vector
, lispobj
*index_vector
,
1885 lispobj
*next_vector
, lispobj
*hash_vector
,
1886 lispobj empty_symbol
, lispobj weakness
)
1888 unsigned index
= *prev
;
1890 unsigned next
= next_vector
[index
];
1891 lispobj key
= kv_vector
[2 * index
];
1892 lispobj value
= kv_vector
[2 * index
+ 1];
1893 gc_assert(key
!= empty_symbol
);
1894 gc_assert(value
!= empty_symbol
);
1895 if (!weak_hash_entry_alivep(weakness
, key
, value
)) {
1896 unsigned count
= fixnum_value(hash_table
->number_entries
);
1897 gc_assert(count
> 0);
1899 hash_table
->number_entries
= make_fixnum(count
- 1);
1900 next_vector
[index
] = fixnum_value(hash_table
->next_free_kv
);
1901 hash_table
->next_free_kv
= make_fixnum(index
);
1902 kv_vector
[2 * index
] = empty_symbol
;
1903 kv_vector
[2 * index
+ 1] = empty_symbol
;
1905 hash_vector
[index
] = MAGIC_HASH_VECTOR_VALUE
;
1907 prev
= &next_vector
[index
];
1914 scan_weak_hash_table (struct hash_table
*hash_table
)
1917 lispobj
*index_vector
;
1918 uword_t length
= 0; /* prevent warning */
1919 lispobj
*next_vector
;
1920 uword_t next_vector_length
= 0; /* prevent warning */
1921 lispobj
*hash_vector
;
1922 lispobj empty_symbol
;
1923 lispobj weakness
= hash_table
->weakness
;
1926 kv_vector
= get_array_data(hash_table
->table
,
1927 SIMPLE_VECTOR_WIDETAG
, NULL
);
1928 index_vector
= get_array_data(hash_table
->index_vector
,
1929 SIMPLE_ARRAY_WORD_WIDETAG
, &length
);
1930 next_vector
= get_array_data(hash_table
->next_vector
,
1931 SIMPLE_ARRAY_WORD_WIDETAG
,
1932 &next_vector_length
);
1933 hash_vector
= get_array_data(hash_table
->hash_vector
,
1934 SIMPLE_ARRAY_WORD_WIDETAG
, NULL
);
1935 empty_symbol
= kv_vector
[1];
1937 for (i
= 0; i
< length
; i
++) {
1938 scan_weak_hash_table_chain(hash_table
, &index_vector
[i
],
1939 kv_vector
, index_vector
, next_vector
,
1940 hash_vector
, empty_symbol
, weakness
);
1944 /* Remove dead entries from weak hash tables. */
1946 scan_weak_hash_tables (void)
1948 struct hash_table
*table
, *next
;
1950 for (table
= weak_hash_tables
; table
!= NULL
; table
= next
) {
1951 next
= (struct hash_table
*)table
->next_weak_hash_table
;
1952 table
->next_weak_hash_table
= NIL
;
1953 scan_weak_hash_table(table
);
1956 weak_hash_tables
= NULL
;
1965 scav_lose(lispobj
*where
, lispobj object
)
1967 lose("no scavenge function for object %p (widetag 0x%x)\n",
1969 widetag_of(*where
));
1971 return 0; /* bogus return value to satisfy static type checking */
1975 trans_lose(lispobj object
)
1977 lose("no transport function for object %p (widetag 0x%x)\n",
1979 widetag_of(*(lispobj
*)native_pointer(object
)));
1980 return NIL
; /* bogus return value to satisfy static type checking */
1984 size_lose(lispobj
*where
)
1986 lose("no size function for object at %p (widetag 0x%x)\n",
1988 widetag_of(*where
));
1989 return 1; /* bogus return value to satisfy static type checking */
1998 gc_init_tables(void)
2002 /* Set default value in all slots of scavenge table. FIXME
2003 * replace this gnarly sizeof with something based on
2005 for (i
= 0; i
< ((sizeof scavtab
)/(sizeof scavtab
[0])); i
++) {
2006 scavtab
[i
] = scav_lose
;
2009 /* For each type which can be selected by the lowtag alone, set
2010 * multiple entries in our widetag scavenge table (one for each
2011 * possible value of the high bits).
2014 for (i
= 0; i
< (1<<(N_WIDETAG_BITS
-N_LOWTAG_BITS
)); i
++) {
2015 for (j
= 0; j
< (1<<N_LOWTAG_BITS
); j
++) {
2017 scavtab
[j
|(i
<<N_LOWTAG_BITS
)] = scav_immediate
;
2020 scavtab
[FUN_POINTER_LOWTAG
|(i
<<N_LOWTAG_BITS
)] = scav_fun_pointer
;
2021 /* skipping OTHER_IMMEDIATE_0_LOWTAG */
2022 scavtab
[LIST_POINTER_LOWTAG
|(i
<<N_LOWTAG_BITS
)] = scav_list_pointer
;
2023 scavtab
[INSTANCE_POINTER_LOWTAG
|(i
<<N_LOWTAG_BITS
)] =
2024 scav_instance_pointer
;
2025 /* skipping OTHER_IMMEDIATE_1_LOWTAG */
2026 scavtab
[OTHER_POINTER_LOWTAG
|(i
<<N_LOWTAG_BITS
)] = scav_other_pointer
;
2029 /* Other-pointer types (those selected by all eight bits of the
2030 * tag) get one entry each in the scavenge table. */
2031 scavtab
[BIGNUM_WIDETAG
] = scav_unboxed
;
2032 scavtab
[RATIO_WIDETAG
] = scav_boxed
;
2033 #if N_WORD_BITS == 64
2034 scavtab
[SINGLE_FLOAT_WIDETAG
] = scav_immediate
;
2036 scavtab
[SINGLE_FLOAT_WIDETAG
] = scav_unboxed
;
2038 scavtab
[DOUBLE_FLOAT_WIDETAG
] = scav_unboxed
;
2039 #ifdef LONG_FLOAT_WIDETAG
2040 scavtab
[LONG_FLOAT_WIDETAG
] = scav_unboxed
;
2042 scavtab
[COMPLEX_WIDETAG
] = scav_boxed
;
2043 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
2044 scavtab
[COMPLEX_SINGLE_FLOAT_WIDETAG
] = scav_unboxed
;
2046 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
2047 scavtab
[COMPLEX_DOUBLE_FLOAT_WIDETAG
] = scav_unboxed
;
2049 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
2050 scavtab
[COMPLEX_LONG_FLOAT_WIDETAG
] = scav_unboxed
;
2052 #ifdef SIMD_PACK_WIDETAG
2053 scavtab
[SIMD_PACK_WIDETAG
] = scav_unboxed
;
2055 scavtab
[SIMPLE_ARRAY_WIDETAG
] = scav_boxed
;
2056 scavtab
[SIMPLE_BASE_STRING_WIDETAG
] = scav_base_string
;
2057 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
2058 scavtab
[SIMPLE_CHARACTER_STRING_WIDETAG
] = scav_character_string
;
2060 scavtab
[SIMPLE_BIT_VECTOR_WIDETAG
] = scav_vector_bit
;
2061 scavtab
[SIMPLE_ARRAY_NIL_WIDETAG
] = scav_vector_nil
;
2062 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG
] =
2063 scav_vector_unsigned_byte_2
;
2064 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG
] =
2065 scav_vector_unsigned_byte_4
;
2066 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG
] =
2067 scav_vector_unsigned_byte_8
;
2068 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG
] =
2069 scav_vector_unsigned_byte_8
;
2070 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG
] =
2071 scav_vector_unsigned_byte_16
;
2072 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG
] =
2073 scav_vector_unsigned_byte_16
;
2074 #if (N_WORD_BITS == 32)
2075 scavtab
[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG
] =
2076 scav_vector_unsigned_byte_32
;
2078 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG
] =
2079 scav_vector_unsigned_byte_32
;
2080 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
] =
2081 scav_vector_unsigned_byte_32
;
2082 #if (N_WORD_BITS == 64)
2083 scavtab
[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG
] =
2084 scav_vector_unsigned_byte_64
;
2086 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
2087 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
] =
2088 scav_vector_unsigned_byte_64
;
2090 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
2091 scavtab
[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
] =
2092 scav_vector_unsigned_byte_64
;
2094 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
2095 scavtab
[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
] = scav_vector_unsigned_byte_8
;
2097 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
2098 scavtab
[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
] =
2099 scav_vector_unsigned_byte_16
;
2101 #if (N_WORD_BITS == 32)
2102 scavtab
[SIMPLE_ARRAY_FIXNUM_WIDETAG
] =
2103 scav_vector_unsigned_byte_32
;
2105 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
2106 scavtab
[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
] =
2107 scav_vector_unsigned_byte_32
;
2109 #if (N_WORD_BITS == 64)
2110 scavtab
[SIMPLE_ARRAY_FIXNUM_WIDETAG
] =
2111 scav_vector_unsigned_byte_64
;
2113 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
2114 scavtab
[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
] =
2115 scav_vector_unsigned_byte_64
;
2117 scavtab
[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG
] = scav_vector_single_float
;
2118 scavtab
[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG
] = scav_vector_double_float
;
2119 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
2120 scavtab
[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
] = scav_vector_long_float
;
2122 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
2123 scavtab
[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
] =
2124 scav_vector_complex_single_float
;
2126 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
2127 scavtab
[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
] =
2128 scav_vector_complex_double_float
;
2130 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
2131 scavtab
[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
] =
2132 scav_vector_complex_long_float
;
2134 scavtab
[COMPLEX_BASE_STRING_WIDETAG
] = scav_boxed
;
2135 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
2136 scavtab
[COMPLEX_CHARACTER_STRING_WIDETAG
] = scav_boxed
;
2138 scavtab
[COMPLEX_VECTOR_NIL_WIDETAG
] = scav_boxed
;
2139 scavtab
[COMPLEX_BIT_VECTOR_WIDETAG
] = scav_boxed
;
2140 scavtab
[COMPLEX_VECTOR_WIDETAG
] = scav_boxed
;
2141 scavtab
[COMPLEX_ARRAY_WIDETAG
] = scav_boxed
;
2142 scavtab
[CODE_HEADER_WIDETAG
] = scav_code_header
;
2143 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
2144 scavtab
[SIMPLE_FUN_HEADER_WIDETAG
] = scav_fun_header
;
2145 scavtab
[RETURN_PC_HEADER_WIDETAG
] = scav_return_pc_header
;
2147 scavtab
[FUNCALLABLE_INSTANCE_HEADER_WIDETAG
] = scav_boxed
;
2148 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
2149 scavtab
[CLOSURE_HEADER_WIDETAG
] = scav_closure_header
;
2151 scavtab
[CLOSURE_HEADER_WIDETAG
] = scav_boxed
;
2153 scavtab
[VALUE_CELL_HEADER_WIDETAG
] = scav_boxed
;
2154 scavtab
[SYMBOL_HEADER_WIDETAG
] = scav_boxed
;
2155 scavtab
[CHARACTER_WIDETAG
] = scav_immediate
;
2156 scavtab
[SAP_WIDETAG
] = scav_unboxed
;
2157 scavtab
[UNBOUND_MARKER_WIDETAG
] = scav_immediate
;
2158 scavtab
[NO_TLS_VALUE_MARKER_WIDETAG
] = scav_immediate
;
2159 scavtab
[INSTANCE_HEADER_WIDETAG
] = scav_instance
;
2160 #if defined(LISP_FEATURE_SPARC) || defined(LISP_FEATURE_ARM)
2161 scavtab
[FDEFN_WIDETAG
] = scav_boxed
;
2163 scavtab
[FDEFN_WIDETAG
] = scav_fdefn
;
2165 scavtab
[SIMPLE_VECTOR_WIDETAG
] = scav_vector
;
2167 /* transport other table, initialized same way as scavtab */
2168 for (i
= 0; i
< ((sizeof transother
)/(sizeof transother
[0])); i
++)
2169 transother
[i
] = trans_lose
;
2170 transother
[BIGNUM_WIDETAG
] = trans_unboxed
;
2171 transother
[RATIO_WIDETAG
] = trans_boxed
;
2173 #if N_WORD_BITS == 64
2174 transother
[SINGLE_FLOAT_WIDETAG
] = trans_immediate
;
2176 transother
[SINGLE_FLOAT_WIDETAG
] = trans_unboxed
;
2178 transother
[DOUBLE_FLOAT_WIDETAG
] = trans_unboxed
;
2179 #ifdef LONG_FLOAT_WIDETAG
2180 transother
[LONG_FLOAT_WIDETAG
] = trans_unboxed
;
2182 transother
[COMPLEX_WIDETAG
] = trans_boxed
;
2183 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
2184 transother
[COMPLEX_SINGLE_FLOAT_WIDETAG
] = trans_unboxed
;
2186 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
2187 transother
[COMPLEX_DOUBLE_FLOAT_WIDETAG
] = trans_unboxed
;
2189 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
2190 transother
[COMPLEX_LONG_FLOAT_WIDETAG
] = trans_unboxed
;
2192 transother
[SIMPLE_ARRAY_WIDETAG
] = trans_boxed
; /* but not GENCGC */
2193 transother
[SIMPLE_BASE_STRING_WIDETAG
] = trans_base_string
;
2194 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
2195 transother
[SIMPLE_CHARACTER_STRING_WIDETAG
] = trans_character_string
;
2197 transother
[SIMPLE_BIT_VECTOR_WIDETAG
] = trans_vector_bit
;
2198 transother
[SIMPLE_VECTOR_WIDETAG
] = trans_vector
;
2199 transother
[SIMPLE_ARRAY_NIL_WIDETAG
] = trans_vector_nil
;
2200 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG
] =
2201 trans_vector_unsigned_byte_2
;
2202 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG
] =
2203 trans_vector_unsigned_byte_4
;
2204 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG
] =
2205 trans_vector_unsigned_byte_8
;
2206 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG
] =
2207 trans_vector_unsigned_byte_8
;
2208 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG
] =
2209 trans_vector_unsigned_byte_16
;
2210 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG
] =
2211 trans_vector_unsigned_byte_16
;
2212 #if (N_WORD_BITS == 32)
2213 transother
[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG
] =
2214 trans_vector_unsigned_byte_32
;
2216 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG
] =
2217 trans_vector_unsigned_byte_32
;
2218 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
] =
2219 trans_vector_unsigned_byte_32
;
2220 #if (N_WORD_BITS == 64)
2221 transother
[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG
] =
2222 trans_vector_unsigned_byte_64
;
2224 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
2225 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
] =
2226 trans_vector_unsigned_byte_64
;
2228 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
2229 transother
[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
] =
2230 trans_vector_unsigned_byte_64
;
2232 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
2233 transother
[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
] =
2234 trans_vector_unsigned_byte_8
;
2236 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
2237 transother
[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
] =
2238 trans_vector_unsigned_byte_16
;
2240 #if (N_WORD_BITS == 32)
2241 transother
[SIMPLE_ARRAY_FIXNUM_WIDETAG
] =
2242 trans_vector_unsigned_byte_32
;
2244 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
2245 transother
[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
] =
2246 trans_vector_unsigned_byte_32
;
2248 #if (N_WORD_BITS == 64)
2249 transother
[SIMPLE_ARRAY_FIXNUM_WIDETAG
] =
2250 trans_vector_unsigned_byte_64
;
2252 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
2253 transother
[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
] =
2254 trans_vector_unsigned_byte_64
;
2256 transother
[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG
] =
2257 trans_vector_single_float
;
2258 transother
[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG
] =
2259 trans_vector_double_float
;
2260 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
2261 transother
[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
] =
2262 trans_vector_long_float
;
2264 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
2265 transother
[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
] =
2266 trans_vector_complex_single_float
;
2268 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
2269 transother
[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
] =
2270 trans_vector_complex_double_float
;
2272 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
2273 transother
[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
] =
2274 trans_vector_complex_long_float
;
2276 transother
[COMPLEX_BASE_STRING_WIDETAG
] = trans_boxed
;
2277 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
2278 transother
[COMPLEX_CHARACTER_STRING_WIDETAG
] = trans_boxed
;
2280 transother
[COMPLEX_BIT_VECTOR_WIDETAG
] = trans_boxed
;
2281 transother
[COMPLEX_VECTOR_NIL_WIDETAG
] = trans_boxed
;
2282 transother
[COMPLEX_VECTOR_WIDETAG
] = trans_boxed
;
2283 transother
[COMPLEX_ARRAY_WIDETAG
] = trans_boxed
;
2284 transother
[CODE_HEADER_WIDETAG
] = trans_code_header
;
2285 transother
[SIMPLE_FUN_HEADER_WIDETAG
] = trans_fun_header
;
2286 transother
[RETURN_PC_HEADER_WIDETAG
] = trans_return_pc_header
;
2287 transother
[CLOSURE_HEADER_WIDETAG
] = trans_boxed
;
2288 transother
[FUNCALLABLE_INSTANCE_HEADER_WIDETAG
] = trans_boxed
;
2289 transother
[VALUE_CELL_HEADER_WIDETAG
] = trans_boxed
;
2290 transother
[SYMBOL_HEADER_WIDETAG
] = trans_tiny_boxed
;
2291 transother
[CHARACTER_WIDETAG
] = trans_immediate
;
2292 transother
[SAP_WIDETAG
] = trans_unboxed
;
2293 #ifdef SIMD_PACK_WIDETAG
2294 transother
[SIMD_PACK_WIDETAG
] = trans_unboxed
;
2296 transother
[UNBOUND_MARKER_WIDETAG
] = trans_immediate
;
2297 transother
[NO_TLS_VALUE_MARKER_WIDETAG
] = trans_immediate
;
2298 transother
[WEAK_POINTER_WIDETAG
] = trans_weak_pointer
;
2299 transother
[INSTANCE_HEADER_WIDETAG
] = trans_instance
;
2300 transother
[FDEFN_WIDETAG
] = trans_boxed
;
2302 /* size table, initialized the same way as scavtab */
2303 for (i
= 0; i
< ((sizeof sizetab
)/(sizeof sizetab
[0])); i
++)
2304 sizetab
[i
] = size_lose
;
2305 for (i
= 0; i
< (1<<(N_WIDETAG_BITS
-N_LOWTAG_BITS
)); i
++) {
2306 for (j
= 0; j
< (1<<N_LOWTAG_BITS
); j
++) {
2308 sizetab
[j
|(i
<<N_LOWTAG_BITS
)] = size_immediate
;
2311 sizetab
[FUN_POINTER_LOWTAG
|(i
<<N_LOWTAG_BITS
)] = size_pointer
;
2312 /* skipping OTHER_IMMEDIATE_0_LOWTAG */
2313 sizetab
[LIST_POINTER_LOWTAG
|(i
<<N_LOWTAG_BITS
)] = size_pointer
;
2314 sizetab
[INSTANCE_POINTER_LOWTAG
|(i
<<N_LOWTAG_BITS
)] = size_pointer
;
2315 /* skipping OTHER_IMMEDIATE_1_LOWTAG */
2316 sizetab
[OTHER_POINTER_LOWTAG
|(i
<<N_LOWTAG_BITS
)] = size_pointer
;
2318 sizetab
[BIGNUM_WIDETAG
] = size_unboxed
;
2319 sizetab
[RATIO_WIDETAG
] = size_boxed
;
2320 #if N_WORD_BITS == 64
2321 sizetab
[SINGLE_FLOAT_WIDETAG
] = size_immediate
;
2323 sizetab
[SINGLE_FLOAT_WIDETAG
] = size_unboxed
;
2325 sizetab
[DOUBLE_FLOAT_WIDETAG
] = size_unboxed
;
2326 #ifdef LONG_FLOAT_WIDETAG
2327 sizetab
[LONG_FLOAT_WIDETAG
] = size_unboxed
;
2329 sizetab
[COMPLEX_WIDETAG
] = size_boxed
;
2330 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
2331 sizetab
[COMPLEX_SINGLE_FLOAT_WIDETAG
] = size_unboxed
;
2333 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
2334 sizetab
[COMPLEX_DOUBLE_FLOAT_WIDETAG
] = size_unboxed
;
2336 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
2337 sizetab
[COMPLEX_LONG_FLOAT_WIDETAG
] = size_unboxed
;
2339 sizetab
[SIMPLE_ARRAY_WIDETAG
] = size_boxed
;
2340 sizetab
[SIMPLE_BASE_STRING_WIDETAG
] = size_base_string
;
2341 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
2342 sizetab
[SIMPLE_CHARACTER_STRING_WIDETAG
] = size_character_string
;
2344 sizetab
[SIMPLE_BIT_VECTOR_WIDETAG
] = size_vector_bit
;
2345 sizetab
[SIMPLE_VECTOR_WIDETAG
] = size_vector
;
2346 sizetab
[SIMPLE_ARRAY_NIL_WIDETAG
] = size_vector_nil
;
2347 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG
] =
2348 size_vector_unsigned_byte_2
;
2349 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG
] =
2350 size_vector_unsigned_byte_4
;
2351 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG
] =
2352 size_vector_unsigned_byte_8
;
2353 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG
] =
2354 size_vector_unsigned_byte_8
;
2355 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG
] =
2356 size_vector_unsigned_byte_16
;
2357 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG
] =
2358 size_vector_unsigned_byte_16
;
2359 #if (N_WORD_BITS == 32)
2360 sizetab
[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG
] =
2361 size_vector_unsigned_byte_32
;
2363 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG
] =
2364 size_vector_unsigned_byte_32
;
2365 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
] =
2366 size_vector_unsigned_byte_32
;
2367 #if (N_WORD_BITS == 64)
2368 sizetab
[SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG
] =
2369 size_vector_unsigned_byte_64
;
2371 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
2372 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
] =
2373 size_vector_unsigned_byte_64
;
2375 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
2376 sizetab
[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
] =
2377 size_vector_unsigned_byte_64
;
2379 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
2380 sizetab
[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
] = size_vector_unsigned_byte_8
;
2382 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
2383 sizetab
[SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
] =
2384 size_vector_unsigned_byte_16
;
2386 #if (N_WORD_BITS == 32)
2387 sizetab
[SIMPLE_ARRAY_FIXNUM_WIDETAG
] =
2388 size_vector_unsigned_byte_32
;
2390 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
2391 sizetab
[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
] =
2392 size_vector_unsigned_byte_32
;
2394 #if (N_WORD_BITS == 64)
2395 sizetab
[SIMPLE_ARRAY_FIXNUM_WIDETAG
] =
2396 size_vector_unsigned_byte_64
;
2398 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
2399 sizetab
[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
] =
2400 size_vector_unsigned_byte_64
;
2402 sizetab
[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG
] = size_vector_single_float
;
2403 sizetab
[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG
] = size_vector_double_float
;
2404 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
2405 sizetab
[SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
] = size_vector_long_float
;
2407 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
2408 sizetab
[SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
] =
2409 size_vector_complex_single_float
;
2411 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
2412 sizetab
[SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
] =
2413 size_vector_complex_double_float
;
2415 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
2416 sizetab
[SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
] =
2417 size_vector_complex_long_float
;
2419 sizetab
[COMPLEX_BASE_STRING_WIDETAG
] = size_boxed
;
2420 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
2421 sizetab
[COMPLEX_CHARACTER_STRING_WIDETAG
] = size_boxed
;
2423 sizetab
[COMPLEX_VECTOR_NIL_WIDETAG
] = size_boxed
;
2424 sizetab
[COMPLEX_BIT_VECTOR_WIDETAG
] = size_boxed
;
2425 sizetab
[COMPLEX_VECTOR_WIDETAG
] = size_boxed
;
2426 sizetab
[COMPLEX_ARRAY_WIDETAG
] = size_boxed
;
2427 sizetab
[CODE_HEADER_WIDETAG
] = size_code_header
;
2429 /* We shouldn't see these, so just lose if it happens. */
2430 sizetab
[SIMPLE_FUN_HEADER_WIDETAG
] = size_function_header
;
2431 sizetab
[RETURN_PC_HEADER_WIDETAG
] = size_return_pc_header
;
2433 sizetab
[CLOSURE_HEADER_WIDETAG
] = size_boxed
;
2434 sizetab
[FUNCALLABLE_INSTANCE_HEADER_WIDETAG
] = size_boxed
;
2435 sizetab
[VALUE_CELL_HEADER_WIDETAG
] = size_boxed
;
2436 sizetab
[SYMBOL_HEADER_WIDETAG
] = size_tiny_boxed
;
2437 sizetab
[CHARACTER_WIDETAG
] = size_immediate
;
2438 sizetab
[SAP_WIDETAG
] = size_unboxed
;
2439 #ifdef SIMD_PACK_WIDETAG
2440 sizetab
[SIMD_PACK_WIDETAG
] = size_unboxed
;
2442 sizetab
[UNBOUND_MARKER_WIDETAG
] = size_immediate
;
2443 sizetab
[NO_TLS_VALUE_MARKER_WIDETAG
] = size_immediate
;
2444 sizetab
[WEAK_POINTER_WIDETAG
] = size_weak_pointer
;
2445 sizetab
[INSTANCE_HEADER_WIDETAG
] = size_instance
;
2446 sizetab
[FDEFN_WIDETAG
] = size_boxed
;
2450 /* Find the code object for the given pc, or return NULL on
2453 component_ptr_from_pc(lispobj
*pc
)
2455 lispobj
*object
= NULL
;
2457 if ( (object
= search_read_only_space(pc
)) )
2459 else if ( (object
= search_static_space(pc
)) )
2462 object
= search_dynamic_space(pc
);
2464 if (object
) /* if we found something */
2465 if (widetag_of(*object
) == CODE_HEADER_WIDETAG
)
2471 /* Scan an area looking for an object which encloses the given pointer.
2472 * Return the object start on success or NULL on failure. */
2474 gc_search_space(lispobj
*start
, size_t words
, lispobj
*pointer
)
2478 lispobj
*forwarded_start
;
2480 if (forwarding_pointer_p(start
))
2482 native_pointer((lispobj
)forwarding_pointer_value(start
));
2484 forwarded_start
= start
;
2485 lispobj thing
= *forwarded_start
;
2486 /* If thing is an immediate then this is a cons. */
2487 if (is_lisp_pointer(thing
) || is_lisp_immediate(thing
))
2490 count
= (sizetab
[widetag_of(thing
)])(forwarded_start
);
2492 /* Check whether the pointer is within this object. */
2493 if ((pointer
>= start
) && (pointer
< (start
+count
))) {
2495 /*FSHOW((stderr,"/found %x in %x %x\n", pointer, start, thing));*/
2499 /* Round up the count. */
2500 count
= CEILING(count
,2);
2508 /* Helper for valid_lisp_pointer_p (below) and
2509 * possibly_valid_dynamic_space_pointer (gencgc).
2511 * pointer is the pointer to validate, and start_addr is the address
2512 * of the enclosing object.
2515 looks_like_valid_lisp_pointer_p(lispobj pointer
, lispobj
*start_addr
)
2517 if (!is_lisp_pointer(pointer
)) {
2521 /* Check that the object pointed to is consistent with the pointer
2523 switch (lowtag_of(pointer
)) {
2524 case FUN_POINTER_LOWTAG
:
2525 /* Start_addr should be the enclosing code object, or a closure
2527 switch (widetag_of(*start_addr
)) {
2528 case CODE_HEADER_WIDETAG
:
2529 /* Make sure we actually point to a function in the code object,
2530 * as opposed to a random point there. */
2531 if (SIMPLE_FUN_HEADER_WIDETAG
==widetag_of(native_pointer(pointer
)[0]))
2535 case CLOSURE_HEADER_WIDETAG
:
2536 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG
:
2537 if (pointer
!= make_lispobj(start_addr
, FUN_POINTER_LOWTAG
)) {
2545 case LIST_POINTER_LOWTAG
:
2546 if (pointer
!= make_lispobj(start_addr
, LIST_POINTER_LOWTAG
)) {
2549 /* Is it plausible cons? */
2550 if ((is_lisp_pointer(start_addr
[0]) ||
2551 is_lisp_immediate(start_addr
[0])) &&
2552 (is_lisp_pointer(start_addr
[1]) ||
2553 is_lisp_immediate(start_addr
[1])))
2558 case INSTANCE_POINTER_LOWTAG
:
2559 if (pointer
!= make_lispobj(start_addr
, INSTANCE_POINTER_LOWTAG
)) {
2562 if (widetag_of(start_addr
[0]) != INSTANCE_HEADER_WIDETAG
) {
2566 case OTHER_POINTER_LOWTAG
:
2568 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
2569 /* The all-architecture test below is good as far as it goes,
2570 * but an LRA object is similar to a FUN-POINTER: It is
2571 * embedded within a CODE-OBJECT pointed to by start_addr, and
2572 * cannot be found by simply walking the heap, therefore we
2573 * need to check for it. -- AB, 2010-Jun-04 */
2574 if ((widetag_of(start_addr
[0]) == CODE_HEADER_WIDETAG
)) {
2575 lispobj
*potential_lra
= native_pointer(pointer
);
2576 if ((widetag_of(potential_lra
[0]) == RETURN_PC_HEADER_WIDETAG
) &&
2577 ((potential_lra
- HeaderValue(potential_lra
[0])) == start_addr
)) {
2578 return 1; /* It's as good as we can verify. */
2583 if (pointer
!= make_lispobj(start_addr
, OTHER_POINTER_LOWTAG
)) {
2586 /* Is it plausible? Not a cons. XXX should check the headers. */
2587 if (is_lisp_pointer(start_addr
[0]) || ((start_addr
[0] & 3) == 0)) {
2590 switch (widetag_of(start_addr
[0])) {
2591 case UNBOUND_MARKER_WIDETAG
:
2592 case NO_TLS_VALUE_MARKER_WIDETAG
:
2593 case CHARACTER_WIDETAG
:
2594 #if N_WORD_BITS == 64
2595 case SINGLE_FLOAT_WIDETAG
:
2599 /* only pointed to by function pointers? */
2600 case CLOSURE_HEADER_WIDETAG
:
2601 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG
:
2604 case INSTANCE_HEADER_WIDETAG
:
2607 /* the valid other immediate pointer objects */
2608 case SIMPLE_VECTOR_WIDETAG
:
2610 case COMPLEX_WIDETAG
:
2611 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
2612 case COMPLEX_SINGLE_FLOAT_WIDETAG
:
2614 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
2615 case COMPLEX_DOUBLE_FLOAT_WIDETAG
:
2617 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
2618 case COMPLEX_LONG_FLOAT_WIDETAG
:
2620 #ifdef SIMD_PACK_WIDETAG
2621 case SIMD_PACK_WIDETAG
:
2623 case SIMPLE_ARRAY_WIDETAG
:
2624 case COMPLEX_BASE_STRING_WIDETAG
:
2625 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
2626 case COMPLEX_CHARACTER_STRING_WIDETAG
:
2628 case COMPLEX_VECTOR_NIL_WIDETAG
:
2629 case COMPLEX_BIT_VECTOR_WIDETAG
:
2630 case COMPLEX_VECTOR_WIDETAG
:
2631 case COMPLEX_ARRAY_WIDETAG
:
2632 case VALUE_CELL_HEADER_WIDETAG
:
2633 case SYMBOL_HEADER_WIDETAG
:
2635 case CODE_HEADER_WIDETAG
:
2636 case BIGNUM_WIDETAG
:
2637 #if N_WORD_BITS != 64
2638 case SINGLE_FLOAT_WIDETAG
:
2640 case DOUBLE_FLOAT_WIDETAG
:
2641 #ifdef LONG_FLOAT_WIDETAG
2642 case LONG_FLOAT_WIDETAG
:
2644 case SIMPLE_BASE_STRING_WIDETAG
:
2645 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
2646 case SIMPLE_CHARACTER_STRING_WIDETAG
:
2648 case SIMPLE_BIT_VECTOR_WIDETAG
:
2649 case SIMPLE_ARRAY_NIL_WIDETAG
:
2650 case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG
:
2651 case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG
:
2652 case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG
:
2653 case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG
:
2654 case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG
:
2655 case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG
:
2657 case SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG
:
2659 case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG
:
2660 case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG
:
2661 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
2662 case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
:
2664 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
2665 case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
:
2667 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
2668 case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
:
2670 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
2671 case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
:
2674 case SIMPLE_ARRAY_FIXNUM_WIDETAG
:
2676 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
2677 case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
:
2679 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
2680 case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
:
2682 case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG
:
2683 case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG
:
2684 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
2685 case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
:
2687 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
2688 case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
:
2690 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
2691 case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
:
2693 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
2694 case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
:
2697 case WEAK_POINTER_WIDETAG
:
2712 /* META: Note the ambiguous word "validate" in the comment below.
2713 * This means "Decide whether <x> is valid".
2714 * But when you see os_validate() elsewhere, that doesn't mean to ask
2715 * whether something is valid, it says to *make* it valid.
2716 * I think it would be nice if we could avoid using the word in the
2717 * sense in which os_validate() uses it, which would entail renaming
2718 * a bunch of stuff, which is harder than just explaining why
2719 * the comments can be deceptive */
2721 /* Used by the debugger to validate possibly bogus pointers before
2722 * calling MAKE-LISP-OBJ on them.
2724 * FIXME: We would like to make this perfect, because if the debugger
2725 * constructs a reference to a bugs lisp object, and it ends up in a
2726 * location scavenged by the GC all hell breaks loose.
2728 * Whereas possibly_valid_dynamic_space_pointer has to be conservative
2729 * and return true for all valid pointers, this could actually be eager
2730 * and lie about a few pointers without bad results... but that should
2731 * be reflected in the name.
2734 valid_lisp_pointer_p(lispobj
*pointer
)
2737 if (((start
=search_dynamic_space(pointer
))!=NULL
) ||
2738 ((start
=search_static_space(pointer
))!=NULL
) ||
2739 ((start
=search_read_only_space(pointer
))!=NULL
))
2740 return looks_like_valid_lisp_pointer_p((lispobj
)pointer
, start
);
2746 maybe_gc(os_context_t
*context
)
2748 lispobj gc_happened
;
2749 struct thread
*thread
= arch_os_get_current_thread();
2750 boolean were_in_lisp
= !foreign_function_call_active_p(thread
);
2753 fake_foreign_function_call(context
);
2756 /* SUB-GC may return without GCing if *GC-INHIBIT* is set, in
2757 * which case we will be running with no gc trigger barrier
2758 * thing for a while. But it shouldn't be long until the end
2761 * FIXME: It would be good to protect the end of dynamic space for
2762 * CheneyGC and signal a storage condition from there.
2765 /* Restore the signal mask from the interrupted context before
2766 * calling into Lisp if interrupts are enabled. Why not always?
2768 * Suppose there is a WITHOUT-INTERRUPTS block far, far out. If an
2769 * interrupt hits while in SUB-GC, it is deferred and the
2770 * os_context_sigmask of that interrupt is set to block further
2771 * deferrable interrupts (until the first one is
2772 * handled). Unfortunately, that context refers to this place and
2773 * when we return from here the signals will not be blocked.
2775 * A kludgy alternative is to propagate the sigmask change to the
2778 #if !(defined(LISP_FEATURE_WIN32) || defined(LISP_FEATURE_SB_SAFEPOINT))
2779 check_gc_signals_unblocked_or_lose(os_context_sigmask_addr(context
));
2780 unblock_gc_signals(0, 0);
2782 FSHOW((stderr
, "/maybe_gc: calling SUB_GC\n"));
2783 /* FIXME: Nothing must go wrong during GC else we end up running
2784 * the debugger, error handlers, and user code in general in a
2785 * potentially unsafe place. Running out of the control stack or
2786 * the heap in SUB-GC are ways to lose. Of course, deferrables
2787 * cannot be unblocked because there may be a pending handler, or
2788 * we may even be in a WITHOUT-INTERRUPTS. */
2789 gc_happened
= funcall0(StaticSymbolFunction(SUB_GC
));
2790 FSHOW((stderr
, "/maybe_gc: gc_happened=%s\n",
2791 (gc_happened
== NIL
)
2793 : ((gc_happened
== T
)
2796 /* gc_happened can take three values: T, NIL, 0.
2798 * T means that the thread managed to trigger a GC, and post-gc
2801 * NIL means that the thread is within without-gcing, and no GC
2804 * Finally, 0 means that *a* GC has occurred, but it wasn't
2805 * triggered by this thread; success, but post-gc doesn't have
2808 if ((gc_happened
== T
) &&
2809 /* See if interrupts are enabled or it's possible to enable
2810 * them. POST-GC has a similar check, but we don't want to
2811 * unlock deferrables in that case and get a pending interrupt
2813 ((SymbolValue(INTERRUPTS_ENABLED
,thread
) != NIL
) ||
2814 (SymbolValue(ALLOW_WITH_INTERRUPTS
,thread
) != NIL
))) {
2815 #ifndef LISP_FEATURE_WIN32
2816 sigset_t
*context_sigmask
= os_context_sigmask_addr(context
);
2817 if (!deferrables_blocked_p(context_sigmask
)) {
2818 thread_sigmask(SIG_SETMASK
, context_sigmask
, 0);
2819 #ifndef LISP_FEATURE_SB_SAFEPOINT
2820 check_gc_signals_unblocked_or_lose(0);
2823 FSHOW((stderr
, "/maybe_gc: calling POST_GC\n"));
2824 funcall0(StaticSymbolFunction(POST_GC
));
2825 #ifndef LISP_FEATURE_WIN32
2827 FSHOW((stderr
, "/maybe_gc: punting on POST_GC due to blockage\n"));
2833 undo_fake_foreign_function_call(context
);
2835 /* Otherwise done by undo_fake_foreign_function_call. And
2836 something later wants them to be blocked. What a nice
2838 block_blockable_signals(0);
2841 FSHOW((stderr
, "/maybe_gc: returning\n"));
2842 return (gc_happened
!= NIL
);
2845 #define BYTES_ZERO_BEFORE_END (1<<12)
2847 /* There used to be a similar function called SCRUB-CONTROL-STACK in
2848 * Lisp and another called zero_stack() in cheneygc.c, but since it's
2849 * shorter to express in, and more often called from C, I keep only
2850 * the C one after fixing it. -- MG 2009-03-25 */
2852 /* Zero the unused portion of the control stack so that old objects
2853 * are not kept alive because of uninitialized stack variables.
2855 * "To summarize the problem, since not all allocated stack frame
2856 * slots are guaranteed to be written by the time you call an another
2857 * function or GC, there may be garbage pointers retained in your dead
2858 * stack locations. The stack scrubbing only affects the part of the
2859 * stack from the SP to the end of the allocated stack." - ram, on
2860 * cmucl-imp, Tue, 25 Sep 2001
2862 * So, as an (admittedly lame) workaround, from time to time we call
2863 * scrub-control-stack to zero out all the unused portion. This is
2864 * supposed to happen when the stack is mostly empty, so that we have
2865 * a chance of clearing more of it: callers are currently (2002.07.18)
2866 * REPL, SUB-GC and sig_stop_for_gc_handler. */
2868 /* Take care not to tread on the guard page and the hard guard page as
2869 * it would be unkind to sig_stop_for_gc_handler. Touching the return
2870 * guard page is not dangerous. For this to work the guard page must
2871 * be zeroed when protected. */
2873 /* FIXME: I think there is no guarantee that once
2874 * BYTES_ZERO_BEFORE_END bytes are zero the rest are also zero. This
2875 * may be what the "lame" adjective in the above comment is for. In
2876 * this case, exact gc may lose badly. */
2878 scrub_control_stack()
2880 scrub_thread_control_stack(arch_os_get_current_thread());
2884 scrub_thread_control_stack(struct thread
*th
)
2886 os_vm_address_t guard_page_address
= CONTROL_STACK_GUARD_PAGE(th
);
2887 os_vm_address_t hard_guard_page_address
= CONTROL_STACK_HARD_GUARD_PAGE(th
);
2888 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
2889 /* On these targets scrubbing from C is a bad idea, so we punt to
2890 * a routine in $ARCH-assem.S. */
2891 extern void arch_scrub_control_stack(struct thread
*, os_vm_address_t
, os_vm_address_t
);
2892 arch_scrub_control_stack(th
, guard_page_address
, hard_guard_page_address
);
2894 lispobj
*sp
= access_control_stack_pointer(th
);
2896 if ((((os_vm_address_t
)sp
< (hard_guard_page_address
+ os_vm_page_size
)) &&
2897 ((os_vm_address_t
)sp
>= hard_guard_page_address
)) ||
2898 (((os_vm_address_t
)sp
< (guard_page_address
+ os_vm_page_size
)) &&
2899 ((os_vm_address_t
)sp
>= guard_page_address
) &&
2900 (th
->control_stack_guard_page_protected
!= NIL
)))
2902 #ifdef LISP_FEATURE_STACK_GROWS_DOWNWARD_NOT_UPWARD
2905 } while (((uword_t
)sp
--) & (BYTES_ZERO_BEFORE_END
- 1));
2906 if ((os_vm_address_t
)sp
< (hard_guard_page_address
+ os_vm_page_size
))
2911 } while (((uword_t
)sp
--) & (BYTES_ZERO_BEFORE_END
- 1));
2915 } while (((uword_t
)++sp
) & (BYTES_ZERO_BEFORE_END
- 1));
2916 if ((os_vm_address_t
)sp
>= hard_guard_page_address
)
2921 } while (((uword_t
)++sp
) & (BYTES_ZERO_BEFORE_END
- 1));
2923 #endif /* LISP_FEATURE_C_STACK_IS_CONTROL_STACK */
2926 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
2929 scavenge_control_stack(struct thread
*th
)
2931 lispobj
*object_ptr
;
2933 /* In order to properly support dynamic-extent allocation of
2934 * non-CONS objects, the control stack requires special handling.
2935 * Rather than calling scavenge() directly, grovel over it fixing
2936 * broken hearts, scavenging pointers to oldspace, and pitching a
2937 * fit when encountering unboxed data. This prevents stray object
2938 * headers from causing the scavenger to blow past the end of the
2939 * stack (an error case checked in scavenge()). We don't worry
2940 * about treating unboxed words as boxed or vice versa, because
2941 * the compiler isn't allowed to store unboxed objects on the
2942 * control stack. -- AB, 2011-Dec-02 */
2944 for (object_ptr
= th
->control_stack_start
;
2945 object_ptr
< access_control_stack_pointer(th
);
2948 lispobj object
= *object_ptr
;
2949 #ifdef LISP_FEATURE_GENCGC
2950 if (forwarding_pointer_p(object_ptr
))
2951 lose("unexpected forwarding pointer in scavenge_control_stack: %p, start=%p, end=%p\n",
2952 object_ptr
, th
->control_stack_start
, access_control_stack_pointer(th
));
2954 if (is_lisp_pointer(object
) && from_space_p(object
)) {
2955 /* It currently points to old space. Check for a
2956 * forwarding pointer. */
2957 lispobj
*ptr
= native_pointer(object
);
2958 if (forwarding_pointer_p(ptr
)) {
2959 /* Yes, there's a forwarding pointer. */
2960 *object_ptr
= LOW_WORD(forwarding_pointer_value(ptr
));
2962 /* Scavenge that pointer. */
2963 long n_words_scavenged
=
2964 (scavtab
[widetag_of(object
)])(object_ptr
, object
);
2965 gc_assert(n_words_scavenged
== 1);
2967 } else if (scavtab
[widetag_of(object
)] == scav_lose
) {
2968 lose("unboxed object in scavenge_control_stack: %p->%x, start=%p, end=%p\n",
2969 object_ptr
, object
, th
->control_stack_start
, access_control_stack_pointer(th
));
2974 /* Scavenging Interrupt Contexts */
2976 static int boxed_registers
[] = BOXED_REGISTERS
;
2978 /* The GC has a notion of an "interior pointer" register, an unboxed
2979 * register that typically contains a pointer to inside an object
2980 * referenced by another pointer. The most obvious of these is the
2981 * program counter, although many compiler backends define a "Lisp
2982 * Interior Pointer" register known to the runtime as reg_LIP, and
2983 * various CPU architectures have other registers that also partake of
2984 * the interior-pointer nature. As the code for pairing an interior
2985 * pointer value up with its "base" register, and fixing it up after
2986 * scavenging is complete is horribly repetitive, a few macros paper
2987 * over the monotony. --AB, 2010-Jul-14 */
2989 /* These macros are only ever used over a lexical environment which
2990 * defines a pointer to an os_context_t called context, thus we don't
2991 * bother to pass that context in as a parameter. */
2993 /* Define how to access a given interior pointer. */
2994 #define ACCESS_INTERIOR_POINTER_pc \
2995 *os_context_pc_addr(context)
2996 #define ACCESS_INTERIOR_POINTER_lip \
2997 *os_context_register_addr(context, reg_LIP)
2998 #define ACCESS_INTERIOR_POINTER_lr \
2999 *os_context_lr_addr(context)
3000 #define ACCESS_INTERIOR_POINTER_npc \
3001 *os_context_npc_addr(context)
3002 #define ACCESS_INTERIOR_POINTER_ctr \
3003 *os_context_ctr_addr(context)
3005 #define INTERIOR_POINTER_VARS(name) \
3006 uword_t name##_offset; \
3007 int name##_register_pair
3009 #define PAIR_INTERIOR_POINTER(name) \
3010 pair_interior_pointer(context, \
3011 ACCESS_INTERIOR_POINTER_##name, \
3013 &name##_register_pair)
3015 /* One complexity here is that if a paired register is not found for
3016 * an interior pointer, then that pointer does not get updated.
3017 * Originally, there was some commentary about using an index of -1
3018 * when calling os_context_register_addr() on SPARC referring to the
3019 * program counter, but the real reason is to allow an interior
3020 * pointer register to point to the runtime, read-only space, or
3021 * static space without problems. */
3022 #define FIXUP_INTERIOR_POINTER(name) \
3024 if (name##_register_pair >= 0) { \
3025 ACCESS_INTERIOR_POINTER_##name = \
3026 (*os_context_register_addr(context, \
3027 name##_register_pair) \
3035 pair_interior_pointer(os_context_t
*context
, uword_t pointer
,
3036 uword_t
*saved_offset
, int *register_pair
)
3041 * I (RLT) think this is trying to find the boxed register that is
3042 * closest to the LIP address, without going past it. Usually, it's
3043 * reg_CODE or reg_LRA. But sometimes, nothing can be found.
3045 /* 0x7FFFFFFF on 32-bit platforms;
3046 0x7FFFFFFFFFFFFFFF on 64-bit platforms */
3047 *saved_offset
= (((uword_t
)1) << (N_WORD_BITS
- 1)) - 1;
3048 *register_pair
= -1;
3049 for (i
= 0; i
< (sizeof(boxed_registers
) / sizeof(int)); i
++) {
3054 index
= boxed_registers
[i
];
3055 reg
= *os_context_register_addr(context
, index
);
3057 /* An interior pointer is never relative to a non-pointer
3058 * register (an oversight in the original implementation).
3059 * The simplest argument for why this is true is to consider
3060 * the fixnum that happens by coincide to be the word-index in
3061 * memory of the header for some object plus two. This is
3062 * happenstance would cause the register containing the fixnum
3063 * to be selected as the register_pair if the interior pointer
3064 * is to anywhere after the first two words of the object.
3065 * The fixnum won't be changed during GC, but the object might
3066 * move, thus destroying the interior pointer. --AB,
3069 if (is_lisp_pointer(reg
) &&
3070 ((reg
& ~LOWTAG_MASK
) <= pointer
)) {
3071 offset
= pointer
- (reg
& ~LOWTAG_MASK
);
3072 if (offset
< *saved_offset
) {
3073 *saved_offset
= offset
;
3074 *register_pair
= index
;
3081 scavenge_interrupt_context(os_context_t
* context
)
3085 /* FIXME: The various #ifdef noise here is precisely that: noise.
3086 * Is it possible to fold it into the macrology so that we have
3087 * one set of #ifdefs and then INTERIOR_POINTER_VARS /et alia/
3088 * compile out for the registers that don't exist on a given
3091 INTERIOR_POINTER_VARS(pc
);
3093 INTERIOR_POINTER_VARS(lip
);
3095 #ifdef ARCH_HAS_LINK_REGISTER
3096 INTERIOR_POINTER_VARS(lr
);
3098 #ifdef ARCH_HAS_NPC_REGISTER
3099 INTERIOR_POINTER_VARS(npc
);
3101 #ifdef LISP_FEATURE_PPC
3102 INTERIOR_POINTER_VARS(ctr
);
3105 PAIR_INTERIOR_POINTER(pc
);
3107 PAIR_INTERIOR_POINTER(lip
);
3109 #ifdef ARCH_HAS_LINK_REGISTER
3110 PAIR_INTERIOR_POINTER(lr
);
3112 #ifdef ARCH_HAS_NPC_REGISTER
3113 PAIR_INTERIOR_POINTER(npc
);
3115 #ifdef LISP_FEATURE_PPC
3116 PAIR_INTERIOR_POINTER(ctr
);
3119 /* Scavenge all boxed registers in the context. */
3120 for (i
= 0; i
< (sizeof(boxed_registers
) / sizeof(int)); i
++) {
3124 index
= boxed_registers
[i
];
3125 foo
= *os_context_register_addr(context
, index
);
3127 *os_context_register_addr(context
, index
) = foo
;
3129 /* this is unlikely to work as intended on bigendian
3130 * 64 bit platforms */
3132 scavenge((lispobj
*) os_context_register_addr(context
, index
), 1);
3135 /* Now that the scavenging is done, repair the various interior
3137 FIXUP_INTERIOR_POINTER(pc
);
3139 FIXUP_INTERIOR_POINTER(lip
);
3141 #ifdef ARCH_HAS_LINK_REGISTER
3142 FIXUP_INTERIOR_POINTER(lr
);
3144 #ifdef ARCH_HAS_NPC_REGISTER
3145 FIXUP_INTERIOR_POINTER(npc
);
3147 #ifdef LISP_FEATURE_PPC
3148 FIXUP_INTERIOR_POINTER(ctr
);
3153 scavenge_interrupt_contexts(struct thread
*th
)
3156 os_context_t
*context
;
3158 index
= fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX
,th
));
3160 #if defined(DEBUG_PRINT_CONTEXT_INDEX)
3161 printf("Number of active contexts: %d\n", index
);
3164 for (i
= 0; i
< index
; i
++) {
3165 context
= th
->interrupt_contexts
[i
];
3166 scavenge_interrupt_context(context
);
3169 #endif /* x86oid targets */
3171 // The following accessors, which take a valid native pointer as input
3172 // and return a Lisp string, are designed to be foolproof during GC,
3173 // hence all the forwarding checks.
3175 #if defined(LISP_FEATURE_SB_LDB)
3176 #include "genesis/classoid.h"
3177 struct vector
* symbol_name(lispobj
* sym
)
3179 if (forwarding_pointer_p(sym
))
3180 sym
= native_pointer((lispobj
)forwarding_pointer_value(sym
));
3181 if (lowtag_of(((struct symbol
*)sym
)->name
) != OTHER_POINTER_LOWTAG
)
3183 lispobj
* name
= native_pointer(((struct symbol
*)sym
)->name
);
3184 if (forwarding_pointer_p(name
))
3185 name
= native_pointer((lispobj
)forwarding_pointer_value(name
));
3186 return (struct vector
*)name
;
3188 struct vector
* classoid_name(lispobj
* classoid
)
3190 if (forwarding_pointer_p(classoid
))
3191 classoid
= native_pointer((lispobj
)forwarding_pointer_value(classoid
));
3192 lispobj sym
= ((struct classoid
*)classoid
)->name
;
3193 return lowtag_of(sym
) != OTHER_POINTER_LOWTAG
? NULL
3194 : symbol_name(native_pointer(sym
));
3196 struct vector
* layout_classoid_name(lispobj
* layout
)
3198 if (forwarding_pointer_p(layout
))
3199 layout
= native_pointer((lispobj
)forwarding_pointer_value(layout
));
3200 lispobj classoid
= ((struct layout
*)layout
)->classoid
;
3201 return lowtag_of(classoid
) != INSTANCE_POINTER_LOWTAG
? NULL
3202 : classoid_name(native_pointer(classoid
));
3204 struct vector
* instance_classoid_name(lispobj
* instance
)
3206 if (forwarding_pointer_p(instance
))
3207 instance
= native_pointer((lispobj
)forwarding_pointer_value(instance
));
3208 lispobj layout
= instance_layout(instance
);
3209 return lowtag_of(layout
) != INSTANCE_POINTER_LOWTAG
? NULL
3210 : layout_classoid_name(native_pointer(layout
));
3212 void safely_show_lstring(struct vector
* string
, int quotes
, FILE *s
)
3214 extern void show_lstring(struct vector
*, int, FILE*);
3215 if (forwarding_pointer_p((lispobj
*)string
))
3216 string
= (struct vector
*)forwarding_pointer_value((lispobj
*)string
);
3218 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
3219 widetag_of(string
->header
) == SIMPLE_CHARACTER_STRING_WIDETAG
||
3221 widetag_of(string
->header
) == SIMPLE_BASE_STRING_WIDETAG
)
3222 show_lstring(string
, quotes
, s
);
3224 fprintf(s
, "#<[widetag=%02X]>", widetag_of(string
->header
));