summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-08-28 06:42:35 -0700
committerPaul Phillips <paulp@improving.org>2012-08-28 06:42:35 -0700
commitca7923dbfbdb663726eae46c6e13da2011b92972 (patch)
treea9be120df4a45751c6d0ecaac20d576c8eeb87ec
parenta23edefac652e3be1474fceb3ee15d7eaecf1359 (diff)
parent730871371ccc29c68e1c12a9f00aa8515236f139 (diff)
downloadscala-ca7923dbfbdb663726eae46c6e13da2011b92972.tar.gz
scala-ca7923dbfbdb663726eae46c6e13da2011b92972.tar.bz2
scala-ca7923dbfbdb663726eae46c6e13da2011b92972.zip
Merge pull request #1185 from paulp/210-updateConserve
Eliminated a metric ton of allocations.
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala36
-rw-r--r--test/files/run/inline-ex-handlers.check27
2 files changed, 36 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
index 8bbf11650c..486a43614b 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
@@ -42,10 +42,14 @@ trait BasicBlocks {
private final class SuccessorList() {
private var successors: List[BasicBlock] = Nil
+ /** This method is very hot! Handle with care. */
private def updateConserve() {
- var lb: ListBuffer[BasicBlock] = null
- var matches = 0
- var remaining = successors
+ var lb: ListBuffer[BasicBlock] = null
+ var matches = 0
+ var remaining = successors
+ val direct = directSuccessors
+ var scratchHandlers: List[ExceptionHandler] = method.exh
+ var scratchBlocks: List[BasicBlock] = direct
def addBlock(bb: BasicBlock) {
if (matches < 0)
@@ -60,25 +64,27 @@ trait BasicBlocks {
}
}
- // exceptionSuccessors
- method.exh foreach { handler =>
- if (handler covers outer)
- addBlock(handler.startBlock)
+ while (scratchBlocks ne Nil) {
+ addBlock(scratchBlocks.head)
+ scratchBlocks = scratchBlocks.tail
}
- // directSuccessors
- val direct = directSuccessors
- direct foreach addBlock
-
/** Return a list of successors for 'b' that come from exception handlers
* covering b's (non-exceptional) successors. These exception handlers
* might not cover 'b' itself. This situation corresponds to an
* exception being thrown as the first thing of one of b's successors.
*/
- method.exh foreach { handler =>
- direct foreach { block =>
- if (handler covers block)
+ while (scratchHandlers ne Nil) {
+ val handler = scratchHandlers.head
+ if (handler covers outer)
+ addBlock(handler.startBlock)
+
+ scratchBlocks = direct
+ while (scratchBlocks ne Nil) {
+ if (handler covers scratchBlocks.head)
addBlock(handler.startBlock)
+ scratchBlocks = scratchBlocks.tail
}
+ scratchHandlers = scratchHandlers.tail
}
// Blocks did not align: create a new list.
if (matches < 0)
@@ -101,7 +107,7 @@ trait BasicBlocks {
}
/** Flags of this basic block. */
- private var flags: Int = 0
+ private[this] var flags: Int = 0
/** Does this block have the given flag? */
def hasFlag(flag: Int): Boolean = (flags & flag) != 0
diff --git a/test/files/run/inline-ex-handlers.check b/test/files/run/inline-ex-handlers.check
index a4c9f215e8..2bc72893e7 100644
--- a/test/files/run/inline-ex-handlers.check
+++ b/test/files/run/inline-ex-handlers.check
@@ -61,22 +61,22 @@
> ? LOAD_LOCAL(variable monitor4)
> 305 MONITOR_EXIT
> ? JUMP 12
-550c557,563
+550c557
< ? THROW(Throwable)
---
> ? JUMP 12
+556c563,570
+< ? THROW(Throwable)
+---
+> ? STORE_LOCAL(value t)
+> ? JUMP 13
>
> 12:
> ? LOAD_LOCAL(variable monitor3)
> 304 MONITOR_EXIT
> ? STORE_LOCAL(value t)
> ? JUMP 13
-556c569,582
-< ? THROW(Throwable)
----
-> ? STORE_LOCAL(value t)
-> ? JUMP 13
->
+571a586,597
> 13:
> 310 LOAD_MODULE object Predef
> 310 CALL_PRIMITIVE(StartConcat)
@@ -88,6 +88,7 @@
> 310 CALL_PRIMITIVE(EndConcat)
> 310 CALL_METHOD scala.Predef.println (dynamic)
> 310 JUMP 2
+>
580c606
< catch (Throwable) in ArrayBuffer(7, 8, 9, 10) starting at: 6
---
@@ -110,12 +111,12 @@
> 81 LOAD_LOCAL(value e)
> ? STORE_LOCAL(variable exc1)
> ? JUMP 12
-668c700,714
+668c700,701
< 81 THROW(Exception)
---
> ? STORE_LOCAL(variable exc1)
> ? JUMP 12
->
+684a718,730
> 12:
> 83 LOAD_MODULE object Predef
> 83 CONSTANT("finally")
@@ -128,6 +129,7 @@
> 84 STORE_LOCAL(variable result)
> 84 LOAD_LOCAL(variable exc1)
> 84 THROW(Throwable)
+>
690c736
< catch (<none>) in ArrayBuffer(4, 6, 7, 9) starting at: 3
---
@@ -171,17 +173,18 @@
---
> ? STORE_LOCAL(value ex6)
> ? JUMP 33
-802c854,861
+802c854,855
< 170 THROW(Throwable)
---
> ? STORE_LOCAL(value ex6)
> ? JUMP 33
->
+811a865,870
> 33:
> 169 LOAD_LOCAL(value ex6)
> 169 STORE_LOCAL(value x4)
> 169 SCOPE_ENTER value x4
> 169 JUMP 5
+>
826,829d884
< 180 LOAD_LOCAL(value x5)
< 180 CALL_METHOD MyException.message (dynamic)
@@ -207,7 +210,7 @@
---
> ? STORE_LOCAL(variable exc2)
> ? JUMP 34
-842a902,914
+857a917,929
> 34:
> 184 LOAD_MODULE object Predef
> 184 CONSTANT("finally")