Skip to content

Commit 9f4c28a

Browse files
committed
Port backend paralleism refactor from Scala 2
1 parent 027e003 commit 9f4c28a

13 files changed

+747
-317
lines changed

compiler/src/dotty/tools/backend/jvm/BTypes.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import scala.tools.asm
1616
*/
1717
abstract class BTypes { self =>
1818
val frontendAccess: PostProcessorFrontendAccess
19-
import frontendAccess.{frontendSynch}
2019

2120
val int: DottyBackendInterface
2221
import int.given
@@ -31,8 +30,7 @@ abstract class BTypes { self =>
3130
* Concurrent because stack map frames are computed when in the class writer, which might run
3231
* on multiple classes concurrently.
3332
*/
34-
protected def classBTypeFromInternalNameMap: collection.concurrent.Map[String, ClassBType]
35-
// NOTE: Should be a lazy val but scalac does not allow abstract lazy vals (dotty does)
33+
protected lazy val classBTypeFromInternalNameMap: collection.concurrent.Map[String, ClassBType]
3634

3735
/**
3836
* Obtain a previously constructed ClassBType for a given internal name.

compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I, val frontendAcce
5555
(classSym != defn.NothingClass && classSym != defn.NullClass),
5656
s"Cannot create ClassBType for special class symbol ${classSym.showFullName}")
5757

58-
convertedClasses.getOrElse(classSym, {
59-
val internalName = classSym.javaBinaryName
60-
// We first create and add the ClassBType to the hash map before computing its info. This
61-
// allows initializing cylic dependencies, see the comment on variable ClassBType._info.
62-
val classBType = new ClassBType(internalName)
63-
convertedClasses(classSym) = classBType
64-
setClassInfo(classSym, classBType)
65-
})
58+
convertedClasses.synchronized {
59+
convertedClasses.getOrElse(classSym, {
60+
val internalName = classSym.javaBinaryName
61+
// We first create and add the ClassBType to the hash map before computing its info. This
62+
// allows initializing cylic dependencies, see the comment on variable ClassBType._info.
63+
val classBType = new ClassBType(internalName)
64+
convertedClasses(classSym) = classBType
65+
setClassInfo(classSym, classBType)
66+
})
67+
}
6668
}
6769

6870
final def mirrorClassBTypeFromSymbol(moduleClassSym: Symbol): ClassBType = {

compiler/src/dotty/tools/backend/jvm/BackendUtils.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import scala.language.unsafeNulls
1717
class BackendUtils(val postProcessor: PostProcessor) {
1818
import postProcessor.{bTypes, frontendAccess}
1919
import frontendAccess.{compilerSettings}
20-
import bTypes.*
21-
import coreBTypes.jliLambdaMetaFactoryAltMetafactoryHandle
20+
import bTypes.{coreBTypes, ClassBType, MethodBType}
2221

2322
// Keep synchronized with `minTargetVersion` and `maxTargetVersion` in ScalaSettings
2423
lazy val classfileVersion: Int = compilerSettings.target match {
@@ -45,6 +44,8 @@ class BackendUtils(val postProcessor: PostProcessor) {
4544
}
4645

4746
def collectSerializableLambdas(classNode: ClassNode): Array[Handle] = {
47+
import coreBTypes.jliLambdaMetaFactoryAltMetafactoryHandle
48+
4849
val indyLambdaBodyMethods = new mutable.ArrayBuffer[Handle]
4950
for (m <- classNode.methods.asScala) {
5051
val iter = m.instructions.iterator
@@ -59,7 +60,7 @@ class BackendUtils(val postProcessor: PostProcessor) {
5960
if isSerializable then
6061
val implMethod = indy.bsmArgs(1).asInstanceOf[Handle]
6162
indyLambdaBodyMethods += implMethod
62-
case _ =>
63+
case _ => ()
6364
}
6465
}
6566
}
@@ -90,8 +91,7 @@ class BackendUtils(val postProcessor: PostProcessor) {
9091
*/
9192
def addLambdaDeserialize(classNode: ClassNode, implMethodsArray: Array[Handle]): Unit = {
9293
import asm.Opcodes._
93-
import bTypes._
94-
import coreBTypes._
94+
import coreBTypes.{jlIllegalArgExceptionRef, jliLambdaDeserializeBootstrapHandle}
9595

9696
val cw = classNode
9797

@@ -101,12 +101,10 @@ class BackendUtils(val postProcessor: PostProcessor) {
101101
// stack map frames and invokes the `getCommonSuperClass` method. This method expects all
102102
// ClassBTypes mentioned in the source code to exist in the map.
103103

104-
val serlamObjDesc = MethodBType(jliSerializedLambdaRef :: Nil, ObjectRef).descriptor
105-
106-
val mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$deserializeLambda$", serlamObjDesc, null, null)
104+
val mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$deserializeLambda$", serializedLamdaObjDesc, null, null)
107105
def emitLambdaDeserializeIndy(targetMethods: Seq[Handle]): Unit = {
108106
mv.visitVarInsn(ALOAD, 0)
109-
mv.visitInvokeDynamicInsn("lambdaDeserialize", serlamObjDesc, jliLambdaDeserializeBootstrapHandle, targetMethods: _*)
107+
mv.visitInvokeDynamicInsn("lambdaDeserialize", serializedLamdaObjDesc, jliLambdaDeserializeBootstrapHandle, targetMethods: _*)
110108
}
111109

112110
val targetMethodGroupLimit = 255 - 1 - 3 // JVM limit. See See MAX_MH_ARITY in CallSite.java
@@ -131,6 +129,11 @@ class BackendUtils(val postProcessor: PostProcessor) {
131129
mv.visitInsn(ARETURN)
132130
}
133131

132+
private lazy val serializedLamdaObjDesc = {
133+
import coreBTypes.{ObjectRef, jliSerializedLambdaRef}
134+
MethodBType(jliSerializedLambdaRef :: Nil, ObjectRef).descriptor
135+
}
136+
134137
/**
135138
* Visit the class node and collect all referenced nested classes.
136139
*/

compiler/src/dotty/tools/backend/jvm/ClassfileWriter.scala

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)