[K/N][New MM] Support thread state switching

Including

* Support thread state switching in codegen
* Introduce and use GCUnsafeCall annotation
* Switch thread state in C++ runtime code

Also

* Register current thread in Mark&Sweep tests
* Store MemoryState in Worker instance
* Set worker tid in WorkerInit
This commit is contained in:
Ilya Matveev
2021-01-25 19:06:27 +07:00
committed by Space
parent 0b46ed3cde
commit 4d346d3735
86 changed files with 1340 additions and 721 deletions
+10 -2
View File
@@ -105,7 +105,7 @@ RuntimeState* initRuntime() {
case DESTROY_RUNTIME_LEGACY:
compareAndSwap(&globalRuntimeStatus, kGlobalRuntimeUninitialized, kGlobalRuntimeRunning);
result->memoryState = InitMemory(false); // The argument will be ignored for legacy DestroyRuntimeMode
result->worker = WorkerInit(true);
result->worker = WorkerInit(result->memoryState, true);
firstRuntime = atomicAdd(&aliveRuntimesCount, 1) == 1;
if (CurrentMemoryModel == MemoryModel::kExperimental) {
RuntimeCheck(firstRuntime, "Experimental MM does not support multiple mutator threads yet");
@@ -124,7 +124,7 @@ RuntimeState* initRuntime() {
RuntimeCheck(firstRuntime, "Experimental MM does not support multiple mutator threads yet");
}
result->memoryState = InitMemory(firstRuntime);
result->worker = WorkerInit(true);
result->worker = WorkerInit(result->memoryState, true);
}
InitOrDeinitGlobalVariables(ALLOC_THREAD_LOCAL_GLOBALS, result->memoryState);
@@ -370,4 +370,12 @@ void Kotlin_Debugging_setForceCheckedShutdown(KBoolean value) {
g_forceCheckedShutdown = value;
}
KBoolean Kotlin_Debugging_isThreadStateRunnable() {
return kotlin::GetThreadState() == kotlin::ThreadState::kRunnable;
}
KBoolean Kotlin_Debugging_isThreadStateNative() {
return kotlin::GetThreadState() == kotlin::ThreadState::kNative;
}
} // extern "C"