@@ -7,7 +7,17 @@ import kotlin.coroutines.CoroutineContext
77import kotlin.coroutines.EmptyCoroutineContext
88
99private const val DEBUG_PROPERTY_NAME = " kotlinx.coroutines.debug"
10- private val DEBUG = CoroutineId ::class .java.desiredAssertionStatus() || System .getProperty(DEBUG_PROPERTY_NAME ) != null
10+
11+ private val DEBUG = run {
12+ val value = System .getProperty(DEBUG_PROPERTY_NAME )
13+ when (value) {
14+ " auto" , null -> CoroutineId ::class .java.desiredAssertionStatus()
15+ " on" , " " -> true
16+ " off" -> false
17+ else -> error(" System property '$DEBUG_PROPERTY_NAME ' has unrecognized value '$value '" )
18+ }
19+ }
20+
1121private val COROUTINE_ID = AtomicLong ()
1222
1323@PublishedApi
@@ -47,14 +57,18 @@ public fun currentCoroutineContextOrDefault(default: CoroutineDispatcher): Corou
4757 * The [context] for the new coroutine must be explicitly specified and must include [CoroutineDispatcher] element.
4858 * This function shall be used to start new coroutines.
4959 *
50- * **Debugging facilities:** When assertions are enabled or when "kotlinx.coroutines.debug" system property
51- * is set, every coroutine is assigned a unique consecutive identifier. Every thread that executes
52- * a coroutine has its name modified to include the name and identifier of the currently currently running coroutine.
53- *
60+ * **Debugging facilities:** In debug mode every coroutine is assigned a unique consecutive identifier.
61+ * Every thread that executes a coroutine has its name modified to include the name and identifier of the
62+ * currently currently running coroutine.
5463 * When one coroutine is suspended and resumes another coroutine in the same thread and a [CoroutineDispatcher]
5564 * is not explicitly or dispatcher executes continuation in the same thread, then the thread name displays
5665 * the whole stack of coroutine descriptions that are being executed on this thread.
5766 *
67+ * Enable debugging facilities with "`kotlinx.coroutines.debug`" system property, use the following values:
68+ * * "`auto`" (default mode) -- enabled when assertions are enabled with "`-ea`" JVM option.
69+ * * "`on`" or empty string -- enabled.
70+ * * "`off`" -- disabled.
71+ *
5872 * Coroutine name can be explicitly assigned using [CoroutineName] context element.
5973 * The string "coroutine" is used as a default name.
6074 */
0 commit comments