Changeset f229fc2 for src/Common/GC.cc
- Timestamp:
- Apr 13, 2018, 12:25:33 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- b5aa3d8
- Parents:
- 09a1ae6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/GC.cc
r09a1ae6 rf229fc2 23 23 #include <cassert> 24 24 25 // #include <csignal>26 27 25 GC& GC::get() { 28 26 static GC gc; … … 47 45 if( obj ) 48 46 { 49 bool isMarked = obj->mark == this->mark; 50 if( !isMarked ) { 47 if( obj->mark != this->mark ) { 51 48 obj->mark = this->mark; 52 49 obj->trace( *this ); … … 57 54 58 55 void GC::register_object(GC_Object* obj) { 59 // if ( obj == (GC_Object*)0x60f00000e410ul ) std::raise( SIGTRAP );60 56 (using_young ? young : old).push_back(obj); 61 obj->mark = ! 57 obj->mark = !this->mark; // initialize as un-marked 62 58 } 63 59 … … 67 63 68 64 void 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 70 69 } 71 70 … … 78 77 79 78 void GC::collect_young() { 80 // check young generation, just reset mark if not using81 if ( ! using_young ) {82 mark = !mark;83 return;84 }85 86 79 // collect young gen 87 80 for ( GC_Object*& obj : young ) { … … 100 93 young.clear(); 101 94 102 // reset mark for next collection95 // reset mark to return to old generation mark 103 96 mark = !mark; 104 97 } 105 98 106 99 void 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 107 103 // collect old gen 108 104 for ( GC_Object*& obj : old ) { 109 105 if ( obj->mark != mark ) { 110 // if ( obj == (GC_Object*)0x60f00000e410ul ) std::raise( SIGTRAP );111 106 delete obj; 112 107 obj = nullptr; … … 117 112 old.erase( std::remove( old.begin(), old.end(), nullptr ), old.end() ); 118 113 119 // collect young gen (also resets mark)120 collect_young();114 // reset mark 115 mark = !mark; 121 116 } 122 117
Note: See TracChangeset
for help on using the changeset viewer.