5 #ifndef INCLUDE_CPPGC_ALLOCATION_H_
6 #define INCLUDE_CPPGC_ALLOCATION_H_
12 #include <type_traits>
15 #include "cppgc/custom-space.h"
16 #include "cppgc/internal/api-constants.h"
17 #include "cppgc/internal/gc-info.h"
18 #include "cppgc/type-traits.h"
26 class AllocationHandle;
34 std::atomic<uint16_t>* atomic_mutable_bitfield =
35 reinterpret_cast<std::atomic<uint16_t>*>(
36 const_cast<uint16_t*>(
reinterpret_cast<
const uint16_t*>(
37 reinterpret_cast<
const uint8_t*>(payload) -
39 atomic_mutable_bitfield->fetch_or(
api_constants::kFullyConstructedBitMask,
40 std::memory_order_release);
43 template <
typename U,
typename CustomSpace>
45 static void*
Allocate(AllocationHandle& handle, size_t size) {
48 "Custom space must inherit from CustomSpaceBase.");
50 handle, size,
internal::GCInfoTrait<U>::Index(),
51 CustomSpace::kSpaceIndex);
57 static void*
Allocate(AllocationHandle& handle, size_t size) {
60 handle, size,
internal::GCInfoTrait<U>::Index());
65 static void* Allocate(
cppgc::AllocationHandle& handle, size_t size,
67 static void* Allocate(
cppgc::AllocationHandle& handle, size_t size,
70 friend class HeapObjectHeader;
87 "T needs to be a garbage collected object");
88 static_assert(!IsGarbageCollectedWithMixinTypeV<T> ||
91 "GarbageCollectedMixin may not be a large object");
104 std::is_base_of<
typename T::ParentMostGarbageCollectedType, T>::value,
105 "U of GarbageCollected<U> must be a base of T. Check "
106 "GarbageCollected<T> base class inheritance.");
109 T,
typename T::ParentMostGarbageCollectedType>::ResultType,
110 typename SpaceTrait<T>::Space>::Allocate(handle, size);
162 template <
typename T>
165 template <
typename... Args>
166 static T*
Call(AllocationHandle& handle, Args&&... args) {
169 T* object = ::
new (memory) T(std::forward<Args>(args)...);
174 template <
typename... Args>
178 handle,
sizeof(T) + additional_bytes
.value);
179 T* object = ::
new (memory) T(std::forward<Args>(args)...);
191 template <
typename T,
typename =
void>
204 template <
typename T,
typename... Args>
222 template <
typename T,
typename... Args>
226 std::forward<Args>(args)...);