5#ifndef INCLUDE_CPPGC_ALLOCATION_H_
6#define INCLUDE_CPPGC_ALLOCATION_H_
21#if defined(__has_attribute)
22#if __has_attribute(assume_aligned)
23#define CPPGC_DEFAULT_ALIGNED \
24 __attribute__((assume_aligned(api_constants::kDefaultAlignment)))
25#define CPPGC_DOUBLE_WORD_ALIGNED \
26 __attribute__((assume_aligned(2 * api_constants::kDefaultAlignment)))
30#if !defined(CPPGC_DEFAULT_ALIGNED)
31#define CPPGC_DEFAULT_ALIGNED
34#if !defined(CPPGC_DOUBLE_WORD_ALIGNED)
35#define CPPGC_DOUBLE_WORD_ALIGNED
43class AllocationHandle;
53 std::atomic_ref<uint16_t> atomic_mutable_bitfield(
54 *
const_cast<uint16_t*
>(
reinterpret_cast<const uint16_t*
>(
55 reinterpret_cast<const uint8_t*
>(payload) -
56 api_constants::kFullyConstructedBitFieldOffsetFromPayload)));
61 uint16_t value = atomic_mutable_bitfield.load(std::memory_order_relaxed);
62 value |= api_constants::kFullyConstructedBitMask;
63 atomic_mutable_bitfield.store(value, std::memory_order_release);
70 template <
typename GCInfoType,
typename CustomSpace,
size_t alignment>
72 static void*
Invoke(AllocationHandle& handle,
size_t size) {
73 static_assert(std::is_base_of_v<CustomSpaceBase, CustomSpace>,
74 "Custom space must inherit from CustomSpaceBase.");
77 "Custom spaces that support compaction do not support allocating "
78 "objects with non-default (i.e. word-sized) alignment.");
79 return MakeGarbageCollectedTraitInternal::Allocate(
80 handle, size,
static_cast<AlignVal>(alignment),
87 template <
typename GCInfoType>
89 api_constants::kDefaultAlignment>
91 static void*
Invoke(AllocationHandle& handle,
size_t size) {
92 return MakeGarbageCollectedTraitInternal::Allocate(
98 template <
typename GCInfoType,
size_t alignment>
100 static void*
Invoke(AllocationHandle& handle,
size_t size) {
101 return MakeGarbageCollectedTraitInternal::Allocate(
102 handle, size,
static_cast<AlignVal>(alignment),
108 template <
typename GCInfoType,
typename CustomSpace>
110 api_constants::kDefaultAlignment>
112 static void*
Invoke(AllocationHandle& handle,
size_t size) {
113 static_assert(std::is_base_of_v<CustomSpaceBase, CustomSpace>,
114 "Custom space must inherit from CustomSpaceBase.");
115 return MakeGarbageCollectedTraitInternal::Allocate(
117 CustomSpace::kSpaceIndex);
123 Allocate(cppgc::AllocationHandle&,
size_t,
GCInfoIndex);
149 "T needs to be a garbage collected object");
150 static_assert(!IsGarbageCollectedWithMixinTypeV<T> ||
152 internal::api_constants::kLargeObjectSizeThreshold,
153 "GarbageCollectedMixin may not be a large object");
166 std::is_base_of_v<typename T::ParentMostGarbageCollectedType, T>,
167 "U of GarbageCollected<U> must be a base of T. Check "
168 "GarbageCollected<T> base class inheritance.");
169 static constexpr size_t kWantedAlignment =
170 alignof(T) < internal::api_constants::kDefaultAlignment
171 ? internal::api_constants::kDefaultAlignment
174 kWantedAlignment <= internal::api_constants::kMaxSupportedAlignment,
175 "Requested alignment larger than alignof(std::max_align_t) bytes. "
176 "Please file a bug to possibly get this restriction lifted.");
179 T,
typename T::ParentMostGarbageCollectedType>::ResultType,
235 template <
typename... Args>
236 static T*
Call(AllocationHandle& handle, Args&&... args) {
239 T*
object = ::new (memory) T(std::forward<Args>(args)...);
244 template <
typename... Args>
248 handle,
sizeof(T) + additional_bytes.
value);
249 T*
object = ::new (memory) T(std::forward<Args>(args)...);
261template <
typename T,
typename =
void>
274template <
typename T,
typename... Args>
292template <
typename T,
typename... Args>
297 std::forward<Args>(args)...);
304#undef CPPGC_DEFAULT_ALIGNED
305#undef CPPGC_DOUBLE_WORD_ALIGNED
#define CPPGC_DEFAULT_ALIGNED
Definition: allocation.h:31
#define CPPGC_DOUBLE_WORD_ALIGNED
Definition: allocation.h:35
Definition: custom-space.h:49
static constexpr bool kSupportsCompaction
Definition: custom-space.h:55
Definition: allocation.h:146
static void * Allocate(AllocationHandle &handle, size_t size)
Definition: allocation.h:164
static void MarkObjectAsFullyConstructed(const void *payload)
Definition: allocation.h:189
Definition: allocation.h:233
static T * Call(AllocationHandle &handle, Args &&... args)
Definition: allocation.h:236
static T * Call(AllocationHandle &handle, AdditionalBytes additional_bytes, Args &&... args)
Definition: allocation.h:245
Definition: allocation.h:49
friend class HeapObjectHeader
Definition: allocation.h:132
static void MarkObjectAsFullyConstructed(const void *payload)
Definition: allocation.h:51
uint16_t GCInfoIndex
Definition: gc-info.h:21
std::align_val_t AlignVal
Definition: allocation.h:47
Definition: allocation.h:38
T * MakeGarbageCollected(AllocationHandle &handle, Args &&... args)
Definition: allocation.h:275
Definition: allocation.h:217
constexpr AdditionalBytes(size_t bytes)
Definition: allocation.h:218
const size_t value
Definition: allocation.h:219
Definition: custom-space.h:15
Definition: allocation.h:262
static void Call(T *)
Definition: allocation.h:263
void Space
Definition: custom-space.h:70
Definition: gc-info.h:109
Definition: type-traits.h:99
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:100
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:91
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:112
Definition: allocation.h:71
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:72
#define V8_EXPORT
Definition: v8config.h:855
#define V8_INLINE
Definition: v8config.h:508