11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "include/cppgc/allocation.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "include/cppgc/internal/api-constants.h"
81cb0ef41Sopenharmony_ci#include "src/base/macros.h"
91cb0ef41Sopenharmony_ci#include "src/heap/cppgc/globals.h"
101cb0ef41Sopenharmony_ci#include "src/heap/cppgc/object-allocator.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci#if defined(__clang__) && !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
131cb0ef41Sopenharmony_ci#define CPPGC_FORCE_ALWAYS_INLINE __attribute__((always_inline))
141cb0ef41Sopenharmony_ci#else
151cb0ef41Sopenharmony_ci#define CPPGC_FORCE_ALWAYS_INLINE
161cb0ef41Sopenharmony_ci#endif
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cinamespace cppgc {
191cb0ef41Sopenharmony_cinamespace internal {
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciSTATIC_ASSERT(api_constants::kLargeObjectSizeThreshold ==
221cb0ef41Sopenharmony_ci              kLargeObjectSizeThreshold);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci#if !(defined(V8_TARGET_ARCH_32_BIT) && defined(V8_CC_GNU))
251cb0ef41Sopenharmony_ci// GCC on x86 has alignof(std::max_alignt) == 16 (quad word) which is not
261cb0ef41Sopenharmony_ci// satisfied by Oilpan.
271cb0ef41Sopenharmony_cistatic_assert(api_constants::kMaxSupportedAlignment >=
281cb0ef41Sopenharmony_ci                  alignof(std::max_align_t),
291cb0ef41Sopenharmony_ci              "Maximum support alignment must at least cover "
301cb0ef41Sopenharmony_ci              "alignof(std::max_align_t).");
311cb0ef41Sopenharmony_ci#endif  // !(defined(V8_TARGET_ARCH_32_BIT) && defined(V8_CC_GNU))
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci// Using CPPGC_FORCE_ALWAYS_INLINE to guide LTO for inlining the allocation
341cb0ef41Sopenharmony_ci// fast path.
351cb0ef41Sopenharmony_ci// static
361cb0ef41Sopenharmony_ciCPPGC_FORCE_ALWAYS_INLINE void* MakeGarbageCollectedTraitInternal::Allocate(
371cb0ef41Sopenharmony_ci    cppgc::AllocationHandle& handle, size_t size, GCInfoIndex index) {
381cb0ef41Sopenharmony_ci  return static_cast<ObjectAllocator&>(handle).AllocateObject(size, index);
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci// Using CPPGC_FORCE_ALWAYS_INLINE to guide LTO for inlining the allocation
421cb0ef41Sopenharmony_ci// fast path.
431cb0ef41Sopenharmony_ci// static
441cb0ef41Sopenharmony_ciCPPGC_FORCE_ALWAYS_INLINE void* MakeGarbageCollectedTraitInternal::Allocate(
451cb0ef41Sopenharmony_ci    cppgc::AllocationHandle& handle, size_t size, AlignVal alignment,
461cb0ef41Sopenharmony_ci    GCInfoIndex index) {
471cb0ef41Sopenharmony_ci  return static_cast<ObjectAllocator&>(handle).AllocateObject(size, alignment,
481cb0ef41Sopenharmony_ci                                                              index);
491cb0ef41Sopenharmony_ci}
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci// Using CPPGC_FORCE_ALWAYS_INLINE to guide LTO for inlining the allocation
521cb0ef41Sopenharmony_ci// fast path.
531cb0ef41Sopenharmony_ci// static
541cb0ef41Sopenharmony_ciCPPGC_FORCE_ALWAYS_INLINE void* MakeGarbageCollectedTraitInternal::Allocate(
551cb0ef41Sopenharmony_ci    cppgc::AllocationHandle& handle, size_t size, GCInfoIndex index,
561cb0ef41Sopenharmony_ci    CustomSpaceIndex space_index) {
571cb0ef41Sopenharmony_ci  return static_cast<ObjectAllocator&>(handle).AllocateObject(size, index,
581cb0ef41Sopenharmony_ci                                                              space_index);
591cb0ef41Sopenharmony_ci}
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci// Using CPPGC_FORCE_ALWAYS_INLINE to guide LTO for inlining the allocation
621cb0ef41Sopenharmony_ci// fast path.
631cb0ef41Sopenharmony_ci// static
641cb0ef41Sopenharmony_ciCPPGC_FORCE_ALWAYS_INLINE void* MakeGarbageCollectedTraitInternal::Allocate(
651cb0ef41Sopenharmony_ci    cppgc::AllocationHandle& handle, size_t size, AlignVal alignment,
661cb0ef41Sopenharmony_ci    GCInfoIndex index, CustomSpaceIndex space_index) {
671cb0ef41Sopenharmony_ci  return static_cast<ObjectAllocator&>(handle).AllocateObject(
681cb0ef41Sopenharmony_ci      size, alignment, index, space_index);
691cb0ef41Sopenharmony_ci}
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci}  // namespace internal
721cb0ef41Sopenharmony_ci}  // namespace cppgc
73