From 0b3fefdca067ef313abff659f9d94b2ae680b77f Mon Sep 17 00:00:00 2001 From: Valentyn Sobol Date: Tue, 11 Feb 2025 00:01:44 +0300 Subject: [PATCH] [jacodb-storage, jacodb-core] Move pluggable caches to jacodb-storage Pluggable caches API moved to the jacodb-storage-api module, implementations are in the jacodb-storage module. The jacodb-storage module has compileOnly dependencies on the libraries providing caches. So to use caches without dependency on the jacodb-core module, one should define particular dependency of the caching library, Guava or Xodus. --- .../src/main/kotlin/org/jacodb/api/jvm/Settings.kt | 3 +-- .../jacodb/api}/caches/PluggableCacheProvider.kt | 2 +- .../org/jacodb/api}/caches/PluggableCaches.kt | 5 +++-- .../performance/caches/PluggableCacheBenchmarks.kt | 4 ++-- .../impl/features/classpaths/ClasspathCache.kt | 6 +++--- .../jacodb/impl/storage/AbstractJcDbPersistence.kt | 8 ++++---- .../jacodb/testing/caches/PluggableCacheTest.kt | 2 +- jacodb-storage/build.gradle.kts | 3 ++- .../org/jacodb/impl/caches/guava/GuavaCaches.kt | 13 ++++++------- .../org/jacodb/impl/caches/xodus/XodusCaches.kt | 14 +++++++------- .../org.jacodb.api.caches.PluggableCacheProvider | 0 11 files changed, 30 insertions(+), 30 deletions(-) rename {jacodb-core/src/main/kotlin/org/jacodb/impl => jacodb-api-storage/src/main/kotlin/org/jacodb/api}/caches/PluggableCacheProvider.kt (98%) rename {jacodb-core/src/main/kotlin/org/jacodb/impl => jacodb-api-storage/src/main/kotlin/org/jacodb/api}/caches/PluggableCaches.kt (96%) rename {jacodb-core => jacodb-storage}/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt (88%) rename {jacodb-core => jacodb-storage}/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt (84%) rename jacodb-core/src/main/resources/META-INF/services/org.jacodb.impl.caches.PluggableCacheProvider => jacodb-storage/src/main/resources/META-INF/services/org.jacodb.api.caches.PluggableCacheProvider (100%) diff --git a/jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/Settings.kt b/jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/Settings.kt index 1bf90d5df..42b361aa4 100644 --- a/jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/Settings.kt +++ b/jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/Settings.kt @@ -18,6 +18,7 @@ package org.jacodb.api.jvm import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList +import org.jacodb.api.caches.ValueStoreType import java.io.File import java.time.Duration @@ -186,8 +187,6 @@ data class JcCacheSegmentSettings( val expiration: Duration = Duration.ofMinutes(1) ) -enum class ValueStoreType { WEAK, SOFT, STRONG } - class JcCacheSettings { var cacheSpiId: String? = null var classes: JcCacheSegmentSettings = JcCacheSegmentSettings() diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/caches/PluggableCacheProvider.kt b/jacodb-api-storage/src/main/kotlin/org/jacodb/api/caches/PluggableCacheProvider.kt similarity index 98% rename from jacodb-core/src/main/kotlin/org/jacodb/impl/caches/PluggableCacheProvider.kt rename to jacodb-api-storage/src/main/kotlin/org/jacodb/api/caches/PluggableCacheProvider.kt index 4020dc887..8ac05d7a6 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/caches/PluggableCacheProvider.kt +++ b/jacodb-api-storage/src/main/kotlin/org/jacodb/api/caches/PluggableCacheProvider.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jacodb.impl.caches +package org.jacodb.api.caches import org.jacodb.api.spi.CommonSPI import org.jacodb.api.spi.SPILoader diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/caches/PluggableCaches.kt b/jacodb-api-storage/src/main/kotlin/org/jacodb/api/caches/PluggableCaches.kt similarity index 96% rename from jacodb-core/src/main/kotlin/org/jacodb/impl/caches/PluggableCaches.kt rename to jacodb-api-storage/src/main/kotlin/org/jacodb/api/caches/PluggableCaches.kt index 5a7e7151e..fa42e8312 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/caches/PluggableCaches.kt +++ b/jacodb-api-storage/src/main/kotlin/org/jacodb/api/caches/PluggableCaches.kt @@ -14,11 +14,12 @@ * limitations under the License. */ -package org.jacodb.impl.caches +package org.jacodb.api.caches -import org.jacodb.api.jvm.ValueStoreType import java.time.Duration +enum class ValueStoreType { WEAK, SOFT, STRONG } + class PluggableCacheException(message: String) : RuntimeException(message) interface PluggableCache { diff --git a/jacodb-benchmarks/src/test/kotlin/org/jacodb/testing/performance/caches/PluggableCacheBenchmarks.kt b/jacodb-benchmarks/src/test/kotlin/org/jacodb/testing/performance/caches/PluggableCacheBenchmarks.kt index d44a0d228..142621acb 100644 --- a/jacodb-benchmarks/src/test/kotlin/org/jacodb/testing/performance/caches/PluggableCacheBenchmarks.kt +++ b/jacodb-benchmarks/src/test/kotlin/org/jacodb/testing/performance/caches/PluggableCacheBenchmarks.kt @@ -17,8 +17,8 @@ package org.jacodb.testing.performance.caches import kotlinx.benchmark.Blackhole -import org.jacodb.api.jvm.ValueStoreType -import org.jacodb.impl.caches.PluggableCache +import org.jacodb.api.caches.PluggableCache +import org.jacodb.api.caches.ValueStoreType import org.jacodb.impl.caches.xodus.XODUS_CACHE_PROVIDER_ID import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.BenchmarkMode diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/ClasspathCache.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/ClasspathCache.kt index b7ceb2731..22c184f38 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/ClasspathCache.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/ClasspathCache.kt @@ -17,6 +17,9 @@ package org.jacodb.impl.features.classpaths import mu.KLogging +import org.jacodb.api.caches.PluggableCache +import org.jacodb.api.caches.PluggableCacheProvider +import org.jacodb.api.caches.PluggableCacheStats import org.jacodb.api.jvm.JcCacheSegmentSettings import org.jacodb.api.jvm.JcCacheSettings import org.jacodb.api.jvm.JcClassType @@ -35,9 +38,6 @@ import org.jacodb.api.jvm.cfg.JcInst import org.jacodb.api.jvm.cfg.JcInstList import org.jacodb.api.jvm.cfg.JcRawInst import org.jacodb.api.jvm.ext.JAVA_OBJECT -import org.jacodb.impl.caches.PluggableCache -import org.jacodb.impl.caches.PluggableCacheProvider -import org.jacodb.impl.caches.PluggableCacheStats import org.jacodb.impl.caches.xodus.XODUS_CACHE_PROVIDER_ID import org.jacodb.impl.features.classpaths.AbstractJcInstResult.JcFlowGraphResultImpl import org.jacodb.impl.features.classpaths.AbstractJcInstResult.JcInstListResultImpl diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/storage/AbstractJcDbPersistence.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/storage/AbstractJcDbPersistence.kt index 7ac84fdf4..0f5e6fbce 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/storage/AbstractJcDbPersistence.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/storage/AbstractJcDbPersistence.kt @@ -16,12 +16,12 @@ package org.jacodb.impl.storage +import org.jacodb.api.caches.PluggableCache +import org.jacodb.api.caches.PluggableCacheProvider import org.jacodb.api.jvm.JcByteCodeLocation import org.jacodb.api.jvm.JcDatabasePersistence import org.jacodb.api.jvm.RegisteredLocation import org.jacodb.api.storage.ers.getEntityOrNull -import org.jacodb.impl.caches.PluggableCache -import org.jacodb.impl.caches.PluggableCacheProvider import org.jacodb.impl.caches.xodus.XODUS_CACHE_PROVIDER_ID import org.jacodb.impl.fs.JavaRuntime import org.jacodb.impl.fs.asByteCodeLocation @@ -73,7 +73,7 @@ abstract class AbstractJcDbPersistence( ).mapNotNull { try { File(it.path).asByteCodeLocation(javaRuntime.version, isRuntime = it.runtime) - } catch (e: Exception) { + } catch (_: Exception) { null } }.flatten().distinct() @@ -131,7 +131,7 @@ abstract class AbstractJcDbPersistence( override fun close() { try { symbolInterner.close() - } catch (e: Exception) { + } catch (_: Exception) { // ignore } } diff --git a/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/caches/PluggableCacheTest.kt b/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/caches/PluggableCacheTest.kt index 81693690b..851ef9fe3 100644 --- a/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/caches/PluggableCacheTest.kt +++ b/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/caches/PluggableCacheTest.kt @@ -16,7 +16,7 @@ package org.jacodb.testing.caches -import org.jacodb.impl.caches.PluggableCache +import org.jacodb.api.caches.PluggableCache import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach diff --git a/jacodb-storage/build.gradle.kts b/jacodb-storage/build.gradle.kts index 922260eaf..18cbaed1c 100644 --- a/jacodb-storage/build.gradle.kts +++ b/jacodb-storage/build.gradle.kts @@ -4,7 +4,8 @@ dependencies { compileOnly(Libs.xodusEnvironment) compileOnly(Libs.lmdb_java) compileOnly(Libs.rocks_db) - + compileOnly(Libs.guava) + compileOnly(Libs.xodusUtils) testImplementation(Libs.xodusEnvironment) testImplementation(Libs.lmdb_java) diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt b/jacodb-storage/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt similarity index 88% rename from jacodb-core/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt rename to jacodb-storage/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt index f9257d6f1..c97b575fd 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt +++ b/jacodb-storage/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt @@ -18,12 +18,11 @@ package org.jacodb.impl.caches.guava import com.google.common.cache.Cache import com.google.common.cache.CacheBuilder -import org.jacodb.api.jvm.ValueStoreType -import org.jacodb.impl.caches.PluggableCache -import org.jacodb.impl.caches.PluggableCacheBuilder -import org.jacodb.impl.caches.PluggableCacheProvider -import org.jacodb.impl.caches.PluggableCacheStats -import java.time.Duration +import org.jacodb.api.caches.PluggableCache +import org.jacodb.api.caches.PluggableCacheBuilder +import org.jacodb.api.caches.PluggableCacheProvider +import org.jacodb.api.caches.PluggableCacheStats +import org.jacodb.api.caches.ValueStoreType const val GUAVA_CACHE_PROVIDER_ID = "org.jacodb.impl.caches.guava.GuavaCacheProvider" @@ -42,7 +41,7 @@ private class GuavaCacheBuilder : PluggableCacheBuilder( .maximumSize(maximumSize.toLong()) .apply { expirationDuration.let { - if (it != Duration.ZERO) { + if (it != java.time.Duration.ZERO) { expireAfterAccess(it) } } diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt b/jacodb-storage/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt similarity index 84% rename from jacodb-core/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt rename to jacodb-storage/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt index 956883760..3c63f322e 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt +++ b/jacodb-storage/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt @@ -19,12 +19,12 @@ package org.jacodb.impl.caches.xodus import jetbrains.exodus.core.dataStructures.ConcurrentObjectCache import jetbrains.exodus.core.dataStructures.ObjectCacheBase import jetbrains.exodus.core.dataStructures.SoftConcurrentObjectCache -import org.jacodb.api.jvm.ValueStoreType -import org.jacodb.impl.caches.PluggableCache -import org.jacodb.impl.caches.PluggableCacheBuilder -import org.jacodb.impl.caches.PluggableCacheException -import org.jacodb.impl.caches.PluggableCacheProvider -import org.jacodb.impl.caches.PluggableCacheStats +import org.jacodb.api.caches.PluggableCache +import org.jacodb.api.caches.PluggableCacheBuilder +import org.jacodb.api.caches.PluggableCacheException +import org.jacodb.api.caches.PluggableCacheProvider +import org.jacodb.api.caches.PluggableCacheStats +import org.jacodb.api.caches.ValueStoreType const val XODUS_CACHE_PROVIDER_ID = "org.jacodb.impl.caches.xodus.XodusCacheProvider" @@ -51,7 +51,7 @@ private class XodusCacheBuilder : PluggableCacheBuilder( } /** - * Generally, Xodus' [ObjectCacheBase] is not synchronized, but [XodusCacheBuilder] creates + * Generally, Xodus' [jetbrains.exodus.core.dataStructures.ObjectCacheBase] is not synchronized, but [XodusCacheBuilder] creates * its "concurrent" implementations which do not require synchronization. If this ever changes, * [XodusCache] should be synchronized. */ diff --git a/jacodb-core/src/main/resources/META-INF/services/org.jacodb.impl.caches.PluggableCacheProvider b/jacodb-storage/src/main/resources/META-INF/services/org.jacodb.api.caches.PluggableCacheProvider similarity index 100% rename from jacodb-core/src/main/resources/META-INF/services/org.jacodb.impl.caches.PluggableCacheProvider rename to jacodb-storage/src/main/resources/META-INF/services/org.jacodb.api.caches.PluggableCacheProvider