Пример #1
0
 Root(Roots* roots, Object* obj)
   : LinkedList::Node()
   , roots_(roots)
   , object_(obj)
 {
   roots_->add(this);
 }
Пример #2
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);
  }
Пример #3
0
  void MarkSweepGC::collect(Roots &roots, CallFrameLocationList& call_frames) {
    Object* tmp;

    Root* root = static_cast<Root*>(roots.head());
    while(root) {
      tmp = root->get();
      if(tmp->reference_p()) {
        saw_object(tmp);
      }

      root = static_cast<Root*>(root->next());
    }

    // Walk all the call frames
    for(CallFrameLocationList::const_iterator i = call_frames.begin();
        i != call_frames.end();
        ++i) {
      CallFrame** loc = *i;
      walk_call_frame(*loc);
    }

    while(!mark_stack_.empty()) {
      tmp = mark_stack_.back();
      mark_stack_.pop_back();
      scan_object(tmp);
    }

    after_marked();
  }
Пример #4
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());
  }
Пример #5
0
  void GarbageCollector::visit_roots(Roots& roots, ObjectVisitor& visit) {
    Root* root = static_cast<Root*>(roots.head());
    while(root) {
      Object* tmp = root->get();
      if(tmp->reference_p()) {
        visit.call(tmp);
      }

      root = static_cast<Root*>(root->next());
    }
  }
Пример #6
0
  void HeapDebug::walk(Roots &roots) {
    Object* tmp;

    Root* root = static_cast<Root*>(roots.head());
    while(root) {
      tmp = root->get();
      if(tmp->reference_p()) {
        saw_object(tmp);
      }

      root = static_cast<Root*>(root->next());
    }
  }
Пример #7
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());
  }
Пример #8
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));
  }
Пример #9
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));
  }
Пример #10
0
  void MarkSweepGC::collect(Roots &roots) {
    Object* tmp;

    Root* root = static_cast<Root*>(roots.head());
    while(root) {
      tmp = root->get();
      if(tmp->reference_p()) {
        saw_object(tmp);
      }

      root = static_cast<Root*>(root->next());
    }

    // Cleanup all weakrefs seen
    clean_weakrefs();

    // Sweep up the garbage
    sweep_objects();
  }
Пример #11
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]);
  }
Пример #12
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);
  }
Пример #13
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);
  }
Пример #14
0
 inline Root::Root(Roots* roots, Object* obj):
   LinkedList::Node(), object(obj), roots(roots)
 {
     roots->add(this);
 }
Foam::plane Foam::sweptFaceAreaWeightAMI<SourcePatch, TargetPatch>::getCutPlane
(
    const point& p0,
    const point& p1,
    const vector& n0,
    const vector& n1,
    const FixedList<point, 3>& tgtTri
) const
{
    // The target plane
    const plane tgtPln(tgtTri[0], tgtTri[1], tgtTri[2]);
    const point& pp = tgtPln.refPoint();
    const vector& np = tgtPln.normal();

    // Calculate the bounding intersection points. These are the locations at
    // which the bounding lines of the projected surface intersect with the
    // target plane.
    const scalar v0 = ((pp - p0) & np)/(n0 & np);
    const scalar v1 = ((pp - p1) & np)/(n1 & np);
    Pair<point> cutPnts(p0 + v0*n0, p1 + v1*n1);
    Pair<vector> cutNrms((p1 - p0 + n1*v0) ^ n0, (p1 - p0 - n0*v1) ^ n1);

    // Calculate edge intersections with the surface
    for (label i = 0; i < 3; ++ i)
    {
        // The current target edge
        const point& l0 = tgtTri[i], l1 = tgtTri[(i + 1)%3];

        // Form the quadratic in the surface parameter u
        const vector k = l0 - p0;
        const vector a = l0 - l1, b = p1 - p0, c = n0, d = n1 - n0;
        const vector ka = k ^ a, ba = b ^ a, ca = c ^ a, da = d ^ a;
        const scalar A = d & ba;
        const scalar B = (c & ba) - (d & ka);
        const scalar C = - c & ka;

        // Solve and extract the other parameters
        const Roots<2> us = quadraticEqn(A, B, C).roots();
        Pair<scalar> vs, ws;
        Pair<vector> ns;
        Pair<bool> cuts(false, false);
        for (label j = 0; j < 2; ++ j)
        {
            if (us.type(j) == rootType::real)
            {
                const vector den = ca + da*us[j];
                if (magSqr(den) > vSmall)
                {
                    const vector vNum = ka - ba*us[j];
                    const vector wNum = (- k + b*us[j]) ^ (c + d*us[j]);
                    vs[j] = (vNum & den)/magSqr(den);
                    ws[j] = (wNum & den)/magSqr(den);
                    ns[j] = (b ^ (c + d*us[j])) + (n1 ^ n0)*vs[j];
                    const bool cutu = 0 < us[j] && us[j] < 1;
                    const bool cutw = 0 < ws[j] && ws[j] < 1;
                    cuts[j] = cutu && cutw;
                }
            }
        }

        // If we have just one intersection in bounds then store it in the
        // result list based on its direction
        if (cuts[0] != cuts[1])
        {
            const label j = cuts[0] ? 0 : 1;
            const scalar na = ns[j] & a;
            cutPnts[na < 0] = l0 + (l1 - l0)*ws[j];
            cutNrms[na < 0] = ns[j];
        }
    }

    // Generate and return the cut plane. If the cut points are not coincident
    // then form a plane normal by crossing the displacement between the points
    // by the target plane normal. If the points are coincident then use the
    // projected surface normal evaluated at the first cut point.
    const vector cutDelta = cutPnts[1] - cutPnts[0];
    const bool coincident = mag(cutDelta) < minCutRatio_*mag(p1 - p0);
    return plane(cutPnts[0], coincident ? cutNrms[0] : np ^ cutDelta);
};
Пример #16
0
 ~Root() {
   if(roots_ && object_) roots_->remove(this);
 }
