diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt index 11fdb487351..04c63261659 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt @@ -64,6 +64,9 @@ class CoroutineTransformerMethodVisitor( override fun performTransformations(methodNode: MethodNode) { val suspensionPoints = collectSuspensionPoints(methodNode) + // First instruction in the method node may change in case of named function + val actualCoroutineStart = methodNode.instructions.first + if (isForNamedFunction) { if (allSuspensionPointsAreTailCalls(containingClassInternalName, methodNode, suspensionPoints)) { dropSuspensionMarkers(methodNode, suspensionPoints) @@ -76,16 +79,6 @@ class CoroutineTransformerMethodVisitor( prepareMethodNodePreludeForNamedFunction(methodNode) } - val customCoroutineStart = run { - val customCoroutineStartMarker = methodNode.instructions.toArray().filterIsInstance().firstOrNull { - it.owner == COROUTINE_MARKER_OWNER && it.name == ACTUAL_COROUTINE_START_MARKER_NAME - } - - customCoroutineStartMarker?.next?.also { - methodNode.instructions.remove(customCoroutineStartMarker) - } - } - for (suspensionPoint in suspensionPoints) { splitTryCatchBlocksContainingSuspensionPoint(methodNode, suspensionPoint) } @@ -110,7 +103,7 @@ class CoroutineTransformerMethodVisitor( methodNode.instructions.apply { val startLabel = LabelNode() val defaultLabel = LabelNode() - val firstToInsertBefore = customCoroutineStart ?: first + val firstToInsertBefore = actualCoroutineStart // tableswitch(this.label) insertBefore(firstToInsertBefore, insnListOf( @@ -221,8 +214,6 @@ class CoroutineTransformerMethodVisitor( checkcast(objectTypeForState) getfield(COROUTINE_IMPL_FOR_NAMED_ASM_TYPE.internalName, "exception", AsmTypes.JAVA_THROWABLE_TYPE.descriptor) visitVarInsn(Opcodes.ASTORE, exceptionIndex) - - invokestatic(COROUTINE_MARKER_OWNER, ACTUAL_COROUTINE_START_MARKER_NAME, "()V", false) }) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt index 972221bf024..e5150cec820 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt @@ -55,7 +55,6 @@ import org.jetbrains.org.objectweb.asm.tree.MethodNode const val COROUTINE_MARKER_OWNER = "kotlin/coroutines/Markers" const val BEFORE_SUSPENSION_POINT_MARKER_NAME = "beforeSuspensionPoint" const val AFTER_SUSPENSION_POINT_MARKER_NAME = "afterSuspensionPoint" -const val ACTUAL_COROUTINE_START_MARKER_NAME = "actualCoroutineStart" const val COROUTINE_LABEL_FIELD_NAME = "label" const val SUSPEND_FUNCTION_CREATE_METHOD_NAME = "create"