Skip to content

Commit cd43ea3

Browse files
committed
Scala 2 backport: Enable parallel optimizing and writing of classes by GenBCode #6124
1 parent 00180bb commit cd43ea3

13 files changed

+769
-340
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
@@ -103,12 +103,10 @@ class BackendUtils(val postProcessor: PostProcessor) {
103103
// stack map frames and invokes the `getCommonSuperClass` method. This method expects all
104104
// ClassBTypes mentioned in the source code to exist in the map.
105105

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

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

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

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

-142
This file was deleted.

0 commit comments

Comments
 (0)