aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-11-27 16:00:58 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-02-01 23:10:49 -0500
commite56f8afa03035140280bc8d3d878ad225def381e (patch)
treec04ee4dee271ebf84777c0b47a639fde475fa9bf /test
parent00d9485f5597fdecc58461bd81df635fafbe494f (diff)
downloadcbt-e56f8afa03035140280bc8d3d878ad225def381e.tar.gz
cbt-e56f8afa03035140280bc8d3d878ad225def381e.tar.bz2
cbt-e56f8afa03035140280bc8d3d878ad225def381e.zip
replace flawed concurrent hashmap cache with consistent replacement
The concurrent hashmap approach to classloader caching was flawed. Assume you have two concurrently running builds A and B and projects P2 and P3 depending on project P1. And assume a time sequence where A compiles P1, then compiles P2, then P1’s sources change, then B compiles P1, then A compiles P3. At the end P2 and P3 will have different versions of P1 as their parent classloaders. This is inconsistent. The easiest way to work around this is making sure only one thread is changing the classloader cache during it’s entire run. This would mean either no concurrency or what we have done here, which is letting threads work on a copy of the cache and replace the original cache in the end using an atomic operation. This means the thread that finishes last wins, but for caching that’s fine. Worst case some things aren’t cached in a concurrent execution. This change also means that we don’t need concurrent hashmaps for the classloader cache anymore since no two theads will access the same hashmap. We still need a concurrent hashmap for the class caches inside of the classloaders as multiple threads can access the same classloaders.
Diffstat (limited to 'test')
-rw-r--r--test/test.scala6
1 files changed, 3 insertions, 3 deletions
diff --git a/test/test.scala b/test/test.scala
index 56ad3b1..ae6c301 100644
--- a/test/test.scala
+++ b/test/test.scala
@@ -1,9 +1,9 @@
package cbt
package test
-import java.util.concurrent.ConcurrentHashMap
import java.io.File
import java.nio.file._
import java.net.URL
+import java.util.{Iterator=>_,_}
import scala.concurrent._
import scala.concurrent.duration._
// micro framework
@@ -115,8 +115,8 @@ object Main{
start,
cbtHasChanged,
null,
- new ConcurrentHashMap[AnyRef,AnyRef],
- new java.util.concurrent.ConcurrentHashMap[AnyRef,AnyRef],
+ new HashMap[AnyRef,AnyRef],
+ new HashMap[AnyRef,AnyRef],
cache,
cbtHome,
cbtHome,