Skip to content

Commit 49b21db

Browse files
committed
Scala 2 backport: Enable parallel optimizing and writing of classes by GenBCode #6124
[Cherry-picked cd43ea3][modified]
1 parent 7eec9eb commit 49b21db

13 files changed

+772
-336
lines changed

Diff for: compiler/src/dotty/tools/backend/jvm/BTypes.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ abstract class BTypes { self =>
3131
* Concurrent because stack map frames are computed when in the class writer, which might run
3232
* on multiple classes concurrently.
3333
*/
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)
34+
protected lazy val classBTypeFromInternalNameMap: collection.concurrent.Map[String, ClassBType]
3635

3736
/**
3837
* Obtain a previously constructed ClassBType for a given internal name.

Diff for: compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

+9-8
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ 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+
})
6667
}
6768

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

Diff for: compiler/src/dotty/tools/backend/jvm/BackendUtils.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ class BackendUtils(val postProcessor: PostProcessor) {
104104
// stack map frames and invokes the `getCommonSuperClass` method. This method expects all
105105
// ClassBTypes mentioned in the source code to exist in the map.
106106

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

115113
val targetMethodGroupLimit = 255 - 1 - 3 // JVM limit. See See MAX_MH_ARITY in CallSite.java
@@ -134,6 +132,11 @@ class BackendUtils(val postProcessor: PostProcessor) {
134132
mv.visitInsn(ARETURN)
135133
}
136134

135+
private lazy val serializedLamdaObjDesc = {
136+
import coreBTypes.{ObjectRef, jliSerializedLambdaRef}
137+
MethodBType(jliSerializedLambdaRef :: Nil, ObjectRef).descriptor
138+
}
139+
137140
/**
138141
* Visit the class node and collect all referenced nested classes.
139142
*/

Diff for: compiler/src/dotty/tools/backend/jvm/ClassfileWriter.scala

-142
This file was deleted.

0 commit comments

Comments
 (0)