예제 #1
0
  void test_collect_young_through_references() {
    ObjectMemory& om = *state->memory();
    Tuple *obj, *obj2, *obj3;

    obj =  (Tuple*)util_new_object(om);
    obj2 = (Tuple*)util_new_object(om);

    obj->field[0] = obj2;
    obj2->field[0] = cTrue;

    om.write_barrier(obj, obj2);

    Root r(roots, obj);

    om.collect_young(state, gc_data);

    TS_ASSERT(obj->forwarded_p());
    TS_ASSERT(obj2->forwarded_p());

    Object* new_obj = roots->front()->get();
    TS_ASSERT(obj != new_obj);
    obj = (Tuple*)new_obj;

    TS_ASSERT(om.young_->in_current_p(obj));
    obj3 = (Tuple*)obj->field[0];
    TS_ASSERT(obj2 != obj3);

    TS_ASSERT_EQUALS(obj2->field[0], cTrue);
  }
예제 #2
0
  void test_collect_young_promotes_objects() {
    ObjectMemory& om = *state->memory();
    Object* young;

    young = util_new_object(om);

    Root r(roots, young);

    om.set_young_lifetime(1);

    TS_ASSERT_EQUALS(young->age(), 0U);
    om.collect_young(state, gc_data);
    TS_ASSERT_EQUALS(roots->front()->get()->age(), 1U);
    om.collect_young(state, gc_data);

    TS_ASSERT(roots->front()->get()->mature_object_p());
  }
예제 #3
0
  void test_collect_young_doesnt_move_mature_objects() {
    ObjectMemory& om = *state->memory();
    Object* obj;

    om.large_object_threshold = 10;

    obj = util_new_object(om,20);

    Root r(roots, obj);

    om.collect_young(state, gc_data);

    TS_ASSERT_EQUALS(obj, roots->front()->get());
  }
예제 #4
0
  void test_collect_young_copies_byte_bodies() {
    ObjectMemory& om = *state->memory();

    ByteArray* obj;

    obj = ByteArray::create(state, 3);
    obj->raw_bytes()[0] = 47;

    Root r(roots, obj);

    om.collect_young(state, gc_data);

    obj = (ByteArray*)roots->front()->get();
    TS_ASSERT_EQUALS(obj->raw_bytes()[0], static_cast<char>(47));
  }
예제 #5
0
  void test_collect_young_copies_chararray_bodies() {
    ObjectMemory& om = *state->vm()->om;

    CharArray* obj;

    obj = CharArray::create(state, 3);
    obj->raw_bytes()[0] = 48;

    Root r(roots, obj);

    om.collect_young(*gc_data);

    obj = (CharArray*)roots->front()->get();
    TS_ASSERT_EQUALS(obj->raw_bytes()[0], static_cast<char>(48));
  }
예제 #6
0
  void test_collect_young_uses_forwarding_pointers() {
    ObjectMemory& om = *state->memory();
    Tuple *obj, *obj2;

    obj =  (Tuple*)util_new_object(om);
    obj2 = (Tuple*)util_new_object(om);

    obj->field[0] = obj2;
    obj->field[1] = obj2;
    obj->field[2] = obj2;

    om.write_barrier(obj, obj2);

    Root r(roots, obj);

    om.collect_young(state, gc_data);

    obj = (Tuple*)roots->front()->get();

    obj2 = (Tuple*)obj->field[0];
    TS_ASSERT_EQUALS(obj2, obj->field[1]);
    TS_ASSERT_EQUALS(obj2, obj->field[2]);
  }
예제 #7
0
  void test_collect_young_stops_at_already_marked_objects() {
    ObjectMemory& om = *state->memory();
    Tuple *obj, *obj2;

    obj =  (Tuple*)util_new_object(om);
    obj2 = (Tuple*)util_new_object(om);

    obj2->field[1] = cTrue;
    obj->field[0] = obj2;
    obj2->field[0] = obj;

    om.write_barrier(obj, obj2);
    om.write_barrier(obj2, obj);

    Root r(roots, obj);

    om.collect_young(state, gc_data);

    obj = (Tuple*)roots->front()->get();
    obj2 = (Tuple*)obj->field[0];

    TS_ASSERT_EQUALS(obj2->field[0], obj);
    TS_ASSERT_EQUALS(obj2->field[1], cTrue);
  }
예제 #8
0
  /* Could segfault on failure due to infinite loop. */
  void test_collect_mature_stops_at_already_marked_objects() {
    ObjectMemory& om = *state->vm()->om;
    Tuple *young, *mature;

    om.large_object_threshold = 50;

    young =  (Tuple*)util_new_object(om);
    mature = (Tuple*)util_new_object(om,20);

    young->field[0] = mature;
    mature->field[0] = young;

    om.write_barrier(young, mature);
    om.write_barrier(mature, young);

    Root r(roots, young);

    om.collect_mature(*gc_data);

    young = (Tuple*)roots->front()->get();
    mature = (Tuple*)young->field[0];

    TS_ASSERT_EQUALS(mature->field[0], young);
  }