mycpp

Coverage Report

Created: 2025-05-21 23:38

/home/uke/oil/mycpp/gc_alloc.h
Line
Count
Source (jump to first uncovered line)
1
// gc_alloc.h: Functions that wrap gHeap.Allocate()
2
3
#ifndef MYCPP_GC_ALLOC_H
4
#define MYCPP_GC_ALLOC_H
5
6
#include <string.h>  // strlen
7
8
#include <new>      // placement new
9
#include <utility>  // std::forward
10
11
#include "mycpp/gc_obj.h"   // for RawObject, ObjHeader
12
#include "mycpp/gc_slab.h"  // for NewSlab()
13
#include "mycpp/gc_str.h"   // for NewStr()
14
15
#if defined(BUMP_LEAK)
16
  #include "mycpp/bump_leak_heap.h"
17
extern BumpLeakHeap gHeap;
18
#elif defined(MARK_SWEEP)
19
  #include "mycpp/mark_sweep_heap.h"
20
extern MarkSweepHeap gHeap;
21
#endif
22
23
// mycpp generates code that keeps track of the root set
24
class StackRoot {
25
 public:
26
0
  StackRoot(void* root) {
27
0
    RawObject** obj = reinterpret_cast<RawObject**>(root);
28
0
    gHeap.PushRoot(obj);
29
0
  }
30
31
0
  ~StackRoot() {
32
0
    gHeap.PopRoot();
33
0
  }
34
};
35
36
// sugar for tests
37
class StackRoots {
38
 public:
39
  // Note: void** seems logical, because these are pointers to pointers, but
40
  // the C++ compiler doesn't like it.
41
54
  StackRoots(std::initializer_list<void*> roots) {
42
54
    n_ = roots.size();
43
44
#if VALIDATE_ROOTS
45
    int i = 0;
46
#endif
47
48
107
    for (auto root : roots) {  // can't use roots[i]
49
107
      RawObject** obj = reinterpret_cast<RawObject**>(root);
50
#if VALIDATE_ROOTS
51
      ValidateRoot(*obj);
52
      i++;
53
#endif
54
55
107
      gHeap.PushRoot(obj);
56
107
    }
57
54
  }
58
59
54
  ~StackRoots() {
60
161
    for (int i = 0; i < n_; ++i) {
61
107
      gHeap.PopRoot();
62
107
    }
63
54
  }
64
65
 private:
66
  int n_;
67
};
68
69
// Note:
70
// - This function causes code bloat due to template expansion on hundreds of
71
//   types.  Could switch to a GC_NEW() macro
72
// - GCC generates slightly larger code if you factor out void* place and new
73
//   (place) T()
74
//
75
// Variadic templates:
76
// https://eli.thegreenplace.net/2014/variadic-templates-in-c/
77
template <typename T, typename... Args>
78
507
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
507
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
507
                "Expected no padding");
91
92
507
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
507
#if MARK_SWEEP
96
507
  int obj_id;
97
507
  int pool_id;
98
507
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
507
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
507
#if MARK_SWEEP
104
507
  header->obj_id = obj_id;
105
507
  #ifndef NO_POOL_ALLOC
106
507
  header->pool_id = pool_id;
107
507
  #endif
108
507
#endif
109
507
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
507
  memset(obj, 0, sizeof(T));
114
507
  return new (obj) T(std::forward<Args>(args)...);
115
507
}
_Z5AllocI6Tuple2IP6BigStriEJS2_iEEPT_DpOT0_
Line
Count
Source
78
5
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
5
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
5
                "Expected no padding");
91
92
5
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
5
#if MARK_SWEEP
96
5
  int obj_id;
97
5
  int pool_id;
98
5
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
5
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
5
#if MARK_SWEEP
104
5
  header->obj_id = obj_id;
105
5
  #ifndef NO_POOL_ALLOC
106
5
  header->pool_id = pool_id;
107
5
  #endif
108
5
#endif
109
5
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
5
  memset(obj, 0, sizeof(T));
114
5
  return new (obj) T(std::forward<Args>(args)...);
115
5
}
_Z5AllocI4DictIP5PointP6BigStrEJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI5PointJiiEEPT_DpOT0_
Line
Count
Source
78
34
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
34
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
34
                "Expected no padding");
91
92
34
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
34
#if MARK_SWEEP
96
34
  int obj_id;
97
34
  int pool_id;
