Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
projedi committed Nov 11, 2020
1 parent d41cc1e commit 0c99715
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.jetbrains.kotlin.backend.konan

// Must match DestroyRuntimeMode in Runtime.h
// Must match `DestroyRuntimeMode` in Runtime.h
enum class DestroyRuntimeMode(val value: Int) {
LEGACY(0),
ON_SHUTDOWN(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
}

private fun appendGlobal(name: String, value: ConstValue) {
// TODO: A similar mechanism is used in ObjCExportCodeGenerator. Consider merging them.
// TODO: A similar mechanism is used in `ObjCExportCodeGenerator`. Consider merging them.
if (context.llvmModuleSpecification.importsKotlinDeclarationsFromOtherSharedLibraries()) {
// When some dynamic caches are used, we consider that stdlib is in the dynamic cache as well.
// Runtime is linked into stdlib module only, so import runtime global from it.
Expand Down
17 changes: 9 additions & 8 deletions runtime/src/legacymm/cpp/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,13 +2032,18 @@ void deinitMemory(MemoryState* memoryState, bool destroyRuntime) {
static int pendingDeinit = 0;
atomicAdd(&pendingDeinit, 1);
#if USE_GC
bool lastMemoryState = atomicAdd(&aliveMemoryStatesCount, -1) == 0;
switch (Kotlin_getDestroyRuntimeMode()) {
case DESTROY_RUNTIME_LEGACY:
destroyRuntime = lastMemoryState;
destroyRuntime = atomicAdd(&aliveMemoryStatesCount, -1) == 0;
break;
case DESTROY_RUNTIME_ON_SHUTDOWN:
// Nothing to do.
if (!destroyRuntime && memoryState->isMainThread) {
// If we are not destroying the runtime but we were the main thread, publish all changes to Kotlin globals.
// This `synchronize` should be before `aliveMemoryStatesCount` decrement to synchronize with
// `initMemory` which does this in the reverse order.
synchronize();
}
atomicAdd(&aliveMemoryStatesCount, -1);
break;
}
bool checkLeaks = Kotlin_memoryLeakCheckerEnabled() && destroyRuntime;
Expand All @@ -2054,10 +2059,6 @@ void deinitMemory(MemoryState* memoryState, bool destroyRuntime) {
cyclicDeinit(g_hasCyclicCollector);
#endif // USE_CYCLIC_GC
}
if (!destroyRuntime && memoryState->isMainThread) {
// If we are not destroying the runtime but we were the main thread, publish all changes to Kotlin globals.
synchronize();
}
// Actual GC only implemented in strict memory model at the moment.
do {
GC_LOG("Calling garbageCollect from DeinitMemory()\n")
Expand All @@ -2077,7 +2078,7 @@ void deinitMemory(MemoryState* memoryState, bool destroyRuntime) {
atomicAdd(&pendingDeinit, -1);

#if TRACE_MEMORY
if (IsStrictMemoryModel && lastMemoryState && allocCount > 0) {
if (IsStrictMemoryModel && destroyRuntime && allocCount > 0) {
MEMORY_LOG("*** Memory leaks, leaked %d containers ***\n", allocCount);
dumpReachable("", memoryState->containers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package kotlin.native.internal

/*
* Internal utilities for debugging K/N compiler and runtime itself.
* Internal utilities for debugging K/N compiler and runtime.
*/
public object Debugging {
public var forceCheckedShutdown: Boolean
Expand Down

0 comments on commit 0c99715

Please sign in to comment.