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<uint16_t>* atomic_mutable_bitfield =
54 reinterpret_cast<std::atomic<uint16_t>*
>(
55 const_cast<uint16_t*
>(
reinterpret_cast<const uint16_t*
>(
56 reinterpret_cast<const uint8_t*
>(payload) -
57 api_constants::kFullyConstructedBitFieldOffsetFromPayload)));
62 uint16_t value = atomic_mutable_bitfield->load(std::memory_order_relaxed);
63 value |= api_constants::kFullyConstructedBitMask;
64 atomic_mutable_bitfield->store(value, std::memory_order_release);
71 template <
typename GCInfoType,
typename CustomSpace,
size_t alignment>
73 static void*
Invoke(AllocationHandle& handle,
size_t size) {
74 static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
75 "Custom space must inherit from CustomSpaceBase.");
78 "Custom spaces that support compaction do not support allocating "
79 "objects with non-default (i.e. word-sized) alignment.");
80 return MakeGarbageCollectedTraitInternal::Allocate(
81 handle, size,
static_cast<AlignVal>(alignment),
88 template <
typename GCInfoType>
90 api_constants::kDefaultAlignment>
92 static void*
Invoke(AllocationHandle& handle,
size_t size) {
93 return MakeGarbageCollectedTraitInternal::Allocate(
99 template <
typename GCInfoType,
size_t alignment>
101 static void*
Invoke(AllocationHandle& handle,
size_t size) {
102 return MakeGarbageCollectedTraitInternal::Allocate(
103 handle, size,
static_cast<AlignVal>(alignment),
109 template <
typename GCInfoType,
typename CustomSpace>
111 api_constants::kDefaultAlignment>
113 static void*
Invoke(AllocationHandle& handle,
size_t size) {
114 static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
115 "Custom space must inherit from CustomSpaceBase.");
116 return MakeGarbageCollectedTraitInternal::Allocate(
118 CustomSpace::kSpaceIndex);
124 Allocate(cppgc::AllocationHandle&,
size_t,
GCInfoIndex);
150 "T needs to be a garbage collected object");
151 static_assert(!IsGarbageCollectedWithMixinTypeV<T> ||
153 internal::api_constants::kLargeObjectSizeThreshold,
154 "GarbageCollectedMixin may not be a large object");
167 std::is_base_of<typename T::ParentMostGarbageCollectedType, T>::value,
168 "U of GarbageCollected<U> must be a base of T. Check "
169 "GarbageCollected<T> base class inheritance.");
170 static constexpr size_t kWantedAlignment =
171 alignof(T) < internal::api_constants::kDefaultAlignment
172 ? internal::api_constants::kDefaultAlignment
175 kWantedAlignment <= internal::api_constants::kMaxSupportedAlignment,
176 "Requested alignment larger than alignof(std::max_align_t) bytes. "
177 "Please file a bug to possibly get this restriction lifted.");
180 T,
typename T::ParentMostGarbageCollectedType>::ResultType,
236 template <
typename... Args>
237 static T*
Call(AllocationHandle& handle, Args&&... args) {
240 T*
object = ::new (memory) T(std::forward<Args>(args)...);
245 template <
typename... Args>
249 handle,
sizeof(T) + additional_bytes.
value);
250 T*
object = ::new (memory) T(std::forward<Args>(args)...);
262template <
typename T,
typename =
void>
275template <
typename T,
typename... Args>
293template <
typename T,
typename... Args>
298 std::forward<Args>(args)...);
305#undef CPPGC_DEFAULT_ALIGNED
306#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:147
static void * Allocate(AllocationHandle &handle, size_t size)
Definition: allocation.h:165
static void MarkObjectAsFullyConstructed(const void *payload)
Definition: allocation.h:190
Definition: allocation.h:234
static T * Call(AllocationHandle &handle, Args &&... args)
Definition: allocation.h:237
static T * Call(AllocationHandle &handle, AdditionalBytes additional_bytes, Args &&... args)
Definition: allocation.h:246
Definition: allocation.h:49
friend class HeapObjectHeader
Definition: allocation.h:133
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:276
Definition: allocation.h:218
constexpr AdditionalBytes(size_t bytes)
Definition: allocation.h:219
const size_t value
Definition: allocation.h:220
Definition: custom-space.h:15
Definition: allocation.h:263
static void Call(T *)
Definition: allocation.h:264
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:101
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:92
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:113
Definition: allocation.h:72
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:73
#define V8_EXPORT
Definition: v8config.h:800
#define V8_INLINE
Definition: v8config.h:500