Make NoOp GC support multiple mutators

This commit is contained in:
Alexander Shabalin
2021-05-21 06:31:09 +00:00
committed by Space
parent 792ac6ab63
commit 73533e4b19
10 changed files with 65 additions and 20 deletions
@@ -13,6 +13,8 @@ namespace gc {
using GC = kotlin::gc::NoOpGC;
inline constexpr bool kSupportsMultipleMutators = true;
} // namespace gc
} // namespace kotlin
@@ -13,6 +13,8 @@ namespace gc {
using GC = kotlin::gc::SingleThreadMarkAndSweep;
inline constexpr bool kSupportsMultipleMutators = false;
} // namespace gc
} // namespace kotlin
@@ -3737,3 +3737,5 @@ kotlin::ThreadState kotlin::GetThreadState(MemoryState* thread) noexcept {
// Assume that we are always in the Runnable thread state.
return ThreadState::kRunnable;
}
const bool kotlin::kSupportsMultipleMutators = true;
@@ -441,6 +441,8 @@ ALWAYS_INLINE inline R CallWithThreadState(R(*function)(Args...), Args... args)
return function(std::forward<Args>(args)...);
}
extern const bool kSupportsMultipleMutators;
} // namespace kotlin
#endif // RUNTIME_MEMORY_H
@@ -107,8 +107,9 @@ RuntimeState* initRuntime() {
result->memoryState = InitMemory(false); // The argument will be ignored for legacy DestroyRuntimeMode
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");
if (!kotlin::kSupportsMultipleMutators && !firstRuntime) {
konan::consoleErrorf("This GC implementation does not support multiple mutator threads.");
konan::abort();
}
break;
case DESTROY_RUNTIME_ON_SHUTDOWN:
@@ -120,8 +121,9 @@ RuntimeState* initRuntime() {
RuntimeAssert(lastStatus != kGlobalRuntimeShutdown, "Kotlin runtime was shut down. Cannot create new runtimes.");
}
firstRuntime = lastStatus == kGlobalRuntimeUninitialized;
if (CurrentMemoryModel == MemoryModel::kExperimental) {
RuntimeCheck(firstRuntime, "Experimental MM does not support multiple mutator threads yet");
if (!kotlin::kSupportsMultipleMutators && !firstRuntime) {
konan::consoleErrorf("This GC implementation does not support multiple mutator threads.");
konan::abort();
}
result->memoryState = InitMemory(firstRuntime);
result->worker = WorkerInit(result->memoryState, true);
@@ -9,6 +9,7 @@
#include "Exceptions.h"
#include "ExtraObjectData.hpp"
#include "Freezing.hpp"
#include "GC.hpp"
#include "GlobalsRegistry.hpp"
#include "InitializationScheme.hpp"
#include "KAssert.h"
@@ -509,3 +510,5 @@ extern "C" ALWAYS_INLINE RUNTIME_NOTHROW void Kotlin_mm_switchThreadStateRunnabl
MemoryState* kotlin::mm::GetMemoryState() {
return ToMemoryState(ThreadRegistry::Instance().CurrentThreadDataNode());
}
const bool kotlin::kSupportsMultipleMutators = kotlin::gc::kSupportsMultipleMutators;