summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2005-11-04 17:20:44 +0000
committerIulian Dragos <jaguarul@gmail.com>2005-11-04 17:20:44 +0000
commitdfe0ebc86a20cade472c636f7a77d537187253e1 (patch)
treea7fde13604f49535dcb5cc19e475e7fe8e129d64 /sources
parent029493a5ec45d0d1f9168725ea7b6ee00b89759c (diff)
downloadscala-dfe0ebc86a20cade472c636f7a77d537187253e1.tar.gz
scala-dfe0ebc86a20cade472c636f7a77d537187253e1.tar.bz2
scala-dfe0ebc86a20cade472c636f7a77d537187253e1.zip
Removed generation of useless jumps to followin...
Removed generation of useless jumps to following instruction.
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/nsc/backend/jvm/GenJVM.scala38
1 files changed, 29 insertions, 9 deletions
diff --git a/sources/scala/tools/nsc/backend/jvm/GenJVM.scala b/sources/scala/tools/nsc/backend/jvm/GenJVM.scala
index df117c7146..13a39289a2 100644
--- a/sources/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/sources/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -227,19 +227,31 @@ abstract class GenJVM extends SubComponent {
val linearizer = new NormalLinearizer();
var linearization: List[BasicBlock] = Nil;
+ var isModuleInitialized = false;
def genCode(m: IMethod): Unit = {
labels.clear;
retAddress.clear;
anyHandler.clear;
+ isModuleInitialized = false;
code = m.code;
linearization = linearizer.linearize(m);
makeLabels(linearization);
- linearization foreach genBlock;
+ genBlocks(linearization);
+
if (this.method.exh != Nil || this.method.finalizers != Nil)
genExceptionHandlers;
}
+ var nextBlock: BasicBlock = _;
+
+ def genBlocks(l: List[BasicBlock]): Unit = l match {
+ case Nil => ();
+ case x :: Nil => nextBlock = null; genBlock(x);
+ case x :: y :: ys => nextBlock = y; genBlock(x); genBlocks(y :: ys);
+ }
+
+
/** Map from finalizer to the code area where its 'any' exception handler was generated. */
val anyHandler: HashMap[Finalizer, Pair[Int, Int]] = new HashMap();
@@ -429,9 +441,10 @@ abstract class GenJVM extends SubComponent {
javaType(method).asInstanceOf[JMethodType]);
// we initialize the MODULE$ field immediately after the super ctor
- if (isTopLevelModule(clasz.symbol) &&
+ if (isTopLevelModule(clasz.symbol) && !isModuleInitialized &&
jmethod.getName() == JMethod.INSTANCE_CONSTRUCTOR_NAME &&
javaName(method) == JMethod.INSTANCE_CONSTRUCTOR_NAME) {
+ isModuleInitialized = true;
jcode.emitALOAD_0();
jcode.emitPUTSTATIC(jclass.getName(),
MODULE_INSTANCE_NAME,
@@ -502,17 +515,20 @@ abstract class GenJVM extends SubComponent {
MIN_SWITCH_DENSITY);
case JUMP(where) =>
- jcode.emitGOTO_maybe_W(labels(where), false); // default to short jumps
+ if (nextBlock != where)
+ jcode.emitGOTO_maybe_W(labels(where), false); // default to short jumps
case CJUMP(success, failure, cond, kind) =>
kind match {
case BOOL | BYTE | CHAR | SHORT | INT =>
jcode.emitIF_ICMP(conds(cond), labels(success));
- jcode.emitGOTO_maybe_W(labels(failure), false);
+ if (nextBlock != failure)
+ jcode.emitGOTO_maybe_W(labels(failure), false);
case REFERENCE(_) | ARRAY(_) =>
jcode.emitIF_ACMP(conds(cond), labels(success));
- jcode.emitGOTO_maybe_W(labels(failure), false);
+ if (nextBlock != failure)
+ jcode.emitGOTO_maybe_W(labels(failure), false);
case _ =>
kind match {
@@ -521,18 +537,21 @@ abstract class GenJVM extends SubComponent {
case DOUBLE => jcode.emitDCMPG();
}
jcode.emitIF(conds(cond), labels(success));
- jcode.emitGOTO_maybe_W(labels(failure), false);
+ if (nextBlock != failure)
+ jcode.emitGOTO_maybe_W(labels(failure), false);
}
case CZJUMP(success, failure, cond, kind) =>
kind match {
case BOOL | BYTE | CHAR | SHORT | INT =>
jcode.emitIF(conds(cond), labels(success));
- jcode.emitGOTO_maybe_W(labels(failure), false);
+ if (nextBlock != failure)
+ jcode.emitGOTO_maybe_W(labels(failure), false);
case REFERENCE(_) | ARRAY(_) =>
jcode.emitIFNULL(labels(success));
- jcode.emitGOTO_maybe_W(labels(failure), false);
+ if (nextBlock != failure)
+ jcode.emitGOTO_maybe_W(labels(failure), false);
case _ =>
kind match {
@@ -541,7 +560,8 @@ abstract class GenJVM extends SubComponent {
case DOUBLE => jcode.emitDCONST_0(); jcode.emitDCMPL();
}
jcode.emitIF(conds(cond), labels(success));
- jcode.emitGOTO_maybe_W(labels(failure), false);
+ if (nextBlock != failure)
+ jcode.emitGOTO_maybe_W(labels(failure), false);
}
case RETURN(kind) =>