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;
54 std::atomic<uint16_t>* atomic_mutable_bitfield =
55 reinterpret_cast<std::atomic<uint16_t>*
>(
56 const_cast<uint16_t*
>(
reinterpret_cast<const uint16_t*
>(
57 reinterpret_cast<const uint8_t*
>(payload) -
58 api_constants::kFullyConstructedBitFieldOffsetFromPayload)));
63 uint16_t value = atomic_mutable_bitfield->load(std::memory_order_relaxed);
64 value |= api_constants::kFullyConstructedBitMask;
65 atomic_mutable_bitfield->store(value, std::memory_order_release);
72 template <
typename GCInfoType,
typename CustomSpace,
size_t alignment>
74 static void*
Invoke(AllocationHandle& handle,
size_t size) {
75 static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
76 "Custom space must inherit from CustomSpaceBase.");
79 "Custom spaces that support compaction do not support allocating "
80 "objects with non-default (i.e. word-sized) alignment.");
81 return MakeGarbageCollectedTraitInternal::Allocate(
82 handle, size,
static_cast<AlignVal>(alignment),
89 template <
typename GCInfoType>
91 api_constants::kDefaultAlignment>
93 static void*
Invoke(AllocationHandle& handle,
size_t size) {
94 return MakeGarbageCollectedTraitInternal::Allocate(
100 template <
typename GCInfoType,
size_t alignment>
102 static void*
Invoke(AllocationHandle& handle,
size_t size) {
103 return MakeGarbageCollectedTraitInternal::Allocate(
104 handle, size,
static_cast<AlignVal>(alignment),
110 template <
typename GCInfoType,
typename CustomSpace>
112 api_constants::kDefaultAlignment>
114 static void*
Invoke(AllocationHandle& handle,
size_t size) {
115 static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
116 "Custom space must inherit from CustomSpaceBase.");
117 return MakeGarbageCollectedTraitInternal::Allocate(
119 CustomSpace::kSpaceIndex);
125 Allocate(cppgc::AllocationHandle&,
size_t,
GCInfoIndex);
151 "T needs to be a garbage collected object");
152 static_assert(!IsGarbageCollectedWithMixinTypeV<T> ||
154 internal::api_constants::kLargeObjectSizeThreshold,
155 "GarbageCollectedMixin may not be a large object");
168 std::is_base_of<typename T::ParentMostGarbageCollectedType, T>::value,
169 "U of GarbageCollected<U> must be a base of T. Check "
170 "GarbageCollected<T> base class inheritance.");
171 static constexpr size_t kWantedAlignment =
172 alignof(T) < internal::api_constants::kDefaultAlignment
173 ? internal::api_constants::kDefaultAlignment
176 kWantedAlignment <= internal::api_constants::kMaxSupportedAlignment,
177 "Requested alignment larger than alignof(std::max_align_t) bytes. "
178 "Please file a bug to possibly get this restriction lifted.");
181 T,
typename T::ParentMostGarbageCollectedType>::ResultType,
237 template <
typename... Args>
238 static T*
Call(AllocationHandle& handle, Args&&... args) {
241 T*
object = ::new (memory) T(std::forward<Args>(args)...);
246 template <
typename... Args>
250 handle,
sizeof(T) + additional_bytes.
value);
251 T*
object = ::new (memory) T(std::forward<Args>(args)...);
263template <
typename T,
typename =
void>
276template <
typename T,
typename... Args>
294template <
typename T,
typename... Args>
299 std::forward<Args>(args)...);
306#undef CPPGC_DEFAULT_ALIGNED
307#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:148
static void * Allocate(AllocationHandle &handle, size_t size)
Definition: allocation.h:166
static void MarkObjectAsFullyConstructed(const void *payload)
Definition: allocation.h:191
Definition: allocation.h:235
static T * Call(AllocationHandle &handle, Args &&... args)
Definition: allocation.h:238
static T * Call(AllocationHandle &handle, AdditionalBytes additional_bytes, Args &&... args)
Definition: allocation.h:247
Definition: allocation.h:50
friend class HeapObjectHeader
Definition: allocation.h:134
static void MarkObjectAsFullyConstructed(const void *payload)
Definition: allocation.h:52
uint16_t GCInfoIndex
Definition: gc-info.h:21
AlignVal
Definition: allocation.h:48
Definition: allocation.h:38
T * MakeGarbageCollected(AllocationHandle &handle, Args &&... args)
Definition: allocation.h:277
Definition: allocation.h:219
constexpr AdditionalBytes(size_t bytes)
Definition: allocation.h:220
const size_t value
Definition: allocation.h:221
Definition: custom-space.h:15
Definition: allocation.h:264
static void Call(T *)
Definition: allocation.h:265
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:102
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:93
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:114
Definition: allocation.h:73
static void * Invoke(AllocationHandle &handle, size_t size)
Definition: allocation.h:74
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499