flx_gc.hpp

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

Generated on Thu May 29 14:05:03 2008 for Felix by  doxygen 1.5.5