98
34
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
34
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
34
#if MARK_SWEEP
104
34
  header->obj_id = obj_id;
105
34
  #ifndef NO_POOL_ALLOC
106
34
  header->pool_id = pool_id;
107
34
  #endif
108
34
#endif
109
34
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
34
  memset(obj, 0, sizeof(T));
114
34
  return new (obj) T(std::forward<Args>(args)...);
115
34
}
_Z5AllocI4DictIiP6BigStrEJEEPT_DpOT0_
Line
Count
Source
78
5
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
5
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
5
                "Expected no padding");
91
92
5
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
5
#if MARK_SWEEP
96
5
  int obj_id;
97
5
  int pool_id;
98
5
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
5
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
5
#if MARK_SWEEP
104
5
  header->obj_id = obj_id;
105
5
  #ifndef NO_POOL_ALLOC
106
5
  header->pool_id = pool_id;
107
5
  #endif
108
5
#endif
109
5
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
5
  memset(obj, 0, sizeof(T));
114
5
  return new (obj) T(std::forward<Args>(args)...);
115
5
}
_Z5AllocI4ListIiEJEEPT_DpOT0_
Line
Count
Source
78
334
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
334
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
334
                "Expected no padding");
91
92
334
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
334
#if MARK_SWEEP
96
334
  int obj_id;
97
334
  int pool_id;
98
334
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
334
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
334
#if MARK_SWEEP
104
334
  header->obj_id = obj_id;
105
334
  #ifndef NO_POOL_ALLOC
106
334
  header->pool_id = pool_id;
107
334
  #endif
108
334
#endif
109
334
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
334
  memset(obj, 0, sizeof(T));
114
334
  return new (obj) T(std::forward<Args>(args)...);
115
334
}
_Z5AllocI10IndexErrorJEEPT_DpOT0_
Line
Count
Source
78
5
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
5
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
5
                "Expected no padding");
91
92
5
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
5
#if MARK_SWEEP
96
5
  int obj_id;
97
5
  int pool_id;
98
5
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
5
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
5
#if MARK_SWEEP
104
5
  header->obj_id = obj_id;
105
5
  #ifndef NO_POOL_ALLOC
106
5
  header->pool_id = pool_id;
107
5
  #endif
108
5
#endif
109
5
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
5
  memset(obj, 0, sizeof(T));
114
5
  return new (obj) T(std::forward<Args>(args)...);
115
5
}
_Z5AllocI4DictIlP6BigStrEJEEPT_DpOT0_
Line
Count
Source
78
2
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
2
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
2
                "Expected no padding");
91
92
2
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
2
#if MARK_SWEEP
96
2
  int obj_id;
97
2
  int pool_id;
98
2
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
2
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
2
#if MARK_SWEEP
104
2
  header->obj_id = obj_id;
105
2
  #ifndef NO_POOL_ALLOC
106
2
  header->pool_id = pool_id;
107
2
  #endif
108
2
#endif
109
2
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
2
  memset(obj, 0, sizeof(T));
114
2
  return new (obj) T(std::forward<Args>(args)...);
115
2
}
_Z5AllocI4ListIlEJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI10ValueErrorJEEPT_DpOT0_
Line
Count
Source
78
7
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
7
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
7
                "Expected no padding");
91
92
7
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
7
#if MARK_SWEEP
96
7
  int obj_id;
97
7
  int pool_id;
98
7
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
7
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
7
#if MARK_SWEEP
104
7
  header->obj_id = obj_id;
105
7
  #ifndef NO_POOL_ALLOC
106
7
  header->pool_id = pool_id;
107
7
  #endif
108
7
#endif
109
7
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
7
  memset(obj, 0, sizeof(T));
114
7
  return new (obj) T(std::forward<Args>(args)...);
115
7
}
_Z5AllocI10ValueErrorJRP6BigStrEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI7OSErrorJiEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI12RuntimeErrorJRP6BigStrEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI12UnicodeErrorJP6BigStrEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI7IOErrorJiEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocIN5iolib10SignalSafeEJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
Unexecuted instantiation: _Z5AllocI7OSErrorJRiEEPT_DpOT0_
_Z5AllocIN5mylib5CFileEJRP8_IO_FILEEEPT_DpOT0_
Line
Count
Source
78
7
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
7
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
7
                "Expected no padding");
91
92
7
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
7
#if MARK_SWEEP
96
7
  int obj_id;
97
7
  int pool_id;
