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 #define CARD_POINTS_TO_NURSERY 0x80
17 #define CARD_POINTS_TO_AGING 0x40
18 #define CARD_MARK_MASK (CARD_POINTS_TO_NURSERY | CARD_POINTS_TO_AGING)
22 #define CARD_SIZE (1<<CARD_BITS)
23 #define 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 #define DECK_BITS (CARD_BITS + 10)
43 #define DECK_SIZE (1<<DECK_BITS)
44 #define 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 #define INVALID_ALLOT_MARKER 0xff
63 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);