namespace factor {
-struct aging_policy {
+struct to_aging_copier : no_fixup {
aging_space* aging;
tenured_space* tenured;
- explicit aging_policy(factor_vm* parent)
- : aging(parent->data->aging), tenured(parent->data->tenured) {}
+ to_aging_copier(aging_space* aging, tenured_space* tenured)
+ : aging(aging), tenured(tenured) { }
- bool should_copy_p(object* untagged) {
- return !(aging->contains_p(untagged) || tenured->contains_p(untagged));
- }
+ object* fixup_data(object* obj) {
+ if (aging->contains_p(obj) || tenured->contains_p(obj)) {
+ return obj;
+ }
+
+ // Is there another forwarding pointer?
+ while (obj->forwarding_pointer_p()) {
+ object* dest = obj->forwarding_pointer();
+ obj = dest;
+ }
+
+ if (aging->contains_p(obj) || tenured->contains_p(obj)) {
+ return obj;
+ }
- void promoted_object(object* obj) {}
+ cell size = obj->size();
+ object* newpointer = aging->allot(size);
+ if (!newpointer)
+ throw must_start_gc_again();
- void visited_object(object* obj) {}
+ memcpy(newpointer, obj, size);
+ obj->forward_to(newpointer);
+
+ return newpointer;
+ }
};
void factor_vm::collect_aging() {
// Change the op so that if we fail here, an assertion will be raised.
current_gc->op = collect_to_tenured_op;
- gc_workhorse<tenured_space, to_tenured_policy>
- workhorse(this, data->tenured, to_tenured_policy(this));
- slot_visitor<gc_workhorse<tenured_space, to_tenured_policy>>
- visitor(this, workhorse);
+ slot_visitor<from_tenured_refs_copier>
+ visitor(this, from_tenured_refs_copier(data->tenured, &mark_stack));
gc_event* event = current_gc->event;
std::swap(data->aging, data->aging_semispace);
data->reset_aging();
- aging_space *target = data->aging;
- gc_workhorse<aging_space, aging_policy>
- workhorse(this, target, aging_policy(this));
- slot_visitor<gc_workhorse<aging_space, aging_policy>>
- visitor(this, workhorse);
- cell scan = target->start + target->occupied_space();
+ aging_space *aging = data->aging;
+ slot_visitor<to_aging_copier>
+ visitor(this, to_aging_copier(aging, data->tenured));
+
+ cell scan = aging->start + aging->occupied_space();
visitor.visit_all_roots();
- visitor.cheneys_algorithm(target, scan);
+ visitor.cheneys_algorithm(aging, scan);
data->reset_nursery();
code->clear_remembered_set();