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

Non-determinism fix: ClassLoaders are now transformed in the Model Checking mode #413

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ internal class LincheckClassVisitor(
mv = ObjectCreationTransformer(fileName, className, methodName, mv.newAdapter())
return mv
}
if (className.contains("ClassLoader")) {
if (isClassLoader(className)) {
if (methodName == "loadClass") {
mv = WrapMethodInIgnoredSectionTransformer(fileName, className, methodName, mv.newAdapter())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ internal object LincheckJavaAgent {
// In the model checking mode, Lincheck processes classes lazily, only when they are used.
instrumentationMode == MODEL_CHECKING -> {
check(instrumentedClasses.isEmpty())
// Transform class loaders on the start, because it's the only place where we can do it.
val classLoaderClasses = getLoadedClassesToInstrument()
.filter { isClassLoader(it.name) }
.toTypedArray()
instrumentation.retransformClasses(*classLoaderClasses)
}
}
}
Expand Down Expand Up @@ -351,7 +356,8 @@ internal object LincheckClassFileTransformer : ClassFileTransformer {
// once they are used in the testing code.
if (!INSTRUMENT_ALL_CLASSES &&
instrumentationMode == MODEL_CHECKING &&
internalClassName.canonicalClassName !in instrumentedClasses) {
internalClassName.canonicalClassName !in instrumentedClasses &&
!isClassLoader(internalClassName)) {
return null
}
return transformImpl(loader, internalClassName, classBytes)
Expand Down Expand Up @@ -382,6 +388,10 @@ internal object LincheckClassFileTransformer : ClassFileTransformer {
if (instrumentationMode == STRESS) {
if (className.startsWith("java.") || className.startsWith("kotlin.")) return false
}
// We should transform all the ClassLoader-s to wrap `loadClass` methods in the ignored section.
if (isClassLoader(className)) {
return true
}
// We do not need to instrument most standard Java classes.
// It is fine to inject the Lincheck analysis only into the
// `java.util.*` ones, ignored the known atomic constructs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,5 @@ internal const val ASM_API = Opcodes.ASM9
internal val STRING_TYPE = getType(String::class.java)
internal val CLASS_TYPE = getType(Class::class.java)
internal val CLASS_FOR_NAME_METHOD = Method("forName", CLASS_TYPE, arrayOf(STRING_TYPE))

internal fun isClassLoader(className: String): Boolean = className.contains("ClassLoader")
Loading