1// Copyright 2020 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "include/cppgc/allocation.h" 6 7#include "include/cppgc/internal/api-constants.h" 8#include "src/base/macros.h" 9#include "src/heap/cppgc/globals.h" 10#include "src/heap/cppgc/object-allocator.h" 11 12#if defined(__clang__) && !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE 13#define CPPGC_FORCE_ALWAYS_INLINE __attribute__((always_inline)) 14#else 15#define CPPGC_FORCE_ALWAYS_INLINE 16#endif 17 18namespace cppgc { 19namespace internal { 20 21STATIC_ASSERT(api_constants::kLargeObjectSizeThreshold == 22 kLargeObjectSizeThreshold); 23 24#if !(defined(V8_TARGET_ARCH_32_BIT) && defined(V8_CC_GNU)) 25// GCC on x86 has alignof(std::max_alignt) == 16 (quad word) which is not 26// satisfied by Oilpan. 27static_assert(api_constants::kMaxSupportedAlignment >= 28 alignof(std::max_align_t), 29 "Maximum support alignment must at least cover " 30 "alignof(std::max_align_t)."); 31#endif // !(defined(V8_TARGET_ARCH_32_BIT) && defined(V8_CC_GNU)) 32 33// Using CPPGC_FORCE_ALWAYS_INLINE to guide LTO for inlining the allocation 34// fast path. 35// static 36CPPGC_FORCE_ALWAYS_INLINE void* MakeGarbageCollectedTraitInternal::Allocate( 37 cppgc::AllocationHandle& handle, size_t size, GCInfoIndex index) { 38 return static_cast<ObjectAllocator&>(handle).AllocateObject(size, index); 39} 40 41// Using CPPGC_FORCE_ALWAYS_INLINE to guide LTO for inlining the allocation 42// fast path. 43// static 44CPPGC_FORCE_ALWAYS_INLINE void* MakeGarbageCollectedTraitInternal::Allocate( 45 cppgc::AllocationHandle& handle, size_t size, AlignVal alignment, 46 GCInfoIndex index) { 47 return static_cast<ObjectAllocator&>(handle).AllocateObject(size, alignment, 48 index); 49} 50 51// Using CPPGC_FORCE_ALWAYS_INLINE to guide LTO for inlining the allocation 52// fast path. 53// static 54CPPGC_FORCE_ALWAYS_INLINE void* MakeGarbageCollectedTraitInternal::Allocate( 55 cppgc::AllocationHandle& handle, size_t size, GCInfoIndex index, 56 CustomSpaceIndex space_index) { 57 return static_cast<ObjectAllocator&>(handle).AllocateObject(size, index, 58 space_index); 59} 60 61// Using CPPGC_FORCE_ALWAYS_INLINE to guide LTO for inlining the allocation 62// fast path. 63// static 64CPPGC_FORCE_ALWAYS_INLINE void* MakeGarbageCollectedTraitInternal::Allocate( 65 cppgc::AllocationHandle& handle, size_t size, AlignVal alignment, 66 GCInfoIndex index, CustomSpaceIndex space_index) { 67 return static_cast<ObjectAllocator&>(handle).AllocateObject( 68 size, alignment, index, space_index); 69} 70 71} // namespace internal 72} // namespace cppgc 73