Skip to content

Commit

Permalink
Do not filter Lincheck events when printing a thread dump if the thre…
Browse files Browse the repository at this point in the history
…ad has hung in the Lincheck internals.
  • Loading branch information
ndkoval committed Feb 6, 2024
1 parent 2d0ab4b commit 0887da4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
19 changes: 13 additions & 6 deletions src/jvm/main/org/jetbrains/kotlinx/lincheck/Reporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -582,17 +582,24 @@ private fun StringBuilder.appendDeadlockWithDumpFailure(failure: DeadlockWithDum
/* fileName = */ it.fileName,
/* lineNumber = */ it.lineNumber
)
}.map { it.toString() }
.filter { stackTraceElementLine -> // Remove all stack trace elements related to lincheck
"org.jetbrains.kotlinx.lincheck.strategy" !in stackTraceElementLine
&& "org.jetbrains.kotlinx.lincheck.runner" !in stackTraceElementLine
&& "org.jetbrains.kotlinx.lincheck.UtilsKt" !in stackTraceElementLine
}.forEach { appendLine("\t$it") }
}.run {
// Remove all the Lincheck internals only if the program
// has hung in the user code. Otherwise, print the full
// stack trace for easier debugging.
if (isEmpty() || first().isLincheckInternals) {
this
} else {
filter { !it.isLincheckInternals }
}
}.forEach { appendLine("\t$it") }
}
}
return this
}

private val StackTraceElement.isLincheckInternals get() =
this.className.startsWith("org.jetbrains.kotlinx.lincheck.")

private fun StringBuilder.appendIncorrectResultsFailure(
failure: IncorrectResultsFailure,
exceptionStackTraces: Map<Throwable, ExceptionNumberAndStacktrace>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal class FixedActiveThreadsExecutor(private val nThreads: Int, runnerHash:
private fun shutdown() {
// submit the shutdown tasks
for (i in 0 until nThreads)
submitTask(i, SHUTDOWN)
submitTask(i, Shutdown)
}

private fun submitTask(iThread: Int, task: Any) {
Expand Down Expand Up @@ -143,7 +143,7 @@ internal class FixedActiveThreadsExecutor(private val nThreads: Int, runnerHash:
private fun testThreadRunnable(iThread: Int) = Runnable {
loop@ while (true) {
val task = getTask(iThread)
if (task === SHUTDOWN) return@Runnable
if (task === Shutdown) return@Runnable
tasks[iThread].value = null // reset task
val threadExecution = task as TestThreadExecution
check(threadExecution.iThread == iThread)
Expand All @@ -154,7 +154,7 @@ internal class FixedActiveThreadsExecutor(private val nThreads: Int, runnerHash:
setResult(iThread, wrapped)
continue@loop
}
setResult(iThread, DONE)
setResult(iThread, Done)
}
}

Expand Down Expand Up @@ -215,5 +215,6 @@ internal class FixedActiveThreadsExecutor(private val nThreads: Int, runnerHash:

private const val SPINNING_LOOP_ITERATIONS_BEFORE_PARK = 1000_000

private val SHUTDOWN = "SHUTDOWN"
private val DONE = "DONE"
// These constants are objects for easier debugging.
private object Shutdown
private object Done

0 comments on commit 0887da4

Please sign in to comment.