Merge pull request #600 from tr8dr/master
[mono.git] / mono / metadata / sgen-cardtable.h
1 /*
2  * Copyright 2001-2003 Ximian, Inc
3  * Copyright 2003-2010 Novell, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #ifndef __MONO_SGEN_CARD_TABLE_INLINES_H__
25 #define __MONO_SGEN_CARD_TABLE_INLINES_H__
26
27 void sgen_card_table_reset_region (mword start, mword end) MONO_INTERNAL;
28 void* sgen_card_table_align_pointer (void *ptr) MONO_INTERNAL;
29 void sgen_card_table_mark_range (mword address, mword size) MONO_INTERNAL;
30 void sgen_cardtable_scan_object (char *obj, mword obj_size, guint8 *cards,
31                 gboolean mod_union, SgenGrayQueue *queue) MONO_INTERNAL;
32
33 gboolean sgen_card_table_get_card_data (guint8 *dest, mword address, mword cards) MONO_INTERNAL;
34
35 guint8* sgen_card_table_update_mod_union (guint8 *dest, char *obj, mword obj_size, size_t *out_num_cards) MONO_INTERNAL;
36
37 void sgen_card_table_init (SgenRemeberedSet *remset) MONO_INTERNAL;
38
39 /*How many bytes a single card covers*/
40 #define CARD_BITS 9
41
42 /* How many bits of the address space is covered by the card table.
43  * If this value is smaller than the number of address bits, card aliasing is required.
44  */
45 #define CARD_TABLE_BITS 32
46
47 #define CARD_SIZE_IN_BYTES (1 << CARD_BITS)
48 #define CARD_COUNT_BITS (CARD_TABLE_BITS - CARD_BITS)
49 #define CARD_COUNT_IN_BYTES (1 << CARD_COUNT_BITS)
50 #define CARD_MASK ((1 << CARD_COUNT_BITS) - 1)
51
52 #if SIZEOF_VOID_P * 8 > CARD_TABLE_BITS
53 #define SGEN_HAVE_OVERLAPPING_CARDS     1
54 #endif
55
56 extern guint8 *sgen_cardtable MONO_INTERNAL;
57
58
59 #ifdef SGEN_HAVE_OVERLAPPING_CARDS
60
61 static inline guint8*
62 sgen_card_table_get_card_address (mword address)
63 {
64         return sgen_cardtable + ((address >> CARD_BITS) & CARD_MASK);
65 }
66
67 extern guint8 *sgen_shadow_cardtable MONO_INTERNAL;
68
69 static inline guint8*
70 sgen_card_table_get_shadow_card_address (mword address)
71 {
72         return sgen_shadow_cardtable + ((address >> CARD_BITS) & CARD_MASK);
73 }
74
75 static inline gboolean
76 sgen_card_table_card_begin_scanning (mword address)
77 {
78         return *sgen_card_table_get_shadow_card_address (address) != 0;
79 }
80
81 static inline void
82 sgen_card_table_prepare_card_for_scanning (guint8 *card)
83 {
84 }
85
86 #define sgen_card_table_get_card_scan_address sgen_card_table_get_shadow_card_address
87
88 #else
89
90 static inline guint8*
91 sgen_card_table_get_card_address (mword address)
92 {
93         return sgen_cardtable + (address >> CARD_BITS);
94 }
95
96 static inline gboolean
97 sgen_card_table_card_begin_scanning (mword address)
98 {
99         guint8 *card = sgen_card_table_get_card_address (address);
100         gboolean res = *card;
101         *card = 0;
102         return res;
103 }
104
105 static inline void
106 sgen_card_table_prepare_card_for_scanning (guint8 *card)
107 {
108         *card = 0;
109 }
110
111 #define sgen_card_table_get_card_scan_address sgen_card_table_get_card_address
112
113 #endif
114
115 static inline gboolean
116 sgen_card_table_address_is_marked (mword address)
117 {
118         return *sgen_card_table_get_card_address (address) != 0;
119 }
120
121 static inline void
122 sgen_card_table_mark_address (mword address)
123 {
124         *sgen_card_table_get_card_address (address) = 1;
125 }
126
127 #endif