0.8.12.6:
[sbcl.git] / src / runtime / gc-internal.h
1 /*
2  * garbage collection - shared definitions for modules "inside" the GC system
3  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
9  * This software is derived from the CMU CL system, which was
10  * written at Carnegie Mellon University and released into the
11  * public domain. The software is in the public domain and is
12  * provided with absolutely no warranty. See the COPYING and CREDITS
13  * files for more information.
14  */
15
16 #ifndef _GC_INTERNAL_H_
17 #define _GC_INTERNAL_H_
18
19 /* disabling gc assertions made no discernable difference to GC speed,
20  * last I tried it - dan 2003.12.21 */
21 #if 1
22 #define gc_assert(ex) do { \
23         if (!(ex)) gc_abort(); \
24 } while (0)
25 #else
26 #define gc_assert(ex)
27 #endif
28 #define gc_abort() lose("GC invariant lost, file \"%s\", line %d", \
29                         __FILE__, __LINE__)
30
31 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
32 #define NWORDS(x,y) (CEILING((x),(y)) / (y))
33
34 /* FIXME: Shouldn't this be defined in sbcl.h? */
35 #define FUN_RAW_ADDR_OFFSET (6*sizeof(lispobj) - FUN_POINTER_LOWTAG)
36
37 /* values for the *_alloc_* parameters */
38 #define FREE_PAGE_FLAG 0
39 #define BOXED_PAGE_FLAG 1
40 #define UNBOXED_PAGE_FLAG 2
41 #define OPEN_REGION_PAGE_FLAG 4
42
43 #define ALLOC_BOXED 0
44 #define ALLOC_UNBOXED 1
45 #define ALLOC_QUICK 1
46
47 void *gc_general_alloc(int nbytes,int unboxed_p,int quick_p);
48
49 extern int (*scavtab[256])(lispobj *where, lispobj object);
50 extern lispobj (*transother[256])(lispobj object);
51 extern int (*sizetab[256])(lispobj *where);
52
53 extern struct weak_pointer *weak_pointers; /* in gc-common.c */
54
55 extern void scavenge(lispobj *start, long n_words);
56 extern void scan_weak_pointers(void);
57
58 lispobj  copy_large_unboxed_object(lispobj object, int nwords);
59 lispobj  copy_unboxed_object(lispobj object, int nwords);
60 lispobj  copy_large_object(lispobj object, int nwords);
61 lispobj  copy_object(lispobj object, int nwords);
62
63 lispobj *search_read_only_space(void *pointer);
64 lispobj *search_static_space(void *pointer);
65 lispobj *search_dynamic_space(void *pointer);
66
67 /* Scan an area looking for an object which encloses the given pointer.
68  * Return the object start on success or NULL on failure. */
69 static lispobj *
70 search_space(lispobj *start, size_t words, lispobj *pointer)
71 {
72     while (words > 0) {
73         size_t count = 1;
74         lispobj thing = *start;
75
76         /* If thing is an immediate then this is a cons. */
77         if (is_lisp_pointer(thing)
78             || ((thing & 3) == 0) /* fixnum */
79             || (widetag_of(thing) == BASE_CHAR_WIDETAG)
80             || (widetag_of(thing) == UNBOUND_MARKER_WIDETAG))
81             count = 2;
82         else
83             count = (sizetab[widetag_of(thing)])(start);
84
85         /* Check whether the pointer is within this object. */
86         if ((pointer >= start) && (pointer < (start+count))) {
87             /* found it! */
88             /*FSHOW((stderr,"/found %x in %x %x\n", pointer, start, thing));*/
89             return(start);
90         }
91
92         /* Round up the count. */
93         count = CEILING(count,2);
94
95         start += count;
96         words -= count;
97     }
98     return (NULL);
99 }
100
101 #ifdef LISP_FEATURE_GENCGC
102 #include "gencgc-internal.h"
103 #else
104 #include "cheneygc-internal.h"
105 #endif
106
107 #endif /* _GC_INTERNAL_H_ */