%other-pointer-widetag derive-type: derive for simple-array.
[sbcl.git] / src / runtime / gencgc-alloc-region.h
blobb2e94ae08b75abea2afc62583c0441f84ec5abee
1 #ifndef _GENCGC_ALLOC_REGION_H_
2 #define _GENCGC_ALLOC_REGION_H_
4 /* Abstract out the data for an allocation region allowing a single
5 * routine to be used for allocation and closing. */
6 /* Caution: if you change this, you may have to change compiler/generic/objdef
7 * (for the THREAD object), all the backends' allocators, and room.lisp.
8 * But as long as the first two words are left alone,
9 * it's generally OK to add or remove other words.
11 struct alloc_region {
12 /* These two are needed for quick allocation. */
13 void *free_pointer;
14 void *end_addr; /* pointer to the byte after the last usable byte */
15 void *start_addr;
18 static inline void gc_set_region_empty(struct alloc_region *region)
20 /* Free-pointer has to be not equal to 0 because it's undefined behavior
21 * to add any value whatsoever to the null pointer.
22 * Annoying, isn't it. http://c-faq.com/null/machexamp.html */
23 region->free_pointer = region->end_addr = (void*)0x1000;
24 /* Start 0 is the indicator of closed-ness. */
25 region->start_addr = 0;
28 static inline void gc_init_region(struct alloc_region *region)
30 // A distinction without a difference (it used to do one more assignment)
31 gc_set_region_empty(region);
34 typedef struct {
35 struct alloc_region cons;
36 struct alloc_region mixed;
37 uword_t token;
38 } arena_state;
40 // One region for each of page type.
41 // These indices have no correlation to PAGE_TYPE constants.
42 // MIXED has to always be at array index 0 because lisp accesses
43 // it directly in #-sb-thread builds.
44 extern struct alloc_region gc_alloc_region[6];
45 #define mixed_region (&gc_alloc_region[0])
46 #define small_mixed_region (&gc_alloc_region[1])
47 #define unboxed_region (&gc_alloc_region[2])
48 #define code_region (&gc_alloc_region[3])
49 #define boxed_region (&gc_alloc_region[4])
50 #define cons_region (&gc_alloc_region[5])
51 #define ASSERT_REGIONS_CLOSED() \
52 gc_assert(!((uintptr_t)gc_alloc_region[0].start_addr \
53 |(uintptr_t)gc_alloc_region[1].start_addr \
54 |(uintptr_t)gc_alloc_region[2].start_addr \
55 |(uintptr_t)gc_alloc_region[3].start_addr \
56 |(uintptr_t)gc_alloc_region[4].start_addr \
57 |(uintptr_t)gc_alloc_region[5].start_addr))
59 extern int gencgc_alloc_profiler;
60 #ifdef LISP_FEATURE_SB_THREAD
61 # define THREAD_ALLOC_REGION(threadvar,slot) &threadvar-> slot ##_tlab
62 #else
63 # define THREAD_ALLOC_REGION(threadvar,slot) main_thread_ ##slot ##_region
64 #define main_thread_mixed_region (struct alloc_region*)(STATIC_SPACE_START + MIXED_REGION_OFFSET)
65 #define main_thread_cons_region (struct alloc_region*)(STATIC_SPACE_START + CONS_REGION_OFFSET)
66 #define main_thread_boxed_region (struct alloc_region*)(STATIC_SPACE_START + BOXED_REGION_OFFSET)
67 #endif
69 #endif /* _GENCGC_ALLOC_REGION_H_ */