Commit 03cea711 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: Fix GC traits and add documentation

- Adds IsGarbageCollectedWithMixin<T> to check for mixin applications.
- Add documentation to all trait values.

Bug: chromium:1056170
Change-Id: I22c255c36c791a5ff9b38d034f205f1e23c968ca
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2644951Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72268}
parent b7a30f18
...@@ -156,7 +156,7 @@ class MakeGarbageCollectedTrait : public MakeGarbageCollectedTraitBase<T> { ...@@ -156,7 +156,7 @@ class MakeGarbageCollectedTrait : public MakeGarbageCollectedTraitBase<T> {
static_assert(internal::IsGarbageCollectedType<T>::value, static_assert(internal::IsGarbageCollectedType<T>::value,
"T needs to be a garbage collected object"); "T needs to be a garbage collected object");
static_assert( static_assert(
!internal::IsGarbageCollectedMixinType<T>::value || !IsGarbageCollectedWithMixinTypeV<T> ||
sizeof(T) <= internal::api_constants::kLargeObjectSizeThreshold, sizeof(T) <= internal::api_constants::kLargeObjectSizeThreshold,
"GarbageCollectedMixin may not be a large object"); "GarbageCollectedMixin may not be a large object");
void* memory = void* memory =
...@@ -172,7 +172,7 @@ class MakeGarbageCollectedTrait : public MakeGarbageCollectedTraitBase<T> { ...@@ -172,7 +172,7 @@ class MakeGarbageCollectedTrait : public MakeGarbageCollectedTraitBase<T> {
static_assert(internal::IsGarbageCollectedType<T>::value, static_assert(internal::IsGarbageCollectedType<T>::value,
"T needs to be a garbage collected object"); "T needs to be a garbage collected object");
static_assert( static_assert(
!internal::IsGarbageCollectedMixinType<T>::value || !IsGarbageCollectedWithMixinTypeV<T> ||
sizeof(T) <= internal::api_constants::kLargeObjectSizeThreshold, sizeof(T) <= internal::api_constants::kLargeObjectSizeThreshold,
"GarbageCollectedMixin may not be a large object"); "GarbageCollectedMixin may not be a large object");
void* memory = MakeGarbageCollectedTraitBase<T>::Allocate( void* memory = MakeGarbageCollectedTraitBase<T>::Allocate(
......
...@@ -117,6 +117,17 @@ struct IsGarbageCollectedOrMixinType ...@@ -117,6 +117,17 @@ struct IsGarbageCollectedOrMixinType
static_assert(sizeof(T), "T must be fully defined"); static_assert(sizeof(T), "T must be fully defined");
}; };
template <typename T, bool = (HasGarbageCollectedTypeMarker<T>::value &&
HasGarbageCollectedMixinTypeMarker<T>::value)>
struct IsGarbageCollectedWithMixinType : std::false_type {
static_assert(sizeof(T), "T must be fully defined");
};
template <typename T>
struct IsGarbageCollectedWithMixinType<T, true> : std::true_type {
static_assert(sizeof(T), "T must be fully defined");
};
template <typename BasicMemberCandidate, typename WeaknessTag, template <typename BasicMemberCandidate, typename WeaknessTag,
typename WriteBarrierPolicy> typename WriteBarrierPolicy>
struct IsSubclassOfBasicMemberTemplate { struct IsSubclassOfBasicMemberTemplate {
...@@ -155,21 +166,60 @@ struct IsUntracedMemberType<T, true> : std::true_type {}; ...@@ -155,21 +166,60 @@ struct IsUntracedMemberType<T, true> : std::true_type {};
} // namespace internal } // namespace internal
/**
* Value is true for types that inherit from `GarbageCollectedMixin` but not
* `GarbageCollected<T>` (i.e., they are free mixins), and false otherwise.
*/
template <typename T> template <typename T>
constexpr bool IsGarbageCollectedMixinTypeV = constexpr bool IsGarbageCollectedMixinTypeV =
internal::IsGarbageCollectedMixinType<T>::value; internal::IsGarbageCollectedMixinType<T>::value;
/**
* Value is true for types that inherit from `GarbageCollected<T>`, and false
* otherwise.
*/
template <typename T> template <typename T>
constexpr bool IsGarbageCollectedTypeV = constexpr bool IsGarbageCollectedTypeV =
internal::IsGarbageCollectedType<T>::value; internal::IsGarbageCollectedType<T>::value;
/**
* Value is true for types that inherit from either `GarbageCollected<T>` or
* `GarbageCollectedMixin`, and false otherwise.
*/
template <typename T> template <typename T>
constexpr bool IsGarbageCollectedOrMixinTypeV = constexpr bool IsGarbageCollectedOrMixinTypeV =
internal::IsGarbageCollectedOrMixinType<T>::value; internal::IsGarbageCollectedOrMixinType<T>::value;
/**
* Value is true for types that inherit from `GarbageCollected<T>` and
* `GarbageCollectedMixin`, and false otherwise.
*/
template <typename T>
constexpr bool IsGarbageCollectedWithMixinTypeV =
internal::IsGarbageCollectedWithMixinType<T>::value;
/**
* Value is true for types of type `Member<T>`, and false otherwise.
*/
template <typename T> template <typename T>
constexpr bool IsMemberTypeV = internal::IsMemberType<T>::value; constexpr bool IsMemberTypeV = internal::IsMemberType<T>::value;
/**
* Value is true for types of type `UntracedMember<T>`, and false otherwise.
*/
template <typename T> template <typename T>
constexpr bool IsUntracedMemberTypeV = internal::IsUntracedMemberType<T>::value; constexpr bool IsUntracedMemberTypeV = internal::IsUntracedMemberType<T>::value;
/**
* Value is true for types of type `WeakMember<T>`, and false otherwise.
*/
template <typename T> template <typename T>
constexpr bool IsWeakMemberTypeV = internal::IsWeakMemberType<T>::value; constexpr bool IsWeakMemberTypeV = internal::IsWeakMemberType<T>::value;
/**
* Value is true for types that are considered weak references, and false
* otherwise.
*/
template <typename T> template <typename T>
constexpr bool IsWeakV = internal::IsWeak<T>::value; constexpr bool IsWeakV = internal::IsWeak<T>::value;
......
...@@ -44,33 +44,43 @@ class GarbageCollectedTestWithHeap ...@@ -44,33 +44,43 @@ class GarbageCollectedTestWithHeap
} // namespace } // namespace
TEST(GarbageCollectedTest, GarbageCollectedTrait) { TEST(GarbageCollectedTest, GarbageCollectedTrait) {
STATIC_ASSERT(!IsGarbageCollectedType<int>::value); STATIC_ASSERT(!IsGarbageCollectedTypeV<int>);
STATIC_ASSERT(!IsGarbageCollectedType<NotGCed>::value); STATIC_ASSERT(!IsGarbageCollectedTypeV<NotGCed>);
STATIC_ASSERT(IsGarbageCollectedType<GCed>::value); STATIC_ASSERT(IsGarbageCollectedTypeV<GCed>);
STATIC_ASSERT(!IsGarbageCollectedType<Mixin>::value); STATIC_ASSERT(!IsGarbageCollectedTypeV<Mixin>);
STATIC_ASSERT(IsGarbageCollectedType<GCedWithMixin>::value); STATIC_ASSERT(IsGarbageCollectedTypeV<GCedWithMixin>);
STATIC_ASSERT(!IsGarbageCollectedType<MergedMixins>::value); STATIC_ASSERT(!IsGarbageCollectedTypeV<MergedMixins>);
STATIC_ASSERT(IsGarbageCollectedType<GCWithMergedMixins>::value); STATIC_ASSERT(IsGarbageCollectedTypeV<GCWithMergedMixins>);
} }
TEST(GarbageCollectedTest, GarbageCollectedMixinTrait) { TEST(GarbageCollectedTest, GarbageCollectedMixinTrait) {
STATIC_ASSERT(!IsGarbageCollectedMixinType<int>::value); STATIC_ASSERT(!IsGarbageCollectedMixinTypeV<int>);
STATIC_ASSERT(!IsGarbageCollectedMixinType<GCed>::value); STATIC_ASSERT(!IsGarbageCollectedMixinTypeV<GCed>);
STATIC_ASSERT(!IsGarbageCollectedMixinType<NotGCed>::value); STATIC_ASSERT(!IsGarbageCollectedMixinTypeV<NotGCed>);
STATIC_ASSERT(IsGarbageCollectedMixinType<Mixin>::value); STATIC_ASSERT(IsGarbageCollectedMixinTypeV<Mixin>);
STATIC_ASSERT(!IsGarbageCollectedMixinType<GCedWithMixin>::value); STATIC_ASSERT(!IsGarbageCollectedMixinTypeV<GCedWithMixin>);
STATIC_ASSERT(IsGarbageCollectedMixinType<MergedMixins>::value); STATIC_ASSERT(IsGarbageCollectedMixinTypeV<MergedMixins>);
STATIC_ASSERT(!IsGarbageCollectedMixinType<GCWithMergedMixins>::value); STATIC_ASSERT(!IsGarbageCollectedMixinTypeV<GCWithMergedMixins>);
} }
TEST(GarbageCollectedTest, GarbageCollectedOrMixinTrait) { TEST(GarbageCollectedTest, GarbageCollectedOrMixinTrait) {
STATIC_ASSERT(!IsGarbageCollectedOrMixinType<int>::value); STATIC_ASSERT(!IsGarbageCollectedOrMixinTypeV<int>);
STATIC_ASSERT(IsGarbageCollectedOrMixinType<GCed>::value); STATIC_ASSERT(IsGarbageCollectedOrMixinTypeV<GCed>);
STATIC_ASSERT(!IsGarbageCollectedOrMixinType<NotGCed>::value); STATIC_ASSERT(!IsGarbageCollectedOrMixinTypeV<NotGCed>);
STATIC_ASSERT(IsGarbageCollectedOrMixinType<Mixin>::value); STATIC_ASSERT(IsGarbageCollectedOrMixinTypeV<Mixin>);
STATIC_ASSERT(IsGarbageCollectedOrMixinType<GCedWithMixin>::value); STATIC_ASSERT(IsGarbageCollectedOrMixinTypeV<GCedWithMixin>);
STATIC_ASSERT(IsGarbageCollectedOrMixinType<MergedMixins>::value); STATIC_ASSERT(IsGarbageCollectedOrMixinTypeV<MergedMixins>);
STATIC_ASSERT(IsGarbageCollectedOrMixinType<GCWithMergedMixins>::value); STATIC_ASSERT(IsGarbageCollectedOrMixinTypeV<GCWithMergedMixins>);
}
TEST(GarbageCollectedTest, GarbageCollectedWithMixinTrait) {
STATIC_ASSERT(!IsGarbageCollectedWithMixinTypeV<int>);
STATIC_ASSERT(!IsGarbageCollectedWithMixinTypeV<GCed>);
STATIC_ASSERT(!IsGarbageCollectedWithMixinTypeV<NotGCed>);
STATIC_ASSERT(!IsGarbageCollectedWithMixinTypeV<Mixin>);
STATIC_ASSERT(IsGarbageCollectedWithMixinTypeV<GCedWithMixin>);
STATIC_ASSERT(!IsGarbageCollectedWithMixinTypeV<MergedMixins>);
STATIC_ASSERT(IsGarbageCollectedWithMixinTypeV<GCWithMergedMixins>);
} }
TEST_F(GarbageCollectedTestWithHeap, GetObjectStartReturnsCurrentAddress) { TEST_F(GarbageCollectedTestWithHeap, GetObjectStartReturnsCurrentAddress) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment