[*] Fix major heap regression

This commit is contained in:
Reece Wilson 2024-03-19 09:58:00 +00:00
parent b65f27fa8f
commit 0b60cb8099
3 changed files with 74 additions and 83 deletions

View File

@ -99,7 +99,7 @@ namespace Aurora::Memory
static const auto kAlignment = AuMax(alignof(T), sizeof(void *));
if constexpr (AuIsClass_v<T> &&
!AuIsTriviallyDefaultConstructible_v<T>)
!AuIsTriviallyDestructible_v<T>)
{
pThat->~T();
}
@ -118,7 +118,7 @@ namespace Aurora::Memory
auto uCount = (AuUInt)pVoids[1];
if constexpr (AuIsClass_v<T> &&
!AuIsTriviallyDefaultConstructible_v<T>)
!AuIsTriviallyDestructible_v<T>)
{
for (AU_ITERATE_N(i, uCount))
{
@ -138,7 +138,7 @@ namespace Aurora::Memory
auto pBaseClass = AuStaticCast<Z>(pThat);
if constexpr (AuIsClass_v<Z> &&
!AuIsTriviallyDefaultConstructible_v<Z>)
!AuIsTriviallyDestructible_v<Z>)
{
pBaseClass->~Z();
}
@ -168,7 +168,7 @@ namespace Aurora::Memory
}
if constexpr (AuIsClass_v<T> &&
!AuIsTriviallyDefaultConstructible_v<T>)
!AuIsTriviallyConstructible_v<T, Args...>)
{
pPtr = pThat->FAlloc<AuUInt8 *>(sizeof(T) + kAlignment, kAlignment);
if (pPtr)
@ -205,7 +205,7 @@ namespace Aurora::Memory
}
if constexpr (AuIsClass_v<T> &&
!AuIsTriviallyDefaultConstructible_v<T>)
!AuIsTriviallyConstructible_v<T, Args...>)
{
pPtr = pThat->FAlloc<AuUInt8 *>(sizeof(T) + kAlignment, kAlignment);
if (pPtr)
@ -253,7 +253,7 @@ namespace Aurora::Memory
}
if constexpr (AuIsClass_v<T> &&
!AuIsTriviallyDefaultConstructible_v<T>)
!AuIsTriviallyConstructible_v<T, Args...>)
{
if (bool(pPtr = pThat->FAlloc<AuUInt8 *>((sizeof(T) * uElements) + kAlignment, kAlignment)))
{
@ -311,7 +311,7 @@ namespace Aurora::Memory
}
if constexpr (AuIsClass_v<T> &&
!AuIsTriviallyDefaultConstructible_v<T>)
!AuIsTriviallyConstructible_v<T, Args...>)
{
if (bool(pPtr = pThat->FAlloc<AuUInt8 *>((sizeof(T) * uElements) + kAlignment, kAlignment)))
{

View File

@ -119,25 +119,19 @@ namespace Aurora::Logging
{
AU_LOCK_GUARD(spin);
try
while (!AuTryInsert(this->filters, AuMakeTuple(uLevel, shouldFilter)))
{
while (!AuTryInsert(filters, AuMakeTuple(uLevel, shouldFilter)))
{
SysPushErrorMem("Push failed - trying again. wont be able to handle pop - wont syspanic yet");
AuThreading::ContextYield();
}
AuMemset(this->shouldFilter, 0, sizeof(this->shouldFilter));
for (auto &tuple : filters)
{
auto uLevel = AuGet<0>(tuple);
auto shouldFilter = AuGet<1>(tuple);
this->shouldFilter[uLevel] = shouldFilter;
}
SysPushErrorMem("Push failed - trying again. wont be able to handle pop - wont syspanic yet");
AuThreading::ContextYield();
}
catch (...)
AuMemset(this->shouldFilter, 0, sizeof(this->shouldFilter));
for (auto &tuple : this->filters)
{
auto uLevel = AuGet<0>(tuple);
auto shouldFilter = AuGet<1>(tuple);
this->shouldFilter[uLevel] = shouldFilter;
}
}
@ -149,93 +143,68 @@ namespace Aurora::Logging
void ForceFlushLoggers()
{
AU_DEBUG_MEMCRUNCH;
decltype(gLogTasks) logTasks;
AU_LOCK_GUARD(gGlobalSpin);
{
AU_LOCK_GUARD(gTaskSpin);
AuSwap(logTasks, gLogTasks);
gLogTasks.reserve(12 * 1024);
}
if (logTasks.empty())
{
return;
}
for (const auto &logEntry : logTasks)
{
auto &logger = AuGet<0>(logEntry);
auto &uLevel = AuGet<1>(logEntry);
auto &message = AuGet<2>(logEntry);
try
{
if (AuTryResize(logTasks, gLogTasks.size()))
{
for (int i = 0; i < gLogTasks.size(); i++)
{
logTasks[i] = AuMove(gLogTasks[i]);
}
gLogTasks.clear();
}
logger->WriteLater(uLevel, message);
}
catch (...)
{
}
if (logTasks.empty())
{
return;
}
}
try
{
for (const auto &logEntry : logTasks)
{
auto &logger = AuGet<0>(logEntry);
auto &uLevel = AuGet<1>(logEntry);
auto &message = AuGet<2>(logEntry);
logger->WriteLater(uLevel, message);
}
}
catch (...)
{
}
}
void ForceFlushLoggersNoLock()
{
AU_DEBUG_MEMCRUNCH;
decltype(gLogTasks) logTasks;
{
AuSwap(logTasks, gLogTasks);
gLogTasks.reserve(1024);
}
if (logTasks.empty())
{
return;
}
for (const auto &logEntry : logTasks)
{
auto &logger = AuGet<0>(logEntry);
auto &uLevel = AuGet<1>(logEntry);
auto &message = AuGet<2>(logEntry);
try
{
if (AuTryResize(logTasks, gLogTasks.size()))
{
for (int i = 0; i < gLogTasks.size(); i++)
{
logTasks[i] = AuMove(gLogTasks[i]);
}
gLogTasks.clear();
}
logger->WriteLater(uLevel, message);
}
catch (...)
{
}
if (logTasks.empty())
{
return;
}
}
try
{
for (const auto &logEntry : logTasks)
{
auto &logger = AuGet<0>(logEntry);
auto &uLevel = AuGet<1>(logEntry);
auto &message = AuGet<2>(logEntry);
logger->WriteLater(uLevel, message);
}
}
catch (...)
{
}
}
@ -321,6 +290,7 @@ namespace Aurora::Logging
SysPushErrorCatch();
}
return;
if (bDelegateLater)
{
AddToPushQueueConst(uLevel, msg);

View File

@ -90,7 +90,28 @@ namespace Aurora::Memory
static bool mi_block_visit_funHandler(const mi_heap_t *heap, const mi_heap_area_t *area, void *block, size_t block_size, void *arg)
{
auto pWalkInstance = (WalkInstance *)arg;
if (!block)
{
return true;
}
if (!area->used)
{
return true;
}
#if 0
for (AU_ITERATE_N(i, area->used))
{
if (!pWalkInstance->fCallback(((AuUInt *)block) + (i * area->block_size), pWalkInstance->pSecondArg))
{
return false;
}
}
#else
return pWalkInstance->fCallback(block, pWalkInstance->pSecondArg);
#endif
return true;
}
void WalkHeap(bool(*fCallback)(void *, void*), void *pSecondArg) override
@ -98,7 +119,7 @@ namespace Aurora::Memory
WalkInstance inst;
inst.fCallback = fCallback;
inst.pSecondArg = pSecondArg;
mi_heap_visit_blocks(nullptr, true, &mi_block_visit_funHandler, &inst);
mi_heap_visit_blocks(mi_heap_get_default(), true , &mi_block_visit_funHandler, &inst);
}
void UpdateStats() override