[K/N] GC: parallel mark with work balancing ^KT-57771

Merge-request: KT-MR-11460
Merged-by: Alexey Glushko <aleksei.glushko@jetbrains.com>
This commit is contained in:
Aleksei.Glushko
2023-08-03 16:25:19 +00:00
committed by Space Team
parent f0f1dc15c3
commit f1efeff21b
32 changed files with 1431 additions and 594 deletions
@@ -41,6 +41,10 @@ object BinaryOptions : BinaryOptionRegistry() {
val concurrentWeakSweep by booleanOption()
val gcMutatorsCooperate by booleanOption()
val auxGCThreads by uintOption()
val linkRuntime by option<RuntimeLinkageStrategyBinaryOption>()
val bundleId by stringOption()
@@ -95,6 +99,15 @@ open class BinaryOptionRegistry {
}
}
protected fun uintOption(): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, CompilerConfigurationKey<UInt>>> =
PropertyDelegateProvider { _, property ->
val option = BinaryOption(property.name, UIntValueParser)
register(option)
ReadOnlyProperty { _, _ ->
option.compilerConfigurationKey
}
}
protected fun stringOption(): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, CompilerConfigurationKey<String>>> =
PropertyDelegateProvider { _, property ->
val option = BinaryOption(property.name, StringValueParser)
@@ -121,6 +134,13 @@ private object BooleanValueParser : BinaryOption.ValueParser<Boolean> {
get() = "true|false"
}
private object UIntValueParser : BinaryOption.ValueParser<UInt> {
override fun parse(value: String): UInt? = value.toUIntOrNull()
override val validValuesHint: String?
get() = "non-negative-number"
}
private object StringValueParser : BinaryOption.ValueParser<String> {
override fun parse(value: String) = value
override val validValuesHint: String?
@@ -143,12 +143,41 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
} ?: arg
}
val gcMarkSingleThreaded: Boolean
get() = configuration.get(BinaryOptions.gcMarkSingleThreaded) ?: false
private val defaultGcMarkSingleThreaded get() = target.family == Family.MINGW
val gcMarkSingleThreaded: Boolean by lazy {
configuration.get(BinaryOptions.gcMarkSingleThreaded) ?: defaultGcMarkSingleThreaded
}
val concurrentWeakSweep: Boolean
get() = configuration.get(BinaryOptions.concurrentWeakSweep) ?: false
val gcMutatorsCooperate: Boolean by lazy {
val mutatorsCooperate = configuration.get(BinaryOptions.gcMutatorsCooperate)
if (gcMarkSingleThreaded) {
if (mutatorsCooperate == true) {
configuration.report(CompilerMessageSeverity.STRONG_WARNING,
"Mutators cooperation is not supported during single threaded mark")
}
false
} else {
mutatorsCooperate ?: true
}
}
val auxGCThreads: UInt by lazy {
val auxGCThreads = configuration.get(BinaryOptions.auxGCThreads)
if (gcMarkSingleThreaded) {
if (auxGCThreads != null && auxGCThreads != 0U) {
configuration.report(CompilerMessageSeverity.STRONG_WARNING,
"Auxiliary GC workers are not supported during single threaded mark")
}
0U
} else {
auxGCThreads ?: 0U
}
}
val irVerificationMode: IrVerificationMode
get() = configuration.getNotNull(KonanConfigKeys.VERIFY_IR)
@@ -408,6 +437,8 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
append("-runtime_asserts=${runtimeAssertsMode.name}")
if (disableMmap != defaultDisableMmap)
append("-disable_mmap=${disableMmap}")
if (gcMarkSingleThreaded != defaultGcMarkSingleThreaded)
append("-gc_mark_single_threaded=${gcMarkSingleThreaded}")
}
private val userCacheFlavorString = buildString {
@@ -2780,7 +2780,8 @@ internal class CodeGeneratorVisitor(
return
overrideRuntimeGlobal("Kotlin_destroyRuntimeMode", llvm.constInt32(context.config.destroyRuntimeMode.value))
overrideRuntimeGlobal("Kotlin_gcMarkSingleThreaded", llvm.constInt32(if (context.config.gcMarkSingleThreaded) 1 else 0))
overrideRuntimeGlobal("Kotlin_gcMutatorsCooperate", llvm.constInt32(if (context.config.gcMutatorsCooperate) 1 else 0))
overrideRuntimeGlobal("Kotlin_auxGCThreads", llvm.constInt32(context.config.auxGCThreads.toInt()))
overrideRuntimeGlobal("Kotlin_workerExceptionHandling", llvm.constInt32(context.config.workerExceptionHandling.value))
overrideRuntimeGlobal("Kotlin_suspendFunctionsFromAnyThreadFromObjC", llvm.constInt32(if (context.config.suspendFunctionsFromAnyThreadFromObjC) 1 else 0))
val getSourceInfoFunctionName = when (context.config.sourceInfoType) {
@@ -3015,6 +3016,7 @@ internal fun NativeGenerationState.generateRuntimeConstantsModule() : LLVMModule
setRuntimeConstGlobal("Kotlin_freezingEnabled", llvm.constInt32(if (config.freezing.enableFreezeAtRuntime) 1 else 0))
setRuntimeConstGlobal("Kotlin_freezingChecksEnabled", llvm.constInt32(if (config.freezing.enableFreezeChecks) 1 else 0))
setRuntimeConstGlobal("Kotlin_concurrentWeakSweep", llvm.constInt32(if (context.config.concurrentWeakSweep) 1 else 0))
setRuntimeConstGlobal("Kotlin_gcMarkSingleThreaded", llvm.constInt32(if (config.gcMarkSingleThreaded) 1 else 0))
return llvmModule
}
@@ -86,7 +86,12 @@ fun testAtomicReferenceStress(workers: Array<Worker>) {
fun runStressTest() {
val COUNT = 20
val workers = Array(COUNT, { _ -> Worker.start()})
testAtomicIntStress(workers)
testAtomicLongStress(workers)
testAtomicReferenceStress(workers)
workers.forEach {
it.requestTermination().result
}
}