[K/N] Refactor allocator modules ^KT-60928
- 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
This commit is contained in:
committed by
Space Team
parent
c6893de9bb
commit
1fa0ef6f56
@@ -612,6 +612,9 @@ bool FinalizersThreadIsRunning() noexcept;
|
||||
|
||||
void OnMemoryAllocation(size_t totalAllocatedBytes) noexcept;
|
||||
|
||||
void initObjectPool() noexcept;
|
||||
void compactObjectPoolInCurrentThread() noexcept;
|
||||
|
||||
} // namespace kotlin
|
||||
|
||||
RUNTIME_NOTHROW ALWAYS_INLINE extern "C" void Kotlin_processObjectInMark(void* state, ObjHeader* object);
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
namespace kotlin {
|
||||
|
||||
void initObjectPool() noexcept;
|
||||
void* allocateInObjectPool(size_t size) noexcept;
|
||||
void freeInObjectPool(void* ptr, size_t size) noexcept;
|
||||
// Instruct the allocator to free unused resources.
|
||||
void compactObjectPoolInCurrentThread() noexcept;
|
||||
// Platform dependent. Schedule `compactObjectPoolInCurrentThread` on the main thread.
|
||||
// May do nothing if the main thread is not an event loop.
|
||||
void compactObjectPoolInMainThread() noexcept;
|
||||
|
||||
size_t allocatedBytes() noexcept;
|
||||
|
||||
template <typename T>
|
||||
struct ObjectPoolAllocator {
|
||||
using value_type = T;
|
||||
using size_type = std::size_t;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using propagate_on_container_move_assignment = std::true_type;
|
||||
using is_always_equal = std::true_type;
|
||||
|
||||
constexpr ObjectPoolAllocator() noexcept = default;
|
||||
|
||||
constexpr ObjectPoolAllocator(const ObjectPoolAllocator&) noexcept = default;
|
||||
|
||||
template <typename U>
|
||||
constexpr ObjectPoolAllocator(const ObjectPoolAllocator<U>&) noexcept {}
|
||||
|
||||
T* allocate(std::size_t n) noexcept { return static_cast<T*>(allocateInObjectPool(n * sizeof(T))); }
|
||||
|
||||
void deallocate(T* p, std::size_t n) noexcept { freeInObjectPool(p, n * sizeof(T)); }
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
constexpr bool operator==(const ObjectPoolAllocator<T>&, const ObjectPoolAllocator<U>&) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
constexpr bool operator!=(const ObjectPoolAllocator<T>&, const ObjectPoolAllocator<U>&) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "MainQueueProcessor.hpp"
|
||||
#include "Memory.h"
|
||||
#include "ObjCExportInit.h"
|
||||
#include "ObjectAlloc.hpp"
|
||||
#include "Porting.h"
|
||||
#include "Runtime.h"
|
||||
#include "RuntimePrivate.hpp"
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "Memory.h"
|
||||
#include "Natives.h"
|
||||
#include "ObjCMMAPI.h"
|
||||
#include "ObjectAlloc.hpp"
|
||||
#include "Runtime.h"
|
||||
#include "Types.h"
|
||||
#include "Worker.h"
|
||||
|
||||
Reference in New Issue
Block a user