Remove GC test code from ancient.

parent f0bad600
......@@ -1635,272 +1635,3 @@ mrb_init_gc(mrb_state *mrb)
#endif
#endif
}
#ifdef GC_TEST
#ifdef GC_DEBUG
void
test_mrb_field_write_barrier(void)
{
mrb_state *mrb = mrb_open();
struct RBasic *obj, *value;
mrb_gc *gc = &mrb->gc;
puts("test_mrb_field_write_barrier");
gc->generational = FALSE;
obj = mrb_basic_ptr(mrb_ary_new(mrb));
value = mrb_basic_ptr(mrb_str_new_lit(mrb, "value"));
paint_black(obj);
paint_partial_white(gc, value);
puts(" in MRB_GC_STATE_MARK");
gc->state = MRB_GC_STATE_MARK;
mrb_field_write_barrier(mrb, obj, value);
mrb_assert(is_gray(value));
puts(" in MRB_GC_STATE_SWEEP");
paint_partial_white(gc, value);
gc->state = MRB_GC_STATE_SWEEP;
mrb_field_write_barrier(mrb, obj, value);
mrb_assert(obj->color & gc->current_white_part);
mrb_assert(value->color & gc->current_white_part);
puts(" fail with black");
gc->state = MRB_GC_STATE_MARK;
paint_white(obj);
paint_partial_white(gc, value);
mrb_field_write_barrier(mrb, obj, value);
mrb_assert(obj->color & gc->current_white_part);
puts(" fail with gray");
gc->state = MRB_GC_STATE_MARK;
paint_black(obj);
paint_gray(value);
mrb_field_write_barrier(mrb, obj, value);
mrb_assert(is_gray(value));
{
puts("test_mrb_field_write_barrier_value");
obj = mrb_basic_ptr(mrb_ary_new(mrb));
mrb_value value = mrb_str_new_lit(mrb, "value");
paint_black(obj);
paint_partial_white(gc, mrb_basic_ptr(value));
gc->state = MRB_GC_STATE_MARK;
mrb_field_write_barrier_value(mrb, obj, value);
mrb_assert(is_gray(mrb_basic_ptr(value)));
}
mrb_close(mrb);
}
void
test_mrb_write_barrier(void)
{
mrb_state *mrb = mrb_open();
struct RBasic *obj;
mrb_gc *gc = &mrb->gc;
puts("test_mrb_write_barrier");
obj = mrb_basic_ptr(mrb_ary_new(mrb));
paint_black(obj);
puts(" in MRB_GC_STATE_MARK");
gc->state = MRB_GC_STATE_MARK;
mrb_write_barrier(mrb, obj);
mrb_assert(is_gray(obj));
mrb_assert(gc->atomic_gray_list == obj);
puts(" fail with gray");
paint_gray(obj);
mrb_write_barrier(mrb, obj);
mrb_assert(is_gray(obj));
mrb_close(mrb);
}
void
test_add_gray_list(void)
{
mrb_state *mrb = mrb_open();
struct RBasic *obj1, *obj2;
mrb_gc *gc = &mrb->gc;
puts("test_add_gray_list");
change_gen_gc_mode(mrb, gc, FALSE);
mrb_assert(gc->gray_list == NULL);
obj1 = mrb_basic_ptr(mrb_str_new_lit(mrb, "test"));
add_gray_list(mrb, gc, obj1);
mrb_assert(gc->gray_list == obj1);
mrb_assert(is_gray(obj1));
obj2 = mrb_basic_ptr(mrb_str_new_lit(mrb, "test"));
add_gray_list(mrb, gc, obj2);
mrb_assert(gc->gray_list == obj2);
mrb_assert(gc->gray_list->gcnext == obj1);
mrb_assert(is_gray(obj2));
mrb_close(mrb);
}
void
test_gc_gray_mark(void)
{
mrb_state *mrb = mrb_open();
mrb_value obj_v, value_v;
struct RBasic *obj;
size_t gray_num = 0;
mrb_gc *gc = &mrb->gc;
puts("test_gc_gray_mark");
puts(" in MRB_TT_CLASS");
obj = (struct RBasic*)mrb->object_class;
paint_gray(obj);
gray_num = gc_gray_mark(mrb, gc, obj);
mrb_assert(is_black(obj));
mrb_assert(gray_num > 1);
puts(" in MRB_TT_ARRAY");
obj_v = mrb_ary_new(mrb);
value_v = mrb_str_new_lit(mrb, "test");
paint_gray(mrb_basic_ptr(obj_v));
paint_partial_white(gc, mrb_basic_ptr(value_v));
mrb_ary_push(mrb, obj_v, value_v);
gray_num = gc_gray_mark(mrb, gc, mrb_basic_ptr(obj_v));
mrb_assert(is_black(mrb_basic_ptr(obj_v)));
mrb_assert(is_gray(mrb_basic_ptr(value_v)));
mrb_assert(gray_num == 1);
mrb_close(mrb);
}
void
test_incremental_gc(void)
{
mrb_state *mrb = mrb_open();
size_t max = ~0, live = 0, total = 0, freed = 0;
RVALUE *free;
mrb_heap_page *page;
mrb_gc *gc = &mrb->gc;
puts("test_incremental_gc");
change_gen_gc_mode(mrb, gc, FALSE);
puts(" in mrb_full_gc");
mrb_full_gc(mrb);
mrb_assert(gc->state == MRB_GC_STATE_ROOT);
puts(" in MRB_GC_STATE_ROOT");
incremental_gc(mrb, gc, max);
mrb_assert(gc->state == MRB_GC_STATE_MARK);
puts(" in MRB_GC_STATE_MARK");
incremental_gc_until(mrb, gc, MRB_GC_STATE_SWEEP);
mrb_assert(gc->state == MRB_GC_STATE_SWEEP);
puts(" in MRB_GC_STATE_SWEEP");
page = gc->heaps;
while (page) {
RVALUE *p = objects(page);
RVALUE *e = p + MRB_HEAP_PAGE_SIZE;
while (p<e) {
if (is_black(&p->as.basic)) {
live++;
}
if (is_gray(&p->as.basic) && !is_dead(gc, &p->as.basic)) {
printf("%p\n", &p->as.basic);
}
p++;
}
page = page->next;
total += MRB_HEAP_PAGE_SIZE;
}
mrb_assert(gc->gray_list == NULL);
incremental_gc(mrb, gc, max);
mrb_assert(gc->state == MRB_GC_STATE_SWEEP);
incremental_gc(mrb, gc, max);
mrb_assert(gc->state == MRB_GC_STATE_ROOT);
free = (RVALUE*)gc->heaps->freelist;
while (free) {
freed++;
free = (RVALUE*)free->as.free.next;
}
mrb_assert(gc->live == live);
mrb_assert(gc->live == total-freed);
puts("test_incremental_gc(gen)");
incremental_gc_until(mrb, gc, MRB_GC_STATE_SWEEP);
change_gen_gc_mode(mrb, gc, TRUE);
mrb_assert(gc->full == FALSE);
mrb_assert(gc->state == MRB_GC_STATE_ROOT);
puts(" in minor");
mrb_assert(is_minor_gc(gc));
mrb_assert(gc->majorgc_old_threshold > 0);
gc->majorgc_old_threshold = 0;
mrb_incremental_gc(mrb);
mrb_assert(gc->full == TRUE);
mrb_assert(gc->state == MRB_GC_STATE_ROOT);
puts(" in major");
mrb_assert(is_major_gc(gc));
do {
mrb_incremental_gc(mrb);
} while (gc->state != MRB_GC_STATE_ROOT);
mrb_assert(gc->full == FALSE);
mrb_close(mrb);
}
void
test_incremental_sweep_phase(void)
{
mrb_state *mrb = mrb_open();
mrb_gc *gc = &mrb->gc;
puts("test_incremental_sweep_phase");
add_heap(mrb, gc);
gc->sweeps = gc->heaps;
mrb_assert(gc->heaps->next->next == NULL);
mrb_assert(gc->free_heaps->next->next == NULL);
incremental_sweep_phase(mrb, gc, MRB_HEAP_PAGE_SIZE * 3);
mrb_assert(gc->heaps->next == NULL);
mrb_assert(gc->heaps == gc->free_heaps);
mrb_close(mrb);
}
static mrb_value
gc_test(mrb_state *mrb, mrb_value self)
{
test_mrb_field_write_barrier();
test_mrb_write_barrier();
test_add_gray_list();
test_gc_gray_mark();
test_incremental_gc();
test_incremental_sweep_phase();
return mrb_nil_value();
}
#endif /* GC_DEBUG */
#endif /* GC_TEST */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment