Skip to content

Commit 92a8ab9

Browse files
committed
Add an "always" cache policy for classloaders
1 parent 8ca0e9b commit 92a8ab9

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/compiler/scala/tools/nsc/PipelineMain.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ class PipelineMainClass(label: String, parallelism: Int, strategy: BuildStrategy
296296
dependency.outlineDone.future
297297

298298

299-
command.settings.YcacheMacroClassLoader.value = "last-modified"
300-
command.settings.YcachePluginClassLoader.value = "last-modified"
299+
command.settings.YcacheMacroClassLoader.value = "always"
300+
command.settings.YcachePluginClassLoader.value = "always"
301301

302302
val groups: List[Group] = {
303303
val isScalaLibrary = files.exists(_.endsWith("Predef.scala"))

src/compiler/scala/tools/nsc/classpath/ZipAndJarFileLookupFactory.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sealed trait ZipAndJarFileLookupFactory {
3939
closeableRegistry.registerClosable(result)
4040
result
4141
} else {
42-
cache.getOrCreate(List(zipFile.file.toPath), () => createForZipFile(zipFile, settings.releaseValue), closeableRegistry)
42+
cache.getOrCreate(List(zipFile.file.toPath), () => createForZipFile(zipFile, settings.releaseValue), closeableRegistry, checkStamps = true)
4343
}
4444
}
4545

@@ -213,7 +213,7 @@ final class FileBasedCache[T] {
213213
}
214214
private val cache = collection.mutable.Map.empty[Seq[Path], Entry]
215215

216-
def getOrCreate(paths: Seq[Path], create: () => T, closeableRegistry: CloseableRegistry): T = cache.synchronized {
216+
def getOrCreate(paths: Seq[Path], create: () => T, closeableRegistry: CloseableRegistry, checkStamps: Boolean): T = cache.synchronized {
217217
val stamps = paths.map { path =>
218218
val attrs = Files.readAttributes(path, classOf[BasicFileAttributes])
219219
val lastModified = attrs.lastModifiedTime()
@@ -224,7 +224,7 @@ final class FileBasedCache[T] {
224224

225225
cache.get(paths) match {
226226
case Some(e@Entry(cachedStamps, cached)) =>
227-
if (cachedStamps == stamps) {
227+
if (!checkStamps || cachedStamps == stamps) {
228228
// Cache hit
229229
e.referenceCount.incrementAndGet()
230230
closeableRegistry.registerClosable(e.referenceCountDecrementer)

src/compiler/scala/tools/nsc/plugins/Plugins.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ trait Plugins { global: Global =>
6969
* @return
7070
*/
7171
protected def findPluginClassLoader(classpath: Seq[Path]): ClassLoader = {
72-
val disableCache = settings.YcachePluginClassLoader.value == settings.CachePolicy.None.name
72+
val policy = settings.YcachePluginClassLoader.value
73+
val disableCache = policy == settings.CachePolicy.None.name
7374
def newLoader = () => {
7475
val compilerLoader = classOf[Plugin].getClassLoader
7576
val urls = classpath map (_.toURL)
@@ -88,7 +89,7 @@ trait Plugins { global: Global =>
8889
val loader = newLoader()
8990
closeableRegistry.registerClosable(loader)
9091
loader
91-
} else pluginClassLoadersCache.getOrCreate(classpath.map(_.jfile.toPath()), newLoader, closeableRegistry)
92+
} else pluginClassLoadersCache.getOrCreate(classpath.map(_.jfile.toPath()), newLoader, closeableRegistry, policy == settings.CachePolicy.LastModified.name)
9293
}
9394

9495
protected lazy val roughPluginsList: List[Plugin] = loadRoughPluginsList()
@@ -181,7 +182,8 @@ trait Plugins { global: Global =>
181182
ScalaClassLoader.fromURLs(classpath, getClass.getClassLoader)
182183
}
183184

184-
val disableCache = settings.YcacheMacroClassLoader.value == settings.CachePolicy.None.name
185+
val policy = settings.YcacheMacroClassLoader.value
186+
val disableCache = policy == settings.CachePolicy.None.name
185187
if (disableCache) newLoader()
186188
else {
187189
import scala.tools.nsc.io.Jar
@@ -196,7 +198,7 @@ trait Plugins { global: Global =>
196198
perRunCaches.recordClassloader(newLoader())
197199
} else {
198200
val locations = urlsAndFiles.map(t => Path(t._2.file))
199-
Macros.macroClassLoadersCache.getOrCreate(locations.map(_.jfile.toPath()), newLoader, closeableRegistry)
201+
Macros.macroClassLoadersCache.getOrCreate(locations.map(_.jfile.toPath()), newLoader, closeableRegistry, checkStamps = policy == settings.CachePolicy.LastModified.name)
200202
}
201203
}
202204
}

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ trait ScalaSettings extends AbsScalaSettings
260260
def setting(style: String, styleLong: String) = ChoiceSetting(s"-Ycache-$style-class-loader", "policy", s"Policy for caching class loaders for $styleLong that are dynamically loaded.", values.map(_.name), None.name, values.map(_.help))
261261
object None extends CachePolicy("none", "Don't cache class loader")
262262
object LastModified extends CachePolicy("last-modified", "Cache class loader, using file last-modified time to invalidate")
263+
object Always extends CachePolicy("always", "Cache class loader with no invalidation")
263264
// TODO Jorge to add new policy. Think about whether there is a benefit to the user on offering this as a separate policy or unifying with the previous one.
264265
// object ZipMetadata extends CachePolicy("zip-metadata", "Cache classloade, using file last-modified time, then ZIP file metadata to invalidate")
265-
def values: List[CachePolicy] = List(None, LastModified)
266+
def values: List[CachePolicy] = List(None, LastModified, Always)
266267
}
267268

268269
object optChoices extends MultiChoiceEnumeration {

0 commit comments

Comments
 (0)