98
7
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
7
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
7
#if MARK_SWEEP
104
7
  header->obj_id = obj_id;
105
7
  #ifndef NO_POOL_ALLOC
106
7
  header->pool_id = pool_id;
107
7
  #endif
108
7
#endif
109
7
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
7
  memset(obj, 0, sizeof(T));
114
7
  return new (obj) T(std::forward<Args>(args)...);
115
7
}
Unexecuted instantiation: _Z5AllocI7IOErrorJRiEEPT_DpOT0_
Unexecuted instantiation: _Z5AllocI17KeyboardInterruptJEEPT_DpOT0_
_Z5AllocI4ListIP6BigStrEJEEPT_DpOT0_
Line
Count
Source
78
48
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
48
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
48
                "Expected no padding");
91
92
48
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
48
#if MARK_SWEEP
96
48
  int obj_id;
97
48
  int pool_id;
98
48
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
48
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
48
#if MARK_SWEEP
104
48
  header->obj_id = obj_id;
105
48
  #ifndef NO_POOL_ALLOC
106
48
  header->pool_id = pool_id;
107
48
  #endif
108
48
#endif
109
48
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
48
  memset(obj, 0, sizeof(T));
114
48
  return new (obj) T(std::forward<Args>(args)...);
115
48
}
_Z5AllocI4DictIiP6BigStrEJSt16initializer_listIiES4_IS2_EEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
Unexecuted instantiation: _Z5AllocI8KeyErrorJEEPT_DpOT0_
_Z5AllocI4DictIP6BigStriEJSt16initializer_listIS2_ES4_IiEEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI4DictIP6BigStriEJEEPT_DpOT0_
Line
Count
Source
78
8
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
8
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
8
                "Expected no padding");
91
92
8
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
8
#if MARK_SWEEP
96
8
  int obj_id;
97
8
  int pool_id;
98
8
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
8
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
8
#if MARK_SWEEP
104
8
  header->obj_id = obj_id;
105
8
  #ifndef NO_POOL_ALLOC
106
8
  header->pool_id = pool_id;
107
8
  #endif
108
8
#endif
109
8
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
8
  memset(obj, 0, sizeof(T));
114
8
  return new (obj) T(std::forward<Args>(args)...);
115
8
}
_Z5AllocI4DictIP6BigStrS2_EJEEPT_DpOT0_
Line
Count
Source
78
3
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
3
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
3
                "Expected no padding");
91
92
3
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
3
#if MARK_SWEEP
96
3
  int obj_id;
97
3
  int pool_id;
98
3
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
3
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
3
#if MARK_SWEEP
104
3
  header->obj_id = obj_id;
105
3
  #ifndef NO_POOL_ALLOC
106
3
  header->pool_id = pool_id;
107
3
  #endif
108
3
#endif
109
3
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
3
  memset(obj, 0, sizeof(T));
114
3
  return new (obj) T(std::forward<Args>(args)...);
115
3
}
_Z5AllocI4DictIiiEJEEPT_DpOT0_
Line
Count
Source
78
8
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
8
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
8
                "Expected no padding");
91
92
8
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
8
#if MARK_SWEEP
96
8
  int obj_id;
97
8
  int pool_id;
98
8
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
8
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
8
#if MARK_SWEEP
104
8
  header->obj_id = obj_id;
105
8
  #ifndef NO_POOL_ALLOC
106
8
  header->pool_id = pool_id;
107
8
  #endif
108
8
#endif
109
8
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
8
  memset(obj, 0, sizeof(T));
114
8
  return new (obj) T(std::forward<Args>(args)...);
115
8
}
_Z5AllocI4ListIP6Tuple2IiiEEJEEPT_DpOT0_
Line
Count
Source
78
2
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
2
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
2
                "Expected no padding");
91
92
2
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
2
#if MARK_SWEEP
96
2
  int obj_id;
97
2
  int pool_id;
98
2
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
2
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
2
#if MARK_SWEEP
104
2
  header->obj_id = obj_id;
105
2
  #ifndef NO_POOL_ALLOC
106
2
  header->pool_id = pool_id;
107
2
  #endif
108
2
#endif
109
2
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
2
  memset(obj, 0, sizeof(T));
114
2
  return new (obj) T(std::forward<Args>(args)...);
115
2
}
_Z5AllocI6Tuple2IiiEJiiEEPT_DpOT0_
Line
Count
Source
78
8
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
8
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
8
                "Expected no padding");
