flx_collector.hpp
00001 #line 583 "./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
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
00026 struct GC_EXTERN flx_collector_t : public collector_t
00027 {
00028 flx_collector_t(allocator_t *);
00029 ~flx_collector_t();
00030
00031
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
00040 void *impl_allocate(gc_shape_t *ptr_map, unsigned long);
00041 void impl_deallocate(frame_t *frame);
00042
00043
00044 unsigned long impl_collect();
00045
00046
00047 void impl_add_root(void *memory);
00048 void impl_remove_root(void *memory);
00049
00050
00051 void check();
00052
00053
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
00063 void *v_allocate(gc_shape_t *ptr_map, unsigned long);
00064 void v_deallocate(frame_t *frame);
00065
00066
00067 unsigned long v_collect();
00068
00069
00070 void v_add_root(void *memory);
00071 void v_remove_root(void *memory);
00072
00073
00074 void v_check();
00075
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
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();
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
00109
00110
00111
00112
00113
00114 void *arena;
00115 void *arena_high;
00116 void *arena_ptr;
00117 unsigned long arena_size;
00118 unsigned long arena_free;
00119 float arena_size_factor;
00120 unsigned long min_arena_size;
00121 };
00122
00123 }}}
00124 #endif
00125