]> gitweb.factorcode.org Git - factor.git/blob - vm/write_barrier.hpp
VM: use better abstractions for tagged pointers, eliminate get()/set() stuff, clean...
[factor.git] / vm / write_barrier.hpp
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.
3
4 the mark flag is set by the write barrier when an object in the
5 card has a slot written to.
6
7 the offset of the first object is set by the allocator. */
8
9 /* if CARD_POINTS_TO_NURSERY is set, CARD_POINTS_TO_AGING must also be set. */
10 #define CARD_POINTS_TO_NURSERY 0x80
11 #define CARD_POINTS_TO_AGING 0x40
12 #define CARD_MARK_MASK (CARD_POINTS_TO_NURSERY | CARD_POINTS_TO_AGING)
13 typedef u8 F_CARD;
14
15 #define CARD_BITS 8
16 #define CARD_SIZE (1<<CARD_BITS)
17 #define ADDR_CARD_MASK (CARD_SIZE-1)
18
19 extern "C" CELL cards_offset;
20
21 #define ADDR_TO_CARD(a) (F_CARD*)(((CELL)(a) >> CARD_BITS) + cards_offset)
22 #define CARD_TO_ADDR(c) (CELL*)(((CELL)(c) - cards_offset)<<CARD_BITS)
23
24 typedef u8 F_DECK;
25
26 #define DECK_BITS (CARD_BITS + 10)
27 #define DECK_SIZE (1<<DECK_BITS)
28 #define ADDR_DECK_MASK (DECK_SIZE-1)
29
30 extern "C" CELL decks_offset;
31
32 #define ADDR_TO_DECK(a) (F_DECK*)(((CELL)(a) >> DECK_BITS) + decks_offset)
33 #define DECK_TO_ADDR(c) (CELL*)(((CELL)(c) - decks_offset) << DECK_BITS)
34
35 #define DECK_TO_CARD(d) (F_CARD*)((((CELL)(d) - decks_offset) << (DECK_BITS - CARD_BITS)) + cards_offset)
36
37 #define ADDR_TO_ALLOT_MARKER(a) (F_CARD*)(((CELL)(a) >> CARD_BITS) + allot_markers_offset)
38 #define CARD_OFFSET(c) (*((c) - (CELL)data_heap->cards + (CELL)data_heap->allot_markers))
39
40 #define INVALID_ALLOT_MARKER 0xff
41
42 extern "C" CELL allot_markers_offset;
43
44 /* the write barrier must be called any time we are potentially storing a
45 pointer from an older generation to a younger one */
46 inline static void write_barrier(F_OBJECT *address)
47 {
48         *ADDR_TO_CARD(address) = CARD_MARK_MASK;
49         *ADDR_TO_DECK(address) = CARD_MARK_MASK;
50 }
51
52 /* we need to remember the first object allocated in the card */
53 inline static void allot_barrier(F_OBJECT *address)
54 {
55         F_CARD *ptr = ADDR_TO_ALLOT_MARKER(address);
56         if(*ptr == INVALID_ALLOT_MARKER)
57                 *ptr = ((CELL)address & ADDR_CARD_MASK);
58 }