From fdd2f4841ba466e3fa7e5c3df285478d06af422c Mon Sep 17 00:00:00 2001 From: Allen Hair Date: Tue, 16 Dec 2014 10:18:04 -0800 Subject: Extend try-catch blocks to cover inserted probes. --- .../internal/flow/MethodProbesAdapterTest.java | 52 ++++++++++++++++++++++ .../core/internal/flow/MethodProbesAdapter.java | 24 ++++++++++ 2 files changed, 76 insertions(+) diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java index ea329632..5590323f 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java @@ -312,6 +312,58 @@ public class MethodProbesAdapterTest implements IProbeIdGenerator { expectedVisitor.visitTableSwitchInsn(0, 1, label, labels); } + @Test + public void testVisitTryCatchBlockNoProbe() { + Label start = new Label(); + Label end = new Label(); + Label handler = new Label(); + + adapter.visitTryCatchBlock(start, end, handler, "java/lang/Exception"); + adapter.visitLabel(start); + + expectedVisitor.visitTryCatchBlock(start, end, handler, "java/lang/Exception"); + expectedVisitor.visitLabel(start); + } + + @Test + public void testVisitTryCatchBlockWithProbe() { + Label target = new Label(); + LabelInfo.setSuccessor(target); + LabelInfo.setTarget(target); + Label end = new Label(); + Label handler = new Label(); + Label start = new Label(); + + adapter.visitTryCatchBlock(target, end, handler, "java/lang/Exception"); + adapter.visitLabel(target); + + expectedVisitor.visitTryCatchBlock(start, end, handler, "java/lang/Exception"); + expectedVisitor.visitLabel(start); + expectedVisitor.visitProbe(1000); + expectedVisitor.visitLabel(target); + } + + @Test + public void testVisitMultipleTryCatchBlocksWithProbe() { + Label target = new Label(); + LabelInfo.setSuccessor(target); + LabelInfo.setTarget(target); + Label end = new Label(); + Label handler1 = new Label(); + Label handler2 = new Label(); + Label start = new Label(); + + adapter.visitTryCatchBlock(target, end, handler1, "java/lang/Exception"); + adapter.visitTryCatchBlock(target, end, handler2, "java/io/IOException"); + adapter.visitLabel(target); + + expectedVisitor.visitTryCatchBlock(start, end, handler1, "java/lang/Exception"); + expectedVisitor.visitTryCatchBlock(start, end, handler2, "java/io/IOException"); + expectedVisitor.visitLabel(start); + expectedVisitor.visitProbe(1000); + expectedVisitor.visitLabel(target); + } + // === IProbeIdGenerator === public int nextId() { diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java index 6d44bc5a..2fe7e315 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java @@ -17,6 +17,9 @@ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.commons.AnalyzerAdapter; +import java.util.HashMap; +import java.util.Map; + /** * Adapter that creates additional visitor events for probes to be inserted into * a method. @@ -29,6 +32,8 @@ public final class MethodProbesAdapter extends MethodVisitor { private AnalyzerAdapter analyzer; + private Map tryCatchProbeLabels = new HashMap(); + /** * Create a new adapter instance. * @@ -55,9 +60,28 @@ public final class MethodProbesAdapter extends MethodVisitor { this.analyzer = analyzer; } + @Override + public void visitTryCatchBlock(Label start, final Label end, + final Label handler, final String type) { + // If a probe will be inserted before the start label, we'll need to use a + // different label for the try-catch block. + if (tryCatchProbeLabels.containsKey(start)) { + start = tryCatchProbeLabels.get(start); + } else if (LabelInfo.isMultiTarget(start) && LabelInfo.isSuccessor(start)) { + Label probeLabel = new Label(); + LabelInfo.setSuccessor(probeLabel); + tryCatchProbeLabels.put(start, probeLabel); + start = probeLabel; + } + probesVisitor.visitTryCatchBlock(start, end, handler, type); + } + @Override public void visitLabel(final Label label) { if (LabelInfo.isMultiTarget(label) && LabelInfo.isSuccessor(label)) { + if (tryCatchProbeLabels.containsKey(label)) { + probesVisitor.visitLabel(tryCatchProbeLabels.get(label)); + } probesVisitor.visitProbe(idGenerator.nextId()); } probesVisitor.visitLabel(label); -- cgit v1.2.3 From bc3c1cad4b60091cc95c1bd7429c7c1d92d1fb5a Mon Sep 17 00:00:00 2001 From: Allen Hair Date: Tue, 30 Dec 2014 15:47:03 -0800 Subject: Increment file version for try-catch probe change. --- org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java b/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java index f064f907..1d0157da 100644 --- a/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java +++ b/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java @@ -24,7 +24,7 @@ public class ExecutionDataWriter implements ISessionInfoVisitor, IExecutionDataVisitor { /** File format version, will be incremented for each incompatible change. */ - public static final char FORMAT_VERSION = 0x1006; + public static final char FORMAT_VERSION = 0x1007; /** Magic number in header for file format identification. */ public static final char MAGIC_NUMBER = 0xC0C0; -- cgit v1.2.3 From 834d1556e4a1051621909f705a6ac94eaa6d7248 Mon Sep 17 00:00:00 2001 From: Allen Hair Date: Tue, 30 Dec 2014 19:59:30 -0800 Subject: Update binary test data with new version number. --- .../it/it-report-nomatch/nomatch.exec | Bin 24 -> 24 bytes org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec | Bin 42 -> 42 bytes org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec | 2 +- org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec b/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec index 31cad96f..b3396529 100644 Binary files a/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec and b/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec differ diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec b/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec index ef7d62ae..66d78df2 100644 Binary files a/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec and b/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec differ diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec b/org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec index b9c3ab93..2e87d6ca 100644 --- a/org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec +++ b/org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec @@ -1 +1 @@ -ÀÀ \ No newline at end of file +ÀÀ \ No newline at end of file diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec b/org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec index b9c3ab93..2e87d6ca 100644 --- a/org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec +++ b/org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec @@ -1 +1 @@ -ÀÀ \ No newline at end of file +ÀÀ \ No newline at end of file -- cgit v1.2.3