Skip to content

Commit

Permalink
Update filter for suspending lambdas for Kotlin 1.4.20 (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Jan 8, 2021
1 parent e859274 commit a2c723c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
6 changes: 5 additions & 1 deletion org.jacoco.core.test.validation.kotlin/pom.xml
Expand Up @@ -25,7 +25,11 @@
<name>JaCoCo :: Test :: Core :: Validation Kotlin</name>

<properties>
<kotlin.version>1.4.0</kotlin.version>
<!--
re-include this module in profiles for JDK 16 and 17 in org.jacoco.core.test.validation
once there is version with resolved https://youtrack.jetbrains.com/issue/KT-43704
-->
<kotlin.version>1.4.20</kotlin.version>
</properties>

<dependencies>
Expand Down
10 changes: 10 additions & 0 deletions org.jacoco.core.test.validation/pom.xml
Expand Up @@ -249,7 +249,12 @@
<maven.compiler.target>16</maven.compiler.target>
</properties>
<modules>
<!--
kotlin-maven-plugin versions 1.4.20 and 1.4.21 fail
due to https://openjdk.java.net/jeps/396
see https://youtrack.jetbrains.com/issue/KT-43704
<module>../org.jacoco.core.test.validation.kotlin</module>
-->
<module>../org.jacoco.core.test.validation.java7</module>
<module>../org.jacoco.core.test.validation.java8</module>
<module>../org.jacoco.core.test.validation.java14</module>
Expand All @@ -272,7 +277,12 @@
<maven.compiler.target>17</maven.compiler.target>
</properties>
<modules>
<!--
kotlin-maven-plugin versions 1.4.20 and 1.4.21 fail
due to https://openjdk.java.net/jeps/396
see https://youtrack.jetbrains.com/issue/KT-43704
<module>../org.jacoco.core.test.validation.kotlin</module>
-->
<module>../org.jacoco.core.test.validation.java7</module>
<module>../org.jacoco.core.test.validation.java8</module>
<module>../org.jacoco.core.test.validation.java14</module>
Expand Down
Expand Up @@ -33,12 +33,11 @@ public void should_filter_suspending_lambdas_generated_by_Kotlin_1_3_30() {
context.classAnnotations
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

m.visitLabel(new Label());
final Range range1 = new Range();
range1.fromInclusive = m.instructions.getLast();
m.visitMethodInsn(Opcodes.INVOKESTATIC,
"kotlin/coroutines/intrinsics/IntrinsicsKt",
"getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false);
final Range range1 = new Range();
range1.fromInclusive = m.instructions.getLast();
m.visitVarInsn(Opcodes.ASTORE, 4);

m.visitVarInsn(Opcodes.ALOAD, 0);
Expand Down Expand Up @@ -129,12 +128,11 @@ public void should_filter_suspending_lambdas() {
context.classAnnotations
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

m.visitLabel(new Label());
final Range range1 = new Range();
range1.fromInclusive = m.instructions.getLast();
m.visitMethodInsn(Opcodes.INVOKESTATIC,
"kotlin/coroutines/intrinsics/IntrinsicsKt",
"getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false);
final Range range1 = new Range();
range1.fromInclusive = m.instructions.getLast();
m.visitVarInsn(Opcodes.ASTORE, 4);

m.visitVarInsn(Opcodes.ALOAD, 0);
Expand Down
Expand Up @@ -20,6 +20,7 @@
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TableSwitchInsnNode;

Expand Down Expand Up @@ -67,10 +68,17 @@ private void matchOptimizedTailCall(final MethodNode methodNode,

private void match(final MethodNode methodNode,
final IFilterOutput output) {
cursor = methodNode.instructions.getFirst();
nextIsInvoke(Opcodes.INVOKESTATIC,
"kotlin/coroutines/intrinsics/IntrinsicsKt",
"getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;");
cursor = skipNonOpcodes(methodNode.instructions.getFirst());
if (cursor == null || cursor.getOpcode() != Opcodes.INVOKESTATIC) {
cursor = null;
} else {
final MethodInsnNode m = (MethodInsnNode) cursor;
if (!"kotlin/coroutines/intrinsics/IntrinsicsKt".equals(m.owner)
|| !"getCOROUTINE_SUSPENDED".equals(m.name)
|| !"()Ljava/lang/Object;".equals(m.desc)) {
cursor = null;
}
}

if (cursor == null) {
cursor = skipNonOpcodes(methodNode.instructions.getFirst());
Expand Down
3 changes: 3 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -30,6 +30,9 @@ <h3>New Features</h3>
<li>Branch added by the Kotlin compiler version 1.4.0 and above for "unsafe" cast
operator is filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1143">#1143</a>).</li>
<li>Branches added by the Kotlin compiler version 1.4.20 and above for suspending
lambdas are filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1149">#1149</a>).</li>
</ul>

<h3>Non-functional Changes</h3>
Expand Down

0 comments on commit a2c723c

Please sign in to comment.