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