]> gitweb.factorcode.org Git - factor.git/blob - vm/gc_info.hpp
f5a25d2e3dfd200b22fdc2a997f15dab6cdcde8f
[factor.git] / vm / gc_info.hpp
1 namespace factor {
2
3 // gc_info should be kept in sync with:
4 //   basis/compiler/codegen/gc-maps/gc-maps.factor
5 //   basis/vm/vm.factor
6 struct gc_info {
7   uint32_t scrub_d_count;
8   uint32_t scrub_r_count;
9   uint32_t gc_root_count;
10   uint32_t derived_root_count;
11   uint32_t return_address_count;
12
13   cell callsite_bitmap_size() {
14     return scrub_d_count + scrub_r_count + gc_root_count;
15   }
16
17   cell total_bitmap_size() {
18     return return_address_count * callsite_bitmap_size();
19   }
20
21   cell total_bitmap_bytes() { return ((total_bitmap_size() + 7) / 8); }
22
23   uint32_t* return_addresses() {
24     return (uint32_t*)this - return_address_count;
25   }
26
27   uint32_t* base_pointer_map() {
28     return return_addresses() - return_address_count * derived_root_count;
29   }
30
31   uint8_t* gc_info_bitmap() {
32     return (uint8_t*)base_pointer_map() - total_bitmap_bytes();
33   }
34
35   cell callsite_scrub_d(cell index) {
36     cell base = 0;
37     return base + index * scrub_d_count;
38   }
39
40   cell callsite_scrub_r(cell index) {
41     cell base = return_address_count * scrub_d_count;
42     return base + index * scrub_r_count;
43   }
44
45   cell callsite_gc_roots(cell index) {
46     cell base =
47         return_address_count * scrub_d_count +
48         return_address_count * scrub_r_count;
49     return base + index * gc_root_count;
50   }
51
52   uint32_t lookup_base_pointer(cell index, cell derived_root) {
53     return base_pointer_map()[index * derived_root_count + derived_root];
54   }
55
56   cell return_address_index(cell return_address);
57 };
58
59 }