91
92
8
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
8
#if MARK_SWEEP
96
8
  int obj_id;
97
8
  int pool_id;
98
8
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
8
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
8
#if MARK_SWEEP
104
8
  header->obj_id = obj_id;
105
8
  #ifndef NO_POOL_ALLOC
106
8
  header->pool_id = pool_id;
107
8
  #endif
108
8
#endif
109
8
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
8
  memset(obj, 0, sizeof(T));
114
8
  return new (obj) T(std::forward<Args>(args)...);
115
8
}
_Z5AllocI4DictIP6Tuple2IiiEiEJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI4DictIP6Tuple2IP6BigStriEiEJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI4LineJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI10DerivedObjJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI4ListIbEJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI4ListIPiEJEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocIN5mylib9BufWriterEJEEPT_DpOT0_
Line
Count
Source
78
4
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
4
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
4
                "Expected no padding");
91
92
4
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
4
#if MARK_SWEEP
96
4
  int obj_id;
97
4
  int pool_id;
98
4
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
4
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
4
#if MARK_SWEEP
104
4
  header->obj_id = obj_id;
105
4
  #ifndef NO_POOL_ALLOC
106
4
  header->pool_id = pool_id;
107
4
  #endif
108
4
#endif
109
4
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
4
  memset(obj, 0, sizeof(T));
114
4
  return new (obj) T(std::forward<Args>(args)...);
115
4
}
_Z5AllocIN5mylib13BufLineReaderEJRP6BigStrEEPT_DpOT0_
Line
Count
Source
78
3
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
3
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
3
                "Expected no padding");
91
92
3
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
3
#if MARK_SWEEP
96
3
  int obj_id;
97
3
  int pool_id;
98
3
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
3
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
3
#if MARK_SWEEP
104
3
  header->obj_id = obj_id;
105
3
  #ifndef NO_POOL_ALLOC
106
3
  header->pool_id = pool_id;
107
3
  #endif
108
3
#endif
109
3
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
3
  memset(obj, 0, sizeof(T));
114
3
  return new (obj) T(std::forward<Args>(args)...);
115
3
}
_Z5AllocI6Tuple2IiP6BigStrEJiS2_EEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI6Tuple3IiP6BigStrS2_EJiS2_S2_EEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI6Tuple4IiP6BigStrS2_iEJiS2_S2_iEEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI6Tuple2IiP6BigStrEJiRS2_EEPT_DpOT0_
Line
Count
Source
78
2
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
2
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
2
                "Expected no padding");
91
92
2
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
2
#if MARK_SWEEP
96
2
  int obj_id;
97
2
  int pool_id;
98
2
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
2
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
2
#if MARK_SWEEP
104
2
  header->obj_id = obj_id;
105
2
  #ifndef NO_POOL_ALLOC
106
2
  header->pool_id = pool_id;
107
2
  #endif
108
2
#endif
109
2
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
2
  memset(obj, 0, sizeof(T));
114
2
  return new (obj) T(std::forward<Args>(args)...);
115
2
}
_Z5AllocI6Tuple2IiPS0_IiP6BigStrEEJiRS4_EEPT_DpOT0_
Line
Count
Source
78
1
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
1
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
1
                "Expected no padding");
91
92
1
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
1
#if MARK_SWEEP
96
1
  int obj_id;
97
1
  int pool_id;
98
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
1
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
1
#if MARK_SWEEP
104
1
  header->obj_id = obj_id;
105
1
  #ifndef NO_POOL_ALLOC
106
1
  header->pool_id = pool_id;
107
1
  #endif
108
1
#endif
109
1
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
1
  memset(obj, 0, sizeof(T));
114
1
  return new (obj) T(std::forward<Args>(args)...);
