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

ProbeInserter should update indexes of local variables in annotations #894

Merged
merged 4 commits into from Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
Expand Up @@ -18,8 +18,11 @@
import org.junit.Before;
import org.junit.Test;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.TypePath;
marchof marked this conversation as resolved.
Show resolved Hide resolved
import org.objectweb.asm.TypeReference;

/**
* Unit tests for {@link ProbeInserter}.
Expand Down Expand Up @@ -182,6 +185,28 @@ public void testVisitLocalVariable() {
expectedVisitor.visitLocalVariable(null, null, null, null, null, 5);
}

@Test
public void should_remap_LocalVariableAnnotation() {
ProbeInserter pi = new ProbeInserter(0, "m", "(I)V", actualVisitor,
arrayStrategy);

final Label start = new Label();
pi.visitLabel(start);
final Label end = new Label();
pi.visitLabel(end);

pi.visitLocalVariableAnnotation(TypeReference.LOCAL_VARIABLE, null,
new Label[] { start }, new Label[] { end }, new int[] { 2 },
"LNonNull;", false);

expectedVisitor.visitLabel(start);
expectedVisitor.visitLabel(end);
// Local variables are shifted by one:
expectedVisitor.visitLocalVariableAnnotation(
TypeReference.LOCAL_VARIABLE, null, new Label[] { start },
new Label[] { end }, new int[] { 3 }, "LNonNull;", false);
}

@Test
public void testVisitMaxs1() {
ProbeInserter pi = new ProbeInserter(0, "m", "(II)V", actualVisitor,
Expand Down
Expand Up @@ -11,10 +11,12 @@
*******************************************************************************/
package org.jacoco.core.internal.instr;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.TypePath;

/**
* Internal utility to add probes into the control flow of a method. The code
Expand Down Expand Up @@ -111,6 +113,18 @@ public final void visitLocalVariable(final String name, final String desc,
mv.visitLocalVariable(name, desc, signature, start, end, map(index));
}

@Override
public AnnotationVisitor visitLocalVariableAnnotation(final int typeRef,
final TypePath typePath, final Label[] start, final Label[] end,
final int[] index, final String descriptor, final boolean visible) {
int[] newIndex = new int[index.length];
marchof marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < newIndex.length; i++) {
newIndex[i] = map(index[i]);
}
return mv.visitLocalVariableAnnotation(typeRef, typePath, start, end,
newIndex, descriptor, visible);
}

@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
// Max stack size of the probe code is 3 which can add to the
Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -32,6 +32,8 @@ <h3>Fixed bugs</h3>
<li><code>synthetic</code> constructors that contain values of default arguments
in Kotlin should not be ignored
(GitHub <a href="https://github.com/jacoco/jacoco/issues/888">#888</a>).</li>
<li>Instrumentation should update indexes of local variables in annotations
(GitHub <a href="https://github.com/jacoco/jacoco/issues/894">#894</a>).</li>
</ul>

<h2>Release 0.8.4 (2019/05/08)</h2>
Expand Down