Changeset f229fc2 for src/Common/GC.cc


Ignore:
Timestamp:
Apr 13, 2018, 12:25:33 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
b5aa3d8
Parents:
09a1ae6
Message:

Modify resolver to use young-generation collection per-top-level expression

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/GC.cc

    r09a1ae6 rf229fc2  
    2323#include <cassert>
    2424
    25 // #include <csignal>
    26 
    2725GC& GC::get() {
    2826        static GC gc;
     
    4745        if( obj )
    4846        {
    49                 bool isMarked = obj->mark == this->mark;
    50                 if( !isMarked ) {
     47                if( obj->mark != this->mark ) {
    5148                        obj->mark = this->mark;
    5249                        obj->trace( *this );
     
    5754
    5855void GC::register_object(GC_Object* obj) {
    59         // if ( obj == (GC_Object*)0x60f00000e410ul ) std::raise( SIGTRAP );
    6056        (using_young ? young : old).push_back(obj);
    61         obj->mark = ! this->mark;  // initialize as un-marked
     57        obj->mark = !this->mark;  // initialize as un-marked
    6258}
    6359
     
    6763
    6864void GC::new_generation() {
    69         using_young = true;
     65        assert(!using_young && "Cannot start new generation when young generation already in use");
     66       
     67        using_young = true;  // mark young generation as in-use
     68        mark = !mark;        // switch mark so aged young objects will still be unmarked in old
    7069}
    7170
     
    7877
    7978void GC::collect_young() {
    80         // check young generation, just reset mark if not using
    81         if ( ! using_young ) {
    82                 mark = !mark;
    83                 return;
    84         }
    85 
    8679        // collect young gen
    8780        for ( GC_Object*& obj : young ) {
     
    10093        young.clear();
    10194
    102         // reset mark for next collection
     95        // reset mark to return to old generation mark
    10396        mark = !mark;
    10497}
    10598
    10699void GC::collect() {
     100        // ensure not called when young gen is active
     101        assert(!using_young && "Cannot do old collection when young generation is active");
     102
    107103        // collect old gen
    108104        for ( GC_Object*& obj : old ) {
    109105                if ( obj->mark != mark ) {
    110                         // if ( obj == (GC_Object*)0x60f00000e410ul ) std::raise( SIGTRAP );
    111106                        delete obj;
    112107                        obj = nullptr;
     
    117112        old.erase( std::remove( old.begin(), old.end(), nullptr ), old.end() );
    118113
    119         // collect young gen (also resets mark)
    120         collect_young();
     114        // reset mark
     115        mark = !mark;
    121116}
    122117
Note: See TracChangeset for help on using the changeset viewer.