/home/andy/git/oilshell/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" // GC_OBJ |
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 | 1.31k | inline int RoundUp(int n) { |
17 | | // TODO: what if int isn't 32 bits? |
18 | 1.31k | n--; |
19 | 1.31k | n |= n >> 1; |
20 | 1.31k | n |= n >> 2; |
21 | 1.31k | n |= n >> 4; |
22 | 1.31k | n |= n >> 8; |
23 | 1.31k | n |= n >> 16; |
24 | 1.31k | n++; |
25 | 1.31k | return n; |
26 | 1.31k | } |
27 | | |
28 | | template <typename T> |
29 | | class Slab { |
30 | | // Slabs of pointers are scanned; slabs of ints/bools are opaque. |
31 | | public: |
32 | 1.17k | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { |
33 | 1.17k | } Line | Count | Source | 32 | 257 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 257 | } |
Line | Count | Source | 32 | 838 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 838 | } |
Unexecuted instantiation: _ZN4SlabIPN10classes_gc10OpaqueBaseEEC2Ej Unexecuted instantiation: _ZN4SlabIPN10classes_gc12PointersBaseEEC2Ej Unexecuted instantiation: _ZN4SlabIPN10classes_gc14BaseWithMethodEEC2Ej _ZN4SlabIP6Tuple2IiP3StrEEC2Ej Line | Count | Source | 32 | 9 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 9 | } |
_ZN4SlabIP6Tuple2IP3StriEEC2Ej Line | Count | Source | 32 | 3 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 3 | } |
_ZN4SlabIPN10hnode_asdl5fieldEEC2Ej Line | Count | Source | 32 | 37 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 37 | } |
Line | Count | Source | 32 | 3 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 3 | } |
_ZN4SlabIP6Tuple2IiiEEC2Ej Line | Count | Source | 32 | 6 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 6 | } |
Line | Count | Source | 32 | 2 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 2 | } |
Unexecuted instantiation: _ZN4SlabIPN10hnode_asdl7hnode_tEEC2Ej _ZN4SlabIPN4pyos11PasswdEntryEEC2Ej Line | Count | Source | 32 | 6 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 6 | } |
_ZN4SlabIPN12runtime_asdl7value_tEEC2Ej Line | Count | Source | 32 | 9 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 9 | } |
_ZN4SlabIPN4args7_ActionEEC2Ej Line | Count | Source | 32 | 6 | explicit Slab(unsigned num_items) : header_(obj_header(num_items)) { | 33 | 6 | } |
Unexecuted instantiation: _ZN4SlabIP6Tuple2IP3StrbEEC2Ej |
34 | | |
35 | 1.17k | static constexpr ObjHeader obj_header(unsigned num_items) { |
36 | 1.17k | return ObjHeader::Slab( |
37 | 1.17k | std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items); |
38 | 1.17k | } _ZN4SlabIP3StrE10obj_headerEj Line | Count | Source | 35 | 257 | static constexpr ObjHeader obj_header(unsigned num_items) { | 36 | 257 | return ObjHeader::Slab( | 37 | 257 | std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items); | 38 | 257 | } |
_ZN4SlabIiE10obj_headerEj Line | Count | Source | 35 | 838 | static constexpr ObjHeader obj_header(unsigned num_items) { | 36 | 838 | return ObjHeader::Slab( | 37 | 838 | std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items); | 38 | 838 | } |
Unexecuted instantiation: _ZN4SlabIPN10classes_gc10OpaqueBaseEE10obj_headerEj Unexecuted instantiation: _ZN4SlabIPN10classes_gc12PointersBaseEE10obj_headerEj Unexecuted instantiation: _ZN4SlabIPN10classes_gc14BaseWithMethodEE10obj_headerEj _ZN4SlabIP6Tuple2IiP3StrEE10obj_headerEj Line | Count | Source | 35 | 9 | static constexpr ObjHeader obj_header(unsigned num_items) { | 36 | 9 | return ObjHeader::Slab( | 37 | 9 | std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items); | 38 | 9 | } |
_ZN4SlabIP6Tuple2IP3StriEE10obj_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 | } |
_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 | } |
_ZN4SlabIbE10obj_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 | } |
_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 | } |
_ZN4SlabIdE10obj_headerEj Line | Count | Source | 35 | 2 | static constexpr ObjHeader obj_header(unsigned num_items) { | 36 | 2 | return ObjHeader::Slab( | 37 | 2 | std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items); | 38 | 2 | } |
Unexecuted instantiation: _ZN4SlabIPN10hnode_asdl7hnode_tEE10obj_headerEj _ZN4SlabIPN4pyos11PasswdEntryEE10obj_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 | } |
_ZN4SlabIPN12runtime_asdl7value_tEE10obj_headerEj Line | Count | Source | 35 | 9 | static constexpr ObjHeader obj_header(unsigned num_items) { | 36 | 9 | return ObjHeader::Slab( | 37 | 9 | std::is_pointer<T>() ? HeapTag::Scanned : HeapTag::Opaque, num_items); | 38 | 9 | } |
_ZN4SlabIPN4args7_ActionEE10obj_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 | } |
Unexecuted instantiation: _ZN4SlabIP6Tuple2IP3StrbEE10obj_headerEj |
39 | | |
40 | | GC_OBJ(header_); |
41 | | T items_[1]; // variable length |
42 | | |
43 | | DISALLOW_COPY_AND_ASSIGN(Slab); |
44 | | }; |
45 | | |
46 | | template <typename T, int N> |
47 | | class GlobalSlab { |
48 | | // A template type with the same layout as Slab of length N. For |
49 | | // initializing global constant List. |
50 | | public: |
51 | | ObjHeader header_; |
52 | | T items_[N]; |
53 | | |
54 | | DISALLOW_COPY_AND_ASSIGN(GlobalSlab) |
55 | | }; |
56 | | |
57 | | // The first field is items_ |
58 | | const int kSlabHeaderSize = offsetof(Slab<int>, items_); |
59 | | |
60 | | #endif // GC_SLAB_H |