flx_collector.hpp

00001 #line 582 "./lpsrc/flx_gc.pak"
00002 #ifndef __FLX_COLLECTOR_H__
00003 #define __FLX_COLLECTOR_H__
00004 #include "flx_gc.hpp"
00005 #include "flx_gc_private.hpp"
00006 #include <map>
00007 
00008 namespace flx {
00009 namespace gc {
00010 namespace collector {
00011 using namespace generic;
00012 
00013 struct GC_EXTERN malloc_free;
00014 struct GC_EXTERN flx_collector_t;
00015 
00016 /// Allocator using malloc and free.
00017 struct GC_EXTERN malloc_free : public virtual allocator_t
00018 {
00019   void *allocate(std::size_t);
00020   void *reallocate(void *, std::size_t);
00021   void deallocate(void *);
00022 };
00023 
00024 
00025 /// Naive Mark and Sweep Collector.
00026 struct GC_EXTERN flx_collector_t : public collector_t
00027 {
00028   flx_collector_t(allocator_t *);
00029   ~flx_collector_t();
00030 
00031   // special to this collector ..?
00032   void set_min_arena_size(unsigned long);
00033   bool check_client_pointer(void *);
00034   bool check_frame_pointer(frame_t *);
00035 
00036 
00037 protected:
00038 
00039   /// allocator
00040   void *impl_allocate(gc_shape_t *ptr_map, unsigned long);
00041   void impl_deallocate(frame_t *frame);
00042 
00043   /// collector (returns number of objects collected)
00044   unsigned long impl_collect();
00045 
00046   // add and remove roots
00047   void impl_add_root(void *memory);
00048   void impl_remove_root(void *memory);
00049 
00050   //
00051   void check();
00052 
00053   // statistics
00054   unsigned long impl_get_allocation_count()const;
00055   unsigned long impl_get_root_count()const;
00056   unsigned long impl_get_allocation_amt()const;
00057 
00058   void impl_compact(bool closed);
00059   void impl_check();
00060 
00061 private:
00062   /// allocator
00063   void *v_allocate(gc_shape_t *ptr_map, unsigned long);
00064   void v_deallocate(frame_t *frame);
00065 
00066   /// collector (returns number of objects collected)
00067   unsigned long v_collect();
00068 
00069   // add and remove roots
00070   void v_add_root(void *memory);
00071   void v_remove_root(void *memory);
00072 
00073   //
00074   void v_check();
00075   // statistics
00076   unsigned long v_get_allocation_count()const;
00077   unsigned long v_get_root_count()const;
00078   unsigned long v_get_allocation_amt()const;
00079 
00080   void v_compact(bool closed);
00081 
00082 private:
00083   bool collecting;
00084   unsigned long allocation_count;
00085   unsigned long root_count;
00086   unsigned long allocation_amt;
00087 
00088 
00089   void unlink(frame_t *frame);
00090   void dispose(frame_t *frame);
00091     // calls post_delete or delete_frame
00092 
00093   void post_delete(frame_t *frame);
00094   void delete_frame(frame_t *frame);
00095   unsigned long reap();
00096 
00097   void mark();
00098   unsigned long sweep(); // calls scan_object
00099   void scan_object(frame_t *frame);
00100 
00101   frame_t *first;
00102   frame_t *to_delete;
00103   typedef std::map<frame_t*,unsigned long, std::less<frame_t*> > rootmap_t;
00104   rootmap_t roots;
00105   bool parity;
00106   allocator_t *allocator;
00107 
00108   // if compaction is being used this stuff controls
00109   // the arena. The arena ptr grows DOWN towards the
00110   // start of the arena. arena is NULL unless arenas
00111   // are being used. Once in use, the allocator is
00112   // not (normally) used for individual objects
00113 
00114   void *arena;       // if compaction is being used, lo address
00115   void *arena_high;  // arena base (high) address
00116   void *arena_ptr;   // current top of the stack
00117   unsigned long arena_size; // hi - lo
00118   unsigned long arena_free; // ptr - lo
00119   float arena_size_factor;
00120   unsigned long min_arena_size;
00121 };
00122 
00123 }}} // end namespaces
00124 #endif
00125 

Generated on Fri Jun 8 02:24:06 2007 for Felix by  doxygen 1.5.2