More write barrier clenaups.
[mono-project.git] / mono / metadata / sgen-cardtable.h
blob0b703395448cd31efb27ffd56f06b17be8df7e8b
1 /*
2 * Copyright 2001-2003 Ximian, Inc
3 * Copyright 2003-2010 Novell, Inc.
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:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
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.
24 #ifndef __MONO_SGEN_CARD_TABLE_INLINES_H__
25 #define __MONO_SGEN_CARD_TABLE_INLINES_H__
27 #define SGEN_HAVE_CARDTABLE 1
29 #ifdef SGEN_HAVE_CARDTABLE
31 void sgen_card_table_reset_region (mword start, mword end) MONO_INTERNAL;
32 void* sgen_card_table_align_pointer (void *ptr) MONO_INTERNAL;
33 void sgen_card_table_mark_range (mword address, mword size) MONO_INTERNAL;
34 void sgen_cardtable_scan_object (char *obj, mword obj_size, guint8 *cards, SgenGrayQueue *queue) MONO_INTERNAL;
36 gboolean sgen_card_table_get_card_data (guint8 *dest, mword address, mword cards) MONO_INTERNAL;
37 void mono_sgen_card_table_finish_scan_remsets (void *start_nursery, void *end_nursery, SgenGrayQueue *queue) MONO_INTERNAL;
38 void sgen_card_tables_collect_stats (gboolean begin) MONO_INTERNAL;
39 void mono_sgen_card_table_prepare_for_major_collection (void) MONO_INTERNAL;
40 void sgen_card_table_init (void) MONO_INTERNAL;
42 void mono_sgen_card_table_wbarrier_set_field (MonoObject *obj, gpointer field_ptr, MonoObject* value) MONO_INTERNAL;
43 void mono_sgen_card_table_wbarrier_set_arrayref (MonoArray *arr, gpointer slot_ptr, MonoObject* value) MONO_INTERNAL;
44 void mono_sgen_card_table_wbarrier_arrayref_copy (gpointer dest_ptr, gpointer src_ptr, int count) MONO_INTERNAL;
45 void mono_sgen_card_table_wbarrier_value_copy (gpointer dest, gpointer src, int count, MonoClass *klass) MONO_INTERNAL;
46 void mono_sgen_card_table_wbarrier_object_copy (MonoObject* obj, MonoObject *src) MONO_INTERNAL;
47 void mono_sgen_card_table_wbarrier_generic_nostore (gpointer ptr) MONO_INTERNAL;
49 /*How many bytes a single card covers*/
50 #define CARD_BITS 9
52 /* How many bits of the address space is covered by the card table.
53 * If this value is smaller than the number of address bits, card aliasing is required.
55 #define CARD_TABLE_BITS 32
57 #define CARD_SIZE_IN_BYTES (1 << CARD_BITS)
58 #define CARD_COUNT_BITS (CARD_TABLE_BITS - CARD_BITS)
59 #define CARD_COUNT_IN_BYTES (1 << CARD_COUNT_BITS)
60 #define CARD_MASK ((1 << CARD_COUNT_BITS) - 1)
62 #if SIZEOF_VOID_P * 8 > CARD_TABLE_BITS
63 #define SGEN_HAVE_OVERLAPPING_CARDS 1
64 #endif
66 extern guint8 *sgen_cardtable MONO_INTERNAL;
69 #ifdef SGEN_HAVE_OVERLAPPING_CARDS
71 static inline guint8*
72 sgen_card_table_get_card_address (mword address)
74 return sgen_cardtable + ((address >> CARD_BITS) & CARD_MASK);
77 extern guint8 *sgen_shadow_cardtable MONO_INTERNAL;
79 static inline guint8*
80 sgen_card_table_get_shadow_card_address (mword address)
82 return sgen_shadow_cardtable + ((address >> CARD_BITS) & CARD_MASK);
85 static inline gboolean
86 sgen_card_table_card_begin_scanning (mword address)
88 return *sgen_card_table_get_shadow_card_address (address) != 0;
91 static inline void
92 sgen_card_table_prepare_card_for_scanning (guint8 *card)
96 #define sgen_card_table_get_card_scan_address sgen_card_table_get_shadow_card_address
98 #else
100 static inline guint8*
101 sgen_card_table_get_card_address (mword address)
103 return sgen_cardtable + (address >> CARD_BITS);
106 static inline gboolean
107 sgen_card_table_card_begin_scanning (mword address)
109 guint8 *card = sgen_card_table_get_card_address (address);
110 gboolean res = *card;
111 *card = 0;
112 return res;
115 static inline void
116 sgen_card_table_prepare_card_for_scanning (guint8 *card)
118 *card = 0;
121 #define sgen_card_table_get_card_scan_address sgen_card_table_get_card_address
123 #endif
125 static inline gboolean
126 sgen_card_table_address_is_marked (mword address)
128 return *sgen_card_table_get_card_address (address) != 0;
131 static inline void
132 sgen_card_table_mark_address (mword address)
134 *sgen_card_table_get_card_address (address) = 1;
137 static inline void
138 mono_sgen_card_table_record_pointer (gpointer address)
140 *sgen_card_table_get_card_address ((mword)address) = 1;
143 #else /*if SGEN_HAVE_CARDTABLE */
145 static inline void
146 sgen_card_table_mark_address (mword address)
148 g_assert_not_reached ();
151 static inline void
152 sgen_card_table_mark_range (mword address, mword size)
154 g_assert_not_reached ();
157 #define sgen_card_table_address_is_marked(p) FALSE
158 #define mono_sgen_card_table_scan_from_remsets(start,end,queue)
159 #define mono_sgen_card_table_prepare_for_major_collection()
160 #define sgen_card_table_init()
161 #define sgen_card_tables_collect_stats(begin)
163 guint8*
164 mono_gc_get_card_table (int *shift_bits, gpointer *mask)
166 return NULL;
169 static void
170 mono_sgen_card_table_record_pointer (gpointer address)
172 g_assert_not_reached ();
175 #endif
179 #endif