Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix thread safety problem in runtime reflection #9080

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ abstract class SymbolLoaders {
}
}
}
private val classFileDataReader: ReusableInstance[ReusableDataReader] = ReusableInstance[ReusableDataReader](new ReusableDataReader())
private lazy val classFileDataReader: ReusableInstance[ReusableDataReader] = ReusableInstance[ReusableDataReader](new ReusableDataReader(), enabled = isCompilerUniverse)
class ClassfileLoader(val classfile: AbstractFile, clazz: ClassSymbol, module: ModuleSymbol) extends SymbolLoader with FlagAssigningCompleter {
private object classfileParser extends {
val symbolTable: SymbolLoaders.this.symbolTable.type = SymbolLoaders.this.symbolTable
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ trait Contexts { self: Analyzer =>
* the search continuing as long as no qualifying name is found.
*/
// OPT: moved this into a (cached) object to avoid costly and non-eliminated {Object,Int}Ref allocations
private[Contexts] final val symbolLookupCache = ReusableInstance[SymbolLookup](new SymbolLookup)
private[Contexts] final val symbolLookupCache = ReusableInstance[SymbolLookup](new SymbolLookup, enabled = isCompilerUniverse)
private[Contexts] final class SymbolLookup {
private[this] var lookupError: NameLookup = _ // set to non-null if a definite error is encountered
private[this] var inaccessible: NameLookup = _ // records inaccessible symbol for error reporting in case none is found
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ trait Implicits {
def isShadowed(name: Name): Boolean
}
object Shadower {
private[this] val localShadowerCache = ReusableInstance[LocalShadower](new LocalShadower)
private[this] val localShadowerCache = ReusableInstance[LocalShadower](new LocalShadower, enabled = isCompilerUniverse)

def using[T](local: Boolean)(f: Shadower => T): T =
if (local) localShadowerCache.using { shadower =>
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Positions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ trait Positions extends api.Positions { self: SymbolTable =>
inform("error while set children pos "+pos+" of "+parent.children)
throw ex
}
private val setChildrenPosAccumulator = ReusableInstance[SetChildrenPosAccumulator](new SetChildrenPosAccumulator)
private val setChildrenPosAccumulator = ReusableInstance[SetChildrenPosAccumulator](new SetChildrenPosAccumulator, enabled = isCompilerUniverse)
private final class SetChildrenPosAccumulator extends (Tree => Boolean) {
private[this] val wrappingPosAccumulator = new WrappingPosAccumulator
private[this] var pos: Position = _
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ trait Trees extends api.Trees {
}
}
}
private val onlyChildAccumulator = ReusableInstance[OnlyChildAccumulator](new OnlyChildAccumulator)
private val onlyChildAccumulator = ReusableInstance[OnlyChildAccumulator](new OnlyChildAccumulator, enabled = isCompilerUniverse)

// -------------- Classtags --------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Variances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ trait Variances {
final def varianceInType(tp: Type, considerUnchecked: Boolean = false)(tparam: Symbol): Variance =
varianceInTypeCache.using(_.apply(tp, tparam, considerUnchecked))

private[this] val varianceInTypeCache = ReusableInstance[varianceInType](new varianceInType)
private[this] val varianceInTypeCache = ReusableInstance[varianceInType](new varianceInType, enabled = isCompilerUniverse)

private final class varianceInType {
private[this] var tp: Type = _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private[internal] trait TypeConstraints {
}
}

private[this] val containsCollectorInstances: ReusableInstance[ContainsCollector] = ReusableInstance(new ContainsCollector(null))
private[this] val containsCollectorInstances: ReusableInstance[ContainsCollector] = ReusableInstance(new ContainsCollector(null), enabled = isCompilerUniverse)

private[this] def containsSymbol(tp: Type, sym: Symbol): Boolean =
containsCollectorInstances.using { cc =>
Expand Down