[sgen] Move some cardtable functions to sgen
[mono.git] / mono / sgen / sgen-cardtable.h
1 /*
2  * Copyright 2001-2003 Ximian, Inc
3  * Copyright 2003-2010 Novell, Inc.
4  *
5  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
6  */
7 #ifndef __MONO_SGEN_CARD_TABLE_INLINES_H__
8 #define __MONO_SGEN_CARD_TABLE_INLINES_H__
9
10 /*WARNING: This function returns the number of cards regardless of overflow in case of overlapping cards.*/
11 mword sgen_card_table_number_of_cards_in_range (mword address, mword size);
12 guint8* sgen_find_next_card (guint8 *card_data, guint8 *end);
13
14 void sgen_card_table_reset_region (mword start, mword end);
15 void* sgen_card_table_align_pointer (void *ptr);
16 void sgen_card_table_mark_range (mword address, mword size);
17 void sgen_cardtable_scan_object (GCObject *obj, mword obj_size, guint8 *cards,
18                 ScanCopyContext ctx);
19
20 gboolean sgen_card_table_get_card_data (guint8 *dest, mword address, mword cards);
21
22 guint8* sgen_card_table_alloc_mod_union (char *obj, mword obj_size);
23 void sgen_card_table_free_mod_union (guint8 *mod_union, char *obj, mword obj_size);
24
25 void sgen_card_table_update_mod_union_from_cards (guint8 *dest, guint8 *start_card, size_t num_cards);
26 void sgen_card_table_update_mod_union (guint8 *dest, char *obj, mword obj_size, size_t *out_num_cards);
27 void sgen_card_table_preclean_mod_union (guint8 *cards, guint8 *cards_preclean, size_t num_cards);
28
29 guint8* sgen_get_card_table_configuration (int *shift_bits, gpointer *mask);
30
31 void sgen_card_table_init (SgenRememberedSet *remset);
32
33 /*How many bytes a single card covers*/
34 #define CARD_BITS 9
35
36 /* How many bits of the address space is covered by the card table.
37  * If this value is smaller than the number of address bits, card aliasing is required.
38  */
39 #define CARD_TABLE_BITS 32
40
41 #define CARD_SIZE_IN_BYTES (1 << CARD_BITS)
42 #define CARD_COUNT_BITS (CARD_TABLE_BITS - CARD_BITS)
43 #define CARD_COUNT_IN_BYTES (1 << CARD_COUNT_BITS)
44 #define CARD_MASK ((1 << CARD_COUNT_BITS) - 1)
45
46 #if SIZEOF_VOID_P * 8 > CARD_TABLE_BITS
47 #define SGEN_HAVE_OVERLAPPING_CARDS     1
48 #endif
49
50 extern guint8 *sgen_cardtable;
51
52
53 #ifdef SGEN_HAVE_OVERLAPPING_CARDS
54
55 static inline guint8*
56 sgen_card_table_get_card_address (mword address)
57 {
58         return sgen_cardtable + ((address >> CARD_BITS) & CARD_MASK);
59 }
60
61 extern guint8 *sgen_shadow_cardtable;
62
63 #define SGEN_SHADOW_CARDTABLE_END (sgen_shadow_cardtable + CARD_COUNT_IN_BYTES)
64
65 static inline guint8*
66 sgen_card_table_get_shadow_card_address (mword address)
67 {
68         return sgen_shadow_cardtable + ((address >> CARD_BITS) & CARD_MASK);
69 }
70
71 static inline gboolean
72 sgen_card_table_card_begin_scanning (mword address)
73 {
74         return *sgen_card_table_get_shadow_card_address (address) != 0;
75 }
76
77 static inline void
78 sgen_card_table_prepare_card_for_scanning (guint8 *card)
79 {
80 }
81
82 #define sgen_card_table_get_card_scan_address sgen_card_table_get_shadow_card_address
83
84 #else
85
86 static inline guint8*
87 sgen_card_table_get_card_address (mword address)
88 {
89         return sgen_cardtable + (address >> CARD_BITS);
90 }
91
92 static inline gboolean
93 sgen_card_table_card_begin_scanning (mword address)
94 {
95         guint8 *card = sgen_card_table_get_card_address (address);
96         gboolean res = *card;
97         *card = 0;
98         return res;
99 }
100
101 static inline void
102 sgen_card_table_prepare_card_for_scanning (guint8 *card)
103 {
104         *card = 0;
105 }
106
107 #define sgen_card_table_get_card_scan_address sgen_card_table_get_card_address
108
109 #endif
110
111 static inline gboolean
112 sgen_card_table_address_is_marked (mword address)
113 {
114         return *sgen_card_table_get_card_address (address) != 0;
115 }
116
117 static inline void
118 sgen_card_table_mark_address (mword address)
119 {
120         *sgen_card_table_get_card_address (address) = 1;
121 }
122
123 static inline size_t
124 sgen_card_table_get_card_offset (char *ptr, char *base)
125 {
126         return (ptr - base) >> CARD_BITS;
127 }
128
129 #endif