[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
@@ -110,8 +110,12 @@ int Konan_DebugBufferSizeWithObjectImpl(KRef obj) {
// Auxilary function which can be called by developer/debugger to inspect an object.
int32_t Konan_DebugObjectToUtf8ArrayImpl(KRef obj, char* buffer, int32_t bufferSize) {
// We need the runnable thread state to call the Kotlin function 'KonanObjectToUtf8Array' and operate with it's result.
// But the current thread can be in any state when this function is called by the debugger. So we use the reentrant state switch.
kotlin::ThreadStateGuard guard(kotlin::ThreadState::kRunnable, /* reentrant */ true);
ObjHolder stringHolder;
auto data = KonanObjectToUtf8Array(obj, stringHolder.slot())->array();
// Kotlin call.
ArrayHeader* data = KonanObjectToUtf8Array(obj, stringHolder.slot())->array();
if (data == nullptr) return 0;
if (bufferSize < 1) return 0;
KInt toCopy = data->count_ > static_cast<uint32_t>(bufferSize - 1) ? bufferSize - 1 : data->count_;