Ant task: use preloader instead of AntClassLoader

Speeds up AntTaskJvmTest by 50%
This commit is contained in:
Alexander Udalov
2015-01-03 12:08:12 +03:00
parent 511b19fcfd
commit cd79c4573d
3 changed files with 8 additions and 6 deletions
+1
View File
@@ -9,5 +9,6 @@
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="ant-1.7" level="project" /> <orderEntry type="library" name="ant-1.7" level="project" />
<orderEntry type="library" name="kotlin-runtime" level="project" /> <orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="preloader" />
</component> </component>
</module> </module>
@@ -25,13 +25,13 @@ import org.apache.tools.ant.types.Commandline
import java.io.PrintStream import java.io.PrintStream
import org.apache.tools.ant.AntClassLoader import org.apache.tools.ant.AntClassLoader
import java.lang.ref.SoftReference import java.lang.ref.SoftReference
import org.apache.tools.ant.Project import org.jetbrains.jet.preloading.ClassPreloadingUtils
import java.net.JarURLConnection import java.net.JarURLConnection
object CompilerClassLoaderHolder { object CompilerClassLoaderHolder {
private var classLoaderRef = SoftReference<ClassLoader?>(null) private var classLoaderRef = SoftReference<ClassLoader?>(null)
synchronized fun getOrCreateClassLoader(project: Project?): ClassLoader { synchronized fun getOrCreateClassLoader(): ClassLoader {
val cached = classLoaderRef.get() val cached = classLoaderRef.get()
if (cached != null) return cached if (cached != null) return cached
@@ -49,7 +49,7 @@ object CompilerClassLoaderHolder {
throw IllegalStateException("kotlin-compiler.jar is not found in the directory of Kotlin Ant task") throw IllegalStateException("kotlin-compiler.jar is not found in the directory of Kotlin Ant task")
} }
val classLoader = AntClassLoader(myLoader, project, Path(project, compilerJarPath.path), /* parentFirst = */ false) val classLoader = ClassPreloadingUtils.preloadClasses(listOf(compilerJarPath), 4096, myLoader, null)
classLoaderRef = SoftReference(classLoader) classLoaderRef = SoftReference(classLoader)
return classLoader return classLoader
@@ -112,7 +112,7 @@ public abstract class KotlinCompilerBaseTask : Task() {
final override fun execute() { final override fun execute() {
fillArguments() fillArguments()
val compilerClass = CompilerClassLoaderHolder.getOrCreateClassLoader(project).loadClass(compilerFqName) val compilerClass = CompilerClassLoaderHolder.getOrCreateClassLoader().loadClass(compilerFqName)
val compiler = compilerClass.newInstance() val compiler = compilerClass.newInstance()
val exec = compilerClass.getMethod("execFullPathsInMessages", javaClass<PrintStream>(), javaClass<Array<String>>()) val exec = compilerClass.getMethod("execFullPathsInMessages", javaClass<PrintStream>(), javaClass<Array<String>>())
+3 -2
View File
@@ -641,7 +641,8 @@
<compilerarg value="-Xlint:all"/> <compilerarg value="-Xlint:all"/>
<classpath> <classpath>
<file file="${kotlin-home}/lib/${compiler.manifest.class.path}"/> <file file="${kotlin-home}/lib/${compiler.manifest.class.path}"/>
<fileset dir="${dependencies.dir}/ant-1.7/lib" includes="ant.jar"/> <pathelement location="${dependencies.dir}/ant-1.7/lib/ant.jar"/>
<pathelement location="${kotlin-home}/lib/kotlin-preloader.jar"/>
</classpath> </classpath>
</javac2> </javac2>
@@ -657,7 +658,7 @@
<attribute name="Implementation-Title" value="${manifest.impl.title.kotlin.compiler.ant.task}"/> <attribute name="Implementation-Title" value="${manifest.impl.title.kotlin.compiler.ant.task}"/>
<attribute name="Implementation-Version" value="${build.number}"/> <attribute name="Implementation-Version" value="${build.number}"/>
<attribute name="Class-Path" value="${compiler.manifest.class.path}"/> <attribute name="Class-Path" value="${compiler.manifest.class.path} kotlin-preloader.jar"/>
</manifest> </manifest>
</jar> </jar>
</target> </target>