diff options
author | Allen Hair <allenhair@google.com> | 2022-03-01 02:18:00 +0000 |
---|---|---|
committer | Allen Hair <allenhair@google.com> | 2022-03-17 23:25:07 +0000 |
commit | 57f9fdd3381050da63e88482a103acea86b74dd7 (patch) | |
tree | e68ce50b1fc964c12a1eb020ca8b2483ff2955d4 /org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java | |
parent | 473f391baad0c5c25a5d82ccda0b31825b11d7be (diff) | |
parent | d19ea595a67af6f16d76b49ccdc12858c3570298 (diff) | |
download | jacoco-57f9fdd3381050da63e88482a103acea86b74dd7.tar.gz |
Update jacoco to 0.8.7.
Bug: 194725917
Bug: 221938918
Bug: 206647174
Test: EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true m
Change-Id: I955b068b3e35d68460a633d0fe606218bdcb9391
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java')
-rw-r--r-- | org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java index 66d450a3..4b850f33 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java @@ -1,9 +1,10 @@ /******************************************************************************* - * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 * * Contributors: * Evgeny Mandrikov - initial API and implementation @@ -19,6 +20,7 @@ import org.objectweb.asm.Type; 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; @@ -27,7 +29,11 @@ import org.objectweb.asm.tree.TableSwitchInsnNode; */ public final class KotlinCoroutineFilter implements IFilter { - static boolean isLastArgumentContinuation(final MethodNode methodNode) { + static boolean isImplementationOfSuspendFunction( + final MethodNode methodNode) { + if (methodNode.name.startsWith("access$")) { + return false; + } final Type methodType = Type.getMethodType(methodNode.desc); final int lastArgument = methodType.getArgumentTypes().length - 1; return lastArgument >= 0 && "kotlin.coroutines.Continuation".equals( @@ -42,16 +48,41 @@ public final class KotlinCoroutineFilter implements IFilter { } new Matcher().match(methodNode, output); - + new Matcher().matchOptimizedTailCall(methodNode, output); } private static class Matcher extends AbstractMatcher { + + private void matchOptimizedTailCall(final MethodNode methodNode, + final IFilterOutput output) { + for (final AbstractInsnNode i : methodNode.instructions) { + cursor = i; + nextIs(Opcodes.DUP); + nextIsInvoke(Opcodes.INVOKESTATIC, + "kotlin/coroutines/intrinsics/IntrinsicsKt", + "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;"); + nextIs(Opcodes.IF_ACMPNE); + nextIs(Opcodes.ARETURN); + nextIs(Opcodes.POP); + if (cursor != null) { + output.ignore(i.getNext(), cursor); + } + } + } + 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()); |