1 /* Setting mark bits in objects. */ 2 3 /* -------------------------- Specification ----------------------------- */ 4 5 /* To mark a heap object (for the purpose of GC or of circularity analysis), we 6 set the garcol_bit in the first word (i.e. the GCself header for varobjects). 7 Immediate objects can not (and need not) be marked. 8 9 Set the mark bit at a given address. 10 mark(addr); 11 local void mark (void* addr); 12 13 Clear the mark bit at a given address. 14 unmark(addr); 15 local void unmark (void* addr); 16 17 Tests the mark bit at a given address. 18 marked(addr) 19 local bool marked (void* addr); 20 21 Add a mark bit to an object pointer. 22 with_mark_bit(obj) 23 local object with_mark_bit (object obj); 24 25 Remove a mark bit from an object pointer. 26 without_mark_bit(obj) 27 local object without_mark_bit (object obj); */ 28 29 /* -------------------------- Implementation ---------------------------- */ 30 31 #if defined(WIDE_STRUCT) || defined(OBJECT_STRUCT) 32 #define mark(addr) (((gcv_object_t*)(addr))->one_o |= wbit(garcol_bit_o)) 33 #else 34 #define mark(addr) (*(gcv_object_t*)(addr) = as_object(as_oint(*(gcv_object_t*)(addr)) | wbit(garcol_bit_o))) 35 #endif 36 37 #if defined(WIDE_STRUCT) || defined(OBJECT_STRUCT) 38 #define unmark(addr) (((gcv_object_t*)(addr))->one_o &= ~wbit(garcol_bit_o)) 39 #else 40 #define unmark(addr) (*(gcv_object_t*)(addr) = as_object(as_oint(*(gcv_object_t*)(addr)) & ~wbit(garcol_bit_o))) 41 #endif 42 43 #ifdef fast_mtypecode 44 #define marked(addr) (mtypecode(*(gcv_object_t*)(addr)) & bit(garcol_bit_t)) 45 #else 46 #if defined(WIDE_STRUCT) || defined(OBJECT_STRUCT) 47 #define marked(addr) (((gcv_object_t*)(addr))->one_o & wbit(garcol_bit_o)) 48 #else 49 #define marked(addr) (as_oint(*(gcv_object_t*)(addr)) & wbit(garcol_bit_o)) 50 #endif 51 #endif 52 53 #define with_mark_bit(obj) as_object(as_oint(obj) | wbit(garcol_bit_o)) 54 #define without_mark_bit(obj) as_object(as_oint(obj) & ~wbit(garcol_bit_o)) 55