From 9c38ff9c20c26dc26f4506dcdf6023d71e3981c0 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Sun, 14 Jul 2019 22:46:20 +0300 Subject: [PATCH] Allow allocations while memory state not yet inited. --- 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 4affb85b435..4f6e836a65e 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -688,7 +688,8 @@ ContainerHeader* allocContainer(MemoryState* state, size_t size) { #endif if (result == nullptr) { #if USE_GC - state->allocSinceLastGc += size; + if (state != nullptr) + state->allocSinceLastGc += size; #endif result = konanConstructSizedInstance(alignUp(size, kObjectAlignment)); atomicAdd(&allocCount, 1); @@ -1661,7 +1662,7 @@ void updateHeapRefIfNull(ObjHeader** location, const ObjHeader* object) { } inline void checkIfGcNeeded(MemoryState* state) { - if (state->allocSinceLastGc > state->allocSinceLastGcThreshold) { + if (state != nullptr && state->allocSinceLastGc > state->allocSinceLastGcThreshold) { // To avoid GC trashing check that at least 10ms passed since last GC. if (konan::getTimeMicros() - state->lastGcTimestamp > 10 * 1000) { garbageCollect(state, false);