1 /* card marking write barrier. a card is a byte storing a mark flag,
2 and the offset (in cells) of the first object in the card.
4 the mark flag is set by the write barrier when an object in the
5 card has a slot written to.
7 the offset of the first object is set by the allocator. */
9 VM_C_API factor::cell cards_offset;
10 VM_C_API factor::cell decks_offset;
15 /* if card_points_to_nursery is set, card_points_to_aging must also be set. */
16 static const cell card_points_to_nursery = 0x80;
17 static const cell card_points_to_aging = 0x40;
18 static const cell card_mark_mask = (card_points_to_nursery | card_points_to_aging);
21 static const cell card_bits = 8;
22 static const cell card_size = (1<<card_bits);
23 static const cell addr_card_mask = (card_size-1);
25 inline static card *addr_to_card(cell a)
27 return (card*)(((cell)(a) >> card_bits) + cards_offset);
30 inline static cell card_to_addr(card *c)
32 return ((cell)c - cards_offset) << card_bits;
35 inline static cell card_offset(card *c)
37 return *(c - (cell)data->cards + (cell)data->allot_markers);
42 static const cell deck_bits = (card_bits + 10);
43 static const cell deck_size = (1<<deck_bits);
44 static const cell addr_deck_mask = (deck_size-1);
46 inline static card_deck *addr_to_deck(cell a)
48 return (card_deck *)(((cell)a >> deck_bits) + decks_offset);
51 inline static cell deck_to_addr(card_deck *c)
53 return ((cell)c - decks_offset) << deck_bits;
56 inline static card *deck_to_card(card_deck *d)
58 return (card *)((((cell)d - decks_offset) << (deck_bits - card_bits)) + cards_offset);
61 static const cell invalid_allot_marker = 0xff;
63 extern cell allot_markers_offset;
65 inline static card *addr_to_allot_marker(object *a)
67 return (card *)(((cell)a >> card_bits) + allot_markers_offset);
70 /* the write barrier must be called any time we are potentially storing a
71 pointer from an older generation to a younger one */
72 inline static void write_barrier(object *obj)
74 *addr_to_card((cell)obj) = card_mark_mask;
75 *addr_to_deck((cell)obj) = card_mark_mask;
78 /* we need to remember the first object allocated in the card */
79 inline static void allot_barrier(object *address)
81 card *ptr = addr_to_allot_marker(address);
82 if(*ptr == invalid_allot_marker)
83 *ptr = ((cell)address & addr_card_mask);