[K/N][Runtime] Separate thread registering and making it 'Runnable'

The new GC will require threads to suspend right after registering
if Stop-The-World is requested. This patch changes the initial
thread state to kNative and adds a separate state switch right
after thread registering. This switch suspends if it is necessary.
This commit is contained in:
Ilya Matveev
2021-06-02 16:56:10 +07:00
committed by Space
parent e240b8a8ee
commit cece652412
11 changed files with 100 additions and 24 deletions

View File

@@ -243,6 +243,10 @@ class {
//! Process exception hook (if any) or just printStackTrace + write crash log
void processUnhandledKotlinException(KRef throwable) {
// Use the reentrant switch because both states are possible here:
// - runnable, if the exception occured in a pure Kotlin thread (except initialization of globals).
// - native, if the throwing code was called from ObjC/Swift or if the exception occured during initialization of globals.
kotlin::ThreadStateGuard guard(kotlin::ThreadState::kRunnable, /* reentrant = */ true);
OnUnhandledException(throwable);
#if KONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG
ReportBacktraceToIosCrashLog(throwable);