VM: Refactor aging_collector to Factor style

db4
Erik Charlebois 2013-05-11 21:39:48 -04:00
parent a42ba561d2
commit ee9fd64b69
2 changed files with 53 additions and 56 deletions

View File

@ -1,16 +1,13 @@
#include "master.hpp" #include "master.hpp"
namespace factor namespace factor {
{
aging_collector::aging_collector(factor_vm *parent_) : aging_collector::aging_collector(factor_vm* parent_)
copying_collector<aging_space,aging_policy>( : copying_collector<aging_space, aging_policy>(parent_,
parent_,
parent_->data->aging, parent_->data->aging,
aging_policy(parent_)) {} aging_policy(parent_)) {}
void factor_vm::collect_aging() void factor_vm::collect_aging() {
{
/* Promote objects referenced from tenured space to tenured space, copy /* Promote objects referenced from tenured space to tenured space, copy
everything else to the aging semi-space, and reset the nursery pointer. */ everything else to the aging semi-space, and reset the nursery pointer. */
{ {
@ -20,17 +17,19 @@ void factor_vm::collect_aging()
to_tenured_collector collector(this); to_tenured_collector collector(this);
gc_event *event = current_gc->event; gc_event* event = current_gc->event;
if(event) event->started_card_scan(); if (event)
collector.trace_cards(data->tenured, event->started_card_scan();
card_points_to_aging, collector.trace_cards(data->tenured, card_points_to_aging, full_unmarker());
full_unmarker()); if (event)
if(event) event->ended_card_scan(collector.cards_scanned,collector.decks_scanned); event->ended_card_scan(collector.cards_scanned, collector.decks_scanned);
if(event) event->started_code_scan(); if (event)
event->started_code_scan();
collector.trace_code_heap_roots(&code->points_to_aging); collector.trace_code_heap_roots(&code->points_to_aging);
if(event) event->ended_code_scan(collector.code_blocks_scanned); if (event)
event->ended_code_scan(collector.code_blocks_scanned);
collector.tenure_reachable_objects(); collector.tenure_reachable_objects();
} }
@ -38,7 +37,7 @@ void factor_vm::collect_aging()
/* If collection fails here, do a to_tenured collection. */ /* If collection fails here, do a to_tenured collection. */
current_gc->op = collect_aging_op; current_gc->op = collect_aging_op;
std::swap(data->aging,data->aging_semispace); std::swap(data->aging, data->aging_semispace);
data->reset_generation(data->aging); data->reset_generation(data->aging);
aging_collector collector(this); aging_collector collector(this);

View File

@ -1,28 +1,26 @@
namespace factor namespace factor {
{
struct aging_policy { struct aging_policy {
factor_vm *parent; factor_vm* parent;
aging_space *aging; aging_space* aging;
tenured_space *tenured; tenured_space* tenured;
explicit aging_policy(factor_vm *parent_) : explicit aging_policy(factor_vm* parent_)
parent(parent_), : parent(parent_),
aging(parent->data->aging), aging(parent->data->aging),
tenured(parent->data->tenured) {} tenured(parent->data->tenured) {}
bool should_copy_p(object *untagged) bool should_copy_p(object* untagged) {
{
return !(aging->contains_p(untagged) || tenured->contains_p(untagged)); return !(aging->contains_p(untagged) || tenured->contains_p(untagged));
} }
void promoted_object(object *obj) {} void promoted_object(object* obj) {}
void visited_object(object *obj) {} void visited_object(object* obj) {}
}; };
struct aging_collector : copying_collector<aging_space,aging_policy> { struct aging_collector : copying_collector<aging_space, aging_policy> {
explicit aging_collector(factor_vm *parent_); explicit aging_collector(factor_vm* parent_);
}; };
} }