2009-05-04 02:46:13 -04:00
|
|
|
namespace factor
|
|
|
|
|
{
|
|
|
|
|
|
2009-05-02 05:04:19 -04:00
|
|
|
/* statistics */
|
2009-10-07 09:33:54 -04:00
|
|
|
struct generation_stats {
|
2009-05-04 05:50:24 -04:00
|
|
|
cell collections;
|
2009-05-02 05:04:19 -04:00
|
|
|
u64 gc_time;
|
|
|
|
|
u64 max_gc_time;
|
2009-05-04 05:50:24 -04:00
|
|
|
cell object_count;
|
2009-05-02 05:04:19 -04:00
|
|
|
u64 bytes_copied;
|
2009-05-02 11:17:05 -04:00
|
|
|
};
|
2009-05-02 05:04:19 -04:00
|
|
|
|
2009-10-07 09:33:54 -04:00
|
|
|
struct gc_stats {
|
|
|
|
|
generation_stats generations[gen_count];
|
|
|
|
|
u64 cards_scanned;
|
|
|
|
|
u64 decks_scanned;
|
|
|
|
|
u64 card_scan_time;
|
|
|
|
|
cell code_heap_scans;
|
|
|
|
|
};
|
|
|
|
|
|
2009-10-03 09:47:05 -04:00
|
|
|
struct gc_state {
|
|
|
|
|
/* The data heap we're collecting */
|
|
|
|
|
data_heap *data;
|
|
|
|
|
|
|
|
|
|
/* sometimes we grow the heap */
|
|
|
|
|
bool growing_data_heap;
|
|
|
|
|
data_heap *old_data_heap;
|
|
|
|
|
|
|
|
|
|
/* Which generation is being collected */
|
|
|
|
|
cell collecting_gen;
|
|
|
|
|
|
|
|
|
|
/* If true, we are collecting aging space for the second time, so if it is still
|
|
|
|
|
full, we go on to collect tenured */
|
|
|
|
|
bool collecting_aging_again;
|
|
|
|
|
|
|
|
|
|
/* GC start time, for benchmarking */
|
|
|
|
|
u64 start_time;
|
|
|
|
|
|
2009-10-05 04:27:28 -04:00
|
|
|
jmp_buf gc_unwind;
|
|
|
|
|
|
2009-10-03 09:47:05 -04:00
|
|
|
explicit gc_state(data_heap *data_, bool growing_data_heap_, cell collecting_gen_);
|
|
|
|
|
~gc_state();
|
|
|
|
|
|
|
|
|
|
inline bool collecting_nursery_p()
|
|
|
|
|
{
|
2009-10-07 09:33:54 -04:00
|
|
|
return collecting_gen == nursery_gen;
|
2009-10-03 09:47:05 -04:00
|
|
|
}
|
|
|
|
|
|
2009-10-05 23:16:08 -04:00
|
|
|
inline bool collecting_aging_p()
|
|
|
|
|
{
|
2009-10-07 09:33:54 -04:00
|
|
|
return collecting_gen == aging_gen;
|
2009-10-05 23:16:08 -04:00
|
|
|
}
|
|
|
|
|
|
2009-10-03 09:47:05 -04:00
|
|
|
inline bool collecting_tenured_p()
|
|
|
|
|
{
|
2009-10-07 09:33:54 -04:00
|
|
|
return collecting_gen == tenured_gen;
|
2009-10-03 09:47:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool collecting_accumulation_gen_p()
|
|
|
|
|
{
|
2009-10-06 03:39:12 -04:00
|
|
|
return ((collecting_aging_p() && !collecting_aging_again)
|
|
|
|
|
|| collecting_tenured_p());
|
2009-10-03 09:47:05 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-10-06 01:13:54 -04:00
|
|
|
template<typename Strategy> struct copying_collector {
|
|
|
|
|
factor_vm *myvm;
|
|
|
|
|
gc_state *current_gc;
|
2009-10-06 03:39:12 -04:00
|
|
|
zone *newspace;
|
2009-10-06 01:13:54 -04:00
|
|
|
cell scan;
|
|
|
|
|
|
2009-10-06 03:39:12 -04:00
|
|
|
explicit copying_collector(factor_vm *myvm_, zone *newspace);
|
2009-10-06 01:13:54 -04:00
|
|
|
Strategy &strategy();
|
2009-10-06 21:45:47 -04:00
|
|
|
object *allot(cell size);
|
2009-10-06 03:39:12 -04:00
|
|
|
cell trace_next(cell scan);
|
2009-10-06 21:45:47 -04:00
|
|
|
object *copy_object(object *untagged);
|
|
|
|
|
bool should_copy_p(object *untagged);
|
2009-10-06 01:13:54 -04:00
|
|
|
void go();
|
|
|
|
|
};
|
|
|
|
|
|
2009-09-25 13:29:07 -04:00
|
|
|
VM_C_API void inline_gc(cell *gc_roots_base, cell gc_roots_size, factor_vm *myvm);
|
2009-05-04 02:00:30 -04:00
|
|
|
|
2009-05-04 02:46:13 -04:00
|
|
|
}
|