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,
34 gboolean mod_union, ScanCopyContext ctx);
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);
44 guint8* sgen_get_card_table_configuration (int *shift_bits, gpointer *mask);
46 void sgen_card_table_init (SgenRememberedSet *remset);
48 /*How many bytes a single card covers*/
51 /* How many bits of the address space is covered by the card table.
52 * If this value is smaller than the number of address bits, card aliasing is required.
54 #define CARD_TABLE_BITS 32
56 #define CARD_SIZE_IN_BYTES (1 << CARD_BITS)
57 #define CARD_COUNT_BITS (CARD_TABLE_BITS - CARD_BITS)
58 #define CARD_COUNT_IN_BYTES (1 << CARD_COUNT_BITS)
59 #define CARD_MASK ((1 << CARD_COUNT_BITS) - 1)
61 #if SIZEOF_VOID_P * 8 > CARD_TABLE_BITS
62 #define SGEN_HAVE_OVERLAPPING_CARDS 1
65 extern guint8 *sgen_cardtable;
68 #ifdef SGEN_HAVE_OVERLAPPING_CARDS
71 sgen_card_table_get_card_address (mword address)
73 return sgen_cardtable + ((address >> CARD_BITS) & CARD_MASK);
76 extern guint8 *sgen_shadow_cardtable;
78 #define SGEN_SHADOW_CARDTABLE_END (sgen_shadow_cardtable + CARD_COUNT_IN_BYTES)
81 sgen_card_table_get_shadow_card_address (mword address)
83 return sgen_shadow_cardtable + ((address >> CARD_BITS) & CARD_MASK);
86 static inline gboolean
87 sgen_card_table_card_begin_scanning (mword address)
89 return *sgen_card_table_get_shadow_card_address (address) != 0;
93 sgen_card_table_prepare_card_for_scanning (guint8 *card)
97 #define sgen_card_table_get_card_scan_address sgen_card_table_get_shadow_card_address
101 static inline guint8*
102 sgen_card_table_get_card_address (mword address)
104 return sgen_cardtable + (address >> CARD_BITS);
107 static inline gboolean
108 sgen_card_table_card_begin_scanning (mword address)
110 guint8 *card = sgen_card_table_get_card_address (address);
111 gboolean res = *card;
117 sgen_card_table_prepare_card_for_scanning (guint8 *card)
122 #define sgen_card_table_get_card_scan_address sgen_card_table_get_card_address
126 static inline gboolean
127 sgen_card_table_address_is_marked (mword address)
129 return *sgen_card_table_get_card_address (address) != 0;
133 sgen_card_table_mark_address (mword address)
135 *sgen_card_table_get_card_address (address) = 1;
139 sgen_card_table_get_card_offset (char *ptr, char *base)
141 return (ptr - base) >> CARD_BITS;