From 3ae7b790a9b1070d6c75149962f3f8842ec6a2b6 Mon Sep 17 00:00:00 2001 From: Troels Bjerre Lund Date: Mon, 2 Oct 2023 14:39:12 +0200 Subject: [PATCH] [K/N] Update HeapTest This adds TypeInfo to the objects allocated in HeapTest, which is now needed by SweepObject to gather problem live set statistics. --- .../runtime/src/alloc/custom/cpp/HeapTest.cpp | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/kotlin-native/runtime/src/alloc/custom/cpp/HeapTest.cpp b/kotlin-native/runtime/src/alloc/custom/cpp/HeapTest.cpp index 4b614cf69ea..975bd21ec39 100644 --- a/kotlin-native/runtime/src/alloc/custom/cpp/HeapTest.cpp +++ b/kotlin-native/runtime/src/alloc/custom/cpp/HeapTest.cpp @@ -8,10 +8,11 @@ #include #include "ExtraObjectPage.hpp" +#include "FixedBlockPage.hpp" +#include "GCApi.hpp" +#include "Heap.hpp" #include "SingleObjectPage.hpp" #include "gtest/gtest.h" -#include "Heap.hpp" -#include "FixedBlockPage.hpp" namespace { @@ -26,15 +27,29 @@ void mark(void* obj) { reinterpret_cast(obj)[0] = 1; } +size_t installType(uint8_t* obj, TypeInfo* typeInfo) { + auto descriptor = kotlin::alloc::HeapObject::make_descriptor(typeInfo); + auto& heapObject = *descriptor.construct(obj); + ObjHeader* object = heapObject.header(descriptor).object(); + object->typeInfoOrMeta_ = const_cast(typeInfo); + return descriptor.size(); +} + TEST(CustomAllocTest, HeapReuseFixedBlockPages) { Heap heap; const int MIN = MIN_BLOCK_SIZE; const int MAX = FIXED_BLOCK_PAGE_MAX_BLOCK_SIZE + 1; + TypeInfo fakeTypes[MAX]; + for (int i = MIN; i < MAX; ++i) { + fakeTypes[i] = {.typeInfo_ = &fakeTypes[i], .instanceSize_ = 8 * (i - 1), .flags_ = 0}; + } FixedBlockPage* pages[MAX]; kotlin::alloc::FinalizerQueue finalizerQueue; for (int blocks = MIN; blocks < MAX; ++blocks) { pages[blocks] = heap.GetFixedBlockPage(blocks, finalizerQueue); - void* obj = pages[blocks]->TryAllocate(); + uint8_t* obj = pages[blocks]->TryAllocate(); + size_t size = installType(obj, &fakeTypes[blocks]); + EXPECT_EQ(size, static_cast(blocks * 8)); mark(obj); // to make the page survive a sweep } heap.PrepareForGC(); @@ -50,7 +65,10 @@ TEST(CustomAllocTest, HeapReuseNextFitPages) { const uint32_t BLOCKSIZE = FIXED_BLOCK_PAGE_MAX_BLOCK_SIZE + 42; kotlin::alloc::FinalizerQueue finalizerQueue; NextFitPage* page = heap.GetNextFitPage(BLOCKSIZE, finalizerQueue); - void* obj = page->TryAllocate(BLOCKSIZE); + uint8_t* obj = page->TryAllocate(BLOCKSIZE); + TypeInfo fakeType = {.typeInfo_ = &fakeType, .instanceSize_ = 8 * (BLOCKSIZE - 1), .flags_ = 0}; + size_t size = installType(obj, &fakeType); + EXPECT_EQ(size, static_cast(BLOCKSIZE * 8)); mark(obj); // to make the page survive a sweep heap.PrepareForGC(); auto gcHandle = kotlin::gc::GCHandle::createFakeForTests();