1fa0ef6f56
- Move std_alloc, opt_alloc and custom_alloc into alloc/std, alloc/mimalloc and alloc/custom to mirror convention of gc, gcScheduler modules. - Add alloc/common with common allocator API - Add alloc/legacy with common implementation details of alloc/std and alloc/mimalloc. alloc/custom does not depend on alloc/legacy. - Removes experimental_memory_manager_custom as it's now unused - Additionally, renames experimental_memory_manager module into mm
75 lines
2.1 KiB
C++
75 lines
2.1 KiB
C++
/*
|
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
* that can be found in the LICENSE file.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifdef CUSTOM_ALLOCATOR
|
|
|
|
// TODO: Move into alloc/custom/AllocatorImpl.hpp
|
|
|
|
#include "CustomAllocator.hpp"
|
|
#include "CustomFinalizerProcessor.hpp"
|
|
#include "GCApi.hpp"
|
|
#include "Heap.hpp"
|
|
|
|
namespace kotlin::gc {
|
|
|
|
inline GC::ObjectData& objectDataForObject(ObjHeader* object) noexcept {
|
|
return kotlin::alloc::objectDataForObject(object);
|
|
}
|
|
|
|
inline ObjHeader* objectForObjectData(GC::ObjectData& objectData) noexcept {
|
|
return kotlin::alloc::objectForObjectData(objectData);
|
|
}
|
|
|
|
using FinalizerQueue = alloc::FinalizerQueue;
|
|
using FinalizerQueueTraits = alloc::FinalizerQueueTraits;
|
|
|
|
} // namespace kotlin::gc
|
|
|
|
#else
|
|
|
|
// TODO: Move into alloc/legacy/AllocatorImpl.hpp
|
|
|
|
#include "ExtraObjectDataFactory.hpp"
|
|
#include "GC.hpp"
|
|
#include "GlobalData.hpp"
|
|
#include "Logging.hpp"
|
|
#include "ObjectFactory.hpp"
|
|
#include "ObjectFactoryAllocator.hpp"
|
|
#include "ObjectFactorySweep.hpp"
|
|
|
|
namespace kotlin::gc {
|
|
|
|
struct ObjectFactoryTraits {
|
|
using Allocator = alloc::AllocatorWithGC<alloc::AllocatorBasic, ObjectFactoryTraits>;
|
|
using ObjectData = gc::GC::ObjectData;
|
|
|
|
Allocator CreateAllocator() noexcept { return Allocator(alloc::AllocatorBasic(), *this); }
|
|
|
|
void OnOOM(size_t size) noexcept {
|
|
RuntimeLogDebug({kTagGC}, "Attempt to GC on OOM at size=%zu", size);
|
|
// TODO: This will print the log for "manual" scheduling. Fix this.
|
|
mm::GlobalData::Instance().gcScheduler().scheduleAndWaitFinished();
|
|
}
|
|
};
|
|
|
|
using ObjectFactory = alloc::ObjectFactory<ObjectFactoryTraits>;
|
|
|
|
inline GC::ObjectData& objectDataForObject(ObjHeader* object) noexcept {
|
|
return ObjectFactory::NodeRef::From(object).ObjectData();
|
|
}
|
|
|
|
inline ObjHeader* objectForObjectData(GC::ObjectData& objectData) noexcept {
|
|
return ObjectFactory::NodeRef::From(objectData)->GetObjHeader();
|
|
}
|
|
|
|
using FinalizerQueue = ObjectFactory::FinalizerQueue;
|
|
using FinalizerQueueTraits = ObjectFactory::FinalizerQueueTraits;
|
|
|
|
} // namespace kotlin::gc
|
|
|
|
#endif
|