[K/N][IR][codegen] Fixed a number of thread safety problems

This commit is contained in:
Igor Chevdar
2022-11-09 19:16:21 +02:00
committed by Space Team
parent f442936320
commit ea7c851748
3 changed files with 9 additions and 3 deletions
@@ -223,10 +223,12 @@ class NaiveSourceBasedFileEntryImpl(
} }
} }
private val lineNumberLock = Any()
override fun getLineNumber(offset: Int): Int { override fun getLineNumber(offset: Int): Int {
if (offset == SYNTHETIC_OFFSET) return 0 if (offset == SYNTHETIC_OFFSET) return 0
if (offset < 0) return -1 if (offset < 0) return -1
return calculatedBeforeLineNumbers.get(offset) return synchronized(lineNumberLock) { calculatedBeforeLineNumbers.get(offset) }
} }
override fun getColumnNumber(offset: Int): Int { override fun getColumnNumber(offset: Int): Int {
@@ -31,6 +31,8 @@ import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.descriptorUtil.module
import java.util.concurrent.ConcurrentHashMap
import kotlin.LazyThreadSafetyMode.PUBLICATION
internal class NativeMapping : DefaultMapping() { internal class NativeMapping : DefaultMapping() {
data class BridgeKey(val target: IrSimpleFunction, val bridgeDirections: BridgeDirections) data class BridgeKey(val target: IrSimpleFunction, val bridgeDirections: BridgeDirections)
@@ -42,7 +44,7 @@ internal class NativeMapping : DefaultMapping() {
val outerThisFields = DefaultDelegateFactory.newDeclarationToDeclarationMapping<IrClass, IrField>() val outerThisFields = DefaultDelegateFactory.newDeclarationToDeclarationMapping<IrClass, IrField>()
val enumValueGetters = DefaultDelegateFactory.newDeclarationToDeclarationMapping<IrClass, IrFunction>() val enumValueGetters = DefaultDelegateFactory.newDeclarationToDeclarationMapping<IrClass, IrFunction>()
val enumEntriesMaps = mutableMapOf<IrClass, Map<Name, LoweredEnumEntryDescription>>() val enumEntriesMaps = mutableMapOf<IrClass, Map<Name, LoweredEnumEntryDescription>>()
val bridges = mutableMapOf<BridgeKey, IrSimpleFunction>() val bridges = ConcurrentHashMap<BridgeKey, IrSimpleFunction>()
val partiallyLoweredInlineFunctions = mutableMapOf<IrFunctionSymbol, IrFunction>() val partiallyLoweredInlineFunctions = mutableMapOf<IrFunctionSymbol, IrFunction>()
val outerThisCacheAccessors = DefaultDelegateFactory.newDeclarationToDeclarationMapping<IrClass, IrSimpleFunction>() val outerThisCacheAccessors = DefaultDelegateFactory.newDeclarationToDeclarationMapping<IrClass, IrSimpleFunction>()
val lateinitPropertyCacheAccessors = DefaultDelegateFactory.newDeclarationToDeclarationMapping<IrProperty, IrSimpleFunction>() val lateinitPropertyCacheAccessors = DefaultDelegateFactory.newDeclarationToDeclarationMapping<IrProperty, IrSimpleFunction>()
@@ -811,7 +811,9 @@ internal class KonanIrLinker(
} }
} }
fun deserializeClassFields(irClass: IrClass, outerThisFieldInfo: ClassLayoutBuilder.FieldInfo?): List<ClassLayoutBuilder.FieldInfo> { private val lock = Any()
fun deserializeClassFields(irClass: IrClass, outerThisFieldInfo: ClassLayoutBuilder.FieldInfo?): List<ClassLayoutBuilder.FieldInfo> = synchronized(lock) {
irClass.getPackageFragment() as? IrExternalPackageFragment irClass.getPackageFragment() as? IrExternalPackageFragment
?: error("Expected an external package fragment for ${irClass.render()}") ?: error("Expected an external package fragment for ${irClass.render()}")
val signature = irClass.symbol.signature val signature = irClass.symbol.signature