[K/N] Create ObjectFactory only w/o custom allocator ^KT-55364

This commit is contained in:
Alexander Shabalin
2023-04-11 13:56:32 +02:00
committed by Space Cloud
parent cb7698a8c2
commit 63231f7b73
6 changed files with 49 additions and 1 deletions
@@ -119,6 +119,17 @@ void CustomAllocator::PrepareForGC() noexcept {
extraObjectPage_ = nullptr;
}
// static
size_t CustomAllocator::GetAllocatedHeapSize(ObjHeader* object) noexcept {
RuntimeAssert(object->heap(), "Object must be a heap object");
const auto* typeInfo = object->type_info();
if (typeInfo->IsArray()) {
return ArrayAllocatedDataSize(typeInfo, object->array()->count_);
} else {
return ObjectAllocatedDataSize(typeInfo);
}
}
uint8_t* CustomAllocator::Allocate(uint64_t size) noexcept {
gcScheduler_.OnSafePointAllocation(size);
CustomAllocDebug("CustomAllocator::Allocate(%" PRIu64 ")", size);
@@ -34,6 +34,8 @@ public:
void PrepareForGC() noexcept;
static size_t GetAllocatedHeapSize(ObjHeader* object) noexcept;
private:
uint8_t* Allocate(uint64_t cellCount) noexcept;
uint8_t* AllocateInSingleObjectPage(uint64_t cellCount) noexcept;
@@ -105,13 +105,14 @@ NO_EXTERNAL_CALLS_CHECK void gc::ConcurrentMarkAndSweep::ThreadData::OnSuspendFo
gc::Mark<internal::MarkTraits>(handle, markQueue);
}
#ifndef CUSTOM_ALLOCATOR
gc::ConcurrentMarkAndSweep::ConcurrentMarkAndSweep(
mm::ObjectFactory<ConcurrentMarkAndSweep>& objectFactory, GCScheduler& gcScheduler) noexcept :
#ifndef CUSTOM_ALLOCATOR
objectFactory_(objectFactory),
gcScheduler_(gcScheduler),
finalizerProcessor_(std_support::make_unique<FinalizerProcessor>([this](int64_t epoch) {
#else
gc::ConcurrentMarkAndSweep::ConcurrentMarkAndSweep(GCScheduler& gcScheduler) noexcept :
gcScheduler_(gcScheduler), finalizerProcessor_(std_support::make_unique<alloc::CustomFinalizerProcessor>([this](int64_t epoch) {
#endif
GCHandle::getByEpoch(epoch).finalizersDone();
@@ -108,7 +108,11 @@ public:
using Allocator = ThreadData::Allocator;
#ifdef CUSTOM_ALLOCATOR
explicit ConcurrentMarkAndSweep(GCScheduler& scheduler) noexcept;
#else
ConcurrentMarkAndSweep(mm::ObjectFactory<ConcurrentMarkAndSweep>& objectFactory, GCScheduler& scheduler) noexcept;
#endif
~ConcurrentMarkAndSweep();
void StartFinalizerThreadIfNeeded() noexcept;
@@ -88,21 +88,41 @@ gc::GC::~GC() = default;
// static
size_t gc::GC::GetAllocatedHeapSize(ObjHeader* object) noexcept {
#ifdef CUSTOM_ALLOCATOR
return alloc::CustomAllocator::GetAllocatedHeapSize(object);
#else
return mm::ObjectFactory<GCImpl>::GetAllocatedHeapSize(object);
#endif
}
size_t gc::GC::GetHeapObjectsCountUnsafe() const noexcept {
#ifndef CUSTOM_ALLOCATOR
return impl_->objectFactory().GetObjectsCountUnsafe();
#else
return 0;
#endif
}
size_t gc::GC::GetTotalHeapObjectsSizeUnsafe() const noexcept {
#ifndef CUSTOM_ALLOCATOR
return impl_->objectFactory().GetTotalObjectsSizeUnsafe();
#else
return 0;
#endif
}
size_t gc::GC::GetExtraObjectsCountUnsafe() const noexcept {
#ifndef CUSTOM_ALLOCATOR
return mm::GlobalData::Instance().extraObjectDataFactory().GetSizeUnsafe();
#else
return 0;
#endif
}
size_t gc::GC::GetTotalExtraObjectsSizeUnsafe() const noexcept {
#ifndef CUSTOM_ALLOCATOR
return mm::GlobalData::Instance().extraObjectDataFactory().GetTotalObjectsSizeUnsafe();
#else
return 0;
#endif
}
size_t gc::GC::GetTotalHeapObjectsSizeBytes() const noexcept {
@@ -115,7 +135,9 @@ gc::GCSchedulerConfig& gc::GC::gcSchedulerConfig() noexcept {
void gc::GC::ClearForTests() noexcept {
impl_->gc().StopFinalizerThreadIfRunning();
#ifndef CUSTOM_ALLOCATOR
impl_->objectFactory().ClearForTests();
#endif
GCHandle::ClearForTests();
}
@@ -20,14 +20,22 @@ using GCImpl = ConcurrentMarkAndSweep;
class GC::Impl : private Pinned {
public:
#ifdef CUSTOM_ALLOCATOR
Impl() noexcept : gc_(gcScheduler_) {}
#else
Impl() noexcept : gc_(objectFactory_, gcScheduler_) {}
#endif
#ifndef CUSTOM_ALLOCATOR
mm::ObjectFactory<gc::GCImpl>& objectFactory() noexcept { return objectFactory_; }
#endif
GCScheduler& gcScheduler() noexcept { return gcScheduler_; }
GCImpl& gc() noexcept { return gc_; }
private:
#ifndef CUSTOM_ALLOCATOR
mm::ObjectFactory<gc::GCImpl> objectFactory_;
#endif
GCScheduler gcScheduler_;
GCImpl gc_;
};