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 card *factorvm::addr_to_card(cell a)
27 return (card*)(((cell)(a) >> card_bits) + cards_offset);
30 inline card *addr_to_card(cell a)
32 return vm->addr_to_card(a);
35 inline cell factorvm::card_to_addr(card *c)
37 return ((cell)c - cards_offset) << card_bits;
40 inline cell card_to_addr(card *c)
42 return vm->card_to_addr(c);
45 inline cell factorvm::card_offset(card *c)
47 return *(c - (cell)data->cards + (cell)data->allot_markers);
50 inline cell card_offset(card *c)
52 return vm->card_offset(c);
57 static const cell deck_bits = (card_bits + 10);
58 static const cell deck_size = (1<<deck_bits);
59 static const cell addr_deck_mask = (deck_size-1);
61 inline card_deck *factorvm::addr_to_deck(cell a)
63 return (card_deck *)(((cell)a >> deck_bits) + decks_offset);
66 inline card_deck *addr_to_deck(cell a)
68 return vm->addr_to_deck(a);
71 inline cell factorvm::deck_to_addr(card_deck *c)
73 return ((cell)c - decks_offset) << deck_bits;
76 inline cell deck_to_addr(card_deck *c)
78 return vm->deck_to_addr(c);
81 inline card *factorvm::deck_to_card(card_deck *d)
83 return (card *)((((cell)d - decks_offset) << (deck_bits - card_bits)) + cards_offset);
86 inline card *deck_to_card(card_deck *d)
88 return vm->deck_to_card(d);
91 static const cell invalid_allot_marker = 0xff;
93 extern cell allot_markers_offset;
95 inline card *factorvm::addr_to_allot_marker(object *a)
97 return (card *)(((cell)a >> card_bits) + allot_markers_offset);
100 inline card *addr_to_allot_marker(object *a)
102 return vm->addr_to_allot_marker(a);
105 /* the write barrier must be called any time we are potentially storing a
106 pointer from an older generation to a younger one */
107 inline void factorvm::write_barrier(object *obj)
109 *addr_to_card((cell)obj) = card_mark_mask;
110 *addr_to_deck((cell)obj) = card_mark_mask;
113 inline void write_barrier(object *obj)
115 return vm->write_barrier(obj);
118 /* we need to remember the first object allocated in the card */
119 inline void factorvm::allot_barrier(object *address)
121 card *ptr = addr_to_allot_marker(address);
122 if(*ptr == invalid_allot_marker)
123 *ptr = ((cell)address & addr_card_mask);
126 inline void allot_barrier(object *address)
128 return vm->allot_barrier(address);