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 /*WARNING: This function returns the number of cards regardless of overflow in case of overlapping cards.*/
28 mword sgen_card_table_number_of_cards_in_range (mword address, mword size);
30 void sgen_card_table_reset_region (mword start, mword end);
31 void* sgen_card_table_align_pointer (void *ptr);
32 void sgen_card_table_mark_range (mword address, mword size);
33 void sgen_cardtable_scan_object (GCObject *obj, mword obj_size, guint8 *cards,
36 gboolean sgen_card_table_get_card_data (guint8 *dest, mword address, mword cards);
38 guint8* sgen_card_table_alloc_mod_union (char *obj, mword obj_size);
39 void sgen_card_table_free_mod_union (guint8 *mod_union, char *obj, mword obj_size);
41 void sgen_card_table_update_mod_union_from_cards (guint8 *dest, guint8 *start_card, size_t num_cards);
42 void sgen_card_table_update_mod_union (guint8 *dest, char *obj, mword obj_size, size_t *out_num_cards);
43 void sgen_card_table_preclean_mod_union (guint8 *cards, guint8 *cards_preclean, size_t num_cards);
45 guint8* sgen_get_card_table_configuration (int *shift_bits, gpointer *mask);
47 void sgen_card_table_init (SgenRememberedSet *remset);
49 /*How many bytes a single card covers*/
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
66 extern guint8 *sgen_cardtable;
69 #ifdef SGEN_HAVE_OVERLAPPING_CARDS
72 sgen_card_table_get_card_address (mword address)
74 return sgen_cardtable + ((address >> CARD_BITS) & CARD_MASK);
77 extern guint8 *sgen_shadow_cardtable;
79 #define SGEN_SHADOW_CARDTABLE_END (sgen_shadow_cardtable + CARD_COUNT_IN_BYTES)
82 sgen_card_table_get_shadow_card_address (mword address)
84 return sgen_shadow_cardtable + ((address >> CARD_BITS) & CARD_MASK);
87 static inline gboolean
88 sgen_card_table_card_begin_scanning (mword address)
90 return *sgen_card_table_get_shadow_card_address (address) != 0;
94 sgen_card_table_prepare_card_for_scanning (guint8 *card)
98 #define sgen_card_table_get_card_scan_address sgen_card_table_get_shadow_card_address
102 static inline guint8*
103 sgen_card_table_get_card_address (mword address)
105 return sgen_cardtable + (address >> CARD_BITS);
108 static inline gboolean
109 sgen_card_table_card_begin_scanning (mword address)
111 guint8 *card = sgen_card_table_get_card_address (address);
112 gboolean res = *card;
118 sgen_card_table_prepare_card_for_scanning (guint8 *card)
123 #define sgen_card_table_get_card_scan_address sgen_card_table_get_card_address
127 static inline gboolean
128 sgen_card_table_address_is_marked (mword address)
130 return *sgen_card_table_get_card_address (address) != 0;
134 sgen_card_table_mark_address (mword address)
136 *sgen_card_table_get_card_address (address) = 1;
140 sgen_card_table_get_card_offset (char *ptr, char *base)
142 return (ptr - base) >> CARD_BITS;