Use same classloader for loading JS and JVM compilers
This commit is contained in:
@@ -44,8 +44,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
|
|
||||||
public class MockLibraryUtil {
|
public class MockLibraryUtil {
|
||||||
|
|
||||||
private static SoftReference<Class<?>> compiler2JVMClassRef = new SoftReference<Class<?>>(null);
|
private static SoftReference<ClassLoader> compilerClassLoader = new SoftReference<ClassLoader>(null);
|
||||||
private static SoftReference<Class<?>> compiler2JSClassRef = new SoftReference<Class<?>>(null);
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static File compileLibraryToJar(
|
public static File compileLibraryToJar(
|
||||||
@@ -199,32 +198,33 @@ public class MockLibraryUtil {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static synchronized Class<?> getCompiler2JVMClass() {
|
private static synchronized Class<?> getCompiler2JVMClass() {
|
||||||
Class<?> compilerClass = compiler2JVMClassRef.get();
|
return loadCompilerClass(K2JVMCompiler.class.getName());
|
||||||
if (compilerClass == null) {
|
|
||||||
compilerClass = getCompilerClass(K2JVMCompiler.class.getName());
|
|
||||||
compiler2JVMClassRef = new SoftReference<Class<?>>(compilerClass);
|
|
||||||
}
|
|
||||||
return compilerClass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static synchronized Class<?> getCompiler2JSClass() {
|
private static synchronized Class<?> getCompiler2JSClass() {
|
||||||
Class<?> compilerClass = compiler2JSClassRef.get();
|
return loadCompilerClass(K2JSCompiler.class.getName());
|
||||||
if (compilerClass == null) {
|
}
|
||||||
compilerClass = getCompilerClass(K2JSCompiler.class.getName());
|
|
||||||
compiler2JSClassRef = new SoftReference<Class<?>>(compilerClass);
|
private static synchronized Class<?> loadCompilerClass(String compilerClassName) {
|
||||||
|
try {
|
||||||
|
ClassLoader classLoader = compilerClassLoader.get();
|
||||||
|
if (classLoader == null) {
|
||||||
|
classLoader = createCompilerClassLoader();
|
||||||
|
compilerClassLoader = new SoftReference<ClassLoader>(classLoader);
|
||||||
|
}
|
||||||
|
return classLoader.loadClass(compilerClassName);
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
throw UtilsPackage.rethrow(e);
|
||||||
}
|
}
|
||||||
return compilerClass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static synchronized Class<?> getCompilerClass(String compilerClassName) {
|
private static synchronized ClassLoader createCompilerClassLoader() {
|
||||||
try {
|
try {
|
||||||
File kotlinCompilerJar = new File(PathUtil.getKotlinPathsForDistDirectory().getLibPath(), "kotlin-compiler.jar");
|
File kotlinCompilerJar = new File(PathUtil.getKotlinPathsForDistDirectory().getLibPath(), "kotlin-compiler.jar");
|
||||||
ClassLoader classLoader =
|
return ClassPreloadingUtils.preloadClasses(Collections.singletonList(kotlinCompilerJar), 4096, null, null, null);
|
||||||
ClassPreloadingUtils.preloadClasses(Collections.singletonList(kotlinCompilerJar), 4096, null, null, null);
|
|
||||||
|
|
||||||
return classLoader.loadClass(compilerClassName);
|
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
throw UtilsPackage.rethrow(e);
|
throw UtilsPackage.rethrow(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user