Skip to content

Commit

Permalink
Parallelise JVM backend - Scala 2 port (#15392)
Browse files Browse the repository at this point in the history
This PR ports scala/scala#6124 introduces
backend parallelism, on top of the previously ported changes introduced
in #15322
Adds Scala2 flags: 
* `-Yjar-compression-level:N`
* `-Ybackend-parallelism:N`
* `-Ybackend-worker-queue:N`
  • Loading branch information
bishabosha authored Oct 10, 2023
2 parents 00180bb + 9746478 commit db7e033
Show file tree
Hide file tree
Showing 14 changed files with 808 additions and 341 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/backend/jvm/BTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ abstract class BTypes { self =>
* Concurrent because stack map frames are computed when in the class writer, which might run
* on multiple classes concurrently.
*/
protected def classBTypeFromInternalNameMap: collection.concurrent.Map[String, ClassBType]
// NOTE: Should be a lazy val but scalac does not allow abstract lazy vals (dotty does)
protected lazy val classBTypeFromInternalNameMap: collection.concurrent.Map[String, ClassBType]

/**
* Obtain a previously constructed ClassBType for a given internal name.
Expand Down
17 changes: 9 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I, val frontendAcce
(classSym != defn.NothingClass && classSym != defn.NullClass),
s"Cannot create ClassBType for special class symbol ${classSym.showFullName}")

convertedClasses.getOrElse(classSym, {
val internalName = classSym.javaBinaryName
// We first create and add the ClassBType to the hash map before computing its info. This
// allows initializing cylic dependencies, see the comment on variable ClassBType._info.
val classBType = new ClassBType(internalName)
convertedClasses(classSym) = classBType
setClassInfo(classSym, classBType)
})
convertedClasses.synchronized:
convertedClasses.getOrElse(classSym, {
val internalName = classSym.javaBinaryName
// We first create and add the ClassBType to the hash map before computing its info. This
// allows initializing cylic dependencies, see the comment on variable ClassBType._info.
val classBType = new ClassBType(internalName)
convertedClasses(classSym) = classBType
setClassInfo(classSym, classBType)
})
}

final def mirrorClassBTypeFromSymbol(moduleClassSym: Symbol): ClassBType = {
Expand Down
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/backend/jvm/BackendUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ class BackendUtils(val postProcessor: PostProcessor) {
// stack map frames and invokes the `getCommonSuperClass` method. This method expects all
// ClassBTypes mentioned in the source code to exist in the map.

val serlamObjDesc = MethodBType(jliSerializedLambdaRef :: Nil, ObjectRef).descriptor

val mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$deserializeLambda$", serlamObjDesc, null, null)
val mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$deserializeLambda$", serializedLamdaObjDesc, null, null)
def emitLambdaDeserializeIndy(targetMethods: Seq[Handle]): Unit = {
mv.visitVarInsn(ALOAD, 0)
mv.visitInvokeDynamicInsn("lambdaDeserialize", serlamObjDesc, jliLambdaDeserializeBootstrapHandle, targetMethods: _*)
mv.visitInvokeDynamicInsn("lambdaDeserialize", serializedLamdaObjDesc, jliLambdaDeserializeBootstrapHandle, targetMethods: _*)
}

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

private lazy val serializedLamdaObjDesc = {
import coreBTypes.{ObjectRef, jliSerializedLambdaRef}
MethodBType(jliSerializedLambdaRef :: Nil, ObjectRef).descriptor
}

/**
* Visit the class node and collect all referenced nested classes.
*/
Expand Down
142 changes: 0 additions & 142 deletions compiler/src/dotty/tools/backend/jvm/ClassfileWriter.scala

This file was deleted.

Loading

0 comments on commit db7e033

Please sign in to comment.