cpp

Coverage Report

Created: 2025-04-27 22:42

/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
549
inline int RoundUp(int n) {
17
  // TODO: what if int isn't 32 bits?
18
549
  n--;
19
549
  n |= n >> 1;
20
549
  n |= n >> 2;
21
549
  n |= n >> 4;
22
549
  n |= n >> 8;
23
549
  n |= n >> 16;
24
549
  n++;
25
549
  return n;
26
549
}
27
28
template <typename T>
29
class Slab {
30
  // Slabs of pointers are scanned; slabs of ints/bools are opaque.
31
 public:
32
2.32k
  explicit Slab(unsigned num_items) {
33
2.32k
  }
_ZN4SlabIiEC2Ej
Line
Count
Source
32
1.06k
  explicit Slab(unsigned num_items) {
33
1.06k
  }
_ZN4SlabIP6BigStrEC2Ej
Line
Count
Source
32
313
  explicit Slab(unsigned num_items) {
33
313
  }
_ZN4SlabIP6Tuple2IP6BigStriEEC2Ej
Line
Count
Source
32
3
  explicit Slab(unsigned num_items) {
33
3
  }
_ZN4SlabIP6Tuple2IiP6BigStrEEC2Ej
Line
Count
Source
32
7
  explicit Slab(unsigned num_items) {
33
7
  }
_ZN4SlabIPN11pretty_asdl11MeasuredDocEEC2Ej
Line
Count
Source
32
719
  explicit Slab(unsigned num_items) {
33
719
  }
_ZN4SlabIPN11pretty_asdl11DocFragmentEEC2Ej
Line
Count
Source
32
57
  explicit Slab(unsigned num_items) {
33
57
  }
_ZN4SlabIbEC2Ej
Line
Count
Source
32
22
  explicit Slab(unsigned num_items) {
33
22
  }
_ZN4SlabIPN10hnode_asdl5FieldEEC2Ej
Line
Count
Source
32
57
  explicit Slab(unsigned num_items) {
33
57
  }
Unexecuted instantiation: _ZN4SlabIPN10hnode_asdl7hnode_tEEC2Ej
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc10OpaqueBaseEEC2Ej
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc12PointersBaseEEC2Ej
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc14BaseWithMethodEEC2Ej
_ZN4SlabIP5PointEC2Ej
Line
Count
Source
32
10
  explicit Slab(unsigned num_items) {
33
10
  }
_ZN4SlabIlEC2Ej
Line
Count
Source
32
42
  explicit Slab(unsigned num_items) {
33
42
  }
_ZN4SlabIP6Tuple2IiiEEC2Ej
Line
Count
Source
32
6
  explicit Slab(unsigned num_items) {
33
6
  }
_ZN4SlabIPN4pyos11PasswdEntryEEC2Ej
Line
Count
Source
32
4
  explicit Slab(unsigned num_items) {
33
4
  }
Unexecuted instantiation: _ZN4SlabIP4ListIP6Tuple2IiiEEEC2Ej
Unexecuted instantiation: _ZN4SlabIP6Tuple2IP4ListIPS1_IPS0_IiiEEEP4DictIiiEEEC2Ej
_ZN4SlabIPN10value_asdl7value_tEEC2Ej
Line
Count
Source
32
8
  explicit Slab(unsigned num_items) {
33
8
  }
_ZN4SlabIPN4args7_ActionEEC2Ej
Line
Count
Source
32
7
  explicit Slab(unsigned num_items) {
33
7
  }
Unexecuted instantiation: _ZN4SlabIPN11syntax_asdl12CompoundWordEEC2Ej
Unexecuted instantiation: _ZN4SlabIP6Tuple2IP6BigStrbEEC2Ej
34
35
2.32k
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
2.32k
    return ObjHeader::Slab(
37
2.32k
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
2.32k
  }
_ZN4SlabIiE10obj_headerEj
Line
Count
Source
35
1.06k
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
1.06k
    return ObjHeader::Slab(
37
1.06k
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
1.06k
  }
_ZN4SlabIP6BigStrE10obj_headerEj
Line
Count
Source
35
313
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
313
    return ObjHeader::Slab(
37
313
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
313
  }
_ZN4SlabIP6Tuple2IP6BigStriEE10obj_headerEj
Line
Count
Source
35
3
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
3
    return ObjHeader::Slab(
37
3
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
3
  }
_ZN4SlabIP6Tuple2IiP6BigStrEE10obj_headerEj
Line
Count
Source
35
7
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
7
    return ObjHeader::Slab(
37
7
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
7
  }
_ZN4SlabIPN11pretty_asdl11MeasuredDocEE10obj_headerEj
Line
Count
Source
35
719
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
719
    return ObjHeader::Slab(
37
719
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
719
  }
_ZN4SlabIPN11pretty_asdl11DocFragmentEE10obj_headerEj
Line
Count
Source
35
57
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
57
    return ObjHeader::Slab(
37
57
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
57
  }
_ZN4SlabIbE10obj_headerEj
Line
Count
Source
35
22
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
22
    return ObjHeader::Slab(
37
22
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
22
  }
_ZN4SlabIPN10hnode_asdl5FieldEE10obj_headerEj
Line
Count
Source
35
57
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
57
    return ObjHeader::Slab(
37
57
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
57
  }
Unexecuted instantiation: _ZN4SlabIPN10hnode_asdl7hnode_tEE10obj_headerEj
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc10OpaqueBaseEE10obj_headerEj
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc12PointersBaseEE10obj_headerEj
Unexecuted instantiation: _ZN4SlabIPN15test_classes_gc14BaseWithMethodEE10obj_headerEj
_ZN4SlabIP5PointE10obj_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
  }
_ZN4SlabIlE10obj_headerEj
Line
Count
Source
35
42
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
42
    return ObjHeader::Slab(
37
42
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
42
  }
_ZN4SlabIP6Tuple2IiiEE10obj_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
  }
_ZN4SlabIPN4pyos11PasswdEntryEE10obj_headerEj
Line
Count
Source
35
4
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
4
    return ObjHeader::Slab(
37
4
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
4
  }
Unexecuted instantiation: _ZN4SlabIP4ListIP6Tuple2IiiEEE10obj_headerEj
Unexecuted instantiation: _ZN4SlabIP6Tuple2IP4ListIPS1_IPS0_IiiEEEP4DictIiiEEE10obj_headerEj
_ZN4SlabIPN10value_asdl7value_tEE10obj_headerEj
Line
Count
Source
35
8
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
8
    return ObjHeader::Slab(
37
8
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
8
  }
_ZN4SlabIPN4args7_ActionEE10obj_headerEj
Line
Count
Source
35
7
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
7
    return ObjHeader::Slab(
37
7
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
7
  }
Unexecuted instantiation: _ZN4SlabIPN11syntax_asdl12CompoundWordEE10obj_headerEj
Unexecuted instantiation: _ZN4SlabIP6Tuple2IP6BigStrbEE10obj_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