factor/vm/gc_info.hpp

55 lines
1.2 KiB
C++
Raw Normal View History

2013-05-11 22:04:08 -04:00
namespace factor {
// gc_info should be kept in sync with:
// basis/compiler/codegen/gc-maps/gc-maps.factor
// basis/vm/vm.factor
struct gc_info {
uint32_t gc_root_count;
uint32_t derived_root_count;
uint32_t return_address_count;
2013-05-11 22:04:08 -04:00
cell callsite_bitmap_size() {
return gc_root_count;
2013-05-11 22:04:08 -04:00
}
2013-05-11 22:04:08 -04:00
cell total_bitmap_size() {
return return_address_count * callsite_bitmap_size();
}
2013-05-11 22:04:08 -04:00
cell total_bitmap_bytes() { return ((total_bitmap_size() + 7) / 8); }
uint32_t* return_addresses() {
return (uint32_t*)this - return_address_count;
}
uint32_t* base_pointer_map() {
2013-05-11 22:04:08 -04:00
return return_addresses() - return_address_count * derived_root_count;
}
uint8_t* gc_info_bitmap() {
return (uint8_t*)base_pointer_map() - total_bitmap_bytes();
2013-05-11 22:04:08 -04:00
}
2013-05-11 22:04:08 -04:00
cell callsite_gc_roots(cell index) {
return index * gc_root_count;
2013-05-11 22:04:08 -04:00
}
uint32_t lookup_base_pointer(cell index, cell derived_root) {
2013-05-11 22:04:08 -04:00
return base_pointer_map()[index * derived_root_count + derived_root];
}
cell return_address_index(cell return_address) {
uint32_t* return_address_array = return_addresses();
for (cell i = 0; i < return_address_count; i++) {
if (return_address == return_address_array[i])
return i;
}
return (cell)-1;
}
};
}