2009-10-07 16:48:09 -04:00
|
|
|
#include "master.hpp"
|
|
|
|
|
2013-05-11 21:39:48 -04:00
|
|
|
namespace factor {
|
2009-10-07 16:48:09 -04:00
|
|
|
|
2016-09-22 06:35:38 -04:00
|
|
|
struct to_aging_copier : no_fixup {
|
2015-05-03 21:57:35 -04:00
|
|
|
aging_space* aging;
|
|
|
|
tenured_space* tenured;
|
|
|
|
|
2016-09-22 06:35:38 -04:00
|
|
|
to_aging_copier(aging_space* aging, tenured_space* tenured)
|
|
|
|
: aging(aging), tenured(tenured) { }
|
2015-05-03 21:57:35 -04:00
|
|
|
|
2016-09-22 06:35:38 -04:00
|
|
|
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;
|
|
|
|
}
|
2015-05-03 21:57:35 -04:00
|
|
|
|
2016-09-22 06:35:38 -04:00
|
|
|
cell size = obj->size();
|
|
|
|
object* newpointer = aging->allot(size);
|
|
|
|
if (!newpointer)
|
|
|
|
throw must_start_gc_again();
|
2015-05-03 21:57:35 -04:00
|
|
|
|
2016-09-22 06:35:38 -04:00
|
|
|
memcpy(newpointer, obj, size);
|
|
|
|
obj->forward_to(newpointer);
|
|
|
|
|
|
|
|
return newpointer;
|
|
|
|
}
|
2015-05-03 21:57:35 -04:00
|
|
|
};
|
|
|
|
|
2013-05-11 21:39:48 -04:00
|
|
|
void factor_vm::collect_aging() {
|
2016-08-21 10:26:04 -04:00
|
|
|
// Promote objects referenced from tenured space to tenured space, copy
|
|
|
|
// everything else to the aging semi-space, and reset the nursery pointer.
|
2013-05-11 21:39:48 -04:00
|
|
|
{
|
2016-08-21 10:26:04 -04:00
|
|
|
// Change the op so that if we fail here, an assertion will be raised.
|
2013-05-11 21:39:48 -04:00
|
|
|
current_gc->op = collect_to_tenured_op;
|
2009-10-15 06:51:11 -04:00
|
|
|
|
2016-09-22 06:35:38 -04:00
|
|
|
slot_visitor<from_tenured_refs_copier>
|
|
|
|
visitor(this, from_tenured_refs_copier(data->tenured, &mark_stack));
|
2016-05-04 11:52:04 -04:00
|
|
|
|
2013-05-11 21:39:48 -04:00
|
|
|
gc_event* event = current_gc->event;
|
2010-09-04 16:21:45 -04:00
|
|
|
|
2013-05-11 21:39:48 -04:00
|
|
|
if (event)
|
2016-04-24 09:21:17 -04:00
|
|
|
event->reset_timer();
|
2016-05-04 11:52:04 -04:00
|
|
|
visitor.visit_cards(data->tenured, card_points_to_aging, 0xff);
|
|
|
|
if (event)
|
|
|
|
event->ended_card_scan(visitor.cards_scanned, visitor.decks_scanned);
|
2009-10-27 00:57:26 -04:00
|
|
|
|
2013-05-11 21:39:48 -04:00
|
|
|
if (event)
|
2016-04-24 09:21:17 -04:00
|
|
|
event->reset_timer();
|
2016-05-04 11:52:04 -04:00
|
|
|
visitor.visit_code_heap_roots(&code->points_to_aging);
|
2013-05-11 21:39:48 -04:00
|
|
|
if (event)
|
2016-04-10 19:31:43 -04:00
|
|
|
event->ended_code_scan(code->points_to_aging.size());
|
2009-11-02 00:14:34 -05:00
|
|
|
|
2016-05-04 11:52:04 -04:00
|
|
|
visitor.visit_mark_stack(&mark_stack);
|
2013-05-11 21:39:48 -04:00
|
|
|
}
|
|
|
|
{
|
2016-08-21 10:26:04 -04:00
|
|
|
// If collection fails here, do a to_tenured collection.
|
2013-05-11 21:39:48 -04:00
|
|
|
current_gc->op = collect_aging_op;
|
2009-10-15 06:51:11 -04:00
|
|
|
|
2013-05-11 21:39:48 -04:00
|
|
|
std::swap(data->aging, data->aging_semispace);
|
2015-01-10 10:14:54 -05:00
|
|
|
data->reset_aging();
|
2009-10-08 03:10:28 -04:00
|
|
|
|
2016-09-22 06:35:38 -04:00
|
|
|
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();
|
2009-10-27 00:57:26 -04:00
|
|
|
|
2016-05-04 11:52:04 -04:00
|
|
|
visitor.visit_all_roots();
|
2016-09-22 06:35:38 -04:00
|
|
|
visitor.cheneys_algorithm(aging, scan);
|
2009-10-21 20:41:54 -04:00
|
|
|
|
2015-01-10 10:14:54 -05:00
|
|
|
data->reset_nursery();
|
2013-05-11 21:39:48 -04:00
|
|
|
code->clear_remembered_set();
|
|
|
|
}
|
2009-10-07 16:48:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|