mycpp

Coverage Report

Created: 2025-06-13 20:54

/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
153
inline int RoundUp(int n) {
17
  // TODO: what if int isn't 32 bits?
18
153
  n--;
19
153
  n |= n >> 1;
20
153
  n |= n >> 2;
21
153
  n |= n >> 4;
22
153
  n |= n >> 8;
23
153
  n |= n >> 16;
24
153
  n++;
25
153
  return n;
26
153
}
27
28
template <typename T>
29
class Slab {
30
  // Slabs of pointers are scanned; slabs of ints/bools are opaque.
31
 public:
32
613
  explicit Slab(unsigned num_items) {
33
613
  }
_ZN4SlabIiEC2Ej
Line
Count
Source
32
479
  explicit Slab(unsigned num_items) {
33
479
  }
_ZN4SlabIP5PointEC2Ej
Line
Count
Source
32
5
  explicit Slab(unsigned num_items) {
33
5
  }
_ZN4SlabIP6BigStrEC2Ej
Line
Count
Source
32
103
  explicit Slab(unsigned num_items) {
33
103
  }
_ZN4SlabIlEC2Ej
Line
Count
Source
32
21
  explicit Slab(unsigned num_items) {
33
21
  }
_ZN4SlabIP6Tuple2IiiEEC2Ej
Line
Count
Source
32
3
  explicit Slab(unsigned num_items) {
33
3
  }
_ZN4SlabIP6Tuple2IP6BigStriEEC2Ej
Line
Count
Source
32
1
  explicit Slab(unsigned num_items) {
33
1
  }
_ZN4SlabIbEC2Ej
Line
Count
Source
32
1
  explicit Slab(unsigned num_items) {
33
1
  }
34
35
613
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
613
    return ObjHeader::Slab(
37
613
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
613
  }
_ZN4SlabIiE10obj_headerEj
Line
Count
Source
35
479
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
479
    return ObjHeader::Slab(
37
479
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
479
  }
_ZN4SlabIP5PointE10obj_headerEj
Line
Count
Source
35
5
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
5
    return ObjHeader::Slab(
37
5
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
5
  }
_ZN4SlabIP6BigStrE10obj_headerEj
Line
Count
Source
35
103
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
103
    return ObjHeader::Slab(
37
103
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
103
  }
_ZN4SlabIlE10obj_headerEj
Line
Count
Source
35
21
  static constexpr ObjHeader obj_header(unsigned num_items) {
36
21
    return ObjHeader::Slab(
37
21
        std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items);
38
21
  }
_ZN4SlabIP6Tuple2IiiEE10obj_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
  }
_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
  }
_ZN4SlabIbE10obj_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
  }
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