From 00a335129bac130ed81ab9a42a153866b3ddb9b7 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 10 Mar 2021 09:39:35 +0300 Subject: [PATCH] JVM_IR indy-SAM: use '-Xsam-conversions=indy' if JVM 1.8+, LV 1.5+ --- .../kotlin/codegen/state/GenerationState.kt | 12 ++++++------ .../bytecodeText/sam/samWrapperInInlineLambda.kt | 1 + .../bytecodeText/sam/samWrapperOfReference.kt | 2 +- .../codegen/bytecodeText/sam/samWrapperRawTypes.kt | 6 ++++++ compiler/testData/codegen/java9/box/kt36984.kt | 4 +++- .../testData/stepping/stepInto/samAdapter.out | 1 + tests/mute-common.csv | 4 ++++ 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index baf2c282898..2762a4abb61 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -213,13 +213,13 @@ class GenerationState private constructor( val fromConfig = configuration.get(JVMConfigurationKeys.SAM_CONVERSIONS) if (fromConfig != null && target >= fromConfig.minJvmTarget) fromConfig - else { - // TODO wait for KT-44844 (properly support 'invokedynamic' in JPS incremental compilation) - // Use JvmClosureGenerationScheme.INDY if - // JVM target is at least JVM_1_8 && - // SamWrapperClassesAreSynthetic language feature is supported + else if ( + target >= JvmClosureGenerationScheme.INDY.minJvmTarget && + languageVersionSettings.supportsFeature(LanguageFeature.SamWrapperClassesAreSynthetic) + ) + JvmClosureGenerationScheme.INDY + else JvmClosureGenerationScheme.CLASS - } } val lambdasScheme = run { diff --git a/compiler/testData/codegen/bytecodeText/sam/samWrapperInInlineLambda.kt b/compiler/testData/codegen/bytecodeText/sam/samWrapperInInlineLambda.kt index b4f83ded013..c3f5e372ea3 100644 --- a/compiler/testData/codegen/bytecodeText/sam/samWrapperInInlineLambda.kt +++ b/compiler/testData/codegen/bytecodeText/sam/samWrapperInInlineLambda.kt @@ -1,3 +1,4 @@ +// SAM_CONVERSIONS: CLASS // FILE: J.java public class J { diff --git a/compiler/testData/codegen/bytecodeText/sam/samWrapperOfReference.kt b/compiler/testData/codegen/bytecodeText/sam/samWrapperOfReference.kt index b0e5071ab8c..23c85c47db3 100644 --- a/compiler/testData/codegen/bytecodeText/sam/samWrapperOfReference.kt +++ b/compiler/testData/codegen/bytecodeText/sam/samWrapperOfReference.kt @@ -1,3 +1,4 @@ +// SAM_CONVERSIONS: CLASS // This optimization is only done by the JVM_IR backend. // IGNORE_BACKEND: JVM // FILE: JFoo.java @@ -17,7 +18,6 @@ fun test() { JFoo.foo(A()::f) } -// Referenced function called from run(), no wrapper class generated: // 1 NEW A // 2 NEW // 0 INVOKEINTERFACE diff --git a/compiler/testData/codegen/bytecodeText/sam/samWrapperRawTypes.kt b/compiler/testData/codegen/bytecodeText/sam/samWrapperRawTypes.kt index c8886a50cf1..af728765eea 100644 --- a/compiler/testData/codegen/bytecodeText/sam/samWrapperRawTypes.kt +++ b/compiler/testData/codegen/bytecodeText/sam/samWrapperRawTypes.kt @@ -25,5 +25,11 @@ inline fun inlineFun() { // There should be no generic information in the SAM wrappers. // 0 declaration: void \(kotlin.jvm.functions.Function1<.*, .*>\) // 0 declaration: function extends kotlin.jvm.functions.Function1<.*, .*> + +// JVM_TEMPLATES // 2 private final synthetic Lkotlin/jvm/functions/Function1; function // 2 \(Lkotlin/jvm/functions/Function1;\)V + +// JVM_IR_TEMPLATES +// 1 private final synthetic Lkotlin/jvm/functions/Function1; function +// 1 \(Lkotlin/jvm/functions/Function1;\)V diff --git a/compiler/testData/codegen/java9/box/kt36984.kt b/compiler/testData/codegen/java9/box/kt36984.kt index 2d7b725c713..1488adc42b7 100644 --- a/compiler/testData/codegen/java9/box/kt36984.kt +++ b/compiler/testData/codegen/java9/box/kt36984.kt @@ -1,4 +1,6 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM_IR +// ^ JVM_IR back-end generates SAM conversion with invokedynamic // WITH_RUNTIME fun box(): String { @@ -13,4 +15,4 @@ fun box(): String { throw Exception("!samJavaClass.isAnonymousClass(): '${samJavaClass.name}'") return "OK" -} \ No newline at end of file +} diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/samAdapter.out b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/samAdapter.out index b7499b8d4ab..d794677211d 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/samAdapter.out +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepInto/samAdapter.out @@ -1,3 +1,4 @@ +// IGNORE_BACKEND: JVM_IR LineBreakpoint created at samAdapter.kt:6 Run Java Connected to the target VM diff --git a/tests/mute-common.csv b/tests/mute-common.csv index bf13f1265df..0135912db41 100644 --- a/tests/mute-common.csv +++ b/tests/mute-common.csv @@ -103,3 +103,7 @@ org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.Scri org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.Script.testInnerClasses, KT-44472,, org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.testDelegatedNested, KT-44472,, org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.testDelegation, KT-44472,, +org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodAdded, KT-44844 fixed in IDEA 212,, +org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodAddedSamAdapter, KT-44844 fixed in IDEA 212,, +org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodSignatureChanged, KT-44844 fixed in IDEA 212,, +org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodSignatureChangedSamAdapter, KT-44844 fixed in IDEA 212,,