@@ -19,6 +19,7 @@ private val logger = KotlinLogging.logger {}
1919
2020//  TODO usvm-sbft-refactoring: copied from `usvm/usvm-jvm/test`, extract this class back to USVM project
2121class  JcContainer  private constructor(
22+     usePersistence :  Boolean ,
2223    classpath :  List <File >,
2324    machineOptions :  UMachineOptions ,
2425    builder :  JcSettings .() ->  Unit ,
@@ -29,8 +30,27 @@ class JcContainer private constructor(
2930    val  runner:  UTestConcreteExecutor 
3031
3132    init  {
33+         val  cpPath =  classpath.map { it.absolutePath }.sorted()
34+ 
35+         /* *
36+          * Persist jacodb cp to achieve: 
37+          * 1. Faster concrete executor initialization 
38+          * 2. Faster analysis for classes from the same cp 
39+          * */  
40+         val  persistenceLocation =  if  (usePersistence) {
41+             " jcdb-persistence-${cpPath.hashCode()} " 
42+         } else  {
43+             null 
44+         }
45+ 
3246        val  (db, cp) =  runBlocking {
33-             val  db =  jacodb(builder)
47+             val  db =  jacodb {
48+                 builder()
49+ 
50+                 if  (persistenceLocation !=  null ) {
51+                     persistent(location =  persistenceLocation, clearOnStart =  false )
52+                 }
53+             }
3454            val  cp =  db.classpathWithApproximations(classpath, listOf (UnknownClasses ))
3555            db to cp
3656        }
@@ -39,8 +59,9 @@ class JcContainer private constructor(
3959        this .machine =  JcMachine (cp, machineOptions)
4060        this .runner =  UTestConcreteExecutor (
4161            JcRuntimeTraceInstrumenterFactory ::class ,
42-             classpath.map { it.absolutePath } ,
62+             cpPath ,
4363            cp,
64+             persistenceLocation,
4465            CONTEST_TEST_EXECUTION_TIMEOUT 
4566        )
4667        runBlocking {
@@ -61,6 +82,7 @@ class JcContainer private constructor(
6182        private  val  cache =  HashMap <Pair <List <File >, UMachineOptions > , JcContainer > ()
6283
6384        operator  fun  invoke (
85+             usePersistence :  Boolean ,
6486            classpath :  List <File >,
6587            machineOptions :  UMachineOptions ,
6688            builder :  JcSettings .() ->  Unit ,
@@ -70,7 +92,7 @@ class JcContainer private constructor(
7092                //  TODO usvm-sbft: right now max cache size is 1, do we need to increase it?
7193                logger.info { " JcContainer cache miss" 
7294                close()
73-                 JcContainer (classpath, machineOptions, builder).also  { cache[cacheKey] =  it }
95+                 JcContainer (usePersistence,  classpath, machineOptions, builder).also  { cache[cacheKey] =  it }
7496            }
7597        }
7698
0 commit comments