Merge branch 'master' of github.com:mono/mono
[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 #define SGEN_HAVE_CARDTABLE     1
28
29 #if SIZEOF_VOID_P == 8
30 #define SGEN_HAVE_OVERLAPPING_CARDS     1
31 #endif
32
33 #ifdef SGEN_HAVE_CARDTABLE
34
35 void sgen_card_table_reset_region (mword start, mword end) MONO_INTERNAL;
36 void* sgen_card_table_align_pointer (void *ptr) MONO_INTERNAL;
37 void sgen_card_table_mark_address (mword address) MONO_INTERNAL;
38 void sgen_card_table_mark_range (mword address, mword size) MONO_INTERNAL;
39 void sgen_cardtable_scan_object (char *obj, mword obj_size, guint8 *cards, SgenGrayQueue *queue) MONO_INTERNAL;
40 void sgen_card_table_get_card_data (guint8 *dest, mword address, mword cards) MONO_INTERNAL;
41 typedef void (*sgen_cardtable_block_callback) (mword start, mword size);
42
43 #define CARD_BITS 9
44 #define CARD_SIZE_IN_BYTES (1 << CARD_BITS)
45 #define CARD_COUNT_BITS (32 - 9)
46 #define CARD_COUNT_IN_BYTES (1 << CARD_COUNT_BITS)
47 #define CARD_MASK ((1 << CARD_COUNT_BITS) - 1)
48
49 extern guint8 *sgen_cardtable MONO_INTERNAL;
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 MONO_INTERNAL;
61
62 static inline  guint8*
63 sgen_card_table_get_shadow_card_address (mword address)
64 {
65         return sgen_shadow_cardtable + ((address >> CARD_BITS) & CARD_MASK);
66 }
67
68 static inline gboolean
69 sgen_card_table_card_begin_scanning (mword address)
70 {
71         return *sgen_card_table_get_shadow_card_address (address) != 0;
72 }
73
74 #else
75
76 static inline guint8*
77 sgen_card_table_get_card_address (mword address)
78 {
79         return sgen_cardtable + (address >> CARD_BITS);
80 }
81
82 static inline gboolean
83 sgen_card_table_card_begin_scanning (mword address)
84 {
85         guint8 *card = sgen_card_table_get_card_address (address);
86         gboolean res = *card;
87         *card = 0;
88         return res;
89 }
90 #endif
91
92 #endif
93
94
95
96 #endif