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