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) -
62 uint16_t value = atomic_mutable_bitfield->load(std::memory_order_relaxed);
64 atomic_mutable_bitfield->store(value, std::memory_order_release);
71 template <
typename GCInfoType,
typename CustomSpace,
size_t alignment>
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.");
81 handle, size,
static_cast<AlignVal>(alignment),
82 internal::GCInfoTrait<GCInfoType>::Index(), CustomSpace::kSpaceIndex);
88 template <
typename GCInfoType>
90 api_constants::kDefaultAlignment>
94 handle, size, internal::GCInfoTrait<GCInfoType>::Index());
99 template <
typename GCInfoType,
size_t alignment>
103 handle, size,
static_cast<AlignVal>(alignment),
104 internal::GCInfoTrait<GCInfoType>::Index());
109 template <
typename GCInfoType,
typename CustomSpace>
111 api_constants::kDefaultAlignment>
114 static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
115 "Custom space must inherit from CustomSpaceBase.");
117 handle, size, internal::GCInfoTrait<GCInfoType>::Index(),
118 CustomSpace::kSpaceIndex);
150 "T needs to be a garbage collected object");
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 =
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>
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
static constexpr bool kSupportsCompaction
static V8_INLINE void MarkObjectAsFullyConstructed(const void *payload)
static V8_INLINE void * Allocate(AllocationHandle &handle, size_t size)
static T * Call(AllocationHandle &handle, Args &&... args)
static T * Call(AllocationHandle &handle, AdditionalBytes additional_bytes, Args &&... args)
static V8_EXPORT void *CPPGC_DEFAULT_ALIGNED Allocate(cppgc::AllocationHandle &, size_t, GCInfoIndex)
static void MarkObjectAsFullyConstructed(const void *payload)
base::Vector< const DirectHandle< Object > > args
#define CPPGC_DEFAULT_ALIGNED
#define CPPGC_DOUBLE_WORD_ALIGNED
static constexpr size_t kDefaultAlignment
static constexpr size_t kMaxSupportedAlignment
static constexpr size_t kLargeObjectSizeThreshold
static constexpr size_t kFullyConstructedBitFieldOffsetFromPayload
static constexpr uint16_t kFullyConstructedBitMask
std::align_val_t AlignVal
V8_INLINE T * MakeGarbageCollected(AllocationHandle &handle, Args &&... args)
constexpr bool IsGarbageCollectedWithMixinTypeV
constexpr AdditionalBytes(size_t bytes)
static void * Invoke(AllocationHandle &handle, size_t size)
static void * Invoke(AllocationHandle &handle, size_t size)
static void * Invoke(AllocationHandle &handle, size_t size)
static void * Invoke(AllocationHandle &handle, size_t size)