flx_gc.hpp

00001 #line 134 "./lpsrc/flx_gc.pak"
00002 #ifndef FLX_GC
00003 #define FLX_GC
00004 
00005 #include <cstdlib>
00006 #include "flx_gc_config.hpp"
00007 
00008 // we use an STL set to hold the collection of roots
00009 #include <set>
00010 
00011 namespace flx {
00012 namespace gc {
00013 namespace generic {
00014 // Here are the types we refer to:
00015 
00016 struct GC_EXTERN frame_t;      // the type of all collectable objects
00017 struct GC_EXTERN gc_shape_t;   // the shape of collectable objects
00018 struct GC_EXTERN collector_t;  // the collector itself
00019 struct GC_EXTERN allocator_t;  // the collector itself
00020 
00021 enum gc_shape_flags_t {
00022   gc_flags_default    = 0,            //< collectable and mobile
00023   gc_flags_immobile   = 1,            //< cannot be moved
00024   gc_flags_persistent = 2             //< cannot be deallocated
00025 };
00026 
00027 /// Describes runtime object shape.
00028 struct GC_EXTERN gc_shape_t
00029 {
00030   gc_shape_t *next_shape;         ///< pointer to next shape in list or NULL
00031   char const *cname;              ///< C++ typename
00032   std::size_t count;              ///< array element count
00033   std::size_t amt;                ///< bytes allocated
00034   void (*finaliser)(collector_t*, void*);  ///< finalisation function
00035   std::size_t n_offsets;          ///< number of offsets
00036   std::size_t *offsets;           ///< actual offsets
00037   gc_shape_flags_t flags;         ///< flags
00038   // convenience constructor
00039   gc_shape_t(
00040     gc_shape_t *ns,
00041     char const *cn,
00042     std::size_t count_a,
00043     std::size_t amt_a,
00044     void (*finaliser_a)(collector_t*, void*),
00045     std::size_t n_offsets_a,
00046     std::size_t *offsets_a
00047   );
00048   gc_shape_t(
00049     gc_shape_t *ns,
00050     char const *cn,
00051     std::size_t count_a,
00052     std::size_t amt_a,
00053     void (*finaliser_a)(collector_t*, void*),
00054     std::size_t n_offsets_a,
00055     std::size_t *offsets_a,
00056     gc_shape_flags_t flags_a
00057   );
00058 };
00059 #line 215 "./lpsrc/flx_gc.pak"
00060 template<class T>
00061 void std_finaliser(collector_t*, void *t)
00062 {
00063   static_cast<T*>(t) -> ~T();
00064 }
00065 
00066 #line 224 "./lpsrc/flx_gc.pak"
00067 
00068 /// Allocator abstraction.
00069 
00070 struct allocator_t {
00071   bool debug;
00072   allocator_t():debug(false){}
00073   virtual void *allocate(std::size_t)=0;
00074   virtual void deallocate(void *)=0;
00075   virtual void *reallocate(void *, std::size_t)=0;
00076   virtual ~allocator_t(){};
00077   void set_debug(bool d){debug=d;}
00078 };
00079 
00080 #line 240 "./lpsrc/flx_gc.pak"
00081 
00082 /// Collector abstraction.
00083 struct GC_EXTERN collector_t
00084 {
00085   bool debug;
00086   void set_debug(bool d){debug=d;}
00087   collector_t();
00088   virtual ~collector_t(){}
00089 
00090 #line 252 "./lpsrc/flx_gc.pak"
00091   unsigned long get_allocation_count()const {
00092     return v_get_allocation_count();
00093   }
00094 
00095   unsigned long get_root_count()const {
00096     return v_get_root_count();
00097   }
00098 
00099   unsigned long get_allocation_amt()const {
00100     return v_get_allocation_amt();
00101   }
00102 
00103 #line 268 "./lpsrc/flx_gc.pak"
00104   void *allocate(gc_shape_t *shape, unsigned long x) {
00105     return v_allocate(shape,x);
00106   }
00107 
00108   void deallocate(frame_t *fp) {
00109     v_deallocate(fp);
00110   }
00111 
00112 #line 279 "./lpsrc/flx_gc.pak"
00113   unsigned long collect() {
00114     return v_collect();
00115   }
00116 
00117 #line 286 "./lpsrc/flx_gc.pak"
00118   void add_root(void *memory) {
00119     v_add_root(memory);
00120   }
00121 
00122   void remove_root(void *memory) {
00123     v_remove_root(memory);
00124   }
00125 
00126 #line 308 "./lpsrc/flx_gc.pak"
00127   void compact(bool closed) {
00128     v_compact(closed);
00129   }
00130 
00131 #line 315 "./lpsrc/flx_gc.pak"
00132   void check() {
00133     v_check();
00134   }
00135 
00136 private:
00137   virtual unsigned long v_get_allocation_count()const=0;
00138   virtual unsigned long v_get_root_count()const=0;
00139   virtual unsigned long v_get_allocation_amt()const=0;
00140   virtual void *v_allocate(gc_shape_t *shape, unsigned long)=0;
00141   virtual void v_deallocate(frame_t *fp)=0;
00142   virtual unsigned long v_collect()=0;
00143   virtual void v_add_root(void *memory)=0;
00144   virtual void v_remove_root(void *memory)=0;
00145   virtual void v_compact(bool closed)=0;
00146   virtual void v_check()=0;
00147 
00148 #line 335 "./lpsrc/flx_gc.pak"
00149   void operator=(collector_t const&);
00150   collector_t(collector_t const&);
00151 };
00152 
00153 
00154 #line 347 "./lpsrc/flx_gc.pak"
00155 void GC_EXTERN destroy(void *b);
00156 
00157 #line 361 "./lpsrc/flx_gc.pak"
00158 void GC_EXTERN _init_ptr(void **a, void *b);
00159 void GC_EXTERN _set_ptr(void **a, void *b);
00160 void GC_EXTERN _release_ptr(void **a);
00161 void GC_EXTERN _destroy_ptr(void **a);
00162 
00163 template<class T>
00164 void init_ptr(T **a, T *b)
00165 {
00166   _init_ptr
00167   (
00168     reinterpret_cast<void**>(a),
00169     reinterpret_cast<void*>(b)
00170   );
00171 }
00172 
00173 template<class T>
00174 void set_ptr(T **a, T *b)
00175 {
00176   _set_ptr
00177   (
00178     reinterpret_cast<void**>(a),
00179     reinterpret_cast<void*>(b)
00180   );
00181 }
00182 
00183 template<class T>
00184 void release_ptr(T **a)
00185 {
00186   _release_ptr
00187   (
00188     reinterpret_cast<void**>(a)
00189   );
00190 }
00191 
00192 template<class T>
00193 void destroy_ptr(T **a)
00194 {
00195   _destroy_ptr
00196   (
00197     reinterpret_cast<void**>(a)
00198   );
00199 }
00200 
00201 #line 410 "./lpsrc/flx_gc.pak"
00202 GC_EXTERN void reset_shape(void *memory, gc_shape_t &);
00203 GC_EXTERN void reset_count(void *memory, unsigned long);
00204 GC_EXTERN unsigned long get_count(void *memory);
00205 
00206 }}} // end namespaces
00207 
00208 #line 426 "./lpsrc/flx_gc.pak"
00209 /// Allocate collectable object
00210 GC_EXTERN void *operator new
00211 (
00212   std::size_t,
00213   flx::gc::generic::collector_t &,
00214   flx::gc::generic::gc_shape_t &
00215 );
00216 
00217 /// Allocate collectable array
00218 GC_EXTERN void *operator new []
00219 (
00220   std::size_t,
00221   flx::gc::generic::collector_t &,
00222   flx::gc::generic::gc_shape_t &,
00223   unsigned long
00224 );
00225 
00226 #endif
00227 

Generated on Mon Dec 11 17:08:15 2006 for Felix by  doxygen 1.5.1