Skip to content

Don't instrument args reads at code line 0 (#722). #724

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
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ internal class LincheckClassVisitor(
fun MethodVisitor.newAdapter() = GeneratorAdapter(this, access, methodName, desc)
fun MethodVisitor.newNonRemappingAdapter() = GeneratorAdapterWithoutLocals(this, access, methodName, desc)

val isStatic = access and ACC_STATIC != 0

if (instrumentationMode == STRESS) {
return if (methodName != "<clinit>" && methodName != "<init>") {
CoroutineCancellabilitySupportTransformer(mv, access, className, methodName, desc)
Expand Down Expand Up @@ -113,7 +115,7 @@ internal class LincheckClassVisitor(
analyzerAdapter
}
val locals: Map<Int, List<LocalVariableInfo>> = methods[methodName + desc]?.variables ?: emptyMap()
mv = LocalVariablesAccessTransformer(fileName, className, methodName, mv.newAdapter(), locals)
mv = LocalVariablesAccessTransformer(fileName, className, methodName, mv.newAdapter(), desc, isStatic, locals)

// Inline method call transformer relies on the original variables' indices, so it should go before (in FIFO order)
// all transformers which can create local variables.
Expand Down Expand Up @@ -258,7 +260,7 @@ internal class LincheckClassVisitor(
aa
}
val locals: Map<Int, List<LocalVariableInfo>> = methods[methodName + desc]?.variables ?: emptyMap()
mv = LocalVariablesAccessTransformer(fileName, className, methodName, mv.newAdapter(), locals)
mv = LocalVariablesAccessTransformer(fileName, className, methodName, mv.newAdapter(), desc, isStatic, locals)
// Inline method call transformer relies on the original variables' indices, so it should go before (in FIFO order)
// all transformers which can create local variables.
// We cannot use trick with
Expand Down Expand Up @@ -303,6 +305,8 @@ internal open class ManagedStrategyMethodVisitor(
adapter.push(codeLocationId)
}

protected fun isKnownLineNumber(): Boolean = lineNumber > 0

override fun visitLineNumber(line: Int, start: Label) {
lineNumber = line
super.visitLineNumber(line, start)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.jetbrains.kotlinx.lincheck.transformation.transformers

import org.jetbrains.kotlinx.lincheck.tracedata.Types.convertAsmMethodType
import org.jetbrains.kotlinx.lincheck.tracedata.VariableDescriptor
import org.jetbrains.kotlinx.lincheck.tracedata.variableCache
import org.jetbrains.kotlinx.lincheck.transformation.*
Expand All @@ -23,10 +24,13 @@ internal class LocalVariablesAccessTransformer(
className: String,
methodName: String,
adapter: GeneratorAdapter,
desc: String,
isStatic: Boolean,
private val locals: Map<Int, List<LocalVariableInfo>>,
) : ManagedStrategyMethodVisitor(fileName, className, methodName, adapter) {
private var turnoffTransform = false
private val visitedLabels = HashSet<Label>()
private val numberOfLocals = convertAsmMethodType(desc).argumentTypes.size + if (isStatic) 0 else 1

override fun visitLabel(label: Label) = adapter.run {
visitedLabels += label
Expand Down Expand Up @@ -94,6 +98,12 @@ internal class LocalVariablesAccessTransformer(
}

private fun visitReadVarInsn(localVariableInfo: LocalVariableInfo, opcode: Int, varIndex: Int) = adapter.run {
// Skip variable read if it is in an unknown line of code and variable is argument
// It can be code inserted by compiler to check Null invariant
if (!isKnownLineNumber() && varIndex < numberOfLocals) {
visitVarInsn(opcode, varIndex)
return
}
invokeIfInAnalyzedCode(
original = {
visitVarInsn(opcode, varIndex)
Expand Down