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())