Changeset bd06384 for src/Common


Ignore:
Timestamp:
Mar 22, 2018, 4:49:53 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
dbc2c2c
Parents:
7e4b44db
Message:

Add static roots to GC; fix some static GC_Objects

Location:
src/Common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Common/GC.cc

    r7e4b44db rbd06384  
    1616#include "GC.h"
    1717
     18#include "Common/PassVisitor.h"
     19
     20#include "SynTree/GcTracer.h"
     21
    1822#include <algorithm>
    1923#include <cassert>
     
    2428}
    2529
    26 GC::GC() : mark(false), old(), young(), using_young(false) {
     30GC::GC() : mark(false), using_young(false), old(), young(), static_roots() {
    2731        old.reserve(70000);
    2832}
     
    5559}
    5660
     61void GC::register_static_root(BaseSyntaxNode* root) {
     62        static_roots.push_back(root);
     63}
     64
    5765void GC::new_generation() {
    5866        using_young = true;
     67}
     68
     69void GC::trace_static_roots() {
     70        PassVisitor<GcTracer> tracer{ *this };
     71        for ( BaseSyntaxNode* root : static_roots ) {
     72                root->accept( tracer );
     73        }
    5974}
    6075
  • src/Common/GC.h

    r7e4b44db rbd06384  
    2020class GC_Traceable;
    2121class GC_Object;
     22class BaseSyntaxNode;
    2223
    2324/// Manually traced and called garbage collector
     
    3435        void register_object(GC_Object*);
    3536
     37        /// Adds an object to the set of static roots
     38        void register_static_root(BaseSyntaxNode*);
     39
    3640        /// Use young generation for subsequent new objects
    3741        void new_generation();
     42
     43        /// Traces all static roots
     44        void trace_static_roots();
    3845
    3946        /// Collects the young generation, placing survivors in old generation.
     
    5057        GC();
    5158
    52         /// The current collection's mark bit
    53         bool mark;
     59        bool mark;                 ///< The current collection's mark bit
     60        bool using_young;          ///< Is the young generation in use?
    5461
    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
    5968};
    6069
     
    8089        GC& gc = GC::get();
    8190        traceAll(gc, roots...);
     91        gc.trace_static_roots();
    8292        gc.collect_young();
    8393}
     
    8898        GC& gc = GC::get();
    8999        traceAll(gc, roots...);
     100        gc.trace_static_roots();
    90101        gc.collect();
     102}
     103
     104/// Makes a new expression as a static root
     105template<typename T, typename... Args>
     106inline 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;
    91110}
    92111
  • src/Common/PassVisitor.impl.h

    r7e4b44db rbd06384  
    3838        MUTATE_END( type, node );      \
    3939
    40 
     40#include "Common/GC.h"
    4141
    4242template<typename T>
     
    397397                        auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    398398                        // 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>(
    400400                                "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    401401                                new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    402402                                nullptr
    403403                        );
    404                         indexerAddId( &func );
     404                        indexerAddId( func );
    405405                        maybeAccept_impl( node->type, *this );
    406406                        maybeAccept_impl( node->statements, *this );
     
    427427                        auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    428428                        // 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>(
    430430                                "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    431431                                new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    432432                                nullptr
    433433                        );
    434                         indexerAddId( &func );
     434                        indexerAddId( func );
    435435                        maybeMutate_impl( node->type, *this );
    436436                        maybeMutate_impl( node->statements, *this );
Note: See TracChangeset for help on using the changeset viewer.