chromium/v8/test/unittests/heap/cppgc/custom-spaces-unittest.cc

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "include/cppgc/allocation.h"
#include "include/cppgc/custom-space.h"
#include "src/heap/cppgc/heap-page.h"
#include "src/heap/cppgc/raw-heap.h"
#include "test/unittests/heap/cppgc/tests.h"

namespace cppgc {

class CustomSpace1 : public CustomSpace<CustomSpace1> {};

class CustomSpace2 : public CustomSpace<CustomSpace2> {};

namespace internal {

namespace {

size_t g_destructor_callcount;

class TestWithHeapWithCustomSpaces : public testing::TestWithPlatform {};

class RegularGCed final : public GarbageCollected<RegularGCed> {};

class CustomGCed1 final : public GarbageCollected<CustomGCed1> {};
class CustomGCed2 final : public GarbageCollected<CustomGCed2> {};

class CustomGCedBase : public GarbageCollected<CustomGCedBase> {};
class CustomGCedFinal1 final : public CustomGCedBase {};
class CustomGCedFinal2 final : public CustomGCedBase {};

constexpr size_t kDoubleWord =;

class alignas(kDoubleWord) CustomGCedWithDoubleWordAlignment final
    : public GarbageCollected<CustomGCedWithDoubleWordAlignment> {};

}  // namespace

}  // namespace internal

template <>
struct SpaceTrait<internal::CustomGCed1> {};

template <>
struct SpaceTrait<internal::CustomGCed2> {};

SpaceTrait<T, std::enable_if_t<std::is_base_of<internal::CustomGCedBase, T>::value>>;

template <>
struct SpaceTrait<internal::CustomGCedWithDoubleWordAlignment> {};

namespace internal {

TEST_F(TestWithHeapWithCustomSpaces, AllocateOnCustomSpaces) {}

TEST_F(TestWithHeapWithCustomSpaces, AllocateDoubleWordAlignedOnCustomSpace) {}

TEST_F(TestWithHeapWithCustomSpaces, DifferentSpacesUsesDifferentPages) {}

TEST_F(TestWithHeapWithCustomSpaces,
       AllocateOnCustomSpacesSpecifiedThroughBase) {}

TEST_F(TestWithHeapWithCustomSpaces, SweepCustomSpace) {}

}  // namespace internal

// Test custom space compactability.

class CompactableCustomSpace : public CustomSpace<CompactableCustomSpace> {};

class NotCompactableCustomSpace
    : public CustomSpace<NotCompactableCustomSpace> {};

class DefaultCompactableCustomSpace
    : public CustomSpace<DefaultCompactableCustomSpace> {};

namespace internal {
namespace {

class TestWithHeapWithCompactableCustomSpaces
    : public testing::TestWithPlatform {};

class CompactableGCed final : public GarbageCollected<CompactableGCed> {};
class NotCompactableGCed final : public GarbageCollected<NotCompactableGCed> {};
class DefaultCompactableGCed final
    : public GarbageCollected<DefaultCompactableGCed> {};

}  // namespace
}  // namespace internal

template <>
struct SpaceTrait<internal::CompactableGCed> {};
template <>
struct SpaceTrait<internal::NotCompactableGCed> {};
template <>
struct SpaceTrait<internal::DefaultCompactableGCed> {};

namespace internal {

TEST_F(TestWithHeapWithCompactableCustomSpaces,
       AllocateOnCompactableCustomSpaces) {}

}  // namespace internal

}  // namespace cppgc