Changeset 2efe4b8
- Timestamp:
- Apr 25, 2018, 3:42:34 PM (5 years ago)
- Branches:
- new-env, with_gc
- Children:
- 1cdfa82
- Parents:
- 5af7306
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/GC.cc
r5af7306 r2efe4b8 77 77 } 78 78 79 void GC::new_generation() {79 GC_Guard GC::new_generation() { 80 80 if ( ++g == gens.size() ) { gens.emplace_back(); } // ensure new generation available 81 81 mark = !mark; // switch mark so aged young objects will still be unmarked in old 82 return { *this, g }; 82 83 } 83 84 -
src/Common/GC.h
r5af7306 r2efe4b8 16 16 #pragma once 17 17 18 #include <cassert> 18 19 #include <vector> 19 20 20 21 class GC_Object; 21 22 class BaseSyntaxNode; 23 class GC_Guard; 22 24 23 25 /// Manually traced and called garbage collector 24 26 class GC { 25 27 friend class GcTracer; 28 friend class GC_Guard; 29 30 /// Collects the youngest generation, placing survivors in previous generation. 31 /// Young generation objects cannot be kept alive by pointers from older generation. 32 /// Older generation is used for subsequent new objects. 33 void collect_young(); 26 34 public: 27 35 /// Gets singleton GC instance … … 38 46 39 47 /// Start new generation for subsequent new objects 40 void new_generation();48 GC_Guard new_generation(); 41 49 42 50 /// Traces all static roots 43 51 void trace_static_roots(); 44 45 /// Collects the youngest generation, placing survivors in previous generation.46 /// Young generation objects cannot be kept alive by pointers from older generation.47 /// Older generation is used for subsequent new objects.48 void collect_young();49 52 50 53 /// Collects oldest generation; use oldest generation afterward. … … 68 71 }; 69 72 73 /// Cleanup object for young generation 74 class GC_Guard { 75 friend class GC; 76 77 GC& gc; ///< GC associated with 78 unsigned g; ///< Generation constructed for 79 80 GC_Guard( GC& gc, unsigned g ) : gc(gc), g(g) {} 81 82 public: 83 ~GC_Guard() { 84 assert( gc.g == g && "collecting current generation" ); 85 gc.collect_young(); 86 } 87 }; 88 70 89 /// Use young generation until next collection 71 inline void new_generation() {GC::get().new_generation(); }90 inline GC_Guard new_generation() { return GC::get().new_generation(); } 72 91 73 92 // /// no-op default trace … … 84 103 } 85 104 86 /// Traces young-generation roots and does a young collection105 /// Traces roots without collecting 87 106 template<typename... Args> 88 inline void collect_young(Args&... roots) {107 inline void trace(Args&... roots) { 89 108 GC& gc = GC::get(); 90 109 traceAll(gc, roots...); 91 110 gc.trace_static_roots(); 92 gc.collect_young();93 111 } 94 112 95 /// Traces roots and collects other elements 113 /// Traces roots and collects other elements; should not be any young generations live 96 114 template<typename... Args> 97 115 inline void collect(Args&... roots) { -
src/GenPoly/Box.cc
r5af7306 r2efe4b8 283 283 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); 284 284 param != otypeParams.end(); ++param ) { 285 TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param );286 std::string paramName = mangleType( ¶mType );285 auto paramType = new TypeInstType( Type::Qualifiers(), (*param)->get_name(), *param ); 286 std::string paramName = mangleType( paramType ); 287 287 layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType->clone(), 0 ) ); 288 288 layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType->clone(), 0 ) ); … … 1436 1436 if ( Type * base = typeDecl->base ) { 1437 1437 // add size/align variables for opaque type declarations 1438 TypeInstType inst( Type::Qualifiers(), typeDecl->name, typeDecl );1439 std::string typeName = mangleType( &inst );1438 auto inst = new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ); 1439 std::string typeName = mangleType( inst ); 1440 1440 Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 1441 1441 -
src/ResolvExpr/Resolver.cc
r5af7306 r2efe4b8 148 148 assertf( untyped, "expected a non-null expression." ); 149 149 150 new_generation(); // set up GC younggeneration for this top-level expression150 auto guard = new_generation(); // set up GC generation for this top-level expression 151 151 152 152 TypeEnvironment env; … … 177 177 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) ); 178 178 if ( winners.size() == 0 ) { 179 collect_young();180 179 SemanticError( untyped, toString( 181 180 "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), … … 189 188 printAlts( winners, stream, 1 ); 190 189 191 collect_young();192 190 SemanticError( untyped->location, stream.str() ); 193 191 } … … 196 194 Alternative & choice = winners.front(); 197 195 if ( findDeletedExpr( choice.expr ) ) { 198 collect_young( choice.expr );196 trace( choice.expr ); 199 197 SemanticError( choice.expr, 200 198 "Unique best alternative includes deleted identifier in " ); 201 199 } 202 200 alt = std::move( choice ); 203 collect_young( alt );201 trace( alt ); 204 202 } 205 203 -
src/SynTree/GcTracer.h
r5af7306 r2efe4b8 20 20 #include "BaseSyntaxNode.h" 21 21 #include "Expression.h" 22 #include "Label.h" 22 23 #include "Type.h" 23 24 … … 53 54 } 54 55 56 void postvisit( AggregateDecl* decl ) { 57 acceptAll( decl->attributes, *visitor ); 58 } 59 55 60 void postvisit( DeclarationWithType* decl ) { 56 61 maybeAccept( decl->asmName, *visitor ); … … 73 78 } 74 79 80 void postvisit( UniqueExpr* expr ) { 81 postvisit( static_cast<Expression*>(expr) ); 82 maybeAccept( expr->object, *visitor ); 83 maybeAccept( expr->var, *visitor ); 84 } 85 75 86 void postvisit( UntypedExpr* expr ) { 76 87 postvisit( static_cast<Expression*>(expr) ); … … 81 92 postvisit( static_cast<Expression*>(expr) ); 82 93 maybeAccept( expr->var, *visitor ); // not in PassVisitor because it causes cycle 94 } 95 96 private: 97 void visit( Label& lbl ) { 98 acceptAll( lbl.get_attributes(), *visitor ); 99 maybeAccept( lbl.get_statement(), *visitor ); // xxx - not sure this is needed... 100 } 101 102 public: 103 void postvisit( Statement* stmt ) { 104 for ( Label& l : stmt->labels ) { 105 visit( l ); 106 } 83 107 } 84 108
Note: See TracChangeset
for help on using the changeset viewer.