First set of licensing changes
[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
13 void sgen_card_table_reset_region (mword start, mword end);
14 void* sgen_card_table_align_pointer (void *ptr);
15 void sgen_card_table_mark_range (mword address, mword size);
16 void sgen_cardtable_scan_object (GCObject *obj, mword obj_size, guint8 *cards,
17                 ScanCopyContext ctx);
18
19 gboolean sgen_card_table_get_card_data (guint8 *dest, mword address, mword cards);
20
21 guint8* sgen_card_table_alloc_mod_union (char *obj, mword obj_size);
22 void sgen_card_table_free_mod_union (guint8 *mod_union, char *obj, mword obj_size);
23
24 void sgen_card_table_update_mod_union_from_cards (guint8 *dest, guint8 *start_card, size_t num_cards);
25 void sgen_card_table_update_mod_union (guint8 *dest, char *obj, mword obj_size, size_t *out_num_cards);
26 void sgen_card_table_preclean_mod_union (guint8 *cards, guint8 *cards_preclean, size_t num_cards);
27
28 guint8* sgen_get_card_table_configuration (int *shift_bits, gpointer *mask);
29
30 void sgen_card_table_init (SgenRememberedSet *remset);
31
32 /*How many bytes a single card covers*/
33 #define CARD_BITS 9
34
35 /* How many bits of the address space is covered by the card table.
36  * If this value is smaller than the number of address bits, card aliasing is required.
37  */
38 #define CARD_TABLE_BITS 32
39
40 #define CARD_SIZE_IN_BYTES (1 << CARD_BITS)
41 #define CARD_COUNT_BITS (CARD_TABLE_BITS - CARD_BITS)
42 #define CARD_COUNT_IN_BYTES (1 << CARD_COUNT_BITS)
43 #define CARD_MASK ((1 << CARD_COUNT_BITS) - 1)
44
45 #if SIZEOF_VOID_P * 8 > CARD_TABLE_BITS
46 #define SGEN_HAVE_OVERLAPPING_CARDS     1
47 #endif
48
49 extern guint8 *sgen_cardtable;
50
51
52 #ifdef SGEN_HAVE_OVERLAPPING_CARDS
53
54 static inline guint8*
55 sgen_card_table_get_card_address (mword address)
56 {
57         return sgen_cardtable + ((address >> CARD_BITS) & CARD_MASK);
58 }
59
60 extern guint8 *sgen_shadow_cardtable;
61
62 #define SGEN_SHADOW_CARDTABLE_END (sgen_shadow_cardtable + CARD_COUNT_IN_BYTES)
63
64 static inline guint8*
65 sgen_card_table_get_shadow_card_address (mword address)
66 {
67         return sgen_shadow_cardtable + ((address >> CARD_BITS) & CARD_MASK);
68 }
69
70 static inline gboolean
71 sgen_card_table_card_begin_scanning (mword address)
72 {
73         return *sgen_card_table_get_shadow_card_address (address) != 0;
74 }
75
76 static inline void
77 sgen_card_table_prepare_card_for_scanning (guint8 *card)
78 {
79 }
80
81 #define sgen_card_table_get_card_scan_address sgen_card_table_get_shadow_card_address
82
83 #else
84
85 static inline guint8*
86 sgen_card_table_get_card_address (mword address)
87 {
88         return sgen_cardtable + (address >> CARD_BITS);
89 }
90
91 static inline gboolean
92 sgen_card_table_card_begin_scanning (mword address)
93 {
94         guint8 *card = sgen_card_table_get_card_address (address);
95         gboolean res = *card;
96         *card = 0;
97         return res;
98 }
99
100 static inline void
101 sgen_card_table_prepare_card_for_scanning (guint8 *card)
102 {
103         *card = 0;
104 }
105
106 #define sgen_card_table_get_card_scan_address sgen_card_table_get_card_address
107
108 #endif
109
110 static inline gboolean
111 sgen_card_table_address_is_marked (mword address)
112 {
113         return *sgen_card_table_get_card_address (address) != 0;
114 }
115
116 static inline void
117 sgen_card_table_mark_address (mword address)
118 {
119         *sgen_card_table_get_card_address (address) = 1;
120 }
121
122 static inline size_t
123 sgen_card_table_get_card_offset (char *ptr, char *base)
124 {
125         return (ptr - base) >> CARD_BITS;
126 }
127
128 #endif