Changeset 2efe4b8 for src/Common/GC.h
- Timestamp:
- Apr 25, 2018, 3:42:34 PM (5 years ago)
- Branches:
- new-env, with_gc
- Children:
- 1cdfa82
- Parents:
- 5af7306
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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) {
Note: See TracChangeset
for help on using the changeset viewer.