Predator  [unstable] git snapshot
symgc.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2010 Kamil Dudka <kdudka@redhat.com>
3  *
4  * This file is part of predator.
5  *
6  * predator is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * any later version.
10  *
11  * predator is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with predator. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef H_GUARD_SYMGC_H
21 #define H_GUARD_SYMGC_H
22 
23 /**
24  * @file symgc.hh
25  * collectJunk - implementation of a garbage collector for the symbolic heap
26  */
27 
28 #include "symheap.hh"
29 
30 #include <boost/foreach.hpp>
31 
32 #define REQUIRE_GC_ACTIVITY(sh, obj, fnc) do { \
33  if (collectJunk(sh, obj)) \
34  break; \
35  CL_ERROR(#fnc "() failed to collect garbage, " #obj " still referenced"); \
36  CL_BREAK_IF("REQUIRE_GC_ACTIVITY has not been successful"); \
37 } while (0)
38 
39 /// collect and remove all junk reachable from the given object
40 bool /* found */ collectJunk(SymHeap &sh, TObjId obj, TObjSet *leakObjs = 0);
41 
42 /// same as collectJunk(), but does not consider prototypes to be junk objects
43 bool collectSharedJunk(SymHeap &sh, TObjId obj, TObjSet *leakObjs = 0);
44 
46  SymHeap &sh,
47  TObjId obj,
48  TObjSet *leakObjs = 0);
49 
50 /// @todo some dox
51 class LeakMonitor {
52  public:
54  sh_(sh),
55  snap_(sh.stor(), sh.traceNode())
56  {
57  }
58 
59  void enter();
60  void leave();
61 
62  template <class TCont>
63  bool collectJunkFrom(const TCont &killedPtrs) {
64  bool leaking = false;
65  BOOST_FOREACH(TValId val, killedPtrs) {
66  const TObjId obj = sh_.objByAddr(val);
67  if (collectJunk(sh_, obj, &leakObjs_))
68  leaking = true;
69  }
70 
71  return leaking;
72  }
73 
74  bool /* leaking */ destroyObject(const TObjId obj) {
76  }
77 
78  bool /* leaking */ importLeakObjs(TObjSet *leakObjs);
79 
80 
81  private:
85 };
86 
87 /// enable/disable debugging of the garbage collector
88 void debugGarbageCollector(bool enable);
89 
90 #endif /* H_GUARD_SYMGC_H */