[K/N] Manually compact mimalloc heap ^KT-53182
Merge-request: KT-MR-7111 Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
This commit is contained in:
committed by
Space
parent
9210108d5a
commit
f009d9b633
@@ -29,6 +29,7 @@ RUNTIME_WEAK int32_t Kotlin_printToAndroidLogcat = 1;
|
||||
// Keep it 0 even when the compiler defaults to 1: if the overriding mechanism breaks, keeping it disabled is safer.
|
||||
RUNTIME_WEAK int32_t Kotlin_appStateTracking = 0;
|
||||
RUNTIME_WEAK int32_t Kotlin_mimallocUseDefaultOptions = 1;
|
||||
RUNTIME_WEAK int32_t Kotlin_mimallocUseCompaction = 0;
|
||||
|
||||
ALWAYS_INLINE compiler::DestroyRuntimeMode compiler::destroyRuntimeMode() noexcept {
|
||||
return static_cast<compiler::DestroyRuntimeMode>(Kotlin_destroyRuntimeMode);
|
||||
@@ -68,3 +69,7 @@ ALWAYS_INLINE int compiler::getSourceInfo(void* addr, SourceInfo *result, int re
|
||||
ALWAYS_INLINE bool compiler::mimallocUseDefaultOptions() noexcept {
|
||||
return Kotlin_mimallocUseDefaultOptions != 0;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool compiler::mimallocUseCompaction() noexcept {
|
||||
return Kotlin_mimallocUseCompaction != 0;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ bool suspendFunctionsFromAnyThreadFromObjCEnabled() noexcept;
|
||||
AppStateTracking appStateTracking() noexcept;
|
||||
int getSourceInfo(void* addr, SourceInfo *result, int result_size) noexcept;
|
||||
bool mimallocUseDefaultOptions() noexcept;
|
||||
bool mimallocUseCompaction() noexcept;
|
||||
|
||||
#ifdef KONAN_ANDROID
|
||||
bool printToAndroidLogcat() noexcept;
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace kotlin {
|
||||
void initObjectPool() noexcept;
|
||||
void* allocateInObjectPool(size_t size) noexcept;
|
||||
void freeInObjectPool(void* ptr) 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;
|
||||
|
||||
template <typename T>
|
||||
struct ObjectPoolAllocator {
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "Memory.h"
|
||||
#include "Natives.h"
|
||||
#include "ObjCMMAPI.h"
|
||||
#include "ObjectAlloc.hpp"
|
||||
#include "Runtime.h"
|
||||
#include "Types.h"
|
||||
#include "Worker.h"
|
||||
@@ -239,6 +240,7 @@ KNativePtr transfer(ObjHolder* holder, KInt mode) {
|
||||
}
|
||||
|
||||
void waitInNativeState(pthread_cond_t* cond, pthread_mutex_t* mutex) {
|
||||
kotlin::compactObjectPoolInCurrentThread();
|
||||
CallWithThreadState<ThreadState::kNative>(pthread_cond_wait, cond, mutex);
|
||||
}
|
||||
|
||||
@@ -246,6 +248,7 @@ void waitInNativeState(pthread_cond_t* cond,
|
||||
pthread_mutex_t* mutex,
|
||||
uint64_t timeoutNanoseconds,
|
||||
uint64_t* microsecondsPassed = nullptr) {
|
||||
kotlin::compactObjectPoolInCurrentThread();
|
||||
CallWithThreadState<ThreadState::kNative>(WaitOnCondVar, cond, mutex, timeoutNanoseconds, microsecondsPassed);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user