Skip to content

Commit

Permalink
Experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkoval committed Mar 28, 2024
1 parent c9eabcd commit 886880e
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal open class ParallelThreadsRunner(
private val useClocks: UseClocks // specifies whether `HBClock`-s should always be used or with some probability
) : Runner(strategy, testClass, validationFunction, stateRepresentationFunction) {
private val testName = testClass.simpleName
private val executor = FixedActiveThreadsExecutor(testName, scenario.nThreads) // should be closed in `close()`
internal val executor = FixedActiveThreadsExecutor(testName, scenario.nThreads) // should be closed in `close()`

private val spinners = SpinnerGroup(executor.threads.size)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.jetbrains.kotlinx.lincheck.runner.*
import org.jetbrains.kotlinx.lincheck.runner.ExecutionPart.*
import org.jetbrains.kotlinx.lincheck.strategy.*
import org.jetbrains.kotlinx.lincheck.transformation.*
import org.jetbrains.kotlinx.lincheck.transformation.LincheckClassFileTransformer.ensureClassIsTransformed
import org.jetbrains.kotlinx.lincheck.transformation.LincheckClassFileTransformer.ensureClassAndAllSuperClassesAreTransformed
import org.jetbrains.kotlinx.lincheck.util.*
import org.jetbrains.kotlinx.lincheck.verifier.*
import sun.misc.*
Expand Down Expand Up @@ -216,7 +216,12 @@ abstract class ManagedStrategy(
// In case the runner detects a deadlock, some threads can still be in an active state,
// simultaneously adding events to the TraceCollector, which leads to an inconsistent trace.
// Therefore, if the runner detects deadlock, we don't even try to collect trace.
if (loggedResults is RunnerTimeoutInvocationResult) return null
if (loggedResults is RunnerTimeoutInvocationResult) {
StringBuilder()
.also { it.appendTrace(DeadlockOrLivelockFailure(scenario, emptyMap(), Trace(traceCollector!!.trace)), null, Trace(traceCollector!!.trace), emptyMap()) }
.also { println(it.toString()) }
return null
}
val sameResultTypes = loggedResults.javaClass == failingResult.javaClass
val sameResults = loggedResults !is CompletedInvocationResult || failingResult !is CompletedInvocationResult || loggedResults.results == failingResult.results
check(sameResultTypes && sameResults) {
Expand Down Expand Up @@ -428,6 +433,19 @@ abstract class ManagedStrategy(
spinners[iThread].spinWaitUntil {
// Finish forcibly if an error occurred and we already have an `InvocationResult`.
if (suddenInvocationResult != null) throw ForcibleExecutionFinishError
val t = (runner as ParallelThreadsRunner).executor.threads[currentThread]
if (t.state == Thread.State.BLOCKED || t.state == Thread.State.WAITING) {
println(t.threadId)
t.stackTrace.forEach {
println(it)
}
synchronized(this) {
if (t.threadId == currentThread) {
// We need a deterministic wait to decide
switchCurrentThread(currentThread, SwitchReason.STRATEGY_SWITCH, true)
}
}
}
currentThread == iThread
}
}
Expand Down Expand Up @@ -640,7 +658,7 @@ abstract class ManagedStrategy(
override fun beforeReadFieldStatic(className: String, fieldName: String, codeLocation: Int) = runInIgnoredSection {
// We need to ensure all the classes related to the reading object are instrumented.
// The following call checks all the static fields.
ensureClassIsTransformed(className.canonicalClassName)
ensureClassAndAllSuperClassesAreTransformed(className.canonicalClassName)

// TODO: remove the isFinal check
if (FinalFields.isFinalField(className, fieldName)) return@runInIgnoredSection
Expand Down Expand Up @@ -786,7 +804,7 @@ abstract class ManagedStrategy(
}

override fun beforeNewObjectCreation(className: String) = runInIgnoredSection {
ensureClassIsTransformed(className)
ensureClassAndAllSuperClassesAreTransformed(className)
}

override fun afterNewObjectCreation(obj: Any) {
Expand Down Expand Up @@ -855,7 +873,7 @@ abstract class ManagedStrategy(
null -> {
if (owner == null) {
runInIgnoredSection {
ensureClassIsTransformed(className.canonicalClassName)
ensureClassAndAllSuperClassesAreTransformed(className.canonicalClassName)
}
}
if (collectTrace) {
Expand Down
Loading

0 comments on commit 886880e

Please sign in to comment.