Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SimpleGC.h
1 /*
2  * SimpleGC 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_SIMPLEGC_H_
22 #define ELM_ALLOC_SIMPLEGC_H_
23 
24 #include <elm/util/BitVector.h>
25 #include <elm/stree/Tree.h>
26 #include <elm/genstruct/SLList.h>
27 #include <elm/alloc/DefaultAllocator.h>
28 
29 namespace elm {
30 
31 class SimpleGC {
32 public:
33  SimpleGC(t::size size = 4096);
34  virtual ~SimpleGC(void);
35  void clear(void);
36  void doGC(void);
37 
38  void *allocate(t::size size) throw(BadAlloc);
39  inline void free(void *block) { }
40 
41 protected:
42  bool mark(void *data, t::size size);
43 
44  virtual void beginGC(void);
45  virtual void collect(void) = 0;
46  virtual void endGC(void);
47 
48 private:
49  void newChunk(void);
50  void *allocFromFreeList(t::size size);
51 
52  typedef struct block_t {
53  block_t *next;
55  } block_t;
56  typedef struct chunk_t {
57  BitVector *bits;
58  t::uint8 buffer[0];
59  } chunk_t;
60 
61  genstruct::SLList<chunk_t *> chunks;
62  t::size csize;
63  block_t *free_list;
64 
65  typedef stree::Tree<void *, chunk_t *> tree_t;
66  tree_t *st;
67 
68  static inline t::size round(t::size size) { return (size + sizeof(block_t) - 1) & ~(sizeof(block_t) - 1); }
69 };
70 
71 } // elm
72 
73 #endif /* ELM_ALLOC_SIMPLEGC_H_ */
virtual ~SimpleGC(void)
Definition: alloc_SimpleGC.cpp:61
virtual void beginGC(void)
Definition: alloc_SimpleGC.cpp:159
void clear(void)
Definition: alloc_SimpleGC.cpp:68
void * allocate(t::size size)
Definition: alloc_SimpleGC.cpp:106
virtual void endGC(void)
Definition: alloc_SimpleGC.cpp:185
void doGC(void)
Definition: alloc_SimpleGC.cpp:77
uint32 size
Definition: int.h:41
SimpleGC(t::size size=4096)
Definition: alloc_SimpleGC.cpp:40
virtual void collect(void)=0
Definition: DefaultAllocator.h:31
uint8_t uint8
Definition: int.h:31
void free(void *block)
Definition: SimpleGC.h:39
Definition: SimpleGC.h:31
bool mark(void *data, t::size size)
Definition: alloc_SimpleGC.cpp:136
uint32 intptr
Definition: int.h:44