[Commonizer] Replace j.u.HashMap by g.t.THashMap to reduce memory usage

This commit is contained in:
Dmitriy Dolovov
2020-06-19 17:48:20 +07:00
parent 70ea53315d
commit 59183a8142
11 changed files with 32 additions and 21 deletions
+1
View File
@@ -20,6 +20,7 @@ dependencies {
compileOnly(project(":native:frontend.native")) compileOnly(project(":native:frontend.native"))
compileOnly(project(":kotlin-util-klib-metadata")) compileOnly(project(":kotlin-util-klib-metadata"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
compileOnly(intellijDep()) { includeJars("trove4j") }
// This dependency is necessary to keep the right dependency record inside of POM file: // This dependency is necessary to keep the right dependency record inside of POM file:
publishedCompile(project(":kotlin-compiler")) publishedCompile(project(":kotlin-compiler"))
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.builder package org.jetbrains.kotlin.descriptors.commonizer.builder
import gnu.trove.THashMap
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
@@ -13,9 +14,9 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
class CommonizedMemberScope : MemberScope { class CommonizedMemberScope : MemberScope {
private val functions = HashMap<Name, MutableList<SimpleFunctionDescriptor>>() private val functions = THashMap<Name, MutableList<SimpleFunctionDescriptor>>()
private val variables = HashMap<Name, MutableList<PropertyDescriptor>>() private val variables = THashMap<Name, MutableList<PropertyDescriptor>>()
private val classifiers = HashMap<Name, ClassifierDescriptorWithTypeParameters>() private val classifiers = THashMap<Name, ClassifierDescriptorWithTypeParameters>()
private fun addMember(member: DeclarationDescriptor) { private fun addMember(member: DeclarationDescriptor) {
when (member) { when (member) {
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.cir.factory package org.jetbrains.kotlin.descriptors.commonizer.cir.factory
import gnu.trove.THashMap
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirAnnotationImpl import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirAnnotationImpl
@@ -26,8 +27,8 @@ object CirAnnotationFactory {
if (allValueArguments.isEmpty()) if (allValueArguments.isEmpty())
return create(fqName = fqName, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap()) return create(fqName = fqName, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap())
val constantValueArguments: MutableMap<Name, ConstantValue<*>> = HashMap() val constantValueArguments: MutableMap<Name, ConstantValue<*>> = THashMap()
val annotationValueArguments: MutableMap<Name, CirAnnotation> = HashMap() val annotationValueArguments: MutableMap<Name, CirAnnotation> = THashMap()
allValueArguments.forEach { (name, constantValue) -> allValueArguments.forEach { (name, constantValue) ->
checkConstantSupportedInCommonization( checkConstantSupportedInCommonization(
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.konan package org.jetbrains.kotlin.descriptors.commonizer.konan
import gnu.trove.THashMap
import org.jetbrains.kotlin.library.KotlinLibrary import org.jetbrains.kotlin.library.KotlinLibrary
internal interface NativeManifestDataProvider { internal interface NativeManifestDataProvider {
@@ -66,4 +67,4 @@ internal class CommonNativeManifestDataProvider(
} }
private fun NativeDistributionLibraries.buildManifestIndex(): MutableMap<String, NativeSensitiveManifestData> = private fun NativeDistributionLibraries.buildManifestIndex(): MutableMap<String, NativeSensitiveManifestData> =
(platformLibs + stdlib).map { it.manifestData }.associateByTo(HashMap()) { it.uniqueName } (platformLibs + stdlib).map { it.manifestData }.associateByTo(THashMap()) { it.uniqueName }
@@ -63,6 +63,6 @@ internal class NativeDistributionModulesProvider(
module.setDependencies(listOf(module) + dependencies + forwardDeclarations) module.setDependencies(listOf(module) + dependencies + forwardDeclarations)
} }
return platformModulesMap.values return platformModulesMap.values.toList()
} }
} }
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
import gnu.trove.THashMap
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -17,10 +18,10 @@ class CirClassNode(
override val fqName: FqName override val fqName: FqName
) : CirNodeWithFqName<CirClass, CirClass> { ) : CirNodeWithFqName<CirClass, CirClass> {
val constructors: MutableMap<ConstructorApproximationKey, CirClassConstructorNode> = HashMap() val constructors: MutableMap<ConstructorApproximationKey, CirClassConstructorNode> = THashMap()
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = HashMap() val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = THashMap()
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = HashMap() val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = THashMap()
val classes: MutableMap<Name, CirClassNode> = HashMap() val classes: MutableMap<Name, CirClassNode> = THashMap()
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R = override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R =
visitor.visitClassNode(this, data) visitor.visitClassNode(this, data)
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
import gnu.trove.THashMap
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -14,7 +15,7 @@ class CirModuleNode(
override val targetDeclarations: CommonizedGroup<CirModule>, override val targetDeclarations: CommonizedGroup<CirModule>,
override val commonDeclaration: NullableLazyValue<CirModule> override val commonDeclaration: NullableLazyValue<CirModule>
) : CirNode<CirModule, CirModule> { ) : CirNode<CirModule, CirModule> {
val packages: MutableMap<FqName, CirPackageNode> = HashMap() val packages: MutableMap<FqName, CirPackageNode> = THashMap()
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) = override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) =
visitor.visitModuleNode(this, data) visitor.visitModuleNode(this, data)
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
import gnu.trove.THashMap
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -18,10 +19,10 @@ class CirPackageNode(
val moduleName: Name val moduleName: Name
) : CirNodeWithFqName<CirPackage, CirPackage> { ) : CirNodeWithFqName<CirPackage, CirPackage> {
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = HashMap() val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = THashMap()
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = HashMap() val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = THashMap()
val classes: MutableMap<Name, CirClassNode> = HashMap() val classes: MutableMap<Name, CirClassNode> = THashMap()
val typeAliases: MutableMap<Name, CirTypeAliasNode> = HashMap() val typeAliases: MutableMap<Name, CirTypeAliasNode> = THashMap()
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) = override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) =
visitor.visitPackageNode(this, data) visitor.visitPackageNode(this, data)
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
import gnu.trove.THashMap
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRoot import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRoot
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -16,11 +17,11 @@ class CirRootNode(
override val commonDeclaration: NullableLazyValue<CirRoot> override val commonDeclaration: NullableLazyValue<CirRoot>
) : CirNode<CirRoot, CirRoot> { ) : CirNode<CirRoot, CirRoot> {
class CirClassifiersCacheImpl : CirClassifiersCache { class CirClassifiersCacheImpl : CirClassifiersCache {
override val classes = HashMap<FqName, CirClassNode>() override val classes = THashMap<FqName, CirClassNode>()
override val typeAliases = HashMap<FqName, CirTypeAliasNode>() override val typeAliases = THashMap<FqName, CirTypeAliasNode>()
} }
val modules: MutableMap<Name, CirModuleNode> = HashMap() val modules: MutableMap<Name, CirModuleNode> = THashMap()
val cache = CirClassifiersCacheImpl() val cache = CirClassifiersCacheImpl()
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R = override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R =
@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.descriptors.commonizer.utils package org.jetbrains.kotlin.descriptors.commonizer.utils
import gnu.trove.THashMap
/** Fixed-size ordered collection with no extra space that represents a commonized group of same-rank elements */ /** Fixed-size ordered collection with no extra space that represents a commonized group of same-rank elements */
class CommonizedGroup<T : Any>( class CommonizedGroup<T : Any>(
override val size: Int, override val size: Int,
@@ -32,7 +34,7 @@ class CommonizedGroup<T : Any>(
} }
internal class CommonizedGroupMap<K, V : Any>(val size: Int) : Iterable<Map.Entry<K, CommonizedGroup<V>>> { internal class CommonizedGroupMap<K, V : Any>(val size: Int) : Iterable<Map.Entry<K, CommonizedGroup<V>>> {
private val wrapped: MutableMap<K, CommonizedGroup<V>> = HashMap() private val wrapped: MutableMap<K, CommonizedGroup<V>> = THashMap()
operator fun get(key: K): CommonizedGroup<V> = wrapped.getOrPut(key) { CommonizedGroup(size) } operator fun get(key: K): CommonizedGroup<V> = wrapped.getOrPut(key) { CommonizedGroup(size) }
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.utils package org.jetbrains.kotlin.descriptors.commonizer.utils
import gnu.trove.THashMap
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
internal fun <T> Sequence<T>.toList(expectedCapacity: Int): List<T> { internal fun <T> Sequence<T>.toList(expectedCapacity: Int): List<T> {
@@ -17,7 +18,7 @@ internal infix fun <K, V> Map<K, V>.concat(other: Map<K, V>): Map<K, V> =
when { when {
isEmpty() -> other isEmpty() -> other
other.isEmpty() -> this other.isEmpty() -> this
else -> HashMap<K, V>(size + other.size, 1F).apply { else -> THashMap<K, V>(size + other.size, 1F).apply {
putAll(this@concat) putAll(this@concat)
putAll(other) putAll(other)
} }