chromium/v8/test/unittests/heap/cppgc/allocation-unittest.cc

// Copyright 2021 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/visitor.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap-object-header.h"
#include "test/unittests/heap/cppgc/tests.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cppgc {
namespace internal {

namespace {

class CppgcAllocationTest : public testing::TestWithHeap {};

struct GCed final : GarbageCollected<GCed> {};

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

}  // namespace

TEST_F(CppgcAllocationTest, MakeGarbageCollectedPreservesPayload) {}

TEST_F(CppgcAllocationTest, ReuseMemoryFromFreelist) {}

namespace {
class CallbackInCtor final : public GarbageCollected<CallbackInCtor> {};
}  // namespace

TEST_F(CppgcAllocationTest,
       ConservativeGCDuringAllocationDoesNotReclaimObject) {}

// The test below requires that a large object is reused in the GC. This only
// reliably works on 64-bit builds using caged heap. On 32-bit builds large
// objects are mapped in individually and returned to the OS as a whole on
// reclamation.
#if defined(CPPGC_CAGED_HEAP)

namespace {
class LargeObjectCheckingPayloadForZeroMemory final
    : public GarbageCollected<LargeObjectCheckingPayloadForZeroMemory> {};
size_t LargeObjectCheckingPayloadForZeroMemory::destructor_calls =;
}  // namespace

TEST_F(CppgcAllocationTest, LargePagesAreZeroedOut) {}

#endif  // defined(CPPGC_CAGED_HEAP)

namespace {

constexpr size_t kDoubleWord =;
constexpr size_t kWord =;

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

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

template <size_t Size>
class CustomPadding final : public GarbageCollected<CustomPadding<Size>> {};

template <size_t Size>
class alignas(kDoubleWord) AlignedCustomPadding final
    : public GarbageCollected<AlignedCustomPadding<Size>> {};

}  // namespace

TEST_F(CppgcAllocationTest, DoubleWordAlignedAllocation) {}

TEST_F(CppgcAllocationTest, LargeDoubleWordAlignedAllocation) {}

TEST_F(CppgcAllocationTest, AlignToDoubleWordFromUnaligned) {}

TEST_F(CppgcAllocationTest, AlignToDoubleWordFromAligned) {}

}  // namespace internal
}  // namespace cppgc