From e2e93d633caaba8af9f57b10080dc2ca43e93546 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 19 May 2017 18:06:15 +0300 Subject: [PATCH] Get rid of using label field in named function It preventing from making it protected (as it was before) #KT-17898 In progress --- .../CoroutineTransformerMethodVisitor.kt | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) 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 de477ee52c5..1ee64591800 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt @@ -113,11 +113,7 @@ class CoroutineTransformerMethodVisitor( *withInstructionAdapter { loadCoroutineSuspendedMarker() }.toArray(), VarInsnNode(Opcodes.ASTORE, suspendMarkerVarIndex), VarInsnNode(Opcodes.ALOAD, continuationIndex), - FieldInsnNode( - Opcodes.GETFIELD, - COROUTINE_IMPL_ASM_TYPE.internalName, - COROUTINE_LABEL_FIELD_NAME, Type.INT_TYPE.descriptor - ), + createInsnForReadingLabel(), TableSwitchInsnNode(0, suspensionPoints.size, defaultLabel, @@ -140,6 +136,38 @@ class CoroutineTransformerMethodVisitor( methodNode.removeEmptyCatchBlocks() } + private fun createInsnForReadingLabel() = + if (isForNamedFunction) + MethodInsnNode( + Opcodes.INVOKEVIRTUAL, + classBuilderForCoroutineState.thisName, + "getLabel", + Type.getMethodDescriptor(Type.INT_TYPE), + false + ) + else + FieldInsnNode( + Opcodes.GETFIELD, + COROUTINE_IMPL_ASM_TYPE.internalName, + COROUTINE_LABEL_FIELD_NAME, Type.INT_TYPE.descriptor + ) + + private fun createInsnForSettingLabel() = + if (isForNamedFunction) + MethodInsnNode( + Opcodes.INVOKEVIRTUAL, + classBuilderForCoroutineState.thisName, + "setLabel", + Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), + false + ) + else + FieldInsnNode( + Opcodes.PUTFIELD, + COROUTINE_IMPL_ASM_TYPE.internalName, + COROUTINE_LABEL_FIELD_NAME, Type.INT_TYPE.descriptor + ) + private fun updateMaxStack(methodNode: MethodNode) { methodNode.instructions.resetLabels() methodNode.accept( @@ -441,18 +469,7 @@ class CoroutineTransformerMethodVisitor( insnListOf( VarInsnNode(Opcodes.ALOAD, continuationIndex), *withInstructionAdapter { iconst(id) }.toArray(), - if (isForNamedFunction) - MethodInsnNode( - Opcodes.INVOKEVIRTUAL, classBuilderForCoroutineState.thisName, - "setLabel", - Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), - false - ) - else - FieldInsnNode( - Opcodes.PUTFIELD, COROUTINE_IMPL_ASM_TYPE.internalName, COROUTINE_LABEL_FIELD_NAME, - Type.INT_TYPE.descriptor - ) + createInsnForSettingLabel() ) )