Extract BasicMapsOwner

This commit is contained in:
Alexey Tsvetkov
2015-11-02 16:10:58 +03:00
parent f6f300d903
commit 9564a7a828
3 changed files with 54 additions and 28 deletions
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.jps.incremental
import org.jetbrains.annotations.TestOnly
import org.jetbrains.jps.incremental.storage.StorageOwner
import org.jetbrains.kotlin.jps.incremental.storage.BasicMap
open class BasicMapsOwner : StorageOwner {
private val maps = arrayListOf<BasicMap<*, *>>()
protected fun <K, V, M : BasicMap<K, V>> registerMap(map: M): M {
maps.add(map)
return map
}
override fun clean() {
maps.forEach { it.clean() }
}
override fun close() {
maps.forEach { it.close() }
}
override fun flush(memoryCachesOnly: Boolean) {
maps.forEach { it.flush(memoryCachesOnly) }
}
@TestOnly
public fun dump(): String = maps.map { it.dump() }.joinToString("\n\n")
}
@@ -26,7 +26,6 @@ import org.jetbrains.jps.builders.storage.StorageProvider
import org.jetbrains.jps.incremental.ModuleBuildTarget
import org.jetbrains.jps.incremental.storage.BuildDataManager
import org.jetbrains.jps.incremental.storage.PathStringDescriptor
import org.jetbrains.jps.incremental.storage.StorageOwner
import org.jetbrains.kotlin.inline.inlineFunctionsJvmNames
import org.jetbrains.kotlin.jps.build.GeneratedJvmClass
import org.jetbrains.kotlin.jps.build.KotlinBuilder
@@ -37,7 +36,6 @@ import org.jetbrains.kotlin.load.kotlin.header.*
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.resolve.jvm.JvmClassName.byInternalName
import org.jetbrains.kotlin.serialization.jvm.BitEncoding
import org.jetbrains.org.objectweb.asm.*
import java.io.DataInput
@@ -56,9 +54,9 @@ public fun getCacheDirectoryName(): String =
public class IncrementalCacheImpl(
targetDataRoot: File,
private val target: ModuleBuildTarget
) : StorageOwner, IncrementalCache {
) : BasicMapsOwner(), IncrementalCache {
companion object {
val CACHE_EXTENSION = "tab"
val CACHE_EXTENSION = ".tab"
val PROTO_MAP = "proto"
val CONSTANTS_MAP = "constants"
@@ -75,15 +73,9 @@ public class IncrementalCacheImpl(
}
private val baseDir = File(targetDataRoot, CACHE_DIRECTORY_NAME)
private val maps = arrayListOf<BasicMap<*, *>>()
private val String.storageFile: File
get() = File(baseDir, this + "." + CACHE_EXTENSION)
private fun <K, V, M : BasicMap<K, V>> registerMap(map: M): M {
maps.add(map)
return map
}
get() = File(baseDir, this + CACHE_EXTENSION)
private val protoMap = registerMap(ProtoMap(PROTO_MAP.storageFile))
private val constantsMap = registerMap(ConstantsMap(CONSTANTS_MAP.storageFile))
@@ -108,11 +100,6 @@ public class IncrementalCacheImpl(
dependents.add(cache)
}
@TestOnly
public fun dump(): String {
return maps.joinToString("\n\n") { it.dump() }
}
public fun markOutputClassesDirty(removedAndCompiledSources: List<File>) {
for (sourceFile in removedAndCompiledSources) {
val classes = sourceToClassesMap[sourceFile]
@@ -278,19 +265,11 @@ public class IncrementalCacheImpl(
return protoMap[JvmClassName.byInternalName(MODULE_MAPPING_FILE_NAME)]?.bytes
}
override fun flush(memoryCachesOnly: Boolean) {
maps.forEach { it.flush(memoryCachesOnly) }
}
public override fun clean() {
maps.forEach { it.clean() }
super.clean()
cacheFormatVersion.clean()
}
public override fun close() {
maps.forEach { it.close () }
}
private inner class ProtoMap(storageFile: File) : BasicStringMap<ProtoMapValue>(storageFile, ProtoMapValueExternalizer) {
public fun process(kotlinClass: LocalFileKotlinClass, isPackage: Boolean, checkChangesIsOpenPart: Boolean = true): ChangesInfo {
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.jps.incremental
import org.jetbrains.jps.builders.storage.StorageProvider
import org.jetbrains.jps.incremental.storage.StorageOwner
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.jps.incremental.storage.LookupMap
@@ -27,8 +26,11 @@ object LOOKUP_TRACKER_STORAGE_PROVIDER : StorageProvider<LookupTrackerImpl>() {
override fun createStorage(targetDataDir: File): LookupTrackerImpl = LookupTrackerImpl(targetDataDir)
}
class LookupTrackerImpl(targetDataDir: File) : LookupTracker, StorageOwner {
private val lookupMap = LookupMap(File(targetDataDir, "lookups.tab"))
class LookupTrackerImpl(private val targetDataDir: File) : BasicMapsOwner(), LookupTracker {
private val String.storageFile: File
get() = File(targetDataDir, this + IncrementalCacheImpl.CACHE_EXTENSION)
private val lookupMap = registerMap(LookupMap("lookups".storageFile))
override fun record(lookupContainingFile: String, lookupLine: Int?, lookupColumn: Int?, scopeFqName: String, scopeKind: ScopeKind, name: String) {
lookupMap.add(name, scopeFqName, lookupContainingFile)