5 #ifndef INCLUDE_CPPGC_ALLOCATION_H_
6 #define INCLUDE_CPPGC_ALLOCATION_H_
12 #include "cppgc/custom-space.h"
13 #include "cppgc/garbage-collected.h"
14 #include "cppgc/heap.h"
15 #include "cppgc/internal/api-constants.h"
16 #include "cppgc/internal/gc-info.h"
21 class MakeGarbageCollectedTraitBase;
29 std::atomic<uint16_t>* atomic_mutable_bitfield =
30 reinterpret_cast<std::atomic<uint16_t>*>(
31 const_cast<uint16_t*>(
reinterpret_cast<
const uint16_t*>(
32 reinterpret_cast<
const uint8_t*>(payload) -
34 uint16_t value = atomic_mutable_bitfield->load(std::memory_order_relaxed);
36 atomic_mutable_bitfield->store(value, std::memory_order_release);
43 friend class HeapObjectHeader;
56 class MakeGarbageCollectedTraitBase
59 template <
typename U,
typename CustomSpace>
61 static void* Allocate(
Heap* heap, size_t size) {
64 "Custom space must inherit from CustomSpaceBase.");
67 CustomSpace::kSpaceIndex);
72 struct SpacePolicy<U,
void> {
73 static void* Allocate(
Heap* heap, size_t size) {
89 return SpacePolicy<T,
typename SpaceTrait<T>::Space>::Allocate(heap, size);
114 template <
typename T>
117 template <
typename... Args>
120 "T needs to be a garbage collected object");
124 "GarbageCollectedMixin may not be a large object");
125 void* memory = MakeGarbageCollectedTraitBase<T>::Allocate(heap,
sizeof(T));
126 T* object = ::
new (memory) T(std::forward<Args>(args)...);
127 MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed(object);
138 template <
typename T,
typename =
void>
151 template <
typename T,
typename... Args>