[K/N] Refactor unhandled exception handling API

* Do not reset unhandled exception hook
* Add processUnhandledException to perform default unhandled exception
  processing
* Add terminateWithUnhandledException to report the unhandled exception
  and terminate the program
* Use the default unhandled exception processing in entrypoint, interop
  boundaries and in Worker.executeAfter
* Add -Xworker-exception-handling to control exception processing of
  Worker.executeAfter. By default its the old behaviour with the old MM,
  and new behaviour with the new MM.
This commit is contained in:
Alexander Shabalin
2021-07-15 12:29:56 +03:00
committed by Space
parent 766857881a
commit 7e04bb4bf1
41 changed files with 983 additions and 71 deletions
@@ -329,6 +329,15 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
}
})
put(PROPERTY_LAZY_INITIALIZATION, arguments.propertyLazyInitialization)
put(WORKER_EXCEPTION_HANDLING, when (arguments.workerExceptionHandling) {
null -> if (memoryModel == MemoryModel.EXPERIMENTAL) WorkerExceptionHandling.USE_HOOK else WorkerExceptionHandling.LEGACY
"legacy" -> WorkerExceptionHandling.LEGACY
"use-hook" -> WorkerExceptionHandling.USE_HOOK
else -> {
configuration.report(ERROR, "Unsupported worker exception handling mode ${arguments.workerExceptionHandling}")
WorkerExceptionHandling.LEGACY
}
})
}
}
}
@@ -320,6 +320,14 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
@Argument(value="-Xruntime-asserts-mode", valueDescription = "<mode>", description = "Enable asserts in runtime. Possible values: 'ignore', 'log', 'panic'")
var runtimeAssertsMode: String? = "ignore"
// TODO: Remove when legacy MM is gone.
@Argument(
value = "-Xworker-exception-handling",
valueDescription = "<mode>",
description = "Unhandled exception processing in Worker.executeAfter. Possible values: 'legacy', 'use-hook'. The default value is 'legacy', for -memory-model experimental the default value is 'use-hook'"
)
var workerExceptionHandling: String? = null
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> =
super.configureAnalysisFlags(collector, languageVersion).also {
val useExperimental = it[AnalysisFlags.useExperimental] as List<*>