[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.
This commit is contained in:
committed by
Space Cloud
parent
2a41b80373
commit
3ae7b790a9
@@ -8,10 +8,11 @@
|
||||
#include <random>
|
||||
|
||||
#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<uint64_t*>(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*>(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<size_t>(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<size_t>(BLOCKSIZE * 8));
|
||||
mark(obj); // to make the page survive a sweep
|
||||
heap.PrepareForGC();
|
||||
auto gcHandle = kotlin::gc::GCHandle::createFakeForTests();
|
||||
|
||||
Reference in New Issue
Block a user