summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-04-20 08:00:07 +0100
committerPaul Phillips <paulp@improving.org>2012-04-24 19:49:13 -0700
commit211df62491ada71a4a574fd2314942ab3c4a4ba8 (patch)
tree945235491107fcc129c331f6878697850671c58c
parent4682c77b7a50f1f72e72ce640216568d9841a5f0 (diff)
downloadscala-211df62491ada71a4a574fd2314942ab3c4a4ba8.tar.gz
scala-211df62491ada71a4a574fd2314942ab3c4a4ba8.tar.bz2
scala-211df62491ada71a4a574fd2314942ab3c4a4ba8.zip
Reordering genBlock match cases by frequency.
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala104
1 files changed, 68 insertions, 36 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
index f7898f2aa2..68996fbdfc 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -1311,6 +1311,40 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
}
}
+ // Collected frequency of opcdes to determine case ordering:
+ //
+ // 47514 CALL_METHOD
+ // 43434 LOAD_LOCAL
+ // 38572 THIS
+ // 31207 RETURN
+ // 5832 JUMP
+ // 5395 CONSTANT
+ // 5010 LOAD_FIELD
+ // 4731 STORE_LOCAL
+ // 4252 DUP
+ // 3612 NEW
+ // 3519 CZJUMP
+ // 2938 SCOPE_ENTER
+ // 2900 CALL_PRIMITIVE
+ // 2884 STORE_FIELD
+ // 2881 CHECK_CAST
+ // 2459 LOAD_MODULE
+ // 1783 SCOPE_EXIT
+ // 1315 CJUMP
+ // 1305 THROW
+ // 1030 DROP
+ // 485 BOX
+ // 468 UNBOX
+ // 464 MONITOR_EXIT
+ // 434 IS_INSTANCE
+ // 428 STORE_ARRAY_ITEM
+ // 329 LOAD_ARRAY_ITEM
+ // 280 CREATE_ARRAY
+ // 253 LOAD_EXCEPTION
+ // 232 MONITOR_ENTER
+ // 37 STORE_THIS
+ // 19 SWITCH
+
def genBlock(b: BasicBlock) {
labels(b).anchorToNext()
@@ -1324,11 +1358,43 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
val lastInstr = b.lastInstruction
for (instr <- b) {
+ println(instr.getClass)
instr match {
- case THIS(clasz) => jcode.emitALOAD_0()
+ case call @ CALL_METHOD(method, style) =>
+ /** Special handling to access native Array.clone() */
+ if (method == definitions.Array_clone && style == Dynamic) {
+ val target = javaType(call.targetTypeKind).getSignature()
+ jcode.emitINVOKEVIRTUAL(target, "clone", arrayCloneType)
+ }
+ else genCallMethod(call)
+
+ case LOAD_LOCAL(local) => jcode.emitLOAD(indexOf(local), javaType(local.kind))
+ case THIS(clasz) => jcode.emitALOAD_0()
+ case RETURN(kind) => jcode emitRETURN javaType(kind)
- case CONSTANT(const) => genConstant(jcode, const)
+ case CONSTANT(const) => genConstant(jcode, const)
+ case JUMP(whereto) =>
+ if (nextBlock != whereto)
+ jcode.emitGOTO_maybe_W(labels(whereto), false) // default to short jumps
+
+ case lf @ LOAD_FIELD(field, isStatic) =>
+ var owner = javaName(lf.hostClass)
+ debuglog("LOAD_FIELD with owner: " + owner + " flags: " + Flags.flagsToString(field.owner.flags))
+ val fieldJName = javaName(field)
+ val fieldJType = javaType(field)
+ if (isStatic) jcode.emitGETSTATIC(owner, fieldJName, fieldJType)
+ else jcode.emitGETFIELD( owner, fieldJName, fieldJType)
+
+ case STORE_LOCAL(local) =>
+ jcode.emitSTORE(indexOf(local), javaType(local.kind))
+
+ case DUP(kind) =>
+ if(kind.isWideType) jcode.emitDUP2()
+ else jcode.emitDUP()
+
+ case NEW(REFERENCE(cls)) =>
+ jcode emitNEW javaName(cls)
case LOAD_ARRAY_ITEM(kind) =>
if(kind.isRefOrArrayType) { jcode.emitAALOAD() }
@@ -1345,17 +1411,6 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
}
}
- case LOAD_LOCAL(local) => jcode.emitLOAD(indexOf(local), javaType(local.kind))
-
- case lf @ LOAD_FIELD(field, isStatic) =>
- var owner = javaName(lf.hostClass)
- debuglog("LOAD_FIELD with owner: " + owner +
- " flags: " + Flags.flagsToString(field.owner.flags))
- val fieldJName = javaName(field)
- val fieldJType = javaType(field)
- if (isStatic) jcode.emitGETSTATIC(owner, fieldJName, fieldJType)
- else jcode.emitGETFIELD( owner, fieldJName, fieldJType)
-
case LOAD_MODULE(module) =>
// assert(module.isModule, "Expected module: " + module)
debuglog("generating LOAD_MODULE for: " + module + " flags: " + Flags.flagsToString(module.flags));
@@ -1381,9 +1436,6 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
}
}
- case STORE_LOCAL(local) =>
- jcode.emitSTORE(indexOf(local), javaType(local.kind))
-
case STORE_THIS(_) =>
// this only works for impl classes because the self parameter comes first
// in the method signature. If that changes, this code has to be revisited.
@@ -1398,13 +1450,6 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
case CALL_PRIMITIVE(primitive) => genPrimitive(primitive, instr.pos)
- /** Special handling to access native Array.clone() */
- case call @ CALL_METHOD(definitions.Array_clone, Dynamic) =>
- val target: String = javaType(call.targetTypeKind).getSignature()
- jcode.emitINVOKEVIRTUAL(target, "clone", arrayCloneType)
-
- case call @ CALL_METHOD(method, style) => genCallMethod(call)
-
case BOX(kind) =>
val Pair(mname, mtype) = jBoxTo(kind)
jcode.emitINVOKESTATIC(BoxesRunTime, mname, mtype)
@@ -1413,10 +1458,6 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
val Pair(mname, mtype) = jUnboxTo(kind)
jcode.emitINVOKESTATIC(BoxesRunTime, mname, mtype)
- case NEW(REFERENCE(cls)) =>
- val className = javaName(cls)
- jcode emitNEW className
-
case CREATE_ARRAY(elem, 1) =>
if(elem.isRefOrArrayType) { jcode emitANEWARRAY javaType(elem).asInstanceOf[JReferenceType] }
else { jcode emitNEWARRAY javaType(elem) }
@@ -1462,10 +1503,6 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
MIN_SWITCH_DENSITY)
()
- case JUMP(whereto) =>
- if (nextBlock != whereto)
- jcode.emitGOTO_maybe_W(labels(whereto), false) // default to short jumps
-
case CJUMP(success, failure, cond, kind) =>
if(kind.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT
if (nextBlock == success) {
@@ -1552,7 +1589,6 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
}
}
- case RETURN(kind) => jcode emitRETURN javaType(kind)
case THROW(_) => jcode.emitATHROW()
@@ -1560,10 +1596,6 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
if(kind.isWideType) jcode.emitPOP2()
else jcode.emitPOP()
- case DUP(kind) =>
- if(kind.isWideType) jcode.emitDUP2()
- else jcode.emitDUP()
-
case MONITOR_ENTER() => jcode.emitMONITORENTER()
case MONITOR_EXIT() => jcode.emitMONITOREXIT()