cpp

Coverage Report

Created: 2022-09-21 22:22

/home/andy/git/oilshell/oil/mycpp/marksweep_heap.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef MARKSWEEP_H
2
#define MARKSWEEP_H
3
4
#include <new>
5
#include <unordered_set>
6
7
class MarkSweepHeap {
8
  void MarkAllReferences(Obj* obj);
9
10
 public:
11
33
  MarkSweepHeap() {
12
33
  }
13
  void Init(int);
14
15
  void* Allocate(int);
16
17
11.7k
  void PushRoot(Obj** p) {
18
11.7k
    assert(roots_top_ < kMaxRoots);
19
0
    roots_[roots_top_++] = p;
20
11.7k
  }
21
22
11.7k
  void PopRoot() {
23
11.7k
    roots_top_--;
24
11.7k
  }
25
26
  void Collect();
27
28
0
  void Report() {};
29
30
  int roots_top_;
31
  Obj** roots_[kMaxRoots];  // These are pointers to Obj* pointers
32
33
  uint64_t current_heap_bytes_;
34
  uint64_t collection_thresh_;
35
36
  // TODO(Jesse): This should really be in an 'internal' build
37
  //
38
  bool is_initialized_ = true;  // mark/sweep doesn't need to be initialized
39
40
#if GC_STATS
41
  int num_live_objs_;
42
#endif
43
44
  std::unordered_set<void*> all_allocations_;
45
  std::unordered_set<void*> marked_allocations_;
46
};
47
48
#endif