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/internal/api-constants.h"
15 #include "cppgc/internal/gc-info.h"
20 class MakeGarbageCollectedTraitBase;
23 class ObjectAllocator;
29 class AllocationHandle;
37 std::atomic<uint16_t>* atomic_mutable_bitfield =
38 reinterpret_cast<std::atomic<uint16_t>*>(
39 const_cast<uint16_t*>(
reinterpret_cast<
const uint16_t*>(
40 reinterpret_cast<
const uint8_t*>(payload) -
42 uint16_t value = atomic_mutable_bitfield->load(std::memory_order_relaxed);
44 atomic_mutable_bitfield->store(value, std::memory_order_release);
52 friend class HeapObjectHeader;
65 class MakeGarbageCollectedTraitBase
68 template <
typename U,
typename CustomSpace>
70 static void* Allocate(AllocationHandle& handle, size_t size) {
73 "Custom space must inherit from CustomSpaceBase.");
76 CustomSpace::kSpaceIndex);
81 struct SpacePolicy<U,
void> {
82 static void* Allocate(AllocationHandle& handle, size_t size) {
98 static void*
Allocate(AllocationHandle& handle, size_t size) {
99 return SpacePolicy<T,
typename SpaceTrait<T>::Space>::Allocate(handle,
125 template <
typename T>
128 template <
typename... Args>
129 static T*
Call(AllocationHandle& handle, Args&&... args) {
131 "T needs to be a garbage collected object");
135 "GarbageCollectedMixin may not be a large object");
137 MakeGarbageCollectedTraitBase<T>::Allocate(handle,
sizeof(T));
138 T* object = ::
new (memory) T(std::forward<Args>(args)...);
139 MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed(object);
150 template <
typename T,
typename =
void>
163 template <
typename T,
typename... Args>