-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Eagerly load CoroutineExceptionHandler and load corresponding service #2957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Partially addresses #2552
@@ -22,6 +22,12 @@ private val handlers: List<CoroutineExceptionHandler> = ServiceLoader.load( | |||
CoroutineExceptionHandler::class.java.classLoader | |||
).iterator().asSequence().toList() | |||
|
|||
internal actual fun initializeDefaultExceptionHandlers() { | |||
// Load CEH and handlers | |||
CoroutineExceptionHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect Class.forName
or something here instead. As is, could you please explain due to what guarantees does this not get thrown away as dead code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JVM has no right to throw away any code with side effects. Classloading is not pure, GETSTATIC CEH.Key
will trigger classloading:
https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html#jvms-5.4.3
Also, the key here is to initialize handlers
which are initialized when initializeDefaultExceptionHandlers
first accessed (because these symbols belong to the same class)
…Kotlin#2957) * Eagerly load CoroutineExceptionHandler and load the corresponding service Partially addresses Kotlin#2552
… service (Kotlin#2957)" (Kotlin#3190) This reverts commit 0b65246.
…Kotlin#2957) * Eagerly load CoroutineExceptionHandler and load the corresponding service Partially addresses Kotlin#2552
… service (Kotlin#2957)" (Kotlin#3190) This reverts commit 0b65246.
Partially addresses #2552