Skip to content

Commit

Permalink
Use JarWriter only when target jar is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMazur committed Aug 1, 2022
1 parent 4b5c077 commit fa42975
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
11 changes: 4 additions & 7 deletions compiler/src/dotty/tools/backend/jvm/PostProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
import int.given

val backendUtils = new BackendUtils(this)
lazy val classfileWriter = ClassfileWriter(frontendAccess)
val classfileWriter = ClassfileWriter(frontendAccess)

def postProcessAndSendToDisk(generatedDefs: GeneratedDefs): Unit = {
val GeneratedDefs(classes, tasty) = generatedDefs
Expand All @@ -30,21 +30,18 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
serializeClass(classNode)
catch
case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.nn.contains("too large!") =>
backendReporting.error(
s"Could not write class ${classNode.name} because it exceeds JVM code size limits. ${e.getMessage}",
NoSourcePosition
)
backendReporting.error(s"Could not write class ${classNode.name} because it exceeds JVM code size limits. ${e.getMessage}")
null
case ex: Throwable =>
ex.printStackTrace()
backendReporting.error(s"Error while emitting ${classNode.name}\n${ex.getMessage}",NoSourcePosition)
backendReporting.error(s"Error while emitting ${classNode.name}\n${ex.getMessage}")
null

if (bytes != null) {
if (AsmUtils.traceSerializedClassEnabled && classNode.name.nn.contains(AsmUtils.traceSerializedClassPattern))
AsmUtils.traceClass(bytes)

val clsFile = classfileWriter.write(classNode.name.nn, bytes, sourceFile)
val clsFile = classfileWriter.writeClass(classNode.name.nn, bytes, sourceFile)
if clsFile != null then onFileCreated(clsFile)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dotty.tools.backend.jvm

import scala.collection.mutable.Clearable
import scala.collection.mutable.{Clearable, HashSet}
import dotty.tools.dotc.util.*
import dotty.tools.io.AbstractFile
import java.util.{Collection => JCollection, Map => JMap}
Expand All @@ -20,7 +20,7 @@ sealed abstract class PostProcessorFrontendAccess {
def getEntryPoints: List[String]

private val frontendLock: AnyRef = new Object()
@inline final def frontendSynch[T](x: => T): T = frontendLock.synchronized(x)
inline final def frontendSynch[T](inline x: => T): T = frontendLock.synchronized(x)
}

object PostProcessorFrontendAccess {
Expand All @@ -35,11 +35,12 @@ object PostProcessorFrontendAccess {
}

sealed trait BackendReporting {
def error(message: String, pos: SourcePosition): Unit
def error(message: String): Unit
def warning(message: String): Unit
def log(message: String): Unit
}

class Impl[I <: DottyBackendInterface](val int: I) extends PostProcessorFrontendAccess {
class Impl[I <: DottyBackendInterface](val int: I, entryPoints: HashSet[String]) extends PostProcessorFrontendAccess {
import int.given
lazy val compilerSettings: CompilerSettings = buildCompilerSettings()

Expand Down Expand Up @@ -67,13 +68,11 @@ object PostProcessorFrontendAccess {
}

object backendReporting extends BackendReporting {
def error(message: String, pos: SourcePosition): Unit = frontendSynch(report.error(message, pos))
def error(message: String): Unit = frontendSynch(report.error(message, NoSourcePosition))
def warning(message: String): Unit = frontendSynch(report.warning(message, NoSourcePosition))
def log(message: String): Unit = frontendSynch(report.log(message))
}

def getEntryPoints: List[String] = frontendSynch(Phases.genBCodePhase match {
case genBCode: GenBCode => genBCode.entryPoints.toList
case _ => Nil
})
def getEntryPoints: List[String] = frontendSynch(entryPoints.toList)
}
}

0 comments on commit fa42975

Please sign in to comment.