mycpp

Coverage Report

Created: 2025-05-16 02:17

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