Use preloader in the IDE
This commit is contained in:
Generated
+1
@@ -32,6 +32,7 @@
|
|||||||
<element id="module-output" name="ide-compiler-runner" />
|
<element id="module-output" name="ide-compiler-runner" />
|
||||||
<element id="module-output" name="cli-common" />
|
<element id="module-output" name="cli-common" />
|
||||||
<element id="module-output" name="util" />
|
<element id="module-output" name="util" />
|
||||||
|
<element id="module-output" name="preloader" />
|
||||||
</element>
|
</element>
|
||||||
</element>
|
</element>
|
||||||
</element>
|
</element>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<orderEntry type="library" name="idea-full" level="project" />
|
<orderEntry type="library" name="idea-full" level="project" />
|
||||||
<orderEntry type="module" module-name="cli-common" />
|
<orderEntry type="module" module-name="cli-common" />
|
||||||
<orderEntry type="module" module-name="util" />
|
<orderEntry type="module" module-name="util" />
|
||||||
|
<orderEntry type="module" module-name="preloader" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.compiler.runner;
|
|||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.common.messages.*;
|
import org.jetbrains.jet.cli.common.messages.*;
|
||||||
|
import org.jetbrains.jet.preloading.ClassPreloadingUtils;
|
||||||
import org.jetbrains.jet.utils.KotlinPaths;
|
import org.jetbrains.jet.utils.KotlinPaths;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -35,7 +36,7 @@ import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.*;
|
|||||||
|
|
||||||
public class CompilerRunnerUtil {
|
public class CompilerRunnerUtil {
|
||||||
|
|
||||||
private static SoftReference<URLClassLoader> ourClassLoaderRef = new SoftReference<URLClassLoader>(null);
|
private static SoftReference<ClassLoader> ourClassLoaderRef = new SoftReference<ClassLoader>(null);
|
||||||
|
|
||||||
public static List<File> kompilerClasspath(KotlinPaths paths, MessageCollector messageCollector) {
|
public static List<File> kompilerClasspath(KotlinPaths paths, MessageCollector messageCollector) {
|
||||||
File libs = paths.getLibPath();
|
File libs = paths.getLibPath();
|
||||||
@@ -50,11 +51,26 @@ public class CompilerRunnerUtil {
|
|||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static URLClassLoader getOrCreateClassLoader(KotlinPaths paths, MessageCollector messageCollector) {
|
public static ClassLoader getOrCreatePreloader(KotlinPaths paths, MessageCollector messageCollector) {
|
||||||
URLClassLoader answer = ourClassLoaderRef.get();
|
ClassLoader answer = ourClassLoaderRef.get();
|
||||||
|
if (answer == null) {
|
||||||
|
try {
|
||||||
|
int estimatedClassNumber = 4096;
|
||||||
|
answer = ClassPreloadingUtils.preloadClasses(kompilerClasspath(paths, messageCollector), estimatedClassNumber, null);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
ourClassLoaderRef = new SoftReference<ClassLoader>(answer);
|
||||||
|
}
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClassLoader getOrCreateClassLoader(KotlinPaths paths, MessageCollector messageCollector) {
|
||||||
|
ClassLoader answer = ourClassLoaderRef.get();
|
||||||
if (answer == null) {
|
if (answer == null) {
|
||||||
answer = createClassloader(paths, messageCollector);
|
answer = createClassloader(paths, messageCollector);
|
||||||
ourClassLoaderRef = new SoftReference<URLClassLoader>(answer);
|
ourClassLoaderRef = new SoftReference<ClassLoader>(answer);
|
||||||
}
|
}
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
@@ -90,9 +106,11 @@ public class CompilerRunnerUtil {
|
|||||||
|
|
||||||
public static Object invokeExecMethod(
|
public static Object invokeExecMethod(
|
||||||
String className, String[] arguments, CompilerEnvironment environment,
|
String className, String[] arguments, CompilerEnvironment environment,
|
||||||
MessageCollector messageCollector, PrintStream out
|
MessageCollector messageCollector, PrintStream out, boolean usePreloader
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
URLClassLoader loader = getOrCreateClassLoader(environment.getKotlinPaths(), messageCollector);
|
ClassLoader loader = usePreloader
|
||||||
|
? getOrCreatePreloader(environment.getKotlinPaths(), messageCollector)
|
||||||
|
: getOrCreateClassLoader(environment.getKotlinPaths(), messageCollector);
|
||||||
Class<?> kompiler = Class.forName(className, true, loader);
|
Class<?> kompiler = Class.forName(className, true, loader);
|
||||||
Method exec = kompiler.getMethod("exec", PrintStream.class, String[].class);
|
Method exec = kompiler.getMethod("exec", PrintStream.class, String[].class);
|
||||||
return exec.invoke(kompiler.newInstance(), out, arguments);
|
return exec.invoke(kompiler.newInstance(), out, arguments);
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ public class KotlinCompilerRunner {
|
|||||||
messageCollector.report(CompilerMessageSeverity.INFO,
|
messageCollector.report(CompilerMessageSeverity.INFO,
|
||||||
"Invoking in-process compiler " + compilerClassName + " with arguments " + Arrays.asList(arguments),
|
"Invoking in-process compiler " + compilerClassName + " with arguments " + Arrays.asList(arguments),
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
Object rc = CompilerRunnerUtil.invokeExecMethod(compilerClassName, arguments, environment, messageCollector, out);
|
Object rc = CompilerRunnerUtil.invokeExecMethod(compilerClassName, arguments, environment,
|
||||||
|
messageCollector, out, /*usePreloader=*/true);
|
||||||
// exec() returns a K2JVMCompiler.ExitCode object, that class is not accessible here,
|
// exec() returns a K2JVMCompiler.ExitCode object, that class is not accessible here,
|
||||||
// so we take it's contents through reflection
|
// so we take it's contents through reflection
|
||||||
return CompilerRunnerUtil.getReturnCodeFromObject(rc);
|
return CompilerRunnerUtil.getReturnCodeFromObject(rc);
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ public final class K2JSCompiler implements TranslatingCompiler {
|
|||||||
File outDir = environment.getOutput();
|
File outDir = environment.getOutput();
|
||||||
File outFile = new File(outDir, module.getName() + ".js");
|
File outFile = new File(outDir, module.getName() + ".js");
|
||||||
String[] commandLineArgs = constructArguments(module, outFile);
|
String[] commandLineArgs = constructArguments(module, outFile);
|
||||||
Object rc = invokeExecMethod("org.jetbrains.jet.cli.js.K2JSCompiler", commandLineArgs, environment, messageCollector, out);
|
// No preloading for in-process compiler
|
||||||
|
Object rc = invokeExecMethod("org.jetbrains.jet.cli.js.K2JSCompiler", commandLineArgs, environment, messageCollector, out, false);
|
||||||
|
|
||||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||||
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(outDir);
|
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(outDir);
|
||||||
|
|||||||
Reference in New Issue
Block a user