[K/N] Create ObjectFactory only w/o custom allocator ^KT-55364
This commit is contained in:
committed by
Space Cloud
parent
cb7698a8c2
commit
63231f7b73
@@ -119,6 +119,17 @@ void CustomAllocator::PrepareForGC() noexcept {
|
|||||||
extraObjectPage_ = nullptr;
|
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 {
|
uint8_t* CustomAllocator::Allocate(uint64_t size) noexcept {
|
||||||
gcScheduler_.OnSafePointAllocation(size);
|
gcScheduler_.OnSafePointAllocation(size);
|
||||||
CustomAllocDebug("CustomAllocator::Allocate(%" PRIu64 ")", size);
|
CustomAllocDebug("CustomAllocator::Allocate(%" PRIu64 ")", size);
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public:
|
|||||||
|
|
||||||
void PrepareForGC() noexcept;
|
void PrepareForGC() noexcept;
|
||||||
|
|
||||||
|
static size_t GetAllocatedHeapSize(ObjHeader* object) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t* Allocate(uint64_t cellCount) noexcept;
|
uint8_t* Allocate(uint64_t cellCount) noexcept;
|
||||||
uint8_t* AllocateInSingleObjectPage(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);
|
gc::Mark<internal::MarkTraits>(handle, markQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef CUSTOM_ALLOCATOR
|
||||||
gc::ConcurrentMarkAndSweep::ConcurrentMarkAndSweep(
|
gc::ConcurrentMarkAndSweep::ConcurrentMarkAndSweep(
|
||||||
mm::ObjectFactory<ConcurrentMarkAndSweep>& objectFactory, GCScheduler& gcScheduler) noexcept :
|
mm::ObjectFactory<ConcurrentMarkAndSweep>& objectFactory, GCScheduler& gcScheduler) noexcept :
|
||||||
#ifndef CUSTOM_ALLOCATOR
|
|
||||||
objectFactory_(objectFactory),
|
objectFactory_(objectFactory),
|
||||||
gcScheduler_(gcScheduler),
|
gcScheduler_(gcScheduler),
|
||||||
finalizerProcessor_(std_support::make_unique<FinalizerProcessor>([this](int64_t epoch) {
|
finalizerProcessor_(std_support::make_unique<FinalizerProcessor>([this](int64_t epoch) {
|
||||||
#else
|
#else
|
||||||
|
gc::ConcurrentMarkAndSweep::ConcurrentMarkAndSweep(GCScheduler& gcScheduler) noexcept :
|
||||||
gcScheduler_(gcScheduler), finalizerProcessor_(std_support::make_unique<alloc::CustomFinalizerProcessor>([this](int64_t epoch) {
|
gcScheduler_(gcScheduler), finalizerProcessor_(std_support::make_unique<alloc::CustomFinalizerProcessor>([this](int64_t epoch) {
|
||||||
#endif
|
#endif
|
||||||
GCHandle::getByEpoch(epoch).finalizersDone();
|
GCHandle::getByEpoch(epoch).finalizersDone();
|
||||||
|
|||||||
@@ -108,7 +108,11 @@ public:
|
|||||||
|
|
||||||
using Allocator = ThreadData::Allocator;
|
using Allocator = ThreadData::Allocator;
|
||||||
|
|
||||||
|
#ifdef CUSTOM_ALLOCATOR
|
||||||
|
explicit ConcurrentMarkAndSweep(GCScheduler& scheduler) noexcept;
|
||||||
|
#else
|
||||||
ConcurrentMarkAndSweep(mm::ObjectFactory<ConcurrentMarkAndSweep>& objectFactory, GCScheduler& scheduler) noexcept;
|
ConcurrentMarkAndSweep(mm::ObjectFactory<ConcurrentMarkAndSweep>& objectFactory, GCScheduler& scheduler) noexcept;
|
||||||
|
#endif
|
||||||
~ConcurrentMarkAndSweep();
|
~ConcurrentMarkAndSweep();
|
||||||
|
|
||||||
void StartFinalizerThreadIfNeeded() noexcept;
|
void StartFinalizerThreadIfNeeded() noexcept;
|
||||||
|
|||||||
@@ -88,21 +88,41 @@ gc::GC::~GC() = default;
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
size_t gc::GC::GetAllocatedHeapSize(ObjHeader* object) noexcept {
|
size_t gc::GC::GetAllocatedHeapSize(ObjHeader* object) noexcept {
|
||||||
|
#ifdef CUSTOM_ALLOCATOR
|
||||||
|
return alloc::CustomAllocator::GetAllocatedHeapSize(object);
|
||||||
|
#else
|
||||||
return mm::ObjectFactory<GCImpl>::GetAllocatedHeapSize(object);
|
return mm::ObjectFactory<GCImpl>::GetAllocatedHeapSize(object);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t gc::GC::GetHeapObjectsCountUnsafe() const noexcept {
|
size_t gc::GC::GetHeapObjectsCountUnsafe() const noexcept {
|
||||||
|
#ifndef CUSTOM_ALLOCATOR
|
||||||
return impl_->objectFactory().GetObjectsCountUnsafe();
|
return impl_->objectFactory().GetObjectsCountUnsafe();
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
size_t gc::GC::GetTotalHeapObjectsSizeUnsafe() const noexcept {
|
size_t gc::GC::GetTotalHeapObjectsSizeUnsafe() const noexcept {
|
||||||
|
#ifndef CUSTOM_ALLOCATOR
|
||||||
return impl_->objectFactory().GetTotalObjectsSizeUnsafe();
|
return impl_->objectFactory().GetTotalObjectsSizeUnsafe();
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
size_t gc::GC::GetExtraObjectsCountUnsafe() const noexcept {
|
size_t gc::GC::GetExtraObjectsCountUnsafe() const noexcept {
|
||||||
|
#ifndef CUSTOM_ALLOCATOR
|
||||||
return mm::GlobalData::Instance().extraObjectDataFactory().GetSizeUnsafe();
|
return mm::GlobalData::Instance().extraObjectDataFactory().GetSizeUnsafe();
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
size_t gc::GC::GetTotalExtraObjectsSizeUnsafe() const noexcept {
|
size_t gc::GC::GetTotalExtraObjectsSizeUnsafe() const noexcept {
|
||||||
|
#ifndef CUSTOM_ALLOCATOR
|
||||||
return mm::GlobalData::Instance().extraObjectDataFactory().GetTotalObjectsSizeUnsafe();
|
return mm::GlobalData::Instance().extraObjectDataFactory().GetTotalObjectsSizeUnsafe();
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t gc::GC::GetTotalHeapObjectsSizeBytes() const noexcept {
|
size_t gc::GC::GetTotalHeapObjectsSizeBytes() const noexcept {
|
||||||
@@ -115,7 +135,9 @@ gc::GCSchedulerConfig& gc::GC::gcSchedulerConfig() noexcept {
|
|||||||
|
|
||||||
void gc::GC::ClearForTests() noexcept {
|
void gc::GC::ClearForTests() noexcept {
|
||||||
impl_->gc().StopFinalizerThreadIfRunning();
|
impl_->gc().StopFinalizerThreadIfRunning();
|
||||||
|
#ifndef CUSTOM_ALLOCATOR
|
||||||
impl_->objectFactory().ClearForTests();
|
impl_->objectFactory().ClearForTests();
|
||||||
|
#endif
|
||||||
GCHandle::ClearForTests();
|
GCHandle::ClearForTests();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,22 @@ using GCImpl = ConcurrentMarkAndSweep;
|
|||||||
|
|
||||||
class GC::Impl : private Pinned {
|
class GC::Impl : private Pinned {
|
||||||
public:
|
public:
|
||||||
|
#ifdef CUSTOM_ALLOCATOR
|
||||||
|
Impl() noexcept : gc_(gcScheduler_) {}
|
||||||
|
#else
|
||||||
Impl() noexcept : gc_(objectFactory_, gcScheduler_) {}
|
Impl() noexcept : gc_(objectFactory_, gcScheduler_) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CUSTOM_ALLOCATOR
|
||||||
mm::ObjectFactory<gc::GCImpl>& objectFactory() noexcept { return objectFactory_; }
|
mm::ObjectFactory<gc::GCImpl>& objectFactory() noexcept { return objectFactory_; }
|
||||||
|
#endif
|
||||||
GCScheduler& gcScheduler() noexcept { return gcScheduler_; }
|
GCScheduler& gcScheduler() noexcept { return gcScheduler_; }
|
||||||
GCImpl& gc() noexcept { return gc_; }
|
GCImpl& gc() noexcept { return gc_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifndef CUSTOM_ALLOCATOR
|
||||||
mm::ObjectFactory<gc::GCImpl> objectFactory_;
|
mm::ObjectFactory<gc::GCImpl> objectFactory_;
|
||||||
|
#endif
|
||||||
GCScheduler gcScheduler_;
|
GCScheduler gcScheduler_;
|
||||||
GCImpl gc_;
|
GCImpl gc_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user