Introduce KClass-based cache for KPackageFragment

* It is a heavy-weight object that is hard to compute
* It is being constructed each type _cached_ method ref is used in equals/hashCode
* Module name is deliberately ignored, corresponding doc is added where appropriate 

#KT-48136

Merge-request: KT-MR-6817
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
This commit is contained in:
Vsevolod Tolstopyatov
2022-08-08 15:57:56 +00:00
committed by Space
parent 28310eb970
commit c6cbab43f7
8 changed files with 63 additions and 6 deletions
@@ -41267,6 +41267,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("jvmKPackageCaching.kt")
public void testJvmKPackageCaching() throws Exception {
runTest("compiler/testData/codegen/box/reflection/jvmKPackageCaching.kt");
}
@Test
@TestMetadata("jvmKTypeCaching.kt")
public void testJvmKTypeCaching() throws Exception {
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM_IR
// FULL_JDK
// WITH_REFLECT
import kotlin.jvm.internal.*
class A
fun box(): String {
val pckg = Reflection.getOrCreateKotlinPackage(A::class.java)
System.gc()
val pckg2 = Reflection.getOrCreateKotlinPackage(A::class.java)
if (pckg === pckg2) return "OK"
return "Fail"
}
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM_IR
// FULL_JDK
// WITH_REFLECT
class A
fun box(): String {
val clz = A::class
System.gc()
val clz2 = A::class
if (clz === clz2) return "OK"
return "Fail"
}
@@ -41267,6 +41267,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("jvmKPackageCaching.kt")
public void testJvmKPackageCaching() throws Exception {
runTest("compiler/testData/codegen/box/reflection/jvmKPackageCaching.kt");
}
@Test
@TestMetadata("jvmKTypeCaching.kt")
public void testJvmKTypeCaching() throws Exception {
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
@TestDataPath("$PROJECT_ROOT")