examples

Coverage Report

Created: 2024-07-26 02:37

/home/uke/oil/mycpp/gc_slab.h
Line
Count
Source
1
#ifndef GC_SLAB_H
2
#define GC_SLAB_H
3
4
#include <utility>  // std::is_pointer
5
6
#include "mycpp/common.h"  // DISALLOW_COPY_AND_ASSIGN
7
#include "mycpp/gc_obj.h"
8
9
// Return the size of a resizeable allocation.  Just round up to the nearest
10
// power of 2.  (CPython has an interesting policy in listobject.c.)
11
//
12
// https://stackoverflow.com/questions/466204/rounding-up-to-next-power-of-2
13
//
14
// Used by List<T> and Dict<K, V>.
15
16
36
inline int RoundUp(int n) {
17
  // TODO: what if int isn't 32 bits?
18
36
  n--;
19
36
  n |= n >> 1;
20
36
  n |= n >> 2;
21
36
  n |= n >> 4;
22
36
  n |= n >> 8;
23
36
  n |= n >> 16;
24
36
  n++;
25
36
  return n;
26
36
}
27
28
template <typename T>
29
class Slab {
30
  // Slabs of pointers are scanned; slabs of ints/bools are opaque.
31
 public:
32
158
  explicit Slab(unsigned num_items) {
33
158
  }
_ZN4SlabIP6BigStrEC2Ej
Line
Count
Source
32
48
  explicit Slab(unsigned num_items) {
33
48
  }
_ZN4SlabIiEC2Ej
Line
Count
Source
32
56
  explicit Slab(unsigned num_items) {
33
56
  }
_ZN4SlabIP6Tuple2IP6BigStriEEC2Ej
Line
Count
Source
32
1
  explicit Slab(unsigned num_items) {
33
1
  }
_ZN4SlabIP6Tuple2IiP6BigStrEEC2Ej
Line
Count
Source
32
6
  explicit Slab(unsigned num_items) {
33
6
  }
_ZN4SlabIbEC2Ej
Line
Count
Source
32
10
  explicit Slab(unsigned num_items) {
33
10
  }
_ZN4SlabIPN10hnode_asdl5FieldEEC2Ej
Line
Count
Source
32
37
  explicit Slab(unsigned num_items) {
33
37
  }
Unexecuted instantiation: _ZN4SlabIPN10hnode_asdl7hnode_tEEC2Ej
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc10OpaqueBaseEEC2Ej
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc12PointersBaseEEC2Ej
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc14BaseWithMethodEEC2Ej
34
35
158
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
158
    return ObjHeader::Slab(
37
158
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
158
  }
_ZN4SlabIP6BigStrE10obj_headerEj
Line
Count
Source
35
48
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
48
    return ObjHeader::Slab(
37
48
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
48
  }
_ZN4SlabIiE10obj_headerEj
Line
Count
Source
35
56
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
56
    return ObjHeader::Slab(
37
56
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
56
  }
_ZN4SlabIP6Tuple2IP6BigStriEE10obj_headerEj
Line
Count
Source
35
1
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
1
    return ObjHeader::Slab(
37
1
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
1
  }
_ZN4SlabIP6Tuple2IiP6BigStrEE10obj_headerEj
Line
Count
Source
35
6
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
6
    return ObjHeader::Slab(
37
6
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
6
  }
_ZN4SlabIbE10obj_headerEj
Line
Count
Source
35
10
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
10
    return ObjHeader::Slab(
37
10
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
10
  }
_ZN4SlabIPN10hnode_asdl5FieldEE10obj_headerEj
Line
Count
Source
35
37
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
37
    return ObjHeader::Slab(
37
37
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
37
  }
Unexecuted instantiation: _ZN4SlabIPN10hnode_asdl7hnode_tEE10obj_headerEj
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc10OpaqueBaseEE10obj_headerEj
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc12PointersBaseEE10obj_headerEj
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc14BaseWithMethodEE10obj_headerEj
39
40
  T items_[1];  // variable length
41
42
  DISALLOW_COPY_AND_ASSIGN(Slab);
43
};
44
45
template <typename T, int N>
46
class GlobalSlab {
47
  // A template type with the same layout as Slab of length N.  For
48
  // initializing global constant List.
49
 public:
50
  T items_[N];
51
52
  DISALLOW_COPY_AND_ASSIGN(GlobalSlab)
53
};
54
55
// XXX(watk): Does this make sense?
56
const int kSlabHeaderSize = sizeof(ObjHeader);
57
58
#endif  // GC_SLAB_H