115
1
}
_Z5AllocI4NodeJEEPT_DpOT0_
Line
Count
Source
78
2
T* Alloc(Args&&... args) {
79
  // Alloc() allocates space for both a header and object and guarantees that
80
  // they're adjacent in memory (so that they're at known offsets from one
81
  // another). However, this means that the address that the object is
82
  // constructed at is offset from the address returned by the memory allocator
83
  // (by the size of the header), and therefore may not be sufficiently aligned.
84
  // Here we assert that the object will be sufficiently aligned by making the
85
  // equivalent assertion that zero padding would be required to align it.
86
  // Note: the required padding is given by the following (according to
87
  // https://en.wikipedia.org/wiki/Data_structure_alignment):
88
  // `padding = -offset & (align - 1)`.
89
2
  static_assert((-sizeof(ObjHeader) & (alignof(T) - 1)) == 0,
90
2
                "Expected no padding");
91
92
2
  DCHECK(gHeap.is_initialized_);
93
94
0
  constexpr size_t num_bytes = sizeof(ObjHeader) + sizeof(T);
95
2
#if MARK_SWEEP
96
2
  int obj_id;
97
2
  int pool_id;
98
2
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
99
#else
100
  void* place = gHeap.Allocate(num_bytes);
101
#endif
102
2
  ObjHeader* header = new (place) ObjHeader(T::obj_header());
103
2
#if MARK_SWEEP
104
2
  header->obj_id = obj_id;
105
2
  #ifndef NO_POOL_ALLOC
106
2
  header->pool_id = pool_id;
107
2
  #endif
108
2
#endif
109
2
  void* obj = header->ObjectAddress();
110
  // Now that mycpp generates code to initialize every field, we should
111
  // get rid of this.
112
  // TODO: fix uftrace failure, maybe by upgrading, or working around
113
2
  memset(obj, 0, sizeof(T));
114
2
  return new (obj) T(std::forward<Args>(args)...);
115
2
}
116
117
//
118
// String "Constructors".  We need these because of the "flexible array"
119
// pattern.  I don't think "new BigStr()" can do that, and placement new would
120
// require mycpp to generate 2 statements everywhere.
121
//
122
123
1.93k
inline BigStr* NewStr(int len) {
124
1.93k
  if (len == 0) {  // e.g. BufLineReader::readline() can use this optimization
125
188
    return kEmptyString;
126
188
  }
127
128
1.74k
  int obj_len = kStrHeaderSize + len + 1;  // NUL terminator
129
1.74k
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
130
1.74k
#if MARK_SWEEP
131
1.74k
  int obj_id;
132
1.74k
  int pool_id;
133
1.74k
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
134
#else
135
  void* place = gHeap.Allocate(num_bytes);
136
#endif
137
1.74k
  ObjHeader* header = new (place) ObjHeader(BigStr::obj_header());
138
139
1.74k
  auto s = new (header->ObjectAddress()) BigStr();
140
141
1.74k
  s->data_[len] = '\0';  // NUL terminate
142
1.74k
  s->len_ = len;
143
1.74k
  s->hash_ = 0;
144
1.74k
  s->is_hashed_ = 0;
145
146
1.74k
#if MARK_SWEEP
147
1.74k
  header->obj_id = obj_id;
148
1.74k
  #ifndef NO_POOL_ALLOC
149
1.74k
  header->pool_id = pool_id;
150
1.74k
  #endif
151
1.74k
#endif
152
1.74k
  return s;
153
1.93k
}
154
155
// Call OverAllocatedStr() when you don't know the length of the string up
156
// front, e.g. with snprintf().  CALLER IS RESPONSIBLE for calling
157
// s->MaybeShrink() afterward!
158
28
inline BigStr* OverAllocatedStr(int len) {
159
28
  int obj_len = kStrHeaderSize + len + 1;  // NUL terminator
160
28
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
161
28
#if MARK_SWEEP
162
28
  int obj_id;
163
28
  int pool_id;
164
28
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
165
#else
166
  void* place = gHeap.Allocate(num_bytes);
167
#endif
168
28
  ObjHeader* header = new (place) ObjHeader(BigStr::obj_header());
169
28
  auto s = new (header->ObjectAddress()) BigStr();
170
28
  s->hash_ = 0;
171
28
  s->is_hashed_ = 0;
172
173
28
#if MARK_SWEEP
174
28
  header->obj_id = obj_id;
175
28
  #ifndef NO_POOL_ALLOC
176
28
  header->pool_id = pool_id;
177
28
  #endif
178
28
#endif
179
28
  return s;
180
28
}
181
182
// Copy C string into the managed heap.
183
795
inline BigStr* StrFromC(const char* data, int len) {
184
  // Optimization that could be taken out once we have SmallStr
185
795
  if (len == 0) {
186
79
    return kEmptyString;
187
79
  }
188
716
  BigStr* s = NewStr(len);
189
716
  memcpy(s->data_, data, len);
190
716
  DCHECK(s->data_[len] == '\0');  // should be true because Heap was zeroed
191
192
0
  return s;
193
795
}
194
195
592
inline BigStr* StrFromC(const char* data) {
196
592
  return StrFromC(data, strlen(data));
197
592
}
198
199
// Create a slab with a number of entries of a certain type.
200
// Note: entries will be zero'd because we use calloc().  TODO: Consider
201
// zeroing them separately.
202
template <typename T>
203
613
inline Slab<T>* NewSlab(int len) {
204
613
  int obj_len = len * sizeof(T);
205
613
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
206
613
#if MARK_SWEEP
207
613
  int obj_id;
208
613
  int pool_id;
209
613
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
210
#else
211
  void* place = gHeap.Allocate(num_bytes);
212
#endif
213
613
  ObjHeader* header = new (place) ObjHeader(Slab<T>::obj_header(len));
214
613
  void* obj = header->ObjectAddress();
215
613
  if (std::is_pointer<T>()) {
216
112
    memset(obj, 0, obj_len);
217
112
  }
218
613
  auto slab = new (obj) Slab<T>(len);
219
613
#if MARK_SWEEP
220
613
  header->obj_id = obj_id;
221
613
  #ifndef NO_POOL_ALLOC
222
613
  header->pool_id = pool_id;
223
613
  #endif
224
613
#endif
225
613
  return slab;
226
613
}
_Z7NewSlabIiEP4SlabIT_Ei
Line
Count
Source
203
479
inline Slab<T>* NewSlab(int len) {
204
479
  int obj_len = len * sizeof(T);
205
479
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
206
479
#if MARK_SWEEP
207
479
  int obj_id;
208
479
  int pool_id;
209
479
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
210
#else
211
  void* place = gHeap.Allocate(num_bytes);
212
#endif
213
479
  ObjHeader* header = new (place) ObjHeader(Slab<T>::obj_header(len));
214
479
  void* obj = header->ObjectAddress();
215
479
  if (std::is_pointer<T>()) {
216
0
    memset(obj, 0, obj_len);
217
0
  }
218
479
  auto slab = new (obj) Slab<T>(len);
219
479
#if MARK_SWEEP
220
479
  header->obj_id = obj_id;
221
479
  #ifndef NO_POOL_ALLOC
222
479
  header->pool_id = pool_id;
223
479
  #endif
224
479
#endif
225
479
  return slab;
226
479
}
_Z7NewSlabIP5PointEP4SlabIT_Ei
Line
Count
Source
203
5
inline Slab<T>* NewSlab(int len) {
204
5
  int obj_len = len * sizeof(T);
205
5
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
206
5
#if MARK_SWEEP
207
5
  int obj_id;
208
5
  int pool_id;
209
5
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
210
#else
211
  void* place = gHeap.Allocate(num_bytes);
212
#endif
213
5
  ObjHeader* header = new (place) ObjHeader(Slab<T>::obj_header(len));
214
5
  void* obj = header->ObjectAddress();
215
5
  if (std::is_pointer<T>()) {
216
5
    memset(obj, 0, obj_len);
217
5
  }
218
5
  auto slab = new (obj) Slab<T>(len);
219
5
#if MARK_SWEEP
220
5
  header->obj_id = obj_id;
221
5
  #ifndef NO_POOL_ALLOC
222
5
  header->pool_id = pool_id;
223
5
  #endif
224
5
#endif
225
5
  return slab;
226
5
}
_Z7NewSlabIP6BigStrEP4SlabIT_Ei
Line
Count
Source
203
103
inline Slab<T>* NewSlab(int len) {
204
103
  int obj_len = len * sizeof(T);
205
103
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
206
103
#if MARK_SWEEP
207
103
  int obj_id;
208
103
  int pool_id;
209
103
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
210
#else
211
  void* place = gHeap.Allocate(num_bytes);
212
#endif
213
103
  ObjHeader* header = new (place) ObjHeader(Slab<T>::obj_header(len));
214
103
  void* obj = header->ObjectAddress();
215
103
  if (std::is_pointer<T>()) {
216
103
    memset(obj, 0, obj_len);
217
103
  }
218
103
  auto slab = new (obj) Slab<T>(len);
219
103
#if MARK_SWEEP
220
103
  header->obj_id = obj_id;
221
103
  #ifndef NO_POOL_ALLOC
222
103
  header->pool_id = pool_id;
223
103
  #endif
224
103
#endif
225
103
  return slab;
226
103
}
_Z7NewSlabIlEP4SlabIT_Ei
Line
Count
Source
203
21
inline Slab<T>* NewSlab(int len) {
204
21
  int obj_len = len * sizeof(T);
205
21
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
206
21
#if MARK_SWEEP
207
21
  int obj_id;
208
21
  int pool_id;
209
21
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
210
#else
211
  void* place = gHeap.Allocate(num_bytes);
212
#endif
213
21
  ObjHeader* header = new (place) ObjHeader(Slab<T>::obj_header(len));
214
21
  void* obj = header->ObjectAddress();
215
21
  if (std::is_pointer<T>()) {
216
0
    memset(obj, 0, obj_len);
217
0
  }
218
21
  auto slab = new (obj) Slab<T>(len);
219
21
#if MARK_SWEEP
220
21
  header->obj_id = obj_id;
221
21
  #ifndef NO_POOL_ALLOC
222
21
  header->pool_id = pool_id;
223
21
  #endif
224
21
#endif
225
21
  return slab;
226
21
}
_Z7NewSlabIP6Tuple2IiiEEP4SlabIT_Ei
Line
Count
Source
203
3
inline Slab<T>* NewSlab(int len) {
204
3
  int obj_len = len * sizeof(T);
205
3
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
206
3
#if MARK_SWEEP
207
3
  int obj_id;
208
3
  int pool_id;
209
3
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
210
#else
211
  void* place = gHeap.Allocate(num_bytes);
212
#endif
213
3
  ObjHeader* header = new (place) ObjHeader(Slab<T>::obj_header(len));
214
3
  void* obj = header->ObjectAddress();
215
3
  if (std::is_pointer<T>()) {
216
3
    memset(obj, 0, obj_len);
217
3
  }
218
3
  auto slab = new (obj) Slab<T>(len);
219
3
#if MARK_SWEEP
220
3
  header->obj_id = obj_id;
221
3
  #ifndef NO_POOL_ALLOC
222
3
  header->pool_id = pool_id;
223
3
  #endif
224
3
#endif
225
3
  return slab;
226
3
}
_Z7NewSlabIP6Tuple2IP6BigStriEEP4SlabIT_Ei
Line
Count
Source
203
1
inline Slab<T>* NewSlab(int len) {
204
1
  int obj_len = len * sizeof(T);
205
1
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
206
1
#if MARK_SWEEP
207
1
  int obj_id;
208
1
  int pool_id;
209
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
210
#else
211
  void* place = gHeap.Allocate(num_bytes);
212
#endif
213
1
  ObjHeader* header = new (place) ObjHeader(Slab<T>::obj_header(len));
214
1
  void* obj = header->ObjectAddress();
215
1
  if (std::is_pointer<T>()) {
216
1
    memset(obj, 0, obj_len);
217
1
  }
218
1
  auto slab = new (obj) Slab<T>(len);
219
1
#if MARK_SWEEP
220
1
  header->obj_id = obj_id;
221
1
  #ifndef NO_POOL_ALLOC
222
1
  header->pool_id = pool_id;
223
1
  #endif
224
1
#endif
225
1
  return slab;
226
1
}
_Z7NewSlabIbEP4SlabIT_Ei
Line
Count
Source
203
1
inline Slab<T>* NewSlab(int len) {
204
1
  int obj_len = len * sizeof(T);
205
1
  const size_t num_bytes = sizeof(ObjHeader) + obj_len;
206
1
#if MARK_SWEEP
207
1
  int obj_id;
208
1
  int pool_id;
209
1
  void* place = gHeap.Allocate(num_bytes, &obj_id, &pool_id);
210
#else
211
  void* place = gHeap.Allocate(num_bytes);
212
#endif
213
1
  ObjHeader* header = new (place) ObjHeader(Slab<T>::obj_header(len));
214
1
  void* obj = header->ObjectAddress();
215
1
  if (std::is_pointer<T>()) {
216
0
    memset(obj, 0, obj_len);
217
0
  }
218
1
  auto slab = new (obj) Slab<T>(len);
219
1
#if MARK_SWEEP
220
1
  header->obj_id = obj_id;
221
1
  #ifndef NO_POOL_ALLOC
222
1
  header->pool_id = pool_id;
223
1
  #endif
224
1
#endif
225
1
  return slab;
226
1
}
227
228
#endif  // MYCPP_GC_ALLOC_H