Changeset 04570c7 for src/Common/GC.cc
- Timestamp:
- Apr 13, 2018, 4:39:28 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- 6f81db3
- Parents:
- 3205495
- git-author:
- Aaron Moss <a3moss@…> (04/13/18 16:27:11)
- git-committer:
- Aaron Moss <a3moss@…> (04/13/18 16:39:28)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/GC.cc
r3205495 r04570c7 28 28 } 29 29 30 GC::GC() : mark(false), using_young(false), old(), young(), static_roots() {31 old.reserve(70000);30 GC::GC() : gens(1), static_roots(), mark(false), g(0) { 31 gens[0].reserve(70000); 32 32 } 33 33 34 34 GC::~GC() { 35 for ( GC_Object* o : young ) { 36 delete o; 37 } 38 39 for ( GC_Object* o : old ) { 40 delete o; 35 for ( unsigned i = 0; i <= g; ++i ) { 36 for ( GC_Object* o : gens[i] ) { 37 delete o; 38 } 41 39 } 42 40 } … … 54 52 55 53 void GC::register_object(GC_Object* obj) { 56 (using_young ? young : old).push_back(obj);54 gens[g].push_back(obj); 57 55 obj->mark = !this->mark; // initialize as un-marked 58 56 } … … 63 61 64 62 void GC::new_generation() { 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 63 if ( ++g == gens.size() ) { gens.emplace_back(); } // ensure new generation available 64 mark = !mark; // switch mark so aged young objects will still be unmarked in old 69 65 } 70 66 … … 77 73 78 74 void GC::collect_young() { 75 // get generations and decrement generation 76 assert(g > 0 && "Cannot collect_young without young generation"); 77 Generation& young = gens[g]; 78 Generation& old = gens[--g]; 79 79 80 // collect young gen 80 81 for ( GC_Object*& obj : young ) { … … 89 90 old.insert( old.end(), young.begin(), end_live ); 90 91 91 // clear young gen 92 using_young = false; 92 // clear young gen and reset mark to return to old generation mark 93 93 young.clear(); 94 95 // reset mark to return to old generation mark96 94 mark = !mark; 97 95 } … … 99 97 void GC::collect() { 100 98 // ensure not called when young gen is active 101 assert(!using_young && "Cannot do old collection when young generation is active"); 99 assert(g == 0 && "Cannot do old collection when young generation is active"); 100 Generation& old = gens[0]; 102 101 103 102 // collect old gen
Note: See TracChangeset
for help on using the changeset viewer.