[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
@@ -0,0 +1,38 @@
package runtime.workers.worker_exceptions
import kotlin.test.*
import kotlin.native.concurrent.*
@Test
fun testExecuteAfterStartQuiet() {
val worker = Worker.start(errorReporting = false)
worker.executeAfter(0L, {
throw Error("testExecuteAfterStartQuiet error")
}.freeze())
worker.requestTermination().result
}
@Test
fun testExecuteStart() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, {}) {
throw Error("testExecuteStart error")
}
assertFailsWith<Throwable> {
future.result
}
worker.requestTermination().result
}
@Test
fun testExecuteStartQuiet() {
val worker = Worker.start(errorReporting = false)
val future = worker.execute(TransferMode.SAFE, {}) {
throw Error("testExecuteStartQuiet error")
}
assertFailsWith<Throwable> {
future.result
}
worker.requestTermination().result
}
@@ -0,0 +1,26 @@
package runtime.workers.worker_exceptions_legacy
import kotlin.test.*
import kotlin.native.concurrent.*
@Test
fun testExecuteAfterStartLegacy() {
val worker = Worker.start()
worker.executeAfter(0L, {
throw Error("testExecuteAfterStartLegacy error")
}.freeze())
worker.requestTermination().result
}
@Test
fun testExecuteStartLegacy() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, {}) {
throw Error("testExecuteStartLegacy error")
}
assertFailsWith<Throwable> {
future.result
}
worker.requestTermination().result
}
@@ -0,0 +1,10 @@
import kotlin.native.concurrent.*
fun main() {
val worker = Worker.start()
worker.executeAfter(0L, {
throw Error("some error")
}.freeze())
worker.requestTermination().result
println("Will not happen")
}
@@ -0,0 +1,9 @@
import kotlin.native.concurrent.*
fun main() {
Worker.current.executeAfter(0L, {
throw Error("some error")
}.freeze())
Worker.current.processQueue()
println("Will not happen")
}
@@ -0,0 +1,15 @@
import kotlin.native.concurrent.*
fun main() {
setUnhandledExceptionHook({ _: Throwable ->
println("hook called")
}.freeze())
val worker = Worker.start()
worker.executeAfter(0L, {
throw Error("some error")
}.freeze())
worker.requestTermination().result
println("Will happen")
}
@@ -0,0 +1,13 @@
import kotlin.native.concurrent.*
fun main() {
setUnhandledExceptionHook({ _: Throwable ->
println("hook called")
}.freeze())
Worker.current.executeAfter(0L, {
throw Error("some error")
}.freeze())
Worker.current.processQueue()
println("Will happen")
}