Skip to content
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

Simplify JobNode.toString to reduce code and avoid potential StackOverflow #2377

Merged
merged 1 commit into from Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 1 addition & 12 deletions kotlinx-coroutines-core/common/src/JobSupport.kt
Expand Up @@ -1151,8 +1151,6 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
override fun invoke(cause: Throwable?) {
parent.continueCompleting(state, child, proposedUpdate)
}
override fun toString(): String =
"ChildCompletion[$child, $proposedUpdate]"
}

private class AwaitContinuation<T>(
Expand Down Expand Up @@ -1350,6 +1348,7 @@ internal abstract class JobNode<out J : Job>(
override val isActive: Boolean get() = true
override val list: NodeList? get() = null
override fun dispose() = (job as JobSupport).removeNode(this)
override fun toString() = "$classSimpleName@$hexAddress[job@${job.hexAddress}]"
}

internal class NodeList : LockFreeLinkedListHead(), Incomplete {
Expand Down Expand Up @@ -1384,15 +1383,13 @@ private class InvokeOnCompletion(
private val handler: CompletionHandler
) : JobNode<Job>(job) {
override fun invoke(cause: Throwable?) = handler.invoke(cause)
override fun toString() = "InvokeOnCompletion[$classSimpleName@$hexAddress]"
}

private class ResumeOnCompletion(
job: Job,
private val continuation: Continuation<Unit>
) : JobNode<Job>(job) {
override fun invoke(cause: Throwable?) = continuation.resume(Unit)
override fun toString() = "ResumeOnCompletion[$continuation]"
}

private class ResumeAwaitOnCompletion<T>(
Expand All @@ -1411,15 +1408,13 @@ private class ResumeAwaitOnCompletion<T>(
continuation.resume(state.unboxState() as T)
}
}
override fun toString() = "ResumeAwaitOnCompletion[$continuation]"
}

internal class DisposeOnCompletion(
job: Job,
private val handle: DisposableHandle
) : JobNode<Job>(job) {
override fun invoke(cause: Throwable?) = handle.dispose()
override fun toString(): String = "DisposeOnCompletion[$handle]"
}

private class SelectJoinOnCompletion<R>(
Expand All @@ -1431,7 +1426,6 @@ private class SelectJoinOnCompletion<R>(
if (select.trySelect())
block.startCoroutineCancellable(select.completion)
}
override fun toString(): String = "SelectJoinOnCompletion[$select]"
}

private class SelectAwaitOnCompletion<T, R>(
Expand All @@ -1443,7 +1437,6 @@ private class SelectAwaitOnCompletion<T, R>(
if (select.trySelect())
job.selectAwaitCompletion(select, block)
}
override fun toString(): String = "SelectAwaitOnCompletion[$select]"
}

// -------- invokeOnCancellation nodes
Expand All @@ -1463,7 +1456,6 @@ private class InvokeOnCancelling(
override fun invoke(cause: Throwable?) {
if (_invoked.compareAndSet(0, 1)) handler.invoke(cause)
}
override fun toString() = "InvokeOnCancelling[$classSimpleName@$hexAddress]"
}

internal class ChildHandleNode(
Expand All @@ -1472,7 +1464,6 @@ internal class ChildHandleNode(
) : JobCancellingNode<JobSupport>(parent), ChildHandle {
override fun invoke(cause: Throwable?) = childJob.parentCancelled(job)
override fun childCancelled(cause: Throwable): Boolean = job.childCancelled(cause)
override fun toString(): String = "ChildHandle[$childJob]"
}

// Same as ChildHandleNode, but for cancellable continuation
Expand All @@ -1483,7 +1474,5 @@ internal class ChildContinuation(
override fun invoke(cause: Throwable?) {
child.parentCancelled(child.getContinuationCancellationCause(job))
}
override fun toString(): String =
"ChildContinuation[$child]"
}

1 change: 0 additions & 1 deletion kotlinx-coroutines-core/common/src/selects/Select.kt
Expand Up @@ -339,7 +339,6 @@ internal class SelectBuilderImpl<in R>(
if (trySelect())
resumeSelectWithException(job.getCancellationException())
}
override fun toString(): String = "SelectOnCancelling[${this@SelectBuilderImpl}]"
}

@PublishedApi
Expand Down
1 change: 0 additions & 1 deletion kotlinx-coroutines-core/jvm/src/Future.kt
Expand Up @@ -41,7 +41,6 @@ private class CancelFutureOnCompletion(
// interruption flag and it will cause spurious failures elsewhere
future.cancel(false)
}
override fun toString() = "CancelFutureOnCompletion[$future]"
}

private class CancelFutureOnCancel(private val future: Future<*>) : CancelHandler() {
Expand Down