Changeset bd06384 for src/Common
- Timestamp:
- Mar 22, 2018, 4:49:53 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- dbc2c2c
- Parents:
- 7e4b44db
- Location:
- src/Common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/GC.cc
r7e4b44db rbd06384 16 16 #include "GC.h" 17 17 18 #include "Common/PassVisitor.h" 19 20 #include "SynTree/GcTracer.h" 21 18 22 #include <algorithm> 19 23 #include <cassert> … … 24 28 } 25 29 26 GC::GC() : mark(false), old(), young(), using_young(false) {30 GC::GC() : mark(false), using_young(false), old(), young(), static_roots() { 27 31 old.reserve(70000); 28 32 } … … 55 59 } 56 60 61 void GC::register_static_root(BaseSyntaxNode* root) { 62 static_roots.push_back(root); 63 } 64 57 65 void GC::new_generation() { 58 66 using_young = true; 67 } 68 69 void GC::trace_static_roots() { 70 PassVisitor<GcTracer> tracer{ *this }; 71 for ( BaseSyntaxNode* root : static_roots ) { 72 root->accept( tracer ); 73 } 59 74 } 60 75 -
src/Common/GC.h
r7e4b44db rbd06384 20 20 class GC_Traceable; 21 21 class GC_Object; 22 class BaseSyntaxNode; 22 23 23 24 /// Manually traced and called garbage collector … … 34 35 void register_object(GC_Object*); 35 36 37 /// Adds an object to the set of static roots 38 void register_static_root(BaseSyntaxNode*); 39 36 40 /// Use young generation for subsequent new objects 37 41 void new_generation(); 42 43 /// Traces all static roots 44 void trace_static_roots(); 38 45 39 46 /// Collects the young generation, placing survivors in old generation. … … 50 57 GC(); 51 58 52 ///The current collection's mark bit53 bool mark;59 bool mark; ///< The current collection's mark bit 60 bool using_young; ///< Is the young generation in use? 54 61 55 typedef std::vector<class GC_Object*> Generation; 56 Generation old; 57 Generation young; 58 bool using_young; 62 using Generation = std::vector<GC_Object*>; 63 Generation old; ///< Old generation 64 Generation young; ///< Young generation 65 66 using StaticRoots = std::vector<BaseSyntaxNode*>; 67 StaticRoots static_roots; ///< Set of static-lifetime roots 59 68 }; 60 69 … … 80 89 GC& gc = GC::get(); 81 90 traceAll(gc, roots...); 91 gc.trace_static_roots(); 82 92 gc.collect_young(); 83 93 } … … 88 98 GC& gc = GC::get(); 89 99 traceAll(gc, roots...); 100 gc.trace_static_roots(); 90 101 gc.collect(); 102 } 103 104 /// Makes a new expression as a static root 105 template<typename T, typename... Args> 106 inline T* new_static_root( Args&&... args ) { 107 T* root = new T( std::forward<Args>(args)... ); 108 GC::get().register_static_root( root ); 109 return root; 91 110 } 92 111 -
src/Common/PassVisitor.impl.h
r7e4b44db rbd06384 38 38 MUTATE_END( type, node ); \ 39 39 40 40 #include "Common/GC.h" 41 41 42 42 template<typename T> … … 397 397 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 398 398 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 399 static ObjectDecl func(399 static ObjectDecl* func = new_static_root<ObjectDecl>( 400 400 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 401 401 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 402 402 nullptr 403 403 ); 404 indexerAddId( &func );404 indexerAddId( func ); 405 405 maybeAccept_impl( node->type, *this ); 406 406 maybeAccept_impl( node->statements, *this ); … … 427 427 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 428 428 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 429 static ObjectDecl func(429 static ObjectDecl* func = new_static_root<ObjectDecl>( 430 430 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 431 431 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 432 432 nullptr 433 433 ); 434 indexerAddId( &func );434 indexerAddId( func ); 435 435 maybeMutate_impl( node->type, *this ); 436 436 maybeMutate_impl( node->statements, *this );
Note: See TracChangeset
for help on using the changeset viewer.