File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed
compiler/tests-common/org/jetbrains/kotlin/codegen
core/reflection.jvm/src/kotlin/reflect/jvm/internal Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 26
26
import org .jetbrains .annotations .Nullable ;
27
27
import org .jetbrains .kotlin .cli .jvm .compiler .KotlinCoreEnvironment ;
28
28
import org .jetbrains .kotlin .fileClasses .JvmFileClassUtil ;
29
+ import org .jetbrains .kotlin .load .java .JvmAbi ;
29
30
import org .jetbrains .kotlin .psi .KtDeclaration ;
30
31
import org .jetbrains .kotlin .psi .KtFile ;
31
32
import org .jetbrains .kotlin .psi .KtNamedFunction ;
@@ -159,6 +160,23 @@ protected void blackBox() {
159
160
System .out .println (generateToText ());
160
161
throw ExceptionUtilsKt .rethrow (e );
161
162
}
163
+ finally {
164
+ clearReflectionCache (generatedClassLoader );
165
+ }
166
+ }
167
+ }
168
+
169
+ private static void clearReflectionCache (@ NotNull ClassLoader classLoader ) {
170
+ try {
171
+ Class <?> klass = classLoader .loadClass (JvmAbi .REFLECTION_FACTORY_IMPL .asSingleFqName ().asString ());
172
+ Method method = klass .getDeclaredMethod ("clearCaches" );
173
+ method .invoke (null );
174
+ }
175
+ catch (ClassNotFoundException e ) {
176
+ // This is OK for a test without kotlin-reflect in the dependencies
177
+ }
178
+ catch (Exception e ) {
179
+ throw ExceptionUtilsKt .rethrow (e );
162
180
}
163
181
}
164
182
Original file line number Diff line number Diff line change @@ -105,4 +105,11 @@ private static KDeclarationContainerImpl getOwner(CallableReference reference) {
105
105
KDeclarationContainer owner = reference .getOwner ();
106
106
return owner instanceof KDeclarationContainerImpl ? ((KDeclarationContainerImpl ) owner ) : EmptyContainerForLocal .INSTANCE ;
107
107
}
108
+
109
+ // Misc
110
+
111
+ public static void clearCaches () {
112
+ KClassCacheKt .clearKClassCache ();
113
+ ModuleByClassLoaderKt .clearModuleByClassLoaderCache ();
114
+ }
108
115
}
Original file line number Diff line number Diff line change @@ -64,3 +64,7 @@ internal fun <T : Any> getOrCreateKotlinClass(jClass: Class<T>): KClassImpl<T> {
64
64
K_CLASS_CACHE = K_CLASS_CACHE .plus(name, WeakReference (newKClass))
65
65
return newKClass
66
66
}
67
+
68
+ internal fun clearKClassCache () {
69
+ K_CLASS_CACHE = HashPMap .empty()
70
+ }
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ private class WeakClassLoaderBox(classLoader: ClassLoader) {
41
41
identityHashCode
42
42
43
43
override fun toString () =
44
- ref.get()?.let { it. toString() } ? : " <null>"
44
+ ref.get()?.toString() ? : " <null>"
45
45
}
46
46
47
47
internal fun Class <* >.getOrCreateModule (): RuntimeModuleData {
@@ -70,3 +70,7 @@ internal fun Class<*>.getOrCreateModule(): RuntimeModuleData {
70
70
key.temporaryStrongRef = null
71
71
}
72
72
}
73
+
74
+ internal fun clearModuleByClassLoaderCache () {
75
+ moduleByClassLoader.clear()
76
+ }
You can’t perform that action at this time.
0 commit comments