Fix deadlock in StaticScopeForKotlinEnum

Also fix possible deadlock in ReflectionTypes

 #KT-11869 Fixed
This commit is contained in:
Alexander Udalov
2016-04-12 16:24:11 +03:00
parent a8629b3836
commit 11d875ca17
4 changed files with 13 additions and 9 deletions
@@ -124,9 +124,11 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
this.declarationProvider = c.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfo);
StorageManager storageManager = c.getStorageManager();
this.unsubstitutedMemberScope = createMemberScope(c, this.declarationProvider);
this.kind = classLikeInfo.getClassKind();
this.staticScope = kind == ClassKind.ENUM_CLASS ? new StaticScopeForKotlinEnum(this) : MemberScope.Empty.INSTANCE;
this.staticScope = kind == ClassKind.ENUM_CLASS ? new StaticScopeForKotlinEnum(storageManager, this) : MemberScope.Empty.INSTANCE;
this.typeConstructor = new LazyClassTypeConstructor();
@@ -154,8 +156,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
this.isInner = isInnerClass(modifierList) && !ModifiersChecker.isIllegalInner(this);
this.isData = modifierList != null && modifierList.hasModifier(KtTokens.DATA_KEYWORD);
StorageManager storageManager = c.getStorageManager();
// Annotation entries are taken from both own annotations (if any) and object literal annotations (if any)
List<KtAnnotationEntry> annotationEntries = new ArrayList<KtAnnotationEntry>();
if (classOrObject != null && classOrObject.getParent() instanceof KtObjectLiteralExpression) {
@@ -32,8 +32,8 @@ import kotlin.reflect.KProperty
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
class ReflectionTypes(private val module: ModuleDescriptor) {
private val kotlinReflectScope: MemberScope by lazy {
class ReflectionTypes(module: ModuleDescriptor) {
private val kotlinReflectScope: MemberScope by lazy(LazyThreadSafetyMode.PUBLICATION) {
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
}
@@ -18,24 +18,28 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValueOfMethod
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValuesMethod
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.utils.Printer
import java.util.*
// We don't need to track lookups here since this scope used only for introduce special Enum class members
class StaticScopeForKotlinEnum(private val containingClass: ClassDescriptor) : MemberScopeImpl() {
class StaticScopeForKotlinEnum(
storageManager: StorageManager,
private val containingClass: ClassDescriptor
) : MemberScopeImpl() {
init {
assert(containingClass.kind == ClassKind.ENUM_CLASS) { "Class should be an enum: $containingClass" }
}
override fun getContributedClassifier(name: Name, location: LookupLocation) = null // TODO
private val functions: List<SimpleFunctionDescriptor> by lazy {
private val functions: List<SimpleFunctionDescriptor> by storageManager.createLazyValue {
listOf(createEnumValueOfMethod(containingClass), createEnumValuesMethod(containingClass))
}
@@ -62,7 +62,7 @@ class DeserializedClassDescriptor(
private val classId = nameResolver.getClassId(classProto.fqName)
private val staticScope = if (kind == ClassKind.ENUM_CLASS) StaticScopeForKotlinEnum(this) else MemberScope.Empty
private val staticScope = if (kind == ClassKind.ENUM_CLASS) StaticScopeForKotlinEnum(c.storageManager, this) else MemberScope.Empty
private val typeConstructor = DeserializedClassTypeConstructor()
private val memberScope = DeserializedClassMemberScope()
private val nestedClasses = NestedClassDescriptors()