From fdae1b6583ed8f92298e53e4125cffbac46e2e87 Mon Sep 17 00:00:00 2001 From: Michael Lippautz Date: Wed, 17 Mar 2021 20:49:57 +0100 Subject: [PATCH] cppgc: Refactor object allocation to improve binary size Refactor SpacePolicy on a non-templated class to avoid the situation of having MakeGarbageCollectedTraitBase::SpacePolicy refer to different T and U which make it hard for the compiler to alias anything. Bug: chromium:1056170 Change-Id: I78eb0362d43403ad2712bcb65746eeb9f6ad44fa Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2769338 Reviewed-by: Omer Katz Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/master@{#73494} --- include/cppgc/allocation.h | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/include/cppgc/allocation.h b/include/cppgc/allocation.h index 78715fc661..f4f0e72bd5 100644 --- a/include/cppgc/allocation.h +++ b/include/cppgc/allocation.h @@ -43,6 +43,28 @@ class V8_EXPORT MakeGarbageCollectedTraitInternal { std::memory_order_release); } + template + struct SpacePolicy { + static void* Allocate(AllocationHandle& handle, size_t size) { + // Custom space. + static_assert(std::is_base_of::value, + "Custom space must inherit from CustomSpaceBase."); + return MakeGarbageCollectedTraitInternal::Allocate( + handle, size, internal::GCInfoTrait::Index(), + CustomSpace::kSpaceIndex); + } + }; + + template + struct SpacePolicy { + static void* Allocate(AllocationHandle& handle, size_t size) { + // Default space. + return MakeGarbageCollectedTraitInternal::Allocate( + handle, size, internal::GCInfoTrait::Index()); + } + }; + + private: static void* Allocate(cppgc::AllocationHandle& handle, size_t size, GCInfoIndex index); static void* Allocate(cppgc::AllocationHandle& handle, size_t size, @@ -71,27 +93,6 @@ class MakeGarbageCollectedTraitBase internal::api_constants::kLargeObjectSizeThreshold, "GarbageCollectedMixin may not be a large object"); - template - struct SpacePolicy { - static void* Allocate(AllocationHandle& handle, size_t size) { - // Custom space. - static_assert(std::is_base_of::value, - "Custom space must inherit from CustomSpaceBase."); - return internal::MakeGarbageCollectedTraitInternal::Allocate( - handle, size, internal::GCInfoTrait::Index(), - CustomSpace::kSpaceIndex); - } - }; - - template - struct SpacePolicy { - static void* Allocate(AllocationHandle& handle, size_t size) { - // Default space. - return internal::MakeGarbageCollectedTraitInternal::Allocate( - handle, size, internal::GCInfoTrait::Index()); - } - }; - protected: /** * Allocates memory for an object of type T. @@ -101,7 +102,7 @@ class MakeGarbageCollectedTraitBase * \param size The size that should be reserved for the object. * \returns the memory to construct an object of type T on. */ - static void* Allocate(AllocationHandle& handle, size_t size) { + V8_INLINE static void* Allocate(AllocationHandle& handle, size_t size) { return SpacePolicy< typename internal::GCInfoFolding< T, typename T::ParentMostGarbageCollectedType>::ResultType, @@ -114,7 +115,7 @@ class MakeGarbageCollectedTraitBase * * \param payload The base pointer the object is allocated at. */ - static void MarkObjectAsFullyConstructed(const void* payload) { + V8_INLINE static void MarkObjectAsFullyConstructed(const void* payload) { internal::MakeGarbageCollectedTraitInternal::MarkObjectAsFullyConstructed( payload); }