diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-14 18:17:55 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-19 21:13:48 -0400 |
commit | 10fe5a8ca1518381ebfa655be4358276c990508e (patch) | |
tree | c633e98ebc42c9d7873cbf52a84befaf76fd73d7 | |
parent | c095f435b68272d4ae0409ab4c9466145609710e (diff) | |
download | cbt-10fe5a8ca1518381ebfa655be4358276c990508e.tar.gz cbt-10fe5a8ca1518381ebfa655be4358276c990508e.tar.bz2 cbt-10fe5a8ca1518381ebfa655be4358276c990508e.zip |
minor enhancements to classloading
-rw-r--r-- | stage1/ClassLoaderCache.scala | 24 | ||||
-rw-r--r-- | stage1/MultiClassLoader.scala | 12 | ||||
-rw-r--r-- | stage1/Stage1Lib.scala | 2 | ||||
-rw-r--r-- | stage1/URLClassLoader.scala | 11 | ||||
-rw-r--r-- | stage1/resolver.scala | 7 | ||||
-rw-r--r-- | stage2/BuildBuild.scala | 2 |
6 files changed, 38 insertions, 20 deletions
diff --git a/stage1/ClassLoaderCache.scala b/stage1/ClassLoaderCache.scala index 35008f0..05589d1 100644 --- a/stage1/ClassLoaderCache.scala +++ b/stage1/ClassLoaderCache.scala @@ -4,15 +4,15 @@ import java.net._ import java.util.concurrent.ConcurrentHashMap class ClassLoaderCache(logger: Logger){ - val permanent = new KeyLockedLazyCache( + val persistent = new KeyLockedLazyCache( NailgunLauncher.classLoaderCache.asInstanceOf[ConcurrentHashMap[String,AnyRef]], NailgunLauncher.classLoaderCache.asInstanceOf[ConcurrentHashMap[AnyRef,ClassLoader]], - logger + Some(logger) ) val transient = new KeyLockedLazyCache( new ConcurrentHashMap[String,AnyRef], new ConcurrentHashMap[AnyRef,ClassLoader], - logger + Some(logger) ) } @@ -25,21 +25,23 @@ simultaneously without a deadlock. final private[cbt] class KeyLockedLazyCache[Key <: AnyRef,Value <: AnyRef]( keys: ConcurrentHashMap[Key,AnyRef], builds: ConcurrentHashMap[AnyRef,Value], - logger: Logger + logger: Option[Logger] ){ def get( key: Key, value: => Value ): Value = { - val keyObject = keys.synchronized{ + val keyObject = keys.synchronized{ if( ! (keys containsKey key) ){ - logger.resolver("CACHE MISS: " ++ key.toString) - keys.put( key, new LockableKey ) + val keyObject = new LockableKey + logger.foreach(_.resolver("CACHE MISS: " ++ key.toString)) + keys.put( key, keyObject ) + keyObject } else { - logger.resolver("CACHE HIT: " ++ key.toString) + val keyObject = keys get key + logger.foreach(_.resolver("CACHE HIT: " ++ keyObject.toString ++ " -> " ++ key.toString)) + keyObject } - keys get key } import collection.JavaConversions._ - logger.resolver("CACHE: \n" ++ keys.mkString("\n")) - def k = ClassPath(new java.io.File("c")).asInstanceOf[Key] + //logger.resolver("CACHE: \n" ++ keys.mkString("\n")) // synchronizing on key only, so asking for a particular key does // not block the whole cache, but just that cache entry key.synchronized{ diff --git a/stage1/MultiClassLoader.scala b/stage1/MultiClassLoader.scala index de9bd32..6a0f28a 100644 --- a/stage1/MultiClassLoader.scala +++ b/stage1/MultiClassLoader.scala @@ -19,6 +19,16 @@ class MultiClassLoader(parents: Seq[ClassLoader]) extends ClassLoader { }.find(_.isDefined).flatten c.getOrElse( ClassLoader.getSystemClassLoader.loadClass(name) ) } - override def toString = "MultiClassLoader(" ++ parents.mkString(",") ++ ")" + override def toString = ( + scala.Console.BLUE + ++ super.toString + ++ scala.Console.RESET + ++ "(" + ++ ( + if(parents.nonEmpty)( + "\n" ++ parents.map(_.toString).sorted.mkString(",\n").split("\n").map(" "++_).mkString("\n") ++ "\n" + ) else "" + ) ++")" + ) } */ diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index 6a8a0ba..9c204ae 100644 --- a/stage1/Stage1Lib.scala +++ b/stage1/Stage1Lib.scala @@ -46,7 +46,7 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{ /** Create instance of the given class via reflection */ def create(cls: String)(args: Any*)(classLoader: ClassLoader): Any = { - logger.composition( logger.showInvocation("Stage1Lib.create", (classLoader,cls,args)) ) + logger.composition( logger.showInvocation("Stage1Lib.create", (cls,args,classLoader)) ) import scala.reflect.runtime.universe._ val m = runtimeMirror(classLoader) val sym = m.classSymbol(classLoader.loadClass(cls)) diff --git a/stage1/URLClassLoader.scala b/stage1/URLClassLoader.scala index 870f186..fbe7ac8 100644 --- a/stage1/URLClassLoader.scala +++ b/stage1/URLClassLoader.scala @@ -10,13 +10,18 @@ case class URLClassLoader(classPath: ClassPath, parent: ClassLoader) parent ){ override def toString = ( - scala.Console.BLUE ++ "cbt.URLClassLoader" ++ scala.Console.RESET - ++ "(\n " ++ getURLs.map(_.toString).sorted.mkString(",\n ") + scala.Console.BLUE + ++ super.toString + ++ scala.Console.RESET + ++ "(\n" + ++ ( + getURLs.map(_.toString).sorted.mkString(",\n") ++ ( if(getParent() != ClassLoader.getSystemClassLoader()) - ",\n" ++ getParent().toString.split("\n").map(" "++_).mkString("\n") + ",\n" ++ getParent().toString else "" ) + ).split("\n").map(" "++_).mkString("\n") ++ "\n)" ) } diff --git a/stage1/resolver.scala b/stage1/resolver.scala index 8dde321..f7f0321 100644 --- a/stage1/resolver.scala +++ b/stage1/resolver.scala @@ -112,7 +112,7 @@ abstract class Dependency{ if(cacheDependencyClassLoader){ new URLClassLoader( buildClassPath, - classLoaderCache.permanent.get( + classLoaderCache.persistent.get( cachedClassPath.string, cbt.URLClassLoader( classpath, ClassLoader.getSystemClassLoader ) ) @@ -133,8 +133,9 @@ abstract class Dependency{ new Tree(this, (dependencies diff parents).map(_.resolveRecursive(this :: parents))) } - def transitiveDependencies: Seq[Dependency] = { - val deps = dependencies.flatMap(_.resolveRecursive().linearize) + private object transitiveDependenciesCache extends Cache[Seq[Dependency]] + def transitiveDependencies: Seq[Dependency] = transitiveDependenciesCache{ + val deps = (dependencies ++ dependencies.flatMap(_.transitiveDependencies)).distinct val hasInfo = deps.collect{ case d:ArtifactInfo => d } val noInfo = deps.filter{ case _:ArtifactInfo => false diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala index 5e0f5d3..639154c 100644 --- a/stage2/BuildBuild.scala +++ b/stage2/BuildBuild.scala @@ -8,7 +8,7 @@ class BuildBuild(context: Context) extends Build(context){ val managedBuild = { val managedContext = context.copy( cwd = managedBuildDirectory ) val cl = new cbt.URLClassLoader( - classpath, + exportedClasspath, classOf[BuildBuild].getClassLoader // FIXME: this looks wrong. Should be ClassLoader.getSystemClassLoader but that crashes ) lib.create( lib.buildClassName )( managedContext )( cl ).asInstanceOf[Build] |