Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
GroupedGC.h
1 /*
2  * GroupedGC class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2014, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_ALLOC_GROUPEDGC_H_
22 #define ELM_ALLOC_GROUPEDGC_H_
23 
24 #include <elm/util/BitVector.h>
25 #include <elm/stree/Tree.h>
26 #include <elm/data/List.h>
27 #include <elm/data/BiDiList.h>
28 #include <elm/alloc/DefaultAllocator.h>
29 
30 namespace elm {
31 
32 class GroupedGC : public DefaultAllocator {
33  friend class TempGroupedGC;
34 public:
35  GroupedGC(t::size size = 4096);
36  virtual ~GroupedGC(void);
37  void clear(void);
38  void doGC(void);
39  virtual void *allocate(t::size size);
40  virtual bool mark(void *data, t::size size);
41  inline void setDisableGC(bool b) { disableGC = b; }
42 protected:
43  virtual void beginGC(void);
44  virtual void collect(void) { ASSERTP(false, "collect function must be implemented."); }
45  virtual void endGC(void);
46  bool getNeedGC(void) { return needGC; }
47 
48 private:
49  void newChunk(int index);
50  void *allocFromFreeList(t::size size, unsigned int index);
51 
52  typedef struct block_t {
53  block_t *next;
55  } block_t;
56 
57  // when init is true, the memory addresses in chunk will not show up in free_list
58  typedef struct chunk_t {
59  BitVector *bits;
60  t::intptr size; // the remaining space of the chunk
61  t::intptr index; // the index that the chunk is corresponding to
62  t::intptr init; // whether a chunk is at its first use
63  t::intptr blockCount;
64  t::uint8 buffer[0];
65  } chunk_t;
66 
67  List<chunk_t *> chunks; // the list of the chunks
68  t::size csize; // the chunk size
69  block_t **free_list; // the free list of blocks
70  inhstruct::DLList temps;
71  bool needGC; // delayed GC feature
72 
73  typedef stree::Tree<void *, chunk_t *> tree_t;
74  tree_t *st; // use to store the tree of the chunks vs the range of the memory addresses
75 
76  static inline t::size round(t::size size) { return (size + sizeof(block_t) - 1) & ~(sizeof(block_t) - 1); }
77 
78  // for future
79  unsigned int shiftToIndex; // the amount of the bit shift to obtain the exact bins' index
80 
81  bool disableGC; // if the GC is disabled
82 
83  // for testing
84  unsigned long totalChunkSize;
85 
86  unsigned int currentMaxIndex;
87  unsigned int maxSlotSize;
88 
89  // see the request distribution
90  unsigned long* useDist;
91  unsigned long* currUseDist;
92  unsigned long* markDist;
93  unsigned long* currMarkDist;
94  unsigned long* freeDist;
95  unsigned long* currFreeDist;
96  unsigned long* chunkDist;
97  unsigned long* gcDist;
98 
99  // used to main the table of allocating size
100  unsigned int maxAllocatableIndex;
101  chunk_t **chunk_list;
102  bool* chunk_init;
103  unsigned long* blockCount;
104 
105  unsigned int requestCount;
106  unsigned int requestThreshold;
107 
108  //unsigned int gcCount;
109  unsigned int allocFuncCount;
110  unsigned int allocCount;
111  unsigned int markCount;
112  unsigned int gcTimes;
113  unsigned long totalAllocTime;
114 };
115 
116 } // elm
117 
118 #endif /* ELM_ALLOC_GROUPEDGC_H_ */
elm::GroupedGC::mark
virtual bool mark(void *data, t::size size)
Definition: alloc_GroupedGC.cpp:352
elm::GroupedGC::TempGroupedGC
friend class TempGroupedGC
Definition: GroupedGC.h:33
elm::GroupedGC::clear
void clear(void)
Definition: alloc_GroupedGC.cpp:171
elm::GroupedGC::allocate
virtual void * allocate(t::size size)
Definition: alloc_GroupedGC.cpp:276
elm
Definition: adapter.h:26
elm::GroupedGC
Definition: GroupedGC.h:32
elm::GroupedGC::getNeedGC
bool getNeedGC(void)
Definition: GroupedGC.h:46
elm::GroupedGC::~GroupedGC
virtual ~GroupedGC(void)
Definition: alloc_GroupedGC.cpp:164
elm::t::size
uint64 size
Definition: arch.h:35
elm::DefaultAllocator
Definition: DefaultAllocator.h:39
elm::GroupedGC::collect
virtual void collect(void)
Definition: GroupedGC.h:44
elm::GroupedGC::GroupedGC
GroupedGC(t::size size=4096)
Definition: alloc_GroupedGC.cpp:62
elm::GroupedGC::endGC
virtual void endGC(void)
Definition: alloc_GroupedGC.cpp:413
elm::t::uint8
unsigned char uint8
Definition: arch.h:27
elm::GroupedGC::beginGC
virtual void beginGC(void)
Definition: alloc_GroupedGC.cpp:385
elm::GroupedGC::setDisableGC
void setDisableGC(bool b)
Definition: GroupedGC.h:41
elm::GroupedGC::doGC
void doGC(void)
Definition: alloc_GroupedGC.cpp:180
elm::t::intptr
uint64 intptr
Definition: arch.h:38