Move main thread check to legacy mm (#4483)

This commit is contained in:
Alexander Shabalin
2020-10-30 11:14:01 +03:00
committed by Stanislav Erokhin
parent 14526e57bc
commit 8dc5b95337
8 changed files with 32 additions and 24 deletions
@@ -641,6 +641,8 @@ struct MemoryState {
// A stack of initializing singletons.
KStdVector<std::pair<ObjHeader**, ObjHeader*>> initializingSingletons;
bool isMainThread = false;
#if COLLECT_STATISTIC
#define CONTAINER_ALLOC_STAT(state, size, container) state->statistic.incAlloc(size, container);
#define CONTAINER_DESTROY_STAT(state, container) \
@@ -2007,6 +2009,7 @@ MemoryState* initMemory() {
#if USE_CYCLIC_GC
cyclicInit();
#endif // USE_CYCLIC_GC
memoryState->isMainThread = true;
}
return memoryState;
}
@@ -3608,4 +3611,9 @@ void PerformFullGC() {
garbageCollect(::memoryState, true);
}
void CheckGlobalsAccessible() {
if (!::memoryState->isMainThread)
ThrowIncorrectDereferenceException();
}
} // extern "C"
@@ -41,4 +41,5 @@ void EnsureDeclarationsEmitted() {
ensureUsed(CheckLifetimesConstraint);
ensureUsed(FreezeSubgraph);
ensureUsed(FreezeSubgraph);
ensureUsed(CheckGlobalsAccessible);
}
@@ -254,6 +254,8 @@ bool IsForeignRefAccessible(ObjHeader* object, ForeignRefContext context);
// and there's nothing else keeping the object alive.
void AdoptReferenceFromSharedVariable(ObjHeader* object);
void CheckGlobalsAccessible();
#ifdef __cplusplus
}
#endif
@@ -69,7 +69,6 @@ KBoolean g_checkLeakedCleaners = KonanNeedDebugInfo;
constexpr RuntimeState* kInvalidRuntime = nullptr;
THREAD_LOCAL_VARIABLE RuntimeState* runtimeState = kInvalidRuntime;
THREAD_LOCAL_VARIABLE int isMainThread = 0;
inline bool isValidRuntime() {
return ::runtimeState != kInvalidRuntime;
@@ -88,7 +87,6 @@ RuntimeState* initRuntime() {
bool firstRuntime = atomicAdd(&aliveRuntimesCount, 1) == 1;
// Keep global variables in state as well.
if (firstRuntime) {
isMainThread = 1;
konan::consoleInit();
#if KONAN_OBJC_INTEROP
Kotlin_ObjCExport_initialize();
@@ -151,11 +149,6 @@ void Kotlin_deinitRuntimeIfNeeded() {
}
}
void CheckIsMainThread() {
if (!isMainThread)
ThrowIncorrectDereferenceException();
}
KInt Konan_Platform_canAccessUnaligned() {
#if KONAN_NO_UNALIGNED_ACCESS
return 0;
@@ -234,4 +234,8 @@ void AdoptReferenceFromSharedVariable(ObjHeader* object) {
RuntimeCheck(false, "Unimplemented");
}
void CheckGlobalsAccessible() {
// Globals are always accessible.
}
} // extern "C"