summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-08-16 11:54:00 +0200
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-08-20 08:11:06 +0100
commitfb3157726bb16d69542de7cf0df1ebefa3505484 (patch)
treed58281bef79e79d89f74f445ad7a10eb77101934
parent1ee7ffb6fd2de6e7194a4eb89601d98503b50048 (diff)
downloadscala-fb3157726bb16d69542de7cf0df1ebefa3505484.tar.gz
scala-fb3157726bb16d69542de7cf0df1ebefa3505484.tar.bz2
scala-fb3157726bb16d69542de7cf0df1ebefa3505484.zip
Make Array creation more efficient in hot places.
Overriden ClassTags in places where we allocate a lot of Arrays.
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala6
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala13
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala5
3 files changed, 23 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
index 3f0cef6703..8bbf11650c 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
@@ -20,6 +20,12 @@ trait BasicBlocks {
import global.{ ifDebug, settings, log, nme }
import nme.isExceptionResultName
+ /** Override Array creation for efficiency (to not go through reflection). */
+ private implicit val instructionTag: scala.reflect.ClassTag[Instruction] = new scala.reflect.ClassTag[Instruction] {
+ def runtimeClass: java.lang.Class[Instruction] = classOf[Instruction]
+ final override def newArray(len: Int): Array[Instruction] = new Array[Instruction](len)
+ }
+
object NoBasicBlock extends BasicBlock(-1, null)
/** This class represents a basic block. Each
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
index dede8f6a13..b57f5e86a3 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
@@ -448,6 +448,17 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
val JAVA_LANG_OBJECT = asm.Type.getObjectType("java/lang/Object")
val JAVA_LANG_STRING = asm.Type.getObjectType("java/lang/String")
+ /**
+ * We call many Java varargs methods from ASM library that expect Arra[asm.Type] as argument so
+ * we override default (compiler-generated) ClassTag so we can provide specialized newArray implementation.
+ *
+ * Examples of methods that should pick our definition are: JBuilder.javaType and JPlainBuilder.genMethod.
+ */
+ private implicit val asmTypeTag: scala.reflect.ClassTag[asm.Type] = new scala.reflect.ClassTag[asm.Type] {
+ def runtimeClass: java.lang.Class[asm.Type] = classOf[asm.Type]
+ final override def newArray(len: Int): Array[asm.Type] = new Array[asm.Type](len)
+ }
+
/** basic functionality for class file building */
abstract class JBuilder(bytecodeWriter: BytecodeWriter) {
@@ -641,7 +652,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
def javaType(s: Symbol): asm.Type = {
if (s.isMethod) {
val resT: asm.Type = if (s.isClassConstructor) asm.Type.VOID_TYPE else javaType(s.tpe.resultType);
- asm.Type.getMethodType( resT, (s.tpe.paramTypes map javaType): _* )
+ asm.Type.getMethodType( resT, (s.tpe.paramTypes map javaType): _*)
} else { javaType(s.tpe) }
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
index f69e5b6098..de927f783a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -2040,6 +2040,11 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
trait CNF extends Logic {
// CNF: a formula is a conjunction of clauses
type Formula = Array[Clause]
+ /** Override Array creation for efficiency (to not go through reflection). */
+ private implicit val formulaTag: scala.reflect.ClassTag[Formula] = new scala.reflect.ClassTag[Formula] {
+ def runtimeClass: java.lang.Class[Formula] = classOf[Formula]
+ final override def newArray(len: Int): Array[Formula] = new Array[Formula](len)
+ }
def formula(c: Clause*): Formula = c.toArray
def andFormula(a: Formula, b: Formula): Formula = a ++ b