Skip to content

Minor improvements of debugging experience #2093

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

Merged
merged 3 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/common/src/Unconfined.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal object Unconfined : CoroutineDispatcher() {
"isDispatchNeeded and dispatch calls.")
}

override fun toString(): String = "Unconfined"
override fun toString(): String = "Dispatchers.Unconfined"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ internal object DebugProbesImpl {
internal fun probeCoroutineSuspended(frame: Continuation<*>) = updateState(frame, SUSPENDED)

private fun updateState(frame: Continuation<*>, state: String) {
if (!isInstalled) return
// KT-29997 is here only since 1.3.30
if (state == RUNNING && KotlinVersion.CURRENT.isAtLeast(1, 3, 30)) {
val stackFrame = frame as? CoroutineStackFrame ?: return
Expand Down
18 changes: 12 additions & 6 deletions kotlinx-coroutines-core/jvm/src/scheduling/Dispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import kotlin.coroutines.*
* Default instance of coroutine dispatcher.
*/
internal object DefaultScheduler : ExperimentalCoroutineDispatcher() {
val IO = blocking(systemProp(IO_PARALLELISM_PROPERTY_NAME, 64.coerceAtLeast(AVAILABLE_PROCESSORS)))
val IO: CoroutineDispatcher = LimitingDispatcher(
this,
systemProp(IO_PARALLELISM_PROPERTY_NAME, 64.coerceAtLeast(AVAILABLE_PROCESSORS)),
"Dispatchers.IO",
TASK_PROBABLY_BLOCKING
)

override fun close() {
throw UnsupportedOperationException("$DEFAULT_SCHEDULER_NAME cannot be closed")
Expand Down Expand Up @@ -85,7 +90,7 @@ public open class ExperimentalCoroutineDispatcher(
*/
public fun blocking(parallelism: Int = BLOCKING_DEFAULT_PARALLELISM): CoroutineDispatcher {
require(parallelism > 0) { "Expected positive parallelism level, but have $parallelism" }
return LimitingDispatcher(this, parallelism, TASK_PROBABLY_BLOCKING)
return LimitingDispatcher(this, parallelism, null, TASK_PROBABLY_BLOCKING)
}

/**
Expand All @@ -98,7 +103,7 @@ public open class ExperimentalCoroutineDispatcher(
public fun limited(parallelism: Int): CoroutineDispatcher {
require(parallelism > 0) { "Expected positive parallelism level, but have $parallelism" }
require(parallelism <= corePoolSize) { "Expected parallelism level lesser than core pool size ($corePoolSize), but have $parallelism" }
return LimitingDispatcher(this, parallelism, TASK_NON_BLOCKING)
return LimitingDispatcher(this, parallelism, null, TASK_NON_BLOCKING)
}

internal fun dispatchWithContext(block: Runnable, context: TaskContext, tailDispatch: Boolean) {
Expand Down Expand Up @@ -130,8 +135,9 @@ public open class ExperimentalCoroutineDispatcher(
}

private class LimitingDispatcher(
val dispatcher: ExperimentalCoroutineDispatcher,
val parallelism: Int,
private val dispatcher: ExperimentalCoroutineDispatcher,
private val parallelism: Int,
private val name: String?,
override val taskMode: Int
) : ExecutorCoroutineDispatcher(), TaskContext, Executor {

Expand Down Expand Up @@ -190,7 +196,7 @@ private class LimitingDispatcher(
}

override fun toString(): String {
return "${super.toString()}[dispatcher = $dispatcher]"
return name ?: "${super.toString()}[dispatcher = $dispatcher]"
}

/**
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/jvm/src/scheduling/Tasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.concurrent.*

// TODO most of these fields will be moved to 'object ExperimentalDispatcher'

internal const val DEFAULT_SCHEDULER_NAME = "DefaultDispatcher"
internal const val DEFAULT_SCHEDULER_NAME = "Dispatchers.Default"

// 100us as default
@JvmField
Expand Down