diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend')
8 files changed, 46 insertions, 42 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala b/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala index 32b5a98b98..7236bf70d5 100644 --- a/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala +++ b/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala @@ -55,8 +55,6 @@ trait JavaPlatform extends Platform { (sym isNonBottomSubClass BoxedBooleanClass) } - def doLoad(cls: ClassPath[AbstractFile]#ClassRep): Boolean = true - def needCompile(bin: AbstractFile, src: AbstractFile) = src.lastModified >= bin.lastModified } diff --git a/src/compiler/scala/tools/nsc/backend/Platform.scala b/src/compiler/scala/tools/nsc/backend/Platform.scala index 499f8a9290..439cc1efb8 100644 --- a/src/compiler/scala/tools/nsc/backend/Platform.scala +++ b/src/compiler/scala/tools/nsc/backend/Platform.scala @@ -31,14 +31,6 @@ trait Platform { def isMaybeBoxed(sym: Symbol): Boolean /** - * Tells whether a class should be loaded and entered into the package - * scope. On .NET, this method returns `false` for all synthetic classes - * (anonymous classes, implementation classes, module classes), their - * symtab is encoded in the pickle of another class. - */ - def doLoad(cls: ClassPath[AbstractFile]#ClassRep): Boolean - - /** * Tells whether a class with both a binary and a source representation * (found in classpath and in sourcepath) should be re-compiled. Behaves * on the JVM similar to javac, i.e. if the source file is newer than the classfile, diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 1cea4bedda..0da66d43f7 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -13,13 +13,12 @@ import scala.collection.{ mutable, immutable } import scala.collection.mutable.{ ListBuffer, Buffer } import scala.tools.nsc.symtab._ import scala.annotation.switch -import PartialFunction._ /** * @author Iulian Dragos * @version 1.0 */ -abstract class GenICode extends SubComponent { +abstract class GenICode extends SubComponent { import global._ import icodes._ import icodes.opcodes._ @@ -30,6 +29,9 @@ abstract class GenICode extends SubComponent { } import platform.isMaybeBoxed + private val bCodeICodeCommon: jvm.BCodeICodeCommon[global.type] = new jvm.BCodeICodeCommon(global) + import bCodeICodeCommon._ + val phaseName = "icode" override def newPhase(prev: Phase) = new ICodePhase(prev) @@ -1326,15 +1328,6 @@ abstract class GenICode extends SubComponent { List(tree) } - /** Some useful equality helpers. - */ - def isNull(t: Tree) = cond(t) { case Literal(Constant(null)) => true } - def isLiteral(t: Tree) = cond(t) { case Literal(_) => true } - def isNonNullExpr(t: Tree) = isLiteral(t) || ((t.symbol ne null) && t.symbol.isModule) - - /* If l or r is constant null, returns the other ; otherwise null */ - def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null - /** * Find the label denoted by `lsym` and enter it in context `ctx`. * diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala index 53142fbd87..92ebe5027a 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala @@ -23,6 +23,7 @@ import scala.tools.asm abstract class BCodeBodyBuilder extends BCodeSkelBuilder { import global._ import definitions._ + import bCodeICodeCommon._ /* * Functionality to build the body of ASM MethodNode, except for `synchronized` and `try` expressions. @@ -1020,17 +1021,6 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder { tree :: Nil } - /* Some useful equality helpers. */ - def isNull(t: Tree) = { - t match { - case Literal(Constant(null)) => true - case _ => false - } - } - - /* If l or r is constant null, returns the other ; otherwise null */ - def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null - /* Emit code to compare the two top-most stack values using the 'op' operator. */ private def genCJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType) { if (tk.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT @@ -1200,6 +1190,12 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder { // expr == null -> expr eq null genLoad(l, ObjectReference) genCZJUMP(success, failure, icodes.EQ, ObjectReference) + } else if (isNonNullExpr(l)) { + // SI-7852 Avoid null check if L is statically non-null. + genLoad(l, ObjectReference) + genLoad(r, ObjectReference) + genCallMethod(Object_equals, icodes.opcodes.Dynamic) + genCZJUMP(success, failure, icodes.NE, BOOL) } else { // l == r -> if (l eq null) r eq null else l.equals(r) val eqEqTempLocal = locals.makeLocal(AnyRefReference, nme.EQEQ_LOCAL_VAR.toString) diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala index cc3265c5f9..aa7e73a36b 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala @@ -22,6 +22,8 @@ abstract class BCodeGlue extends SubComponent { import global._ + protected val bCodeICodeCommon: BCodeICodeCommon[global.type] = new BCodeICodeCommon(global) + object BType { import global.chrs diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala index 359e5d6c29..f800dbf9cd 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala @@ -239,6 +239,13 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters { } /* + * must-single-thread + */ + def serialVUID(csym: Symbol): Option[Long] = csym getAnnotation definitions.SerialVersionUIDAttr collect { + case AnnotationInfo(_, _, (_, LiteralAnnotArg(const)) :: Nil) => const.longValue + } + + /* * Populates the InnerClasses JVM attribute with `refedInnerClasses`. * In addition to inner classes mentioned somewhere in `jclass` (where `jclass` is a class file being emitted) * `refedInnerClasses` should contain those inner classes defined as direct member classes of `jclass` @@ -881,13 +888,6 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters { val MIN_SWITCH_DENSITY = 0.7 /* - * must-single-thread - */ - def serialVUID(csym: Symbol): Option[Long] = csym getAnnotation definitions.SerialVersionUIDAttr collect { - case AnnotationInfo(_, Literal(const) :: _, _) => const.longValue - } - - /* * Add public static final field serialVersionUID with value `id` * * can-multi-thread diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeICodeCommon.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeICodeCommon.scala new file mode 100644 index 0000000000..50d20921d5 --- /dev/null +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeICodeCommon.scala @@ -0,0 +1,25 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2014 LAMP/EPFL + * @author Martin Odersky + */ + +package scala.tools.nsc.backend.jvm + +import scala.tools.nsc.Global +import PartialFunction._ + +/** + * This trait contains code shared between GenBCode and GenICode that depends on types defined in + * the compiler cake (Global). + */ +final class BCodeICodeCommon[G <: Global](val global: G) { + import global._ + + /** Some useful equality helpers. */ + def isNull(t: Tree) = cond(t) { case Literal(Constant(null)) => true } + def isLiteral(t: Tree) = cond(t) { case Literal(_) => true } + def isNonNullExpr(t: Tree) = isLiteral(t) || ((t.symbol ne null) && t.symbol.isModule) + + /** If l or r is constant null, returns the other ; otherwise null */ + def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null +} diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index a389816caf..b7f9b30e19 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -1142,9 +1142,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM { def isParcelableClass = isAndroidParcelableClass(clasz.symbol) - def serialVUID: Option[Long] = clasz.symbol getAnnotation SerialVersionUIDAttr collect { - case AnnotationInfo(_, Literal(const) :: _, _) => const.longValue - } + def serialVUID: Option[Long] = genBCode.serialVUID(clasz.symbol) private def getSuperInterfaces(c: IClass): Array[String] = { |