Пример #17
0
 inline Root::~Root() {
   if(roots && object) {
     roots->remove(this);
   }
 }
Пример #18
0
// Function to compute the sustainable speed in KM/H from input params and a
// bunch of real world constants.
// Relies upon cubic root finder.
// The bicycle related equations came from http://kreuzotter.de/english/espeed.htm,
// The pressure and density equations came from wikipedia.
double computeInstantSpeed(double weightKG,
                           double slope,
                           double altitude, // altitude in meters
                           double pw,       // watts
                           double crr,      // rolling resistance
                           double Cm,       // powertrain loss
                           double Cd,       // coefficient of drag
                           double A,        // frontal area (m2)
                           double T)        // temp in kelvin
{
    double vs = 0; // Return value

    double sl = slope / 100;          // 10% = 0.1

    // Compute velocity using equations from http://kreuzotter.de/english/espeed.htm
    const double CrV = 0.1;           // Coefficient for velocity - dependent dynamic rolling resistance, here approximated with 0.1
    double CrVn = CrV * cos(sl);      // Coefficient for the dynamic rolling resistance, normalized to road inclination; CrVn = CrV*cos(slope)
    const double W = 0;               // Windspeed
    double Hnn = altitude;            // Altitude above sea level (m).
    double m = weightKG;

    double Rho = AirDensity(Hnn, T);
    double Beta = atan(sl);
    double cosBeta = cos(Beta);
    double sinBeta = sin(Beta);
    double Frg = s_g0 * m * (crr * cosBeta + sinBeta);

    // Home Rolled cubic solver:
    // v^3 + v^2 * 2 * (W + CrVn/(Cd *A*Rho)) + V*(W^2 + (2*Frg/(Cd*A*Rho))) - (2*P)/(Cm*Cd*A*Rho) = 0;
    //
    //  A = 1 (monic)
    //  B = 2 * (W + CrVn / (Cd*A*Rho))
    //  C = (W ^ 2 + (2 * Frg / (Cd*A*Rho)))
    //  D = -(2 * P) / (Cm*Cd*A*Rho)

    double CdARho = Cd * A * Rho;

    double  a = 1;
    double  b = 2 * (W + CrVn / (CdARho));
    double  c = (W * W + (2 * Frg / (CdARho)));
    double  d = -(2 * pw) / (Cm * CdARho);

    vs = 0;
    {
        Roots r = BlinnCubicSolver(a, b, c, d);

        // Iterate across roots for one that provides a positive velocity,
        // otherwise try and choose a positive one that is closest to zero,
        // finally tolerate a negative one thats closest to zero.
        for (unsigned u = 0; u < r.resultcount(); u++) {
            double t = r.result(u).x / r.result(u).w;
            if (vs == 0) vs = t;
            else if (vs > 0) {
                if (t > 0 && t < vs) vs = t;
            } else {
                if (t > vs) vs = t;
            }
        }
    }

#if 0
    // Now to test we run the equation the other way and compute power needed to sustain computed speed.
    // A properly computed v should very closely predict the power needed to sustain that speed.
    double testPw = Cm * vs * (Cd * A * Rho / 2 * (vs + W)*(vs + W) + Frg + vs * CrVn);
    double delta = fabs(testPw - pw);
#endif

    vs *= 3.6; // m/s to km/h.

    return vs;
}
Пример #19
0
 ~Root() {
   if(roots_ && object_ && object_ != cUndef) roots_->remove(this);
 }