From 70ae22b3f0cd718a9ef4f8b2d3147372c2324bd9 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Thu, 17 Feb 2022 02:27:01 -0800 Subject: [PATCH] Revert "Eagerly load CoroutineExceptionHandler and load corresponding service (#2957)" (#3190) This reverts commit 0b65246a32a81da724fc920d9f62f1670dff7d35. --- .../common/src/CoroutineExceptionHandler.kt | 8 +------- kotlinx-coroutines-core/common/src/Job.kt | 8 +------- .../js/src/CoroutineExceptionHandlerImpl.kt | 4 ---- .../jvm/src/CoroutineExceptionHandlerImpl.kt | 5 ----- .../native/src/CoroutineExceptionHandlerImpl.kt | 4 ---- 5 files changed, 2 insertions(+), 27 deletions(-) diff --git a/kotlinx-coroutines-core/common/src/CoroutineExceptionHandler.kt b/kotlinx-coroutines-core/common/src/CoroutineExceptionHandler.kt index 819f205b17..49923a92e7 100644 --- a/kotlinx-coroutines-core/common/src/CoroutineExceptionHandler.kt +++ b/kotlinx-coroutines-core/common/src/CoroutineExceptionHandler.kt @@ -1,19 +1,13 @@ /* * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ + package kotlinx.coroutines import kotlin.coroutines.* -import kotlin.jvm.* internal expect fun handleCoroutineExceptionImpl(context: CoroutineContext, exception: Throwable) -/** - * JVM kludge: trigger loading of all the classes and service loading - * **before** any exception occur because it may be OOM, SOE or VerifyError - */ -internal expect fun initializeDefaultExceptionHandlers() - /** * Helper function for coroutine builder implementations to handle uncaught and unexpected exceptions in coroutines, * that could not be otherwise handled in a normal way through structured concurrency, saving them to a future, and diff --git a/kotlinx-coroutines-core/common/src/Job.kt b/kotlinx-coroutines-core/common/src/Job.kt index 085ef7e8af..31d90eeef0 100644 --- a/kotlinx-coroutines-core/common/src/Job.kt +++ b/kotlinx-coroutines-core/common/src/Job.kt @@ -113,13 +113,7 @@ public interface Job : CoroutineContext.Element { /** * Key for [Job] instance in the coroutine context. */ - public companion object Key : CoroutineContext.Key { - init { - // `Job` will necessarily be accessed early, so this is as good a place as any for the - // initialization logic that we want to happen as soon as possible - initializeDefaultExceptionHandlers() - } - } + public companion object Key : CoroutineContext.Key // ------------ state query ------------ diff --git a/kotlinx-coroutines-core/js/src/CoroutineExceptionHandlerImpl.kt b/kotlinx-coroutines-core/js/src/CoroutineExceptionHandlerImpl.kt index a4d671dc65..54a65e10a6 100644 --- a/kotlinx-coroutines-core/js/src/CoroutineExceptionHandlerImpl.kt +++ b/kotlinx-coroutines-core/js/src/CoroutineExceptionHandlerImpl.kt @@ -6,10 +6,6 @@ package kotlinx.coroutines import kotlin.coroutines.* -internal actual fun initializeDefaultExceptionHandlers() { - // Do nothing -} - internal actual fun handleCoroutineExceptionImpl(context: CoroutineContext, exception: Throwable) { // log exception console.error(exception) diff --git a/kotlinx-coroutines-core/jvm/src/CoroutineExceptionHandlerImpl.kt b/kotlinx-coroutines-core/jvm/src/CoroutineExceptionHandlerImpl.kt index dd39210d25..4259092e78 100644 --- a/kotlinx-coroutines-core/jvm/src/CoroutineExceptionHandlerImpl.kt +++ b/kotlinx-coroutines-core/jvm/src/CoroutineExceptionHandlerImpl.kt @@ -22,11 +22,6 @@ private val handlers: List = ServiceLoader.load( CoroutineExceptionHandler::class.java.classLoader ).iterator().asSequence().toList() -internal actual fun initializeDefaultExceptionHandlers() { - // Load CEH and handlers - CoroutineExceptionHandler -} - /** * Private exception without stacktrace that is added to suppressed exceptions of the original exception * when it is reported to the last-ditch current thread 'uncaughtExceptionHandler'. diff --git a/kotlinx-coroutines-core/native/src/CoroutineExceptionHandlerImpl.kt b/kotlinx-coroutines-core/native/src/CoroutineExceptionHandlerImpl.kt index d97743b4bf..434813dc29 100644 --- a/kotlinx-coroutines-core/native/src/CoroutineExceptionHandlerImpl.kt +++ b/kotlinx-coroutines-core/native/src/CoroutineExceptionHandlerImpl.kt @@ -7,10 +7,6 @@ package kotlinx.coroutines import kotlin.coroutines.* import kotlin.native.* -internal actual fun initializeDefaultExceptionHandlers() { - // Do nothing -} - @OptIn(ExperimentalStdlibApi::class) internal actual fun handleCoroutineExceptionImpl(context: CoroutineContext, exception: Throwable) { // log exception