From ccb6927e0571b241c7ab08f9f885ee026c40c860 Mon Sep 17 00:00:00 2001 From: LepilkinaElena Date: Wed, 30 Sep 2020 19:23:27 +0300 Subject: [PATCH] [KT-42275] Eliminate recursive GC calls (#4412) --- runtime/src/main/cpp/Memory.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index 1eebfe9961d..438ad78db5d 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -2115,7 +2115,7 @@ void updateHeapRefIfNull(ObjHeader** location, const ObjHeader* object) { } inline void checkIfGcNeeded(MemoryState* state) { - if (state != nullptr && state->allocSinceLastGc > state->allocSinceLastGcThreshold) { + if (state != nullptr && state->allocSinceLastGc > state->allocSinceLastGcThreshold && state->gcSuspendCount == 0) { // To avoid GC trashing check that at least 10ms passed since last GC. if (konan::getTimeMicros() - state->lastGcTimestamp > 10 * 1000) { GC_LOG("Calling GC from checkIfGcNeeded: %d\n", state->toRelease->size()) @@ -2125,7 +2125,8 @@ inline void checkIfGcNeeded(MemoryState* state) { } inline void checkIfForceCyclicGcNeeded(MemoryState* state) { - if (state != nullptr && state->toFree != nullptr && state->toFree->size() > kMaxToFreeSizeThreshold) { + if (state != nullptr && state->toFree != nullptr && state->toFree->size() > kMaxToFreeSizeThreshold + && state->gcSuspendCount == 0) { // To avoid GC trashing check that at least 10ms passed since last GC. if (konan::getTimeMicros() - state->lastGcTimestamp > 10 * 1000) { GC_LOG("Calling GC from checkIfForceCyclicGcNeeded: %d\n", state->toFree->size())